-
Notifications
You must be signed in to change notification settings - Fork 1
Extract create file placeholder #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
21bd1ad
Create napi safe wrap
dajimenezriv-internxt 819a1f1
Extract create folder placeholder
dajimenezriv-internxt cc1b678
Extract create file placeholder
dajimenezriv-internxt 05d94e8
Merge branch 'master' into extract-create-file-placeholder
dajimenezriv-internxt e55ab97
Update .gitattributes
dajimenezriv-internxt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| * text=auto eol=crlf | ||
| * text=auto eol=crlf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #pragma once | ||
|
|
||
| #include <node_api.h> | ||
|
|
||
| napi_value create_file_placeholder_impl(napi_env env, napi_callback_info args); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| #include <Windows.h> | ||
| #include "Placeholders.h" | ||
|
|
||
| napi_value create_file_placeholder_impl(napi_env env, napi_callback_info args) | ||
| { | ||
| size_t argc = 8; | ||
| napi_value argv[8]; | ||
|
|
||
| napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr); | ||
|
|
||
| if (argc < 8) | ||
| { | ||
| napi_throw_error(env, nullptr, "Insufficient arguments passed to create_file_placeholder_impl"); | ||
| return nullptr; | ||
| } | ||
|
|
||
| LPCWSTR fileName; | ||
| size_t fileNameLength; | ||
| napi_get_value_string_utf16(env, argv[0], nullptr, 0, &fileNameLength); | ||
| fileName = new WCHAR[fileNameLength + 1]; | ||
| napi_get_value_string_utf16(env, argv[0], reinterpret_cast<char16_t *>(const_cast<wchar_t *>(fileName)), fileNameLength + 1, nullptr); | ||
|
|
||
| size_t fileIdentityLength; | ||
| napi_get_value_string_utf16(env, argv[1], nullptr, 0, &fileIdentityLength); | ||
| wchar_t *fileIdentity = new wchar_t[fileIdentityLength + 1]; | ||
| napi_get_value_string_utf16(env, argv[1], reinterpret_cast<char16_t *>(fileIdentity), fileIdentityLength + 1, nullptr); | ||
|
|
||
| if (fileIdentityLength > CF_PLACEHOLDER_MAX_FILE_IDENTITY_LENGTH) | ||
| { | ||
| napi_throw_error(env, nullptr, "File identity is too long"); | ||
| return nullptr; | ||
| } | ||
|
|
||
| int64_t fileSize; | ||
| napi_get_value_int64(env, argv[2], &fileSize); | ||
|
|
||
| uint32_t fileAttributes; | ||
| napi_get_value_uint32(env, argv[3], &fileAttributes); | ||
|
|
||
| FILETIME creationTime, lastWriteTime, lastAccessTime; | ||
|
|
||
| size_t creationTimeStringLength; | ||
| napi_get_value_string_utf16(env, argv[4], nullptr, 0, &creationTimeStringLength); | ||
| std::vector<wchar_t> creationTimeStringBuffer(creationTimeStringLength + 1); | ||
| napi_get_value_string_utf16(env, argv[4], reinterpret_cast<char16_t *>(creationTimeStringBuffer.data()), creationTimeStringLength + 1, nullptr); | ||
|
|
||
| __int64 windowsTimeValue; | ||
| if (swscanf_s(creationTimeStringBuffer.data(), L"%lld", &windowsTimeValue) != 1) | ||
| { | ||
| napi_throw_error(env, nullptr, "No se pudo convertir el valor de Windows Time"); | ||
| return nullptr; | ||
| } | ||
|
|
||
| creationTime.dwLowDateTime = static_cast<DWORD>(windowsTimeValue & 0xFFFFFFFF); | ||
| creationTime.dwHighDateTime = static_cast<DWORD>((windowsTimeValue >> 32) & 0xFFFFFFFF); | ||
|
|
||
| size_t lastWriteTimeStringLength; | ||
| napi_get_value_string_utf16(env, argv[5], nullptr, 0, &lastWriteTimeStringLength); | ||
| std::vector<wchar_t> lastWriteTimeStringBuffer(lastWriteTimeStringLength + 1); | ||
| napi_get_value_string_utf16(env, argv[5], reinterpret_cast<char16_t *>(lastWriteTimeStringBuffer.data()), lastWriteTimeStringLength + 1, nullptr); | ||
|
|
||
| __int64 windowsTimeValue2; | ||
| if (swscanf_s(lastWriteTimeStringBuffer.data(), L"%lld", &windowsTimeValue2) != 1) | ||
| { | ||
| napi_throw_error(env, nullptr, "No se pudo convertir el valor de Windows Time"); | ||
| return nullptr; | ||
| } | ||
|
|
||
| lastWriteTime.dwLowDateTime = static_cast<DWORD>(windowsTimeValue2 & 0xFFFFFFFF); | ||
| lastWriteTime.dwHighDateTime = static_cast<DWORD>((windowsTimeValue2 >> 32) & 0xFFFFFFFF); | ||
|
|
||
| lastAccessTime.dwLowDateTime = 34567890; | ||
| lastAccessTime.dwHighDateTime = 78901234; | ||
|
|
||
| LPCWSTR destPath; | ||
| size_t destPathLength; | ||
| napi_get_value_string_utf16(env, argv[7], nullptr, 0, &destPathLength); | ||
| destPath = new WCHAR[destPathLength + 1]; | ||
| napi_get_value_string_utf16(env, argv[7], reinterpret_cast<char16_t *>(const_cast<wchar_t *>(destPath)), destPathLength + 1, nullptr); | ||
|
|
||
| PlaceholderResult result = Placeholders::CreateOne( | ||
| fileName, | ||
| fileIdentity, | ||
| fileSize, | ||
| fileIdentityLength, | ||
| fileAttributes, | ||
| creationTime, | ||
| lastWriteTime, | ||
| lastAccessTime, | ||
| destPath); | ||
|
|
||
| // Create result object | ||
| napi_value resultObj; | ||
| napi_create_object(env, &resultObj); | ||
|
|
||
| // Add success property | ||
| napi_value successValue; | ||
| napi_get_boolean(env, result.success, &successValue); | ||
| napi_set_named_property(env, resultObj, "success", successValue); | ||
|
|
||
| // Add errorMessage property if there is an error | ||
| if (!result.success && !result.errorMessage.empty()) | ||
| { | ||
| napi_value errorMessageValue; | ||
| napi_create_string_utf16(env, reinterpret_cast<const char16_t*>(result.errorMessage.c_str()), result.errorMessage.length(), &errorMessageValue); | ||
| napi_set_named_property(env, resultObj, "errorMessage", errorMessageValue); | ||
| } | ||
|
|
||
| delete[] fileName; | ||
| delete[] fileIdentity; | ||
| delete[] destPath; | ||
|
|
||
| return resultObj; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything removed from here should be the same in
create_file_placeholder.cpp.