diff --git a/Plugson/src/Core/ventoy_json.h b/Plugson/src/Core/ventoy_json.h index ad130b97..be2b4341 100644 --- a/Plugson/src/Core/ventoy_json.h +++ b/Plugson/src/Core/ventoy_json.h @@ -70,6 +70,7 @@ #define VTOY_JSON_TOKEN_ERR_RET "{ \"result\" : \"tokenerror\" }" #define VTOY_JSON_EXIST_RET "{ \"result\" : \"exist\" }" #define VTOY_JSON_TIMEOUT_RET "{ \"result\" : \"timeout\" }" +#define VTOY_JSON_DUPLICATE "{ \"result\" : \"duplicate\" }" #define VTOY_JSON_BUSY_RET "{ \"result\" : \"busy\" }" #define VTOY_JSON_INUSE_RET "{ \"result\" : \"inuse\" }" #define VTOY_JSON_NOTFOUND_RET "{ \"result\" : \"notfound\" }" diff --git a/Plugson/src/Web/ventoy_http.c b/Plugson/src/Web/ventoy_http.c index 6de2159a..aa1d87d4 100644 --- a/Plugson/src/Web/ventoy_http.c +++ b/Plugson/src/Web/ventoy_http.c @@ -918,9 +918,11 @@ 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; @@ -928,6 +930,19 @@ 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) + { + realpath = ventoy_real_path(node->path); + if (strcmp(pathbuf, realpath) == 0) + { + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; + } + } + node = zalloc(sizeof(path_node)); if (node) { @@ -980,16 +995,31 @@ 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; 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) + { + realpath = ventoy_real_path(node->path); + if (strcmp(pathbuf, realpath) == 0) + { + ventoy_json_result(conn, VTOY_JSON_DUPLICATE); + return 0; + } + } + node = zalloc(sizeof(path_node)); if (node) { diff --git a/Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe b/Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe index d0f55609..72ec6e2a 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 548287f1..043c1b45 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/index.html b/Plugson/www/index.html index 02d27c6a..29f909f9 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_theme.html b/Plugson/www/plugson_theme.html index e6f96a02..5c2f6d8e 100644 --- a/Plugson/www/plugson_theme.html +++ b/Plugson/www/plugson_theme.html @@ -403,9 +403,13 @@ index: current_tab_index, path: data.path }, function(e) { - list.push(data); - FillThemeFileTable(list, m_data_theme[current_tab_index].default_file); - Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + if (e.result === 'success') { + list.push(data); + FillThemeFileTable(list, m_data_theme[current_tab_index].default_file); + Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + } else if (e.result === 'duplicate') { + Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH); + } }); } @@ -428,9 +432,13 @@ index: current_tab_index, path: data.path }, function(e) { - list.push(data); - FillThemeFontTable(list); - Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + if (e.result === 'success') { + list.push(data); + FillThemeFontTable(list); + Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); + } else if (e.result === 'duplicate') { + Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH); + } }); }