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 .github/workflows/check-pr-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
jobs:
publish_npm:
runs-on: ubuntu-latest
timeout-minutes: 1

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/stale-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ permissions:
jobs:
stale_prs:
runs-on: ubuntu-latest
timeout-minutes: 1

steps:
- uses: actions/stale@v9
Expand Down
1 change: 0 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"include/placeholders_interface",
"include/sync_root_interface",
"include/sync_root_interface/callbacks",
"include/types",
"include/virtual_drive"
],
"libraries": [
Expand Down
Binary file modified dist/addon.node
Binary file not shown.
18 changes: 0 additions & 18 deletions include/sync_root_interface/Utilities.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
#pragma once
#include <Windows.h>
#include "ProcessTypes.h"
class Utilities
{
public:
static void AddFolderToSearchIndexer(_In_ LPCWSTR folder);
static void ApplyTransferStateToFile(_In_ LPCWSTR fullPath, _In_ CF_CALLBACK_INFO &callbackInfo, UINT64 total, UINT64 completed);
static void ApplyCustomStateToPlaceholderFile(_In_ LPCWSTR path, _In_ LPCWSTR filename, _In_ winrt::StorageProviderItemProperty &prop);
static void ApplyCustomOverwriteStateToPlaceholderFile(_In_ LPCWSTR path, _In_ LPCWSTR filename, _In_ winrt::StorageProviderItemProperty &prop);
static std::wstring ProcessErrorNameToWString(_In_ ProcessErrorName error);
static std::wstring FileOperationErrorToWString(_In_ FileOperationError error);
static bool IsTemporaryFile(const std::wstring &fullPath);
static std::wstring GetErrorMessageCloudFiles(HRESULT hr);
static void ClearTransferProperties(_In_ LPCWSTR fullPath);

static winrt::com_array<wchar_t>
ConvertSidToStringSid(_In_ PSID sid)
Expand Down Expand Up @@ -45,17 +38,6 @@ class Utilities
return largeInteger;
}

inline static CF_OPERATION_INFO ToOperationInfo(
_In_ CF_CALLBACK_INFO const *info,
_In_ CF_OPERATION_TYPE operationType)
{
return CF_OPERATION_INFO{
sizeof(CF_OPERATION_INFO),
operationType,
info->ConnectionKey,
info->TransferKey};
}

static DWORD convertSizeToDWORD(size_t &convertVar)
{
if (convertVar > UINT_MAX)
Expand Down
22 changes: 0 additions & 22 deletions include/types/ProcessTypes.h

This file was deleted.

8 changes: 0 additions & 8 deletions native-src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

napi_value init(napi_env env, napi_value exports)
{
// CreatePlaceholderFileWrapper
napi_property_descriptor desc = {
"createPlaceholderFile",
nullptr,
Expand All @@ -21,7 +20,6 @@ napi_value init(napi_env env, napi_value exports)
return nullptr;
}

// UnregisterSyncRootWrapper
napi_property_descriptor unregisterDesc = {
"unregisterSyncRoot",
nullptr,
Expand All @@ -39,7 +37,6 @@ napi_value init(napi_env env, napi_value exports)
return nullptr;
}

// RegisterSyncRootWrapper
napi_property_descriptor registerSyncRootDesc = {
"registerSyncRoot",
nullptr,
Expand All @@ -57,7 +54,6 @@ napi_value init(napi_env env, napi_value exports)
return nullptr;
}

// GetRegisteredSyncRootsWrapper
napi_property_descriptor getRegisteredSyncRootsRootDesc = {
"getRegisteredSyncRoots",
nullptr,
Expand All @@ -75,7 +71,6 @@ napi_value init(napi_env env, napi_value exports)
return nullptr;
}

// ConnectSyncRootWrapper
napi_property_descriptor connectSyncRootDesc = {
"connectSyncRoot",
nullptr,
Expand Down Expand Up @@ -110,7 +105,6 @@ napi_value init(napi_env env, napi_value exports)
return nullptr;
}

// disconection
napi_property_descriptor disconnectDesc = {
"disconnectSyncRoot",
nullptr,
Expand Down Expand Up @@ -247,7 +241,6 @@ napi_value init(napi_env env, napi_value exports)
return nullptr;
}

// Define HydrateFile wrapper
napi_property_descriptor hydrateFileDesc = {
"hydrateFile",
nullptr,
Expand All @@ -265,7 +258,6 @@ napi_value init(napi_env env, napi_value exports)
return nullptr;
}

// Define DehydrateFile wrapper
napi_property_descriptor dehydrateFileDesc = {
"dehydrateFile",
nullptr,
Expand Down
141 changes: 0 additions & 141 deletions native-src/sync_root_interface/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,11 @@
#include <propkey.h>
#include <propvarutil.h>
#include "Utilities.h"
#include <ProcessTypes.h>
#include <Logger.h>

#define MSSEARCH_INDEX L"SystemIndex"
DEFINE_PROPERTYKEY(PKEY_StorageProviderTransferProgress, 0xE77E90DF, 0x6271, 0x4F5B, 0x83, 0x4F, 0x2D, 0xD1, 0xF2, 0x45, 0xDD, 0xA4, 4);

void Utilities::ApplyCustomStateToPlaceholderFile(LPCWSTR path, LPCWSTR filename, winrt::StorageProviderItemProperty &prop)
{
try
{
std::wstring fullPath(path);
fullPath.append(L"\\");
fullPath.append(filename);

// wprintf(L"Full path: %s\n", fullPath.c_str());
winrt::IStorageItem item = winrt::StorageFile::GetFileFromPathAsync(fullPath).get();
winrt::StorageProviderItemProperties::SetAsync(item, {prop}).get();
}
catch (const winrt::hresult_error &error)
{
wprintf(L"Failed to set custom state. Error: %s (Code: %08x)\n", error.message().c_str(), error.code());
}
catch (...)
{
wprintf(L"Failed to set custom state with unknown error %08x\n", static_cast<HRESULT>(winrt::to_hresult()));
}
}

void Utilities::ApplyCustomOverwriteStateToPlaceholderFile(LPCWSTR path, LPCWSTR filename, winrt::StorageProviderItemProperty &prop)
{
try
{
std::wstring fullPath(path);
fullPath.append(L"\\");
fullPath.append(filename);

// wprintf(L"Full path: %s\n", fullPath.c_str());
winrt::IStorageItem item = winrt::StorageFile::GetFileFromPathAsync(fullPath).get();
winrt::StorageProviderItemProperties::SetAsync(item, {}).get();
winrt::StorageProviderItemProperties::SetAsync(item, {prop}).get();
}
catch (const winrt::hresult_error &error)
{
wprintf(L"Failed to set custom state. Error: %s (Code: %08x)\n", error.message().c_str(), error.code());
}
catch (...)
{
wprintf(L"Failed to set custom state with unknown error %08x\n", static_cast<HRESULT>(winrt::to_hresult()));
}
}

void Utilities::AddFolderToSearchIndexer(_In_ PCWSTR folder)
{
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
Expand Down Expand Up @@ -88,26 +42,6 @@ void Utilities::AddFolderToSearchIndexer(_In_ PCWSTR folder)
}
}

void Utilities::ClearTransferProperties(PCWSTR fullPath)
{
winrt::com_ptr<IShellItem2> item;
winrt::com_ptr<IPropertyStore>store;

if (FAILED(SHCreateItemFromParsingName(fullPath, nullptr,
__uuidof(item), item.put_void())))
return;

if (FAILED(item->GetPropertyStore(GPS_READWRITE | GPS_VOLATILEPROPERTIESONLY,
__uuidof(store), store.put_void())))
return;

PROPVARIANT empty; PropVariantInit(&empty);
store->SetValue(PKEY_StorageProviderTransferProgress, empty);
store->SetValue(PKEY_SyncTransferStatus, empty);
store->Commit();
}


void Utilities::ApplyTransferStateToFile(_In_ PCWSTR fullPath, _In_ CF_CALLBACK_INFO &callbackInfo, UINT64 total, UINT64 completed)
{
Logger::getInstance().log("ApplyTransferStateToFile", LogLevel::INFO);
Expand Down Expand Up @@ -211,78 +145,3 @@ std::wstring Utilities::GetErrorMessageCloudFiles(HRESULT hr) {
LocalFree(errorMsg);
return message;
}


bool Utilities::IsTemporaryFile(const std::wstring &fullPath)
{
size_t fileNameStart = fullPath.find_last_of(L'\\') + 1;
if (fullPath.size() >= fileNameStart + 2 && fullPath.compare(fileNameStart, 2, L"~$") == 0)
{
return true;
}

std::array<std::wstring, 7> tempExtensions = {
L".tmp",
L".laccdb",
L".ldb",
L".bak",
L".sv$",
L".psdtmp",
L".~tmp"
};

for (const auto &ext : tempExtensions)
{
if (fullPath.size() >= ext.size() &&
fullPath.compare(fullPath.size() - ext.size(), ext.size(), ext) == 0)
{
return true;
}
}

return false;
}

std::wstring Utilities::ProcessErrorNameToWString(ProcessErrorName error)
{
switch (error)
{
case ProcessErrorName::NOT_EXISTS:
return L"NOT_EXISTS";
case ProcessErrorName::NO_PERMISSION:
return L"NO_PERMISSION";
case ProcessErrorName::NO_INTERNET:
return L"NO_INTERNET";
case ProcessErrorName::NO_REMOTE_CONNECTION:
return L"NO_REMOTE_CONNECTION";
case ProcessErrorName::BAD_RESPONSE:
return L"BAD_RESPONSE";
case ProcessErrorName::EMPTY_FILE:
return L"EMPTY_FILE";
case ProcessErrorName::FILE_TOO_BIG:
return L"FILE_TOO_BIG";
case ProcessErrorName::UNKNOWN:
return L"UNKNOWN";
case ProcessErrorName::FILE_NON_EXTENSION:
return L"FILE_NON_EXTENSION";
default:
return L"UNKNOWN";
}
}

std::wstring Utilities::FileOperationErrorToWString(FileOperationError error)
{
switch (error)
{
case FileOperationError::UPLOAD_ERROR:
return L"UPLOAD_ERROR";
case FileOperationError::DOWNLOAD_ERROR:
return L"DOWNLOAD_ERROR";
case FileOperationError::DELETE_ERROR:
return L"DELETE_ERROR";
case FileOperationError::METADATA_READ_ERROR:
return L"METADATA_READ_ERROR";
default:
return L"UNKNOWN";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ void load_data()
printf("load_data called");
}

void setup_global_tsfn_fetch_data(napi_threadsafe_function tsfn)
{
g_fetch_data_threadsafe_callback = tsfn;
}

napi_value create_response(napi_env env, bool finished, float progress)
{
napi_value result_object;
Expand Down Expand Up @@ -276,34 +271,6 @@ static napi_value response_callback_fn_fetch_data(napi_env env, napi_callback_in
return create_response(env, ctxPtr->loadFinished, progress);
}

static napi_value create_error_response(napi_env env)
{
Logger::getInstance().log("An error occurred during callback execution", LogLevel::ERROR);
return create_response(env, true, 0);
}

static void handle_cancellation(TransferContext* ctxPtr)
{
ctxPtr->loadFinished = true;
ctxPtr->lastReadOffset = 0;
{
std::lock_guard<std::mutex> lock(ctxPtr->mtx);
ctxPtr->ready = true;
ctxPtr->cv.notify_one();
}
}

static void notify_completion(TransferContext* ctxPtr, float progress)
{
std::lock_guard<std::mutex> lock(ctxPtr->mtx);
if (ctxPtr->loadFinished) {
ctxPtr->ready = true;
ctxPtr->cv.notify_one();
}
}



static void notify_fetch_data_call(napi_env env, napi_value js_callback, void *context, void *data)
{
Logger::getInstance().log("notify_fetch_data_call called context isolated", LogLevel::DEBUG);
Expand Down
Loading