Skip to content
Closed
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
Binary file modified dist/addon.node
Binary file not shown.
7 changes: 3 additions & 4 deletions native-src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iterator>
#include <node_api.h>
#include "Wrappers.h"

Expand All @@ -17,11 +18,9 @@ napi_value init(napi_env env, napi_value exports)
{"hydrateFile", nullptr, HydrateFileWrapper, nullptr, nullptr, nullptr, napi_default, nullptr},
{"dehydrateFile", nullptr, DehydrateFileWrapper, nullptr, nullptr, nullptr, napi_default, nullptr}};

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

napi_define_properties(env, exports, property_count, properties);
napi_define_properties(env, exports, std::size(properties), properties);

return exports;
}

NAPI_MODULE(NODE_GYP_MODULE_NAME, init)
NAPI_MODULE(NODE_GYP_MODULE_NAME, init)
8 changes: 3 additions & 5 deletions native-src/placeholders_interface/Planceholders.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "stdafx.h"
#include "Placeholders.h"
#include <stdafx.h>
#include <Placeholders.h>
#include <winrt/base.h>
#include <shlwapi.h>
#include <vector>
Expand All @@ -13,11 +13,9 @@
#include <cctype>
#include <windows.h>
#include <shlobj.h>
#include "convert_to_placeholder.h"
#include <convert_to_placeholder.h>
#include <check_hresult.h>

#pragma comment(lib, "shlwapi.lib")

winrt::file_handle Placeholders::OpenFileHandle(const std::wstring &path, DWORD dwDesiredAccess, bool openAsPlaceholder)
{
bool isDirectory = std::filesystem::is_directory(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ void register_threadsafe_cancel_fetch_data_callback(const std::string &resource_
napi_create_threadsafe_function(
env,
cancel_fetch_data_value,
NULL,
nullptr,
resource_name_value,
0,
1,
NULL,
NULL,
NULL,
nullptr,
nullptr,
nullptr,
notify_cancel_fetch_data_call,
&tsfn_cancel_fetch_data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#include <vector>
#include <windows.h>

napi_threadsafe_function g_fetch_data_threadsafe_callback = nullptr;

#define FIELD_SIZE(type, field) (sizeof(((type *)nullptr)->field))

#define CF_SIZE_OF_OP_PARAM(field) (FIELD_OFFSET(CF_OPERATION_PARAMETERS, field) + FIELD_SIZE(CF_OPERATION_PARAMETERS, field))

napi_threadsafe_function g_fetch_data_threadsafe_callback = nullptr;

HRESULT transfer_data(
_In_ CF_CONNECTION_KEY connectionKey,
_In_ LARGE_INTEGER transferKey,
Expand Down Expand Up @@ -177,10 +177,8 @@ void CALLBACK fetch_data_callback_wrapper(_In_ CONST CF_CALLBACK_INFO *callbackI

{
std::unique_lock<std::mutex> lock(ctx->mtx);
while (!ctx->ready)
{
ctx->cv.wait(lock);
}
ctx->cv.wait(lock, [&ctx]()
{ return ctx->ready; });
}

wprintf(L"Remove transfer context\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ struct CfTransferKeyLess
}
};

static std::map<CF_TRANSFER_KEY, std::shared_ptr<TransferContext>, CfTransferKeyLess> g_transferContextMap;

static std::mutex g_contextMapMutex;
std::map<CF_TRANSFER_KEY, std::shared_ptr<TransferContext>, CfTransferKeyLess> g_transferContextMap;
std::mutex g_contextMapMutex;

std::shared_ptr<TransferContext> CreateTransferContext(CF_TRANSFER_KEY transferKey)
{
Expand Down
2 changes: 1 addition & 1 deletion native-src/virtual_drive/create_file_placeholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ napi_value create_file_placeholder_impl(napi_env env, napi_callback_info info)

check_hresult(
"CfCreatePlaceholders",
CfCreatePlaceholders(parentPath.c_str(), &cloudEntry, 1, CF_CREATE_FLAG_NONE, NULL));
CfCreatePlaceholders(parentPath.c_str(), &cloudEntry, 1, CF_CREATE_FLAG_NONE, nullptr));

return nullptr;
}
2 changes: 1 addition & 1 deletion native-src/virtual_drive/create_folder_placeholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ napi_value create_folder_placeholder_impl(napi_env env, napi_callback_info info)

check_hresult(
"CfCreatePlaceholders",
CfCreatePlaceholders(parentPath.c_str(), &cloudEntry, 1, CF_CREATE_FLAG_NONE, NULL));
CfCreatePlaceholders(parentPath.c_str(), &cloudEntry, 1, CF_CREATE_FLAG_NONE, nullptr));

Placeholders::UpdateSyncStatus(path);

Expand Down
11 changes: 5 additions & 6 deletions native-src/virtual_drive/dehydrate_file.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#include <windows.h>
#include "napi_extract_args.h"
#include "stdafx.h"
#include "Placeholders.h"
#include <napi_extract_args.h>
#include <stdafx.h>
#include <Placeholders.h>
#include <check_hresult.h>
#include <filesystem>

napi_value dehydrate_file(napi_env env, napi_callback_info info)
{
auto [path] = napi_extract_args<std::wstring>(env, info);

DWORD attrib = GetFileAttributesW(path.c_str());

if (attrib & FILE_ATTRIBUTE_DIRECTORY)
if (std::filesystem::is_directory(path))
{
throw std::runtime_error("Cannot dehydrate folder");
}
Expand Down
14 changes: 7 additions & 7 deletions native-src/virtual_drive/hydrate_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Placeholders.h>
#include <napi_extract_args.h>
#include <check_hresult.h>
#include <filesystem>

struct AsyncWork
{
Expand All @@ -16,9 +17,7 @@ struct AsyncWork

void hydrate_file(const std::wstring &path)
{
DWORD attrib = GetFileAttributesW(path.c_str());

if (attrib & FILE_ATTRIBUTE_DIRECTORY)
if (std::filesystem::is_directory(path))
{
throw std::runtime_error("Cannot hydrate folder");
}
Expand Down Expand Up @@ -63,7 +62,7 @@ void execute_work(napi_env env, void *data)

void complete_work(napi_env env, napi_status status, void *data)
{
AsyncWork *asyncWork = static_cast<AsyncWork *>(data);
std::unique_ptr<AsyncWork> asyncWork(static_cast<AsyncWork *>(data));

if (asyncWork->success)
{
Expand All @@ -79,7 +78,6 @@ void complete_work(napi_env env, napi_status status, void *data)
}

napi_delete_async_work(env, asyncWork->work);
delete asyncWork;
}

napi_value hydrate_file_impl(napi_env env, napi_callback_info info)
Expand All @@ -90,15 +88,17 @@ napi_value hydrate_file_impl(napi_env env, napi_callback_info info)
napi_value promise;
napi_create_promise(env, &deferred, &promise);

AsyncWork *asyncWork = new AsyncWork{};
auto asyncWork = std::make_unique<AsyncWork>();
asyncWork->deferred = deferred;
asyncWork->path = std::move(path);

napi_value resourceName;
napi_create_string_utf8(env, "HydrateFileAsync", NAPI_AUTO_LENGTH, &resourceName);

napi_create_async_work(env, nullptr, resourceName, execute_work, complete_work, asyncWork, &asyncWork->work);
napi_create_async_work(env, nullptr, resourceName, execute_work, complete_work, asyncWork.get(), &asyncWork->work);
napi_queue_async_work(env, asyncWork->work);

asyncWork.release();

return promise;
}