-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
197 lines (177 loc) · 6.96 KB
/
MainForm.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Diagnostics;
namespace Launcher
{
public partial class MainForm : DevComponents.DotNetBar.Metro.MetroForm
{
string[] fileconf;
bool isUpdateLauncher;
bool isUpdateGame;
string server;
string name;
string[] ver;
bool updateGame = false;
public MainForm()
{
InitializeComponent();
}
private void MenuResolution_Click(object sender, EventArgs e)
{
}
private void MenuPlay_Click(object sender, EventArgs e)
{
Process.Start(fileconf[3] + "Steam.exe", "-applaunch 105600");
this.Close();
}
private void MenuLanguage0_Click(object sender, EventArgs e)
{
}
private void MainForm_Load(object sender, EventArgs e)
{
fileconf = File.ReadAllText("Server.txt").Split('\n');
if (fileconf.Length < 4)
{
lblStatus.Text = "Configuring for first time usage.";
rtbUpdate.AppendText("\n- Configuring for first time usage.");
File.WriteAllText("Server.txt", "http://127.0.0.1/"+ Environment.NewLine +"true" + Environment.NewLine +"true" + Environment.NewLine + @"C:\Program Files\Steam\");
fileconf = File.ReadAllText("Server.txt").Split('\n');
}
server = fileconf[0].Trim();
isUpdateLauncher = bool.Parse(fileconf[1]);
isUpdateGame = bool.Parse(fileconf[2]);
using (WebClient ww = new WebClient())
{
ww.DownloadStringAsync(new Uri(server + "changelog.txt"));
ww.DownloadStringCompleted += ww_DownloadchangelogCompleted;
}
using (WebClient wc = new WebClient())
{
lblStatus.Text = "Contacting Server...";
rtbUpdate.AppendText("\n- Contacting Server...");
wc.DownloadStringAsync(new Uri(server + "updt.txt"));
wc.DownloadProgressChanged += wc_DownloadupdtChanged;
wc.DownloadStringCompleted +=wc_DownloadupdtCompleted;
}
}
void ww_DownloadchangelogCompleted(object sender, DownloadStringCompletedEventArgs e)
{
rtbChangeLog.Text = e.Result;
}
private void wc_DownloadupdtChanged(object sender, DownloadProgressChangedEventArgs e)
{
lblStatus.Text = "Reply Received.";
rtbUpdate.AppendText("\n- Reply Received.");
lblData.Text = e.BytesReceived.ToString() + "/" + e.TotalBytesToReceive.ToString();
pgLoading.Value = e.ProgressPercentage;
}
private void wc_DownloadupdtCompleted(object sender, DownloadStringCompletedEventArgs e)
{
lblStatus.Text = "Read Updates...";
rtbUpdate.AppendText("\n- Read Updates...");
lblData.Text = "No Data";
pgLoading.Value = 0;
ver = e.Result.Split('\n');
if (int.Parse(FileVersionInfo.GetVersionInfo("Terraria.exe").ProductVersion.Replace(".", "")) < int.Parse(ver[0].Trim().Replace(".", "")))
{
name = @"Updates\Terraria-" + ver[0] + ".zip";
if (!Directory.Exists("Updates"))
{
Directory.CreateDirectory("Updates");
}
if (isUpdateGame)
{
lblStatus.Text = "Found New Game Update, Downloading...";
rtbUpdate.AppendText("\n- Found New Game Update, Downloading...");
using (WebClient wc = new WebClient())
{
updateGame = true;
wc.DownloadFileAsync(new Uri(server + "terraria.zip"), name);
wc.DownloadProgressChanged += wc_DownloadzipChanged;
wc.DownloadFileCompleted += wc_DownloadzipCompleted;
}
}
else
{
lblStatus.Text = "Found New Pending Game Update..";
rtbUpdate.AppendText("\n- Found New Pending Game Update...");
updateLauncher();
}
}
else
{
MainMenu.Enabled = true;
lblStatus.Text = "Already Updated.";
rtbUpdate.AppendText("\n- Already Updated.");
updateLauncher();
}
}
void updateLauncher()
{
if (int.Parse(Application.ProductVersion.Replace(".", "")) < int.Parse(ver[1].Trim().Replace(".", "")))
{
name = @"Updates\Launcher-" + ver[1] + ".zip";
if (!Directory.Exists("Updates"))
{
Directory.CreateDirectory("Updates");
}
if (isUpdateGame)
{
lblStatus.Text = "Found New Launcher Update, Downloading...";
rtbUpdate.AppendText("\n- Found New Launcher Update, Downloading.");
using (WebClient wc = new WebClient())
{
wc.DownloadFileAsync(new Uri(server + "launcher.zip"), name);
wc.DownloadProgressChanged += wc_DownloadzipChanged;
wc.DownloadFileCompleted += wc_DownloadzipCompleted;
}
}
else
{
lblStatus.Text = "Found New Pending Launcher Update..";
rtbUpdate.AppendText("\n- Found New Pending Launcher Update.");
}
}
else
{
MainMenu.Enabled = true;
lblStatus.Text = "Already Updated.";
rtbUpdate.AppendText("\n- Already Updated.");
}
}
void wc_DownloadzipCompleted(object sender, AsyncCompletedEventArgs e)
{
Process proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "unzip.exe",
Arguments = "-o " + name,
UseShellExecute = true,
CreateNoWindow = false
}
};
proc.Start();
if (int.Parse(Application.ProductVersion.Replace(".", "")) < int.Parse(ver[1].Replace(".", "")) && updateGame)
{
updateLauncher();
}
else
{
this.Close();
}
}
private void wc_DownloadzipChanged(object sender, DownloadProgressChangedEventArgs e)
{
lblData.Text = e.BytesReceived.ToString() + "/" + e.TotalBytesToReceive.ToString();
pgLoading.Value = e.ProgressPercentage;
}
}
}