-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_file_placeholder.cpp
More file actions
42 lines (35 loc) · 1.76 KB
/
create_file_placeholder.cpp
File metadata and controls
42 lines (35 loc) · 1.76 KB
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
36
37
38
39
40
41
42
#include <filesystem>
#include <windows.h>
#include "Placeholders.h"
#include "convert_to_placeholder.h"
#include "napi_extract_args.h"
#include <check_hresult.h>
napi_value create_file_placeholder_impl(napi_env env, napi_callback_info info)
{
auto [name, placeholderId, fileSize, creationTimeMs, lastWriteTimeMs, lastAccessTimeMs, parentPath] =
napi_extract_args<std::wstring, std::wstring, int64_t, int64_t, int64_t, int64_t, std::wstring>(env, info);
LARGE_INTEGER creationTime = Utilities::JsTimestampToLargeInteger(creationTimeMs);
LARGE_INTEGER lastWriteTime = Utilities::JsTimestampToLargeInteger(lastWriteTimeMs);
LARGE_INTEGER lastAccessTime = Utilities::JsTimestampToLargeInteger(lastAccessTimeMs);
std::wstring path = parentPath + L'\\' + name;
if (std::filesystem::exists(path))
{
convert_to_placeholder(path, placeholderId);
return nullptr;
}
CF_PLACEHOLDER_CREATE_INFO cloudEntry = {};
cloudEntry.FileIdentity = placeholderId.c_str();
cloudEntry.FileIdentityLength = static_cast<DWORD>((placeholderId.size() + 1) * sizeof(WCHAR));
cloudEntry.RelativeFileName = name.c_str();
cloudEntry.Flags = CF_PLACEHOLDER_CREATE_FLAG_MARK_IN_SYNC;
cloudEntry.FsMetadata.FileSize.QuadPart = fileSize;
cloudEntry.FsMetadata.BasicInfo.FileAttributes = FILE_ATTRIBUTE_NORMAL;
cloudEntry.FsMetadata.BasicInfo.CreationTime = creationTime;
cloudEntry.FsMetadata.BasicInfo.LastWriteTime = lastWriteTime;
cloudEntry.FsMetadata.BasicInfo.LastAccessTime = lastAccessTime;
cloudEntry.FsMetadata.BasicInfo.ChangeTime = lastWriteTime;
check_hresult(
"CfCreatePlaceholders",
CfCreatePlaceholders(parentPath.c_str(), &cloudEntry, 1, CF_CREATE_FLAG_NONE, nullptr));
return nullptr;
}