This repository has been archived by the owner on Apr 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
设置备份
95 lines (88 loc) · 2.37 KB
/
设置备份
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
//Name: 设置备份
//Strokesplus.Net Version: 0.3.1.9+
//Author: f9y4ng#gmail.com
//声明变量
var rs = 0;
var info = "";
var t_files = [];
var f_config_main = "";
var f_config_backup = "";
//可以自定义
var SourceFolder = "D:\\Program Files\\StrokesPlus.net"; //定义StrokesPlus.net的安装目录
var BackupFolder = SourceFolder + "\\backup"; //定义备份文件夹目录
var n_range = 20; // 定义备份数量(将按时间倒序进行清理,仅保存最近的配置备份)
//下面代码如果你看不懂最好别动
var date = DateTime.Now.ToString("yyyy-MM-dd_HHmmss");
var p_SPlusNetMainFile = SourceFolder + "\\StrokesPlus.net.bin"
var p_SPlusNetBackupFile = BackupFolder + "\\StrokesPlus.net." + date + ".bin"
function BackupConfigFile() {
// FUNCTIONS
function tInsert(arr, str)
{
var size = arr.length;
arr[size] = str;
return arr;
}
function tReverse(arr)
{
for (i = 0; i < arr.length / 2; i++) {
temp = arr[i];
arr[i] = arr[arr.length - i - 1];
arr[arr.length - i - 1] = temp;
}
return arr;
}
// GET FILES
var MainFile = clr.System.IO.Directory.GetFiles(SourceFolder, "*.bin");
var file = new FileInfo(MainFile[0]);
var name = file.Name;
var date_time = file.LastWriteTime;
var size = file.Length;
if (name == "StrokesPlus.net.bin")
{
f_config_main = date_time;
}
var files = clr.System.IO.Directory.GetFiles(BackupFolder);
if (files.Length > 0) {
for (var i = 0; i < files.Length; i++) {
file = new FileInfo(files[i]);
name = file.Name;
date_time = file.LastWriteTime;
var bsize = file.Length;
var patt = /^StrokesPlus\.net\.[0-9-_]+\.bin$/ig;
if (patt.test(name))
{
f_config_backup = date_time;
bsize = bsize;
tInsert(t_files, name);
}
}
} else {
f_config_backup = "null";
}
// BACKUP&CLEAN
if (f_config_main != f_config_backup)
{
if(size != bsize)
{
File.Copy(p_SPlusNetMainFile, p_SPlusNetBackupFile);
if (t_files.length >= n_range)
{
tReverse(t_files); // reverse table
for (var i = (n_range - 1); i < t_files.length; i++) {
File.Delete(BackupFolder + "\\" + t_files[i]);
}
}
rs = 1;
}
}
//NOTICE
if (rs == 1) {
info = "设置文件备份完成!\n备份创建时间:" + DateTime.Now.ToString();
} else {
info = "设置文件无更新,无需新备份";
}
sp.ShowBalloonTip("备份", info, "Info", 5000);
}
//RUN BACKUP
BackupConfigFile();