-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdehydrate_file.cpp
More file actions
35 lines (28 loc) · 876 Bytes
/
dehydrate_file.cpp
File metadata and controls
35 lines (28 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <windows.h>
#include "napi_extract_args.h"
#include "stdafx.h"
#include "Placeholders.h"
#include <check_hresult.h>
napi_value dehydrate_file(napi_env env, napi_callback_info info)
{
auto [path] = napi_extract_args<std::wstring>(env, info);
DWORD attrib = GetFileAttributesW(path.c_str());
if (attrib & FILE_ATTRIBUTE_DIRECTORY)
{
throw std::runtime_error("Cannot dehydrate folder");
}
auto fileHandle = Placeholders::OpenFileHandle(path, FILE_WRITE_ATTRIBUTES, true);
LARGE_INTEGER offset;
offset.QuadPart = 0;
LARGE_INTEGER length;
GetFileSizeEx(fileHandle.get(), &length);
check_hresult(
"CfDehydratePlaceholder",
CfDehydratePlaceholder(
fileHandle.get(),
offset,
length,
CF_DEHYDRATE_FLAG_NONE,
nullptr));
return nullptr;
}