"scripts/wan22/run_wan22_moe_i2v.sh" did not exist on "8bc0da34b4d1ae737af9f4e3dd713e76a64de202"
vtoy.js 49.8 KB
Newer Older
1

2
3
4
5
6
7
8
9
10
function VtoyUTF16HexToAscii(hex) {
    var str = "";        
    for (var i = 0; i < hex.length; i += 4) {
        str += String.fromCharCode(parseInt(hex.substring(i, i + 4), 16));
    }
    
    return str;
}

11
12
13
function ventoy_replace_slash(str) {
    var str1 = str.replace(/\\/g, '/');
    var str2 = str1.replace(/\/\//g, '/');
14
15
16
17
18
19
20
    
    if (str2 && str2.length > 0) {
        if (str2.substr(-1) === "/") {
            return str2.substr(0, str2.length - 1);
        }
    }
    
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
    return str2;
}


function ventoy_get_ulen(str) {    
    var c, b = 0, l = str.length;    
    while(l) {    
        c = str.charCodeAt(--l);    
        b += (c < 128) ? 1 : ((c < 2048) ? 2 : ((c < 65536) ? 3 : 4));    
    };    
    return b;    
}


function ventoy_common_check_path(path) {
    if (path.indexOf('//') >= 0) {
        return false;
    }

    if (path.length <= g_current_dir.length) {
        return false;
    }

    if (path.substr(0, g_current_dir.length) != g_current_dir) {
        return false;
    }

    return true;
}


// 加载子页面内容
function loadContent(page) {
    $("#plugson-content").load(page + ".html?_=" + (new Date().getTime()), function() {
        $("body").scrollTop(0);
    });
}

// 包装ajax请求
function callVtoyCatchErr(p1, p2, p3) {
    var url = '/vtoy/json';
    var data = {};
    var func = function(data) {};
    var errfunc = function(xmlHttpRequest, textStatus, errorThrown) {};

    if (typeof(p1) === 'string') {
        url = p1;
    } else if (typeof(p1) === 'object') {
        data = p1;
    }
    if (typeof(p2) === 'object') {
        data = p2;
    } else if (typeof(p2) === 'function') {
        func = p2;
    }
    if (typeof(p3) === 'function') {
        errfunc = p3;
    }

    //vtoy.debug('callVtoy:\t\t\t\t' + JSON.stringify(data));
    $.ajax({
        url: url,
        type: 'post',
        cache: false,
        dataType: 'json',
        data: JSON.stringify(data),
        success: func,
        error: errfunc,
        complete: function(data) {
        //vtoy.debug('callVtoy\'s resp:\t\t' + data.responseText);
        }
    });
}

// 包装ajax请求
function callVtoy(p1, p2, p3) {
    var url = '/vtoy/json';
    var data = {};
    var func = function(data) {};

    if (typeof(p1) === 'string') {
        url = p1;
    } else if (typeof(p1) === 'object') {
        data = p1;
    }
    if (typeof(p2) === 'object') {
        data = p2;
    } else if (typeof(p2) === 'function') {
        func = p2;
    }
    if (typeof(p3) === 'function') {
        func = p3;
    }

    //vtoy.debug('callVtoy:\t\t\t\t' + JSON.stringify(data));
    $.ajax({
        url: url,
        type: 'post',
        cache: false,
        dataType: 'json',
        data: JSON.stringify(data),
        success: func,
        error: function(xmlHttpRequest, textStatus, errorThrown) {

            if(undefined === errorThrown)
            {
                Message.error(g_vtoy_cur_language.STR_WEB_REMOTE_ABNORMAL);
            }
            else if(undefined === errorThrown.length)
            {
                
            }
            else if('' == errorThrown.trim())
            {
            }
            else
            {
                switch(errorThrown)
                {
                    case 'timeout':
                    {
                        Message.error(g_vtoy_cur_language.STR_WEB_REQUEST_TIMEOUT);
                        break;
                    }
                    case 'Service Unavailable':
                    {
                        Message.error(g_vtoy_cur_language.STR_WEB_SERVICE_UNAVAILABLE);
                        break;
                    }
                    case 'abort':
                    {
                        break;
                    }
                    default:
                    {
                        Message.error(g_vtoy_cur_language.STR_WEB_COMMUNICATION_ERR + errorThrown);
                        break;
                    }
                }
            }
        },
        complete: function(data) {
        //vtoy.debug('callVtoy\'s resp:\t\t' + data.responseText);
        }
    });
}

function callVtoyASyncTimeout(time, data, func) {
    $.ajax({
        url: '/vtoy/json',
        type: 'post',
        cache: false,
        dataType: 'json',
        async: true,
        timeout: time,
        data: JSON.stringify(data),
        success: func,
        error: function(xmlHttpRequest, textStatus, errorThrown) {
            if(undefined === errorThrown)
            {                
            }
            else if(undefined === errorThrown.length)
            {
                
            }
            else if('' == errorThrown.trim())
            {
            }
            else
            {
                switch(errorThrown)
                {
                    case 'timeout':
                    {
                        callVtoyASyncTimeout(time, data, func);
                        break;
                    }
                    case 'Service Unavailable':
                    {
                        break;
                    }
                    case 'abort':
                    {
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
        },
        complete: function(data) {
            //vtoy.debug('callVtoyASyncTimeout\'s resp:\t' + JSON.stringify(data));
        }
    });
}

function callVtoySync(data, func) {
    //vtoy.debug('callVtoySync:\t\t\t' + JSON.stringify(data));
    $.ajax({
        url: '/vtoy/json',
        type: 'post',
        cache: false,
        dataType: 'json',
        async: false,
        data: JSON.stringify(data),
        success: function VtoyCallFuncWrapper(data) {            
            if (data.result === 'busy') {
                var titlestr = '<span class="fa fa-check-circle" style="color:green; font-weight:bold;"> ' + g_vtoy_cur_language.STR_INFO + '</span>';
                var msgstr = '<span style="font-size:14px; font-weight:bold;"> ' + g_vtoy_cur_language.STR_WEB_SERVICE_BUSY + '</span>';
                Modal.alert({title:titlestr, msg:msgstr, btnok:g_vtoy_cur_language.STR_BTN_OK });                
            }else {
                func(data);
            }
        },
        error: function(xmlHttpRequest, textStatus, errorThrown) {
            if(undefined === errorThrown)
            {
                Message.error(g_vtoy_cur_language.STR_WEB_REMOTE_ABNORMAL);
            }
            else if(undefined === errorThrown.length)
            {
                
            }
            else if('' == errorThrown.trim())
            {
            }
            else
            {
                switch(errorThrown)
                {
                    case 'timeout':
                    {
                        Message.error(g_vtoy_cur_language.STR_WEB_REQUEST_TIMEOUT);
                        break;
                    }
                    case 'Service Unavailable':
                    {
                        Message.error(g_vtoy_cur_language.STR_WEB_SERVICE_UNAVAILABLE);
                        break;
                    }
                    case 'abort':
                    {
                        break;
                    }
                    default:
                    {
                        Message.error(g_vtoy_cur_language.STR_WEB_COMMUNICATION_ERR + errorThrown);
                        break;
                    }
                }
            }
        },
        complete: function(data) {
            //vtoy.debug('callVtoySync\'s resp:\t' + JSON.stringify(data));
        }
    });
}

var vtoy = {    
    baseurl : '',
    status: '',    
    scan: {
        time: 3,
        ret: []
    }
}

// 
String.prototype.endsWith = function(str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
    if (this.substring(this.length - str.length) == str)
        return true;
    else
        return false;
}


var g_vtoy_cur_language_en = 
{
    "STR_INFO": "Info",
    "STR_BTN_OK": "OK",
    "STR_BTN_CANCEL": "Cancel",
    "STR_SAVE": " Save",
    "STR_RESET": " Reset",
    "STR_DISCARD": " Discard",
    "STR_ENABLE": " Enable",
    "STR_ADD": "Add",
    "STR_DEL": "Delete",
    "STR_CLEAR": "Clear",
    "STR_STATUS": "Status",
    "STR_DEFAULT": "Default",
    "STR_DEFAULT_SEL": "Default",
    "STR_RANDOM_SEL": "Random",
    "STR_OPERATION": "Operation",
    "STR_VALID": "Valid",
    "STR_INVALID": "Invalid",
    "STR_OPT_SETTING": "Option Setting",
    "STR_OPT_DESC": "Option Description",
    "STR_EDIT": "Edit",
longpanda's avatar
longpanda committed
323
    "STR_RESET": "Reset",
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
    "STR_FILE": "File",
    "STR_DIR": "Dir",
    "STR_SAVE_TIP": "Data in current page has been modified. Do you want to save it?",
    "STR_SAVE_SUCCESS": "Configuration successfully saved!",
    "STR_FILE_EXIST": "OK",
    "STR_FILE_NONEXIST": "Invalid",
    "STR_FILE_FUZZY": "Fuzzy",
    "STR_DIR_EXIST": "OK",
    "STR_DIR_NONEXIST": "Invalid",
    "STR_DUPLICATE_PATH": "Duplicate path",
    "STR_DELETE_CONFIRM": "Delete this item, Continue?",
    "STR_FILE_PATH": "File Path",
    "STR_DIR_PATH": "Directory Path",

    "STR_SET_ALIAS": "Set Menu Alias",
    "STR_ALIAS": "Alias",
    "STR_SET_TIP": "Set Menu Tip",
    "STR_TIP": "Tip",
    "STR_SET_CLASS": "Set Menu Class",
    "STR_CLASS": "Class",
    "STR_SET_INJECTION": "Set Injection",
    "STR_SET_AUTO_INS": "Set Auto Install",
    "STR_SET_AUTO_TEMPLATE": "Template",

    "STR_SET_PERSISTENCE": "Set Persistence",
    "STR_SET_PERSISTENCE_DAT": "Dat File",

    "STR_SET_DUD": "Set DUD",
    "STR_SET_DUD_FILE": "DUD File",

    "STR_PASSWORD": "Password",
    "STR_SET_PASSWORD": "Set Password",
    "STR_PASSWORD_TYPE": "Password Type",
    "STR_PASSWORD_VALUE": "Password Value",


    "STR_WEB_COMMUNICATION_ERR":"Communication error:",
    "STR_WEB_REMOTE_ABNORMAL":"Communication error: remote abnormal",
    "STR_WEB_REQUEST_TIMEOUT":"Communication error: Request timed out",
    "STR_WEB_SERVICE_UNAVAILABLE":"Communication error: Service Unavailable",
    "STR_WEB_SERVICE_BUSY":"Service is busy, please retry later.",

    "STR_PLUG_DEVICE": "Device Information",
    "STR_PLUG_CONTROL": "Global Control Plugin",
    "STR_PLUG_THEME": "Theme Plugin",
    "STR_PLUG_ALIAS": "Menu Alias Plugin",
    "STR_PLUG_CLASS": "Menu Class Plugin",
    "STR_PLUG_TIP": "Menu Tip Plugin",
    "STR_PLUG_AUTO_INSTALL": "Auto Install Plugin",
    "STR_PLUG_PERSISTENCE": "Persistence Plugin",
    "STR_PLUG_INJECTION": "Injection Plugin",
    "STR_PLUG_CONF_REPLACE": "Boot Conf Replace Plugin",
    "STR_PLUG_PASSWORD": "Password Plugin",
    "STR_PLUG_IMAGELIST": "Image List Plugin",
    "STR_PLUG_AUTO_MEMDISK": "Auto Memdisk Plugin",
    "STR_PLUG_DUD": "DUD Plugin",
    "STR_PLUG_DONATION": "Donation",

    "STR_PATH_TOO_LONG": "The path exceeds the maximum supported length, please check!",
    "STR_INPUT_TOO_LONG": "The string exceeds the maximum supported length, please check!",
longpanda's avatar
longpanda committed
384
385
386
387
    "STR_INVALID_FILE_PATH": "Invalid or nonexist full file path, please check!",
    "STR_INVALID_FILE_PATH1": "The 1st file path is invalid or nonexist!",    
    "STR_INVALID_FILE_PATH2": "The 2nd file path is invalid or nonexist!",    
    "STR_INVALID_NEW_FILE_PATH": "The full file path of new is invalid or nonexist, please check!",
388
389
390
391
392
393
394
395
396
397
398
399
400
    "STR_INVALID_DIR_PATH": "Invalid directory path, please check!",
    "STR_INVALID_NUMBER": "Please input valid non-negative integer!",
    "STR_INVALID_AUTOSEL": "autosel exceeds the length of the list!",
    "STR_INVALID_TIMEOUT": "Please input valid timeout integer!",
    "STR_INVALID_PERCENT": "Please input integer between 0-100 !",
    "STR_INVALID_COLOR": "Please input valid color!",
    "STR_SELECT": "Please Select",
    "STR_SET_ALIAS_FOR_FILE": "Set Menu Alias For File",
    "STR_SET_ALIAS_FOR_DIR": "Set Menu Alias For Directory",
    "STR_SET_TIP_FOR_FILE": "Set Menu Tip For File",
    "STR_SET_TIP_FOR_DIR": "Set Menu Tip For Directory",
    "STR_SET_INJECTION_FOR_FILE": "[image] Set injection for a file",
    "STR_SET_INJECTION_FOR_DIR": "[parent] Set the same injection for all the files under a directory.",
longpanda's avatar
longpanda committed
401
    "STR_INVALID_ARCHIVE_PATH": "Invalid or nonexist archive file path, please check!",
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
    "STR_SET_PWD_FOR_FILE": "[file] Set password for a file.",
    "STR_SET_PWD_FOR_DIR": "[parent] Set the same password for all the files under a directory.",
    "STR_SET_AUTO_INSTALL_FOR_FILE": "[image] Set auto install template for a file",
    "STR_SET_AUTO_INSTALL_FOR_DIR": "[parent] Set the same auto install template for all the files under a directory.",

    "STR_SET_CLASS_BY_KEY": "[key] Set menu class by filename keyword.",
    "STR_SET_CLASS_BY_DIR": "[dir] Set menu class for a directory.",
    "STR_SET_CLASS_BY_PARENT": "[parent] Set menu class for all the files under a directory.",
    "STR_SET_IMAGE_PWD": "[file] Set Password For A File",
    "STR_SET_PARENT_PWD": "[parent] Set the same password for all the files under a directory.",

    "STR_SET_SEARCH_ROOT": "Set Search Root",    
    "STR_SET_DEFAULT_IMAGE": "Set Default Image",
    "STR_ADD_THEME": "Add Theme",
    "STR_ADD_FONT": "Set Font",
    "STR_ADD_FILE_TO_LIST": "Add File To List",
    "STR_DEFAULT_SELECT": " Default",
    "STR_AUTO_TEMPLATE": "Auto Install Template",
    "STR_ADD_AUTO_TEMPLATE": "Add Auto Install Template",
    
    "STR_PERSISTENCE_DAT": "Persistence Dat File",
    "STR_ADD_PERSISTENCE_DAT": "Add Persistence Dat File",

    "STR_DUD_FILE": "DUD File",
    "STR_ADD_DUD_FILE": "Add DUD File",

    "STR_DEL_LAST": "The entry will be deleted if you delete the this last item. Continue?",

    "STR_CLOSE_TIP": "Service unavailable, the page will close!",
    "STR_SECURE_BOOT_ENABLE": "Enable",
    "STR_SECURE_BOOT_DISABLE": "Disable",
    "STR_SYNTAX_ERROR_TIP": "Syntax error detected in ventoy.json, so the configuration is not loaded!",
434
    "STR_INVALID_CONFIG_TIP": "Invalid configuration detected in ventoy.json, so the configuration is not loaded!",
435
    "STR_CONFIG_SAVE_ERROR_TIP": "Failed to write ventoy.json file. Check VentoyPlugson.log for more details!",
436

longpanda's avatar
longpanda committed
437
438
439
440
    "STR_JSON_PREVIEW": "JSON Preview",
    "STR_JSON_COPY_SUCCESS": "JSON Copy Success",
    "STR_JSON_COPY_FAILED": "JSON Copy Failed",

441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
    "STR_XXX": "xxx"
};

var g_vtoy_cur_language_cn = 
{
    "STR_INFO": "提醒",
    "STR_BTN_OK": "确定",
    "STR_BTN_CANCEL": "取消",
    "STR_SAVE": " 保存",
    "STR_RESET": " 重置",
    "STR_DISCARD": " 丢弃",
    "STR_ENABLE": " 使能",
    "STR_ADD": "新增",
    "STR_DEL": "删除",
    "STR_CLEAR": "清除",
    "STR_STATUS": "状态",
    "STR_DEFAULT": "默认",
    "STR_DEFAULT_SEL": "默认选择",
    "STR_RANDOM_SEL": "随机选择",
    "STR_OPERATION": "操作",
    "STR_VALID": "有效",
    "STR_INVALID": "无效",
    "STR_OPT_SETTING": "选项设置",
    "STR_OPT_DESC": "选项说明",
    "STR_EDIT": "设置",
longpanda's avatar
longpanda committed
466
    "STR_RESET": "重置",
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
    "STR_FILE": "文件",
    "STR_DIR": "目录",
    "STR_SAVE_TIP": "当前页面数据已经修改,是否保存?",
    "STR_SAVE_SUCCESS": "配置保存成功!",
    "STR_FILE_EXIST": "文件存在",
    "STR_FILE_NONEXIST": "文件无效",
    "STR_FILE_FUZZY": "模糊匹配",
    "STR_DIR_EXIST": "目录存在",
    "STR_DIR_NONEXIST": "目录无效",
    "STR_DUPLICATE_PATH": "路径不允许重复",
    "STR_DELETE_CONFIRM": "确定要删除吗?",
    "STR_FILE_PATH": "文件路径",
    "STR_DIR_PATH": "目录路径",
    
    "STR_SET_ALIAS": "设置菜单别名",
    "STR_ALIAS": "别名",
    "STR_SET_TIP": "设置菜单提示",
    "STR_TIP": "提示",
    "STR_SET_CLASS": "设置菜单类型",
    "STR_CLASS": "类型",
    "STR_SET_INJECTION": "设置文件注入",
    "STR_SET_AUTO_INS": "设置自动安装",
    "STR_SET_AUTO_TEMPLATE": "自动安装脚本",
    "STR_SET_PERSISTENCE": "设置持久化文件",
    "STR_SET_PERSISTENCE_DAT": "持久化文件",

    "STR_SET_DUD": "设置 DUD",
    "STR_SET_DUD_FILE": "DUD 文件",

    "STR_PASSWORD": "密码",
    "STR_SET_PASSWORD": "设置密码",
    "STR_PASSWORD_TYPE": "密码类型",
    "STR_PASSWORD_VALUE": "密码内容",

    "STR_WEB_COMMUNICATION_ERR":"通信失败:",
    "STR_WEB_REMOTE_ABNORMAL":"通信失败:服务端异常",
    "STR_WEB_REQUEST_TIMEOUT":"通信失败:请求超时",
    "STR_WEB_SERVICE_UNAVAILABLE":"通信失败:服务不可用",
    "STR_WEB_SERVICE_BUSY":"后台服务正忙,请稍后重试",

    "STR_PLUG_DEVICE": "设备信息",
    "STR_PLUG_CONTROL": "全局控制插件",
    "STR_PLUG_THEME": "主题插件",
    "STR_PLUG_ALIAS": "菜单别名插件",
    "STR_PLUG_CLASS": "菜单类型插件",
    "STR_PLUG_TIP": "菜单提示插件",
    "STR_PLUG_AUTO_INSTALL": "自动安装插件",
    "STR_PLUG_PERSISTENCE": "数据持久化插件",
    "STR_PLUG_INJECTION": "文件注入插件",
    "STR_PLUG_CONF_REPLACE": "启动配置替换插件",
    "STR_PLUG_PASSWORD": "密码插件",
    "STR_PLUG_IMAGELIST": "文件列表插件",
    "STR_PLUG_AUTO_MEMDISK": "自动Memdisk插件",
    "STR_PLUG_DUD": "Driver Update Disk插件",
    "STR_PLUG_DONATION": "捐助",

    "STR_PATH_TOO_LONG": "路径超过最大支持长度,请检查!",
    "STR_INPUT_TOO_LONG": "字符串超过最大支持长度,请检查!",
longpanda's avatar
longpanda committed
525
526
527
528
    "STR_INVALID_FILE_PATH": "文件路径不合法或不存在,请检查!",    
    "STR_INVALID_FILE_PATH1": "第1个文件路径不合法或不存在,请检查!",    
    "STR_INVALID_FILE_PATH2": "第2个文件路径不合法或不存在,请检查!",    
    "STR_INVALID_NEW_FILE_PATH": "new 文件路径不合法或不存在,请检查!",    
529
530
531
532
533
534
535
536
537
538
539
540
541
    "STR_INVALID_DIR_PATH": "文件夹路径不合法,请检查!",
    "STR_INVALID_NUMBER": "请输入合法的非负整数!",
    "STR_INVALID_AUTOSEL": "autosel 的值超过了列表实际长度!",
    "STR_INVALID_TIMEOUT": "请输入合法的超时秒数!",
    "STR_INVALID_PERCENT": "请输入 0-100 以内的整数!",
    "STR_INVALID_COLOR": "请输入合法的颜色!",
    "STR_SELECT": "请选择",
    "STR_SET_ALIAS_FOR_FILE": "为文件设置别名",
    "STR_SET_ALIAS_FOR_DIR": "为目录设置别名",
    "STR_SET_TIP_FOR_FILE": "为文件设置菜单提示信息",
    "STR_SET_TIP_FOR_DIR": "为目录设置菜单提示信息",
    "STR_SET_INJECTION_FOR_FILE": "[image] 为某一个文件设置注入",
    "STR_SET_INJECTION_FOR_DIR": "[parent] 为某个目录下的所有文件设置相同的注入",
longpanda's avatar
longpanda committed
542
    "STR_INVALID_ARCHIVE_PATH": "Archive 文件路径非法或不存在,请检查!",
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
    "STR_SET_PWD_FOR_FILE": "[file] 为指定文件设置密码",
    "STR_SET_PWD_FOR_DIR": "[parent] 为某个目录下的所有文件设置相同的密码",
    "STR_SET_AUTO_INSTALL_FOR_FILE": "[image] 为某个镜像文件设置自动安装脚本",
    "STR_SET_AUTO_INSTALL_FOR_DIR": "[parent] 为某个目录下的所有文件设置相同的自动安装脚本",

    "STR_SET_CLASS_BY_KEY": "[key] 通过文件名关键字设置类型",
    "STR_SET_CLASS_BY_DIR": "[dir] 为某个目录设置类型(只针对该目录本身,不包含里面的文件及子目录)",
    "STR_SET_CLASS_BY_PARENT": "[parent] 为某个目录下的所有子文件设置类型(只针对文件,不包含目录)",

    "STR_SET_IMAGE_PWD": "[file] 为某个镜像文件设置密码",
    "STR_SET_PARENT_PWD": "[parent] 为某个目录下的所有文件设置相同的密码",


    
    "STR_SET_SEARCH_ROOT": "设置搜索目录",
    "STR_SET_DEFAULT_IMAGE": "设置默认镜像文件",
    "STR_ADD_THEME": "添加主题",
    "STR_ADD_FONT": "添加字体",
    "STR_ADD_FILE_TO_LIST": "添加文件",
    "STR_DEFAULT_SELECT": " 默认选择",
    "STR_AUTO_TEMPLATE": "自动安装脚本",
    "STR_ADD_AUTO_TEMPLATE": "添加自动安装脚本",
    "STR_PERSISTENCE_DAT": "持久化数据文件",
    "STR_ADD_PERSISTENCE_DAT": "添加持久化数据文件",
    "STR_DUD_FILE": "DUD 文件",
    "STR_ADD_DUD_FILE": "添加 DUD 文件",

    "STR_DEL_LAST": "这是本条目中的最后一项,删除此项将会删除整个条目。是否继续?",
    "STR_CLOSE_TIP": "后台服务不可用,页面即将关闭!",
    "STR_SECURE_BOOT_ENABLE": "开启",
    "STR_SECURE_BOOT_DISABLE": "未开启",
    "STR_SYNTAX_ERROR_TIP": "ventoy.json 文件中存在语法错误,配置未加载!",
575
    "STR_INVALID_CONFIG_TIP": "ventoy.json 文件中存在错误配置,配置未加载!",
576
    "STR_CONFIG_SAVE_ERROR_TIP": "ventoy.json 文件写入失败,详细信息请参考 VentoyPlugson.log 文件!",
577

longpanda's avatar
longpanda committed
578
579
580
    "STR_JSON_PREVIEW": "JSON 预览",
    "STR_JSON_COPY_SUCCESS": "JSON 内容复制成功",
    "STR_JSON_COPY_FAILED": "JSON 内容复制失败",
581
582
583
584
585
586
587
588
589
590

    "STR_XXX": "xxx"
};

var g_current_dir;
var g_current_os;
var g_current_language = 'cn';
var g_vtoy_cur_language = g_vtoy_cur_language_cn;
var g_vtoy_data_default_index = 6;

longpanda's avatar
longpanda committed
591
592
var g_bios_postfix = [ "", "_legacy", "_uefi", "_ia32", "_aa64", "_mips" ];
var g_del_all_path = '4119ae33-98ea-448e-b9c0-569aafcf1fb4';
593
594
595
596
597
598
var g_file_with_extra = false;
var g_dir_with_extra = false;
var g_file_fuzzy_match = 0;
var g_file_modal_callback;
var g_dir_modal_callback;

longpanda's avatar
longpanda committed
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
function GetResetTabConfigTipMsg(index, name) {
    var msgstr;
    
    if (g_current_language === 'en') {
        msgstr = 'Are you sure to reset all the configurations on the <code>' + name + g_bios_postfix[index] + '</code> tab ?';
    } else {
        msgstr = '确认要重置 <code>' + name + g_bios_postfix[index] + '</code> 标签页下的所有配置?';
    }
    
    return msgstr;
}

function CommonUpdateTabTitleIcon(exists, id, name) {
    var exspan = " <span id='tab_0_icon' class='fa fa-circle' style='color:red;'></span>";
    for (var i = 0; i < g_vtoy_data_default_index; i++) {
        var fid = id + i + '"]';
        var oldhtml = $(fid).html();
        var newhtml;

        if (exists[i]) {
            newhtml = name + g_bios_postfix[i] + exspan;
        } else {
            newhtml = name + g_bios_postfix[i];
        }
        
        if (newhtml != oldhtml) {
            $(fid).html(newhtml);
        }
    }
}

630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
function ventoy_file_submit(form, extra) {
    var filepath = $("#FilePath").val();
    var fileextra = $("#FileExtra").val();

    if (!filepath) {
        return;
    }

    if (extra) {
        if (!fileextra) {
            return;
        }
    }

    filepath = ventoy_replace_slash(filepath);

    if (!ventoy_common_check_path(filepath)) {
        Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH);
        return;
    }

    if (g_file_fuzzy_match && filepath.indexOf("*") >= 0) {
        callVtoySync({
            method : 'check_fuzzy',
            path: filepath
        }, function(data) {        
            if (data.exist != 0) {
                if (typeof(g_file_modal_callback) === 'function') {
                    g_file_modal_callback(filepath, -1, fileextra);
                }
                $("#SetFileModal").modal('hide');
            } else {
                Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH);
            }
       });
    } else {
        callVtoySync({
            method : 'check_path',
            dir: 0,
            path: filepath
        }, function(data) {        
            if (data.exist === 1) {
                if (typeof(g_file_modal_callback) === 'function') {
                    g_file_modal_callback(filepath, 1, fileextra);
                }
                $("#SetFileModal").modal('hide');
            } else {
                Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH);
            }
       });
    }
}


var g_filepath_validator = $("#SetFileForm").validate({
    rules: {            
        FilePath : {
            required: true,
            utfmaxlen: true,
            noquotes: true
        },
        FileExtra : {
            required: false,
            utfmaxlen: true
        }
    },
    submitHandler: function(form) {
        ventoy_file_submit(form, g_file_with_extra);
    }
});

var g_dirpath_validator = $("#SetDirForm").validate({
    rules: {            
        DirPath : {
            required: true,
            utfmaxlen: true,
            noquotes: true
        },
        DirExtra : {
            required: false,
            utfmaxlen: true
        }
    },
    submitHandler: function(form) {
        var dirpath = $("#DirPath").val();
        var dirextra = $("#DirExtra").val();
        
        if (!dirpath) {
            return;
        }

        if (g_dir_with_extra) {
            if (!dirextra) {
                return;
            }
        }

        dirpath = ventoy_replace_slash(dirpath);

        if (dirpath.length > 0 && dirpath.charCodeAt(dirpath.length - 1) === 47) {
            dirpath = dirpath.substring(0, dirpath.length - 1);
        }

        if (!ventoy_common_check_path(dirpath)) {
            Message.error(g_vtoy_cur_language.STR_INVALID_DIR_PATH);
            return;
        }

        callVtoySync({
            method : 'check_path',
            dir: 1,
            path: dirpath                
        }, function(data) {        
            if (data.exist === 1) {
                if (typeof(g_dir_modal_callback) === 'function') {
                    g_dir_modal_callback(dirpath, dirextra);
                }
                $("#SetDirModal").modal('hide');
            } else {
                Message.error(g_vtoy_cur_language.STR_INVALID_DIR_PATH);
            }
       });
    }
});

function VtoySelectFilePath(cb, para) {
    g_file_fuzzy_match = para.fuzzy;
    
    if (para.extra) {
        $('div[id=id_div_file_extra]').show();
        $('#SetFileForm_extra').text(para.extra_title);
    } else {
        $('div[id=id_div_file_extra]').hide();
    }

    $('span[id=id_span_filepath_tip1]').each(function(){
        $(this).text(para.tip1);
    });
    $('span[id=id_span_filepath_tip2]').each(function(){
        $(this).text(para.tip2);
    });
    $('span[id=id_span_filepath_tip3]').each(function(){
        $(this).text(para.tip3);
    });

    if (g_current_language === 'en') {
        if (para.title.length === 0) {
            $('#SetFileForm #SetFileForm_lang_1').text("Set File Path");
        } else {
            $('#SetFileForm #SetFileForm_lang_1').text(para.title);
        }
        
        $('#SetFileForm #SetFileForm_lang_2').text("File Path");
        $('#SetFileForm #SetFileForm_lang_3').text(" OK");
        $('#SetFileForm #SetFileForm_lang_4').text("Cancel");
        $('#SetFileForm #id_note_setfile_cn').hide();
        $('#SetFileForm #id_note_setfile_en').show();
    } else {
        if (para.title.length === 0) {
            $('#SetFileForm #SetFileForm_lang_1').text("设置文件路径");
        } else {
            $('#SetFileForm #SetFileForm_lang_1').text(para.title);
        }
        $('#SetFileForm #SetFileForm_lang_2').text("文件路径");
        $('#SetFileForm #SetFileForm_lang_3').text("确定");
        $('#SetFileForm #SetFileForm_lang_4').text("取消");
        $('#SetFileForm #id_note_setfile_cn').show();
        $('#SetFileForm #id_note_setfile_en').hide();
    }

    if (para.tip3.length > 0) {
        if (g_current_language === 'en') {
            $('#SetFileForm #id_note_tip3_en').show();
            $('#SetFileForm #id_note_tip3_cn').hide();
        } else {
            $('#SetFileForm #id_note_tip3_cn').show();
            $('#SetFileForm #id_note_tip3_en').hide();
        }
    } else {
        $('#SetFileForm #id_note_tip3_en').hide();
        $('#SetFileForm #id_note_tip3_cn').hide();
    }

    g_file_modal_callback = cb;
    g_file_with_extra = para.extra;
    g_filepath_validator.settings.rules.FileExtra.required = g_file_with_extra;
    g_filepath_validator.resetForm();
    $("#SetFileModal").modal();            
}


function VtoySelectDirPath(cb, para) {
    $('span[id=id_span_dirpath_tip]').each(function(){
        $(this).text(para.tip);
    });
    $('span[id=id_span_dirpath_tip3]').each(function(){
        $(this).text(para.tip3);
    });

    if (para.extra) {
        $('div[id=id_div_dir_extra]').show();
        $('label[id=SetDirForm_extra]').text(para.extra_title);
    } else {
        $('div[id=id_div_dir_extra]').hide();
    }

    if (g_current_language === 'en') {
        if (para.title.length === 0) {
            $('#SetDirForm #SetDirForm_lang_1').text("Set Directory Path");
        } else {
            $('#SetDirForm #SetDirForm_lang_1').text(para.title);
        }
        $('#SetDirForm #SetDirForm_lang_2').text("Directory Path");
        $('#SetDirForm #SetDirForm_lang_3').text(" OK");
        $('#SetDirForm #SetDirForm_lang_4').text("Cancel");
        $('#SetDirForm #id_note_setfile_cn').hide();
        $('#SetDirForm #id_note_setfile_en').show();
    } else {
        if (para.title.length === 0) {
            $('#SetDirForm #SetDirForm_lang_1').text("设置文件夹路径");
        } else {
            $('#SetDirForm #SetDirForm_lang_1').text(para.title);
        }
        $('#SetDirForm #SetDirForm_lang_2').text("文件夹路径");
        $('#SetDirForm #SetDirForm_lang_3').text("确定");
        $('#SetDirForm #SetDirForm_lang_4').text("取消");
        $('#SetDirForm #id_note_setfile_cn').show();
        $('#SetDirForm #id_note_setfile_en').hide();
    }

    if (para.tip3.length > 0) {
        if (g_current_language === 'en') {
            $('#SetDirForm #id_note_tip3_en').show();
            $('#SetDirForm #id_note_tip3_cn').hide();
        } else {
            $('#SetDirForm #id_note_tip3_cn').show();
            $('#SetDirForm #id_note_tip3_en').hide();
        }
    } else {
        $('#SetDirForm #id_note_tip3_en').hide();
        $('#SetDirForm #id_note_tip3_cn').hide();
    }

    g_dir_modal_callback = cb;
    g_dir_with_extra = para.extra;
    g_dirpath_validator.settings.rules.DirExtra.required = g_dir_with_extra;
    g_dirpath_validator.resetForm(); 
    $("#SetDirModal").modal();            
}

function VtoyCommonChangeLanguage(newlang) {
    if (newlang === 'en') {
        g_vtoy_cur_language = g_vtoy_cur_language_en;
        ;$.extend($.validator.messages, {
            required: "This field is required",
            remote: "Please modify this field",    
            maxlength: $.validator.format("You can enter up to {0} characters"),
            minlength: $.validator.format("Must enter at least {0} characters"),
            rangelength: $.validator.format("Please input {0} to {1} characters"),
            range: $.validator.format("The input range is from {0} to {1}"),
            max: $.validator.format("Please input a number less than or equal to {0}"),
            min: $.validator.format("Please input a number bigger than or equal to {0}"),
            utfmaxlen: $.validator.format("The string exceeds the maximum supported length"),
            start_slash: $.validator.format("Must start with /"),
            noquotes: $.validator.format("Can not include double quotes"),
895
            filenamepart:$.validator.format("As part of file name, can not include invalid characters"),
896
897
898
899
900
901
902
903
904
905
906
907
908
            printascii: $.validator.format("Can not include non-ascii characters.")
        });

        $("a[id=id_a_official_doc]").each(function(){
            var oldlink = $(this).attr('href');
            var newlink = oldlink.replace("/cn/", "/en/");
            $(this).attr('href', newlink);
        });
        
        $("span[id=id_span_official_doc]").each(function(){
            $(this).text(" Plugin Official Document");
        });
        
longpanda's avatar
longpanda committed
909
910
        $('#id_span_copy').text("Copy");
        $('#id_span_preview').text("Preview");
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
        $('#id_span_language').text("中文");
        
        $("tr[id=tr_title_desc_cn]").each(function(){
            $(this).hide();
        });
        
        $("tr[id=tr_title_desc_en]").each(function(){
            $(this).show();
        });
      
        $("th[id=id_th_file_path]").each(function(){
            $(this).text("Full File Path");
        });

        $("span[id=id_span_desc_cn]").each(function(){
            $(this).hide();
        });

    } else {
        g_vtoy_cur_language = g_vtoy_cur_language_cn;
        ;$.extend($.validator.messages, {
            required: "这是必填字段",
            remote: "请修正此字段",    
            maxlength: $.validator.format("最多可以输入 {0} 个字符"),
            minlength: $.validator.format("最少要输入 {0} 个字符"),
            rangelength: $.validator.format("请输入长度在 {0} 到 {1} 之间的字符串"),
            range: $.validator.format("取值范围{0}到{1}"),
            max: $.validator.format("请输入不大于 {0} 的数值"),
            min: $.validator.format("请输入不小于 {0} 的数值"),
            utfmaxlen: $.validator.format("超过最大长度"),
            start_slash: $.validator.format("必须以反斜杠 / 开头"),
            noquotes: $.validator.format("不能包含双引号"),
943
            filenamepart:$.validator.format("作为文件名的一部分,不能包含特殊的符号"),
944
945
946
947
948
949
950
951
952
953
954
955
956
            printascii: $.validator.format("不能包含中文或其他非 ascii 字符。")
        });
        
        $("a[id=id_a_official_doc]").each(function(){
            var oldlink = $(this).attr('href');
            var newlink = oldlink.replace("/en/", "/cn/");
            $(this).attr('href', newlink);
        });
        
        $("span[id=id_span_official_doc]").each(function(){
            $(this).text(" 插件官网文档");
        });
        
longpanda's avatar
longpanda committed
957
958
        $('#id_span_copy').text("复制");
        $('#id_span_preview').text("预览");
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
        $('#id_span_language').text("English");
        
        $("tr[id=tr_title_desc_cn]").each(function(){
            $(this).show();
        });
        
        $("tr[id=tr_title_desc_en]").each(function(){
            $(this).hide();
        });
        
        $("th[id=id_th_file_path]").each(function(){
            $(this).text("文件路径");
        });

        $("span[id=id_span_desc_cn]").each(function(){
            $(this).show();
        });
    }

    $("span[id=id_span_menu_device]").text(g_vtoy_cur_language.STR_PLUG_DEVICE);
    $("span[id=id_span_menu_control]").text(g_vtoy_cur_language.STR_PLUG_CONTROL);
    $("span[id=id_span_menu_theme]").text(g_vtoy_cur_language.STR_PLUG_THEME);
    $("span[id=id_span_menu_alias]").text(g_vtoy_cur_language.STR_PLUG_ALIAS);
    $("span[id=id_span_menu_tip]").text(g_vtoy_cur_language.STR_PLUG_TIP);
    $("span[id=id_span_menu_class]").text(g_vtoy_cur_language.STR_PLUG_CLASS);
    $("span[id=id_span_menu_auto_install]").text(g_vtoy_cur_language.STR_PLUG_AUTO_INSTALL);
    $("span[id=id_span_menu_persistence]").text(g_vtoy_cur_language.STR_PLUG_PERSISTENCE);
    $("span[id=id_span_menu_injection]").text(g_vtoy_cur_language.STR_PLUG_INJECTION);
    $("span[id=id_span_menu_conf_replace]").text(g_vtoy_cur_language.STR_PLUG_CONF_REPLACE);
    $("span[id=id_span_menu_password]").text(g_vtoy_cur_language.STR_PLUG_PASSWORD);
    $("span[id=id_span_menu_imagelist]").text(g_vtoy_cur_language.STR_PLUG_IMAGELIST);
    $("span[id=id_span_menu_auto_memdisk]").text(g_vtoy_cur_language.STR_PLUG_AUTO_MEMDISK);
    $("span[id=id_span_menu_dud]").text(g_vtoy_cur_language.STR_PLUG_DUD);
    $('#id_span_save').text(g_vtoy_cur_language.STR_SAVE);
    $('#id_span_reset').text(g_vtoy_cur_language.STR_RESET);
    $('#id_span_donation').text(g_vtoy_cur_language.STR_PLUG_DONATION);
longpanda's avatar
longpanda committed
995
996
997
998
    
    $('span[id=id_btn_span_reset]').each(function(){
        $(this).text(' ' + g_vtoy_cur_language.STR_RESET);
    });
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
    $("span[id=id_span_btn_add]").each(function(){
        $(this).text(g_vtoy_cur_language.STR_ADD);
    });
    $("span[id=id_span_btn_del]").each(function(){
        $(this).text(g_vtoy_cur_language.STR_DEL);
    });

    $("span[id=id_span_enable]").each(function(){
        $(this).text(g_vtoy_cur_language.STR_ENABLE);
    });

    $("th[id=id_th_operation]").each(function(){
        $(this).text(g_vtoy_cur_language.STR_OPERATION);
    });
    $("th[id=id_th_status]").each(function(){
        $(this).text(g_vtoy_cur_language.STR_STATUS);
    });

    $('span [id=id_span_valid').each(function(){
        $(this).text(g_vtoy_cur_language.STR_VALID);
    });
    $('span [id=id_span_invalid').each(function(){
        $(this).text(g_vtoy_cur_language.STR_INVALID);
    });

    $("td[id=td_title_desc]").each(function(){
        $(this).text(g_vtoy_cur_language.STR_OPT_DESC);
    });
    
    $("td[id=td_title_setting]").each(function(){
        $(this).text(g_vtoy_cur_language.STR_OPT_SETTING);
    });
}

  
function ventoy_get_status_line(dir, exist) {
    if (dir) {
        if (exist === 0) {
        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>';
        } else {
        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>';
        }
    } else {
        if (exist === -1) {
        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>';
        } else if (exist === 1) {
        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>';
        } else {
        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>';
        }
    }
}



var g_type_select_callback;

var g_type_select_validator = $("#TypeSelectForm").validate({    
    submitHandler: function(form) {
        var sel =  parseInt($('input:radio[name=name_select_type_radio]:checked').val());
        if (typeof(g_type_select_callback) === 'function') {
            g_type_select_callback(sel);
        }

        $("#TypeSelectModal").modal('hide');
    }
});

function VtoySelectType(cb, para) {

    $('#TypeSelectForm #TypeSelForm_lang_1').text(g_vtoy_cur_language.STR_SELECT);
1070
    
1071
    if (g_current_language === 'en') {
1072
1073
        $('#TypeSelectForm #TypeSelForm_lang_2').text(" OK");
        $('#TypeSelectForm #TypeSelForm_lang_3').text("Cancel");
1074
    } else {
1075
1076
        $('#TypeSelectForm #TypeSelForm_lang_2').text("确定");
        $('#TypeSelectForm #TypeSelForm_lang_3').text("取消");
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
    }
    
    var $tbl = $("#id_type_select_table tbody");
    $tbl.empty();

    for (var i = 0; i < para.length; i++) {
        var $tr;

        if (para[i].selected) {
            $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>');
        } else {
            $tr = $('<tr><td><label class="radio-inline"><input type="radio" name="name_select_type_radio" value="' + i + '"/>' + para[i].tip + '</label></td></tr>');
        }

        $tbl.append($tr);
    }

    g_type_select_callback = cb;
    g_type_select_validator.resetForm(); 
    $("#TypeSelectModal").modal();            
}


var g_set_key_callback;

var g_set_key_validator = $("#SetKeyForm").validate({    
    rules: {            
        SetKeyKey : {
            required: true,
            utfmaxlen: true      
        },
        SetKeyValue : {
            required: true,
1110
1111
            utfmaxlen: true,
            filenamepart: true        
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
        }
    },

    submitHandler: function(form) {
        var key = $('input:text[id=SetKeyKey]').val();
        var val = $('input:text[id=SetKeyValue]').val();

        if ((!key) || (!val))
        {
            return;
        }

        if (typeof(g_set_key_callback) === 'function') {
            g_set_key_callback(key, val);
        }

        $("#SetKeyModal").modal('hide');
    }
});

function VtoySetKey(cb, para) {

    $('#SetKeyForm #SetKeyForm_lang_1').text(para.title);
    $('#SetKeyForm #SetKeyForm_lang_2').text(para.title1);
    $('#SetKeyForm #SetKeyForm_lang_3').text(para.title2);

    if (g_current_language === 'en') {
1139
1140
        $('#SetKeyForm #SetKeyForm_lang_4').text(" OK");
        $('#SetKeyForm #SetKeyForm_lang_5').text("Cancel");
1141
    } else {
1142
1143
        $('#SetKeyForm #SetKeyForm_lang_4').text("确定");
        $('#SetKeyForm #SetKeyForm_lang_5').text("取消");
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
    }
    
    g_set_key_callback = cb;
    g_set_key_validator.resetForm(); 
    $("#SetKeyModal").modal();            
}

var g_valid_color_name = [
    "black",
    "blue",
    "green",
    "cyan",
    "red",
    "magenta",
    "brown",
    "light-gray",
    "dark-gray",
    "light-blue",
    "light-green",
    "light-cyan",
    "light-red",
    "light-magenta",
    "yellow",
    "white"
];

function ventoy_check_color(color) {
    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)) {
        return true;
    } else {
        for (var i = 0; i < g_valid_color_name.length; i++) {
            if (g_valid_color_name[i] === color) {
                return true;
            }
        }
    }

    return false;
}

