Skip to content
Closed
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
5 changes: 2 additions & 3 deletions native-src/placeholders_interface/PlaceHolderInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ std::optional<BYTE> PlaceHolderInfo::FileIdentity() const
}

printf("FILE OPTIONAL: %d\n", _data->FileIdentity[0]);
return _data->FileIdentity[0]; // Devuelve el primer byte del array
return _data->FileIdentity[0];
}

void FileHandle::deletePlaceholderInfo(CF_PLACEHOLDER_BASIC_INFO *info)
Expand Down Expand Up @@ -193,7 +193,6 @@ FileHandle handleForPath(const std::wstring &wPath)
}
else
{
// Convert only for logging purposes
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::string path = converter.to_bytes(wPath);
printf("Could not CfOpenFileWithOplock for path: %s with error: %ld\n", path.c_str(), openResult);
Expand All @@ -202,7 +201,7 @@ FileHandle handleForPath(const std::wstring &wPath)
else if (std::filesystem::is_regular_file(pathFs))
{
HANDLE handle = CreateFileW(
wPath.c_str(), // Use wide string path directly
wPath.c_str(),
FILE_READ_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr,
Expand Down
35 changes: 7 additions & 28 deletions native-src/placeholders_interface/Planceholders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ void Placeholders::CreateOne(
prop.Id(1);
prop.Value(L"Value1");
prop.IconResource(L"shell32.dll,-44");

// UpdateSyncStatus(fullDestPath, true, false);
}
catch (...)
{
Expand Down Expand Up @@ -121,10 +119,6 @@ void Placeholders::MaintainIdentity(std::wstring &fullPath, PCWSTR itemIdentity,
Placeholders::UpdateFileIdentity(fullPath, itemIdentityStrW, isDirectory);
}
}
else
{
// Handle error as needed
}
}
}

Expand All @@ -140,30 +134,27 @@ void Placeholders::CreateEntry(
FILETIME lastAccessTime,
_In_ PCWSTR destPath)
{

std::wstring fullDestPath = std::wstring(destPath) + L"\\" + std::wstring(itemName);
CF_PLACEHOLDER_CREATE_INFO cloudEntry = {};
std::wstring relativeName(itemIdentity);
cloudEntry.FileIdentity = relativeName.c_str();
cloudEntry.FileIdentityLength = static_cast<DWORD>((relativeName.size() + 1) * sizeof(WCHAR));
cloudEntry.RelativeFileName = itemName;
cloudEntry.Flags = CF_PLACEHOLDER_CREATE_FLAG_DISABLE_ON_DEMAND_POPULATION; // -> desactive download on demand
cloudEntry.Flags = CF_PLACEHOLDER_CREATE_FLAG_DISABLE_ON_DEMAND_POPULATION;
cloudEntry.FsMetadata.BasicInfo.FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
cloudEntry.FsMetadata.BasicInfo.CreationTime = Utilities::FileTimeToLargeInteger(creationTime);
cloudEntry.FsMetadata.BasicInfo.LastWriteTime = Utilities::FileTimeToLargeInteger(lastWriteTime);
try
{
// TODO: si existe o es placeholder return
if (DirectoryExists(fullDestPath.c_str()))
{
Placeholders::ConvertToPlaceholder(fullDestPath, itemIdentity);
Placeholders::MaintainIdentity(fullDestPath, itemIdentity, true);
return; // No hacer nada si ya existe
return;
}

if (isDirectory) // TODO: the function createEntry is used to create only folders (directories), so this if is always true
if (isDirectory)
{
// wprintf(L"Create directory, full destination path: %ls, fullDestPath.c_str()");
PathRemoveFileSpecW(&fullDestPath[0]);
HRESULT hr = CfCreatePlaceholders(fullDestPath.c_str(), &cloudEntry, 1, CF_CREATE_FLAG_NONE, NULL);
if (FAILED(hr))
Expand Down Expand Up @@ -207,7 +198,6 @@ bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std:

if (fileHandle == INVALID_HANDLE_VALUE)
{
// Manejar el error al abrir el archivo
return false;
}

Expand All @@ -222,24 +212,21 @@ bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std:

if (FAILED(hr))
{
// Manejar el error al convertir a marcador de posición
if (hr != 0x8007017C)
{
wprintf(L"[ConvertToPlaceholder] Error converting to placeholder, ConvertToPlaceholder failed with HRESULT 0x%X\n", hr);
}

// Puedes obtener información detallada sobre el error usando FormatMessage
LPVOID errorMsg;
FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
hr,
0, // Default language
0,
(LPWSTR)&errorMsg,
0,
NULL);

// Liberar el buffer de mensaje de error
LocalFree(errorMsg);

CloseHandle(fileHandle);
Expand All @@ -248,24 +235,16 @@ bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std:

if (!isDirectory)
{
HRESULT hrPinState = CfSetPinState(fileHandle, CF_PIN_STATE_PINNED, CF_SET_PIN_FLAG_NONE, nullptr);
if (FAILED(hrPinState))
{
std::wstring errorMessage = Utilities::GetErrorMessageCloudFiles(hrPinState);
wprintf(L"[ConvertToPlaceholder] Error setting pin state, HRESULT: 0x%X\nDetails: %s\n", hrPinState, errorMessage.c_str());
CloseHandle(fileHandle);
return false;
}
Placeholders::UpdatePinState(fullPath, PinState::AlwaysLocal);
}

CloseHandle(fileHandle);
wprintf(L"[ConvertToPlaceholder] Successfully converted to placeholder: %ls\n", fullPath.c_str());
return true;
}
catch (const winrt::hresult_error &error)
catch (...)
{
// Manejar excepciones desconocidas
wprintf(L"[ConvertToPlaceholder] Unknown exception occurred\n");
wprintf(L"[ConvertToPlaceholder] Failed to convert to placeholder with %08x\n", static_cast<HRESULT>(winrt::to_hresult()));
return false;
}
}
Expand Down
12 changes: 0 additions & 12 deletions native-src/sync_root_interface/SyncRoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ void SyncRoot::HydrateFile(const wchar_t *filePath)

if (attrib & FILE_ATTRIBUTE_PINNED)
{
// if (!(attrib & FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS))
// {
Logger::getInstance().log("Hydration file init", LogLevel::INFO);

auto start = std::chrono::steady_clock::now();
Expand All @@ -68,19 +66,12 @@ void SyncRoot::HydrateFile(const wchar_t *filePath)
wprintf(L"Hydration finished %ls\n", filePath);
}
}
// }
// else
// {
// wprintf(L"File is already hydrated: %ls\n", filePath);
// Logger::getInstance().log("File is already hydrated " + Logger::fromWStringToString(filePath), LogLevel::INFO);
// }
}
}
}

