-
Notifications
You must be signed in to change notification settings - Fork 1
Simplify main #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify main #202
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,76 +62,33 @@ void Placeholders::MaintainIdentity(std::wstring &fullPath, PCWSTR itemIdentity, | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @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 */) | ||
| void Placeholders::UpdateSyncStatus(const std::wstring &path, bool isDirectory) | ||
| { | ||
| 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(h); | ||
| 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)) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't care about the different types of errors, we just throw the error. If this is not inside a cloud provider (second |
||
| { | ||
| 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: | ||
| convert_to_placeholder(filePath, L"temp_identity"); | ||
| hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr); | ||
| wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n"); | ||
| break; | ||
| winrt::file_handle fileHandle{CreateFileW( | ||
| path.c_str(), | ||
| FILE_WRITE_ATTRIBUTES, | ||
| FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | ||
| nullptr, | ||
| OPEN_EXISTING, | ||
| flags, | ||
| nullptr)}; | ||
|
|
||
| default: | ||
| wprintf(L"[UpdateSyncStatus] CfSetInSyncState 0x%08X\n", hr); | ||
| break; | ||
| } | ||
| } | ||
| else | ||
| if (!fileHandle) | ||
| { | ||
| wprintf(L"[UpdateSyncStatus] Estado actualizado\n"); | ||
| throw std::runtime_error("Failed to open item: " + std::to_string(GetLastError())); | ||
| } | ||
|
|
||
| CloseHandle(h); | ||
| winrt::check_hresult(CfSetInSyncState( | ||
| fileHandle.get(), | ||
| CF_IN_SYNC_STATE_IN_SYNC, | ||
| CF_SET_IN_SYNC_FLAG_NONE, | ||
| nullptr)); | ||
|
|
||
| SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, filePath.c_str(), nullptr); | ||
| SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, path.c_str(), nullptr); | ||
| } | ||
|
|
||
| void Placeholders::UpdateFileIdentity(const std::wstring &filePath, const std::wstring &fileIdentity, bool isDirectory) | ||
|
|
@@ -248,25 +205,3 @@ FileState Placeholders::GetPlaceholderInfo(const std::wstring &directoryPath) | |
|
|
||
| return fileState; | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of defining all functions one by one we define all of them at the same time. See that we replaced
1by14which is the number of elements in the array.