function ventoy_check_percent(percent) {
    if (percent.length > 0) {
        return true;
    } else {
        return false;
    }
}


function ventoy_check_file_path(isopath, fuzzy, cb) {
    if (fuzzy && isopath.indexOf("*") >= 0) {
        callVtoySync({
            method : 'check_fuzzy',
            path: isopath
        }, function(data) {        
            if (data.exist != 0) {
                if (typeof(cb) === 'function') {
                    cb(data.exist);
                }
            } else {
                Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH);
            }
        });
    } else {
        callVtoySync({
            method : 'check_path',
            dir: 0,
            path: isopath
        }, function(data) {        
            if (data.exist === 1) {
                if (typeof(cb) === 'function') {
                    cb(data.exist);
                }
            } else {
                Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH);
            }
        });
    }
}

function ventoy_random_string(e) {  
    var t = "abcdefhijkmnprstwxyz2345678";
    var a = t.length;
    var n = "";

    e = e || 4;
    for (i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
    return n
}


var g_set_filefile_callback;

var g_set_filefile_validator = $("#SetFileFileForm").validate({    
    rules: {            
        FileFilePath1 : {
            required: true,
            utfmaxlen: true
        },
        FileFilePath2 : {
            required: true,
            utfmaxlen: true          
        }
    },

    submitHandler: function(form) {
        var path1 = $('input:text[id=FileFilePath1]').val();
        var path2 = $('input:text[id=FileFilePath2]').val();

        if ((!path1) || (!path2))
        {
            return;
        }

        path1 = ventoy_replace_slash(path1);

        if (!ventoy_common_check_path(path1)) {
            Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH1);
            return;
        }

        path2 = ventoy_replace_slash(path2);

        if (!ventoy_common_check_path(path2)) {
            Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH2);
            return;
        }

        callVtoy({
            method : 'check_path2',
            dir1: 0,
            fuzzy1: 1,
            path1: path1,
            dir2: 0,
            fuzzy2: 0,
            path2: path2
        }, function(retdata) {
            if (retdata.exist1 != 0 && retdata.exist2 != 0) {
                if (typeof(g_set_filefile_callback) === 'function') {
                    g_set_filefile_callback(retdata.exist1, path1, path2);
                }

                $("#SetFileFileModal").modal('hide');
            } else if (retdata.exist1 === 0) {
              Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH1);
            } else {
              Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH2);
            }
        });
    }
});

