2222napi_threadsafe_function g_fetch_data_threadsafe_callback = nullptr ;
2323
2424#define FIELD_SIZE (type, field ) (sizeof (((type *)0 )->field))
25-
26- #define CF_SIZE_OF_OP_PARAM (field ) \
27- (FIELD_OFFSET (CF_OPERATION_PARAMETERS , field) + \
28- FIELD_SIZE (CF_OPERATION_PARAMETERS , field))
25+ #define CF_SIZE_OF_OP_PARAM (field ) (FIELD_OFFSET (CF_OPERATION_PARAMETERS , field) + FIELD_SIZE (CF_OPERATION_PARAMETERS , field))
2926
3027HRESULT transfer_data (
3128 _In_ CF_CONNECTION_KEY connectionKey,
@@ -65,14 +62,10 @@ napi_value response_callback_fn_fetch_data(napi_env env, napi_callback_info info
6562 {
6663 wprintf (L" Hydration finished\n " );
6764
68- wprintf (L" 1\n " );
6965 CfSetPinState (handleForPath (ctx->path .c_str ()).get (), CF_PIN_STATE_PINNED , CF_SET_PIN_FLAG_NONE , nullptr );
70- wprintf (L" 2\n " );
7166
7267 std::lock_guard<std::mutex> lock (ctx->mtx );
73- wprintf (L" 3\n " );
7468 ctx->ready = true ;
75- wprintf (L" 4\n " );
7669 ctx->cv .notify_one ();
7770
7871 return nullptr ;
@@ -89,24 +82,11 @@ napi_value response_callback_fn_fetch_data(napi_env env, napi_callback_info info
8982 startingOffset.QuadPart = offset;
9083 chunkSize.QuadPart = length;
9184
92- HRESULT hr = transfer_data (
93- ctx->connectionKey ,
94- ctx->transferKey ,
95- data,
96- startingOffset,
97- chunkSize,
98- STATUS_SUCCESS );
85+ HRESULT hr = transfer_data (ctx->connectionKey , ctx->transferKey , data, startingOffset, chunkSize, STATUS_SUCCESS );
9986
10087 if (FAILED (hr))
10188 {
102- transfer_data (
103- ctx->connectionKey ,
104- ctx->transferKey ,
105- nullptr ,
106- ctx->requiredOffset ,
107- ctx->requiredLength ,
108- STATUS_UNSUCCESSFUL );
109-
89+ transfer_data (ctx->connectionKey , ctx->transferKey , nullptr , ctx->requiredOffset , ctx->requiredLength , STATUS_UNSUCCESSFUL );
11090 winrt::throw_hresult (hr);
11191 }
11292
@@ -128,16 +108,13 @@ void notify_fetch_data_call(napi_env env, napi_value js_callback, void *context,
128108{
129109 TransferContext *ctx = static_cast <TransferContext *>(data);
130110
131- const wchar_t *wchar_ptr = static_cast <const wchar_t *>(ctx->callbackInfo .FileIdentity );
132- DWORD fileIdentityLength = ctx->callbackInfo .FileIdentityLength / sizeof (wchar_t );
133-
134- napi_value js_fileIdentityArg;
135- napi_create_string_utf16 (env, (char16_t *)wchar_ptr, fileIdentityLength, &js_fileIdentityArg);
111+ napi_value js_path;
112+ napi_create_string_utf16 (env, (char16_t *)ctx->path .c_str (), ctx->path .length (), &js_path);
136113
137- napi_value js_response_callback_fn ;
138- napi_create_function (env, " callback" , NAPI_AUTO_LENGTH , response_callback_fn_fetch_data_wrapper, ctx, &js_response_callback_fn );
114+ napi_value js_callback ;
115+ napi_create_function (env, " callback" , NAPI_AUTO_LENGTH , response_callback_fn_fetch_data_wrapper, ctx, &js_callback );
139116
140- napi_value args_to_js_callback[2 ] = {js_fileIdentityArg, js_response_callback_fn };
117+ napi_value args_to_js_callback[2 ] = {js_path, js_callback };
141118
142119 {
143120 std::unique_lock<std::mutex> lock (ctx->mtx );
@@ -160,8 +137,6 @@ void CALLBACK fetch_data_callback_wrapper(_In_ CONST CF_CALLBACK_INFO *callbackI
160137 ctx->path = std::wstring (callbackInfo->VolumeDosName ) + callbackInfo->NormalizedPath ;
161138
162139 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 );
165140
166141 napi_call_threadsafe_function (g_fetch_data_threadsafe_callback, ctx.get (), napi_tsfn_blocking);
167142
0 commit comments