-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLauncherBox.cs
More file actions
308 lines (283 loc) · 10.3 KB
/
LauncherBox.cs
File metadata and controls
308 lines (283 loc) · 10.3 KB
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
/*
* LauncherShyax, un launcher pour World Of Warcraft avec téléchargement de mise à jour
Copyright (C) 2011 Shyax — Tous droits réservés.
Ce programme est un logiciel libre ; vous pouvez le redistribuer ou le
modifier suivant les termes de la “GNU General Public License” telle que
publiée par la Free Software Foundation : soit la version 3 de cette
licence, soit (à votre gré) toute version ultérieure.
Ce programme est distribué dans l’espoir qu’il vous sera utile, mais SANS
AUCUNE GARANTIE : sans même la garantie implicite de COMMERCIALISABILITÉ
ni d’ADÉQUATION À UN OBJECTIF PARTICULIER. Consultez la Licence Générale
Publique GNU pour plus de détails.
Vous devriez avoir reçu une copie de la Licence Générale Publique GNU avec
ce programme ; si ce n’est pas le cas, consultez :
<http://www.gnu.org/licenses/>.
* */
using System;
using System.Collections.Generic;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using Microsoft.Win32;
namespace LauncherShyax
{
public partial class Launcher : Form
{
#region Variables
public bool isAllowedToDeleteCache
{
get { return Configuration.Default.IsAllowedToDeleteCache; }
set { Configuration.Default.IsAllowedToDeleteCache = value; }
}
public string hostAddress
{
get { return Configuration.Default.HostAddress; }
}
public string siteAddress
{
get { return Configuration.Default.SiteAddress; }
}
public string forumAddress
{
get { return Configuration.Default.ForumAddress; }
}
public string bugTrackerAddress
{
get { return Configuration.Default.BugTrackerAddress; }
}
public int realmPort
{
get { return Convert.ToInt32(Configuration.Default.RealmServerPort); }
}
public int worldPort
{
get { return Convert.ToInt32(Configuration.Default.WorldServerPort); }
}
public string _wowDir
{
get { return Configuration.Default.WoWDirectory; }
set
{
Configuration.Default.WoWDirectory = value;
}
}
#endregion
public Launcher()
{
InitializeComponent();
}
private void LauncherBox_Load(object sender, EventArgs e)
{
FindWoWDir();
VerifyVersion();
VerifyStatus();
ChangeRealmlist();
AddLinks();
checkBoxCache.Checked = Configuration.Default.IsAllowedToDeleteCache;
}
/// <summary>
/// Find the game's directory locally (in the directory of the launcher) then in the registry
/// </summary>
private void FindWoWDir()
{
const string wowExe = "Wow.exe";
FileInfo wowInfo = new FileInfo(Path.Combine(_wowDir, wowExe));
if (wowInfo.Exists)
{
return;
}
else
{
// Look Locally before in registry
_wowDir = Path.GetFullPath(System.Reflection.Assembly.GetExecutingAssembly().Location);
FileInfo wowInfo2 = new FileInfo(Path.Combine(_wowDir, wowExe));
if (wowInfo2.Exists)
{
return;
}
else
{
// Look In Registry
RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE");
if (key == null)
{
MessageBox.Show("World Of Warcraft non trouvé. Raison : Clé SOFTWARE");
return;
}
if (Environment.Is64BitProcess)
{
key = key.OpenSubKey("Wow6432Node");
if (key == null)
{
MessageBox.Show("World Of Warcraft non trouvé. Raison : Clé Wow6432Node");
return;
}
}
key = key.OpenSubKey("Blizzard Entertainment");
if (key == null)
{
MessageBox.Show("World Of Warcraft non trouvé. Raison : Clé Blizzard Entertainment");
return;
}
key = key.OpenSubKey("World of Warcraft");
if (key == null)
{
MessageBox.Show("World Of Warcraft non trouvé. Raison : Clé World of Warcraft");
return;
}
_wowDir = key.GetValue("InstallPath").ToString();
key.Close();
}
}
}
/// <summary>
/// Verify if we have the latest version of the server using version.xml
/// If the file of the latest is not found, DownloaderBox is launched
/// </summary>
private void VerifyVersion()
{
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load("http://"+ hostAddress + "/version.xml");
}
catch (Exception e)
{
MessageBox.Show("XML de MAJ non trouvé !");
return;
}
const string dataDir = "Data";
DirectoryInfo mpqInfo = new DirectoryInfo(Path.Combine(_wowDir, dataDir));
FileInfo[] mpqFiles = mpqInfo.GetFiles("patch-*.mpq", SearchOption.TopDirectoryOnly);
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("version");
XmlNode lastNode = nodeList[0];
FileInfo lastNodeInfo = new FileInfo(lastNode.InnerText);
try
{
FileInfo contains = mpqFiles.First(fileInfo => fileInfo.Name == lastNode.InnerText);
}
catch (Exception e)
{
DownloaderBox dlBox = new DownloaderBox();
dlBox.Show(this);
dlBox.Download(nodeList, mpqFiles, Path.Combine(_wowDir, dataDir));
}
}
/// <summary>
/// Verify the status of the realm server and the world server using worldPort, realmPort and ipAddress
/// </summary>
private void VerifyStatus()
{
IPAddress[] address = Dns.GetHostAddresses(hostAddress);
Socket s = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
try
{
s.Connect(address[0], realmPort);
}
catch (Exception e)
{
pictureBoxRealm.Image = LauncherShyax.Properties.Resources.down;
}
pictureBoxRealm.Visible = true;
try
{
s.Connect(address[0], worldPort);
}
catch (Exception e)
{
pictureBoxWorld.Image = LauncherShyax.Properties.Resources.down;
}
pictureBoxWorld.Visible = true;
}
/// <summary>
/// Create a new realmlist.wtf
/// </summary>
private void ChangeRealmlist()
{
const string dataDir = "Data";
const string localeDir = "frFR";
const string realmFile = "realmlist.wtf";
FileInfo realmList = new FileInfo(Path.Combine(_wowDir, dataDir, localeDir, realmFile));
if (realmList != null)
{
realmList.Delete();
}
FileStream stream = realmList.Create();
byte[] bytes = Encoding.UTF8.GetBytes(("set realmlist " + hostAddress + ":" + worldPort));
stream.Write(bytes, 0, bytes.Length);
stream.Dispose();
}
private void AddLinks()
{
linkLabelSite.Links.Add(0, linkLabelSite.Text.Length, siteAddress);
linkLabelForum.Links.Add(0, linkLabelForum.Text.Length, forumAddress);
linkLabelBugTracker.Links.Add(0, linkLabelBugTracker.Text.Length, bugTrackerAddress);
}
/// <summary>
/// Delete the Cache/ directory
/// Call only when isAllowedToDeleteCache is true !
/// </summary>
private void DeleteCache()
{
const string cacheDir = "Cache";
DirectoryInfo cacheInfo = new DirectoryInfo(Path.Combine(_wowDir, cacheDir));
if (cacheInfo.Exists)
cacheInfo.Delete(true);
}
/// <summary>
/// Launch the game and close the launcher
/// </summary>
private void LaunchGame()
{
const string wowExe = "Wow.exe";
ProcessStartInfo wowStartInfo = new ProcessStartInfo(Path.Combine(_wowDir, wowExe));
Process.Start(wowStartInfo);
Close();
}
#region Events
private void pictureBoxLancer_Click(object sender, EventArgs e)
{
Configuration.Default.IsAllowedToDeleteCache = checkBoxCache.Checked;
Configuration.Default.Save();
if (checkBoxCache.Checked)
DeleteCache();
LaunchGame();
}
private void pictureBoxClose_Click(object sender, EventArgs e)
{
Close();
}
private void pictureBoxHelp_Click(object sender, EventArgs e)
{
HelpBox box = new HelpBox();
box.ShowDialog();
}
private void linkLabelSite_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
linkLabelSite.LinkVisited = true;
Process.Start(siteAddress);
}
private void linkLabelForum_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
linkLabelForum.LinkVisited = true;
Process.Start(forumAddress);
}
private void linkLabelBugTracker_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
linkLabelBugTracker.LinkVisited = true;
Process.Start(bugTrackerAddress);
}
#endregion
}
}