function VtoySetFileFile(cb, para) {

    $('#SetFileFileForm #SetFileFileForm_title').text(para.title);
    $('#SetFileFileForm #SetFileFileForm_label1').text(para.label1);
    $('#SetFileFileForm #SetFileFileForm_label2').text(para.label2);

    if (g_current_language === 'en') {
        $('#SetFileFileForm #SetFileFileForm_ok').text(" OK");
        $('#SetFileFileForm #SetFileFileForm_cancel').text("Cancel");

        $('#SetFileFileForm #id_note_filefile_cn').hide();
        $('#SetFileFileForm #id_note_filefile_en').show();

    } else {
        $('#SetFileFileForm #SetFileFileForm_ok').text("确定");
        $('#SetFileFileForm #SetFileFileForm_cancel').text("取消");

        $('#SetFileFileForm #id_note_filefile_en').hide();
        $('#SetFileFileForm #id_note_filefile_cn').show();
    }

    $('span[id=id_span_filefile_tip1]').each(function(){
        $(this).text(para.tip1);
    });
    $('span[id=id_span_filefile_tip2]').each(function(){
        $(this).text(para.tip2);
    });
    $('span[id=id_span_filefile_tip3]').each(function(){
        $(this).text(para.tip3);
    });
    
    g_set_filefile_callback = cb;
    g_set_filefile_validator.resetForm(); 
    $("#SetFileFileModal").modal();
}


