forked from tModLoader/tModLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestoreTask.cs
45 lines (42 loc) · 1.24 KB
/
RestoreTask.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
using System;
using System.IO;
using System.Windows.Forms;
namespace Installer
{
class RestoreTask : Task
{
private bool vanilla;
public RestoreTask(bool vanilla)
{
this.vanilla = vanilla;
}
protected override bool DoTask(DoWorkArgs args)
{
string file = Installer.GetPath();
if (!File.Exists(file))
{
MessageBox.Show("The file " + file + " does not exist.", "Restore Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
string backupFile = "Resources" + Path.DirectorySeparatorChar + "Backups";
if (!File.Exists(backupFile))
{
MessageBox.Show("Either tModLoader has not been installed or the backups resource file is missing.",
"Restore Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
ZipFile backups = ZipFile.Read(backupFile);
string fetchFile = vanilla ? "Vanilla" : "tModLoader";
if (!backups.HasFile(fetchFile))
{
MessageBox.Show("Missing " + file + " from Backups resources", "Installation Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
File.WriteAllBytes(file, backups[fetchFile]);
MessageBox.Show("Success!", "Restore", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true;
}
}
}