Skip to content

Commit 2c3c6b1

Browse files
Extract update sync status (#196)
* Create napi safe wrap * Extract create folder placeholder * Extract create file placeholder * Extract get file identity * Update package.json * Extract connect sync root * Extract hydrate file * Hydrate file thread safe * Improve safe wrap * Remove delete file from c++ * Extract convert to placeholder * Refactor register sync root * Extract code * Improve * Simplify providerId * Commit * Commit * Commit * Update get_registered_sync_roots.cpp * Update addon.node * Commt * Commit * Simplify unregister * Fix wrapper * Remove context * Improve napi * Template napi_extract_args * Extract dehydrate file wrapper * Refactor dehydrate file * Throw exceptions * Commit * Extract disconnect sync root * Extract get placeholder state * Remove sync state * Extract update sync status * Update publish-npm.yml * Update addon.node * Clean * Update addon.node
1 parent 37065fe commit 2c3c6b1

File tree

9 files changed

+33
-82
lines changed

9 files changed

+33
-82
lines changed

.github/workflows/publish-npm.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ jobs:
99
runs-on: ubuntu-latest
1010
timeout-minutes: 1
1111

12-
permissions:
13-
contents: read
14-
id-token: write
15-
packages: write
16-
1712
steps:
1813
- name: Checkout code
1914
uses: actions/checkout@v4

binding.gyp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"native-src/virtual_drive/hydrate_file.cpp",
4141
"native-src/virtual_drive/register_sync_root/register_sync_root.cpp",
4242
"native-src/virtual_drive/register_sync_root/register_sync_root_wrapper.cpp",
43-
"native-src/virtual_drive/unregister_sync_root_wrapper.cpp"
43+
"native-src/virtual_drive/unregister_sync_root_wrapper.cpp",
44+
"native-src/virtual_drive/update_sync_status/update_sync_status_wrapper.cpp"
4445
],
4546
"include_dirs": [
4647
"include",
@@ -52,7 +53,8 @@
5253
"include/virtual_drive",
5354
"include/virtual_drive/get_placeholder_state",
5455
"include/virtual_drive/get_registered_sync_roots",
55-
"include/virtual_drive/register_sync_root"
56+
"include/virtual_drive/register_sync_root",
57+
"include/virtual_drive/update_sync_status"
5658
],
5759
"libraries": [
5860
"-lCldApi.lib",

dist/addon.node

0 Bytes
Binary file not shown.

include/placeholders_interface/PlaceHolderInfo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,4 @@ class FileHandle
5959

6060
FileHandle handleForPath(const std::wstring &path);
6161

62-
std::string pinStateToString(PinState state);
6362
CF_PIN_STATE pinStateToCfPinState(PinState state);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include <node_api.h>
4+
5+
napi_value update_sync_status_wrapper(napi_env info, napi_callback_info args);

native-src/placeholders_interface/PlaceHolderInfo.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,6 @@ CF_PIN_STATE pinStateToCfPinState(PinState state)
4444
}
4545
}
4646

47-
std::string pinStateToString(PinState state)
48-
{
49-
switch (state)
50-
{
51-
case PinState::Inherited:
52-
return "Inherited";
53-
case PinState::AlwaysLocal:
54-
return "AlwaysLocal";
55-
case PinState::OnlineOnly:
56-
return "OnlineOnly";
57-
case PinState::Unspecified:
58-
return "Unspecified";
59-
case PinState::Excluded:
60-
return "Excluded";
61-
default:
62-
return "Unknown";
63-
}
64-
}
65-
6647
PlaceHolderInfo::PlaceHolderInfo()
6748
: _data(nullptr, [](CF_PLACEHOLDER_BASIC_INFO *) {})
6849
{

native-src/placeholders_interface/Planceholders.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -270,32 +270,6 @@ PlaceholderResult Placeholders::ConvertToPlaceholder(const std::wstring &fullPat
270270
return result;
271271
}
272272

273-
std::wstring GetErrorMessageFromHRESULT(HRESULT hr)
274-
{
275-
LPWSTR errorMessage = nullptr;
276-
DWORD result = FormatMessageW(
277-
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
278-
nullptr,
279-
hr,
280-
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
281-
reinterpret_cast<LPWSTR>(&errorMessage),
282-
0,
283-
nullptr);
284-
285-
std::wstring message;
286-
if (result > 0 && errorMessage)
287-
{
288-
message = errorMessage;
289-
LocalFree(errorMessage);
290-
}
291-
else
292-
{
293-
message = L"Error desconocido";
294-
}
295-
296-
return message;
297-
}
298-
299273
/**
300274
* @brief Mark a file or directory as synchronized
301275
* @param filePath path to the file or directory

native-src/virtual_drive/Wrappers.cpp

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "dehydrate_file.h"
2121
#include "disconnect_sync_root.h"
2222
#include "get_placeholder_state_wrapper.h"
23+
#include "update_sync_status_wrapper.h"
2324
#include "NAPI_SAFE_WRAP.h"
2425

2526
napi_value CreatePlaceholderFile(napi_env env, napi_callback_info args) {
@@ -94,35 +95,8 @@ napi_value addLoggerPathWrapper(napi_env env, napi_callback_info args)
9495
return result;
9596
}
9697

97-
napi_value UpdateSyncStatusWrapper(napi_env env, napi_callback_info args)
98-
{
99-
size_t argc = 3;
100-
napi_value argv[3];
101-
102-
napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr);
103-
if (argc < 3)
104-
{
105-
napi_throw_error(env, nullptr, "Three arguments are required for UpdateSyncStatus");
106-
return nullptr;
107-
}
108-
109-
size_t pathLength;
110-
napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength);
111-
112-
std::unique_ptr<wchar_t[]> widePath(new wchar_t[pathLength + 1]);
113-
napi_get_value_string_utf16(env, argv[0], reinterpret_cast<char16_t *>(widePath.get()), pathLength + 1, nullptr);
114-
115-
bool inputSyncState;
116-
napi_get_value_bool(env, argv[1], &inputSyncState);
117-
118-
bool isDirectory;
119-
napi_get_value_bool(env, argv[2], &isDirectory);
120-
121-
Placeholders::UpdateSyncStatus(widePath.get(), inputSyncState, isDirectory);
122-
123-
napi_value result;
124-
napi_get_boolean(env, true, &result);
125-
return result;
98+
napi_value UpdateSyncStatusWrapper(napi_env env, napi_callback_info args) {
99+
return NAPI_SAFE_WRAP(env, args, update_sync_status_wrapper);
126100
}
127101

128102
napi_value GetPlaceholderStateWrapper(napi_env env, napi_callback_info args) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <windows.h>
2+
#include "Placeholders.h"
3+
4+
napi_value update_sync_status_wrapper(napi_env env, napi_callback_info info) {
5+
size_t argc = 3;
6+
napi_value argv[3];
7+
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
8+
9+
size_t pathLength;
10+
napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength);
11+
std::unique_ptr<wchar_t[]> widePath(new wchar_t[pathLength + 1]);
12+
napi_get_value_string_utf16(env, argv[0], reinterpret_cast<char16_t *>(widePath.get()), pathLength + 1, nullptr);
13+
14+
bool inputSyncState, isDirectory;
15+
napi_get_value_bool(env, argv[1], &inputSyncState);
16+
napi_get_value_bool(env, argv[2], &isDirectory);
17+
18+
Placeholders::UpdateSyncStatus(widePath.get(), inputSyncState, isDirectory);
19+
20+
return nullptr;
21+
}

0 commit comments

Comments
 (0)