diff --git a/Plugson/src/Core/ventoy_util_windows.c b/Plugson/src/Core/ventoy_util_windows.c index 1d8d97fc..6610894c 100644 --- a/Plugson/src/Core/ventoy_util_windows.c +++ b/Plugson/src/Core/ventoy_util_windows.c @@ -638,7 +638,8 @@ int CheckRuntimeEnvironment(char Letter, ventoy_disk *disk) return 1; } - if (_stricmp(FsName, "NTFS") == 0) + /* Fix: enable for all file system on Windows */ + /* if (_stricmp(FsName, "NTFS") == 0) */ { disk->pathcase = 1; } diff --git a/Plugson/src/Web/ventoy_http.c b/Plugson/src/Web/ventoy_http.c index aa1d87d4..2f1f8820 100644 --- a/Plugson/src/Web/ventoy_http.c +++ b/Plugson/src/Web/ventoy_http.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -97,6 +98,9 @@ static char *g_pub_save_buffer = NULL; static pthread_mutex_t g_api_mutex; static struct mg_context *g_ventoy_http_ctx = NULL; +#define ventoy_is_real_exist_common(xpath, xnode, xtype) \ + ventoy_path_is_real_exist(xpath, xnode, offsetof(xtype, path), offsetof(xtype, next)) + static int ventoy_is_kbd_valid(const char *key) { int i = 0; @@ -170,6 +174,40 @@ static void ventoy_free_path_node_list(path_node *list) } } +static int ventoy_path_is_real_exist(const char *path, void *head, size_t pathoff, size_t nextoff) +{ + char *node = NULL; + const char *nodepath = NULL; + const char *realpath = NULL; + char pathbuf[MAX_PATH]; + + if (strchr(path, '*')) + { + return 0; + } + + realpath = ventoy_real_path(path); + scnprintf(pathbuf, sizeof(pathbuf), "%s", realpath); + + node = (char *)head; + while (node) + { + nodepath = node + pathoff; + if (NULL == strchr(nodepath, '*')) + { + realpath = ventoy_real_path(nodepath); + if (strcmp(pathbuf, realpath) == 0) + { + return 1; + } + } + + memcpy(&node, node + nextoff, sizeof(node)); + } + + return 0; +} + static path_node * ventoy_path_node_add_array(VTOY_JSON *array) { path_node *head = NULL; @@ -913,16 +951,15 @@ static int ventoy_api_save_theme(struct mg_connection *conn, VTOY_JSON *json) return 0; } + static int ventoy_api_theme_add_file(struct mg_connection *conn, VTOY_JSON *json) { int ret; int index = 0; const char *path = NULL; - const char *realpath = NULL; path_node *node = NULL; path_node *cur = NULL; data_theme *data = NULL; - char pathbuf[MAX_PATH]; vtoy_json_get_int(json, "index", &index); data = g_data_theme + index; @@ -930,19 +967,12 @@ static int ventoy_api_theme_add_file(struct mg_connection *conn, VTOY_JSON *json path = VTOY_JSON_STR_EX("path"); if (path) { - realpath = ventoy_real_path(path); - scnprintf(pathbuf, sizeof(pathbuf), "%s", realpath); - - for (node = data->filelist; node; node = node->next) + if (ventoy_is_real_exist_common(path, data->filelist, path_node)) { - realpath = ventoy_real_path(node->path); - if (strcmp(pathbuf, realpath) == 0) - { - ventoy_json_result(conn, VTOY_JSON_DUPLICATE); - return 0; - } + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; } - + node = zalloc(sizeof(path_node)); if (node) { @@ -989,17 +1019,14 @@ static int ventoy_api_theme_del_file(struct mg_connection *conn, VTOY_JSON *json return 0; } - static int ventoy_api_theme_add_font(struct mg_connection *conn, VTOY_JSON *json) { int ret; int index = 0; const char *path = NULL; - const char *realpath = NULL; path_node *node = NULL; path_node *cur = NULL; data_theme *data = NULL; - char pathbuf[MAX_PATH]; vtoy_json_get_int(json, "index", &index); data = g_data_theme + index; @@ -1007,19 +1034,12 @@ static int ventoy_api_theme_add_font(struct mg_connection *conn, VTOY_JSON *json path = VTOY_JSON_STR_EX("path"); if (path) { - realpath = ventoy_real_path(path); - scnprintf(pathbuf, sizeof(pathbuf), "%s", realpath); - - for (node = data->fontslist; node; node = node->next) + if (ventoy_is_real_exist_common(path, data->fontslist, path_node)) { - realpath = ventoy_real_path(node->path); - if (strcmp(pathbuf, realpath) == 0) - { - ventoy_json_result(conn, VTOY_JSON_DUPLICATE); - return 0; - } + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; } - + node = zalloc(sizeof(path_node)); if (node) { @@ -1222,6 +1242,12 @@ static int ventoy_api_alias_add(struct mg_connection *conn, VTOY_JSON *json) alias = VTOY_JSON_STR_EX("alias"); if (path && alias) { + if (ventoy_is_real_exist_common(path, data->list, data_alias_node)) + { + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; + } + node = zalloc(sizeof(data_alias_node)); if (node) { @@ -1467,6 +1493,12 @@ static int ventoy_api_tip_add(struct mg_connection *conn, VTOY_JSON *json) tip = VTOY_JSON_STR_EX("tip"); if (path && tip) { + if (ventoy_is_real_exist_common(path, data->list, data_tip_node)) + { + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; + } + node = zalloc(sizeof(data_tip_node)); if (node) { @@ -1816,6 +1848,12 @@ static int ventoy_api_auto_memdisk_add(struct mg_connection *conn, VTOY_JSON *js path = VTOY_JSON_STR_EX("path"); if (path) { + if (ventoy_is_real_exist_common(path, data->list, path_node)) + { + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; + } + node = zalloc(sizeof(path_node)); if (node) { @@ -1998,6 +2036,12 @@ static int ventoy_api_image_list_add(struct mg_connection *conn, VTOY_JSON *json path = VTOY_JSON_STR_EX("path"); if (path) { + if (ventoy_is_real_exist_common(path, data->list, path_node)) + { + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; + } + node = zalloc(sizeof(path_node)); if (node) { @@ -2253,6 +2297,12 @@ static int ventoy_api_password_add(struct mg_connection *conn, VTOY_JSON *json) pwd = VTOY_JSON_STR_EX("pwd"); if (path && pwd) { + if (ventoy_is_real_exist_common(path, data->list, menu_password)) + { + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; + } + node = zalloc(sizeof(menu_password)); if (node) { @@ -2658,6 +2708,12 @@ static int ventoy_api_dud_add(struct mg_connection *conn, VTOY_JSON *json) path = VTOY_JSON_STR_EX("path"); if (path && array) { + if (ventoy_is_real_exist_common(path, data->list, dud_node)) + { + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; + } + node = zalloc(sizeof(dud_node)); if (node) { @@ -3013,6 +3069,12 @@ static int ventoy_api_auto_install_add(struct mg_connection *conn, VTOY_JSON *js path = VTOY_JSON_STR_EX("path"); if (path && array) { + if (ventoy_is_real_exist_common(path, data->list, auto_install_node)) + { + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; + } + node = zalloc(sizeof(auto_install_node)); if (node) { @@ -3355,6 +3417,12 @@ static int ventoy_api_persistence_add(struct mg_connection *conn, VTOY_JSON *jso path = VTOY_JSON_STR_EX("path"); if (path && array) { + if (ventoy_is_real_exist_common(path, data->list, persistence_node)) + { + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; + } + node = zalloc(sizeof(persistence_node)); if (node) { @@ -3648,6 +3716,12 @@ static int ventoy_api_injection_add(struct mg_connection *conn, VTOY_JSON *json) archive = VTOY_JSON_STR_EX("archive"); if (path && archive) { + if (ventoy_is_real_exist_common(path, data->list, injection_node)) + { + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; + } + node = zalloc(sizeof(injection_node)); if (node) { diff --git a/Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe b/Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe index 72ec6e2a..dc8b2166 100644 Binary files a/Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe and b/Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe differ diff --git a/Plugson/vs/VentoyPlugson/x64/Release/VentoyPlugson_X64.exe b/Plugson/vs/VentoyPlugson/x64/Release/VentoyPlugson_X64.exe index 043c1b45..4912f408 100644 Binary files a/Plugson/vs/VentoyPlugson/x64/Release/VentoyPlugson_X64.exe and b/Plugson/vs/VentoyPlugson/x64/Release/VentoyPlugson_X64.exe differ diff --git a/Plugson/www/buildtime b/Plugson/www/buildtime index 5d528f42..0dbb63cf 100644 --- a/Plugson/www/buildtime +++ b/Plugson/www/buildtime @@ -1 +1 @@ -20221220 18:30:51 \ No newline at end of file +20221221 12:11:59 \ No newline at end of file diff --git a/Plugson/www/index.html b/Plugson/www/index.html index 29f909f9..b5391fd7 100644 --- a/Plugson/www/index.html +++ b/Plugson/www/index.html @@ -757,7 +757,7 @@ @@ -777,10 +777,10 @@ - + - - + + diff --git a/Plugson/www/plugson_auto_install.html b/Plugson/www/plugson_auto_install.html index 4014e101..a8e45bcf 100644 --- a/Plugson/www/plugson_auto_install.html +++ b/Plugson/www/plugson_auto_install.html @@ -359,9 +359,13 @@ template: call_array, type: type }, function(e) { - list.push(data); - FillAutoInsTable(list); - Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + if (e.result === 'success') { + list.push(data); + FillAutoInsTable(list); + Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + } else if (e.result === 'duplicate') { + Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH); + } }); } diff --git a/Plugson/www/plugson_auto_memdisk.html b/Plugson/www/plugson_auto_memdisk.html index 14ed690d..96bac5b3 100644 --- a/Plugson/www/plugson_auto_memdisk.html +++ b/Plugson/www/plugson_auto_memdisk.html @@ -131,9 +131,13 @@ index: current_tab_index, path: data.path, }, function(e) { - list.push(data); - FillMemdiskTable(list); - Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + if (e.result === 'success') { + list.push(data); + FillMemdiskTable(list); + Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + } else if (e.result === 'duplicate') { + Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH); + } }); } diff --git a/Plugson/www/plugson_dud.html b/Plugson/www/plugson_dud.html index 426400e7..4c172af8 100644 --- a/Plugson/www/plugson_dud.html +++ b/Plugson/www/plugson_dud.html @@ -203,9 +203,13 @@ dud: call_array, type: type }, function(e) { - list.push(data); - FillDudTable(list); - Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + if (e.result === 'success') { + list.push(data); + FillDudTable(list); + Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + } else if (e.result === 'duplicate') { + Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH); + } }); } diff --git a/Plugson/www/plugson_image_list.html b/Plugson/www/plugson_image_list.html index fbbcf07f..8d702f4d 100644 --- a/Plugson/www/plugson_image_list.html +++ b/Plugson/www/plugson_image_list.html @@ -221,9 +221,13 @@ index: current_tab_index, path: data.path, }, function(e) { - list.push(data); - FillImageListTable(list); - Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + if (e.result === 'success') { + list.push(data); + FillImageListTable(list); + Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + } else if (e.result === 'duplicate') { + Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH); + } }); } diff --git a/Plugson/www/plugson_injection.html b/Plugson/www/plugson_injection.html index bd8e6d56..17055ad2 100644 --- a/Plugson/www/plugson_injection.html +++ b/Plugson/www/plugson_injection.html @@ -158,9 +158,13 @@ archive: data.archive, type: type }, function(e) { - list.push(data); - FillInjectionTable(list); - Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + if (e.result === 'success') { + list.push(data); + FillInjectionTable(list); + Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + } else if (e.result === 'duplicate') { + Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH); + } }); } diff --git a/Plugson/www/plugson_menu_alias.html b/Plugson/www/plugson_menu_alias.html index ed7d27bb..2e275d35 100644 --- a/Plugson/www/plugson_menu_alias.html +++ b/Plugson/www/plugson_menu_alias.html @@ -152,9 +152,13 @@ alias: data.alias, type: type }, function(e) { - list.push(data); - FillAliasTable(list); - Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + if (e.result === 'success') { + list.push(data); + FillAliasTable(list); + Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + } else if (e.result === 'duplicate') { + Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH); + } }); } diff --git a/Plugson/www/plugson_menu_class.html b/Plugson/www/plugson_menu_class.html index f2309356..0a14dc45 100644 --- a/Plugson/www/plugson_menu_class.html +++ b/Plugson/www/plugson_menu_class.html @@ -178,9 +178,13 @@ class: data.class, type: type }, function(e) { - list.push(data); - FillClassTable(list); - Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + if (e.result === 'success') { + list.push(data); + FillClassTable(list); + Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + } else if (e.result === 'duplicate') { + Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH); + } }); } diff --git a/Plugson/www/plugson_menu_tip.html b/Plugson/www/plugson_menu_tip.html index 214a43eb..75ef8086 100644 --- a/Plugson/www/plugson_menu_tip.html +++ b/Plugson/www/plugson_menu_tip.html @@ -244,9 +244,13 @@ tip: data.tip, type: type }, function(e) { - list.push(data); - FillTipTable(list); - Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + if (e.result === 'success') { + list.push(data); + FillTipTable(list); + Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + } else if (e.result === 'duplicate') { + Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH); + } }); } diff --git a/Plugson/www/plugson_password.html b/Plugson/www/plugson_password.html index 97cdc68d..bca84bc9 100644 --- a/Plugson/www/plugson_password.html +++ b/Plugson/www/plugson_password.html @@ -464,9 +464,13 @@ function VtoySetPassword(common, type, cb, data) { path: data.path, pwd: data.pwd }, function(e) { - list.push(data); - FillMenuPwdTable(list); - Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + if (e.result === 'success') { + list.push(data); + FillMenuPwdTable(list); + Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + } else if (e.result === 'duplicate') { + Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH); + } }); } diff --git a/Plugson/www/plugson_persistence.html b/Plugson/www/plugson_persistence.html index d5a4c076..37359ab8 100644 --- a/Plugson/www/plugson_persistence.html +++ b/Plugson/www/plugson_persistence.html @@ -358,9 +358,13 @@ backend: call_array, type: type }, function(e) { - list.push(data); - FillPersistenceTable(list); - Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + if (e.result === 'success') { + list.push(data); + FillPersistenceTable(list); + Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + } else if (e.result === 'duplicate') { + Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH); + } }); }