-
Notifications
You must be signed in to change notification settings - Fork 12
/
MainWindow.xaml.cs
599 lines (526 loc) · 22.1 KB
/
MainWindow.xaml.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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.ComponentModel;
using System.IO;
using System.Xml.Linq;
using RedditSharp;
using System.Diagnostics;
namespace SlickUpdater
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public BackgroundWorker worker;
public BackgroundWorker checkWorker;
public BackgroundWorker redditWorker;
public logIt logThread;
public string slickVersion = "1.2.4";
List<MenuItem> items = new List<MenuItem>();
string rawslickServVer;
string[] slickServVer;
string subreddit = "/r/ProjectMilSim";
public int downloadSpeed = 0;
Stopwatch sw = new Stopwatch();
public MainWindow()
{
InitializeComponent();
logThread = new logIt();
repoHide();
FileStream fs = new FileStream("localversion", FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(slickVersion);
sw.Close();
menuAnimation(140, 0);
showRepo = false;
rawslickServVer = downloader.webRead("http://projectawesomemodhost.com/beta/repo/slickupdater/slickversion");
slickServVer = rawslickServVer.Split('%');
MenuItem pa = new MenuItem();
pa.Tag = "http://projectawesomemodhost.com/beta/repo/";
pa.Header = "PA Repo";
items.Add(pa);
if (slickServVer[0] != slickVersion)
{
MessageBoxResult result = MessageBox.Show("There seems to be a new version of slickupdater available, do you wanne update it it?", "New Update", MessageBoxButton.YesNo);
switch (result)
{
case MessageBoxResult.Yes:
System.Diagnostics.Process.Start("SlickAutoUpdate.exe");
System.Diagnostics.Process.GetCurrentProcess().Kill();
break;
case MessageBoxResult.No:
break;
}
}
// Initialize Update Worker
worker = new BackgroundWorker();
worker.DoWork += worker_DoWork;
worker.ProgressChanged += worker_ProgressChanged;
worker.WorkerReportsProgress = true;
worker.RunWorkerCompleted += worker_RunWorkerCompleted;
//init checkWorker
checkWorker = new BackgroundWorker();
checkWorker.DoWork += checkWorker_DoWork;
checkWorker.ProgressChanged += checkWorker_ProgressChanged;
checkWorker.WorkerReportsProgress = true;
checkWorker.RunWorkerCompleted += checkWorker_RunWorkerCompleted;
//reddit worker
redditWorker = new BackgroundWorker();
redditWorker.DoWork += redditWorker_DoWork;
redditWorker.RunWorkerCompleted += redditworker_Done;
WindowManager.SetWnd(this);
//Test if config is up to date
if(File.Exists("config.xml")){
XDocument testdoc = XDocument.Load("config.xml");
if (testdoc.Element("SlickUpdater").Element("ArmA3").Element("repourl") == null)
{
File.Delete("config.xml");
}
}
//Grenerate config xml
if (!File.Exists("config.xml")) {
MessageBox.Show("Hello! This seems to be the first time you launch SlickUpdater so make sure your arma 3 and ts3 path is set correctly in options. Have a nice day!", "Welcome");
XDocument doc = new XDocument(
new XComment("Slick Updater config.xml File!"),
new XElement("SlickUpdater",
new XElement("ArmA3",
new XElement("path", ""),
new XElement("window","false"),
new XElement("nosplash","true"),
new XElement("skipIntro","true"),
new XElement("noLogs","false"),
new XElement("noPause","true"),
new XElement("showScriptErrors","false"),
new XElement("world",""),
new XElement("customParameters", ""),
new XElement("ts3Dir",""),
new XElement("repourl", "http://projectawesomemodhost.com/beta/repo/"),
new XElement("currentrepo", "PA Repo")),
new XElement("ArmA2"),
new XElement("repoGen",
new XElement("inputDir",""),
new XElement("outputDir", "")),
new XElement("Client",
new XElement("FirstTimeLaunch", "true"))));
doc.Save("config.xml");
}
//Check if the user if a PA user or a TEST user
a3DirText.Text = regcheck.arma3RegCheck();
ts3DirText.Text = regcheck.ts3RegCheck();
menuButton.Content = ConfigManager.fetch("ArmA3", "currentrepo");
var subredd = ConfigManager.fetch("ArmA3", "currentrepo");
if (subredd == "PA Repo")
{
subreddit = "/r/ProjectMilSim";
joinButton.Content = "Join PA server";
}else if(subredd == "Test Outfit Repo"){
subreddit = "/r/testoutfit";
joinButton.Content = "Join TEST server";
}
}
//Do some work
void checkWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
if (checkWorker.IsBusy) return;
if (worker.IsBusy) return;
setBusy(false);
}
//check if da shit is up to date
void a3UpdateCheck() {
if (!checkWorker.IsBusy) {
setBusy(true);
checkWorker.RunWorkerAsync();
} else {
MessageBox.Show("checkWorker is Busy!");
}
}
void checkWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
switch (e.ProgressPercentage) {
case -1:
MessageBox.Show(e.UserState as String);
break;
case 1:
arma3Button.Content = e.UserState as String;
break;
case 2:
a3ModList.ItemsSource = e.UserState as List<Mod>;
break;
}
}
void checkWorker_DoWork(object sender, DoWorkEventArgs e) {
a3UpdateManager.arma3UpdateCheck();
}
private void setBusy(bool isBusy) {
if (isBusy) {
a3RefreshButton.IsEnabled = false;
arma3Button.IsEnabled = false;
joinButton.IsEnabled = false;
menuButton.IsEnabled = false;
} else if (!isBusy) {
a3RefreshButton.IsEnabled = true;
arma3Button.IsEnabled = true;
joinButton.IsEnabled = true;
menuButton.IsEnabled = true;
}
}
private void onArma3Clicked(object sender, RoutedEventArgs e) {
if (arma3Button.Content as string == "Update ArmA 3") {
if (!worker.IsBusy) {
setBusy(true);
worker.RunWorkerAsync();
sw.Start();
} else {
MessageBox.Show("Worker is Busy(You really must be dicking around or unlucky to make this pop up...)");
}
} else {
Launch.a3Launch(false, "");
}
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) {
System.Diagnostics.Process.Start(e.Uri.ToString());
}
private void a3RefreshButton_Click(object sender, RoutedEventArgs e) {
if (!checkWorker.IsBusy) {
setBusy(true);
a3UpdateCheck();
} else {
MessageBox.Show("checkWorker thread is currently busy...");
}
}
private void a3RefreshImageEnter(object sender, MouseEventArgs e) {
DoubleAnimation rotationAnimation = new DoubleAnimation();
rotationAnimation.From = 0;
rotationAnimation.To = 360;
rotationAnimation.Duration = new Duration(TimeSpan.FromSeconds(.5));
rotationAnimation.AccelerationRatio = 0.3;
rotationAnimation.DecelerationRatio = 0.3;
Storyboard storyboard = new Storyboard();
Storyboard.SetTarget(rotationAnimation, refreshImage);
Storyboard.SetTargetProperty(rotationAnimation,
new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)"));
storyboard.Children.Add(rotationAnimation);
this.BeginStoryboard(storyboard);
}
private void launchOptionsButton_Click(object sender, RoutedEventArgs e) {
Arma3LaunchOptionsDialogue dialogue = new Arma3LaunchOptionsDialogue();
dialogue.Show();
mainWindow.IsEnabled = false;
}
private void a3DirText_TextChanged(object sender, TextChangedEventArgs e) {
ConfigManager.write("ArmA3", "path", a3DirText.Text);
}
private void a3Ts3Text_TextChanged(object sender, TextChangedEventArgs e)
{
ConfigManager.write("ArmA3", "ts3Dir", ts3DirText.Text);
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e) {
setBusy(true);
a3UpdateCheck();
redditWorker.RunWorkerAsync();
eventbutton.IsEnabled = false;
}
private void repoGen_Options_Click(object sender, RoutedEventArgs e) {
RepoGen_Options repoGen = new RepoGen_Options();
repoGen.Show();
mainWindow.IsEnabled = false;
}
private void inputDirListBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
DragAndDrop.startPoint = e.GetPosition(null);
}
private void inputDirListBox_PreviewMouseMove(object sender, MouseEventArgs e) {
DragAndDrop.inputDirListBox_PreviewMouseMove(sender, e);
}
private void outputDirListBox_DragEnter(object sender, DragEventArgs e) {
DragAndDrop.outputDirListBox_DragEnter(sender, e);
}
private void outputDirListBox_Drop(object sender, DragEventArgs e) {
DragAndDrop.outputDirListBox_Drop(sender, e);
}
private void repoGen_Refresh_Click(object sender, RoutedEventArgs e) {
RepoGenerator.inputGen();
}
private void inputDirListBox_DragEnter(object sender, DragEventArgs e) {
DragAndDrop.inputDirListBox_DragEnter(sender, e);
}
private void inputDirListBox_Drop(object sender, DragEventArgs e) {
DragAndDrop.inputDirListBox_Drop(sender, e);
}
private void outputDirListBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
DragAndDrop.startPoint = e.GetPosition(null);
}
private void outputDirListBox_PreviewMouseMove(object sender, MouseEventArgs e) {
DragAndDrop.outputDirListBox_PreviewMouseMove(sender, e);
}
private void repoGenButton_Click(object sender, RoutedEventArgs e) {
mainWindow.IsEnabled = false;
RepoGenerator.startGen();
}
private void worker_DoWork(object sender, DoWorkEventArgs e) {
a3UpdateManager.a3Update();
}
private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
if (e.ProgressPercentage <= 100 && e.ProgressPercentage >= 0) {
indivProgress.Value = e.ProgressPercentage;
indivProgressTxt.Content = e.ProgressPercentage + "%";
} else if (e.ProgressPercentage > 100 && e.ProgressPercentage <= 201) {
midProgressTxt.Content = e.ProgressPercentage - 101 + "%";
midProgress.Value = e.ProgressPercentage - 101;
} else if (e.ProgressPercentage > 201 && e.ProgressPercentage <= 302) {
totalProgressTxt.Content = e.ProgressPercentage - 202 + "%";
totalProgress.Value = e.ProgressPercentage - 202;
} else if (e.ProgressPercentage == -1) {
MessageBox.Show(e.UserState as string);
}
//int dlSpeed = (int)(downloadSpeed);
Title = "Slick Updater Beta @ " + (downloadSpeed / 1024d / sw.Elapsed.TotalSeconds).ToString("0.00") + "kb/s";
}
private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
sw.Reset();
a3UpdateCheck();
indivProgress.Value = 0;
midProgress.Value = 0;
totalProgress.Value = 0;
midProgressTxt.Content = "";
indivProgressTxt.Content = "";
totalProgressTxt.Content = "";
Title = "Slick Updater Beta";
sw.Stop();
}
private void helpButton_Click(object sender, RoutedEventArgs e) {
mainWindow.IsEnabled = false;
About abt = new About();
abt.Show();
}
private void logging_click(object sender, RoutedEventArgs e)
{
log logging = new log();
logging.Show();
}
private void forceToggle(object sender, RoutedEventArgs e)
{
var currepourl = ConfigManager.fetch("ArmA3", "repourl");
string[] modlist = downloader.webReadLines(currepourl + "modlist.cfg");
MessageBoxResult result = MessageBox.Show("This will delete your mods and redownload them are you sure?", "You 100% sure?", MessageBoxButton.YesNo);
switch (result)
{
case MessageBoxResult.Yes:
string msg = "Removed mods";
forceButton.Content = msg;
forceButton.Width = 90;
string a3path = regcheck.arma3RegCheck();
foreach (string modline in modlist)
{
try
{
if(Directory.Exists(a3path + "\\" + modline)){
logIt.addData("Deleted " + modline);
Directory.Delete(a3path + "\\" + modline, true);
}
}
catch (IOException) { }
}
break;
case MessageBoxResult.No:
break;
}
}
private void repoHide()
{
repoGen.Visibility = Visibility.Hidden;
}
int clickCount = 0;
private void showrepo(object sender, MouseButtonEventArgs e)
{
clickCount++;
if (clickCount > 4)
{
repoGen.Visibility = Visibility.Visible;
}
}
#region TOPSECRET EASTEREGG NO PEAKING
int nyanClick = 0;
private void nyanEgg(object sender, MouseButtonEventArgs e)
{
nyanClick++;
if (nyanClick > 14)
{
suIcon.Visibility = Visibility.Hidden;
nyan.Visibility = Visibility.Visible;
}
}
#endregion
private void LaunchAndJoin(object sender, RoutedEventArgs e)
{
var server = ConfigManager.fetch("ArmA3", "currentrepo");
Launch.a3Launch(true, server);
}
bool showRepo = false;
private void showRepos(object sender, RoutedEventArgs e)
{
if (showRepo == false)
{
menuAnimation(0, 140);
//repomenu.Visibility = Visibility.Visible;
showRepo = true;
}
else {
menuAnimation(140, 0);
showRepo = false;
}
}
private void setActiveRepo(object sender, RoutedEventArgs e)
{
MenuItem obj = sender as MenuItem;
if (obj.Tag.ToString() == "pa")
{
menuButton.Content = obj.Header;
menuAnimation(140, 0);
ConfigManager.write("ArmA3", "repourl", slickServVer[2]);
ConfigManager.write("ArmA3", "currentrepo", obj.Header.ToString());
joinButton.Content = "Join PA server";
subreddit = "/r/ProjectMilSim";
}
if (obj.Tag.ToString() == "test")
{
menuButton.Content = obj.Header;
menuAnimation(140, 0);
ConfigManager.write("ArmA3", "repourl", slickServVer[3]);
ConfigManager.write("ArmA3", "currentrepo", obj.Header.ToString());
joinButton.Content = "Join TEST server";
subreddit = "/r/TestOutfit";
}
if (obj.Tag.ToString() == "paExtra")
{
if (slickServVer[4] == "not")
{
MessageBox.Show("This repo has not yet been implemented, setting you to PA repo");
menuButton.Content = "PA Repo";
menuAnimation(140, 0);
ConfigManager.write("ArmA3", "repourl", slickServVer[2]);
ConfigManager.write("ArmA3", "currentrepo", obj.Header.ToString());
joinButton.Content = "Join PA server";
subreddit = "/r/ProjectMilSim";
}
else
{
menuButton.Content = obj.Header;
menuAnimation(140, 0);
ConfigManager.write("ArmA3", "repourl", slickServVer[4]);
ConfigManager.write("ArmA3", "currentrepo", obj.Header.ToString());
joinButton.Content = "Join PA server";
subreddit = "/r/ProjectMilSim";
}
}
showRepo = false;
if (!checkWorker.IsBusy)
{
setBusy(true);
a3UpdateCheck();
}
else
{
MessageBox.Show("checkWorker thread is currently busy...");
}
}
private void repoLostFocus(object sender, MouseButtonEventArgs e)
{
menuAnimation(140, 0);
showRepo = false;
}
void menuAnimation(int from, int to)
{
DoubleAnimation animation = new DoubleAnimation();
animation.From = from;
animation.To = to;
animation.Duration = new Duration(TimeSpan.FromSeconds(.3));
animation.AccelerationRatio = 0.3;
animation.DecelerationRatio = 0.3;
Storyboard storyboard = new Storyboard();
Storyboard.SetTarget(animation, repomenu);
Storyboard.SetTargetProperty(animation,
new PropertyPath("Height", repomenu));
storyboard.Children.Add(animation);
this.BeginStoryboard(storyboard);
//repomenu.Visibility = Visibility.Hidden;
showRepo = false;
}
void addNewMenuItem(string repoPath, string name)
{
MenuItem newItem = new MenuItem();
newItem.Header = name;
newItem.Tag = repoPath;
//newItem.Click += new EventHandler(this.setActiveRepo);
items.Add(newItem);
}
private void refreshEvents(object sender, RoutedEventArgs e)
{
eventbox.Items.Clear();
rposts.Clear();
redditWorker.RunWorkerAsync();
eventbutton.IsEnabled = false;
}
List<events> rposts = new List<events>();
void redditWorker_DoWork(object sender, DoWorkEventArgs e)
{
var reddit = new Reddit();
var rsubreddit = reddit.GetSubreddit(subreddit);
var posts = rsubreddit.GetHot();
foreach (var post in posts.Take(20))
{
if (post.LinkFlairText == "EVENT")
{
events evt = new events();
evt.title = post.Title.ToString();
evt.author = post.Author.ToString();
evt.url = post.Shortlink;
rposts.Add(evt);
}
}
}
void redditworker_Done(object sender, AsyncCompletedEventArgs e)
{
foreach (events evn in rposts)
{
Button newEvent = new Button();
newEvent.Content = evn.title + " by " + evn.author;
newEvent.Height = 50;
newEvent.Width = 520;
newEvent.Tag = evn.url;
newEvent.FontSize = 14;
newEvent.Click += newEvent_Click;
eventbox.Items.Add(newEvent);
}
eventbutton.IsEnabled = true;
}
void newEvent_Click(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
//string url = button.Tag.ToString();
System.Diagnostics.Process.Start(button.Tag.ToString());
}
}
public class Mod {
public ImageSource status { get; set; }
public string modName { get; set; }
public string version { get; set; }
public string servVersion { get; set; }
}
public class events
{
public string title { get; set; }
public string author { get; set; }
public string url { get; set; }
}
}