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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/internxt/node-win)
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/internxt/node-win) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=internxt_node-win&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=internxt_node-win&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=internxt_node-win&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=internxt_node-win&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=internxt_node-win&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=internxt_node-win&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=internxt_node-win&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=internxt_node-win&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=internxt_node-win&metric=coverage)](https://sonarcloud.io/summary/new_code?id=internxt_node-win) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=internxt_node-win&metric=bugs)](https://sonarcloud.io/summary/new_code?id=internxt_node-win)
1 change: 0 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"native-src/logger/Logger.cpp",
"native-src/logger/LoggerPath.cpp",
"native-src/main.cpp",
"native-src/placeholders_interface/PlaceHolderInfo.cpp",
"native-src/placeholders_interface/Planceholders.cpp",
"native-src/sync_root_interface/SyncRoot.cpp",
"native-src/sync_root_interface/Utilities.cpp",
Expand Down
Binary file modified dist/addon.node
Binary file not shown.
27 changes: 0 additions & 27 deletions include/placeholders_interface/PlaceHolderInfo.h

This file was deleted.

9 changes: 8 additions & 1 deletion include/placeholders_interface/Placeholders.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#pragma once

#include <vector>
#include <string>
#include <PlaceholderInfo.h>
#include <stdafx.h>

struct FileState
{
std::string placeholderId;
CF_PIN_STATE pinState;
};

class Placeholders
{
Expand Down
11 changes: 6 additions & 5 deletions include/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
#include <cfapi.h>
#include <sddl.h>
#include <windows.h>
#include <winrt\Windows.Foundation.h>
#include <winrt\windows.foundation.collections.h>
#include <winrt\windows.storage.provider.h>
#include <winrt\Windows.Security.Cryptography.h>
#include <winrt/windows.foundation.h>
#include <winrt/windows.foundation.collections.h>
#include <winrt/windows.storage.provider.h>
#include <winrt/windows.security.cryptography.h>
#include <functional>
#include <mutex>
#include <condition_variable>
#include <node_api.h>
#include <strsafe.h>

namespace winrt {
namespace winrt
{
using namespace Windows::Foundation;
using namespace Windows::Storage;
using namespace Windows::Storage::Streams;
Expand Down
7 changes: 2 additions & 5 deletions include/sync_root_interface/SyncRoot.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
class SyncRoot
{
public:
static HRESULT ConnectSyncRoot(const wchar_t *syncRootPath, InputSyncCallbacks syncCallbacks, napi_env env, CF_CONNECTION_KEY *connectionKey);
static HRESULT DisconnectSyncRoot(const wchar_t *syncRootPath);

private:
CF_CONNECTION_KEY connectionKey;
static void ConnectSyncRoot(const wchar_t *syncRootPath, InputSyncCallbacks syncCallbacks, napi_env env);
static void DisconnectSyncRoot(const wchar_t *syncRootPath);
};
2 changes: 0 additions & 2 deletions include/sync_root_interface/callbacks/Callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

#include <CallbacksContext.h>

// Fetch Data Callback
void register_threadsafe_fetch_data_callback(const std::string &resource_name, napi_env env, InputSyncCallbacks input);
void CALLBACK fetch_data_callback_wrapper(_In_ CONST CF_CALLBACK_INFO *callbackInfo, _In_ CONST CF_CALLBACK_PARAMETERS *callbackParameters);

// Fetch Data Cancel Callback
void register_threadsafe_cancel_fetch_data_callback(const std::string &resource_name, napi_env env, InputSyncCallbacks input);
void CALLBACK cancel_fetch_data_callback_wrapper(_In_ CONST CF_CALLBACK_INFO *callbackInfo, _In_ CONST CF_CALLBACK_PARAMETERS *callbackParameters);
6 changes: 1 addition & 5 deletions native-src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ napi_value init(napi_env env, napi_value exports)

size_t property_count = sizeof(properties) / sizeof(properties[0]);

if (napi_define_properties(env, exports, property_count, properties) != napi_ok)
{
napi_throw_error(env, nullptr, "Failed to define properties");
return nullptr;
}
napi_define_properties(env, exports, property_count, properties);

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?


return exports;
}
Expand Down
88 changes: 0 additions & 88 deletions native-src/placeholders_interface/PlaceHolderInfo.cpp

This file was deleted.

1 change: 0 additions & 1 deletion native-src/placeholders_interface/Planceholders.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "stdafx.h"
#include "Placeholders.h"
#include "Logger.h"
#include "PlaceholderInfo.h"
#include <winrt/base.h>
#include <shlwapi.h>
#include <vector>
Expand Down
29 changes: 11 additions & 18 deletions native-src/sync_root_interface/SyncRoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

Choose a reason for hiding this comment

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

winrt::check_hresult(CfConnectSyncRoot(
    syncRootPath,
    callbackTable,
    nullptr,
    CF_CONNECT_FLAG_REQUIRE_PROCESS_INFO | CF_CONNECT_FLAG_REQUIRE_FULL_FILE_PATH,
    &connectionKey));


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

Choose a reason for hiding this comment

The 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?
winrt::check_hresult(CfDisconnectSyncRoot(it->second));


connectionMap.erase(it);
}
return E_FAIL;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "stdafx.h"
#include <stdafx.h>
#include <Callbacks.h>
#include <string>
#include <condition_variable>
Expand All @@ -17,6 +17,7 @@
#include <filesystem>
#include <Logger.h>
#include <TransferContext.h>
#include <Placeholders.h>

napi_threadsafe_function g_fetch_data_threadsafe_callback = nullptr;

Expand Down Expand Up @@ -213,7 +214,8 @@ static napi_value response_callback_fn_fetch_data(napi_env env, napi_callback_in

::Sleep(CHUNKDELAYMS);

CfSetPinState(handleForPath(ctxPtr->fullClientPath.c_str()).get(), CF_PIN_STATE_PINNED, CF_SET_PIN_FLAG_NONE, nullptr);
auto fileHandle = Placeholders::OpenFileHandle(ctxPtr->fullClientPath.c_str(), FILE_WRITE_ATTRIBUTES, true);
CfSetPinState(fileHandle.get(), CF_PIN_STATE_PINNED, CF_SET_PIN_FLAG_NONE, nullptr);
}

{
Expand Down
24 changes: 4 additions & 20 deletions native-src/virtual_drive/connect_sync_root.cpp
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)
{
Expand All @@ -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 = {};

Expand All @@ -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);

Choose a reason for hiding this comment

The 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;
}
3 changes: 2 additions & 1 deletion native-src/virtual_drive/dehydrate_file.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <windows.h>
#include "napi_extract_args.h"
#include "stdafx.h"
#include "Placeholders.h"

napi_value dehydrate_file(napi_env env, napi_callback_info info)
{
Expand All @@ -13,7 +14,7 @@ napi_value dehydrate_file(napi_env env, napi_callback_info info)
throw std::runtime_error("Cannot dehydrate folder");
}

winrt::handle fileHandle(CreateFileW(path.c_str(), 0, FILE_READ_DATA, nullptr, OPEN_EXISTING, 0, nullptr));
auto fileHandle = Placeholders::OpenFileHandle(path, FILE_WRITE_ATTRIBUTES, true);

LARGE_INTEGER offset;
offset.QuadPart = 0;
Expand Down
5 changes: 3 additions & 2 deletions native-src/virtual_drive/disconnect_sync_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not necessary to handle the error here?


return nullptr;
}
6 changes: 3 additions & 3 deletions native-src/virtual_drive/hydrate_file.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <thread>
#include <string>
#include <Windows.h>
#include "napi_extract_args.h"
#include "SyncRoot.h"
#include <Placeholders.h>
#include <napi_extract_args.h>

struct AsyncWork
{
Expand All @@ -22,7 +22,7 @@ void hydrate_file(const std::wstring &path)
throw std::runtime_error("Cannot hydrate folder");
}

winrt::handle fileHandle(CreateFileW(path.c_str(), 0, FILE_READ_DATA, nullptr, OPEN_EXISTING, 0, nullptr));
auto fileHandle = Placeholders::OpenFileHandle(path, FILE_WRITE_ATTRIBUTES, true);

LARGE_INTEGER offset;
offset.QuadPart = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "SyncRoot.h"
#include "stdafx.h"
#include <filesystem>
#include "Logger.h"
#include <iostream>
#include <vector>

Expand Down