-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor register sync root #189
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
8a126f3
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,5 @@ | ||
| #pragma once | ||
|
|
||
| #include <node_api.h> | ||
|
|
||
| napi_value convert_to_placeholder_impl(napi_env env, napi_callback_info args); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #pragma once | ||
|
|
||
| #include <cfapi.h> | ||
| #include <Callbacks.h> | ||
| #include "stdafx.h" | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| void register_sync_root(const wchar_t *syncRootPath, const wchar_t *providerName, const wchar_t *providerVersion, const wchar_t *providerId, const wchar_t *logoPath); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #pragma once | ||
|
|
||
| #include <node_api.h> | ||
|
|
||
| napi_value register_sync_root_wrapper(napi_env env, napi_callback_info args); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #include <Windows.h> | ||
| #include "Placeholders.h" | ||
|
|
||
| napi_value convert_to_placeholder_impl(napi_env env, napi_callback_info args) | ||
|
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. Exact same code |
||
| { | ||
| size_t argc = 2; | ||
| napi_value argv[2]; | ||
| napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr); | ||
|
|
||
| size_t pathLen, serverIdentityLen; | ||
| napi_get_value_string_utf8(env, argv[0], nullptr, 0, &pathLen); | ||
| napi_get_value_string_utf8(env, argv[1], nullptr, 0, &serverIdentityLen); | ||
|
|
||
| std::string path(pathLen, '\0'); | ||
| std::string serverIdentity(serverIdentityLen, '\0'); | ||
|
|
||
| napi_get_value_string_utf8(env, argv[0], &path[0], pathLen + 1, nullptr); | ||
| napi_get_value_string_utf8(env, argv[1], &serverIdentity[0], serverIdentityLen + 1, nullptr); | ||
|
|
||
| std::wstring wPath(path.begin(), path.end()); | ||
| std::wstring wServerIdentity(serverIdentity.begin(), serverIdentity.end()); | ||
|
|
||
| PlaceholderResult result = Placeholders::ConvertToPlaceholder(wPath, wServerIdentity); | ||
|
|
||
| napi_value resultObj; | ||
| napi_create_object(env, &resultObj); | ||
|
|
||
| napi_value successValue; | ||
| napi_get_boolean(env, result.success, &successValue); | ||
| napi_set_named_property(env, resultObj, "success", successValue); | ||
|
|
||
| if (!result.success) | ||
| { | ||
| std::string errorMessage(result.errorMessage.begin(), result.errorMessage.end()); | ||
| napi_value errorValue; | ||
| napi_create_string_utf8(env, errorMessage.c_str(), errorMessage.length(), &errorValue); | ||
| napi_set_named_property(env, resultObj, "errorMessage", errorValue); | ||
| } | ||
|
|
||
| return resultObj; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #include "Callbacks.h" | ||
| #include "SyncRoot.h" | ||
| #include "stdafx.h" | ||
| #include <filesystem> | ||
| #include "Logger.h" | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| void register_sync_root(const wchar_t *syncRootPath, const wchar_t *providerName, const wchar_t *providerVersion, const wchar_t *providerId, const wchar_t *logoPath) | ||
|
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. This code is the same as before, but now we have removed the check that providerId is a GUID since we already sending it in that from from javascript.
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. We set the provider id, the root folder path "C:\Users\user\InternxtDrive - uuid", display name, icon, the recycle bin link and a context to filter later these sync roots. |
||
| { | ||
| winrt::StorageProviderSyncRootInfo info; | ||
| info.Id(providerId); | ||
|
|
||
| auto folder = winrt::StorageFolder::GetFolderFromPathAsync(syncRootPath).get(); | ||
| info.Path(folder); | ||
|
|
||
| info.DisplayNameResource(providerName); | ||
|
|
||
| std::wstring completeIconResource = std::wstring(logoPath) + L",0"; | ||
| info.IconResource(completeIconResource); | ||
|
|
||
| info.HydrationPolicy(winrt::StorageProviderHydrationPolicy::Full); | ||
| info.HydrationPolicyModifier(winrt::StorageProviderHydrationPolicyModifier::None); | ||
| info.PopulationPolicy(winrt::StorageProviderPopulationPolicy::AlwaysFull); | ||
| info.InSyncPolicy(winrt::StorageProviderInSyncPolicy::FileCreationTime | winrt::StorageProviderInSyncPolicy::DirectoryCreationTime); | ||
| info.Version(providerVersion); | ||
| info.ShowSiblingsAsGroup(false); | ||
| info.HardlinkPolicy(winrt::StorageProviderHardlinkPolicy::None); | ||
|
|
||
| winrt::Uri uri(L"https://drive.internxt.com/app/trash"); | ||
| info.RecycleBinUri(uri); | ||
|
|
||
| // Context | ||
| std::wstring syncRootIdentity(syncRootPath); | ||
| syncRootIdentity.append(L"#inxt#"); | ||
| syncRootIdentity.append(providerName); | ||
|
|
||
| winrt::IBuffer contextBuffer = winrt::CryptographicBuffer::ConvertStringToBinary(syncRootIdentity, winrt::BinaryStringEncoding::Utf8); | ||
| info.Context(contextBuffer); | ||
|
|
||
| winrt::StorageProviderSyncRootManager::Register(info); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #include <Windows.h> | ||
| #include "register_sync_root.h" | ||
|
|
||
| napi_value register_sync_root_wrapper(napi_env env, napi_callback_info args) | ||
|
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. This function just obtains all args taking into account memory leaks. |
||
| { | ||
| size_t argc = 5; | ||
| napi_value argv[5]; | ||
| napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr); | ||
|
|
||
| size_t syncRootPathLength; | ||
| napi_get_value_string_utf16(env, argv[0], nullptr, 0, &syncRootPathLength); | ||
| std::wstring syncRootPath(syncRootPathLength, L'\0'); | ||
| napi_get_value_string_utf16(env, argv[0], reinterpret_cast<char16_t*>(&syncRootPath[0]), syncRootPathLength + 1, nullptr); | ||
|
|
||
| size_t providerNameLength; | ||
| napi_get_value_string_utf16(env, argv[1], nullptr, 0, &providerNameLength); | ||
| std::wstring providerName(providerNameLength, L'\0'); | ||
| napi_get_value_string_utf16(env, argv[1], reinterpret_cast<char16_t*>(&providerName[0]), providerNameLength + 1, nullptr); | ||
|
|
||
| size_t providerVersionLength; | ||
| napi_get_value_string_utf16(env, argv[2], nullptr, 0, &providerVersionLength); | ||
| std::wstring providerVersion(providerVersionLength, L'\0'); | ||
| napi_get_value_string_utf16(env, argv[2], reinterpret_cast<char16_t*>(&providerVersion[0]), providerVersionLength + 1, nullptr); | ||
|
|
||
| size_t providerIdLength; | ||
| napi_get_value_string_utf16(env, argv[3], nullptr, 0, &providerIdLength); | ||
| std::wstring providerId(providerIdLength, L'\0'); | ||
| napi_get_value_string_utf16(env, argv[3], reinterpret_cast<char16_t*>(&providerId[0]), providerIdLength + 1, nullptr); | ||
|
|
||
| size_t logoPathLength; | ||
| napi_get_value_string_utf16(env, argv[4], nullptr, 0, &logoPathLength); | ||
| std::wstring logoPath(logoPathLength, L'\0'); | ||
| napi_get_value_string_utf16(env, argv[4], reinterpret_cast<char16_t*>(&logoPath[0]), logoPathLength + 1, nullptr); | ||
|
|
||
| register_sync_root(syncRootPath.c_str(), providerName.c_str(), providerVersion.c_str(), providerId.c_str(), logoPath.c_str()); | ||
|
|
||
| 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.
This was used inside the register, and technically is for defining custom columns for the placeholders. However, nothing appeared in the file explorer and base on the names "CustomStateX" and a fixed value, it seems it was something to test.