-
Notifications
You must be signed in to change notification settings - Fork 1
Improve connect and disconnect sync root #206
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
Changes from all commits
ad3a7a3
4a874c3
f199172
90bebc7
2f6a9c3
9de9b2a
ff5a19b
4154a47
a548ace
36e0bf7
3e4476a
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| [](https://deepwiki.com/internxt/node-win) | ||
| [](https://deepwiki.com/internxt/node-win) [](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [](https://sonarcloud.io/summary/new_code?id=internxt_node-win) |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,12 @@ | |
| #include "SyncRoot.h" | ||
| #include "stdafx.h" | ||
| #include <filesystem> | ||
| #include "Logger.h" | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| std::map<std::wstring, CF_CONNECTION_KEY> connectionMap; | ||
|
|
||
| HRESULT SyncRoot::ConnectSyncRoot(const wchar_t *syncRootPath, InputSyncCallbacks syncCallbacks, napi_env env, CF_CONNECTION_KEY *connectionKey) | ||
| void SyncRoot::ConnectSyncRoot(const wchar_t *syncRootPath, InputSyncCallbacks syncCallbacks, napi_env env) | ||
| { | ||
| register_threadsafe_fetch_data_callback("FetchDataThreadSafe", env, syncCallbacks); | ||
| register_threadsafe_cancel_fetch_data_callback("CancelFetchDataThreadSafe", env, syncCallbacks); | ||
|
|
@@ -18,35 +17,29 @@ HRESULT SyncRoot::ConnectSyncRoot(const wchar_t *syncRootPath, InputSyncCallback | |
| {CF_CALLBACK_TYPE_CANCEL_FETCH_DATA, cancel_fetch_data_callback_wrapper}, | ||
| CF_CALLBACK_REGISTRATION_END}; | ||
|
|
||
| CF_CONNECTION_KEY connectionKey; | ||
|
|
||
| HRESULT hr = CfConnectSyncRoot( | ||
| syncRootPath, | ||
| callbackTable, | ||
| nullptr, | ||
| CF_CONNECT_FLAG_REQUIRE_PROCESS_INFO | CF_CONNECT_FLAG_REQUIRE_FULL_FILE_PATH, | ||
| connectionKey); | ||
|
|
||
| wprintf(L"Connection key: %llu\n", connectionKey->Internal); | ||
| &connectionKey); | ||
|
|
||
| if (SUCCEEDED(hr)) | ||
| { | ||
| connectionMap[syncRootPath] = *connectionKey; | ||
| } | ||
| winrt::check_hresult(hr); | ||
|
Comment on lines
22
to
+29
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 need the variable hr?, why not do it as in previous revisions? |
||
|
|
||
| return hr; | ||
| connectionMap[syncRootPath] = connectionKey; | ||
| } | ||
|
|
||
| // disconection sync root | ||
| HRESULT SyncRoot::DisconnectSyncRoot(const wchar_t *syncRootPath) | ||
| void SyncRoot::DisconnectSyncRoot(const wchar_t *syncRootPath) | ||
| { | ||
| auto it = connectionMap.find(syncRootPath); | ||
| if (it != connectionMap.end()) | ||
| { | ||
| HRESULT hr = CfDisconnectSyncRoot(it->second); | ||
| if (SUCCEEDED(hr)) | ||
| { | ||
| connectionMap.erase(it); | ||
| } | ||
| return hr; | ||
|
|
||
| winrt::check_hresult(hr); | ||
|
Comment on lines
39
to
+41
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 need the variable hr?, why not do it as in previous revisions? |
||
|
|
||
| connectionMap.erase(it); | ||
| } | ||
| return E_FAIL; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| #include <Windows.h> | ||
| #include "SyncRoot.h" | ||
| #include <SyncRoot.h> | ||
|
|
||
| napi_value connect_sync_root_impl(napi_env env, napi_callback_info args) | ||
| { | ||
|
|
@@ -10,7 +10,7 @@ napi_value connect_sync_root_impl(napi_env env, napi_callback_info args) | |
| size_t pathLength; | ||
| napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength); | ||
| std::wstring syncRootPath(pathLength, L'\0'); | ||
| napi_get_value_string_utf16(env, argv[0], reinterpret_cast<char16_t*>(&syncRootPath[0]), pathLength + 1, nullptr); | ||
| napi_get_value_string_utf16(env, argv[0], reinterpret_cast<char16_t *>(&syncRootPath[0]), pathLength + 1, nullptr); | ||
|
|
||
| InputSyncCallbacks callbacks = {}; | ||
|
|
||
|
|
@@ -22,23 +22,7 @@ napi_value connect_sync_root_impl(napi_env env, napi_callback_info args) | |
| napi_get_named_property(env, argv[1], "cancelFetchDataCallback", &cancelFetchDataCallback); | ||
| napi_create_reference(env, cancelFetchDataCallback, 1, &callbacks.cancel_fetch_data_callback_ref); | ||
|
|
||
| CF_CONNECTION_KEY connectionKey; | ||
| HRESULT hr = SyncRoot::ConnectSyncRoot(syncRootPath.c_str(), callbacks, env, &connectionKey); | ||
| SyncRoot::ConnectSyncRoot(syncRootPath.c_str(), callbacks, env); | ||
|
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. Why is the possible error that this function may return no longer being handled? |
||
|
|
||
| if (FAILED(hr)) { | ||
| napi_throw_error(env, nullptr, "ConnectSyncRoot failed"); | ||
| return nullptr; | ||
| } | ||
|
|
||
| napi_value resultObj, hrValue, connectionKeyValue; | ||
| napi_create_object(env, &resultObj); | ||
|
|
||
| napi_create_int32(env, static_cast<int32_t>(hr), &hrValue); | ||
| napi_set_named_property(env, resultObj, "hr", hrValue); | ||
|
|
||
| std::wstring connectionKeyString = std::to_wstring(connectionKey.Internal); | ||
| napi_create_string_utf16(env, reinterpret_cast<const char16_t*>(connectionKeyString.c_str()), connectionKeyString.length(), &connectionKeyValue); | ||
| napi_set_named_property(env, resultObj, "connectionKey", connectionKeyValue); | ||
|
|
||
| return resultObj; | ||
| return nullptr; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,11 @@ | |
| #include "napi_extract_args.h" | ||
| #include "SyncRoot.h" | ||
|
|
||
| napi_value disconnect_sync_root(napi_env env, napi_callback_info info) { | ||
| napi_value disconnect_sync_root(napi_env env, napi_callback_info info) | ||
| { | ||
| auto [syncRootPath] = napi_extract_args<std::wstring>(env, info); | ||
|
|
||
| HRESULT result = SyncRoot::DisconnectSyncRoot(syncRootPath.c_str()); | ||
| SyncRoot::DisconnectSyncRoot(syncRootPath.c_str()); | ||
|
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. Is it not necessary to handle the error here? |
||
|
|
||
| return nullptr; | ||
| } | ||
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.
Why is it no longer necessary to take this error into account?