-
Notifications
You must be signed in to change notification settings - Fork 0
/
DowngradeTool.cs
507 lines (422 loc) · 17.1 KB
/
DowngradeTool.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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using Microsoft.VisualBasic.FileIO;
using Steamworks;
using DevComponents.DotNetBar;
using DeReplaysManager;
using DevComponents.DotNetBar.Rendering;
namespace De_Roll
{
public partial class Form1 : OfficeForm
{
public string SetPatchVer { get; set; }
public Form1()
{
InitializeComponent();
}
public int _currentDepots;
public string depo;
public string manif;
public List<string> AllDepots = new List<string>();
public List<string> AllManif = new List<string>();
public bool Tdone = false;
private string saveDirectoryPath = "";
public string exeDIR = System.AppDomain.CurrentDomain.BaseDirectory;
public bool archOS = Environment.Is64BitOperatingSystem;
public static bool IsConnected()
{
try
{
using (var client = new WebClient())
using (client.OpenRead("http://google.com/generate_204"))
return true;
}
catch
{
return false;
}
}
private async void Form1_Load(object sender, EventArgs e)
{
//if(IsConnected())
//{
//string stid = await DownloadStringAsync(new Uri(@"https://github.com/gregstein/DE-Replays-Manager/raw/master/depotpatches.txt"));
string stid = File.ReadAllText(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory,@"depatches.txt"));
if (stid != null)
{
cbPATCH.Items.Clear();
cbPATCH.Items.Add("Select Patch Version");
using (StringReader sr = new StringReader(stid))
{
while (sr.Peek() >= 0)
{
string str;
//string[] strArray;
str = sr.ReadLine();
string[] arrstr = str.Split('>');
cbPATCH.Items.Add(arrstr[0]);
}
}
cbPATCH.Text = "Select Patch Version";
this.TopMost = true;
}
//}
if (SetPatchVer != null)
cbPATCH.Text = SetPatchVer;
string result = await CheckDotNet();
if(!result.Contains("Usage"))
{
DialogResult dialogResult = MessageBox.Show(new Form { TopMost = true }, "DotNet Runtime is missing. Download it now?", "Missing Component!", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
if (archOS)
Process.Start("https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-desktop-3.1.6-windows-x64-installer");
else
Process.Start("https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-desktop-3.1.6-windows-x86-installer");
}
else if (dialogResult == DialogResult.No)
{
}
}
}
async Task<string> CheckDotNet()
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "CMD.EXE";
p.StartInfo.Arguments = "/C dotnet && exit";
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
await Task.Delay(100);
return output;
}
private void btnINSTALL_Click(object sender, EventArgs e)
{
}
private void userBOX_TextChanged(object sender, EventArgs e)
{
}
private void kryptonHeader1_Paint(object sender, PaintEventArgs e)
{
}
private void kryptonButton1_Click(object sender, EventArgs e)
{
kryptonButton1.Enabled = false;
if (cbPATCH.Text != "Select Patch Version")
DepotCommander(cbPATCH.Text);
VerCheck();
kryptonButton1.Enabled = true;
}
static void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
//* Do your stuff with the output (write to console/log/StringBuilder)
MessageBox.Show(outLine.Data);
}
private void cmdDEPOT(string depot, string manifest)
{
try
{
string argz = "/K dotnet \"" + System.AppDomain.CurrentDomain.BaseDirectory + "\\DepotDownloader.dll\" -app 221380 -depot " + depot + " -manifest " + manifest + " -dir " + "\"" + SaveDirectoryPath() + "\"" + " -username " + userBOX.Text + " -password " + "\"" + passBOX.Text + "\"" + " -remember-password -filelist " + "\"" + System.AppDomain.CurrentDomain.BaseDirectory + "exclude.txt" + "\"" + " && exit";
//MessageBox.Show(argz);
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "CMD.EXE";
psi.Verb = "runas";
psi.Arguments = argz;
p.StartInfo = psi;
p.Start();
p.WaitForExit();
}
catch (SystemException)
{
}
//Copier(depot);
}
static void ErrorOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
//* Do your stuff with the output (write to console/log/StringBuilder)
MessageBox.Show(outLine.Data);
}
private void cmdDEPOTS(string depot, string manifest)
{
if(SaveDirectoryPath() != null)
{
string argz = "/K dotnet \"" + System.AppDomain.CurrentDomain.BaseDirectory + "\\DepotDownloader.dll\" -app 221380 -depot " + depot + " -manifest " + manifest + " -dir " + "\"" + SaveDirectoryPath() + "\"" + " -username " + userBOX.Text + " -password " + "\"" + passBOX.Text + "\"" + " -remember-password -filelist " + "\"" + System.AppDomain.CurrentDomain.BaseDirectory + "exclude.txt" + "\"" + " && exit";
MessageBox.Show(argz);
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "CMD.EXE";
psi.Verb = "runas";
psi.Arguments = argz;
p.StartInfo = psi;
p.Start();
p.WaitForExit();
}
else
{
MessageBox.Show("Game directory for AoE2 HD was not found! Please connect to your steam account or download the game.", "Opps!");
}
//Copier(depot);
}
private static int LinePicker(string ver, string mydir)
{
int i = 0;
foreach (string line in File.ReadLines(mydir + "\\depatches.txt"))
{
i++;
if(line.Contains(ver))
{
return i;
}
}
return 0;
}
public async Task<string> DownloadStringAsync(Uri uri, int timeOut = 60000)
{
try {
string output = null;
bool cancelledOrError = false;
using (var client = new WebClient())
{
client.Headers.Add("user-agent", "DE Replays Manager");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.Expect100Continue = false; ServicePointManager.MaxServicePointIdleTime = 0;
client.Encoding = System.Text.Encoding.UTF8;
client.Proxy = null;
client.DownloadStringCompleted += (sender, e) =>
{
if (e.Error != null || e.Cancelled)
{
cancelledOrError = true;
}
else
{
output = e.Result;
}
};
client.DownloadStringAsync(uri);
var n = DateTime.Now;
while (output == null && !cancelledOrError && DateTime.Now.Subtract(n).TotalMilliseconds < timeOut)
{
await Task.Delay(100); // wait for respsonse
}
}
return await Task.FromResult(output);
}
catch (SystemException)
{
return await Task.FromResult(File.Exists(AppDomain.CurrentDomain.BaseDirectory + "depatches.txt") ? File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "depatches.txt"):"");
}
}
private async void DepotCommander(string version)
{
try
{
AllDepots.Clear();
AllManif.Clear();
int i = 0;
string line;
//string Releases = await DownloadStringAsync(new Uri(@"https://github.com/gregstein/DE-Replays-Manager/raw/master/depotpatches.txt"));
//File.WriteAllText(exeDIR + "\\depatches.txt", Releases);
StreamReader file = new StreamReader(exeDIR + "\\depatches.txt");
while ((line = file.ReadLine()) != null)
{
// foreach (string line in File.ReadLines(exeDIR + "\\depatches.txt"))
//{
i++;
if(i == LinePicker(version, exeDIR) && i != 0)
{
string[] spline = line.Split('>');
string[] subline = spline[1].Split('#');
_currentDepots = subline.Length;
int j = 0;
foreach(string id in subline)
{
j++;
//Depot command
if(j>=1)
{
string[] fsplit = id.Split('+');
AllDepots.Add(fsplit[0]);
depo = fsplit[0];
string[] ffsplit = fsplit[1].Split('<');
AllManif.Add(ffsplit[0]);
manif = ffsplit[0];
}
}
MessageBox.Show(AllDepots.Count.ToString() + " Depots To Download.");
//Depot Counter
if (AllDepots.Count == 1)
{
cmdDEPOT(depo, manif);
Tdone = true;
VerCheck();
}
else if(AllDepots.Count == 2)
{
cmdDEPOT(AllDepots[0], AllManif[0]);
cmdDEPOT(AllDepots[1], AllManif[1]);
Tdone = true;
VerCheck();
}
else if (AllDepots.Count == 3)
{
cmdDEPOT(AllDepots[0], AllManif[0]);
cmdDEPOT(AllDepots[1], AllManif[1]);
cmdDEPOT(AllDepots[2], AllManif[2]);
Tdone = true;
VerCheck();
}
else if (AllDepots.Count == 4)
{
cmdDEPOT(AllDepots[0], AllManif[0]);
cmdDEPOT(AllDepots[1], AllManif[1]);
cmdDEPOT(AllDepots[2], AllManif[2]);
cmdDEPOT(AllDepots[3], AllManif[3]);
Tdone = true;
VerCheck();
}
//TESTING
}
//break;
//END LINES
}
file.Close();
}
catch (System.IndexOutOfRangeException)
{
MessageBox.Show("Filed to retrieve Patch notes.", "Error!");
}
}
private void VerCheck()
{
//Re-check game version
var versionInfo = FileVersionInfo.GetVersionInfo(SaveDirectoryPath() + @"\AoK HD.exe");
string verzion = versionInfo.FileVersion;
//string[] sver = verzion.Split('.');
label1.Text = "Current Version: " + verzion;
}
private void Copier(string depot)
{
try
{
//Source from where we copy the file
string sourceFolderPath = System.AppDomain.CurrentDomain.BaseDirectory + @"tmp";
// Destination for copied files.
string destinationFolderPath = @"C:\test";
FileSystem.CopyDirectory(sourceFolderPath, destinationFolderPath,UIOption.AllDialogs);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public string SaveDirectoryPath()
{
if (this.saveDirectoryPath == "")
{
uint size = SteamApps.GetAppInstallDir((AppId_t)221380, out this.saveDirectoryPath, 500u);
if (size <= 0)
{
}
else
{
}
}
return this.saveDirectoryPath;
}
private async void timer1_Tick(object sender, EventArgs e)
{
try
{
if (!SteamAPI.Init())
{
if (SteamAPI.IsSteamRunning())
{
steamLBL.ForeColor = Color.DarkBlue;
steamLBL.Text = "Steam Running..";
steamSTATUS.Image = HDDowngradeTool.Properties.Resources.dotred;
}
else
{
steamLBL.ForeColor = Color.Gold;
await Task.Delay(200);
steamLBL.Text = "Steam OFF";
await Task.Delay(100);
steamLBL.ForeColor = Color.Maroon;
steamSTATUS.Image = HDDowngradeTool.Properties.Resources.dotred;
}
//SteamUtils.GetAppID();
}
else
{
steamLBL.ForeColor = Color.ForestGreen;
steamLBL.Text = "Steam ON";
steamSTATUS.Image = HDDowngradeTool.Properties.Resources.dotgreen;
cbPATCH.Enabled = true;
kryptonButton1.Enabled = true;
await Task.Delay(200);
bool IsDE = SteamApps.BIsAppInstalled(new AppId_t(221380));
if (!IsDE)
{
MessageBox.Show("Please Buy or Install Age of Empires II: Definitive Edition before you proceed!", "Game Missing");
cbPATCH.Enabled = false;
timer1.Stop();
}
var versionInfo = FileVersionInfo.GetVersionInfo(SaveDirectoryPath() + @"\AoK HD.exe");
string version = versionInfo.FileVersion;
//string[] sver = version.Split('.');
label1.Text = "Current Version: " + version;
timer1.Stop();
}
}
catch(SystemException)
{
steamLBL.ForeColor = Color.Black;
steamLBL.Text = "Steam OFF";
steamSTATUS.Image = HDDowngradeTool.Properties.Resources.dotred;
}
}
private void cbPATCH_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void cbPATCH_MouseHover(object sender, EventArgs e)
{
}
private void browseREP_Click(object sender, EventArgs e)
{
}
private void settingbtn_Click(object sender, EventArgs e)
{
if(saveDirectoryPath == "" || saveDirectoryPath == null)
{
MessageBox.Show("Please sign into steam first then try again.", "Steam not ON!");
return;
}
DTSettings dt = new DTSettings();
dt._HDpath = saveDirectoryPath;
dt.Show();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
}
}
}