-
Notifications
You must be signed in to change notification settings - Fork 0
/
OSL.cs
326 lines (291 loc) · 12.9 KB
/
OSL.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
//Code by Samantha Joy (https://github.com/SamanthaJoy)
//Additional code added by Gruntlord6
//Licensed under GPLv3, check LICENSE
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Windows.Forms;
using System.Xml;
using System.ServiceModel.Syndication;
namespace OldSpice
{
public partial class OSL : Form
{
public OSL()
{
InitializeComponent();
}
Stopwatch watch = new Stopwatch();
WebClient webClient = new WebClient();
public String procArch;
public void ProcessStart(string fileName)
{
ProcessStart(fileName, null);
}
public void ProcessStart(string fileName, string args)
{
var psi = new ProcessStartInfo();
psi.UseShellExecute = true;
psi.WorkingDirectory = Path.GetDirectoryName(fileName);
psi.FileName = fileName;
if (args != null && args.Length > 0) psi.Arguments = args;
if (Environment.OSVersion.Version >= new Version(6, 2, 9200, 0))
{
psi.EnvironmentVariables["__COMPAT_LAYER"] += "WINXPSP2 SingleProcAffinity EmulateSlowCPU ";
psi.UseShellExecute = false;
}
Process.Start(psi);
}
private void OSL_Load(object sender, EventArgs e)
{
getNewsFeed();
getVersion();
}
private void button2_Click(object sender, EventArgs e)
{
//Since DisplayIcon IS the executable, we can just set that as a string to be launched.
string fileName = getRegistryValue("DisplayIcon");
ProcessStart(fileName);
}
private void button1_Click(object sender, EventArgs e)
{
try
{
//Grabs version of local install
string localVersionString = getRegistryValue("DisplayVersion");
//Grabs version.txt from the server
WebRequest request = WebRequest.Create("http://old.gruntmods.com/Support/version2.txt");
WebResponse response = request.GetResponse();
//Reads the text file
System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream());
//Turns the contents of the text file into a string
string newestversion = sr.ReadToEnd();
onlineVersion.Text = newestversion;
//Self explanatory
Version onlinev = new Version(newestversion);
Version localv = new Version(localVersionString);
//This is for allowing the Update button to be used
if (onlinev > localv)
{
kUpdateButton.Visible = true;
kUpdateLabel.Visible = true;
kUpdatedLabel.Visible = false;
}
//If there isn't an update
else if (localv == onlinev)
{
kUpdatedLabel.Visible = true;
kUpdateLabel.Visible = false;
}
else if (localv > onlinev)
{
MessageBox.Show("Your version is newer then the one hosted online.", "Client Newer Then Server");
}
}
catch (Exception ex)
{
MessageBox.Show("Update version cannot be received from update server.\rPlease visit support the support page and let us know if the issue persists.\rhttps://gruntmods.com/contact-us/", "Version not found");
Console.WriteLine(ex.Message);
}
}
private void kUpdateButton_Click(object sender, EventArgs e)
{
//deletes update.exe just in case the update file is present from a previous update attempt
File.Delete(@"update.exe");
WebClient webClient = new WebClient();
webClient.DownloadFileAsync(new Uri("http://old.gruntmods.com/Support/Updates/1.6.2/update1.6.2.2.exe"), @"update.exe");
kUpdateButton.Enabled = false;
watch.Start();
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
//Shows the progress of the download
size.Visible = true;
progress.Visible = true;
percent.Visible = true;
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
About about = new About();
about.Show();
}
public string getRegistryValue(string value)
{
string localVersion;
switch (procArch)
{ //If the processor is x86 - then remove "WOW6432Node"
case "AMD64": localVersion = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Dune 2000: Gruntmods Edition", value, null); break;
case "x86": localVersion = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Dune 2000: Gruntmods Edition", value, null); break;
default: localVersion = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Dune 2000: Gruntmods Edition", value, null); break;
}
return localVersion;
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
//resets stopwatch once download finishes
watch.Reset();
try
{
if (!IsProcessOpen("update"))
{
//launches the update only if the download is completed
Process.Start("update.exe");
this.Close();
}
else
{
MessageBox.Show("The update program is already running!\r Please close it before continuing", "Update already running");
}
}
catch
{
MessageBox.Show("The update program was unable to run.\rPlease contact support.\rhttps://gruntmods.com/contact-us/");
size.Visible = false;
progress.Visible = false;
percent.Visible = false;
}
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
//To open a link in a program thats running with elevated privileges, it needs to be launched through explorer for some stupid reason
var startInfo = new ProcessStartInfo("explorer.exe", "http://gruntmods.com");
Process.Start(startInfo);
}
public bool IsProcessOpen(string name)
{
//here we're going to get a list of all running processes on the computer
foreach (Process clsProcess in Process.GetProcesses())
{
//now we're going to see if any of the running processes
//match the currently running processes. Be sure to not
//add the .exe to the name you provide, i.e: NOTEPAD,
//not NOTEPAD.EXE or false is always returned even if
//notepad is running.
//Remember, if you have the process running more than once,
//say IE open 4 times the loop thr way it is now will close all 4,
//if you want it to just close the first one it finds
//then add a return; after the Kill
if (clsProcess.ProcessName.Contains(name))
{
//if the process is found to be running then we
//return a true
return true;
}
}
//otherwise we return a false
return false;
}
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
try
{
//Only changes the progressbar if there has been any change to the percent
if (progress.Value != e.ProgressPercentage)
progress.Value = e.ProgressPercentage;
//How much has been downloaded on the percent label
if (percent.Text != e.ProgressPercentage.ToString() + "%")
percent.Text = e.ProgressPercentage.ToString() + "%";
//How much has been downloaded on the size label
size.Text = (Convert.ToDouble(e.TotalBytesToReceive) / 1024 / 1024).ToString("0.00") + "MB";
}
catch (Exception ex)
{
//Messagebox displays any exceptions thrown by the download
MessageBox.Show(ex.Message);
}
}
private void button3_Click(object sender, EventArgs e)
{
string configureSettings = getRegistryValue("ConfigureSettings");
ProcessStart(configureSettings);
}
private void button4_Click(object sender, EventArgs e)
{
string multiPlayer = getRegistryValue("Multiplayer");
ProcessStart(multiPlayer);
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
//To open a link in a program thats running with elevated privileges, it needs to be launched through explorer for some stupid reason
var startInfo = new ProcessStartInfo("explorer.exe", "http://forum.dune2k.com/forum/37-dune-2000-support/");
Process.Start(startInfo);
}
private void button5_Click(object sender, EventArgs e)
{
Toolkit toolkit = new Toolkit();
toolkit.Show();
}
private void button6_Click(object sender, EventArgs e)
{
string RiseOfMerc = getRegistryValue("RiseOfMerc");
Process.Start(RiseOfMerc);
}
private void button7_Click(object sender, EventArgs e)
{
string MissionLauncher = getRegistryValue("MissionLauncher");
Process.Start(MissionLauncher);
}
private void RSSViewer_CellClick(object sender, DataGridViewCellEventArgs e)
{
var rssurl = RSSViewer.CurrentRow.Cells[1].Value.ToString();
var launchRSSUrl = new ProcessStartInfo("explorer.exe", rssurl);
Process.Start(launchRSSUrl);
}
private void getNewsFeed()
{
string url = "https://gruntmods.com/category/dune-2000-gruntmods-edition/duneupdates/feed/";
try
{
using (XmlReader reader = XmlReader.Create(url))
{
SyndicationFeed feed = SyndicationFeed.Load(reader);
RSSViewer.ColumnCount = 2;
RSSViewer.Columns[1].Visible = false;
DataGridViewColumn column1 = RSSViewer.Columns[0];
column1.Width = RSSViewer.Width - 20;
foreach (SyndicationItem item in feed.Items)
{
//RSSViewer.Rows.Add(item.Title.Text, item.Summary.Text);
RSSViewer.Rows.Add(item.Title.Text, item.Links[0].Uri);
RSSViewer.Rows.Add(item.Summary.Text, item.Links[0].Uri);
RSSViewer.Rows.Add("");
}
RSSViewer.Rows[0].Selected = false;
}
}
catch
{
MessageBox.Show("Unable to fetch newsfeed.\r\nServer may be down. If not, please check your connection settings.");
}
}
private void getVersion()
{
procArch = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
//Grabs version of local installation
string localVersionString = getRegistryValue("DisplayVersion");
//Pretty much some shit in case they dont have the game installed
if (localVersionString == null)
{
localVersion.Text = "Not Detected";
button1.Enabled = false;
button1.Text = "Game not installed";
button2.Enabled = false;
button2.Text = "Game not installed";
button3.Enabled = false;
button3.Text = "Game not installed";
button4.Enabled = false;
button4.Text = "Game not installed";
button5.Enabled = false;
button5.Text = "Game not installed";
MessageBox.Show("The game is not installed correctly, please reinstall it. If you need technical support, visit https://gruntmods.com/contact-us/");
}
else
{
//Self-explanatory
localVersion.Text = localVersionString;
}
}
}
}