mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-08-28 16:31:14 +00:00
VentoyPlugson update
This commit is contained in:
@@ -143,6 +143,48 @@ ventoy_file * ventoy_tar_find_file(const char *path)
|
||||
}
|
||||
|
||||
|
||||
int ventoy_decompress_tar(char *tarbuf, int buflen, int *tarsize)
|
||||
{
|
||||
int rc = 1;
|
||||
int inused = 0;
|
||||
int BufLen = 0;
|
||||
unsigned char *buffer = NULL;
|
||||
char tarxz[MAX_PATH];
|
||||
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
scnprintf(tarxz, sizeof(tarxz), "%s\\ventoy\\%s", g_ventoy_dir, PLUGSON_TXZ);
|
||||
#else
|
||||
scnprintf(tarxz, sizeof(tarxz), "%s/tool/%s", g_ventoy_dir, PLUGSON_TXZ);
|
||||
#endif
|
||||
|
||||
if (ventoy_read_file_to_buf(tarxz, 0, (void **)&buffer, &BufLen))
|
||||
{
|
||||
vlog("Failed to read file <%s>\n", tarxz);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_unxz_buffer = (unsigned char *)tarbuf;
|
||||
g_unxz_len = 0;
|
||||
|
||||
unxz(buffer, BufLen, NULL, unxz_flush, NULL, &inused, unxz_error);
|
||||
vlog("xzlen:%u rawdata size:%d\n", BufLen, g_unxz_len);
|
||||
|
||||
if (inused != BufLen)
|
||||
{
|
||||
vlog("Failed to unxz data %d %d\n", inused, BufLen);
|
||||
rc = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*tarsize = g_unxz_len;
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int ventoy_www_init(void)
|
||||
{
|
||||
int i = 0;
|
||||
|
@@ -20,6 +20,8 @@
|
||||
#ifndef __VENTOY_UTIL_H__
|
||||
#define __VENTOY_UTIL_H__
|
||||
|
||||
#define PLUGSON_TXZ "plugson.tar.xz"
|
||||
|
||||
#define check_free(p) if (p) free(p)
|
||||
#define vtoy_safe_close_fd(fd) \
|
||||
{\
|
||||
@@ -139,16 +141,6 @@ typedef struct tag_tar_head
|
||||
}VENTOY_TAR_HEAD;
|
||||
|
||||
|
||||
|
||||
typedef struct VENTOY_MAGIC
|
||||
{
|
||||
uint32_t magic1; // 0x51 0x52 0x53 0x54
|
||||
uint32_t xzlen; //
|
||||
uint32_t magic2; // 0xa1 0xa2 0xa3 0xa4
|
||||
}VENTOY_MAGIC;
|
||||
|
||||
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#define VENTOY_UP_ALIGN(N, align) (((N) + ((align) - 1)) / (align) * (align))
|
||||
|
@@ -234,42 +234,6 @@ int ventoy_write_buf_to_file(const char *FileName, void *Bufer, int BufLen)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ventoy_decompress_tar(char *tarbuf, int buflen, int *tarsize)
|
||||
{
|
||||
int rc = 1;
|
||||
int inused = 0;
|
||||
int BufLen = 0;
|
||||
unsigned char *buffer = NULL;
|
||||
char tarxz[MAX_PATH];
|
||||
|
||||
scnprintf(tarxz, sizeof(tarxz), "%s/tool/plugson.tar.xz", g_ventoy_dir);
|
||||
if (ventoy_read_file_to_buf(tarxz, 0, (void **)&buffer, &BufLen))
|
||||
{
|
||||
vlog("Failed to read file <%s>\n", tarxz);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_unxz_buffer = (unsigned char *)tarbuf;
|
||||
g_unxz_len = 0;
|
||||
|
||||
unxz(buffer, BufLen, NULL, unxz_flush, NULL, &inused, unxz_error);
|
||||
vlog("xzlen:%u rawdata size:%d\n", BufLen, g_unxz_len);
|
||||
|
||||
if (inused != BufLen)
|
||||
{
|
||||
vlog("Failed to unxz data %d %d\n", inused, BufLen);
|
||||
rc = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*tarsize = g_unxz_len;
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static volatile int g_thread_stop = 0;
|
||||
static pthread_t g_writeback_thread;
|
||||
|
@@ -683,75 +683,6 @@ int ventoy_write_buf_to_file(const char *FileName, void *Bufer, int BufLen)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ventoy_decompress_tar(char *tarbuf, int buflen, int *tarsize)
|
||||
{
|
||||
int rc = 1;
|
||||
int inused;
|
||||
HANDLE hFile;
|
||||
DWORD dwSize;
|
||||
DWORD dwRead;
|
||||
WCHAR FullPath[MAX_PATH];
|
||||
BYTE *buffer;
|
||||
VENTOY_MAGIC Magic;
|
||||
|
||||
GetModuleFileNameW(NULL, FullPath, MAX_PATH);
|
||||
hFile = CreateFileW(FullPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
vlog("Failed to open self %u\n", LASTERR);
|
||||
return 1;
|
||||
}
|
||||
|
||||
dwSize = GetFileSize(hFile, NULL);
|
||||
if (dwSize == INVALID_FILE_SIZE)
|
||||
{
|
||||
vlog("Invalid self exe size %u\n", LASTERR);
|
||||
CHECK_CLOSE_HANDLE(hFile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
buffer = malloc(dwSize);
|
||||
if (!buffer)
|
||||
{
|
||||
vlog("Failed to malloc %u\n", dwSize);
|
||||
CHECK_CLOSE_HANDLE(hFile);
|
||||
return 1;
|
||||
}
|
||||
ReadFile(hFile, buffer, dwSize, &dwRead, NULL);
|
||||
|
||||
memcpy(&Magic, buffer + dwSize - sizeof(Magic), sizeof(Magic));
|
||||
if (Magic.magic1 == 0x54535251 && Magic.magic2 == 0xa4a3a2a1)
|
||||
{
|
||||
g_unxz_buffer = (UCHAR *)tarbuf;
|
||||
g_unxz_len = 0;
|
||||
|
||||
unxz(buffer + dwSize - Magic.xzlen - sizeof(Magic), Magic.xzlen, NULL, unxz_flush, NULL, &inused, unxz_error);
|
||||
vlog("bigexe:%u xzlen:%u rawdata size:%d\n", dwSize, Magic.xzlen, g_unxz_len);
|
||||
|
||||
if (inused != Magic.xzlen)
|
||||
{
|
||||
vlog("Failed to unxz www %d\n", inused);
|
||||
rc = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*tarsize = g_unxz_len;
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vlog("Invalid magic 0x%x 0x%x\n", Magic.magic1, Magic.magic2);
|
||||
rc = 1;
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
CHECK_CLOSE_HANDLE(hFile);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
static volatile int g_thread_stop = 0;
|
||||
static HANDLE g_writeback_thread;
|
||||
static HANDLE g_writeback_event;
|
||||
|
Reference in New Issue
Block a user