-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
1139 lines (959 loc) · 44.4 KB
/
Form1.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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Microsoft.Win32;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Net;
using System.IO;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using System.Net.NetworkInformation;
using System.Threading;
using System.Collections.Specialized;
using System.Diagnostics;
namespace ArmaCore_Client
{
public partial class Form1 : Form
{
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
public Form1()
{
InitializeComponent();
// Get the steam path from the registry.
var steamPath = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Valve\Steam", "SteamPath", "") as string;
// We need the path to the steam folder.
if (String.IsNullOrEmpty(steamPath))
throw new InvalidOperationException("Unable to locate the steam folder");
// Set the module directory to steam.
SetDllDirectory(steamPath);
// Load the steam client library.
_handle = LoadLibraryEx(Environment.Is64BitProcess ?
"steamclient64.dll" : "steamclient.dll", IntPtr.Zero, 8);
// Restore default path.
SetDllDirectory(null);
// We have to be able to load the library.
if (_handle == IntPtr.Zero)
throw new InvalidOperationException("Unable to load steamclient.dll");
// Get the virtual table address of the steam client interface.
_steamClientVirtualTable = GetSteamClientVirtualTableAddress();
// Make sure we have the virtual table address.#FF0000
if (_steamClientVirtualTable == IntPtr.Zero)
throw new InvalidOperationException("Unable to get the address of ISteamClient012");
}
public static class Globals
{
public static string steam64ID;
public static string serverIP;
public static int whitelisted;
public static int blacklisted;
public static int adminlvl;
public static string a3Path;
public static List<string> FTPFilesFound = new List<string>();
public static string[] FilesFoundDelete;
public static int FTPFiles = 0;
public static int FTPFilesDownloaded = 0;
public static bool FileDownload_InProgress = false;
public static bool CancelDownload = false;
}
private void Button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void Button2_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
public class Server_Info
{
public string personaname { get; set; }
public string players { get; set; }
public string max_players { get; set; }
public string avatarmedium { get; set; }
public string Name { get; set; }
}
public void pingServer()
{
using (Ping p = new Ping())
{
while (true)
{
var ping = p.Send(Globals.serverIP).RoundtripTime.ToString();
var pingMS = Int32.Parse(ping);
if (pingMS < 55)
{
labelsrvPing.Invoke((MethodInvoker)(() => {
labelsrvPing.Text = ping + "ms";
labelsrvPing.ForeColor = Color.DarkGreen;
}));
} else if (pingMS > 55 && pingMS < 80)
{
labelsrvPing.Invoke((MethodInvoker)(() => {
labelsrvPing.Text = ping + "ms";
labelsrvPing.ForeColor = Color.GreenYellow;
}));
} else if (pingMS > 80)
{
labelsrvPing.Invoke((MethodInvoker)(() => {
labelsrvPing.Text = ping + "ms";
labelsrvPing.ForeColor = Color.DarkRed;
}));
}
Thread.Sleep(3000);
}
}
}
public void ServerStatus()
{
using (WebClient client = new WebClient())
{
try
{
string json_result = client.DownloadString("https://api.steampowered.com/IGameServersService/GetServerList/v1/?filter=\\appid\\107410\\gameaddr\\" + Globals.serverIP + ":2302 &key=8EBF814ECA6B306B6A1AF2FEA5F4B62D");
var data = (JObject)JsonConvert.DeserializeObject(json_result);
var result = data.SelectToken("response.servers").ToString();
JavaScriptSerializer js = new JavaScriptSerializer();
Server_Info[] ServerInfo = js.Deserialize<Server_Info[]>(result);
foreach (var i in ServerInfo)
{
labelsrvName.Invoke((MethodInvoker)(() => labelsrvName.Text = i.Name));
labelsrvOnline.Invoke((MethodInvoker)(() => labelsrvOnline.Text = i.players + " / " + i.max_players));
labelsrvStatus.Invoke((MethodInvoker)(() => labelsrvStatus.Text = "Online"));
labelsrvStatus.Invoke((MethodInvoker)(() => labelsrvStatus.ForeColor = Color.DarkGreen));
}
}
catch
{
labelsrvName.Invoke((MethodInvoker)(() => labelsrvName.Text = "N/A"));
labelsrvOnline.Invoke((MethodInvoker)(() => labelsrvOnline.Text = "N/A"));
labelsrvStatus.Invoke((MethodInvoker)(() => labelsrvStatus.Text = "Offline"));
labelsrvStatus.Invoke((MethodInvoker)(() => labelsrvStatus.ForeColor = Color.DarkRed));
}
}
}
public void loadCheckBoxes()
{
checkshowScriptErrors.Checked = false;
checkNoSplash.Checked = false;
checkNoPause.Checked = false;
checknologs.Checked = false;
checkSkipIntro.Checked = false;
checkWindow.Checked = false;
check64Bit.Checked = false;
if (Properties.Settings.Default.showScriptErrors)
{
checkshowScriptErrors.Checked = true;
}
if (Properties.Settings.Default.NoSplash)
{
checkNoSplash.Checked = true;
}
if (Properties.Settings.Default.noPause)
{
checkNoPause.Checked = true;
}
if (Properties.Settings.Default.noLogs)
{
checknologs.Checked = true;
}
if (Properties.Settings.Default.skipIntro)
{
checkSkipIntro.Checked = true;
}
if (Properties.Settings.Default.Window)
{
checkWindow.Checked = true;
}
if (Properties.Settings.Default.A364Bit)
{
check64Bit.Checked = true;
}
}
public void loadClientStats()
{
using (WebClient client = new WebClient())
{
NameValueCollection postData = new NameValueCollection()
{
{"Steam64", Globals.steam64ID}
};
string pagesource = Encoding.UTF8.GetString(client.UploadValues("http://" + Globals.serverIP + "/getUserStats.php", postData));
List<string> jsonlist = JsonConvert.DeserializeObject<List<string>>(pagesource);
int index = 0;
foreach (var value in jsonlist)
{
switch(index)
{
case 0:
Globals.whitelisted = Int32.Parse(value);
break;
case 1:
Globals.blacklisted = Int32.Parse(value);
break;
case 2:
Globals.adminlvl = Int32.Parse(value);
break;
case 3:
txtCash.Invoke((MethodInvoker)(() => txtCash.Text = "$" + String.Format("{0:n0}", Int32.Parse(value))));
break;
case 4:
txtBank.Invoke((MethodInvoker)(() => txtBank.Text = "$" + String.Format("{0:n0}", Int32.Parse(value))));
break;
case 5:
TimeSpan time = TimeSpan.FromSeconds(Int32.Parse(value));
string str = time.ToString(@"hh\:mm\:ss");
txtPlaytime.Invoke((MethodInvoker)(() => txtPlaytime.Text = str));
break;
}
index++;
}
if (Globals.whitelisted == 1)
{
labelWhitelisted.Invoke((MethodInvoker)(() => labelWhitelisted.Text = "You are whitelisted for ArmaCore!"));
labelWhitelisted.Invoke((MethodInvoker)(() => labelWhitelisted.ForeColor = Color.DarkGreen));
}
else
{
labelWhitelisted.Invoke((MethodInvoker)(() => labelWhitelisted.Text = "You are not whitelisted!"));
labelWhitelisted.Invoke((MethodInvoker)(() => labelWhitelisted.ForeColor = Color.DarkRed));
}
};
}
public void checkforClientUpdate()
{
string currentVersion = this.ProductVersion.ToString();
using (WebClient client = new WebClient())
{
NameValueCollection postData = new NameValueCollection()
{
{"Steam64", Globals.steam64ID}
};
string version = Encoding.UTF8.GetString(client.UploadValues("http://54.39.130.122/version.php", postData));
if (currentVersion != version)
{
MessageBox.Show("There is a new client version, update starting now!", "New client version", MessageBoxButtons.OK, MessageBoxIcon.Information);
string pathtoExeFile = System.Reflection.Assembly.GetEntryAssembly().Location;
string pathtoUpdater = Path.GetDirectoryName(pathtoExeFile) + "\\ArmaCoreInstaller.exe";
System.Diagnostics.Process.Start(pathtoUpdater);
this.Close();
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
checkforClientUpdate();
labelVersion.Text = "Client Version: " + this.ProductVersion.ToString();
Globals.steam64ID = GetSteamId().ToString(CultureInfo.InvariantCulture);
serverCombo.DropDownStyle = ComboBoxStyle.DropDownList;
Globals.serverIP = "54.39.130.122";
Task.Run(() => ServerStatus());
Task.Run(() => loadClientStats());
Task.Run(() => pingServer());
loadCheckBoxes();
button4.Enabled = false;
using (WebClient client = new WebClient())
{
var json_result = client.DownloadString("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=8EBF814ECA6B306B6A1AF2FEA5F4B62D&format=json&steamids=" + Globals.steam64ID);
var data = (JObject)JsonConvert.DeserializeObject(json_result);
var result1 = data.SelectToken("response.players").ToString();
JavaScriptSerializer js = new JavaScriptSerializer();
Server_Info[] ServerInfo = js.Deserialize<Server_Info[]>(result1);
foreach (var i in ServerInfo)
{
labelWelcome.Text = "Welcome " + i.personaname + " to ArmaCore Client";
}
if (Globals.steam64ID == "")
{
MessageBox.Show("Please login to your steam account before using our launcher!", "Error with steam", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
};
if (Properties.Settings.Default.a3path != "")
{
txt_a3path.Text = Properties.Settings.Default.a3path;
Globals.a3Path = Properties.Settings.Default.a3path;
} else
{
var steamPath = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Valve\Steam", "SteamPath", "") as string;
string arma3Path = @"" + steamPath + "/steamapps/common/Arma 3";
Globals.a3Path = arma3Path;
txt_a3path.Text = arma3Path;
}
}
/// <summary>
/// Handle to the steamclient.dll.
/// </summary>
private readonly IntPtr _handle;
/// <summary>
/// Address to the vtable of the steam client.
/// </summary>
private readonly IntPtr _steamClientVirtualTable;
/// <summary>
/// Call the CreateInterface method in the Steam Client.
/// </summary>
private IntPtr CreateInterface(string version)
{
// Get the address of CreateInterface.
var address = GetProcAddress(_handle, "CreateInterface");
// We require the address of CreateInterface.
if (address == IntPtr.Zero)
throw new InvalidOperationException("CreateInterface not found in steamclient.dll");
// Marshal the function so we can call it.
var createInterface = (CreateInterfaceFn)Marshal.GetDelegateForFunctionPointer(
address, typeof(CreateInterfaceFn));
// Call the function.
return createInterface(version, IntPtr.Zero);
}
/// <summary>
/// Get the virtual table address of the ISteamClient012 interface.
/// </summary>
private IntPtr GetSteamClientVirtualTableAddress()
{
// Use CreateInterface to create the interface and return a pointer.
var address = CreateInterface("SteamClient012");
// Read the pointer to the vtable.
return Marshal.ReadIntPtr(address);
}
/// <summary>
/// Create a steam pipe and return the handle.
/// </summary>
private int CreateSteamPipe()
{
// The CreateSteamPipe function is index 0 in the vtable.
var createSteamPipe = (CreateSteamPipeFn)Marshal.GetDelegateForFunctionPointer(
Marshal.ReadIntPtr(_steamClientVirtualTable, 0 * IntPtr.Size), typeof(CreateSteamPipeFn));
// Call the method and return the handle.
return createSteamPipe(_steamClientVirtualTable);
}
/// <summary>
/// Create a steam pipe and return the handle.
/// </summary>
private bool ReleaseSteamPipe(int hSteamPipe)
{
// The BReleaseSteamPipe function is index 1 in the vtable.
var releaseSteamPipe = (ReleaseSteamPipeFn)Marshal.GetDelegateForFunctionPointer(
Marshal.ReadIntPtr(_steamClientVirtualTable, 1 * IntPtr.Size), typeof(ReleaseSteamPipeFn));
// Call the method and return the status.
return releaseSteamPipe(_steamClientVirtualTable, hSteamPipe);
}
/// <summary>
/// Get a handle to the global user.
/// </summary>
private int ConnectToGlobalUser(int hSteamPipe)
{
// The ConnectToGlobalUser function is index 2 in the vtable.
var connectToGlobalUser = (ConnectToGlobalUserFn)Marshal.GetDelegateForFunctionPointer(
Marshal.ReadIntPtr(_steamClientVirtualTable, 2 * IntPtr.Size), typeof(ConnectToGlobalUserFn));
// Call the method and return the handle.
return connectToGlobalUser(_steamClientVirtualTable, hSteamPipe);
}
/// <summary>
/// Release the handle to the steam user.
/// </summary>
private void ReleaseUser(int hSteamPipe, int hSteamUser)
{
// The ReleaseUser function is index 4 in the vtable.
var releaseUser = (ReleaseUserFn)Marshal.GetDelegateForFunctionPointer(
Marshal.ReadIntPtr(_steamClientVirtualTable, 4 * IntPtr.Size), typeof(ReleaseUserFn));
// Call the method to release the user handle.
releaseUser(_steamClientVirtualTable, hSteamPipe, hSteamUser);
}
/// <summary>
/// Get the steam id of the current user.
/// </summary>
public UInt64 GetSteamId()
{
try
{
// Create a steam pipe and connect to the global user.
var hSteamPipe = CreateSteamPipe();
var hSteamUser = ConnectToGlobalUser(hSteamPipe);
// The GetSteamUser function is index 5 in the vtable.
var getSteamUser = (GetSteamUserFn)Marshal.GetDelegateForFunctionPointer(
Marshal.ReadIntPtr(_steamClientVirtualTable, 5 * IntPtr.Size), typeof(GetSteamUserFn));
// Get the address where we can find the vtable address.
var steamUserAddress = getSteamUser(_steamClientVirtualTable, hSteamUser, hSteamPipe, "SteamUser012");
// Get the virtual table of the user.
var steamUserVirtualTableAddress = Marshal.ReadIntPtr(steamUserAddress);
// The GetSteamId function is index 2 in the vtable.
var getSteamId = (GetSteamIdFn)Marshal.GetDelegateForFunctionPointer(
Marshal.ReadIntPtr(steamUserVirtualTableAddress, 2 * IntPtr.Size), typeof(GetSteamIdFn));
// Create a variable to hold the steam id.
UInt64 id = 0;
// Call the method to read the steam id into the variable.
getSteamId(steamUserAddress, ref id);
// Release the global user and steam pipe.
ReleaseUser(hSteamPipe, hSteamUser);
ReleaseSteamPipe(hSteamPipe);
// Return the steam id.
return id;
}
catch
{
return 0;
}
}
#region Delegates
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal delegate IntPtr CreateInterfaceFn(string version, IntPtr returnCode);
[UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Ansi)]
internal delegate int CreateSteamPipeFn(IntPtr thisA);
[UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Ansi)]
internal delegate bool ReleaseSteamPipeFn(IntPtr thisA, int hSteamPipe);
[UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Ansi)]
internal delegate int ConnectToGlobalUserFn(IntPtr thisA, int hSteamPipe);
[UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Ansi)]
internal delegate void ReleaseUserFn(IntPtr thisA, int hSteamPipe, int hUser);
[UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Ansi)]
internal delegate IntPtr GetSteamUserFn(IntPtr thisA, int hUser, int hSteamPipe, string pchVersion);
[UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Ansi)]
internal delegate void GetSteamIdFn(IntPtr thisA, ref UInt64 steamId);
#endregion
#region Native
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, UInt32 dwFlags);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool FreeLibrary(IntPtr hModule);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool SetDllDirectory(string lpPathName);
#endregion
private void Button3_Click(object sender, EventArgs e)
{
if (serverCombo.Text == "EU Server #1 (DEV)" && Globals.adminlvl <= 0)
{
MessageBox.Show("Your not whitelisted to join the development server.", "Not whitelisted", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (Globals.whitelisted == 0)
{
MessageBox.Show("Your not whitelisted to play on this server!\nvisit: Armacore.net for support.", "Not whitelisted", MessageBoxButtons.OK, MessageBoxIcon.Error);
} else if (Globals.blacklisted == 1)
{
MessageBox.Show("You have been blacklisted!\nvisit: Armacore.net for support.", "Blacklisted", MessageBoxButtons.OK, MessageBoxIcon.Error);
} else
{
string arma3Path = txt_a3path.Text;
if (Directory.Exists(arma3Path) == false)
{
MessageBox.Show("ArmA 3 path not found! " + arma3Path, "ArmA 3 path error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string arma3exeFile = "";
if (Properties.Settings.Default.A364Bit)
{
arma3exeFile = @"" + arma3Path + "/arma3_x64.exe";
}
else
{
arma3exeFile = @"" + arma3Path + "/arma3.exe";
}
if (!(File.Exists(arma3exeFile)))
{
MessageBox.Show("Error no ArmA 3 execute file was found! " + arma3exeFile, "Arma3exe not found.", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string launchOptions = "-connect=" + Globals.serverIP + " -port=2302 -password=armacoreFirst169420 -mod=@ArmaCore";
if (Properties.Settings.Default.showScriptErrors)
{
launchOptions += " -showScriptErrors";
}
if (Properties.Settings.Default.NoSplash)
{
launchOptions += " -noSplash";
}
if (Properties.Settings.Default.noPause)
{
launchOptions += " -noPause";
}
if (Properties.Settings.Default.noLogs)
{
launchOptions += " -noLogs";
}
if (Properties.Settings.Default.skipIntro)
{
launchOptions += " -skipIntro";
}
if (Properties.Settings.Default.Window)
{
launchOptions += " -Window";
}
System.Diagnostics.Process.Start(arma3exeFile, launchOptions);
}
}
}
}
private void CheckshowScriptErrors_CheckedChanged(object sender, EventArgs e)
{
if (checkshowScriptErrors.Checked)
{
Properties.Settings.Default.showScriptErrors = true;
} else
{
Properties.Settings.Default.showScriptErrors = false;
}
Properties.Settings.Default.Save();
}
private void Checknologs_CheckedChanged(object sender, EventArgs e)
{
if (checknologs.Checked)
{
Properties.Settings.Default.noLogs = true;
}
else
{
Properties.Settings.Default.noLogs = false;
}
Properties.Settings.Default.Save();
}
private void CheckNoPause_CheckedChanged(object sender, EventArgs e)
{
if (checkNoPause.Checked)
{
Properties.Settings.Default.noPause = true;
}
else
{
Properties.Settings.Default.noPause = false;
}
Properties.Settings.Default.Save();
}
private void CheckSkipIntro_CheckedChanged(object sender, EventArgs e)
{
if (checkSkipIntro.Checked)
{
Properties.Settings.Default.skipIntro = true;
}
else
{
Properties.Settings.Default.skipIntro = false;
}
Properties.Settings.Default.Save();
}
private void CheckWindow_CheckedChanged(object sender, EventArgs e)
{
if (checkWindow.Checked)
{
Properties.Settings.Default.Window = true;
}
else
{
Properties.Settings.Default.Window = false;
}
Properties.Settings.Default.Save();
}
private void CheckNoSplash_CheckedChanged(object sender, EventArgs e)
{
if (checkNoSplash.Checked)
{
Properties.Settings.Default.NoSplash = true;
}
else
{
Properties.Settings.Default.NoSplash = false;
}
Properties.Settings.Default.Save();
}
private void PanelTop_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
private void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (check64Bit.Checked)
{
Properties.Settings.Default.A364Bit = true;
}
else
{
Properties.Settings.Default.A364Bit = false;
}
Properties.Settings.Default.Save();
}
private void Button6_Click(object sender, EventArgs e)
{
loadClientStats();
}
WebClient webClient; // Our WebClient that will be doing the downloading for us
Stopwatch sw = new Stopwatch(); // The stopwatch which we will be using to calculate the download speed
private string[] CurrentFiles;
private static string GetFileSize(Uri uriPath)
{
var webRequest = HttpWebRequest.Create(uriPath);
webRequest.Method = "HEAD";
using (var webResponse = webRequest.GetResponse())
{
var fileSize = webResponse.Headers.Get("Content-Length");
return fileSize;
}
}
public void DownloadFile(string urlAddress, string location, string filename, string path)
{
using (webClient = new WebClient())
{
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
// The variable that will be holding the url address (making sure it starts with http://)
// Start the stopwatch which we will be using to calculate the download speed
sw.Start();
this.Invoke((MethodInvoker)(() =>
{
text_fileDownloading.Text = "Downloading File: " + filename;
}));
var size = GetFileSize(new Uri(urlAddress));
bool fileUptoDate = false;
if (File.Exists(@"" + Globals.a3Path + "\\@ArmaCore\\addons\\" + filename) || File.Exists(@"" + Globals.a3Path + "\\@ArmaCore\\" + filename))
{
string fileTypeurl = @"" + urlAddress;
string fileType = System.IO.Path.GetExtension(fileTypeurl);
long length = 1;
if (fileType == ".pbo" || fileType == ".ebo" || fileType == ".bisign")
{
if (File.Exists(@"" + Globals.a3Path + "\\@ArmaCore\\addons\\" + filename))
{
length = new System.IO.FileInfo(@"" + Globals.a3Path + "\\@ArmaCore\\addons\\" + filename).Length;
}
}
else
{
if (File.Exists(@"" + Globals.a3Path + "\\@ArmaCore\\" + filename))
{
length = new System.IO.FileInfo(@"" + Globals.a3Path + "\\@ArmaCore\\" + filename).Length;
}
}
if (Int32.Parse(size) == length)
{
fileUptoDate = true;
}
}
if (fileUptoDate == false)
{
this.Invoke((MethodInvoker)(() =>
{
progressBar2.Minimum = 0;
progressBar2.Value = 0;
progressBar2.Maximum = 100;
}));
try
{
// Start downloading the file
webClient.DownloadFileAsync(new Uri(urlAddress), location);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
Globals.FTPFilesDownloaded++;
Globals.FileDownload_InProgress = false;
this.Invoke((MethodInvoker)(() =>
{
progressBar1.Value = Globals.FTPFilesDownloaded;
}));
}
}
}
// The event that will fire whenever the progress of the WebClient is changed
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
this.Invoke((MethodInvoker)(() =>
{
// Calculate download speed and output it to labelSpeed.
text_speed.Text = string.Format("Download Speed: {0} kb/s", (e.BytesReceived / 1024d / sw.Elapsed.TotalSeconds).ToString("0.00"));
// Update the progressbar percentage only when the value is not the same.
progressBar2.Value = e.ProgressPercentage;
// Show the percentage on our label.
labelPerc.Text = "File Download Percentage: " + e.ProgressPercentage.ToString() + "%";
// Update the label with how much data have been downloaded so far and the total size of the file we are currently downloading
labelDownloaded.Text = string.Format("Downloaded: {0} MB's / {1} MB's",
(e.BytesReceived / 1024d / 1024d).ToString("0.00"),
(e.TotalBytesToReceive / 1024d / 1024d).ToString("0.00"));
}));
}
// The event that will trigger when the WebClient is completed
private void Completed(object sender, AsyncCompletedEventArgs e)
{
// Reset the stopwatch.
sw.Reset();
if (e.Cancelled == true)
{
Globals.CancelDownload = false;
Globals.FileDownload_InProgress = false;
}
else
{
//Finished
Globals.FileDownload_InProgress = false;
Globals.FTPFilesDownloaded++;
this.Invoke((MethodInvoker)(() =>
{
progressBar1.Value = Globals.FTPFilesDownloaded;
}));
}
}
public async void SyncFilesAsync(string FTPHost, string FTPUser, string FTPPW, string DownloadURL)
{
try
{
this.Invoke((MethodInvoker)(() =>
{
text_Sync.Text = "Syncing...";
}));
FtpWebRequest listRequest = (FtpWebRequest)WebRequest.Create("ftp://" + FTPHost);
listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
NetworkCredential credentials = new NetworkCredential(FTPUser, FTPPW);
listRequest.Credentials = credentials;
List<string> lines = new List<string>();
using (FtpWebResponse listResponse = (FtpWebResponse)listRequest.GetResponse())
using (Stream listStream = listResponse.GetResponseStream())
using (StreamReader listReader = new StreamReader(listStream))
{
while (!listReader.EndOfStream)
{
lines.Add(listReader.ReadLine());
}
listReader.Close();
}
Globals.FTPFilesFound.Clear();
Globals.FTPFiles = 0;
Globals.FTPFilesDownloaded = 0;
foreach (string line in lines)
{
string[] tokens = line.Split(new[] { ' ' }, 9, StringSplitOptions.RemoveEmptyEntries);
string name = tokens[8];
string permissions = tokens[0];
Globals.FTPFilesFound.Add(name);
Globals.FTPFiles++;
}
this.Invoke((MethodInvoker)(() =>
{
progressBar1.Minimum = 0;
progressBar1.Value = 0;
progressBar1.Maximum = Globals.FTPFiles;
}));
if (!(Directory.Exists(Globals.a3Path + "\\@ArmaCore\\addons\\")))
{
Directory.CreateDirectory(Globals.a3Path + "\\@ArmaCore\\addons\\");
}
CurrentFiles = Directory.GetFiles(@"" + Globals.a3Path + "\\@ArmaCore\\addons\\", "*");
string path = Globals.a3Path;
bool FileFound;
foreach (string file in CurrentFiles)
{
FileFound = false;
string filenew = Path.GetFileName(file);
foreach (string filename in Globals.FTPFilesFound)
{
if (filenew == filename)
{
FileFound = true;
}
}
if (FileFound == false)
{
File.Delete(file);
Globals.FTPFilesFound.Remove(file);
Globals.FTPFiles = Globals.FTPFiles - 1;
}
}
if (Globals.FTPFiles <= 0)
{
this.Invoke((MethodInvoker)(() =>
{
progressBar1.Value = 0;
}));
}
this.Invoke((MethodInvoker)(() =>
{
progressBar1.Maximum = Globals.FTPFiles;
}));
bool canceled = false;
Globals.CancelDownload = false;
Globals.FileDownload_InProgress = false;
foreach (string file in Globals.FTPFilesFound)
{
if (Globals.CancelDownload == true)
{
Globals.CancelDownload = false;
canceled = true;
break;
}
Globals.FileDownload_InProgress = true;
this.Invoke((MethodInvoker)(() =>
{
text_Sync.Text = "Syncing file " + file + "...";
}));
string fileTypeurl = @"" + DownloadURL + file;
string fileType = System.IO.Path.GetExtension(fileTypeurl);
if (fileType == ".pbo" || fileType == ".ebo" || fileType == ".bisign")
{
DownloadFile(DownloadURL + file, @"" + path + "\\@ArmaCore\\addons\\" + file, file, path);
}
else
{
DownloadFile(DownloadURL + file, @"" + path + "\\@ArmaCore\\" + file, file, path);
}
await Task.Delay(50);
while (Globals.FileDownload_InProgress == true)
{
await Task.Delay(50);
if (Globals.CancelDownload == true)
{
break;
}
}
}
if (canceled == false)
{
MessageBox.Show("Download finished!", "Finished", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Invoke((MethodInvoker)(() =>
{
text_Sync.Text = "";
text_fileDownloading.Text = "Downloading File:";