]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Fix the "plugson.tar.xz not found" error, when the path contains unicode characters.
authorlongpanda <admin@ventoy.net>
Fri, 3 Dec 2021 06:21:47 +0000 (14:21 +0800)
committerlongpanda <admin@ventoy.net>
Fri, 3 Dec 2021 06:21:47 +0000 (14:21 +0800)
Plugson/src/Core/ventoy_util.c
Plugson/src/Core/ventoy_util_linux.c
Plugson/src/Core/ventoy_util_windows.c
Plugson/src/main_windows.c
Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe

index d6ce0106a7dfb8d3550b00a0bf3ed6eb01ebebe7..2a0043393922cc00203d18ed034d615dbfb91b44 100644 (file)
@@ -80,44 +80,6 @@ uint64_t ventoy_get_human_readable_gb(uint64_t SizeBytes)
     return (uint64_t)GB;
 }
 
-int ventoy_read_file_to_buf(const char *FileName, int ExtLen, void **Bufer, int *BufLen)
-{
-    int FileSize;
-    FILE *fp = NULL;
-    void *Data = NULL;
-
-#if defined(_MSC_VER) || defined(WIN32)
-    fopen_s(&fp, FileName, "rb");
-#else
-    fp = fopen(FileName, "rb");
-#endif
-    if (fp == NULL)
-    {
-        vlog("Failed to open file %s", FileName);
-        return 1;
-    }
-
-    fseek(fp, 0, SEEK_END);
-    FileSize = (int)ftell(fp);
-
-    Data = malloc(FileSize + ExtLen);
-    if (!Data)
-    {
-        fclose(fp);
-        return 1;
-    }
-
-    fseek(fp, 0, SEEK_SET);
-    fread(Data, 1, FileSize, fp);
-
-    fclose(fp);
-
-    *Bufer = Data;
-    *BufLen = FileSize;
-
-    return 0;
-}
-
 ventoy_file * ventoy_tar_find_file(const char *path)
 {
     int i;
@@ -211,6 +173,7 @@ int ventoy_www_init(void)
 
     if (ventoy_decompress_tar(g_tar_buffer, TAR_BUF_MAX, &tarsize))
     {
+        vlog("Failed to decompress tar\n");
         return 1;
     }
 
index 69b6022f47a2da4fcada87f6577926dc33a65cab..c432f084fc6f507acf432499954bef45886cfec6 100644 (file)
@@ -292,6 +292,41 @@ void ventoy_stop_writeback_thread(void)
 }
 
 
+
+int ventoy_read_file_to_buf(const char *FileName, int ExtLen, void **Bufer, int *BufLen)
+{
+    int FileSize;
+    FILE *fp = NULL;
+    void *Data = NULL;
+
+    fp = fopen(FileName, "rb");
+    if (fp == NULL)
+    {
+        vlog("Failed to open file %s", FileName);
+        return 1;
+    }
+
+    fseek(fp, 0, SEEK_END);
+    FileSize = (int)ftell(fp);
+
+    Data = malloc(FileSize + ExtLen);
+    if (!Data)
+    {
+        fclose(fp);
+        return 1;
+    }
+
+    fseek(fp, 0, SEEK_SET);
+    fread(Data, 1, FileSize, fp);
+
+    fclose(fp);
+
+    *Bufer = Data;
+    *BufLen = FileSize;
+
+    return 0;
+}
+
 int ventoy_copy_file(const char *a, const char *b)
 {
     int len = 0;
index b65f773d3b7620819dd8fdd99251bf5c400b5aa3..1d8d97fc387c2b9189f1dc3291dee09241b6de40 100644 (file)
@@ -655,33 +655,6 @@ int CheckRuntimeEnvironment(char Letter, ventoy_disk *disk)
 }
 
 
-int ventoy_write_buf_to_file(const char *FileName, void *Bufer, int BufLen)
-{
-    BOOL bRet;
-    DWORD dwBytes;
-    HANDLE hFile;
-
-    hFile = CreateFileA(FileName, GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
-    if (hFile == INVALID_HANDLE_VALUE)
-    {
-               vlog("CreateFile %s failed %u\n", FileName, LASTERR);
-        return 1;
-    }
-
-    bRet = WriteFile(hFile, Bufer, (DWORD)BufLen, &dwBytes, NULL);
-
-    if ((!bRet) || ((DWORD)BufLen != dwBytes))
-    {
-        vlog("Failed to write file <%s> %u err:%u", FileName, dwBytes, LASTERR);
-        CloseHandle(hFile);
-        return 1;
-    }
-    
-    FlushFileBuffers(hFile);
-    CloseHandle(hFile);
-
-    return 0;
-}
 
 static volatile int g_thread_stop = 0;
 static HANDLE g_writeback_thread;
@@ -735,6 +708,85 @@ void ventoy_stop_writeback_thread(void)
     CHECK_CLOSE_HANDLE(g_writeback_event);
 }
 
