Skip to content

Commit 5cde01c

Browse files
Commit
1 parent 511a255 commit 5cde01c

3 files changed

Lines changed: 16 additions & 36 deletions

File tree

dist/addon.node

-512 Bytes
Binary file not shown.

include/sync_root_interface/TransferContext.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,13 @@ struct TransferContext
2020
LARGE_INTEGER requiredLength;
2121
LARGE_INTEGER requiredOffset;
2222
std::wstring path;
23-
std::wstring tmpPath;
2423

25-
size_t lastReadOffset = 0;
26-
size_t lastSize = 0;
27-
bool loadFinished = false;
2824
bool ready = false;
2925

3026
std::mutex mtx;
3127
std::condition_variable cv;
3228
};
3329

34-
std::shared_ptr<TransferContext> GetOrCreateTransferContext(
35-
CF_CONNECTION_KEY connKey,
36-
CF_TRANSFER_KEY transferKey);
30+
std::shared_ptr<TransferContext> GetOrCreateTransferContext(CF_CONNECTION_KEY connKey, CF_TRANSFER_KEY transferKey);
3731

3832
void RemoveTransferContext(CF_TRANSFER_KEY transferKey);

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

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ napi_threadsafe_function g_fetch_data_threadsafe_callback = nullptr;
2727
(FIELD_OFFSET(CF_OPERATION_PARAMETERS, field) + \
2828
FIELD_SIZE(CF_OPERATION_PARAMETERS, field))
2929

30-
napi_value create_response(napi_env env, bool finished)
31-
{
32-
napi_value result;
33-
napi_get_boolean(env, finished, &result);
34-
return result;
35-
}
36-
3730
HRESULT transfer_data(
3831
_In_ CF_CONNECTION_KEY connectionKey,
3932
_In_ LARGE_INTEGER transferKey,
@@ -60,8 +53,6 @@ HRESULT transfer_data(
6053

6154
napi_value response_callback_fn_fetch_data(napi_env env, napi_callback_info info)
6255
{
63-
wprintf(L"Function response_callback_fn_fetch_data called\n");
64-
6556
size_t argc = 3;
6657
napi_value args[3];
6758
TransferContext *ctx = nullptr;
@@ -72,16 +63,19 @@ napi_value response_callback_fn_fetch_data(napi_env env, napi_callback_info info
7263

7364
if (finished)
7465
{
75-
wprintf(L"Canceling hydration\n");
66+
wprintf(L"Hydration finished\n");
7667

77-
ctx->loadFinished = true;
78-
ctx->lastReadOffset = 0;
68+
wprintf(L"1\n");
69+
CfSetPinState(handleForPath(ctx->path.c_str()).get(), CF_PIN_STATE_PINNED, CF_SET_PIN_FLAG_NONE, nullptr);
70+
wprintf(L"2\n");
7971

8072
std::lock_guard<std::mutex> lock(ctx->mtx);
73+
wprintf(L"3\n");
8174
ctx->ready = true;
75+
wprintf(L"4\n");
8276
ctx->cv.notify_one();
8377

84-
return create_response(env, true);
78+
return nullptr;
8579
}
8680

8781
void *data;
@@ -116,25 +110,13 @@ napi_value response_callback_fn_fetch_data(napi_env env, napi_callback_info info
116110
winrt::throw_hresult(hr);
117111
}
118112

119-
ctx->lastReadOffset = offset + length;
113+
size_t completed = offset + length;
120114

121-
UINT64 totalSize = static_cast<UINT64>(ctx->fileSize.QuadPart);
122-
Utilities::ApplyTransferStateToFile(ctx->path, ctx->callbackInfo, totalSize, ctx->lastReadOffset);
115+
Utilities::ApplyTransferStateToFile(ctx->path, ctx->callbackInfo, ctx->fileSize.QuadPart, completed);
123116

124-
if (finished)
125-
{
126-
ctx->loadFinished = true;
127-
Utilities::ApplyTransferStateToFile(ctx->path, ctx->callbackInfo, ctx->fileSize.QuadPart, ctx->fileSize.QuadPart);
128-
CfSetPinState(handleForPath(ctx->path.c_str()).get(), CF_PIN_STATE_PINNED, CF_SET_PIN_FLAG_NONE, nullptr);
117+
wprintf(L"Bytes completed: %d bytes\n", completed);
129118

130-
std::lock_guard<std::mutex> lock(ctx->mtx);
131-
ctx->ready = true;
132-
ctx->cv.notify_one();
133-
}
134-
135-
wprintf(L"Chunk transferred, finished: %d\n", finished);
136-
137-
return create_response(env, finished);
119+
return nullptr;
138120
}
139121

140122
napi_value response_callback_fn_fetch_data_wrapper(napi_env env, napi_callback_info info)
@@ -177,6 +159,10 @@ void CALLBACK fetch_data_callback_wrapper(_In_ CONST CF_CALLBACK_INFO *callbackI
177159
ctx->callbackInfo = *callbackInfo;
178160
ctx->path = std::wstring(callbackInfo->VolumeDosName) + callbackInfo->NormalizedPath;
179161

162+
wprintf(L"Download path: %s\n", ctx->path.c_str());
163+
wprintf(L"Required length: %d\n", ctx->requiredLength.QuadPart);
164+
wprintf(L"Required offset: %d\n", ctx->requiredOffset.QuadPart);
165+
180166
napi_call_threadsafe_function(g_fetch_data_threadsafe_callback, ctx.get(), napi_tsfn_blocking);
181167

182168
{

0 commit comments

Comments
 (0)