forked from tModLoader/tModLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetupTask.cs
102 lines (100 loc) · 2.84 KB
/
SetupTask.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
using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;
using Ionic.Zlib;
namespace Installer
{
class SetupTask : Task
{
protected override bool DoTask(DoWorkArgs args)
{
ProgressChangedArgs pass = new ProgressChangedArgs();
pass.maxProgress = 1;
pass.header = "";
pass.message = "";
pass.main = args.main;
ReportProgress(args.background, 0, pass);
Directory.CreateDirectory("Setup");
if (!CreateResources(args, pass, "Windows", new string[]
{
"Windows.exe",
"Mac.exe",
"FNA.dll",
"Content" + Path.DirectorySeparatorChar + "MysteryItem.png"
}))
{
return false;
}
if (!CreateResources(args, pass, "Mac", new string[]
{
"Windows.exe",
"Mac.exe",
"Microsoft.Xna.Framework.dll",
"Microsoft.Xna.Framework.Game.dll",
"Microsoft.Xna.Framework.Graphics.dll",
"Microsoft.Xna.Framework.Xact.dll",
"MP3Sharp.dll",
"Content" + Path.DirectorySeparatorChar + "MysteryItem.png"
}))
{
return false;
}
if (!CreateResources(args, pass, "Linux", new string[]
{
"Windows.exe",
"Linux.exe",
"Microsoft.Xna.Framework.dll",
"Microsoft.Xna.Framework.Game.dll",
"Microsoft.Xna.Framework.Graphics.dll",
"Microsoft.Xna.Framework.Xact.dll",
"MP3Sharp.dll",
"Content" + Path.DirectorySeparatorChar + "MysteryItem.png"
}))
{
return false;
}
MessageBox.Show("Success!", "Setup", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true;
}
private bool CreateResources(DoWorkArgs args, ProgressChangedArgs pass, string platform, string[] files)
{
pass.maxProgress = 2 * files.Length + 1;
pass.header = "Creating " + platform + " installation resources";
pass.message = "Finding files...";
ReportProgress(args.background, 0, pass);
string prefix = "Setup" + Path.DirectorySeparatorChar;
for (int k = 0; k < files.Length; k++)
{
files[k] = prefix + files[k];
if (!File.Exists(files[k]))
{
MessageBox.Show("The file " + files[k] + " does not exist.", "Setup Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
Directory.CreateDirectory("Resources");
try
{
ZipFile zip = new ZipFile("Resources" + Path.DirectorySeparatorChar + "Install_" + platform);
foreach (string file in files)
{
string fileName = file.Substring(prefix.Length);
fileName = fileName.Replace(Path.DirectorySeparatorChar, '/');
pass.message = "Packing " + fileName + "...";
ReportProgress(args.background, -1, pass);
zip[fileName] = File.ReadAllBytes(file);
}
zip.Write(this, args, pass);
}
catch (Exception e)
{
MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace, "Setup Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
return true;
}
}
}