-
Notifications
You must be signed in to change notification settings - Fork 0
/
Launcher.cs
440 lines (410 loc) · 18.7 KB
/
Launcher.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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
//------------------------------------------------------------------
//-----------------------------Usings-------------------------------
//------------------------------------------------------------------
#region Usings
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Net;
using System.IO;
using System.Runtime.InteropServices;
using Ionic.Zip;
using Ionic.Zlib;
using Microsoft.Win32;
#endregion
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
//------------------------------------------------------------------
//---------------------Click Anywhere to Move-----------------------
//------------------------------------------------------------------
#region Click Anywhere to Move
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd,
int Msg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
#endregion
//------------------------------------------------------------------
//------------------Click Anywhere to Move Event--------------------
//------------------------------------------------------------------
#region Click Anywhere to Move Event
private void titelLeiste_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
#endregion
//------------------------------------------------------------------
//-----------------------------Form1--------------------------------
//------------------------------------------------------------------
#region Form1
public Form1()
{
InitializeComponent();
if (!check_dir())
{
MessageBox.Show("Launcher liegt im falschen Verzeichnis", "Fehler!");
MessageBox.Show("Launcher muss ins OA Verzeichnis!", "Fehler hoch 2!");
MessageBox.Show("PACK MICH DA REIN!!!!", "Fehler hoch 3!");
Application.Exit();
}
Boolean check_b = check();
if (check_b)
{
version_txt.Text = "Version: " + get_version();
StartGameButton.Image = ExtremLauncher.Properties.Resources.extrem_rdy;
set_text("Spiel ist auf dem neusten Stand");
StartGameButton.Enabled = true;
updateb.Enabled = false;
updateb.Image = ExtremLauncher.Properties.Resources.update;
}
else
{
version_txt.Text = "Version: " + get_version();
StartGameButton.Enabled = false;
updateb.Enabled = true;
StartGameButton.Image = ExtremLauncher.Properties.Resources.extrem_nonstart;
updateb.Image = ExtremLauncher.Properties.Resources.update;
}
}
#endregion
public Boolean check_dir()
{
if (File.Exists(Directory.GetCurrentDirectory() + "\\Expansion\\beta\\arma2oa.exe"))
return true;
else
return false;
}
public Boolean check()
{
string version = get_version();
string next_version = get_next_version();
// ==
if (version == next_version)
{
return true;
}
else
{
return false;
}
}
public String get_version()
{
if (File.Exists(Directory.GetCurrentDirectory() + "\\e_version.ini"))
{
return System.IO.File.ReadAllText(Directory.GetCurrentDirectory() + "\\e_version.ini");
}
else
{
return "0.00";
}
}
public String get_next_version()
{
string version = get_version();
string myTextUrl = "http://dengpeng.eu/mod/e/version.php?version=" + version;
WebClient urlGrabber = new WebClient();
return urlGrabber.DownloadString(myTextUrl);
}
public String get_arma2ordner()
{
if (File.Exists(Directory.GetCurrentDirectory() + "\\arma2_pfad.ini"))
{
using (StreamReader reader = new StreamReader(Directory.GetCurrentDirectory() + "\\arma2_pfad.ini", System.Text.Encoding.Default))
{
return reader.ReadLine();
}
}
else
{
return Directory.GetCurrentDirectory();
}
}
public String get_extra_cmd()
{
if (File.Exists(Directory.GetCurrentDirectory() + "\\e_extra_cmd.ini"))
{
using (StreamReader reader = new StreamReader(Directory.GetCurrentDirectory() + "\\e_extra_cmd.ini", System.Text.Encoding.Default))
{
return reader.ReadLine();
}
}
else
{
return "-nosplash";
}
}
delegate void SetTextCallback(string text);
public void set_text(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.status.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(set_text);
this.Invoke(d, new object[] { text });
}
else
{
this.status.Text = text;
}
}
//------------------------------------------------------------------
//---------------------StartGameButton Events-----------------------
//------------------------------------------------------------------
#region StartGameButton Events
private void StartGamebtn_Click(object sender, EventArgs e)
{
if (check_dir())
{
string a2path = get_arma2ordner();
string extra_cmd = get_extra_cmd();
Process P = new Process();
P.StartInfo.FileName = Directory.GetCurrentDirectory() + "\\Expansion\\beta\\arma2oa.exe";
if (sm.Checked == true)
{
P.StartInfo.Arguments = "\"-mod=" + a2path + ";EXPANSION;ca\" -mod=Expansion\\beta;Expansion\\beta\\Expansion;@DayZ_EX;@CBA;@CBA_A2;@CBA_OA;@DayZ_EX_SFX -connect=95.156.251.20 -port=2401 " + extra_cmd; // -nosplash -cpuCount=4 -exThreads=7
}
else
{
P.StartInfo.Arguments = "\"-mod=" + a2path + ";EXPANSION;ca\" -mod=Expansion\\beta;Expansion\\beta\\Expansion;@DayZ_EX;@CBA;@CBA_A2;@CBA_OA -connect=95.156.251.20 -port=2401 " + extra_cmd; // -nosplash -cpuCount=4 -exThreads=7
}
P.Start();
}
else
{
MessageBox.Show("Launcher liegt im falschen Verzeichnis", "Fehler!");
MessageBox.Show("Launcher muss ins OA Verzeichnis!", "Fehler hoch 2!");
MessageBox.Show("PACK MICH DA REIN!!!!", "Fehler hoch 3!");
}
}
private void StartGamebtn_MouseEnter(object sender, EventArgs e)
{
StartGameButton.Image = ExtremLauncher.Properties.Resources.extrem_rdy;
}
private void StartGamebtn_MouseHover(object sender, EventArgs e)
{
StartGameButton.Image = ExtremLauncher.Properties.Resources.extrem_start;
}
#endregion
//------------------------------------------------------------------
//----------------------Updateb Events--------------------------
//------------------------------------------------------------------
#region updateb Events
private void updateb_MouseEnter(object sender, EventArgs e)
{
updateb.Image = ExtremLauncher.Properties.Resources.update_hover;
}
private void updateb_MouseLeave(object sender, EventArgs e)
{
updateb.Image = ExtremLauncher.Properties.Resources.update;
}
private void updateb_MouseDown(object sender, MouseEventArgs e)
{
updateb.Image = ExtremLauncher.Properties.Resources.update_on_druck;
}
private void updateb_Click(object sender, EventArgs e)
{
string version = get_version();
string new_version = get_next_version();
updateb.Enabled = false;
updateb.Image = ExtremLauncher.Properties.Resources.update;
set_text("Starte Update auf Version: " + new_version + "\n\rDu hast momentan Version: " + version);
downloadUpdates = new BackgroundWorker();
downloadUpdates.DoWork += new DoWorkEventHandler(downloadUpdates_DoWork);
downloadUpdates.RunWorkerAsync();
}
#endregion
//------------------------------------------------------------------
//----------------------CloseButton Events--------------------------
//------------------------------------------------------------------
#region CloseButton Events
private void Closebtn_MouseEnter(object sender, EventArgs e)
{
CloseButton.Image = ExtremLauncher.Properties.Resources.exit_over;
}
private void Closebtn_MouseLeave(object sender, EventArgs e)
{
CloseButton.Image = ExtremLauncher.Properties.Resources.exit_off;
}
private void Closebtn_MouseDown(object sender, MouseEventArgs e)
{
CloseButton.Image = ExtremLauncher.Properties.Resources.exit_over;
}
private void Closebtn_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
//------------------------------------------------------------------
//--------------------AutomaticUpdater Events-----------------------
//------------------------------------------------------------------
#region AutomaticUpdater Events
private void downloadUpdates_DoWork(object sender, DoWorkEventArgs e)
{
string version = get_version();
string next_version = get_next_version();
// the URL to download the file from
string sUrlToReadFileFrom = "http://dengpeng.eu/mod/e/" + next_version + "/update.zip";
// the path to write the file to
string sFilePathToWriteFileTo = next_version + ".zip";
// first, we need to get the exact size (in bytes) of the file we are downloading
Uri url = new Uri(sUrlToReadFileFrom);
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
response.Close();
// gets the size of the file in bytes
Int64 iSize = response.ContentLength;
Int64 size = 0;
if (File.Exists(next_version + ".zip"))
{
FileInfo finfo = new FileInfo(next_version + ".zip");
size = finfo.Length;
}
if (size == iSize)
entpacken(next_version);
else
{
// keeps track of the total bytes downloaded so we can update the progress bar
Int64 iRunningByteTotal = 0;
// use the webclient object to download the file
using (System.Net.WebClient client = new System.Net.WebClient())
{
// open the file at the remote URL for reading
using (System.IO.Stream streamRemote = client.OpenRead(new Uri(sUrlToReadFileFrom)))
{
// using the FileStream object, we can write the downloaded bytes to the file system
using (Stream streamLocal = new FileStream(sFilePathToWriteFileTo, FileMode.Create, FileAccess.Write, FileShare.None))
{
// loop the stream and get the file into the byte buffer
int iByteSize = 0;
byte[] byteBuffer = new byte[iSize];
while ((iByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
{
// write the bytes to the file system at the file path specified
streamLocal.Write(byteBuffer, 0, iByteSize);
iRunningByteTotal += iByteSize;
// calculate the progress out of a base "100"
double dIndex = (double)(iRunningByteTotal);
double dTotal = (double)byteBuffer.Length;
double dProgressPercentage = (dIndex / dTotal);
int iProgressPercentage = (int)(dProgressPercentage * 100);
mbs.Text = Math.Round(dIndex / 1024 / 1024, 0) + "MB von " + Math.Round(dTotal / 1024 / 1024, 0) + "MB";
prozent.Text = iProgressPercentage + " %";
// update the progress bar
downloadUpdates.ReportProgress(iProgressPercentage);
}
// clean up the file stream
streamLocal.Close();
}
// close the connection to the remote server
streamRemote.Close();
}
}
}
}
private void downloadUpdates_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
downloadProgress.Value = e.ProgressPercentage;
if (e.ProgressPercentage == 10)
dlp.Image = ExtremLauncher.Properties.Resources.pBar_01;
if (e.ProgressPercentage == 20)
dlp.Image = ExtremLauncher.Properties.Resources.pBar_02;
if (e.ProgressPercentage == 30)
dlp.Image = ExtremLauncher.Properties.Resources.pBar_03;
if (e.ProgressPercentage == 40)
dlp.Image = ExtremLauncher.Properties.Resources.pBar_04;
if (e.ProgressPercentage == 50)
dlp.Image = ExtremLauncher.Properties.Resources.pBar_05;
if (e.ProgressPercentage == 60)
dlp.Image = ExtremLauncher.Properties.Resources.pBar_06;
if (e.ProgressPercentage == 70)
dlp.Image = ExtremLauncher.Properties.Resources.pBar_07;
if (e.ProgressPercentage == 80)
dlp.Image = ExtremLauncher.Properties.Resources.pBar_08;
if (e.ProgressPercentage == 90)
dlp.Image = ExtremLauncher.Properties.Resources.pBar_09;
if (e.ProgressPercentage > 98)
dlp.Image = ExtremLauncher.Properties.Resources.pBar_10;
}
private void downloadUpdates_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
string version = get_version();
string next_version = get_next_version();
set_text("Download komplett. \n\r Starte den Update Vorgang....");
if (entpacken(next_version))
Application.Restart();
else
Application.Restart();
}
#endregion
public Boolean entpacken(String filename)
{
if (File.Exists(filename + ".zip"))
{
try
{
try
{
using (ZipFile zip = ZipFile.Read(filename + ".zip"))
{
zip.ExtractAll(Directory.GetCurrentDirectory(), ExtractExistingFileAction.OverwriteSilently);
}
if (File.Exists(Directory.GetCurrentDirectory() + "\\delete.ini"))
{
string line;
System.IO.StreamReader file = new System.IO.StreamReader(Directory.GetCurrentDirectory() + "\\delete.ini");
set_text("Lösche alte Dateien....");
while ((line = file.ReadLine()) != null)
{
if (line.Length > 0)
{
string[] lines = line.Split(new Char[] { ':' });
if(lines[0] == "f")
if (File.Exists(Directory.GetCurrentDirectory() + "\\" + lines[1]))
System.IO.File.Delete(Directory.GetCurrentDirectory() + "\\" + lines[1]);
if (lines[0] == "d")
if (Directory.Exists(Directory.GetCurrentDirectory() + "\\" + lines[1]))
System.IO.Directory.Delete(Directory.GetCurrentDirectory() + "\\" + lines[1], true);
}
}
file.Close();
System.IO.File.Delete(Directory.GetCurrentDirectory() + "\\delete.ini");
}
File.Delete(filename + ".zip");
set_text("Starte Launcher neu....");
return true;
}
catch (Exception)
{
MessageBox.Show("Konnte Update Zip nicht öffnen :(");
MessageBox.Show("Noch mal Versuchen oder Dateien manuell downloaden");
MessageBox.Show("und ins OA Verzeichnis tun. Und dann wieder auf Update klicken");
MessageBox.Show("UND DIE ZIP DATEIEN NICHT SELBST ENTPACKEN!!!!");
//File.Delete(filename + ".zip");
return false;
}
}
catch
{
MessageBox.Show("Fehler beim Entpacken :(");
//File.Delete(filename + ".zip");
return false;
}
}
else
return false;
}
}
}