]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Add theme plugin duplicate file check. (#2078)
authorlongpanda <admin@ventoy.net>
Tue, 20 Dec 2022 12:02:06 +0000 (20:02 +0800)
committerlongpanda <admin@ventoy.net>
Tue, 20 Dec 2022 12:02:06 +0000 (20:02 +0800)
Plugson/src/Core/ventoy_json.h
Plugson/src/Web/ventoy_http.c
Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe
Plugson/vs/VentoyPlugson/x64/Release/VentoyPlugson_X64.exe
Plugson/www/index.html
Plugson/www/plugson_theme.html

index ad130b97228fdd39e9e710a1e96cca0e041a3315..be2b4341d815b31fe6dbf385ef4552ad9a2f1ad5 100644 (file)
@@ -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\" }"
index 6de2159a0a4f932e6a4ac9db03b350f22bae554e..aa1d87d4f7191e931d098cf6eb1e8c290df07cfd 100644 (file)
@@ -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)
         {
index d0f55609d342a66b4473ef27afb60fc6861fbbd1..72ec6e2a7d04e33a2453fe2930672083fd63c073 100644 (file)
Binary files a/Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe and b/Plugson/vs/VentoyPlugson/Release/VentoyPlugson.exe differ
index 548287f180ee74dfbfe8b5c8b30812d47cbbb42f..043c1b45abe3c51945616c7f2f282ad30fe57386 100644 (file)
Binary files a/Plugson/vs/VentoyPlugson/x64/Release/VentoyPlugson_X64.exe and b/Plugson/vs/VentoyPlugson/x64/Release/VentoyPlugson_X64.exe differ
index 02d27c6a7e65af95063eb5553004b21329d138e7..29f909f984ef3fe171e771310bb66c2d49385d8a 100644 (file)
 \r
         <footer class="main-footer">\r
             <div class="pull-right hidden-xs">\r
-                <b id="plugson_build_date">20221220 18:30:51</b>
+                <b id="plugson_build_date">20221220 19:41:37</b>
             </div>\r
             <strong><a href="https://www.ventoy.net" target="_blank">https://www.ventoy.net</a></strong>\r
         </footer>\r
     <script src="/static/js/jQuery-2.1.4.min.js"></script>\r
     <!-- jquery validate -->\r
     <script src="/static/js/jquery.validate.min.js"></script>    \r
-    <script src="/static/js/jquery.validate.vtoymethods.js?v=101"></script>\r
+    <script src="/static/js/jquery.validate.vtoymethods.js?v=102"></script>\r
 \r
-    <script src="/static/js/jquery.vtoy.alert.js?v=101"></script>\r
-    <script src="/static/js/vtoy.js?v=101"></script>\r
+    <script src="/static/js/jquery.vtoy.alert.js?v=102"></script>\r
+    <script src="/static/js/vtoy.js?v=102"></script>\r
     <script src="/static/js/md5.min.js"></script>\r
 \r
     <!-- Bootstrap 3.3.5 -->\r
index e6f96a0226915ced5bbbc44acda03b09eb7e596a..5c2f6d8e80239559e57808ddfd64243e74e2e31b 100644 (file)
       index: current_tab_index,\r
       path: data.path\r
     }, function(e) {\r
-      list.push(data);\r
-      FillThemeFileTable(list, m_data_theme[current_tab_index].default_file);\r
-      Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);\r
+        if (e.result === 'success') {\r
+            list.push(data);\r
+            FillThemeFileTable(list, m_data_theme[current_tab_index].default_file);\r
+            Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);\r
+        } else if (e.result === 'duplicate') {\r
+            Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH);\r
+        }\r
     });\r
   }\r
 \r
       index: current_tab_index,\r
       path: data.path\r
     }, function(e) {\r
-      list.push(data);\r
-      FillThemeFontTable(list);\r
-      Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);\r
+        if (e.result === 'success') {\r
+            list.push(data);\r
+            FillThemeFontTable(list);\r
+            Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);\r
+        } else if (e.result === 'duplicate') {\r
+            Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH);\r
+        }\r
     });\r
   }\r
 \r