diff --git a/binding.gyp b/binding.gyp index 858e963a..8f2aacf2 100644 --- a/binding.gyp +++ b/binding.gyp @@ -17,7 +17,6 @@ "native-src/logger/Logger.cpp", "native-src/logger/LoggerPath.cpp", "native-src/main.cpp", - "native-src/placeholders_interface/PlaceHolderInfo.cpp", "native-src/placeholders_interface/Planceholders.cpp", "native-src/sync_root_interface/SyncRoot.cpp", "native-src/sync_root_interface/Utilities.cpp", diff --git a/dist/addon.node b/dist/addon.node index 58d9b178..381ce8cc 100644 Binary files a/dist/addon.node and b/dist/addon.node differ diff --git a/include/placeholders_interface/PlaceHolderInfo.h b/include/placeholders_interface/PlaceHolderInfo.h deleted file mode 100644 index fa0514fc..00000000 --- a/include/placeholders_interface/PlaceHolderInfo.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "stdafx.h" -#include - -struct FileState -{ - std::string placeholderId; - CF_PIN_STATE pinState; -}; - -class FileHandle -{ -public: - using Deleter = void (*)(void *); - - FileHandle(); - FileHandle(void *data, Deleter deleter); - - inline void *get() const { return _data.get(); } - inline explicit operator bool() const noexcept { return static_cast(_data); } - -private: - std::unique_ptr _data; -}; - -FileHandle handleForPath(const std::wstring &path); diff --git a/include/placeholders_interface/Placeholders.h b/include/placeholders_interface/Placeholders.h index ac1befec..335a555e 100644 --- a/include/placeholders_interface/Placeholders.h +++ b/include/placeholders_interface/Placeholders.h @@ -1,7 +1,14 @@ #pragma once + #include #include -#include +#include + +struct FileState +{ + std::string placeholderId; + CF_PIN_STATE pinState; +}; class Placeholders { diff --git a/native-src/placeholders_interface/PlaceHolderInfo.cpp b/native-src/placeholders_interface/PlaceHolderInfo.cpp deleted file mode 100644 index efb60713..00000000 --- a/native-src/placeholders_interface/PlaceHolderInfo.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include "PlaceHolderInfo.h" -#include -#include -#include -#include -#include -#include "Logger.h" - -FileHandle::FileHandle() - : _data( - nullptr, [](void *) {}) -{ -} - -FileHandle::FileHandle(void *data, Deleter deleter) - : _data(data, deleter) -{ -} - -FileHandle handleForPath(const std::wstring &wPath) -{ - if (wPath.empty()) - { - return {}; - } - - /** - * v1.0.9 Jonathan Arce - * - * We directly use the wPath parameter in handleForPath for several important reasons: - * - * 1. Performance optimization: Using wPath directly avoids unnecessary string conversions - * between wide strings and UTF-8/ANSI, which would be costly for file operations. - * - * 2. Unicode support: Windows APIs like CfOpenFileWithOplock and CreateFileW require wide - * character strings (wchar_t) to properly handle Unicode paths with international - * characters, spaces, and special symbols. - */ - - std::filesystem::path pathFs(wPath); - if (!std::filesystem::exists(pathFs)) - { - return {}; - } - - if (std::filesystem::is_directory(pathFs)) - { - HANDLE handle = nullptr; - const HRESULT openResult = CfOpenFileWithOplock(wPath.c_str(), CF_OPEN_FILE_FLAG_NONE, &handle); - if (openResult == S_OK) - { - return {handle, [](HANDLE h) - { CfCloseHandle(h); }}; - } - else - { - // Convert only for logging purposes - std::wstring_convert> converter; - std::string path = converter.to_bytes(wPath); - printf("Could not CfOpenFileWithOplock for path: %s with error: %ld\n", path.c_str(), openResult); - } - } - else if (std::filesystem::is_regular_file(pathFs)) - { - HANDLE handle = CreateFileW( - wPath.c_str(), // Use wide string path directly - FILE_READ_ATTRIBUTES, - FILE_SHARE_READ | FILE_SHARE_WRITE, - nullptr, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - nullptr); - if (handle != INVALID_HANDLE_VALUE) - { - return {handle, [](HANDLE h) - { CloseHandle(h); }}; - } - else - { - // Convert only for logging purposes - std::wstring_convert> converter; - std::string path = converter.to_bytes(wPath); - printf("Could not CreateFile for path: %s with error: %ld\n", path.c_str(), GetLastError()); - } - } - - return {}; -} \ No newline at end of file diff --git a/native-src/placeholders_interface/Planceholders.cpp b/native-src/placeholders_interface/Planceholders.cpp index 56664ad4..90f0d6c6 100644 --- a/native-src/placeholders_interface/Planceholders.cpp +++ b/native-src/placeholders_interface/Planceholders.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include "Placeholders.h" #include "Logger.h" -#include "PlaceholderInfo.h" #include #include #include diff --git a/native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp b/native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp index 3366060f..3eff8ac9 100644 --- a/native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp +++ b/native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include #include #include #include @@ -17,6 +17,7 @@ #include #include #include +#include napi_threadsafe_function g_fetch_data_threadsafe_callback = nullptr; @@ -213,7 +214,8 @@ static napi_value response_callback_fn_fetch_data(napi_env env, napi_callback_in ::Sleep(CHUNKDELAYMS); - CfSetPinState(handleForPath(ctxPtr->fullClientPath.c_str()).get(), CF_PIN_STATE_PINNED, CF_SET_PIN_FLAG_NONE, nullptr); + auto fileHandle = Placeholders::OpenFileHandle(ctxPtr->fullClientPath.c_str(), FILE_WRITE_ATTRIBUTES, true); + CfSetPinState(fileHandle.get(), CF_PIN_STATE_PINNED, CF_SET_PIN_FLAG_NONE, nullptr); } {