var g_set_dirfile_callback;

var g_set_dirfile_validator = $("#SetDirFileForm").validate({    
    rules: {            
        DirFilePath1 : {
            required: true,
            utfmaxlen: true
        },
        DirFilePath2 : {
            required: true,
            utfmaxlen: true          
        }
    },

    submitHandler: function(form) {
        var path1 = $('input:text[id=DirFilePath1]').val();
        var path2 = $('input:text[id=DirFilePath2]').val();

        if ((!path1) || (!path2))
        {
            return;
        }

        path1 = ventoy_replace_slash(path1);

        if (!ventoy_common_check_path(path1)) {
            Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH1);
            return;
        }

        path2 = ventoy_replace_slash(path2);

        if (!ventoy_common_check_path(path2)) {
            Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH2);
            return;
        }

        callVtoy({
            method : 'check_path2',
            dir1: 1,
            fuzzy1: 0,
            path1: path1,
            dir2: 0,
            fuzzy2: 0,
            path2: path2
        }, function(retdata) {
            if (retdata.exist1 != 0 && retdata.exist2 != 0) {
                if (typeof(g_set_dirfile_callback) === 'function') {
                    g_set_dirfile_callback(path1, path2);
                }

                $("#SetDirFileModal").modal('hide');
            } else if (retdata.exist1 === 0) {
              Message.error(g_vtoy_cur_language.STR_INVALID_DIR_PATH);
            } else {
              Message.error(g_vtoy_cur_language.STR_INVALID_FILE_PATH2);
            }
        });
    }
});

