diff --git a/binding.gyp b/binding.gyp index f15a4e9c..65e648e0 100644 --- a/binding.gyp +++ b/binding.gyp @@ -34,6 +34,7 @@ "native-src/virtual_drive/dehydrate_file.cpp", "native-src/virtual_drive/disconnect_sync_root.cpp", "native-src/virtual_drive/get_file_identity.cpp", + "native-src/virtual_drive/get_placeholder_state/get_placeholder_state_wrapper.cpp", "native-src/virtual_drive/get_registered_sync_roots/get_registered_sync_roots.cpp", "native-src/virtual_drive/get_registered_sync_roots/get_registered_sync_roots_wrapper.cpp", "native-src/virtual_drive/hydrate_file.cpp", @@ -49,6 +50,7 @@ "include/sync_root_interface", "include/sync_root_interface/callbacks", "include/virtual_drive", + "include/virtual_drive/get_placeholder_state", "include/virtual_drive/get_registered_sync_roots", "include/virtual_drive/register_sync_root" ], diff --git a/dist/addon.node b/dist/addon.node index cb608cc8..6154dd1c 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 index 1042cadb..28899944 100644 --- a/include/placeholders_interface/PlaceHolderInfo.h +++ b/include/placeholders_interface/PlaceHolderInfo.h @@ -3,14 +3,6 @@ #include "stdafx.h" #include -enum class SyncState -{ - /* status that occurs when an error occurs while reading the status*/ - Undefined = -1, - NotInSync = 0, - InSync = 1, -}; - enum class PinState { /* The pin state is derived from the state of the parent folder. For example new remote files start out in this state, following the state of their parent folder. This state is used purely for resetting pin states to their derived value. The effective state for an item will never be "Inherited". */ @@ -27,7 +19,6 @@ enum class PinState struct FileState { PinState pinstate; - SyncState syncstate; }; class PlaceHolderInfo @@ -43,7 +34,6 @@ class PlaceHolderInfo inline explicit operator bool() const noexcept { return static_cast(_data); } std::optional pinState() const; - std::optional syncState() const; std::optional FileId() const; std::optional FileIdentity() const; @@ -70,5 +60,4 @@ class FileHandle FileHandle handleForPath(const std::wstring &path); std::string pinStateToString(PinState state); -std::string syncStateToString(SyncState state); CF_PIN_STATE pinStateToCfPinState(PinState state); \ No newline at end of file diff --git a/include/placeholders_interface/Placeholders.h b/include/placeholders_interface/Placeholders.h index 38ad50d3..f6fb2aa8 100644 --- a/include/placeholders_interface/Placeholders.h +++ b/include/placeholders_interface/Placeholders.h @@ -3,13 +3,6 @@ #include #include -enum class PlaceholderAttribute -{ - OTHER = 0, - NOT_PINNED = 1, - PINNED = 2, -}; - struct PlaceholderResult { bool success; std::wstring errorMessage; @@ -46,7 +39,6 @@ class Placeholders static void ForceShellRefresh(const std::wstring &path); static void UpdateSyncStatus(const std::wstring &filePath, bool syncState, bool isDirectory); static HRESULT UpdatePinState(const std::wstring &path, const PinState state); - static CF_PLACEHOLDER_STATE GetPlaceholderState(const std::wstring &filePath); static PlaceholderResult ConvertToPlaceholder(const std::wstring &fullPath, const std::wstring &serverIdentity); static std::string GetFileIdentity(const std::wstring &filePath); static void UpdateFileIdentity(const std::wstring &filePath, const std::wstring &fileIdentity, bool isDirectory); diff --git a/include/virtual_drive/get_placeholder_state/get_placeholder_state_wrapper.h b/include/virtual_drive/get_placeholder_state/get_placeholder_state_wrapper.h new file mode 100644 index 00000000..63333127 --- /dev/null +++ b/include/virtual_drive/get_placeholder_state/get_placeholder_state_wrapper.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +napi_value get_placeholder_state_wrapper(napi_env env, napi_callback_info info); diff --git a/native-src/placeholders_interface/PlaceHolderInfo.cpp b/native-src/placeholders_interface/PlaceHolderInfo.cpp index a690eeb3..c9d8b019 100644 --- a/native-src/placeholders_interface/PlaceHolderInfo.cpp +++ b/native-src/placeholders_interface/PlaceHolderInfo.cpp @@ -6,32 +6,6 @@ #include #include "Logger.h" -SyncState cfSyncStateToSyncState(CF_IN_SYNC_STATE state) -{ - switch (state) - { - case CF_IN_SYNC_STATE_NOT_IN_SYNC: - return SyncState::NotInSync; - case CF_IN_SYNC_STATE_IN_SYNC: - return SyncState::InSync; - default: - return SyncState::NotInSync; - } -} - -std::string syncStateToString(SyncState state) -{ - switch (state) - { - case SyncState::NotInSync: - return "NotInSync"; - case SyncState::InSync: - return "InSync"; - default: - return "Unknown"; - } -} - PinState cfPinStateToPinState(CF_PIN_STATE state) { switch (state) @@ -109,16 +83,6 @@ std::optional PlaceHolderInfo::pinState() const return cfPinStateToPinState(_data->PinState); } -std::optional PlaceHolderInfo::syncState() const -{ - if (!_data) - { - return {}; - } - - return cfSyncStateToSyncState(_data->InSyncState); -} - std::optional PlaceHolderInfo::FileId() const { if (!_data) diff --git a/native-src/placeholders_interface/Planceholders.cpp b/native-src/placeholders_interface/Planceholders.cpp index fe1ace50..c9a63496 100644 --- a/native-src/placeholders_interface/Planceholders.cpp +++ b/native-src/placeholders_interface/Planceholders.cpp @@ -458,7 +458,6 @@ FileState Placeholders::GetPlaceholderInfo(const std::wstring &directoryPath) { printf("Error: Invalid file handle.\n"); fileState.pinstate = PinState::Unspecified; - fileState.syncstate = SyncState::Undefined; return fileState; } @@ -468,18 +467,10 @@ FileState Placeholders::GetPlaceholderInfo(const std::wstring &directoryPath) { 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()) { @@ -488,7 +479,6 @@ FileState Placeholders::GetPlaceholderInfo(const std::wstring &directoryPath) } fileState.pinstate = pinStateOpt.value_or(PinState::Unspecified); - fileState.syncstate = syncStateOpt.value_or(SyncState::Undefined); return fileState; } diff --git a/native-src/virtual_drive/Wrappers.cpp b/native-src/virtual_drive/Wrappers.cpp index 1d63e34c..fe8c3074 100644 --- a/native-src/virtual_drive/Wrappers.cpp +++ b/native-src/virtual_drive/Wrappers.cpp @@ -19,6 +19,7 @@ #include "unregister_sync_root_wrapper.h" #include "dehydrate_file.h" #include "disconnect_sync_root.h" +#include "get_placeholder_state_wrapper.h" #include "NAPI_SAFE_WRAP.h" napi_value CreatePlaceholderFile(napi_env env, napi_callback_info args) { @@ -124,40 +125,8 @@ napi_value UpdateSyncStatusWrapper(napi_env env, napi_callback_info args) return result; } -napi_value GetPlaceholderStateWrapper(napi_env env, napi_callback_info args) -{ - size_t argc = 1; - napi_value argv[1]; - - napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr); - if (argc < 1) - { - napi_throw_error(env, nullptr, "The path is required for GetPlaceholderState"); - return nullptr; - } - - size_t pathLength; - napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength); - - std::unique_ptr widePath(new wchar_t[pathLength + 1]); - - napi_get_value_string_utf16(env, argv[0], reinterpret_cast(widePath.get()), pathLength + 1, nullptr); - - // DWORD state = Placeholders::GetPlaceholderState(widePath.get()); - FileState state = Placeholders::GetPlaceholderInfo(widePath.get()); - - napi_value result; - napi_create_object(env, &result); - - napi_value jsPinState; - napi_create_int32(env, static_cast(state.pinstate), &jsPinState); - napi_set_named_property(env, result, "pinState", jsPinState); - - napi_value jsSyncState; - napi_create_int32(env, static_cast(state.syncstate), &jsSyncState); - napi_set_named_property(env, result, "syncState", jsSyncState); - - return result; +napi_value GetPlaceholderStateWrapper(napi_env env, napi_callback_info args) { + return NAPI_SAFE_WRAP(env, args, get_placeholder_state_wrapper); } napi_value ConvertToPlaceholderWrapper(napi_env env, napi_callback_info args) { diff --git a/native-src/virtual_drive/get_placeholder_state/get_placeholder_state_wrapper.cpp b/native-src/virtual_drive/get_placeholder_state/get_placeholder_state_wrapper.cpp new file mode 100644 index 00000000..032fac6c --- /dev/null +++ b/native-src/virtual_drive/get_placeholder_state/get_placeholder_state_wrapper.cpp @@ -0,0 +1,18 @@ +#include +#include "napi_extract_args.h" +#include "Placeholders.h" + +napi_value get_placeholder_state_wrapper(napi_env env, napi_callback_info info) { + auto [path] = napi_extract_args<1>(env, info); + + FileState state = Placeholders::GetPlaceholderInfo(path); + + napi_value result; + napi_create_object(env, &result); + + napi_value jsPinState; + napi_create_int32(env, static_cast(state.pinstate), &jsPinState); + napi_set_named_property(env, result, "pinState", jsPinState); + + return result; +}