diff --git a/binding.gyp b/binding.gyp index 5c2dfe91..ff2cb92a 100644 --- a/binding.gyp +++ b/binding.gyp @@ -27,6 +27,7 @@ "native-src/sync_root_interface/callbacks/FetchData/FileCopierWithProgress.cpp", "native-src/sync_root_interface/callbacks/FetchData/TransferContext.cpp", "native-src/virtual_drive/Wrappers.cpp", + "native-src/virtual_drive/create_folder_placeholder.cpp", "native-src/virtual_drive/register_sync_root.cpp" ], "include_dirs": [ diff --git a/dist/addon.node b/dist/addon.node index f5ca0bf8..976496b4 100644 Binary files a/dist/addon.node and b/dist/addon.node differ diff --git a/include/virtual_drive/create_folder_placeholder.h b/include/virtual_drive/create_folder_placeholder.h new file mode 100644 index 00000000..82bd8da5 --- /dev/null +++ b/include/virtual_drive/create_folder_placeholder.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +napi_value create_folder_placeholder_impl(napi_env env, napi_callback_info args); diff --git a/native-src/sync_root_interface/SyncRoot.cpp b/native-src/sync_root_interface/SyncRoot.cpp index fd6fefd8..16ed6027 100644 --- a/native-src/sync_root_interface/SyncRoot.cpp +++ b/native-src/sync_root_interface/SyncRoot.cpp @@ -173,8 +173,6 @@ HRESULT SyncRoot::RegisterSyncRoot(const wchar_t *syncRootPath, const wchar_t *p winrt::StorageProviderSyncRootManager::Register(info); - Sleep(1000); - return S_OK; } catch (...) diff --git a/native-src/virtual_drive/Wrappers.cpp b/native-src/virtual_drive/Wrappers.cpp index 74b642a5..2bbbf977 100644 --- a/native-src/virtual_drive/Wrappers.cpp +++ b/native-src/virtual_drive/Wrappers.cpp @@ -9,6 +9,7 @@ #include #include #include "register_sync_root.h" +#include "create_folder_placeholder.h" #include "napi_safe_wrap.h" std::string WStringToUTF8(const std::wstring &wstr) @@ -342,115 +343,7 @@ napi_value ConnectSyncRootWrapper(napi_env env, napi_callback_info args) napi_value CreateEntryWrapper(napi_env env, napi_callback_info args) { - size_t argc = 9; - napi_value argv[9]; - - napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr); - - if (argc < 9) - { - napi_throw_error(env, nullptr, "Insufficient arguments passed to CreateEntryWrapper"); - return nullptr; - } - - LPCWSTR itemName; - size_t itemNameLength; - napi_get_value_string_utf16(env, argv[0], nullptr, 0, &itemNameLength); - itemName = new WCHAR[itemNameLength + 1]; - napi_get_value_string_utf16(env, argv[0], reinterpret_cast(const_cast(itemName)), itemNameLength + 1, nullptr); - - LPCWSTR itemIdentity; - size_t itemIdentityLength; - napi_get_value_string_utf16(env, argv[1], nullptr, 0, &itemIdentityLength); - itemIdentity = new WCHAR[itemIdentityLength + 1]; - napi_get_value_string_utf16(env, argv[1], reinterpret_cast(const_cast(itemIdentity)), itemIdentityLength + 1, nullptr); - - bool isDirectory; - napi_get_value_bool(env, argv[2], &isDirectory); - - uint32_t itemSize; - napi_get_value_uint32(env, argv[3], &itemSize); - - DWORD itemIdentityLengthDword = static_cast(itemIdentityLength); - - uint32_t itemAttributes; - napi_get_value_uint32(env, argv[4], &itemAttributes); - - FILETIME creationTime, lastWriteTime, lastAccessTime; - - size_t creationTimeStringLengthFolder; - napi_get_value_string_utf16(env, argv[5], nullptr, 0, &creationTimeStringLengthFolder); - std::vector creationTimeStringBufferFolder(creationTimeStringLengthFolder + 1); - napi_get_value_string_utf16(env, argv[5], reinterpret_cast(creationTimeStringBufferFolder.data()), creationTimeStringLengthFolder + 1, nullptr); - - __int64 windowsTimeValue; - if (swscanf_s(creationTimeStringBufferFolder.data(), L"%lld", &windowsTimeValue) != 1) - { - napi_throw_error(env, nullptr, "No se pudo convertir el valor de Windows Time"); - return nullptr; - } - - creationTime.dwLowDateTime = static_cast(windowsTimeValue & 0xFFFFFFFF); - creationTime.dwHighDateTime = static_cast((windowsTimeValue >> 32) & 0xFFFFFFFF); - - size_t lastWriteTimeStringLength; - napi_get_value_string_utf16(env, argv[6], nullptr, 0, &lastWriteTimeStringLength); - std::vector lastWriteTimeStringBuffer(lastWriteTimeStringLength + 1); - napi_get_value_string_utf16(env, argv[6], reinterpret_cast(lastWriteTimeStringBuffer.data()), lastWriteTimeStringLength + 1, nullptr); - - __int64 windowsTimeValue2; - if (swscanf_s(lastWriteTimeStringBuffer.data(), L"%lld", &windowsTimeValue2) != 1) - { - napi_throw_error(env, nullptr, "No se pudo convertir el valor de Windows Time"); - return nullptr; - } - - lastWriteTime.dwLowDateTime = static_cast(windowsTimeValue2 & 0xFFFFFFFF); - lastWriteTime.dwHighDateTime = static_cast((windowsTimeValue2 >> 32) & 0xFFFFFFFF); - - lastAccessTime.dwLowDateTime = 34567890; - lastAccessTime.dwHighDateTime = 34567890; - - LPCWSTR destPath; - size_t destPathLength; - napi_get_value_string_utf16(env, argv[8], nullptr, 0, &destPathLength); - destPath = new WCHAR[destPathLength + 1]; - napi_get_value_string_utf16(env, argv[8], reinterpret_cast(const_cast(destPath)), destPathLength + 1, nullptr); - - PlaceholderResult result = Placeholders::CreateEntry( - itemName, - itemIdentity, - isDirectory, - itemSize, - itemIdentityLengthDword, - itemAttributes, - creationTime, - lastWriteTime, - lastAccessTime, - destPath); - - // Create result object - napi_value resultObj; - napi_create_object(env, &resultObj); - - // Add success property - napi_value successValue; - napi_get_boolean(env, result.success, &successValue); - napi_set_named_property(env, resultObj, "success", successValue); - - // Add errorMessage property if there is an error - if (!result.success && !result.errorMessage.empty()) - { - napi_value errorMessageValue; - napi_create_string_utf16(env, reinterpret_cast(result.errorMessage.c_str()), result.errorMessage.length(), &errorMessageValue); - napi_set_named_property(env, resultObj, "errorMessage", errorMessageValue); - } - - delete[] itemName; - delete[] itemIdentity; - delete[] destPath; - - return resultObj; + return napi_safe_wrap(env, args, create_folder_placeholder_impl); } // disconection wrapper diff --git a/native-src/virtual_drive/create_folder_placeholder.cpp b/native-src/virtual_drive/create_folder_placeholder.cpp new file mode 100644 index 00000000..ec6b975f --- /dev/null +++ b/native-src/virtual_drive/create_folder_placeholder.cpp @@ -0,0 +1,115 @@ +#include +#include "Placeholders.h" + +napi_value create_folder_placeholder_impl(napi_env env, napi_callback_info args) +{ + size_t argc = 9; + napi_value argv[9]; + + napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr); + + if (argc < 9) + { + napi_throw_error(env, nullptr, "Insufficient arguments passed to create_folder_placeholder_impl"); + return nullptr; + } + + LPCWSTR itemName; + size_t itemNameLength; + napi_get_value_string_utf16(env, argv[0], nullptr, 0, &itemNameLength); + itemName = new WCHAR[itemNameLength + 1]; + napi_get_value_string_utf16(env, argv[0], reinterpret_cast(const_cast(itemName)), itemNameLength + 1, nullptr); + + LPCWSTR itemIdentity; + size_t itemIdentityLength; + napi_get_value_string_utf16(env, argv[1], nullptr, 0, &itemIdentityLength); + itemIdentity = new WCHAR[itemIdentityLength + 1]; + napi_get_value_string_utf16(env, argv[1], reinterpret_cast(const_cast(itemIdentity)), itemIdentityLength + 1, nullptr); + + bool isDirectory; + napi_get_value_bool(env, argv[2], &isDirectory); + + uint32_t itemSize; + napi_get_value_uint32(env, argv[3], &itemSize); + + DWORD itemIdentityLengthDword = static_cast(itemIdentityLength); + + uint32_t itemAttributes; + napi_get_value_uint32(env, argv[4], &itemAttributes); + + FILETIME creationTime, lastWriteTime, lastAccessTime; + + size_t creationTimeStringLengthFolder; + napi_get_value_string_utf16(env, argv[5], nullptr, 0, &creationTimeStringLengthFolder); + std::vector creationTimeStringBufferFolder(creationTimeStringLengthFolder + 1); + napi_get_value_string_utf16(env, argv[5], reinterpret_cast(creationTimeStringBufferFolder.data()), creationTimeStringLengthFolder + 1, nullptr); + + __int64 windowsTimeValue; + if (swscanf_s(creationTimeStringBufferFolder.data(), L"%lld", &windowsTimeValue) != 1) + { + napi_throw_error(env, nullptr, "No se pudo convertir el valor de Windows Time"); + return nullptr; + } + + creationTime.dwLowDateTime = static_cast(windowsTimeValue & 0xFFFFFFFF); + creationTime.dwHighDateTime = static_cast((windowsTimeValue >> 32) & 0xFFFFFFFF); + + size_t lastWriteTimeStringLength; + napi_get_value_string_utf16(env, argv[6], nullptr, 0, &lastWriteTimeStringLength); + std::vector lastWriteTimeStringBuffer(lastWriteTimeStringLength + 1); + napi_get_value_string_utf16(env, argv[6], reinterpret_cast(lastWriteTimeStringBuffer.data()), lastWriteTimeStringLength + 1, nullptr); + + __int64 windowsTimeValue2; + if (swscanf_s(lastWriteTimeStringBuffer.data(), L"%lld", &windowsTimeValue2) != 1) + { + napi_throw_error(env, nullptr, "No se pudo convertir el valor de Windows Time"); + return nullptr; + } + + lastWriteTime.dwLowDateTime = static_cast(windowsTimeValue2 & 0xFFFFFFFF); + lastWriteTime.dwHighDateTime = static_cast((windowsTimeValue2 >> 32) & 0xFFFFFFFF); + + lastAccessTime.dwLowDateTime = 34567890; + lastAccessTime.dwHighDateTime = 34567890; + + LPCWSTR destPath; + size_t destPathLength; + napi_get_value_string_utf16(env, argv[8], nullptr, 0, &destPathLength); + destPath = new WCHAR[destPathLength + 1]; + napi_get_value_string_utf16(env, argv[8], reinterpret_cast(const_cast(destPath)), destPathLength + 1, nullptr); + + PlaceholderResult result = Placeholders::CreateEntry( + itemName, + itemIdentity, + isDirectory, + itemSize, + itemIdentityLengthDword, + itemAttributes, + creationTime, + lastWriteTime, + lastAccessTime, + destPath); + + // Create result object + napi_value resultObj; + napi_create_object(env, &resultObj); + + // Add success property + napi_value successValue; + napi_get_boolean(env, result.success, &successValue); + napi_set_named_property(env, resultObj, "success", successValue); + + // Add errorMessage property if there is an error + if (!result.success && !result.errorMessage.empty()) + { + napi_value errorMessageValue; + napi_create_string_utf16(env, reinterpret_cast(result.errorMessage.c_str()), result.errorMessage.length(), &errorMessageValue); + napi_set_named_property(env, resultObj, "errorMessage", errorMessageValue); + } + + delete[] itemName; + delete[] itemIdentity; + delete[] destPath; + + return resultObj; +} diff --git a/native-src/virtual_drive/register_sync_root.cpp b/native-src/virtual_drive/register_sync_root.cpp index 06a4b752..54e8f35e 100644 --- a/native-src/virtual_drive/register_sync_root.cpp +++ b/native-src/virtual_drive/register_sync_root.cpp @@ -1,5 +1,5 @@ #include -#include +#include "SyncRoot.h" napi_value register_sync_root_impl(napi_env env, napi_callback_info args) {