void SyncRoot::DehydrateFile(const wchar_t *filePath)
{
// Logger::getInstance().log("Dehydration file init", LogLevel::INFO);
wprintf(L"Dehydration file init %ls\n", filePath);
DWORD attrib = GetFileAttributesW(filePath);
if (!(attrib & FILE_ATTRIBUTE_DIRECTORY))
Expand All @@ -94,7 +85,6 @@ void SyncRoot::DehydrateFile(const wchar_t *filePath)

if (attrib & FILE_ATTRIBUTE_UNPINNED)
{
// Logger::getInstance().log("Dehydrating file " + Logger::fromWStringToString(filePath), LogLevel::INFO);
wprintf(L"Dehydrating file starteeed %ls\n", filePath);
HRESULT hr = CfDehydratePlaceholder(placeholder.get(), offset, length, CF_DEHYDRATE_FLAG_NONE, NULL);

Expand All @@ -115,12 +105,10 @@ void SyncRoot::DehydrateFile(const wchar_t *filePath)
{
wprintf(L"Error dehydrating file %ls\n", filePath);
}
// Logger::getInstance().log("Error dehydrating file " + Logger::fromWStringToString(filePath), LogLevel::ERROR);
}
else
{
wprintf(L"Dehydration finished %ls\n", filePath);
// Logger::getInstance().log("Dehydration finished " + Logger::fromWStringToString(filePath), LogLevel::INFO);
}
}
}
Expand Down
58 changes: 4 additions & 54 deletions native-src/virtual_drive/Wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ napi_value RegisterSyncRootWrapper(napi_env env, napi_callback_info args)

HRESULT result = SyncRoot::RegisterSyncRoot(syncRootPath, providerName, providerVersion, providerId, logoPath);

delete[] syncRootPath;
delete[] providerName;
delete[] providerVersion;
delete[] providerIdStr;
delete[] logoPath;

napi_value napiResult;
napi_create_int32(env, static_cast<int32_t>(result), &napiResult);
Expand Down Expand Up @@ -837,60 +841,6 @@ napi_value HydrateFileWrapper(napi_env env, napi_callback_info args)

return promise;
}
// napi_value HydrateFileWrapper(napi_env env, napi_callback_info args) {
// size_t argc = 1;
// napi_value argv[1];
// napi_value thisArg;
// napi_get_cb_info(env, args, &argc, argv, &thisArg, nullptr);

// if (argc < 1) {
// napi_throw_type_error(env, nullptr, "The file path is required for HydrateFile");
// return nullptr;
// }

// // Obtener el argumento de JavaScript y convertirlo a una cadena de C++
// size_t pathLength;
// napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength);
// std::wstring fullPath(pathLength, L'\0');
// napi_get_value_string_utf16(env, argv[0], reinterpret_cast<char16_t *>(&fullPath[0]), pathLength + 1, nullptr);

// // Crear una promesa
// napi_deferred deferred;
// napi_value promise;
// napi_create_promise(env, &deferred, &promise);

// // Crear un handle scope para manejar la creación de objetos V8
// napi_handle_scope handleScope;
// napi_open_handle_scope(env, &handleScope);

// // Usar un bloque de manejo de V8
// {
// v8::Isolate* isolate = v8::Isolate::GetCurrent();
// v8::HandleScope scope(isolate);

// try {
// Logger::getInstance().log("init... " + Logger::fromWStringToString(fullPath.c_str()), LogLevel::INFO);
// SyncRoot::HydrateFile(fullPath.c_str());

// napi_value result;
// napi_get_undefined(env, &result);
// napi_resolve_deferred(env, deferred, result);
// } catch (const std::exception& e) {
// napi_value error;
// napi_create_string_utf8(env, e.what(), NAPI_AUTO_LENGTH, &error);
// napi_reject_deferred(env, deferred, error);
// } catch (...) {
// napi_value error;
// napi_create_string_utf8(env, "Unknown error", NAPI_AUTO_LENGTH, &error);
// napi_reject_deferred(env, deferred, error);
// }
// }

// // Cerrar el handle scope
// napi_close_handle_scope(env, handleScope);

// return promise;
// }

// Wrapper for DehydrateFile
napi_value DehydrateFileWrapper(napi_env env, napi_callback_info args)
Expand Down
Loading