Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"native-src/virtual_drive/Wrappers.cpp",
"native-src/virtual_drive/create_file_placeholder.cpp",
"native-src/virtual_drive/create_folder_placeholder.cpp",
"native-src/virtual_drive/get_file_identity.cpp",
"native-src/virtual_drive/register_sync_root.cpp"
],
"include_dirs": [
Expand Down
Binary file modified dist/addon.node
Binary file not shown.
5 changes: 5 additions & 0 deletions include/virtual_drive/get_file_identity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <node_api.h>

napi_value get_file_identity_impl(napi_env env, napi_callback_info args);
27 changes: 2 additions & 25 deletions native-src/virtual_drive/Wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "register_sync_root.h"
#include "create_folder_placeholder.h"
#include "create_file_placeholder.h"
#include "get_file_identity.h"
#include "napi_safe_wrap.h"

std::string WStringToUTF8(const std::wstring &wstr)
Expand Down Expand Up @@ -271,31 +272,7 @@ napi_value DisconnectSyncRootWrapper(napi_env env, napi_callback_info args)

napi_value GetFileIdentityWrapper(napi_env env, napi_callback_info args)
{
size_t argc = 1;
napi_value argv[1];
napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr);

if (argc < 1)
{
napi_throw_error(env, nullptr, "The path is required for GetFileIdentity");
return nullptr;
}

LPCWSTR fullPath;
size_t pathLength;
napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength);
fullPath = new WCHAR[pathLength + 1];
napi_get_value_string_utf16(env, argv[0], reinterpret_cast<char16_t *>(const_cast<wchar_t *>(fullPath)), pathLength + 1, nullptr);

std::string fileIdentity = Placeholders::GetFileIdentity(fullPath);
fileIdentity.erase(std::remove(fileIdentity.begin(), fileIdentity.end(), '\0'), fileIdentity.end());
fileIdentity.erase(std::remove(fileIdentity.begin(), fileIdentity.end(), ' '), fileIdentity.end());

napi_value jsFileIdentity;
napi_create_string_utf8(env, fileIdentity.c_str(), fileIdentity.length(), &jsFileIdentity);

delete[] fullPath;
return jsFileIdentity;
return napi_safe_wrap(env, args, get_file_identity_impl);
}

napi_value DeleteFileSyncRootWrapper(napi_env env, napi_callback_info args)
Expand Down
31 changes: 31 additions & 0 deletions native-src/virtual_drive/get_file_identity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <Windows.h>
#include "Placeholders.h"

napi_value get_file_identity_impl(napi_env env, napi_callback_info args)
{
size_t argc = 1;
napi_value argv[1];
napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr);

if (argc < 1)
{
napi_throw_error(env, nullptr, "The path is required for GetFileIdentity");
return nullptr;
}

LPCWSTR fullPath;
size_t pathLength;
napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength);
fullPath = new WCHAR[pathLength + 1];
napi_get_value_string_utf16(env, argv[0], reinterpret_cast<char16_t *>(const_cast<wchar_t *>(fullPath)), pathLength + 1, nullptr);

std::string fileIdentity = Placeholders::GetFileIdentity(fullPath);
fileIdentity.erase(std::remove(fileIdentity.begin(), fileIdentity.end(), '\0'), fileIdentity.end());
fileIdentity.erase(std::remove(fileIdentity.begin(), fileIdentity.end(), ' '), fileIdentity.end());

napi_value jsFileIdentity;
napi_create_string_utf8(env, fileIdentity.c_str(), fileIdentity.length(), &jsFileIdentity);

delete[] fullPath;
return jsFileIdentity;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@internxt/node-win",
"version": "1.0.22",
"version": "1.0.23",
"author": "Internxt <hello@internxt.com>",
"description": "Drive desktop node addon",
"main": "dist/index.js",
Expand Down