mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-08-28 16:31:14 +00:00
VentoyPlugson Update:
1. Add preview json feature 2. Add reset button 3. Add configuration active identifier for each tab 4. Bug fix
This commit is contained in:
@@ -311,12 +311,24 @@ uint64_t ventoy_get_disk_size_in_byte(const char *disk)
|
||||
|
||||
int ventoy_get_disk_vendor(const char *name, char *vendorbuf, int bufsize)
|
||||
{
|
||||
return ventoy_get_sys_file_line(vendorbuf, bufsize, "/sys/block/%s/device/vendor", name);
|
||||
if (strncmp(name, "loop", 4) == 0)
|
||||
{
|
||||
scnprintf(vendorbuf, bufsize, "Local");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ventoy_get_sys_file_line(vendorbuf, bufsize, "/sys/block/%s/device/vendor", name);
|
||||
}
|
||||
|
||||
int ventoy_get_disk_model(const char *name, char *modelbuf, int bufsize)
|
||||
{
|
||||
return ventoy_get_sys_file_line(modelbuf, bufsize, "/sys/block/%s/device/model", name);
|
||||
if (strncmp(name, "loop", 4) == 0)
|
||||
{
|
||||
scnprintf(modelbuf, bufsize, "Loop Device");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ventoy_get_sys_file_line(modelbuf, bufsize, "/sys/block/%s/device/model", name);
|
||||
}
|
||||
|
||||
static int fatlib_media_sector_read(uint32 sector, uint8 *buffer, uint32 sector_count)
|
||||
@@ -576,9 +588,9 @@ int ventoy_get_disk_info(char **argv)
|
||||
char model[128];
|
||||
char *disk = argv[4];
|
||||
|
||||
if (strncmp(argv[4], "/dev/", 4) == 0)
|
||||
if (strncmp(argv[4], "/dev/", 5) == 0)
|
||||
{
|
||||
disk += 4;
|
||||
disk += 5;
|
||||
}
|
||||
ventoy_get_disk_vendor(disk, vendor, sizeof(vendor));
|
||||
ventoy_get_disk_model(disk, model, sizeof(model));
|
||||
|
@@ -152,6 +152,9 @@ typedef struct tagVTOY_JSON
|
||||
#define VTOY_JSON_FMT_ITEM_LN(P, Item) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\",\n", P, (Item))
|
||||
#define VTOY_JSON_FMT_ITEM_PATH_LN(P, Item) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\",\n", P, ventoy_real_path(Item))
|
||||
|
||||
#define VTOY_JSON_FMT_ITEM_INT(Item) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%d,", (Item))
|
||||
|
||||
|
||||
#define VTOY_JSON_FMT_COMA() ssprintf(__uiCurPos, __pcBuf, __uiBufLen, ",")
|
||||
#define VTOY_JSON_FMT_COMA_N(cnt) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, ",\n")
|
||||
#define VTOY_JSON_FMT_COMA_N_CNT(cnt) if ((cnt) > 0) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, ",\n")
|
||||
|
@@ -257,4 +257,48 @@ if (backup)
|
||||
#endif
|
||||
}
|
||||
|
||||
static const char g_encoding_table[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
||||
'4', '5', '6', '7', '8', '9', '+', '/'};
|
||||
|
||||
char * ventoy_base64_encode(const char *data, int input_length, int *output_length)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
char *encoded_data = NULL;
|
||||
int mod_table[] = {0, 2, 1};
|
||||
|
||||
*output_length = 4 * ((input_length + 2) / 3);
|
||||
encoded_data = malloc(*output_length + 4);
|
||||
if (!encoded_data)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (i < input_length)
|
||||
{
|
||||
unsigned int octet_a = i < input_length ? (unsigned char)data[i++] : 0;
|
||||
unsigned int octet_b = i < input_length ? (unsigned char)data[i++] : 0;
|
||||
unsigned int octet_c = i < input_length ? (unsigned char)data[i++] : 0;
|
||||
|
||||
unsigned int triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;
|
||||
|
||||
encoded_data[j++] = g_encoding_table[(triple >> 3 * 6) & 0x3F];
|
||||
encoded_data[j++] = g_encoding_table[(triple >> 2 * 6) & 0x3F];
|
||||
encoded_data[j++] = g_encoding_table[(triple >> 1 * 6) & 0x3F];
|
||||
encoded_data[j++] = g_encoding_table[(triple >> 0 * 6) & 0x3F];
|
||||
}
|
||||
|
||||
for (i = 0; i < mod_table[input_length % 3]; i++)
|
||||
{
|
||||
encoded_data[*output_length - 1 - i] = '=';
|
||||
}
|
||||
|
||||
return encoded_data;
|
||||
}
|
||||
|
||||
|
@@ -199,6 +199,7 @@ extern unsigned char *g_unxz_buffer;
|
||||
extern int g_unxz_len;
|
||||
void unxz_error(char *x);
|
||||
int unxz_flush(void *src, unsigned int size);
|
||||
char * ventoy_base64_encode(const char *data, int input_length, int *output_length);
|
||||
|
||||
#endif /* __VENTOY_UTIL_H__ */
|
||||
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include <linux/fs.h>
|
||||
#include <dirent.h>
|
||||
#include <time.h>
|
||||
#include <semaphore.h>
|
||||
#include <ventoy_define.h>
|
||||
#include <ventoy_util.h>
|
||||
|
||||
@@ -234,30 +235,18 @@ int ventoy_write_buf_to_file(const char *FileName, void *Bufer, int BufLen)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static sem_t g_writeback_sem;
|
||||
static volatile int g_thread_stop = 0;
|
||||
static pthread_t g_writeback_thread;
|
||||
static pthread_mutex_t g_writeback_mutex;
|
||||
static pthread_cond_t g_writeback_cond;
|
||||
|
||||
static void * ventoy_local_thread_run(void* data)
|
||||
{
|
||||
ventoy_http_writeback_pf callback = (ventoy_http_writeback_pf)data;
|
||||
|
||||
while (1)
|
||||
while (0 == g_thread_stop)
|
||||
{
|
||||
pthread_mutex_lock(&g_writeback_mutex);
|
||||
pthread_cond_wait(&g_writeback_cond, &g_writeback_mutex);
|
||||
|
||||
if (g_thread_stop)
|
||||
{
|
||||
pthread_mutex_unlock(&g_writeback_mutex);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
callback();
|
||||
pthread_mutex_unlock(&g_writeback_mutex);
|
||||
}
|
||||
sem_wait(&g_writeback_sem);
|
||||
callback();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -265,15 +254,14 @@ static void * ventoy_local_thread_run(void* data)
|
||||
|
||||
void ventoy_set_writeback_event(void)
|
||||
{
|
||||
pthread_cond_signal(&g_writeback_cond);
|
||||
sem_post(&g_writeback_sem);
|
||||
}
|
||||
|
||||
int ventoy_start_writeback_thread(ventoy_http_writeback_pf callback)
|
||||
{
|
||||
g_thread_stop = 0;
|
||||
pthread_mutex_init(&g_writeback_mutex, NULL);
|
||||
pthread_cond_init(&g_writeback_cond, NULL);
|
||||
|
||||
sem_init(&g_writeback_sem, 0, 0);
|
||||
pthread_create(&g_writeback_thread, NULL, ventoy_local_thread_run, callback);
|
||||
|
||||
return 0;
|
||||
@@ -282,13 +270,10 @@ int ventoy_start_writeback_thread(ventoy_http_writeback_pf callback)
|
||||
void ventoy_stop_writeback_thread(void)
|
||||
{
|
||||
g_thread_stop = 1;
|
||||
pthread_cond_signal(&g_writeback_cond);
|
||||
|
||||
|
||||
sem_post(&g_writeback_sem);
|
||||
pthread_join(g_writeback_thread, NULL);
|
||||
|
||||
|
||||
pthread_cond_destroy(&g_writeback_cond);
|
||||
pthread_mutex_destroy(&g_writeback_mutex);
|
||||
sem_destroy(&g_writeback_sem);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user