function VtoySetDirFile(cb, para) {

    $('#SetDirFileModal #SetDirFileForm_title').text(para.title);
    $('#SetDirFileModal #SetDirFileForm_label1').text(para.label1);
    $('#SetDirFileModal #SetDirFileForm_label2').text(para.label2);

    if (g_current_language === 'en') {
1401
1402
        $('#SetDirFileModal #SetDirFileForm_ok').text(" OK");
        $('#SetDirFileModal #SetDirFileForm_cancel').text("Cancel");
1403
1404
1405
1406
1407

        $('#SetDirFileModal #id_note_dirfile_cn').hide();
        $('#SetDirFileModal #id_note_dirfile_en').show();

    } else {
1408
1409
        $('#SetDirFileModal #SetDirFileForm_ok').text("确定");
        $('#SetDirFileModal #SetDirFileForm_cancel').text("取消");
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451

        $('#SetDirFileModal #id_note_dirfile_en').hide();
        $('#SetDirFileModal #id_note_dirfile_cn').show();
    }

    $('span[id=id_span_dirfile_tip1]').each(function(){
        $(this).text(para.tip1);
    });
    $('span[id=id_span_dirfile_tip2]').each(function(){
        $(this).text(para.tip2);
    });
    
    g_set_dirfile_callback = cb;
    g_set_dirfile_validator.resetForm(); 
    $("#SetDirFileModal").modal();
}

function ventoy_get_xslg_addbtn(mclass) {
    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>';
}

function ventoy_get_xslg_delbtn(mclass) {
    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>';
}

function ventoy_get_addbtn(mclass) {
    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>';
}

function ventoy_get_delbtn(mclass) {
    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>';
}

function ventoy_confirm(title, cb, data1, data2) {
    Modal.confirm({msg:g_vtoy_cur_language.STR_DEL_LAST}).on(function(e) {
        if (e) {
            if (typeof(cb) === 'function') {
                cb(data1, data2);
            }
        }
    });
}