-
Notifications
You must be signed in to change notification settings - Fork 2
/
Form1.cs
351 lines (350 loc) · 14.4 KB
/
Form1.cs
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
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
323
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
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.Versioning;
using System.Windows.Forms;
using FFXIVBackupTool;
using ICSharpCode.SharpZipLib.Zip;
using Microsoft.Win32;
namespace BackupTool
{
[SupportedOSPlatform("windows")]
public partial class Form1 : Form
{
public const string ToolVersion = "1.0.5"; //版本号
public Form1()
{
InitializeComponent();
}
private void Button3_Click(object sender, EventArgs e)
{
string path = ReadGamePath(1);
if (path == null)
{
MessageBox.Show("没有读取到国服游戏目录,请手动选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
textBox1.Text = path;
}
private void Button5_Click(object sender, EventArgs e)
{
string path = ReadGamePath(2);
if (path == null)
{
MessageBox.Show("没有读取到国际服游戏目录,请手动选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
textBox2.Text = path;
}
private void Button4_Click(object sender, EventArgs e)
{
//先判断输入框有没有路径,没有就不做任何操作
if (textBox1.Text == "")
{
MessageBox.Show("请先选择或获取国服游戏路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
//判断当前目录是否存在
if (File.Exists(@".\FFXIVBackupPackage-CHN.zip"))
{
DialogResult result = MessageBox.Show("当前目录下已有国服数据备份,是否覆盖?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
if (result == DialogResult.No)
{
return;
}
}
CHNButtonDisable();
File.Delete(@".\FFXIVBackupPackage-CHN.zip");
using var bw = new BackgroundWorker();
bw.DoWork += (s, a) =>
{
try
{
string startPath = textBox1.Text;
string zipPath = @".\FFXIVBackupPackage-CHN.zip";
FastZip compressfile = new();
compressfile.CreateZip(zipPath, startPath, true, @"-\.log$");
}
catch
{
MessageBox.Show("备份失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
};
bw.RunWorkerCompleted += (s, b) =>
{
CHNButtonEnable();
MessageBox.Show("国服数据已备份至当前目录下FFXIVBackupPackage-CHN.zip", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
};
bw.RunWorkerAsync();
}
private void Bw_DoWork(object sender, DoWorkEventArgs e)
{
throw new NotImplementedException();
}
private void Button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderBrowserDialog = new()
{
Description = "请选择国服游戏目录:",
ShowNewFolderButton = false
};
FolderBrowserDialog dialog = folderBrowserDialog;
if (dialog.ShowDialog() == DialogResult.OK)
{
textBox1.Text = dialog.SelectedPath;
}
}
private void Button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderBrowserDialog = new()
{
Description = "请选择当前用户文档下的My Games文件夹:",
ShowNewFolderButton = false
};
FolderBrowserDialog dialog = folderBrowserDialog;
if (dialog.ShowDialog() == DialogResult.OK)
{
textBox2.Text = dialog.SelectedPath;
}
}
private void Button6_Click(object sender, EventArgs e)
{
//先判断输入框有没有路径,没有就不做任何操作
if (textBox2.Text == "")
{
MessageBox.Show("请先选择或获取国际服游戏路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
else
{
//判断当前目录是否存在文件
if (File.Exists(@".\FFXIVBackupPackage-Intl.zip"))
{
DialogResult result = MessageBox.Show("当前目录下已有国际服备份文件,是否覆盖?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
if (result == DialogResult.No)
{
return;
}
}
IntlButtonDisable();
File.Delete(@".\FFXIVBackupPackage-Intl.zip");
using var bw = new BackgroundWorker();
bw.DoWork += (s, a) =>
{
try
{
string startPath = textBox2.Text + "\\FINAL FANTASY XIV - A Realm Reborn";
string zipPath = @".\FFXIVBackupPackage-Intl.zip";
FastZip compressfile = new();
compressfile.CreateZip(zipPath, startPath, true, @"-\.log$");
}
catch
{
MessageBox.Show("备份失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
};
bw.RunWorkerCompleted += (s, b) =>
{
//置灰的按钮还原
IntlButtonEnable();
MessageBox.Show("国际服数据已备份至当前目录下FFXIVBackupPackage-Intl.zip", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
};
bw.RunWorkerAsync();
}
}
private void Button7_Click(object sender, EventArgs e)
{
//先判断输入框有没有路径,没有就不做任何操作
if (textBox1.Text == "")
{
MessageBox.Show("请先选择或获取国服游戏路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
else
{
//判断当前目录是否存在还原包
if (File.Exists(@".\FFXIVBackupPackage-CHN.zip"))
{
DialogResult result = MessageBox.Show("你真的要还原国服数据吗?原有数据将会被删除并覆盖!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
if (result == DialogResult.No)
{
return;
}
}
else
{
MessageBox.Show("未发现国服备份数据包", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
//如果有目录先删除
if (Directory.Exists(textBox1.Text + "\\FINAL FANTASY XIV - A Realm Reborn"))
{
Directory.Delete(textBox1.Text + "\\FINAL FANTASY XIV - A Realm Reborn", true);
}
CHNButtonDisable();
using var bw = new BackgroundWorker();
bw.DoWork += (s, a) =>
{
try
{
string zipPath = @".\FFXIVBackupPackage-CHN.zip";
string extractPath = textBox1.Text;
FastZip decompressfile = new();
decompressfile.ExtractZip(zipPath, extractPath, null);
}
catch
{
MessageBox.Show("还原失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
};
bw.RunWorkerCompleted += (s, b) =>
{
CHNButtonEnable();
MessageBox.Show("国服数据已还原", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
};
bw.RunWorkerAsync();
}
}
private void Button8_Click(object sender, EventArgs e)
{
//先判断输入框有没有路径,没有就不做任何操作
if (textBox2.Text == "")
{
MessageBox.Show("请先选择或获取国际服游戏路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
//判断当前目录是否存在还原包
if (File.Exists(@".\FFXIVBackupPackage-Intl.zip"))
{
DialogResult result = MessageBox.Show("你真的要还原国际服数据吗?原有数据将会被删除并覆盖!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
if (result == DialogResult.No)
{
return;
}
}
else
{
MessageBox.Show("未发现国际服备份数据包", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
//如果有目录先删除
if (Directory.Exists(textBox2.Text + "\\FINAL FANTASY XIV - A Realm Reborn"))
{ Directory.Delete(textBox2.Text + "\\FINAL FANTASY XIV - A Realm Reborn", true); }
IntlButtonDisable();
using var bw = new BackgroundWorker();
bw.DoWork += (s, a) =>
{
try
{
string zipPath = @".\FFXIVBackupPackage-Intl.zip";
string extractPath = textBox2.Text;
FastZip decompressfile = new();
decompressfile.ExtractZip(zipPath, extractPath, null);
}
catch
{
MessageBox.Show("还原失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
};
bw.RunWorkerCompleted += (s, b) =>
{
IntlButtonEnable();
MessageBox.Show("国际服数据已还原", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
};
bw.RunWorkerAsync();
}
/* 以下是公共函数 */
//国服相关控件置灰
public void CHNButtonDisable()
{
label3.Visible = true;
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button7.Enabled = false;
}
//国服相关控件还原
public void CHNButtonEnable()
{
label3.Visible = false;
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button7.Enabled = true;
}
//国际服相关控件置灰
public void IntlButtonDisable()
{
label3.Visible = true;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button8.Enabled = false;
}
//国际服相关控件还原
public void IntlButtonEnable()
{
label3.Visible = false;
button4.Enabled = true;
button5.Enabled = true;
button6.Enabled = true;
button8.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text += "" + ToolVersion;
this.Update();
}
//读目录策略,1是国服官网,2是国际服,3是国服wegame(暂不使用)
public static string ReadGamePath(int a)
{
if (a == 1)
{
//国服策略,通过注册表读目录
try
{
string value32 = String.Empty;
RegistryKey localKey32 = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);
localKey32 = localKey32.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\FFXIV");
if (localKey32 != null)
{
value32 = localKey32.GetValue("UninstallString").ToString();
localKey32.Close();
}
return value32.Replace("uninst.exe", "") + "game\\My Games";
}
catch
{
return null;
}
}
else if (a == 2)
{
//国际服策略,读取环境变量拼接目录
try
{
string userfolder = Environment.GetEnvironmentVariable("USERPROFILE");
if (Directory.Exists(userfolder + "\\Documents\\My Games\\FINAL FANTASY XIV - A Realm Reborn"))
{
return userfolder + "\\Documents\\My Games";
}
}
catch
{
return null;
}
}
else if (a == 3)
{
//预留wegame相关
}
return null;
}
private void ToolStripMenuItem2_Click(object sender, EventArgs e)
{
Form about = new Form2();
about.ShowDialog();
}
private void OneDrive备份BToolStripMenuItem_Click(object sender, EventArgs e)
{
Form about = new Form4();
about.Show();
}
}
}