Skip to content

Commit b48cf58

Browse files
Simplify node win (#179)
* Simplify node-win * Update package.json
1 parent a05bc06 commit b48cf58

12 files changed

Lines changed: 6 additions & 289 deletions

File tree

.github/workflows/check-pr-size.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111

1212
steps:
1313
- name: Checkout code
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515
with:
1616
fetch-depth: 0
1717

.github/workflows/publish-npm.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
jobs:
88
publish_npm:
99
runs-on: ubuntu-latest
10+
timeout-minutes: 1
1011

1112
permissions:
1213
contents: read

.github/workflows/stale-prs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ permissions:
1212
jobs:
1313
stale_prs:
1414
runs-on: ubuntu-latest
15+
timeout-minutes: 1
1516

1617
steps:
1718
- uses: actions/stale@v9

binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"include/placeholders_interface",
3535
"include/sync_root_interface",
3636
"include/sync_root_interface/callbacks",
37-
"include/types",
3837
"include/virtual_drive"
3938
],
4039
"libraries": [

dist/addon.node

0 Bytes
Binary file not shown.

include/sync_root_interface/Utilities.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
#pragma once
22
#include <Windows.h>
3-
#include "ProcessTypes.h"
43
class Utilities
54
{
65
public:
76
static void AddFolderToSearchIndexer(_In_ LPCWSTR folder);
87
static void ApplyTransferStateToFile(_In_ LPCWSTR fullPath, _In_ CF_CALLBACK_INFO &callbackInfo, UINT64 total, UINT64 completed);
9-
static void ApplyCustomStateToPlaceholderFile(_In_ LPCWSTR path, _In_ LPCWSTR filename, _In_ winrt::StorageProviderItemProperty &prop);
10-
static void ApplyCustomOverwriteStateToPlaceholderFile(_In_ LPCWSTR path, _In_ LPCWSTR filename, _In_ winrt::StorageProviderItemProperty &prop);
11-
static std::wstring ProcessErrorNameToWString(_In_ ProcessErrorName error);
12-
static std::wstring FileOperationErrorToWString(_In_ FileOperationError error);
13-
static bool IsTemporaryFile(const std::wstring &fullPath);
148
static std::wstring GetErrorMessageCloudFiles(HRESULT hr);
15-
static void ClearTransferProperties(_In_ LPCWSTR fullPath);
169

1710
static winrt::com_array<wchar_t>
1811
ConvertSidToStringSid(_In_ PSID sid)
@@ -45,17 +38,6 @@ class Utilities
4538
return largeInteger;
4639
}
4740

48-
inline static CF_OPERATION_INFO ToOperationInfo(
49-
_In_ CF_CALLBACK_INFO const *info,
50-
_In_ CF_OPERATION_TYPE operationType)
51-
{
52-
return CF_OPERATION_INFO{
53-
sizeof(CF_OPERATION_INFO),
54-
operationType,
55-
info->ConnectionKey,
56-
info->TransferKey};
57-
}
58-
5941
static DWORD convertSizeToDWORD(size_t &convertVar)
6042
{
6143
if (convertVar > UINT_MAX)

include/types/ProcessTypes.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

native-src/main.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
napi_value init(napi_env env, napi_value exports)
55
{
6-
// CreatePlaceholderFileWrapper
76
napi_property_descriptor desc = {
87
"createPlaceholderFile",
98
nullptr,
@@ -21,7 +20,6 @@ napi_value init(napi_env env, napi_value exports)
2120
return nullptr;
2221
}
2322

24-
// UnregisterSyncRootWrapper
2523
napi_property_descriptor unregisterDesc = {
2624
"unregisterSyncRoot",
2725
nullptr,
@@ -39,7 +37,6 @@ napi_value init(napi_env env, napi_value exports)
3937
return nullptr;
4038
}
4139

42-
// RegisterSyncRootWrapper
4340
napi_property_descriptor registerSyncRootDesc = {
4441
"registerSyncRoot",
4542
nullptr,
@@ -57,7 +54,6 @@ napi_value init(napi_env env, napi_value exports)
5754
return nullptr;
5855
}
5956

60-
// GetRegisteredSyncRootsWrapper
6157
napi_property_descriptor getRegisteredSyncRootsRootDesc = {
6258
"getRegisteredSyncRoots",
6359
nullptr,
@@ -75,7 +71,6 @@ napi_value init(napi_env env, napi_value exports)
7571
return nullptr;
7672
}
7773

78-
// ConnectSyncRootWrapper
7974
napi_property_descriptor connectSyncRootDesc = {
8075
"connectSyncRoot",
8176
nullptr,
@@ -110,7 +105,6 @@ napi_value init(napi_env env, napi_value exports)
110105
return nullptr;
111106
}
112107

113-
// disconection
114108
napi_property_descriptor disconnectDesc = {
115109
"disconnectSyncRoot",
116110
nullptr,
@@ -247,7 +241,6 @@ napi_value init(napi_env env, napi_value exports)
247241
return nullptr;
248242
}
249243

250-
// Define HydrateFile wrapper
251244
napi_property_descriptor hydrateFileDesc = {
252245
"hydrateFile",
253246
nullptr,
@@ -265,7 +258,6 @@ napi_value init(napi_env env, napi_value exports)
265258
return nullptr;
266259
}
267260

268-
// Define DehydrateFile wrapper
269261
napi_property_descriptor dehydrateFileDesc = {
270262
"dehydrateFile",
271263
nullptr,

native-src/sync_root_interface/Utilities.cpp

Lines changed: 0 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,11 @@
33
#include <propkey.h>
44
#include <propvarutil.h>
55
#include "Utilities.h"
6-
#include <ProcessTypes.h>
76
#include <Logger.h>
87

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

12-
void Utilities::ApplyCustomStateToPlaceholderFile(LPCWSTR path, LPCWSTR filename, winrt::StorageProviderItemProperty &prop)
13-
{
14-
try
15-
{
16-
std::wstring fullPath(path);
17-
fullPath.append(L"\\");
18-
fullPath.append(filename);
19-
20-
// wprintf(L"Full path: %s\n", fullPath.c_str());
21-
winrt::IStorageItem item = winrt::StorageFile::GetFileFromPathAsync(fullPath).get();
22-
winrt::StorageProviderItemProperties::SetAsync(item, {prop}).get();
23-
}
24-
catch (const winrt::hresult_error &error)
25-
{
26-
wprintf(L"Failed to set custom state. Error: %s (Code: %08x)\n", error.message().c_str(), error.code());
27-
}
28-
catch (...)
29-
{
30-
wprintf(L"Failed to set custom state with unknown error %08x\n", static_cast<HRESULT>(winrt::to_hresult()));
31-
}
32-
}
33-
34-
void Utilities::ApplyCustomOverwriteStateToPlaceholderFile(LPCWSTR path, LPCWSTR filename, winrt::StorageProviderItemProperty &prop)
35-
{
36-
try
37-
{
38-
std::wstring fullPath(path);
39-
fullPath.append(L"\\");
40-
fullPath.append(filename);
41-
42-
// wprintf(L"Full path: %s\n", fullPath.c_str());
43-
winrt::IStorageItem item = winrt::StorageFile::GetFileFromPathAsync(fullPath).get();
44-
winrt::StorageProviderItemProperties::SetAsync(item, {}).get();
45-
winrt::StorageProviderItemProperties::SetAsync(item, {prop}).get();
46-
}
47-
catch (const winrt::hresult_error &error)
48-
{
49-
wprintf(L"Failed to set custom state. Error: %s (Code: %08x)\n", error.message().c_str(), error.code());
50-
}
51-
catch (...)
52-
{
53-
wprintf(L"Failed to set custom state with unknown error %08x\n", static_cast<HRESULT>(winrt::to_hresult()));
54-
}
55-
}
56-
5711
void Utilities::AddFolderToSearchIndexer(_In_ PCWSTR folder)
5812
{
5913
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
@@ -88,26 +42,6 @@ void Utilities::AddFolderToSearchIndexer(_In_ PCWSTR folder)
8842
}
8943
}
9044

91-
void Utilities::ClearTransferProperties(PCWSTR fullPath)
92-
{
93-
winrt::com_ptr<IShellItem2> item;
94-
winrt::com_ptr<IPropertyStore>store;
95-
96-
if (FAILED(SHCreateItemFromParsingName(fullPath, nullptr,
97-
__uuidof(item), item.put_void())))
98-
return;
99-
100-
if (FAILED(item->GetPropertyStore(GPS_READWRITE | GPS_VOLATILEPROPERTIESONLY,
101-
__uuidof(store), store.put_void())))
102-
return;
103-
104-
PROPVARIANT empty; PropVariantInit(&empty);
105-
store->SetValue(PKEY_StorageProviderTransferProgress, empty);
106-
store->SetValue(PKEY_SyncTransferStatus, empty);
107-
store->Commit();
108-
}
109-
110-
11145
void Utilities::ApplyTransferStateToFile(_In_ PCWSTR fullPath, _In_ CF_CALLBACK_INFO &callbackInfo, UINT64 total, UINT64 completed)
11246
{
11347
Logger::getInstance().log("ApplyTransferStateToFile", LogLevel::INFO);
@@ -211,78 +145,3 @@ std::wstring Utilities::GetErrorMessageCloudFiles(HRESULT hr) {
211145
LocalFree(errorMsg);
212146
return message;
213147
}
214-
215-
216-
bool Utilities::IsTemporaryFile(const std::wstring &fullPath)
217-
{
218-
size_t fileNameStart = fullPath.find_last_of(L'\\') + 1;
219-
if (fullPath.size() >= fileNameStart + 2 && fullPath.compare(fileNameStart, 2, L"~$") == 0)
220-
{
221-
return true;
222-
}
223-
224-
std::array<std::wstring, 7> tempExtensions = {
225-
L".tmp",
226-
L".laccdb",
227-
L".ldb",
228-
L".bak",
229-
L".sv$",
230-
L".psdtmp",
231-
L".~tmp"
232-
};
233-
234-
for (const auto &ext : tempExtensions)
235-
{
236-
if (fullPath.size() >= ext.size() &&
237-
fullPath.compare(fullPath.size() - ext.size(), ext.size(), ext) == 0)
238-
{
239-
return true;
240-
}
241-
}
242-
243-
return false;
244-
}
245-
246-
std::wstring Utilities::ProcessErrorNameToWString(ProcessErrorName error)
247-
{
248-
switch (error)
249-
{
250-
case ProcessErrorName::NOT_EXISTS:
251-
return L"NOT_EXISTS";
252-
case ProcessErrorName::NO_PERMISSION:
253-
return L"NO_PERMISSION";
254-
case ProcessErrorName::NO_INTERNET:
255-
return L"NO_INTERNET";
256-
case ProcessErrorName::NO_REMOTE_CONNECTION:
257-
return L"NO_REMOTE_CONNECTION";
258-
case ProcessErrorName::BAD_RESPONSE:
259-
return L"BAD_RESPONSE";
260-
case ProcessErrorName::EMPTY_FILE:
261-
return L"EMPTY_FILE";
262-
case ProcessErrorName::FILE_TOO_BIG:
263-
return L"FILE_TOO_BIG";
264-
case ProcessErrorName::UNKNOWN:
265-
return L"UNKNOWN";
266-
case ProcessErrorName::FILE_NON_EXTENSION:
267-
return L"FILE_NON_EXTENSION";
268-
default:
269-
return L"UNKNOWN";
270-
}
271-
}
272-
273-
std::wstring Utilities::FileOperationErrorToWString(FileOperationError error)
274-
{
275-
switch (error)
276-
{
277-
case FileOperationError::UPLOAD_ERROR:
278-
return L"UPLOAD_ERROR";
279-
case FileOperationError::DOWNLOAD_ERROR:
280-
return L"DOWNLOAD_ERROR";
281-
case FileOperationError::DELETE_ERROR:
282-
return L"DELETE_ERROR";
283-
case FileOperationError::METADATA_READ_ERROR:
284-
return L"METADATA_READ_ERROR";
285-
default:
286-
return L"UNKNOWN";
287-
}
288-
}

native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ void load_data()
5050
printf("load_data called");
5151
}
5252

53-
void setup_global_tsfn_fetch_data(napi_threadsafe_function tsfn)
54-
{
55-
g_fetch_data_threadsafe_callback = tsfn;
56-
}
57-
5853
napi_value create_response(napi_env env, bool finished, float progress)
5954
{
6055
napi_value result_object;
@@ -276,34 +271,6 @@ static napi_value response_callback_fn_fetch_data(napi_env env, napi_callback_in
276271
return create_response(env, ctxPtr->loadFinished, progress);
277272
}
278273

279-
static napi_value create_error_response(napi_env env)
280-
{
281-
Logger::getInstance().log("An error occurred during callback execution", LogLevel::ERROR);
282-
return create_response(env, true, 0);
283-
}
284-
285-
static void handle_cancellation(TransferContext* ctxPtr)
286-
{
287-
ctxPtr->loadFinished = true;
288-
ctxPtr->lastReadOffset = 0;
289-
{
290-
std::lock_guard<std::mutex> lock(ctxPtr->mtx);
291-
ctxPtr->ready = true;
292-
ctxPtr->cv.notify_one();
293-
}
294-
}
295-
296-
static void notify_completion(TransferContext* ctxPtr, float progress)
297-
{
298-
std::lock_guard<std::mutex> lock(ctxPtr->mtx);
299-
if (ctxPtr->loadFinished) {
300-
ctxPtr->ready = true;
301-
ctxPtr->cv.notify_one();
302-
}
303-
}
304-
305-
306-
307274
static void notify_fetch_data_call(napi_env env, napi_value js_callback, void *context, void *data)
308275
{
309276
Logger::getInstance().log("notify_fetch_data_call called context isolated", LogLevel::DEBUG);

0 commit comments

Comments
 (0)