-
Notifications
You must be signed in to change notification settings - Fork 1
Extract get registered sync roots #190
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
21bd1ad
819a1f1
cc1b678
444a2d5
b5eff5e
fe31746
32c5ea9
75681d6
205f2be
9648c94
46ee84c
313dfbf
ff28084
d1a7164
70d004e
69ce991
1020526
e94646e
0601df9
73a1c9e
0c49242
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #pragma once | ||
|
|
||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| struct SyncRoots | ||
| { | ||
| std::wstring id; | ||
| std::wstring path; | ||
| std::wstring displayName; | ||
| std::wstring version; | ||
| std::wstring context; | ||
| }; | ||
|
|
||
| std::vector<SyncRoots> get_registered_sync_roots(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #pragma once | ||
|
|
||
| #include <node_api.h> | ||
|
|
||
| napi_value get_registered_sync_roots_wrapper(napi_env env, napi_callback_info args); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include "stdafx.h" | ||
| #include <filesystem> | ||
| #include <iostream> | ||
| #include <vector> | ||
| #include "get_registered_sync_roots.h" | ||
|
|
||
| std::vector<SyncRoots> get_registered_sync_roots() { | ||
| std::vector<SyncRoots> syncRootList; | ||
|
|
||
| auto syncRoots = winrt::StorageProviderSyncRootManager::GetCurrentSyncRoots(); | ||
|
|
||
| for (auto const &info : syncRoots) { | ||
| SyncRoots sr; | ||
| sr.id = info.Id(); | ||
| sr.path = info.Path().Path(); | ||
| sr.displayName = info.DisplayNameResource(); | ||
| sr.version = info.Version(); | ||
|
|
||
| auto contextBuffer = info.Context(); | ||
| if (contextBuffer) { | ||
| sr.context = winrt::CryptographicBuffer::ConvertBinaryToString(winrt::BinaryStringEncoding::Utf8, contextBuffer).c_str(); | ||
| } | ||
|
|
||
|
Contributor
Author
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. Previously here we were filtering by context using #inxt#, however now we do this filter in javascript using the displayName and the path instead. |
||
| syncRootList.push_back(sr); | ||
| } | ||
|
|
||
| return syncRootList; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include <locale> | ||
| #include <codecvt> | ||
| #include <windows.h> | ||
| #include <node_api.h> | ||
| #include "get_registered_sync_roots.h" | ||
|
|
||
| std::string WStringToUTF8(const std::wstring &wstr) { | ||
| std::wstring_convert<std::codecvt_utf8<wchar_t>> conv; | ||
| return conv.to_bytes(wstr); | ||
| } | ||
|
|
||
| void add_string_property(napi_env env, napi_value obj, const char* key, const std::wstring& value) { | ||
| std::string utf8Value = WStringToUTF8(value); | ||
| napi_value napiValue; | ||
| napi_create_string_utf8(env, utf8Value.c_str(), utf8Value.size(), &napiValue); | ||
| napi_set_named_property(env, obj, key, napiValue); | ||
| } | ||
|
|
||
| napi_value get_registered_sync_roots_wrapper(napi_env env, napi_callback_info args) { | ||
| std::vector<SyncRoots> roots = get_registered_sync_roots(); | ||
|
Contributor
Author
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. Now we just parse the sync roots obtained before to a napi vector that javascript can understand. |
||
|
|
||
| napi_value jsArray; | ||
| napi_create_array_with_length(env, roots.size(), &jsArray); | ||
|
|
||
| for (size_t i = 0; i < roots.size(); i++) { | ||
| napi_value jsObj; | ||
| napi_create_object(env, &jsObj); | ||
|
|
||
| add_string_property(env, jsObj, "id", roots[i].id); | ||
| add_string_property(env, jsObj, "path", roots[i].path); | ||
| add_string_property(env, jsObj, "displayName", roots[i].displayName); | ||
| add_string_property(env, jsObj, "version", roots[i].version); | ||
| add_string_property(env, jsObj, "context", roots[i].context); | ||
|
|
||
| napi_set_element(env, jsArray, i, jsObj); | ||
| } | ||
|
|
||
| return jsArray; | ||
| } | ||
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.
This function returns an array of SyncRoots. We obtain them from windows using
winrtand iterate them obtaining their info.