+int ventoy_read_file_to_buf(const char *FileName, int ExtLen, void **Bufer, int *BufLen)
+{
+    int UTF8 = 0;
+    int Size = 0;
+    BOOL bRet;
+    DWORD dwBytes;
+    HANDLE hFile;
+    char *buffer = NULL;
+    WCHAR FilePathW[MAX_PATH];
+
+    UTF8 = IsUTF8Encode(FileName);
+    if (UTF8)
+    {
+        Utf8ToUtf16(FileName, FilePathW);
+        hFile = CreateFileW(FilePathW, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
+    }
+    else
+    {
+        hFile = CreateFileA(FileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
+    }
+
+    if (hFile == INVALID_HANDLE_VALUE)
+    {
+               vlog("Failed to open %s %u\n", FileName, LASTERR);
+        return 1;
+    }
+
+    Size = (int)GetFileSize(hFile, NULL);
+    buffer = malloc(Size + ExtLen);
+    if (!buffer)
+    {
+        vlog("Failed to alloc file buffer\n");
+        CloseHandle(hFile);
+        return 1;
+    }
+
+    bRet = ReadFile(hFile, buffer, (DWORD)Size, &dwBytes, NULL);
+    if ((!bRet) || ((DWORD)Size != dwBytes))
+    {
+        vlog("Failed to read file <%s> %u err:%u", FileName, dwBytes, LASTERR);
+        CloseHandle(hFile);
+        free(buffer);
+        return 1;
+    }
+
+    *Bufer = buffer;
+    *BufLen = Size;
+    
+    CloseHandle(hFile);
+    return 0;
+}
+
+int ventoy_write_buf_to_file(const char *FileName, void *Bufer, int BufLen)
+{
+    BOOL bRet;
+    DWORD dwBytes;
+    HANDLE hFile;
+
+    hFile = CreateFileA(FileName, GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
+    if (hFile == INVALID_HANDLE_VALUE)
+    {
+               vlog("CreateFile %s failed %u\n", FileName, LASTERR);
+        return 1;
+    }
+
+    bRet = WriteFile(hFile, Bufer, (DWORD)BufLen, &dwBytes, NULL);
+
+    if ((!bRet) || ((DWORD)BufLen != dwBytes))
+    {
+        vlog("Failed to write file <%s> %u err:%u", FileName, dwBytes, LASTERR);
+        CloseHandle(hFile);
+        return 1;
+    }
+    
+    FlushFileBuffers(hFile);
+    CloseHandle(hFile);
+
+    return 0;
+}
 
 int ventoy_copy_file(const char *a, const char *b)
 {
index 67d6ee0fa43bb77a30205b0e5cac82e4761b7298..e6a0bf47a0f361751e9dca618c4114d8e9976c94 100644 (file)
@@ -468,6 +468,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
 {\r
     int rc;\r
        HANDLE hMutex;\r
+       WCHAR CurDir[MAX_PATH];\r
 \r
     UNREFERENCED_PARAMETER(hPrevInstance);\r
 \r
@@ -489,7 +490,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
                return 1;\r
        }\r
 \r
-       GetCurrentDirectoryA(MAX_PATH, g_cur_dir);\r
+       GetCurrentDirectoryW(MAX_PATH, CurDir);\r
+       WideCharToMultiByte(CP_UTF8, 0, CurDir, -1, g_cur_dir, MAX_PATH, NULL, 0);\r
+\r
        sprintf_s(g_ventoy_dir, sizeof(g_ventoy_dir), "%s", g_cur_dir);\r
        sprintf_s(g_log_file, sizeof(g_log_file), "%s\\%s", g_cur_dir, LOG_FILE);\r
        ventoy_log_init();\r
index 7c4a7645b5b0d8b2cb6b6d88699b870a2b2d2e61..d33e7be91302dad9c42997d5826758b506e89ea0 100644 (file)
Binary files a/Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe and b/Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe differ