-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlanceholders.cpp
More file actions
632 lines (536 loc) · 21.1 KB
/
Planceholders.cpp
File metadata and controls
632 lines (536 loc) · 21.1 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
#include "stdafx.h"
#include "Placeholders.h"
#include "Logger.h"
#include "PlaceholderInfo.h"
#include <winrt/base.h>
#include <shlwapi.h>
#include <vector>
#include <filesystem>
#include <fstream>
#include <random>
#include <iostream>
#include <Utilities.h>
#include <winbase.h>
#include <string>
#include <cctype>
using namespace std;
namespace fs = std::filesystem;
#pragma comment(lib, "shlwapi.lib")
bool DirectoryExists(const wchar_t *path)
{
DWORD attributes = GetFileAttributesW(path);
return attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_DIRECTORY);
}
void Placeholders::CreateOne(
_In_ PCWSTR fileName,
_In_ PCWSTR fileIdentity,
int64_t fileSize,
DWORD fileIdentityLength,
uint32_t fileAttributes,
FILETIME creationTime,
FILETIME lastWriteTime,
FILETIME lastAccessTime,
_In_ PCWSTR destPath)
{
try
{
CF_PLACEHOLDER_CREATE_INFO cloudEntry = {};
std::wstring fullDestPath = std::wstring(destPath) + L'\\';
wstring fullPath = std::wstring(destPath) + L'\\' + fileName;
if (std::filesystem::exists(fullPath))
{
Placeholders::ConvertToPlaceholder(fullPath, fileIdentity);
Placeholders::MaintainIdentity(fullPath, fileIdentity, false);
return;
}
std::wstring relativeName(fileIdentity);
cloudEntry.FileIdentity = relativeName.c_str();
cloudEntry.FileIdentityLength = static_cast<DWORD>((relativeName.size() + 1) * sizeof(WCHAR));
cloudEntry.RelativeFileName = fileName;
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 = Utilities::FileTimeToLargeInteger(creationTime);
cloudEntry.FsMetadata.BasicInfo.LastWriteTime = Utilities::FileTimeToLargeInteger(lastWriteTime);
cloudEntry.FsMetadata.BasicInfo.LastAccessTime = Utilities::FileTimeToLargeInteger(lastAccessTime);
cloudEntry.FsMetadata.BasicInfo.ChangeTime = Utilities::FileTimeToLargeInteger(lastWriteTime);
try
{
winrt::check_hresult(CfCreatePlaceholders(fullDestPath.c_str(), &cloudEntry, 1, CF_CREATE_FLAG_NONE, NULL));
Placeholders::UpdatePinState(fullPath, PinState::OnlineOnly);
}
catch (const winrt::hresult_error &error)
{
wprintf(L"[CreatePlaceholder] error: %s", error.message().c_str());
}
winrt::StorageProviderItemProperty prop;
prop.Id(1);
prop.Value(L"Value1");
prop.IconResource(L"shell32.dll,-44");
// UpdateSyncStatus(fullDestPath, true, false);
}
catch (...)
{
wprintf(L"[CreatePlaceholder] Failed to create or customize placeholder with %08x\n", static_cast<HRESULT>(winrt::to_hresult()));
}
}
std::string cleanString(const std::string &str)
{
std::string cleanedStr;
for (char ch : str)
{
if (std::isprint(static_cast<unsigned char>(ch)))
{
cleanedStr.push_back(ch);
}
}
return cleanedStr;
}
void Placeholders::MaintainIdentity(std::wstring &fullPath, PCWSTR itemIdentity, bool isDirectory)
{
std::string identity = Placeholders::GetFileIdentity(fullPath);
if (!identity.empty())
{
int len = WideCharToMultiByte(CP_UTF8, 0, itemIdentity, -1, NULL, 0, NULL, NULL);
if (len > 0)
{
std::string itemIdentityStr(len, 0);
WideCharToMultiByte(CP_UTF8, 0, itemIdentity, -1, &itemIdentityStr[0], len, NULL, NULL);
std::string cleanIdentity = cleanString(identity);
std::string cleanItemIdentity = cleanString(itemIdentityStr);
if (cleanIdentity != cleanItemIdentity)
{
wprintf(L"[MaintainIdentity] Identity is incorrect, updating...\n");
std::wstring itemIdentityStrW(itemIdentity);
Placeholders::UpdateFileIdentity(fullPath, itemIdentityStrW, isDirectory);
}
}
else
{
// Handle error as needed
}
}
}
void Placeholders::CreateEntry(
_In_ PCWSTR itemName,
_In_ PCWSTR itemIdentity,
bool isDirectory,
uint32_t itemSize,
DWORD itemIdentityLength,
uint32_t itemAttributes,
FILETIME creationTime,
FILETIME lastWriteTime,
FILETIME lastAccessTime,
_In_ PCWSTR destPath)
{
std::wstring fullDestPath = std::wstring(destPath) + L"\\" + std::wstring(itemName);
CF_PLACEHOLDER_CREATE_INFO cloudEntry = {};
std::wstring relativeName(itemIdentity);
cloudEntry.FileIdentity = relativeName.c_str();
cloudEntry.FileIdentityLength = static_cast<DWORD>((relativeName.size() + 1) * sizeof(WCHAR));
cloudEntry.RelativeFileName = itemName;
cloudEntry.Flags = CF_PLACEHOLDER_CREATE_FLAG_DISABLE_ON_DEMAND_POPULATION; // -> desactive download on demand
cloudEntry.FsMetadata.BasicInfo.FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
cloudEntry.FsMetadata.BasicInfo.CreationTime = Utilities::FileTimeToLargeInteger(creationTime);
cloudEntry.FsMetadata.BasicInfo.LastWriteTime = Utilities::FileTimeToLargeInteger(lastWriteTime);
try
{
// TODO: si existe o es placeholder return
if (DirectoryExists(fullDestPath.c_str()))
{
Placeholders::ConvertToPlaceholder(fullDestPath, itemIdentity);
Placeholders::MaintainIdentity(fullDestPath, itemIdentity, true);
return; // No hacer nada si ya existe
}
if (isDirectory) // TODO: the function createEntry is used to create only folders (directories), so this if is always true
{
// wprintf(L"Create directory, full destination path: %ls, fullDestPath.c_str()");
PathRemoveFileSpecW(&fullDestPath[0]);
HRESULT hr = CfCreatePlaceholders(fullDestPath.c_str(), &cloudEntry, 1, CF_CREATE_FLAG_NONE, NULL);
if (FAILED(hr))
{
wprintf(L"[CreatePlaceholder] Failed to create placeholder directory with HRESULT 0x%08x\n", hr);
throw winrt::hresult_error(hr);
}
std::wstring finalPath = std::wstring(destPath) + L"\\" + std::wstring(itemName);
Placeholders::UpdatePinState(finalPath, PinState::OnlineOnly);
UpdateSyncStatus(finalPath, true, true);
}
}
catch (const winrt::hresult_error &error)
{
wprintf(L"[CreatePlaceholder] Error while creating %s: %s\n", isDirectory ? L"directory" : L"file", error.message().c_str());
}
}
bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std::wstring &serverIdentity)
{
try
{
if (!std::filesystem::exists(fullPath))
{
wprintf(L"[ConvertToPlaceholder] File does not exist\n");
return false;
}
wprintf(L"[ConvertToPlaceholder] Full path: %ls\n", fullPath.c_str());
bool isDirectory = fs::is_directory(fullPath);
HANDLE fileHandle = CreateFileW(
fullPath.c_str(),
FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr,
OPEN_EXISTING,
isDirectory ? FILE_FLAG_BACKUP_SEMANTICS : 0,
nullptr);
if (fileHandle == INVALID_HANDLE_VALUE)
{
// Manejar el error al abrir el archivo
return false;
}
CF_CONVERT_FLAGS convertFlags = CF_CONVERT_FLAG_MARK_IN_SYNC;
USN convertUsn;
OVERLAPPED overlapped = {};
LPCVOID idStrLPCVOID = static_cast<LPCVOID>(serverIdentity.c_str());
DWORD idStrByteLength = static_cast<DWORD>(serverIdentity.size() * sizeof(wchar_t));
HRESULT hr = CfConvertToPlaceholder(fileHandle, idStrLPCVOID, idStrByteLength, convertFlags, &convertUsn, &overlapped);
if (FAILED(hr))
{
// Manejar el error al convertir a marcador de posición
if (hr != 0x8007017C)
{
wprintf(L"[ConvertToPlaceholder] Error converting to placeholder, ConvertToPlaceholder failed with HRESULT 0x%X\n", hr);
}
// Puedes obtener información detallada sobre el error usando FormatMessage
LPVOID errorMsg;
FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
hr,
0, // Default language
(LPWSTR)&errorMsg,
0,
NULL);
// Liberar el buffer de mensaje de error
LocalFree(errorMsg);
CloseHandle(fileHandle);
return false;
}
if (!isDirectory)
{
HRESULT hrPinState = CfSetPinState(fileHandle, CF_PIN_STATE_PINNED, CF_SET_PIN_FLAG_NONE, nullptr);
if (FAILED(hrPinState))
{
std::wstring errorMessage = Utilities::GetErrorMessageCloudFiles(hrPinState);
wprintf(L"[ConvertToPlaceholder] Error setting pin state, HRESULT: 0x%X\nDetails: %s\n", hrPinState, errorMessage.c_str());
CloseHandle(fileHandle);
return false;
}
}
CloseHandle(fileHandle);
wprintf(L"[ConvertToPlaceholder] Successfully converted to placeholder: %ls\n", fullPath.c_str());
return true;
}
catch (const winrt::hresult_error &error)
{
// Manejar excepciones desconocidas
wprintf(L"[ConvertToPlaceholder] Unknown exception occurred\n");
return false;
}
}
std::wstring GetErrorMessageFromHRESULT(HRESULT hr)
{
LPWSTR errorMessage = nullptr;
DWORD result = FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&errorMessage),
0,
nullptr);
std::wstring message;
if (result > 0 && errorMessage)
{
message = errorMessage;
LocalFree(errorMessage);
}
else
{
message = L"Error desconocido";
}
return message;
}
/**
* @brief Mark a file or directory as synchronized
* @param filePath path to the file or directory
* @param isDirectory true if the path is a directory, false if it is a file
* @return void
*/
void Placeholders::UpdateSyncStatus(const std::wstring &filePath,
bool inputSyncState,
bool isDirectory /* = false */)
{
wprintf(L"[UpdateSyncStatus] Path: %ls\n", filePath.c_str());
DWORD flags = FILE_FLAG_OPEN_REPARSE_POINT;
if (isDirectory)
flags |= FILE_FLAG_BACKUP_SEMANTICS;
HANDLE h = CreateFileW(filePath.c_str(),
FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr,
OPEN_EXISTING,
flags,
nullptr);
if (h == INVALID_HANDLE_VALUE)
{
wprintf(L"[UpdateSyncStatus] CreateFileW falló: %lu\n", GetLastError());
CloseHandle(fileHandle);
return;
}
CF_IN_SYNC_STATE sync = inputSyncState ? CF_IN_SYNC_STATE_IN_SYNC
: CF_IN_SYNC_STATE_NOT_IN_SYNC;
HRESULT hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr);
if (FAILED(hr))
{
switch (HRESULT_CODE(hr))
{
case ERROR_RETRY:
Sleep(50);
hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr);
wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n");
break;
case ERROR_CLOUD_FILE_PROVIDER_NOT_RUNNING: // 0x1A94
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, filePath.c_str(), nullptr);
wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n");
break;
case ERROR_CLOUD_FILE_NOT_IN_SYNC:
ConvertToPlaceholder(filePath, L"temp_identity");
hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr);
wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n");
break;
default:
wprintf(L"[UpdateSyncStatus] CfSetInSyncState 0x%08X\n", hr);
break;
}
}
else
{
wprintf(L"[UpdateSyncStatus] Estado actualizado\n");
}
CloseHandle(h);
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, filePath.c_str(), nullptr);
}
void Placeholders::UpdateFileIdentity(const std::wstring &filePath, const std::wstring &fileIdentity, bool isDirectory)
{
HANDLE fileHandle = CreateFileW(
filePath.c_str(),
FILE_WRITE_ATTRIBUTES, // permisson needed to change the state
FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr,
OPEN_EXISTING,
isDirectory ? FILE_FLAG_BACKUP_SEMANTICS : FILE_ATTRIBUTE_NORMAL,
nullptr);
if (fileHandle == INVALID_HANDLE_VALUE)
{
DWORD errorCode = GetLastError();
wprintf(L"[UpdateFileIdentity] Error opening file: %d\n", errorCode);
LPWSTR errorMessage = nullptr;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
errorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&errorMessage),
0,
nullptr);
if (errorMessage)
{
wprintf(L"[UpdateFileIdentity] Error: %ls\n", errorMessage);
LocalFree(errorMessage);
}
return;
}
HRESULT hr = CfUpdatePlaceholder(
fileHandle, // Handle del archivo.
nullptr, // CF_FS_METADATA opcional.
fileIdentity.c_str(), // Identidad del archivo.
static_cast<DWORD>(fileIdentity.size() * sizeof(wchar_t)), // Longitud de la identidad del archivo.
nullptr, // Rango a deshidratar, opcional.
0, // Conteo de rangos a deshidratar, debe ser 0 si no se usa.
CF_UPDATE_FLAG_NONE, // Flags de actualización.
nullptr, // USN opcional.
nullptr // OVERLAPPED opcional.
);
if (FAILED(hr))
{
std::wstring errorMessage = Utilities::GetErrorMessageCloudFiles(hr);
wprintf(L"[UpdateFileIdentity] Error updating fileIdentity: %ls\n", errorMessage.c_str());
CloseHandle(fileHandle);
return;
}
CloseHandle(fileHandle);
}
std::string Placeholders::GetFileIdentity(const std::wstring &filePath)
{
constexpr auto fileIdMaxLength = 128;
const auto infoSize = sizeof(CF_PLACEHOLDER_BASIC_INFO) + fileIdMaxLength;
auto info = PlaceHolderInfo(reinterpret_cast<CF_PLACEHOLDER_BASIC_INFO *>(new char[infoSize]), FileHandle::deletePlaceholderInfo);
HRESULT result = CfGetPlaceholderInfo(handleForPath(filePath).get(), CF_PLACEHOLDER_INFO_BASIC, info.get(), Utilities::sizeToDWORD(infoSize), nullptr);
if (result == S_OK)
{
BYTE *FileIdentity = info->FileIdentity;
size_t length = info->FileIdentityLength;
std::string fileIdentityString(reinterpret_cast<const char *>(FileIdentity), length);
return fileIdentityString;
}
else
{
return "";
}
}
FileState Placeholders::GetPlaceholderInfo(const std::wstring &directoryPath)
{
constexpr auto fileIdMaxLength = 400;
const auto infoSize = sizeof(CF_PLACEHOLDER_BASIC_INFO) + fileIdMaxLength;
auto info = PlaceHolderInfo(reinterpret_cast<CF_PLACEHOLDER_BASIC_INFO *>(new char[infoSize]), FileHandle::deletePlaceholderInfo);
FileState fileState;
auto fileHandle = handleForPath(directoryPath);
if (!fileHandle)
{
printf("Error: Invalid file handle.\n");
fileState.pinstate = PinState::Unspecified;
fileState.syncstate = SyncState::Undefined;
return fileState;
}
HRESULT result = CfGetPlaceholderInfo(fileHandle.get(), CF_PLACEHOLDER_INFO_BASIC, info.get(), Utilities::sizeToDWORD(infoSize), nullptr);
if (result != S_OK)
{
printf("CfGetPlaceholderInfo failed with HRESULT %lx\n", result);
fileState.pinstate = PinState::Unspecified;
fileState.syncstate = SyncState::Undefined;
return fileState;
}
auto pinStateOpt = info.pinState();
auto syncStateOpt = info.syncState();
if (syncStateOpt.has_value())
{
SyncState syncState = syncStateOpt.value();
}
if (pinStateOpt.has_value())
{
PinState pinState = pinStateOpt.value();
}
fileState.pinstate = pinStateOpt.value_or(PinState::Unspecified);
fileState.syncstate = syncStateOpt.value_or(SyncState::Undefined);
return fileState;
}
std::vector<std::wstring> Placeholders::GetPlaceholderWithStatePending(const std::wstring &directoryPath)
{
std::vector<std::wstring> resultPaths;
for (const auto &entry : std::filesystem::directory_iterator(directoryPath))
{
const auto &path = entry.path().wstring();
if (entry.is_directory())
{
std::vector<std::wstring> subfolderPaths = GetPlaceholderWithStatePending(path);
resultPaths.insert(resultPaths.end(), subfolderPaths.begin(), subfolderPaths.end());
}
else if (entry.is_regular_file())
{
FileState placeholderState = Placeholders::GetPlaceholderInfo(path);
bool isFileValidForSync = (placeholderState.syncstate == SyncState::Undefined || placeholderState.syncstate == SyncState::NotInSync);
if (isFileValidForSync && IsFileValidForSync(path))
{
resultPaths.push_back(path);
}
}
}
return resultPaths;
}
bool Placeholders::IsFileValidForSync(const std::wstring &filePath)
{
// Obtener un handle al archivo
HANDLE fileHandle = CreateFileW(
filePath.c_str(),
FILE_READ_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
nullptr);
if (fileHandle == INVALID_HANDLE_VALUE)
{
// No se pudo abrir el archivo
return false;
}
// Verificar si el archivo está vacío
LARGE_INTEGER fileSize;
if (!GetFileSizeEx(fileHandle, &fileSize))
{
CloseHandle(fileHandle);
return false;
}
if (fileSize.QuadPart == 0)
{
CloseHandle(fileHandle);
return false;
}
LARGE_INTEGER maxFileSize;
maxFileSize.QuadPart = 20LL * 1024 * 1024 * 1024; // 20GB
if (fileSize.QuadPart > maxFileSize.QuadPart)
{
CloseHandle(fileHandle);
return false;
}
// // Verificar la extensión del archivo
if (std::filesystem::path(filePath).extension().empty())
{
CloseHandle(fileHandle);
return false;
}
// Cerrar el handle del archivo
CloseHandle(fileHandle);
return true;
}
void Placeholders::ForceShellRefresh(const std::wstring &path)
{
SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH, path.c_str(), nullptr);
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, path.c_str(), nullptr);
}
HRESULT Placeholders::UpdatePinState(const std::wstring &path, const PinState state)
{
const auto cfState = pinStateToCfPinState(state);
HRESULT result = CfSetPinState(handleForPath(path).get(), cfState, CF_SET_PIN_FLAG_NONE, nullptr);
// ForceShellRefresh(path);
if (result != S_OK)
{
Logger::getInstance().log("[UpdatePinState] Error updating pin state.", LogLevel::WARN);
}
return result;
}
PlaceholderAttribute Placeholders::GetAttribute(const std::wstring &filePath)
{
DWORD attrib = GetFileAttributesW(filePath.c_str());
if (!(attrib & FILE_ATTRIBUTE_DIRECTORY))
{
winrt::handle placeholder(CreateFileW(filePath.c_str(), 0, FILE_READ_DATA, nullptr, OPEN_EXISTING, 0, nullptr));
LARGE_INTEGER offset;
offset.QuadPart = 0;
LARGE_INTEGER length;
GetFileSizeEx(placeholder.get(), &length);
// length.QuadPart = MAXLONGLONG;
// bool isHydrated = fileState.pinstate == PinState::AlwaysLocal && fileState.syncstate == SyncState::InSync;
if (attrib & FILE_ATTRIBUTE_PINNED) // && !(isHydrated)
{
Logger::getInstance().log("Attribute: PINNED", LogLevel::INFO);
return PlaceholderAttribute::PINNED;
}
else if (attrib & FILE_ATTRIBUTE_UNPINNED)
{
Logger::getInstance().log("Attribute: NO PINNED", LogLevel::INFO);
return PlaceholderAttribute::NOT_PINNED;
}
Logger::getInstance().log("Attribute: Other", LogLevel::INFO);
return PlaceholderAttribute::OTHER;
}
Logger::getInstance().log("Attribute: Other", LogLevel::DEBUG);
return PlaceholderAttribute::OTHER;
}