33#include < propkey.h>
44#include < propvarutil.h>
55#include " Utilities.h"
6- #include < ProcessTypes.h>
76#include < Logger.h>
87
98#define MSSEARCH_INDEX L" SystemIndex"
109DEFINE_PROPERTYKEY (PKEY_StorageProviderTransferProgress, 0xE77E90DF , 0x6271 , 0x4F5B , 0x83 , 0x4F , 0x2D , 0xD1 , 0xF2 , 0x45 , 0xDD , 0xA4 , 4 );
1110
12- void Utilities::ApplyCustomStateToPlaceholderFile (LPCWSTR path, LPCWSTR filename, winrt::StorageProviderItemProperty &prop)
13- {
14- try
15- {
16- std::wstring fullPath (path);
17- fullPath.append (L" \\ " );
18- fullPath.append (filename);
19-
20- // wprintf(L"Full path: %s\n", fullPath.c_str());
21- winrt::IStorageItem item = winrt::StorageFile::GetFileFromPathAsync (fullPath).get ();
22- winrt::StorageProviderItemProperties::SetAsync (item, {prop}).get ();
23- }
24- catch (const winrt::hresult_error &error)
25- {
26- wprintf (L" Failed to set custom state. Error: %s (Code: %08x)\n " , error.message ().c_str (), error.code ());
27- }
28- catch (...)
29- {
30- wprintf (L" Failed to set custom state with unknown error %08x\n " , static_cast <HRESULT>(winrt::to_hresult ()));
31- }
32- }
33-
34- void Utilities::ApplyCustomOverwriteStateToPlaceholderFile (LPCWSTR path, LPCWSTR filename, winrt::StorageProviderItemProperty &prop)
35- {
36- try
37- {
38- std::wstring fullPath (path);
39- fullPath.append (L" \\ " );
40- fullPath.append (filename);
41-
42- // wprintf(L"Full path: %s\n", fullPath.c_str());
43- winrt::IStorageItem item = winrt::StorageFile::GetFileFromPathAsync (fullPath).get ();
44- winrt::StorageProviderItemProperties::SetAsync (item, {}).get ();
45- winrt::StorageProviderItemProperties::SetAsync (item, {prop}).get ();
46- }
47- catch (const winrt::hresult_error &error)
48- {
49- wprintf (L" Failed to set custom state. Error: %s (Code: %08x)\n " , error.message ().c_str (), error.code ());
50- }
51- catch (...)
52- {
53- wprintf (L" Failed to set custom state with unknown error %08x\n " , static_cast <HRESULT>(winrt::to_hresult ()));
54- }
55- }
56-
5711void Utilities::AddFolderToSearchIndexer (_In_ PCWSTR folder)
5812{
5913 HRESULT hr = CoInitializeEx (NULL , COINIT_MULTITHREADED);
@@ -88,26 +42,6 @@ void Utilities::AddFolderToSearchIndexer(_In_ PCWSTR folder)
8842 }
8943}
9044
91- void Utilities::ClearTransferProperties (PCWSTR fullPath)
92- {
93- winrt::com_ptr<IShellItem2> item;
94- winrt::com_ptr<IPropertyStore>store;
95-
96- if (FAILED (SHCreateItemFromParsingName (fullPath, nullptr ,
97- __uuidof (item), item.put_void ())))
98- return ;
99-
100- if (FAILED (item->GetPropertyStore (GPS_READWRITE | GPS_VOLATILEPROPERTIESONLY,
101- __uuidof (store), store.put_void ())))
102- return ;
103-
104- PROPVARIANT empty; PropVariantInit (&empty);
105- store->SetValue (PKEY_StorageProviderTransferProgress, empty);
106- store->SetValue (PKEY_SyncTransferStatus, empty);
107- store->Commit ();
108- }
109-
110-
11145void Utilities::ApplyTransferStateToFile (_In_ PCWSTR fullPath, _In_ CF_CALLBACK_INFO &callbackInfo, UINT64 total, UINT64 completed)
11246{
11347 Logger::getInstance ().log (" ApplyTransferStateToFile" , LogLevel::INFO);
@@ -211,78 +145,3 @@ std::wstring Utilities::GetErrorMessageCloudFiles(HRESULT hr) {
211145 LocalFree (errorMsg);
212146 return message;
213147}
214-
215-
216- bool Utilities::IsTemporaryFile (const std::wstring &fullPath)
217- {
218- size_t fileNameStart = fullPath.find_last_of (L' \\ ' ) + 1 ;
219- if (fullPath.size () >= fileNameStart + 2 && fullPath.compare (fileNameStart, 2 , L" ~$" ) == 0 )
220- {
221- return true ;
222- }
223-
224- std::array<std::wstring, 7 > tempExtensions = {
225- L" .tmp" ,
226- L" .laccdb" ,
227- L" .ldb" ,
228- L" .bak" ,
229- L" .sv$" ,
230- L" .psdtmp" ,
231- L" .~tmp"
232- };
233-
234- for (const auto &ext : tempExtensions)
235- {
236- if (fullPath.size () >= ext.size () &&
237- fullPath.compare (fullPath.size () - ext.size (), ext.size (), ext) == 0 )
238- {
239- return true ;
240- }
241- }
242-
243- return false ;
244- }
245-
246- std::wstring Utilities::ProcessErrorNameToWString (ProcessErrorName error)
247- {
248- switch (error)
249- {
250- case ProcessErrorName::NOT_EXISTS:
251- return L" NOT_EXISTS" ;
252- case ProcessErrorName::NO_PERMISSION:
253- return L" NO_PERMISSION" ;
254- case ProcessErrorName::NO_INTERNET:
255- return L" NO_INTERNET" ;
256- case ProcessErrorName::NO_REMOTE_CONNECTION:
257- return L" NO_REMOTE_CONNECTION" ;
258- case ProcessErrorName::BAD_RESPONSE:
259- return L" BAD_RESPONSE" ;
260- case ProcessErrorName::EMPTY_FILE:
261- return L" EMPTY_FILE" ;
262- case ProcessErrorName::FILE_TOO_BIG:
263- return L" FILE_TOO_BIG" ;
264- case ProcessErrorName::UNKNOWN:
265- return L" UNKNOWN" ;
266- case ProcessErrorName::FILE_NON_EXTENSION:
267- return L" FILE_NON_EXTENSION" ;
268- default :
269- return L" UNKNOWN" ;
270- }
271- }
272-
273- std::wstring Utilities::FileOperationErrorToWString (FileOperationError error)
274- {
275- switch (error)
276- {
277- case FileOperationError::UPLOAD_ERROR:
278- return L" UPLOAD_ERROR" ;
279- case FileOperationError::DOWNLOAD_ERROR:
280- return L" DOWNLOAD_ERROR" ;
281- case FileOperationError::DELETE_ERROR:
282- return L" DELETE_ERROR" ;
283- case FileOperationError::METADATA_READ_ERROR:
284- return L" METADATA_READ_ERROR" ;
285- default :
286- return L" UNKNOWN" ;
287- }
288- }
0 commit comments