Skip to content

Commit 4e295a3

Browse files
Commit
1 parent 432becb commit 4e295a3

File tree

5 files changed

+24
-76
lines changed

5 files changed

+24
-76
lines changed

dist/addon.node

-1 KB
Binary file not shown.

include/placeholders_interface/Placeholders.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Placeholders
88
public:
99
static void MaintainIdentity(std::wstring &fullPath, PCWSTR fileIdentity, bool isDirectory);
1010
static void ForceShellRefresh(const std::wstring &path);
11-
static void UpdateSyncStatus(const std::wstring &filePath, bool syncState, bool isDirectory);
11+
static void UpdateSyncStatus(const std::wstring &filePath, bool isDirectory);
1212
static HRESULT UpdatePinState(const std::wstring &path, const PinState state);
1313
static std::string GetFileIdentity(const std::wstring &filePath);
1414
static void UpdateFileIdentity(const std::wstring &filePath, const std::wstring &fileIdentity, bool isDirectory);

native-src/placeholders_interface/Planceholders.cpp

Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -62,76 +62,33 @@ void Placeholders::MaintainIdentity(std::wstring &fullPath, PCWSTR itemIdentity,
6262
}
6363
}
6464

65-
/**
66-
* @brief Mark a file or directory as synchronized
67-
* @param filePath path to the file or directory
68-
* @param isDirectory true if the path is a directory, false if it is a file
69-
* @return void
70-
*/
71-
void Placeholders::UpdateSyncStatus(const std::wstring &filePath,
72-
bool inputSyncState,
73-
bool isDirectory /* = false */)
65+
void Placeholders::UpdateSyncStatus(const std::wstring &path, bool isDirectory)
7466
{
75-
wprintf(L"[UpdateSyncStatus] Path: %ls\n", filePath.c_str());
76-
7767
DWORD flags = FILE_FLAG_OPEN_REPARSE_POINT;
7868
if (isDirectory)
7969
flags |= FILE_FLAG_BACKUP_SEMANTICS;
8070

81-
HANDLE h = CreateFileW(filePath.c_str(),
82-
FILE_WRITE_ATTRIBUTES,
83-
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
84-
nullptr,
85-
OPEN_EXISTING,
86-
flags,
87-
nullptr);
88-
89-
if (h == INVALID_HANDLE_VALUE)
90-
{
91-
wprintf(L"[UpdateSyncStatus] CreateFileW falló: %lu\n", GetLastError());
92-
CloseHandle(h);
93-
return;
94-
}
95-
96-
CF_IN_SYNC_STATE sync = inputSyncState ? CF_IN_SYNC_STATE_IN_SYNC
97-
: CF_IN_SYNC_STATE_NOT_IN_SYNC;
98-
99-
HRESULT hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr);
71+
winrt::file_handle fileHandle{CreateFileW(
72+
path.c_str(),
73+
FILE_WRITE_ATTRIBUTES,
74+
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
75+
nullptr,
76+
OPEN_EXISTING,
77+
flags,
78+
nullptr)};
10079

101-
if (FAILED(hr))
102-
{
103-
switch (HRESULT_CODE(hr))
104-
{
105-
case ERROR_RETRY:
106-
Sleep(50);
107-
hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr);
108-
wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n");
109-
break;
110-
111-
case ERROR_CLOUD_FILE_PROVIDER_NOT_RUNNING: // 0x1A94
112-
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, filePath.c_str(), nullptr);
113-
wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n");
114-
break;
115-
116-
case ERROR_CLOUD_FILE_NOT_IN_SYNC:
117-
convert_to_placeholder(filePath, L"temp_identity");
118-
hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr);
119-
wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n");
120-
break;
121-
122-
default:
123-
wprintf(L"[UpdateSyncStatus] CfSetInSyncState 0x%08X\n", hr);
124-
break;
125-
}
126-
}
127-
else
80+
if (!fileHandle)
12881
{
129-
wprintf(L"[UpdateSyncStatus] Estado actualizado\n");
82+
throw std::runtime_error("Failed to open item: " + std::to_string(GetLastError()));
13083
}
13184

132-
CloseHandle(h);
85+
winrt::check_hresult(CfSetInSyncState(
86+
fileHandle.get(),
87+
CF_IN_SYNC_STATE_IN_SYNC,
88+
CF_SET_IN_SYNC_FLAG_NONE,
89+
nullptr));
13390

134-
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, filePath.c_str(), nullptr);
91+
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, path.c_str(), nullptr);
13592
}
13693

13794
void Placeholders::UpdateFileIdentity(const std::wstring &filePath, const std::wstring &fileIdentity, bool isDirectory)

native-src/virtual_drive/create_folder_placeholder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ napi_value create_folder_placeholder_impl(napi_env env, napi_callback_info info)
3535

3636
winrt::check_hresult(CfCreatePlaceholders(parentPath.c_str(), &cloudEntry, 1, CF_CREATE_FLAG_NONE, NULL));
3737
// Placeholders::UpdatePinState(path, PinState::OnlineOnly);
38-
// UpdateSyncStatus(path, true, true);
38+
Placeholders::UpdateSyncStatus(path, true);
3939

4040
return nullptr;
4141
}
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
#include <windows.h>
22
#include "Placeholders.h"
3+
#include "napi_extract_args.h"
34

4-
napi_value update_sync_status_wrapper(napi_env env, napi_callback_info info) {
5-
size_t argc = 3;
6-
napi_value argv[3];
7-
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
5+
napi_value update_sync_status_wrapper(napi_env env, napi_callback_info info)
6+
{
7+
auto [path, isDirectory] = napi_extract_args<std::wstring, bool>(env, info);
88

9-
size_t pathLength;
10-
napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength);
11-
std::unique_ptr<wchar_t[]> widePath(new wchar_t[pathLength + 1]);
12-
napi_get_value_string_utf16(env, argv[0], reinterpret_cast<char16_t *>(widePath.get()), pathLength + 1, nullptr);
13-
14-
bool inputSyncState, isDirectory;
15-
napi_get_value_bool(env, argv[1], &inputSyncState);
16-
napi_get_value_bool(env, argv[2], &isDirectory);
17-
18-
Placeholders::UpdateSyncStatus(widePath.get(), inputSyncState, isDirectory);
9+
Placeholders::UpdateSyncStatus(path, isDirectory);
1910

2011
return nullptr;
2112
}

0 commit comments

Comments
 (0)