Skip to content

Commit f7f6b0e

Browse files
Commit
1 parent 64a4623 commit f7f6b0e

2 files changed

Lines changed: 14 additions & 23 deletions

File tree

dist/addon.node

0 Bytes
Binary file not shown.

native-src/virtual_drive/dehydrate_file.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,29 @@
22
#include "napi_extract_args.h"
33
#include "stdafx.h"
44

5-
napi_value dehydrate_file(napi_env env, napi_callback_info info) {
5+
napi_value dehydrate_file(napi_env env, napi_callback_info info)
6+
{
67
auto [rawPath] = napi_extract_args<std::wstring>(env, info);
7-
const wchar_t* path = rawPath.c_str();
8+
const wchar_t *path = rawPath.c_str();
89

910
DWORD attrib = GetFileAttributesW(path);
1011

11-
if (attrib & FILE_ATTRIBUTE_DIRECTORY) {
12+
if (attrib & FILE_ATTRIBUTE_DIRECTORY)
13+
{
1214
throw std::runtime_error("Cannot dehydrate folder");
1315
}
1416

15-
winrt::handle placeholder(CreateFileW(path, 0, FILE_READ_DATA, nullptr, OPEN_EXISTING, 0, nullptr));
17+
winrt::handle fileHandle(CreateFileW(path, 0, FILE_READ_DATA, nullptr, OPEN_EXISTING, 0, nullptr));
1618

1719
LARGE_INTEGER offset;
1820
offset.QuadPart = 0;
1921
LARGE_INTEGER length;
20-
GetFileSizeEx(placeholder.get(), &length);
21-
22-
HRESULT hr = CfDehydratePlaceholder(placeholder.get(), offset, length, CF_DEHYDRATE_FLAG_NONE, NULL);
23-
24-
if (SUCCEEDED(hr)) {
25-
return nullptr;
26-
}
27-
28-
DWORD err = HRESULT_CODE(hr);
29-
30-
if (err == ERROR_SHARING_VIOLATION || err == ERROR_CLOUD_FILE_IN_USE) {
31-
// MessageBoxW(
32-
// nullptr,
33-
// L"Unable to free up space because the file is currently in use.\nPlease close the file and try again.",
34-
// L"File in use",
35-
// MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL);
36-
}
37-
38-
winrt::throw_hresult(hr);
22+
GetFileSizeEx(fileHandle.get(), &length);
23+
24+
winrt::check_hresult(CfDehydratePlaceholder(
25+
fileHandle.get(),
26+
offset,
27+
length,
28+
CF_DEHYDRATE_FLAG_NONE,
29+
nullptr));
3930
}

0 commit comments

Comments
 (0)