forked from Buttys/DevProLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLauncherHelper.cs
170 lines (158 loc) · 6.45 KB
/
LauncherHelper.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
using System;
using System.Security.Cryptography;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using System.Net;
namespace YGOPro_Launcher
{
public static class LauncherHelper
{
public static string RequestWebData(string url)
{
try
{
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
using (StreamReader Reader = new StreamReader(webresponse.GetResponseStream()))
{
return Reader.ReadToEnd();
}
}
catch (WebException ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
public static string EncodePassword(string password)
{
var salt = System.Text.Encoding.UTF8.GetBytes("&^%£$Ugdsgs:;");
var userpassword = System.Text.Encoding.UTF8.GetBytes(password);
var hmacMD5 = new HMACMD5(salt);
var saltedHash = hmacMD5.ComputeHash(userpassword);
//Convert encoded bytes back to a 'readable' string
return Convert.ToBase64String(saltedHash);
}
public static string[] OpenFileWindow(string title, string startpath, string filefilter, bool multiselect)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.InitialDirectory = startpath;
dialog.Title = title;
dialog.Filter = filefilter;
dialog.Multiselect = true;
if ((dialog.ShowDialog() == DialogResult.OK))
{
return dialog.FileNames;
}
return null;
}
public delegate void UpdateUserInfo();
public static UpdateUserInfo GameClosed;
public static void RunGame(string arg)
{
try
{
Process process = new Process();
ProcessStartInfo startInfos = new ProcessStartInfo(Program.Config.LauncherDir + Program.Config.GameExe, arg);
process.StartInfo = startInfos;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.StartInfo.WorkingDirectory = Program.Config.LauncherDir;
process.Exited += new EventHandler(UpdateInfo);
process.EnableRaisingEvents = true;
process.Start();
}
catch
{
MessageBox.Show("Cannot find: " +Program.Config.LauncherDir + Program.Config.GameExe);
}
}
static void UpdateInfo(object sender, EventArgs e)
{
if (GameClosed != null)
GameClosed();
}
private static bool InstantExsists(string processname)
{
Process[] pname = Process.GetProcessesByName(processname);
if (pname.Length == 0)
return true;
else
return false;
}
public static Process checkInstance()
{
Process cProcess = Process.GetCurrentProcess();
Process[] aProcesses = Process.GetProcessesByName(cProcess.ProcessName);
foreach (Process process in aProcesses)
{
if (process.Id != cProcess.Id)
{
if (Assembly.GetExecutingAssembly().Location == cProcess.MainModule.FileName)
{
return process;
}
}
}
return null;
}
public static void GenerateConfig(string roominfo)
{
if ((File.Exists(Program.Config.LauncherDir + "system.CONF")))
{
File.Delete(Program.Config.LauncherDir + "system.CONF");
}
char slash = '/';
char commer = ',';
string[] xparts = null;
string GameName = null;
xparts = roominfo.Split(slash);
GameName = xparts[3];
string[] GameNameParts = GameName.Split(commer);
StreamWriter writer = new StreamWriter(Program.Config.LauncherDir + "system.CONF");
writer.WriteLine("#config file");
writer.WriteLine("#nickname & gamename should be less than 20 characters");
writer.WriteLine("#Generated using " + roominfo);
writer.WriteLine("use_d3d = " +Convert.ToInt32(Program.Config.Enabled3D));
writer.WriteLine(("antialias = " + Program.Config.Antialias));
writer.WriteLine("errorlog = 1");
writer.WriteLine(("nickname = " + Program.UserInfo.Username + "$" + Program.UserInfo.LoginKey));
writer.WriteLine("gamename = " + GameName);
writer.WriteLine(("roompass ="));
writer.WriteLine(("lastdeck = " + Program.Config.DefaultDeck));
writer.WriteLine("textfont = fonts/simhei.ttf 14");
writer.WriteLine("numfont = fonts/arialbd.ttf");
writer.WriteLine(("serverport = " + Program.Config.GamePort));
writer.WriteLine(("lastip = " + Program.Config.ServerAddress));
writer.WriteLine(("lastport = " + Program.Config.GamePort));
writer.WriteLine(("fullscreen = " + Convert.ToInt32(Program.Config.Fullscreen)));
writer.WriteLine(("enable_sound = " + Convert.ToInt32(Program.Config.EnableSound)));
writer.WriteLine(("enable_music = " + Convert.ToInt32(Program.Config.EnableMusic)));
writer.Close();
}
public static string GenerateString()
{
Guid g = Guid.NewGuid();
string GuidString = Convert.ToBase64String(g.ToByteArray());
GuidString = GuidString.Replace("=", "");
GuidString = GuidString.Replace("+", "");
GuidString = GuidString.Replace("/", "");
return GuidString;
}
public static string GetUID()
{
if (RegEditor.Read("Software\\devpro\\", "UID") != null)
{
return RegEditor.Read("Software\\devpro\\", "UID");
}
else
{
RegEditor.CreateDirectory("Software\\devpro\\");
RegEditor.Write("Software\\devpro\\", "UID", GenerateString());
return RegEditor.Read("Software\\devpro\\", "UID");
}
}
}
}