Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dadigang
Ventoy
Commits
8c18f91a
Commit
8c18f91a
authored
Dec 03, 2021
by
longpanda
Browse files
Fix the "plugson.tar.xz not found" error, when the path contains unicode characters.
parent
73fabd0c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
66 deletions
+119
-66
Plugson/src/Core/ventoy_util.c
Plugson/src/Core/ventoy_util.c
+1
-38
Plugson/src/Core/ventoy_util_linux.c
Plugson/src/Core/ventoy_util_linux.c
+35
-0
Plugson/src/Core/ventoy_util_windows.c
Plugson/src/Core/ventoy_util_windows.c
+79
-27
Plugson/src/main_windows.c
Plugson/src/main_windows.c
+4
-1
Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe
Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe
+0
-0
No files found.
Plugson/src/Core/ventoy_util.c
View file @
8c18f91a
...
...
@@ -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
;
}
...
...
Plugson/src/Core/ventoy_util_linux.c
View file @
8c18f91a
...
...
@@ -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
;
...
...
Plugson/src/Core/ventoy_util_windows.c
View file @
8c18f91a
...
...
@@ -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
)
{
...
...
Plugson/src/main_windows.c
View file @
8c18f91a
...
...
@@ -468,6 +468,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
{
int
rc
;
HANDLE
hMutex
;
WCHAR
CurDir
[
MAX_PATH
];
UNREFERENCED_PARAMETER
(
hPrevInstance
);
...
...
@@ -489,7 +490,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
return
1
;
}
GetCurrentDirectoryA
(
MAX_PATH
,
g_cur_dir
);
GetCurrentDirectoryW
(
MAX_PATH
,
CurDir
);
WideCharToMultiByte
(
CP_UTF8
,
0
,
CurDir
,
-
1
,
g_cur_dir
,
MAX_PATH
,
NULL
,
0
);
sprintf_s
(
g_ventoy_dir
,
sizeof
(
g_ventoy_dir
),
"%s"
,
g_cur_dir
);
sprintf_s
(
g_log_file
,
sizeof
(
g_log_file
),
"%s
\\
%s"
,
g_cur_dir
,
LOG_FILE
);
ventoy_log_init
();
...
...
Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe
View file @
8c18f91a
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment