-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainWindow.cs
308 lines (301 loc) · 11.1 KB
/
MainWindow.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
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Collections;
using System.Globalization;
using System.Resources;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using IWshRuntimeLibrary;
using System.Threading;
using System.Text.RegularExpressions;
namespace Shortcut_Generator
{
public partial class MainWindow : Form
{
public MainWindow()
{
InitializeComponent();
}
public bool hold = false;
Point CP;
List<string> NoIco = new List<string>();
List<string> GamePaths = new List<string>();
List<string> Games = new List<string>();
List<string> SelectedGames = new List<string>();
string GD;
string SD;
string CD;
string ID = "";
FolderBrowserDialog fbd = new FolderBrowserDialog();
private void reset()
{
CheckGames.Items.Clear();
GamePaths = new List<string>();
Games = new List<string>();
SelectedGames = new List<string>();
try
{
GamePaths.AddRange(Directory.GetFiles(GD, "*.rpx", SearchOption.AllDirectories));
GamePaths.AddRange(Directory.GetFiles(GD, "*.wud", SearchOption.AllDirectories));
GamePaths.AddRange(Directory.GetFiles(GD, "*.wux", SearchOption.AllDirectories));
GamePaths.AddRange(Directory.GetFiles(GD, "*.iso", SearchOption.AllDirectories));
GamePaths.AddRange(Directory.GetFiles(GD, "*.wad", SearchOption.AllDirectories));
}
catch (System.UnauthorizedAccessException e)
{
MessageBox.Show("No Access to " + GD + "\r\n" + e.Message);
Back_Click(new object(), new EventArgs());
}
foreach (var s in GamePaths)
{
Games.Add(ToGameName(s));
}
CheckGames.Items.AddRange(Games.ToArray());
}
private void MainWindow_Load(object sender, EventArgs e)
{
RegistryKey Software =
Registry.CurrentUser.OpenSubKey("Software");
using (RegistryKey
Directories = Software.OpenSubKey("Shortcut-Generator"))
{
GD = Directories.GetValue("GameDirectory").ToString();
SD = Directories.GetValue("ShortcutDirectory").ToString();
CD = Directories.GetValue("CEMUDirectory").ToString();
try
{
ID = Directories.GetValue("IconDirectory").ToString();
}
catch
{
checkBox1.Enabled = false;
}
}
reset();
}
private void CreateShortcut(string shpath, string CMpath, string Game, string Gamepath, string GameID, string icopath)
{
WshShell shell = new WshShell();
object shDesktop = (object)"Desktop";
string shortcutAddress = shpath + @"\" + Game + ".lnk";
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.Description = "Created by Shortcut-Generator for CEMU";
shortcut.TargetPath = CMpath + @"\cemu.exe";
shortcut.WorkingDirectory = CMpath;
if (checkBox1.Checked)
{
if (Directory.Exists(icopath))
{
string ico = icopath + @"\" + GameID + @".ico";
if (System.IO.File.Exists(ico))
{
shortcut.IconLocation = ico;
}
else
{
NoIco.Add(Game + " [" + GameID + "]\r\n");
}
}
else
{
MessageBox.Show("Your Icon-Path hasn't been found?");
DialogResult dialogResult = MessageBox.Show("Do you want to select a new one?\r\n(Alternatively Icons are unavailable)", "Shortcut-Generator", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
Back_Click(new object(), new EventArgs());
}
else if (dialogResult == DialogResult.No)
{
MessageBox.Show("Continuing without Icons!");
}
}
}
string args = "-g \"" + Gamepath + "\"";
if (checkBox1.Checked)
args += " -f";
shortcut.Arguments = args;
shortcut.Save();
reset();
//MainWindow_Load(new object(), new EventArgs());
}
private void Continue_Click(object sender, EventArgs e)
{
foreach (Object item in CheckGames.CheckedItems)
{
int index = CheckGames.Items.IndexOf(item);
SelectedGames.Add(GamePaths[index]);
//MessageBox.Show(index.ToString());
}
foreach (var item in SelectedGames)
{
CreateShortcut(SD, CD, ToGameName(item), item, ToID(item), ID);
}
if (NoIco.Count > 0)
{
MessageBox.Show("Icons not found for:\r\n" + string.Join("", NoIco));
NoIco = new List<string>();
}
}
private string ToGameName(string s)
{
string a = s;
a = a.Substring(GD.Length + 1, a.Length - GD.Length - 1);
a = a.Substring(0, a.IndexOfAny(new char[] { '\\', '[' }));
a = a.TrimEnd(' ');
return a;
}
private string ToID(string s)
{
string a = s;
a = a.Substring(GD.Length + 1, a.Length - GD.Length - 1);
a = a.Substring(0, a.IndexOf('\\'));
a = Regex.Match(a, @"\[([^)]*)\]").Groups[1].Value;
//MessageBox.Show((a.Substring(Math.Max(0, a.Length - 4))).ToString());
if (a.Substring(Math.Max(0, a.Length - 2)) == "01")
{
//MessageBox.Show("1");
a = a.Substring(0, a.Length - 2);
StringBuilder sb = new StringBuilder(a);
if (a.Substring(Math.Max(0, a.Length - 2)) == "01")
{
sb[a.Length - 3] = 'E';
}
else
{
sb[a.Length - 1] = 'E';
}
a = sb.ToString();
}
else
{
StringBuilder sb = new StringBuilder(a);
//sb[a.Length - 3] = 'E';
//a = sb.ToString();
try
{
a = a.Substring(0, a.LastIndexOf('P'));
}
catch
{
return "ERROR, for not European games with strange ID-Thingys\r\n--(like [BRX(E/P/A)NV]; not ending on 01 or 0101), not supported quite yet!\r\n--Also, dont put .rpx/.iso/.wud/.wad files in folders, without []!";
}
a += "E";
}
//MessageBox.Show(a);
return a;
}
private void MainWindow_MouseDown(object sender, MouseEventArgs e)
{
hold = true;
CP = Cursor.Position;
}
private void MainWindow_MouseUp(object sender, MouseEventArgs e)
{
hold = false;
}
private void MainWindow_MouseMove(object sender, MouseEventArgs e)
{
if (hold)
{
Point FormLocation = Location;
Point CursorLocation = Cursor.Position;
if (FormLocation.Y <= CursorLocation.Y + 50)
{
Top = FormLocation.Y + (CursorLocation.Y - CP.Y);
Left = FormLocation.X + (CursorLocation.X - CP.X);
//.Show((CursorLocation.X - FormLocation.X).ToString() + "\r\n" + (CursorLocation.Y - FormLocation.Y));
CP = Cursor.Position;
}
}
}
private void X_Click(object sender, EventArgs e)
{
this.Close();
}
private void minus_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
//X
private void X_MouseEnter(object sender, EventArgs e)
{
this.X.Image = global::Shortcut_Generator.Properties.Resources.X_hover;
}
private void X_MouseLeave(object sender, EventArgs e)
{
this.X.Image = global::Shortcut_Generator.Properties.Resources.X;
}
private void X_MouseDown(object sender, MouseEventArgs e)
{
this.X.Image = global::Shortcut_Generator.Properties.Resources.X_click;
}
private void X_MouseUp(object sender, MouseEventArgs e)
{
this.X.Image = global::Shortcut_Generator.Properties.Resources.X_hover;
}
//minus
private void minus_MouseEnter(object sender, EventArgs e)
{
this.minus.Image = global::Shortcut_Generator.Properties.Resources.minus_hover;
}
private void minus_MouseLeave(object sender, EventArgs e)
{
this.minus.Image = global::Shortcut_Generator.Properties.Resources.minus;
}
private void minus_MouseDown(object sender, MouseEventArgs e)
{
this.minus.Image = global::Shortcut_Generator.Properties.Resources.minus_click;
}
private void minus_MouseUp(object sender, MouseEventArgs e)
{
this.minus.Image = global::Shortcut_Generator.Properties.Resources.minus_hover;
}
//label-moving
private void label1_MouseDown(object sender, MouseEventArgs e)
{
MainWindow_MouseDown(sender, e);
}
private void label1_MouseMove(object sender, MouseEventArgs e)
{
MainWindow_MouseMove(sender, e);
}
private void label1_MouseUp(object sender, MouseEventArgs e)
{
MainWindow_MouseUp(sender, e);
}
//credit
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://sythriox.deviantart.com/art/Wii-U-game-icons-for-CEMU-667116100");
}
private void MainWindow_OnClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
Application.Exit();
}
private void CheckAll_Click(object sender, EventArgs e)
{
bool b = true;
if (CheckGames.CheckedItems.Count == Games.Count)
b = false;
for (int i = 0; i < CheckGames.Items.Count; i++)
{
CheckGames.SetItemChecked(i, b);
}
}
private void Back_Click(object sender, EventArgs e)
{
Setup s = new Setup();
s.Show();
this.Hide();
}
}
}