Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@
"native-src/sync_root_interface/callbacks/FetchData/TransferContext.cpp",
"native-src/virtual_drive/Wrappers.cpp",
"native-src/virtual_drive/connect_sync_root.cpp",
"native-src/virtual_drive/convert_to_placeholder.cpp",
"native-src/virtual_drive/create_file_placeholder.cpp",
"native-src/virtual_drive/create_folder_placeholder.cpp",
"native-src/virtual_drive/get_file_identity.cpp",
"native-src/virtual_drive/hydrate_file.cpp",
"native-src/virtual_drive/register_sync_root.cpp"
"native-src/virtual_drive/register_sync_root/register_sync_root.cpp",
"native-src/virtual_drive/register_sync_root/register_sync_root_wrapper.cpp"
],
"include_dirs": [
"include",
"include/logger",
"include/placeholders_interface",
"include/sync_root_interface",
"include/sync_root_interface/callbacks",
"include/virtual_drive"
"include/virtual_drive",
"include/virtual_drive/register_sync_root"
],
"libraries": [
"-lCldApi.lib",
Expand Down
Binary file modified dist/addon.node
Binary file not shown.
1 change: 0 additions & 1 deletion include/sync_root_interface/SyncRoot.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ struct ItemInfo
class SyncRoot
{
public:
static HRESULT RegisterSyncRoot(const wchar_t *syncRootPath, const wchar_t *providerName, const wchar_t *providerVersion, const GUID &providerId, const wchar_t *logoPath);
static std::vector<SyncRoots> GetRegisteredSyncRoots();
static HRESULT ConnectSyncRoot(const wchar_t *syncRootPath, InputSyncCallbacks syncCallbacks, napi_env env, CF_CONNECTION_KEY *connectionKey);
static HRESULT DisconnectSyncRoot(const wchar_t *syncRootPath);
Expand Down
5 changes: 5 additions & 0 deletions include/virtual_drive/convert_to_placeholder.h
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);
67 changes: 0 additions & 67 deletions native-src/sync_root_interface/SyncRoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ namespace fs = std::filesystem;
CF_CONNECTION_KEY gloablConnectionKey;
std::map<std::wstring, CF_CONNECTION_KEY> connectionMap;

void AddCustomState(
_In_ winrt::IVector<winrt::StorageProviderItemPropertyDefinition> &customStates,
_In_ LPCWSTR displayNameResource,
_In_ int id)
{
winrt::StorageProviderItemPropertyDefinition customState;
customState.DisplayNameResource(displayNameResource);
customState.Id(id);
customStates.Append(customState);
}

void SyncRoot::HydrateFile(const wchar_t *filePath)
{
wprintf(L"Hydration file started %ls\n", filePath);
Expand Down Expand Up @@ -115,62 +104,6 @@ void SyncRoot::DehydrateFile(const wchar_t *filePath)
}
}

HRESULT SyncRoot::RegisterSyncRoot(const wchar_t *syncRootPath, const wchar_t *providerName, const wchar_t *providerVersion, const GUID &providerId, const wchar_t *logoPath)
{
try
{
// Convert GUID to string for syncRootID
wchar_t syncRootID[39];
StringFromGUID2(providerId, syncRootID, 39);

winrt::StorageProviderSyncRootInfo info;
info.Id(syncRootID);

auto folder = winrt::StorageFolder::GetFolderFromPathAsync(syncRootPath).get();
info.Path(folder);

// The string can be in any form acceptable to SHLoadIndirectString.
info.DisplayNameResource(providerName);

std::wstring completeIconResource = std::wstring(logoPath) + L",0";

// This icon is just for the sample. You should provide your own branded icon here
info.IconResource(completeIconResource.c_str());
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.data(), winrt::BinaryStringEncoding::Utf8);
info.Context(contextBuffer);

winrt::IVector<winrt::StorageProviderItemPropertyDefinition> customStates = info.StorageProviderItemPropertyDefinitions();
AddCustomState(customStates, L"CustomStateName1", 1);
AddCustomState(customStates, L"CustomStateName2", 2);
AddCustomState(customStates, L"CustomStateName3", 3);
Copy link
Contributor Author

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.


winrt::StorageProviderSyncRootManager::Register(info);

return S_OK;
}
catch (...)
{
wprintf(L"Could not register the sync root, hr %08x\n", static_cast<HRESULT>(winrt::to_hresult()));
return E_FAIL;
}
}

std::vector<SyncRoots> SyncRoot::GetRegisteredSyncRoots()
{
std::vector<SyncRoots> syncRootList;
Expand Down
47 changes: 5 additions & 42 deletions native-src/virtual_drive/Wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include <codecvt>
#include <locale>
#include <vector>
#include "register_sync_root.h"
#include "register_sync_root_wrapper.h"
#include "create_folder_placeholder.h"
#include "create_file_placeholder.h"
#include "get_file_identity.h"
#include "connect_sync_root.h"
#include "hydrate_file.h"
#include "convert_to_placeholder.h"
#include "NAPI_SAFE_WRAP.h"

std::string WStringToUTF8(const std::wstring &wstr)
Expand Down Expand Up @@ -81,7 +82,7 @@ napi_value UnregisterSyncRootWrapper(napi_env env, napi_callback_info args)
}

napi_value RegisterSyncRootWrapper(napi_env env, napi_callback_info info) {
return NAPI_SAFE_WRAP(env, info, register_sync_root_impl);
return NAPI_SAFE_WRAP(env, info, register_sync_root_wrapper);
}

napi_value GetRegisteredSyncRootsWrapper(napi_env env, napi_callback_info args)
Expand Down Expand Up @@ -300,46 +301,8 @@ napi_value GetPlaceholderStateWrapper(napi_env env, napi_callback_info args)
return result;
}

napi_value ConvertToPlaceholderWrapper(napi_env env, napi_callback_info args)
{
size_t argc = 2;
napi_value argv[2];
napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr);

if (argc < 2)
{
napi_throw_type_error(env, nullptr, "Wrong number of arguments");
return nullptr;
}

char path[1024];
char serverIdentity[1024];
size_t pathLen, serverIdentityLen;

napi_get_value_string_utf8(env, argv[0], path, sizeof(path), &pathLen);
napi_get_value_string_utf8(env, argv[1], serverIdentity, sizeof(serverIdentity), &serverIdentityLen);

std::wstring wPath(path, path + pathLen);
std::wstring wServerIdentity(serverIdentity, serverIdentity + serverIdentityLen);

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;
napi_value ConvertToPlaceholderWrapper(napi_env env, napi_callback_info args) {
return NAPI_SAFE_WRAP(env, args, convert_to_placeholder_impl);
}

napi_value UpdateFileIdentityWrapper(napi_env env, napi_callback_info args)
Expand Down
41 changes: 41 additions & 0 deletions native-src/virtual_drive/convert_to_placeholder.cpp
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}