]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Plugson/www/static/js/vtoy.js
1.0.69 release
[Ventoy.git] / Plugson / www / static / js / vtoy.js
1
2 function ventoy_replace_slash(str) {
3 var str1 = str.replace(/\\/g, '/');
4 var str2 = str1.replace(/\/\//g, '/');
5 return str2;
6 }
7
8
9 function ventoy_get_ulen(str) {
10 var c, b = 0, l = str.length;
11 while(l) {
12 c = str.charCodeAt(--l);
13 b += (c < 128) ? 1 : ((c < 2048) ? 2 : ((c < 65536) ? 3 : 4));
14 };
15 return b;
16 }
17
18
19 function ventoy_common_check_path(path) {
20 if (path.indexOf('//') >= 0) {
21 return false;
22 }
23
24 if (path.length <= g_current_dir.length) {
25 return false;
26 }
27
28 if (path.substr(0, g_current_dir.length) != g_current_dir) {
29 return false;
30 }
31
32 return true;
33 }
34
35
36 // 加载子页面内容
37 function loadContent(page) {
38 $("#plugson-content").load(page + ".html?_=" + (new Date().getTime()), function() {
39 $("body").scrollTop(0);
40 });
41 }
42
43 // 包装ajax请求
44 function callVtoyCatchErr(p1, p2, p3) {
45 var url = '/vtoy/json';
46 var data = {};
47 var func = function(data) {};
48 var errfunc = function(xmlHttpRequest, textStatus, errorThrown) {};
49
50 if (typeof(p1) === 'string') {
51 url = p1;
52 } else if (typeof(p1) === 'object') {
53 data = p1;
54 }
55 if (typeof(p2) === 'object') {
56 data = p2;
57 } else if (typeof(p2) === 'function') {
58 func = p2;
59 }
60 if (typeof(p3) === 'function') {
61 errfunc = p3;
62 }
63
64 //vtoy.debug('callVtoy:\t\t\t\t' + JSON.stringify(data));
65 $.ajax({
66 url: url,
67 type: 'post',
68 cache: false,
69 dataType: 'json',
70 data: JSON.stringify(data),
71 success: func,
72 error: errfunc,
73 complete: function(data) {
74 //vtoy.debug('callVtoy\'s resp:\t\t' + data.responseText);
75 }
76 });
77 }
78
79 // 包装ajax请求
80 function callVtoy(p1, p2, p3) {
81 var url = '/vtoy/json';
82 var data = {};
83 var func = function(data) {};
84
85 if (typeof(p1) === 'string') {
86 url = p1;
87 } else if (typeof(p1) === 'object') {
88 data = p1;
89 }
90 if (typeof(p2) === 'object') {
91 data = p2;
92 } else if (typeof(p2) === 'function') {
93 func = p2;
94 }
95 if (typeof(p3) === 'function') {
96 func = p3;
97 }
98
99 //vtoy.debug('callVtoy:\t\t\t\t' + JSON.stringify(data));
100 $.ajax({
101 url: url,
102 type: 'post',
103 cache: false,
104 dataType: 'json',
105 data: JSON.stringify(data),
106 success: func,
107 error: function(xmlHttpRequest, textStatus, errorThrown) {
108
109 if(undefined === errorThrown)
110 {
111 Message.error(g_vtoy_cur_language.STR_WEB_REMOTE_ABNORMAL);
112 }
113 else if(undefined === errorThrown.length)
114 {
115
116 }
117 else if('' == errorThrown.trim())
118 {
119 }
120 else
121 {
122 switch(errorThrown)
123 {
124 case 'timeout':
125 {
126 Message.error(g_vtoy_cur_language.STR_WEB_REQUEST_TIMEOUT);
127 break;
128 }
129 case 'Service Unavailable':
130 {
131 Message.error(g_vtoy_cur_language.STR_WEB_SERVICE_UNAVAILABLE);
132 break;
133 }
134 case 'abort':
135 {
136 break;
137 }
138 default:
139 {
140 Message.error(g_vtoy_cur_language.STR_WEB_COMMUNICATION_ERR + errorThrown);
141 break;
142 }
143 }
144 }
145 },
146 complete: function(data) {
147 //vtoy.debug('callVtoy\'s resp:\t\t' + data.responseText);
148 }
149 });
150 }
151
152 function callVtoyASyncTimeout(time, data, func) {
153 $.ajax({
154 url: '/vtoy/json',
155 type: 'post',
156 cache: false,
157 dataType: 'json',
158 async: true,
159 timeout: time,
160 data: JSON.stringify(data),
161 success: func,
162 error: function(xmlHttpRequest, textStatus, errorThrown) {
163 if(undefined === errorThrown)
164 {
165 }
166 else if(undefined === errorThrown.length)
167 {
168
169 }
170 else if('' == errorThrown.trim())
171 {
172 }
173 else
174 {
175 switch(errorThrown)
176 {
177 case 'timeout':
178 {
179 callVtoyASyncTimeout(time, data, func);
180 break;
181 }
182 case 'Service Unavailable':
183 {
184 break;
185 }
186 case 'abort':
187 {
188 break;
189 }
190 default:
191 {
192 break;
193 }
194 }
195 }
196 },
197 complete: function(data) {
198 //vtoy.debug('callVtoyASyncTimeout\'s resp:\t' + JSON.stringify(data));
199 }
200 });
201 }
202
203 function callVtoySync(data, func) {
204 //vtoy.debug('callVtoySync:\t\t\t' + JSON.stringify(data));
205 $.ajax({
206 url: '/vtoy/json',
207 type: 'post',
208 cache: false,
209 dataType: 'json',
210 async: false,
211 data: JSON.stringify(data),
212 success: function VtoyCallFuncWrapper(data) {
213 if (data.result === 'busy') {
214 var titlestr = '<span class="fa fa-check-circle" style="color:green; font-weight:bold;"> ' + g_vtoy_cur_language.STR_INFO + '</span>';
215 var msgstr = '<span style="font-size:14px; font-weight:bold;"> ' + g_vtoy_cur_language.STR_WEB_SERVICE_BUSY + '</span>';
216 Modal.alert({title:titlestr, msg:msgstr, btnok:g_vtoy_cur_language.STR_BTN_OK });
217 }else {
218 func(data);
219 }
220 },
221 error: function(xmlHttpRequest, textStatus, errorThrown) {
222 if(undefined === errorThrown)
223 {
224 Message.error(g_vtoy_cur_language.STR_WEB_REMOTE_ABNORMAL);
225 }
226 else if(undefined === errorThrown.length)
227 {
228
229 }
230 else if('' == errorThrown.trim())
231 {
232 }
233 else
234 {
235 switch(errorThrown)
236 {
237 case 'timeout':
238 {
239 Message.error(g_vtoy_cur_language.STR_WEB_REQUEST_TIMEOUT);
240 break;
241 }
242 case 'Service Unavailable':
243 {
244 Message.error(g_vtoy_cur_language.STR_WEB_SERVICE_UNAVAILABLE);
245 break;
246 }
247 case 'abort':
248 {
249 break;
250 }
251 default:
252 {
253 Message.error(g_vtoy_cur_language.STR_WEB_COMMUNICATION_ERR + errorThrown);
254 break;
255 }
256 }
257 }
258 },
259 complete: function(data) {
260 //vtoy.debug('callVtoySync\'s resp:\t' + JSON.stringify(data));
261 }
262 });
263 }
264
265 var vtoy = {
266 baseurl : '',
267 status: '',
268 scan: {
269 time: 3,
270 ret: []
271 }
272 }
273
274 //
275 String.prototype.endsWith = function(str) {
276 if (str == null || str == "" || this.length == 0 || str.length > this.length)
277 return false;
278 if (this.substring(this.length - str.length) == str)
279 return true;
280 else
281 return false;
282 }
283
284 window.Message = function() {
285 var _showMsg = function(type, msg, time) {
286 var o = {type : type, msg : msg };
287 if(time) {
288 o.time = time;
289 }
290 _show(o);
291 }
292
293 var _show = function(options) {
294 var ops = {
295 msg : "提示内容",
296 type: 'S',
297 time: 3000
298 };
299 $.extend(ops, options);
300
301 var msg_class = 'alert-success';
302 if('S' === ops.type || 's' === ops.type) {
303 msg_class = 'alert-success';
304 } else if ('E' === ops.type || 'e' === ops.type) {
305 msg_class = 'alert-danger';
306 } else if ('W' === ops.type || 'w' === ops.type) {
307 msg_class = 'alert-warning';
308 } else if ('I' === ops.type || 'i' === ops.type) {
309 msg_class = 'alert-info';
310 } else {
311 alert("未知的类型,请使用: w-警告;s-成功;e-失败;i-提示");
312 return;
313 }
314 var $messageContainer = $("#fcss_message");
315 if($messageContainer.length === 0) {
316 $messageContainer = $('<div id="fcss_message" style="position:fixed; left: 20%; right: 20%; top:0px; z-index:99999999"></div>');
317 $messageContainer.appendTo($('body'));
318 }
319 var $div = $('<div class="alert ' + msg_class + ' alert-dismissible fade in" role="alert" style="margin-bottom: 0; padding-top:10px; padding-bottom: 10px;"></div>');
320 var $btn = $('<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>');
321 $div.append($btn).append(ops.msg).appendTo($messageContainer);
322 setTimeout(function() {
323 $div.remove();
324 }, ops.time);
325 }
326
327 var _success = function(msg, time) {
328 _showMsg('s', msg, time);
329 }
330 var _error = function(msg, time) {
331 _showMsg('e', msg, time || 5000);
332 }
333 var _warn = function(msg, time) {
334 _showMsg('w', msg, time);
335 }
336 var _info = function(msg, time) {
337 _showMsg('i', msg, time);
338 }
339
340 return {
341 success : _success,
342 error : _error,
343 warn : _warn,
344 info : _info,
345 show : _show
346 }
347 }();
348
349
350 var g_vtoy_cur_language_en =
351 {
352 "STR_INFO": "Info",
353 "STR_BTN_OK": "OK",
354 "STR_BTN_CANCEL": "Cancel",
355 "STR_SAVE": " Save",
356 "STR_RESET": " Reset",
357 "STR_DISCARD": " Discard",
358 "STR_ENABLE": " Enable",
359 "STR_ADD": "Add",
360 "STR_DEL": "Delete",
361 "STR_CLEAR": "Clear",
362 "STR_STATUS": "Status",
363 "STR_DEFAULT": "Default",
364 "STR_DEFAULT_SEL": "Default",
365 "STR_RANDOM_SEL": "Random",
366 "STR_OPERATION": "Operation",
367 "STR_VALID": "Valid",
368 "STR_INVALID": "Invalid",
369 "STR_OPT_SETTING": "Option Setting",
370 "STR_OPT_DESC": "Option Description",
371 "STR_EDIT": "Edit",
372 "STR_FILE": "File",
373 "STR_DIR": "Dir",
374 "STR_SAVE_TIP": "Data in current page has been modified. Do you want to save it?",
375 "STR_SAVE_SUCCESS": "Configuration successfully saved!",
376 "STR_FILE_EXIST": "OK",
377 "STR_FILE_NONEXIST": "Invalid",
378 "STR_FILE_FUZZY": "Fuzzy",
379 "STR_DIR_EXIST": "OK",
380 "STR_DIR_NONEXIST": "Invalid",
381 "STR_DUPLICATE_PATH": "Duplicate path",
382 "STR_DELETE_CONFIRM": "Delete this item, Continue?",
383 "STR_FILE_PATH": "File Path",
384 "STR_DIR_PATH": "Directory Path",
385
386 "STR_SET_ALIAS": "Set Menu Alias",
387 "STR_ALIAS": "Alias",
388 "STR_SET_TIP": "Set Menu Tip",
389 "STR_TIP": "Tip",
390 "STR_SET_CLASS": "Set Menu Class",
391 "STR_CLASS": "Class",
392 "STR_SET_INJECTION": "Set Injection",
393 "STR_SET_AUTO_INS": "Set Auto Install",
394 "STR_SET_AUTO_TEMPLATE": "Template",
395
396 "STR_SET_PERSISTENCE": "Set Persistence",
397 "STR_SET_PERSISTENCE_DAT": "Dat File",
398
399 "STR_SET_DUD": "Set DUD",
400 "STR_SET_DUD_FILE": "DUD File",
401
402 "STR_PASSWORD": "Password",
403 "STR_SET_PASSWORD": "Set Password",
404 "STR_PASSWORD_TYPE": "Password Type",
405 "STR_PASSWORD_VALUE": "Password Value",
406
407
408 "STR_WEB_COMMUNICATION_ERR":"Communication error:",
409 "STR_WEB_REMOTE_ABNORMAL":"Communication error: remote abnormal",
410 "STR_WEB_REQUEST_TIMEOUT":"Communication error: Request timed out",
411 "STR_WEB_SERVICE_UNAVAILABLE":"Communication error: Service Unavailable",
412 "STR_WEB_SERVICE_BUSY":"Service is busy, please retry later.",
413
414 "STR_PLUG_DEVICE": "Device Information",
415 "STR_PLUG_CONTROL": "Global Control Plugin",
416 "STR_PLUG_THEME": "Theme Plugin",
417 "STR_PLUG_ALIAS": "Menu Alias Plugin",
418 "STR_PLUG_CLASS": "Menu Class Plugin",
419 "STR_PLUG_TIP": "Menu Tip Plugin",
420 "STR_PLUG_AUTO_INSTALL": "Auto Install Plugin",
421 "STR_PLUG_PERSISTENCE": "Persistence Plugin",
422 "STR_PLUG_INJECTION": "Injection Plugin",
423 "STR_PLUG_CONF_REPLACE": "Boot Conf Replace Plugin",
424 "STR_PLUG_PASSWORD": "Password Plugin",
425 "STR_PLUG_IMAGELIST": "Image List Plugin",
426 "STR_PLUG_AUTO_MEMDISK": "Auto Memdisk Plugin",
427 "STR_PLUG_DUD": "DUD Plugin",
428 "STR_PLUG_DONATION": "Donation",
429
430 "STR_PATH_TOO_LONG": "The path exceeds the maximum supported length, please check!",
431 "STR_INPUT_TOO_LONG": "The string exceeds the maximum supported length, please check!",
432 "STR_INVALID_FILE_PATH": "Invalid or nonexist full file path, please check!",
433 "STR_INVALID_FILE_PATH1": "The 1st file path is invalid or nonexist!",
434 "STR_INVALID_FILE_PATH2": "The 2nd file path is invalid or nonexist!",
435 "STR_INVALID_NEW_FILE_PATH": "The full file path of new is invalid or nonexist, please check!",
436 "STR_INVALID_DIR_PATH": "Invalid directory path, please check!",
437 "STR_INVALID_NUMBER": "Please input valid non-negative integer!",
438 "STR_INVALID_AUTOSEL": "autosel exceeds the length of the list!",
439 "STR_INVALID_TIMEOUT": "Please input valid timeout integer!",
440 "STR_INVALID_PERCENT": "Please input integer between 0-100 !",
441 "STR_INVALID_COLOR": "Please input valid color!",
442 "STR_SELECT": "Please Select",
443 "STR_SET_ALIAS_FOR_FILE": "Set Menu Alias For File",
444 "STR_SET_ALIAS_FOR_DIR": "Set Menu Alias For Directory",
445 "STR_SET_TIP_FOR_FILE": "Set Menu Tip For File",
446 "STR_SET_TIP_FOR_DIR": "Set Menu Tip For Directory",
447 "STR_SET_INJECTION_FOR_FILE": "[image] Set injection for a file",
448 "STR_SET_INJECTION_FOR_DIR": "[parent] Set the same injection for all the files under a directory.",
449 "STR_INVALID_ARCHIVE_PATH": "Invalid or nonexist archive file path, please check!",
450 "STR_SET_PWD_FOR_FILE": "[file] Set password for a file.",
451 "STR_SET_PWD_FOR_DIR": "[parent] Set the same password for all the files under a directory.",
452 "STR_SET_AUTO_INSTALL_FOR_FILE": "[image] Set auto install template for a file",
453 "STR_SET_AUTO_INSTALL_FOR_DIR": "[parent] Set the same auto install template for all the files under a directory.",
454
455 "STR_SET_CLASS_BY_KEY": "[key] Set menu class by filename keyword.",
456 "STR_SET_CLASS_BY_DIR": "[dir] Set menu class for a directory.",
457 "STR_SET_CLASS_BY_PARENT": "[parent] Set menu class for all the files under a directory.",
458 "STR_SET_IMAGE_PWD": "[file] Set Password For A File",
459 "STR_SET_PARENT_PWD": "[parent] Set the same password for all the files under a directory.",
460
461 "STR_SET_SEARCH_ROOT": "Set Search Root",
462 "STR_SET_DEFAULT_IMAGE": "Set Default Image",
463 "STR_ADD_THEME": "Add Theme",
464 "STR_ADD_FONT": "Set Font",
465 "STR_ADD_FILE_TO_LIST": "Add File To List",
466 "STR_DEFAULT_SELECT": " Default",
467 "STR_AUTO_TEMPLATE": "Auto Install Template",
468 "STR_ADD_AUTO_TEMPLATE": "Add Auto Install Template",
469
470 "STR_PERSISTENCE_DAT": "Persistence Dat File",
471 "STR_ADD_PERSISTENCE_DAT": "Add Persistence Dat File",
472
473 "STR_DUD_FILE": "DUD File",
474 "STR_ADD_DUD_FILE": "Add DUD File",
475
476 "STR_DEL_LAST": "The entry will be deleted if you delete the this last item. Continue?",
477
478 "STR_CLOSE_TIP": "Service unavailable, the page will close!",
479 "STR_SECURE_BOOT_ENABLE": "Enable",
480 "STR_SECURE_BOOT_DISABLE": "Disable",
481 "STR_SYNTAX_ERROR_TIP": "Syntax error detected in ventoy.json, so the configuration is not loaded!",
482 "STR_INVALID_CONFIG_TIP": "Invalid configuration detected in ventoy.json, so the configuration is not loaded!",
483
484 "STR_XXX": "xxx"
485 };
486
487 var g_vtoy_cur_language_cn =
488 {
489 "STR_INFO": "提醒",
490 "STR_BTN_OK": "确定",
491 "STR_BTN_CANCEL": "取消",
492 "STR_SAVE": " 保存",
493 "STR_RESET": " 重置",
494 "STR_DISCARD": " 丢弃",
495 "STR_ENABLE": " 使能",
496 "STR_ADD": "新增",
497 "STR_DEL": "删除",
498 "STR_CLEAR": "清除",
499 "STR_STATUS": "状态",
500 "STR_DEFAULT": "默认",
501 "STR_DEFAULT_SEL": "默认选择",
502 "STR_RANDOM_SEL": "随机选择",
503 "STR_OPERATION": "操作",
504 "STR_VALID": "有效",
505 "STR_INVALID": "无效",
506 "STR_OPT_SETTING": "选项设置",
507 "STR_OPT_DESC": "选项说明",
508 "STR_EDIT": "设置",
509 "STR_FILE": "文件",
510 "STR_DIR": "目录",
511 "STR_SAVE_TIP": "当前页面数据已经修改,是否保存?",
512 "STR_SAVE_SUCCESS": "配置保存成功!",
513 "STR_FILE_EXIST": "文件存在",
514 "STR_FILE_NONEXIST": "文件无效",
515 "STR_FILE_FUZZY": "模糊匹配",
516 "STR_DIR_EXIST": "目录存在",
517 "STR_DIR_NONEXIST": "目录无效",
518 "STR_DUPLICATE_PATH": "路径不允许重复",
519 "STR_DELETE_CONFIRM": "确定要删除吗?",
520 "STR_FILE_PATH": "文件路径",
521 "STR_DIR_PATH": "目录路径",
522
523 "STR_SET_ALIAS": "设置菜单别名",
524 "STR_ALIAS": "别名",
525 "STR_SET_TIP": "设置菜单提示",
526 "STR_TIP": "提示",
527 "STR_SET_CLASS": "设置菜单类型",
528 "STR_CLASS": "类型",
529 "STR_SET_INJECTION": "设置文件注入",
530 "STR_SET_AUTO_INS": "设置自动安装",
531 "STR_SET_AUTO_TEMPLATE": "自动安装脚本",
532 "STR_SET_PERSISTENCE": "设置持久化文件",
533 "STR_SET_PERSISTENCE_DAT": "持久化文件",
534
535 "STR_SET_DUD": "设置 DUD",
536 "STR_SET_DUD_FILE": "DUD 文件",
537
538 "STR_PASSWORD": "密码",
539 "STR_SET_PASSWORD": "设置密码",
540 "STR_PASSWORD_TYPE": "密码类型",
541 "STR_PASSWORD_VALUE": "密码内容",
542
543 "STR_WEB_COMMUNICATION_ERR":"通信失败:",
544 "STR_WEB_REMOTE_ABNORMAL":"通信失败:服务端异常",
545 "STR_WEB_REQUEST_TIMEOUT":"通信失败:请求超时",
546 "STR_WEB_SERVICE_UNAVAILABLE":"通信失败:服务不可用",
547 "STR_WEB_SERVICE_BUSY":"后台服务正忙,请稍后重试",
548
549 "STR_PLUG_DEVICE": "设备信息",
550 "STR_PLUG_CONTROL": "全局控制插件",
551 "STR_PLUG_THEME": "主题插件",
552 "STR_PLUG_ALIAS": "菜单别名插件",
553 "STR_PLUG_CLASS": "菜单类型插件",
554 "STR_PLUG_TIP": "菜单提示插件",
555 "STR_PLUG_AUTO_INSTALL": "自动安装插件",
556 "STR_PLUG_PERSISTENCE": "数据持久化插件",
557 "STR_PLUG_INJECTION": "文件注入插件",
558 "STR_PLUG_CONF_REPLACE": "启动配置替换插件",
559 "STR_PLUG_PASSWORD": "密码插件",
560 "STR_PLUG_IMAGELIST": "文件列表插件",
561 "STR_PLUG_AUTO_MEMDISK": "自动Memdisk插件",
562 "STR_PLUG_DUD": "Driver Update Disk插件",
563 "STR_PLUG_DONATION": "捐助",
564
565 "STR_PATH_TOO_LONG": "路径超过最大支持长度,请检查!",
566 "STR_INPUT_TOO_LONG": "字符串超过最大支持长度,请检查!",
567 "STR_INVALID_FILE_PATH": "文件路径不合法或不存在,请检查!",
568 "STR_INVALID_FILE_PATH1": "第1个文件路径不合法或不存在,请检查!",
569 "STR_INVALID_FILE_PATH2": "第2个文件路径不合法或不存在,请检查!",
570 "STR_INVALID_NEW_FILE_PATH": "new 文件路径不合法或不存在,请检查!",
571 "STR_INVALID_DIR_PATH": "文件夹路径不合法,请检查!",
572 "STR_INVALID_NUMBER": "请输入合法的非负整数!",
573 "STR_INVALID_AUTOSEL": "autosel 的值超过了列表实际长度!",
574 "STR_INVALID_TIMEOUT": "请输入合法的超时秒数!",
575 "STR_INVALID_PERCENT": "请输入 0-100 以内的整数!",
576 "STR_INVALID_COLOR": "请输入合法的颜色!",
577 "STR_SELECT": "请选择",
578 "STR_SET_ALIAS_FOR_FILE": "为文件设置别名",
579 "STR_SET_ALIAS_FOR_DIR": "为目录设置别名",
580 "STR_SET_TIP_FOR_FILE": "为文件设置菜单提示信息",
581 "STR_SET_TIP_FOR_DIR": "为目录设置菜单提示信息",
582 "STR_SET_INJECTION_FOR_FILE": "[image] 为某一个文件设置注入",
583 "STR_SET_INJECTION_FOR_DIR": "[parent] 为某个目录下的所有文件设置相同的注入",
584 "STR_INVALID_ARCHIVE_PATH": "Archive 文件路径非法或不存在,请检查!",
585 "STR_SET_PWD_FOR_FILE": "[file] 为指定文件设置密码",
586 "STR_SET_PWD_FOR_DIR": "[parent] 为某个目录下的所有文件设置相同的密码",
587 "STR_SET_AUTO_INSTALL_FOR_FILE": "[image] 为某个镜像文件设置自动安装脚本",
588 "STR_SET_AUTO_INSTALL_FOR_DIR": "[parent] 为某个目录下的所有文件设置相同的自动安装脚本",
589
590 "STR_SET_CLASS_BY_KEY": "[key] 通过文件名关键字设置类型",
591 "STR_SET_CLASS_BY_DIR": "[dir] 为某个目录设置类型(只针对该目录本身,不包含里面的文件及子目录)",
592 "STR_SET_CLASS_BY_PARENT": "[parent] 为某个目录下的所有子文件设置类型(只针对文件,不包含目录)",
593
594 "STR_SET_IMAGE_PWD": "[file] 为某个镜像文件设置密码",
595 "STR_SET_PARENT_PWD": "[parent] 为某个目录下的所有文件设置相同的密码",
596
597
598
599 "STR_SET_SEARCH_ROOT": "设置搜索目录",
600 "STR_SET_DEFAULT_IMAGE": "设置默认镜像文件",
601 "STR_ADD_THEME": "添加主题",
602 "STR_ADD_FONT": "添加字体",
603 "STR_ADD_FILE_TO_LIST": "添加文件",
604 "STR_DEFAULT_SELECT": " 默认选择",
605 "STR_AUTO_TEMPLATE": "自动安装脚本",
606 "STR_ADD_AUTO_TEMPLATE": "添加自动安装脚本",
607 "STR_PERSISTENCE_DAT": "持久化数据文件",
608 "STR_ADD_PERSISTENCE_DAT": "添加持久化数据文件",
609 "STR_DUD_FILE": "DUD 文件",
610 "STR_ADD_DUD_FILE": "添加 DUD 文件",
611
612 "STR_DEL_LAST": "这是本条目中的最后一项,删除此项将会删除整个条目。是否继续?",
613 "STR_CLOSE_TIP": "后台服务不可用,页面即将关闭!",
614 "STR_SECURE_BOOT_ENABLE": "开启",
615 "STR_SECURE_BOOT_DISABLE": "未开启",
616 "STR_SYNTAX_ERROR_TIP": "ventoy.json 文件中存在语法错误,配置未加载!",
617 "STR_INVALID_CONFIG_TIP": "ventoy.json 文件中存在错误配置,配置未加载!",
618
619
620
621 "STR_XXX": "xxx"
622 };
623
624 var g_current_dir;
625 var g_current_os;
626 var g_current_language = 'cn';
627 var g_vtoy_cur_language = g_vtoy_cur_language_cn;
628 var g_vtoy_data_default_index = 6;
629
630 var g_file_with_extra = false;
631 var g_dir_with_extra = false;
632 var g_file_fuzzy_match = 0;
633 var g_file_modal_callback;
634 var g_dir_modal_callback;
635
636 function ventoy_file_submit(form, extra) {
637 var filepath = $("#FilePath").val();
638 var fileextra = $("#FileExtra").val();
639
640 if (!filepath) {
641 return;
642 }
643
644 if (extra) {
645 if (!fileextra) {
646 return;
647 }
648 }
649
650 filepath = ventoy_replace_slash(filepath);
651
652 if (!ventoy_common_check_path(filepath)) {
653 Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH);
654 return;
655 }
656
657 if (g_file_fuzzy_match && filepath.indexOf("*") >= 0) {
658 callVtoySync({
659 method : 'check_fuzzy',
660 path: filepath
661 }, function(data) {
662 if (data.exist != 0) {
663 if (typeof(g_file_modal_callback) === 'function') {
664 g_file_modal_callback(filepath, -1, fileextra);
665 }
666 $("#SetFileModal").modal('hide');
667 } else {
668 Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH);
669 }
670 });
671 } else {
672 callVtoySync({
673 method : 'check_path',
674 dir: 0,
675 path: filepath
676 }, function(data) {
677 if (data.exist === 1) {
678 if (typeof(g_file_modal_callback) === 'function') {
679 g_file_modal_callback(filepath, 1, fileextra);
680 }
681 $("#SetFileModal").modal('hide');
682 } else {
683 Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH);
684 }
685 });
686 }
687 }
688
689
690 var g_filepath_validator = $("#SetFileForm").validate({
691 rules: {
692 FilePath : {
693 required: true,
694 utfmaxlen: true,
695 noquotes: true
696 },
697 FileExtra : {
698 required: false,
699 utfmaxlen: true
700 }
701 },
702 submitHandler: function(form) {
703 ventoy_file_submit(form, g_file_with_extra);
704 }
705 });
706
707 var g_dirpath_validator = $("#SetDirForm").validate({
708 rules: {
709 DirPath : {
710 required: true,
711 utfmaxlen: true,
712 noquotes: true
713 },
714 DirExtra : {
715 required: false,
716 utfmaxlen: true
717 }
718 },
719 submitHandler: function(form) {
720 var dirpath = $("#DirPath").val();
721 var dirextra = $("#DirExtra").val();
722
723 if (!dirpath) {
724 return;
725 }
726
727 if (g_dir_with_extra) {
728 if (!dirextra) {
729 return;
730 }
731 }
732
733 dirpath = ventoy_replace_slash(dirpath);
734
735 if (dirpath.length > 0 && dirpath.charCodeAt(dirpath.length - 1) === 47) {
736 dirpath = dirpath.substring(0, dirpath.length - 1);
737 }
738
739 if (!ventoy_common_check_path(dirpath)) {
740 Message.error(g_vtoy_cur_language.STR_INVALID_DIR_PATH);
741 return;
742 }
743
744 callVtoySync({
745 method : 'check_path',
746 dir: 1,
747 path: dirpath
748 }, function(data) {
749 if (data.exist === 1) {
750 if (typeof(g_dir_modal_callback) === 'function') {
751 g_dir_modal_callback(dirpath, dirextra);
752 }
753 $("#SetDirModal").modal('hide');
754 } else {
755 Message.error(g_vtoy_cur_language.STR_INVALID_DIR_PATH);
756 }
757 });
758 }
759 });
760
761 function VtoySelectFilePath(cb, para) {
762 g_file_fuzzy_match = para.fuzzy;
763
764 if (para.extra) {
765 $('div[id=id_div_file_extra]').show();
766 $('#SetFileForm_extra').text(para.extra_title);
767 } else {
768 $('div[id=id_div_file_extra]').hide();
769 }
770
771 $('span[id=id_span_filepath_tip1]').each(function(){
772 $(this).text(para.tip1);
773 });
774 $('span[id=id_span_filepath_tip2]').each(function(){
775 $(this).text(para.tip2);
776 });
777 $('span[id=id_span_filepath_tip3]').each(function(){
778 $(this).text(para.tip3);
779 });
780
781 if (g_current_language === 'en') {
782 if (para.title.length === 0) {
783 $('#SetFileForm #SetFileForm_lang_1').text("Set File Path");
784 } else {
785 $('#SetFileForm #SetFileForm_lang_1').text(para.title);
786 }
787
788 $('#SetFileForm #SetFileForm_lang_2').text("File Path");
789 $('#SetFileForm #SetFileForm_lang_3').text(" OK");
790 $('#SetFileForm #SetFileForm_lang_4').text("Cancel");
791 $('#SetFileForm #id_note_setfile_cn').hide();
792 $('#SetFileForm #id_note_setfile_en').show();
793 } else {
794 if (para.title.length === 0) {
795 $('#SetFileForm #SetFileForm_lang_1').text("设置文件路径");
796 } else {
797 $('#SetFileForm #SetFileForm_lang_1').text(para.title);
798 }
799 $('#SetFileForm #SetFileForm_lang_2').text("文件路径");
800 $('#SetFileForm #SetFileForm_lang_3').text("确定");
801 $('#SetFileForm #SetFileForm_lang_4').text("取消");
802 $('#SetFileForm #id_note_setfile_cn').show();
803 $('#SetFileForm #id_note_setfile_en').hide();
804 }
805
806 if (para.tip3.length > 0) {
807 if (g_current_language === 'en') {
808 $('#SetFileForm #id_note_tip3_en').show();
809 $('#SetFileForm #id_note_tip3_cn').hide();
810 } else {
811 $('#SetFileForm #id_note_tip3_cn').show();
812 $('#SetFileForm #id_note_tip3_en').hide();
813 }
814 } else {
815 $('#SetFileForm #id_note_tip3_en').hide();
816 $('#SetFileForm #id_note_tip3_cn').hide();
817 }
818
819 g_file_modal_callback = cb;
820 g_file_with_extra = para.extra;
821 g_filepath_validator.settings.rules.FileExtra.required = g_file_with_extra;
822 g_filepath_validator.resetForm();
823 $("#SetFileModal").modal();
824 }
825
826
827 function VtoySelectDirPath(cb, para) {
828 $('span[id=id_span_dirpath_tip]').each(function(){
829 $(this).text(para.tip);
830 });
831 $('span[id=id_span_dirpath_tip3]').each(function(){
832 $(this).text(para.tip3);
833 });
834
835 if (para.extra) {
836 $('div[id=id_div_dir_extra]').show();
837 $('label[id=SetDirForm_extra]').text(para.extra_title);
838 } else {
839 $('div[id=id_div_dir_extra]').hide();
840 }
841
842 if (g_current_language === 'en') {
843 if (para.title.length === 0) {
844 $('#SetDirForm #SetDirForm_lang_1').text("Set Directory Path");
845 } else {
846 $('#SetDirForm #SetDirForm_lang_1').text(para.title);
847 }
848 $('#SetDirForm #SetDirForm_lang_2').text("Directory Path");
849 $('#SetDirForm #SetDirForm_lang_3').text(" OK");
850 $('#SetDirForm #SetDirForm_lang_4').text("Cancel");
851 $('#SetDirForm #id_note_setfile_cn').hide();
852 $('#SetDirForm #id_note_setfile_en').show();
853 } else {
854 if (para.title.length === 0) {
855 $('#SetDirForm #SetDirForm_lang_1').text("设置文件夹路径");
856 } else {
857 $('#SetDirForm #SetDirForm_lang_1').text(para.title);
858 }
859 $('#SetDirForm #SetDirForm_lang_2').text("文件夹路径");
860 $('#SetDirForm #SetDirForm_lang_3').text("确定");
861 $('#SetDirForm #SetDirForm_lang_4').text("取消");
862 $('#SetDirForm #id_note_setfile_cn').show();
863 $('#SetDirForm #id_note_setfile_en').hide();
864 }
865
866 if (para.tip3.length > 0) {
867 if (g_current_language === 'en') {
868 $('#SetDirForm #id_note_tip3_en').show();
869 $('#SetDirForm #id_note_tip3_cn').hide();
870 } else {
871 $('#SetDirForm #id_note_tip3_cn').show();
872 $('#SetDirForm #id_note_tip3_en').hide();
873 }
874 } else {
875 $('#SetDirForm #id_note_tip3_en').hide();
876 $('#SetDirForm #id_note_tip3_cn').hide();
877 }
878
879 g_dir_modal_callback = cb;
880 g_dir_with_extra = para.extra;
881 g_dirpath_validator.settings.rules.DirExtra.required = g_dir_with_extra;
882 g_dirpath_validator.resetForm();
883 $("#SetDirModal").modal();
884 }
885
886 function VtoyCommonChangeLanguage(newlang) {
887 if (newlang === 'en') {
888 g_vtoy_cur_language = g_vtoy_cur_language_en;
889 ;$.extend($.validator.messages, {
890 required: "This field is required",
891 remote: "Please modify this field",
892 maxlength: $.validator.format("You can enter up to {0} characters"),
893 minlength: $.validator.format("Must enter at least {0} characters"),
894 rangelength: $.validator.format("Please input {0} to {1} characters"),
895 range: $.validator.format("The input range is from {0} to {1}"),
896 max: $.validator.format("Please input a number less than or equal to {0}"),
897 min: $.validator.format("Please input a number bigger than or equal to {0}"),
898 utfmaxlen: $.validator.format("The string exceeds the maximum supported length"),
899 start_slash: $.validator.format("Must start with /"),
900 noquotes: $.validator.format("Can not include double quotes"),
901 filenamepart:$.validator.format("As part of file name, can not include invalid characters"),
902 printascii: $.validator.format("Can not include non-ascii characters.")
903 });
904
905 $("a[id=id_a_official_doc]").each(function(){
906 var oldlink = $(this).attr('href');
907 var newlink = oldlink.replace("/cn/", "/en/");
908 $(this).attr('href', newlink);
909 });
910
911 $("span[id=id_span_official_doc]").each(function(){
912 $(this).text(" Plugin Official Document");
913 });
914
915 $('#id_span_language').text("中文");
916
917 $("tr[id=tr_title_desc_cn]").each(function(){
918 $(this).hide();
919 });
920
921 $("tr[id=tr_title_desc_en]").each(function(){
922 $(this).show();
923 });
924
925 $("th[id=id_th_file_path]").each(function(){
926 $(this).text("Full File Path");
927 });
928
929 $("span[id=id_span_desc_cn]").each(function(){
930 $(this).hide();
931 });
932
933 } else {
934 g_vtoy_cur_language = g_vtoy_cur_language_cn;
935 ;$.extend($.validator.messages, {
936 required: "这是必填字段",
937 remote: "请修正此字段",
938 maxlength: $.validator.format("最多可以输入 {0} 个字符"),
939 minlength: $.validator.format("最少要输入 {0} 个字符"),
940 rangelength: $.validator.format("请输入长度在 {0} 到 {1} 之间的字符串"),
941 range: $.validator.format("取值范围{0}到{1}"),
942 max: $.validator.format("请输入不大于 {0} 的数值"),
943 min: $.validator.format("请输入不小于 {0} 的数值"),
944 utfmaxlen: $.validator.format("超过最大长度"),
945 start_slash: $.validator.format("必须以反斜杠 / 开头"),
946 noquotes: $.validator.format("不能包含双引号"),
947 filenamepart:$.validator.format("作为文件名的一部分,不能包含特殊的符号"),
948 printascii: $.validator.format("不能包含中文或其他非 ascii 字符。")
949 });
950
951 $("a[id=id_a_official_doc]").each(function(){
952 var oldlink = $(this).attr('href');
953 var newlink = oldlink.replace("/en/", "/cn/");
954 $(this).attr('href', newlink);
955 });
956
957 $("span[id=id_span_official_doc]").each(function(){
958 $(this).text(" 插件官网文档");
959 });
960
961 $('#id_span_language').text("English");
962
963 $("tr[id=tr_title_desc_cn]").each(function(){
964 $(this).show();
965 });
966
967 $("tr[id=tr_title_desc_en]").each(function(){
968 $(this).hide();
969 });
970
971 $("th[id=id_th_file_path]").each(function(){
972 $(this).text("文件路径");
973 });
974
975 $("span[id=id_span_desc_cn]").each(function(){
976 $(this).show();
977 });
978 }
979
980 $("span[id=id_span_menu_device]").text(g_vtoy_cur_language.STR_PLUG_DEVICE);
981 $("span[id=id_span_menu_control]").text(g_vtoy_cur_language.STR_PLUG_CONTROL);
982 $("span[id=id_span_menu_theme]").text(g_vtoy_cur_language.STR_PLUG_THEME);
983 $("span[id=id_span_menu_alias]").text(g_vtoy_cur_language.STR_PLUG_ALIAS);
984 $("span[id=id_span_menu_tip]").text(g_vtoy_cur_language.STR_PLUG_TIP);
985 $("span[id=id_span_menu_class]").text(g_vtoy_cur_language.STR_PLUG_CLASS);
986 $("span[id=id_span_menu_auto_install]").text(g_vtoy_cur_language.STR_PLUG_AUTO_INSTALL);
987 $("span[id=id_span_menu_persistence]").text(g_vtoy_cur_language.STR_PLUG_PERSISTENCE);
988 $("span[id=id_span_menu_injection]").text(g_vtoy_cur_language.STR_PLUG_INJECTION);
989 $("span[id=id_span_menu_conf_replace]").text(g_vtoy_cur_language.STR_PLUG_CONF_REPLACE);
990 $("span[id=id_span_menu_password]").text(g_vtoy_cur_language.STR_PLUG_PASSWORD);
991 $("span[id=id_span_menu_imagelist]").text(g_vtoy_cur_language.STR_PLUG_IMAGELIST);
992 $("span[id=id_span_menu_auto_memdisk]").text(g_vtoy_cur_language.STR_PLUG_AUTO_MEMDISK);
993 $("span[id=id_span_menu_dud]").text(g_vtoy_cur_language.STR_PLUG_DUD);
994 $('#id_span_save').text(g_vtoy_cur_language.STR_SAVE);
995 $('#id_span_reset').text(g_vtoy_cur_language.STR_RESET);
996 $('#id_span_donation').text(g_vtoy_cur_language.STR_PLUG_DONATION);
997
998 $("span[id=id_span_btn_add]").each(function(){
999 $(this).text(g_vtoy_cur_language.STR_ADD);
1000 });
1001 $("span[id=id_span_btn_del]").each(function(){
1002 $(this).text(g_vtoy_cur_language.STR_DEL);
1003 });
1004
1005 $("span[id=id_span_enable]").each(function(){
1006 $(this).text(g_vtoy_cur_language.STR_ENABLE);
1007 });
1008
1009 $("th[id=id_th_operation]").each(function(){
1010 $(this).text(g_vtoy_cur_language.STR_OPERATION);
1011 });
1012 $("th[id=id_th_status]").each(function(){
1013 $(this).text(g_vtoy_cur_language.STR_STATUS);
1014 });
1015
1016 $('span [id=id_span_valid').each(function(){
1017 $(this).text(g_vtoy_cur_language.STR_VALID);
1018 });
1019 $('span [id=id_span_invalid').each(function(){
1020 $(this).text(g_vtoy_cur_language.STR_INVALID);
1021 });
1022
1023 $("td[id=td_title_desc]").each(function(){
1024 $(this).text(g_vtoy_cur_language.STR_OPT_DESC);
1025 });
1026
1027 $("td[id=td_title_setting]").each(function(){
1028 $(this).text(g_vtoy_cur_language.STR_OPT_SETTING);
1029 });
1030 }
1031
1032
1033 function ventoy_get_status_line(dir, exist) {
1034 if (dir) {
1035 if (exist === 0) {
1036 return '<span id="id_span_dir_nonexist" style="line-height: 1.5;" class="label pull-left bg-red">' + g_vtoy_cur_language.STR_DIR_NONEXIST + '</span>';
1037 } else {
1038 return '<span id="id_span_dir_exist" style="line-height: 1.5;" class="label pull-left bg-green">' + g_vtoy_cur_language.STR_DIR_EXIST + '</span>';
1039 }
1040 } else {
1041 if (exist === -1) {
1042 return '<span id="id_span_file_fuzzy" style="line-height: 1.5;" class="label pull-left bg-yellow">' + g_vtoy_cur_language.STR_FILE_FUZZY + '</span>';
1043 } else if (exist === 1) {
1044 return '<span id="id_span_file_exist" style="line-height: 1.5;" class="label pull-left bg-green">' + g_vtoy_cur_language.STR_FILE_EXIST + '</span>';
1045 } else {
1046 return '<span id="id_span_file_nonexist" style="line-height: 1.5;" class="label pull-left bg-red">' + g_vtoy_cur_language.STR_FILE_NONEXIST + '</span>';
1047 }
1048 }
1049 }
1050
1051
1052
1053 var g_type_select_callback;
1054
1055 var g_type_select_validator = $("#TypeSelectForm").validate({
1056 submitHandler: function(form) {
1057 var sel = parseInt($('input:radio[name=name_select_type_radio]:checked').val());
1058 if (typeof(g_type_select_callback) === 'function') {
1059 g_type_select_callback(sel);
1060 }
1061
1062 $("#TypeSelectModal").modal('hide');
1063 }
1064 });
1065
1066 function VtoySelectType(cb, para) {
1067
1068 $('#TypeSelectForm #TypeSelForm_lang_1').text(g_vtoy_cur_language.STR_SELECT);
1069
1070 if (g_current_language === 'en') {
1071 $('#TypeSelectForm #TypeSelForm_lang_2').text(" OK");
1072 $('#TypeSelectForm #TypeSelForm_lang_3').text("Cancel");
1073 } else {
1074 $('#TypeSelectForm #TypeSelForm_lang_2').text("确定");
1075 $('#TypeSelectForm #TypeSelForm_lang_3').text("取消");
1076 }
1077
1078 var $tbl = $("#id_type_select_table tbody");
1079 $tbl.empty();
1080
1081 for (var i = 0; i < para.length; i++) {
1082 var $tr;
1083
1084 if (para[i].selected) {
1085 $tr = $('<tr><td><label class="radio-inline"><input type="radio" checked="checked" name="name_select_type_radio" value="' + i + '"/>' + para[i].tip + '</label></td></tr>');
1086 } else {
1087 $tr = $('<tr><td><label class="radio-inline"><input type="radio" name="name_select_type_radio" value="' + i + '"/>' + para[i].tip + '</label></td></tr>');
1088 }
1089
1090 $tbl.append($tr);
1091 }
1092
1093 g_type_select_callback = cb;
1094 g_type_select_validator.resetForm();
1095 $("#TypeSelectModal").modal();
1096 }
1097
1098
1099 var g_set_key_callback;
1100
1101 var g_set_key_validator = $("#SetKeyForm").validate({
1102 rules: {
1103 SetKeyKey : {
1104 required: true,
1105 utfmaxlen: true
1106 },
1107 SetKeyValue : {
1108 required: true,
1109 utfmaxlen: true,
1110 filenamepart: true
1111 }
1112 },
1113
1114 submitHandler: function(form) {
1115 var key = $('input:text[id=SetKeyKey]').val();
1116 var val = $('input:text[id=SetKeyValue]').val();
1117
1118 if ((!key) || (!val))
1119 {
1120 return;
1121 }
1122
1123 if (typeof(g_set_key_callback) === 'function') {
1124 g_set_key_callback(key, val);
1125 }
1126
1127 $("#SetKeyModal").modal('hide');
1128 }
1129 });
1130
1131 function VtoySetKey(cb, para) {
1132
1133 $('#SetKeyForm #SetKeyForm_lang_1').text(para.title);
1134 $('#SetKeyForm #SetKeyForm_lang_2').text(para.title1);
1135 $('#SetKeyForm #SetKeyForm_lang_3').text(para.title2);
1136
1137 if (g_current_language === 'en') {
1138 $('#SetKeyForm #SetKeyForm_lang_4').text(" OK");
1139 $('#SetKeyForm #SetKeyForm_lang_5').text("Cancel");
1140 } else {
1141 $('#SetKeyForm #SetKeyForm_lang_4').text("确定");
1142 $('#SetKeyForm #SetKeyForm_lang_5').text("取消");
1143 }
1144
1145 g_set_key_callback = cb;
1146 g_set_key_validator.resetForm();
1147 $("#SetKeyModal").modal();
1148 }
1149
1150 var g_valid_color_name = [
1151 "black",
1152 "blue",
1153 "green",
1154 "cyan",
1155 "red",
1156 "magenta",
1157 "brown",
1158 "light-gray",
1159 "dark-gray",
1160 "light-blue",
1161 "light-green",
1162 "light-cyan",
1163 "light-red",
1164 "light-magenta",
1165 "yellow",
1166 "white"
1167 ];
1168
1169 function ventoy_check_color(color) {
1170 if (/^#[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]$/.test(color)) {
1171 return true;
1172 } else {
1173 for (var i = 0; i < g_valid_color_name.length; i++) {
1174 if (g_valid_color_name[i] === color) {
1175 return true;
1176 }
1177 }
1178 }
1179
1180 return false;
1181 }
1182
1183 function ventoy_check_percent(percent) {
1184 if (percent.length > 0) {
1185 return true;
1186 } else {
1187 return false;
1188 }
1189 }
1190
1191
1192 function ventoy_check_file_path(isopath, fuzzy, cb) {
1193 if (fuzzy && isopath.indexOf("*") >= 0) {
1194 callVtoySync({
1195 method : 'check_fuzzy',
1196 path: isopath
1197 }, function(data) {
1198 if (data.exist != 0) {
1199 if (typeof(cb) === 'function') {
1200 cb(data.exist);
1201 }
1202 } else {
1203 Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH);
1204 }
1205 });
1206 } else {
1207 callVtoySync({
1208 method : 'check_path',
1209 dir: 0,
1210 path: isopath
1211 }, function(data) {
1212 if (data.exist === 1) {
1213 if (typeof(cb) === 'function') {
1214 cb(data.exist);
1215 }
1216 } else {
1217 Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH);
1218 }
1219 });
1220 }
1221 }
1222
1223 function ventoy_random_string(e) { 
1224 var t = "abcdefhijkmnprstwxyz2345678";
1225 var a = t.length;
1226 var n = "";
1227
1228 e = e || 4;
1229    for (i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
1230    return n
1231 }
1232
1233
1234 var g_set_filefile_callback;
1235
1236 var g_set_filefile_validator = $("#SetFileFileForm").validate({
1237 rules: {
1238 FileFilePath1 : {
1239 required: true,
1240 utfmaxlen: true
1241 },
1242 FileFilePath2 : {
1243 required: true,
1244 utfmaxlen: true
1245 }
1246 },
1247
1248 submitHandler: function(form) {
1249 var path1 = $('input:text[id=FileFilePath1]').val();
1250 var path2 = $('input:text[id=FileFilePath2]').val();
1251
1252 if ((!path1) || (!path2))
1253 {
1254 return;
1255 }
1256
1257 path1 = ventoy_replace_slash(path1);
1258
1259 if (!ventoy_common_check_path(path1)) {
1260 Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH1);
1261 return;
1262 }
1263
1264 path2 = ventoy_replace_slash(path2);
1265
1266 if (!ventoy_common_check_path(path2)) {
1267 Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH2);
1268 return;
1269 }
1270
1271 callVtoy({
1272 method : 'check_path2',
1273 dir1: 0,
1274 fuzzy1: 1,
1275 path1: path1,
1276 dir2: 0,
1277 fuzzy2: 0,
1278 path2: path2
1279 }, function(retdata) {
1280 if (retdata.exist1 != 0 && retdata.exist2 != 0) {
1281 if (typeof(g_set_filefile_callback) === 'function') {
1282 g_set_filefile_callback(retdata.exist1, path1, path2);
1283 }
1284
1285 $("#SetFileFileModal").modal('hide');
1286 } else if (retdata.exist1 === 0) {
1287 Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH1);
1288 } else {
1289 Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH2);
1290 }
1291 });
1292 }
1293 });
1294
1295 function VtoySetFileFile(cb, para) {
1296
1297 $('#SetFileFileForm #SetFileFileForm_title').text(para.title);
1298 $('#SetFileFileForm #SetFileFileForm_label1').text(para.label1);
1299 $('#SetFileFileForm #SetFileFileForm_label2').text(para.label2);
1300
1301 if (g_current_language === 'en') {
1302 $('#SetFileFileForm #SetFileFileForm_ok').text(" OK");
1303 $('#SetFileFileForm #SetFileFileForm_cancel').text("Cancel");
1304
1305 $('#SetFileFileForm #id_note_filefile_cn').hide();
1306 $('#SetFileFileForm #id_note_filefile_en').show();
1307
1308 } else {
1309 $('#SetFileFileForm #SetFileFileForm_ok').text("确定");
1310 $('#SetFileFileForm #SetFileFileForm_cancel').text("取消");
1311
1312 $('#SetFileFileForm #id_note_filefile_en').hide();
1313 $('#SetFileFileForm #id_note_filefile_cn').show();
1314 }
1315
1316 $('span[id=id_span_filefile_tip1]').each(function(){
1317 $(this).text(para.tip1);
1318 });
1319 $('span[id=id_span_filefile_tip2]').each(function(){
1320 $(this).text(para.tip2);
1321 });
1322 $('span[id=id_span_filefile_tip3]').each(function(){
1323 $(this).text(para.tip3);
1324 });
1325
1326 g_set_filefile_callback = cb;
1327 g_set_filefile_validator.resetForm();
1328 $("#SetFileFileModal").modal();
1329 }
1330
1331
1332 var g_set_dirfile_callback;
1333
1334 var g_set_dirfile_validator = $("#SetDirFileForm").validate({
1335 rules: {
1336 DirFilePath1 : {
1337 required: true,
1338 utfmaxlen: true
1339 },
1340 DirFilePath2 : {
1341 required: true,
1342 utfmaxlen: true
1343 }
1344 },
1345
1346 submitHandler: function(form) {
1347 var path1 = $('input:text[id=DirFilePath1]').val();
1348 var path2 = $('input:text[id=DirFilePath2]').val();
1349
1350 if ((!path1) || (!path2))
1351 {
1352 return;
1353 }
1354
1355 path1 = ventoy_replace_slash(path1);
1356
1357 if (!ventoy_common_check_path(path1)) {
1358 Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH1);
1359 return;
1360 }
1361
1362 path2 = ventoy_replace_slash(path2);
1363
1364 if (!ventoy_common_check_path(path2)) {
1365 Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH2);
1366 return;
1367 }
1368
1369 callVtoy({
1370 method : 'check_path2',
1371 dir1: 1,
1372 fuzzy1: 0,
1373 path1: path1,
1374 dir2: 0,
1375 fuzzy2: 0,
1376 path2: path2
1377 }, function(retdata) {
1378 if (retdata.exist1 != 0 && retdata.exist2 != 0) {
1379 if (typeof(g_set_dirfile_callback) === 'function') {
1380 g_set_dirfile_callback(path1, path2);
1381 }
1382
1383 $("#SetDirFileModal").modal('hide');
1384 } else if (retdata.exist1 === 0) {
1385 Message.error(g_vtoy_cur_language.STR_INVALID_DIR_PATH);
1386 } else {
1387 Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH2);
1388 }
1389 });
1390 }
1391 });
1392
1393 function VtoySetDirFile(cb, para) {
1394
1395 $('#SetDirFileModal #SetDirFileForm_title').text(para.title);
1396 $('#SetDirFileModal #SetDirFileForm_label1').text(para.label1);
1397 $('#SetDirFileModal #SetDirFileForm_label2').text(para.label2);
1398
1399 if (g_current_language === 'en') {
1400 $('#SetDirFileModal #SetDirFileForm_ok').text(" OK");
1401 $('#SetDirFileModal #SetDirFileForm_cancel').text("Cancel");
1402
1403 $('#SetDirFileModal #id_note_dirfile_cn').hide();
1404 $('#SetDirFileModal #id_note_dirfile_en').show();
1405
1406 } else {
1407 $('#SetDirFileModal #SetDirFileForm_ok').text("确定");
1408 $('#SetDirFileModal #SetDirFileForm_cancel').text("取消");
1409
1410 $('#SetDirFileModal #id_note_dirfile_en').hide();
1411 $('#SetDirFileModal #id_note_dirfile_cn').show();
1412 }
1413
1414 $('span[id=id_span_dirfile_tip1]').each(function(){
1415 $(this).text(para.tip1);
1416 });
1417 $('span[id=id_span_dirfile_tip2]').each(function(){
1418 $(this).text(para.tip2);
1419 });
1420
1421 g_set_dirfile_callback = cb;
1422 g_set_dirfile_validator.resetForm();
1423 $("#SetDirFileModal").modal();
1424 }
1425
1426 function ventoy_get_xslg_addbtn(mclass) {
1427 return '<button class="btn btn-xs btn-lg btn-success btn-add ' + mclass + '"><span class="fa fa-plus">&nbsp;&nbsp;</span><span id="id_span_btn_add">'+g_vtoy_cur_language.STR_ADD+'</span></button>';
1428 }
1429
1430 function ventoy_get_xslg_delbtn(mclass) {
1431 return '<button class="btn btn-xs btn-lg btn-danger btn-del '+mclass+'"><span class="fa fa-trash">&nbsp;&nbsp;</span><span id="id_span_btn_del">'+g_vtoy_cur_language.STR_DEL+'</span></button>';
1432 }
1433
1434 function ventoy_get_addbtn(mclass) {
1435 return '<button class="btn btn-success btn-add ' + mclass + '"><span class="fa fa-plus">&nbsp;&nbsp;</span><span id="id_span_btn_add">'+g_vtoy_cur_language.STR_ADD+'</span></button>';
1436 }
1437
1438 function ventoy_get_delbtn(mclass) {
1439 return '<button class="btn btn-danger btn-del '+mclass+'"><span class="fa fa-trash">&nbsp;&nbsp;</span><span id="id_span_btn_del">'+g_vtoy_cur_language.STR_DEL+'</span></button>';
1440 }
1441
1442 function ventoy_confirm(title, cb, data1, data2) {
1443 Modal.confirm({msg:g_vtoy_cur_language.STR_DEL_LAST}).on(function(e) {
1444 if (e) {
1445 if (typeof(cb) === 'function') {
1446 cb(data1, data2);
1447 }
1448 }
1449 });
1450 }