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;
if (ventoy_decompress_tar(g_tar_buffer, TAR_BUF_MAX, &tarsize))
{
+ vlog("Failed to decompress tar\n");
return 1;
}
}
+
+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;
}
-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;
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)
{
{\r
int rc;\r
HANDLE hMutex;\r
+ WCHAR CurDir[MAX_PATH];\r
\r
UNREFERENCED_PARAMETER(hPrevInstance);\r
\r
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