-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
308 lines (255 loc) · 9.96 KB
/
Program.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 System;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Controls;
using System.Windows.Forms;
using MCRPCGUI;
namespace MCRPCGUI
{
class Window
{
//Close console window
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool FreeConsole();
[STAThread]
public static void Main ()
{
FreeConsole ();
Application.EnableVisualStyles();
// ---- Icon ---- //
var iconpath = System.Reflection.Assembly.GetExecutingAssembly ().GetManifestResourceStream ("icon");
Icon icon = new Icon (iconpath);
// ---- GUI ---- //
//window
Form form = new Form();
form.Text = "RPCMC";
form.Width = 512;
form.Height = 350;
form.MaximizeBox = false;
form.MinimizeBox = false;
form.FormBorderStyle = FormBorderStyle.FixedSingle;
form.Icon = icon;
//pack name
TextBox namefield = new TextBox ();
namefield.Text = "Name";
namefield.Width = 128;
namefield.Height = 20;
namefield.TabIndex = 1;
namefield.Name = "namefield";
//start button
Button startbutton = new Button ();
startbutton.Text = "Create Pack";
startbutton.Width = 112;
startbutton.Height = 20;
startbutton.Location = new Point (128, 0);
startbutton.TabIndex = 5;
startbutton.Click += new EventHandler (startbutton_Click);
//description
TextBox descriptionfield = new TextBox ();
descriptionfield.Text = "Description";
descriptionfield.Multiline = true;
descriptionfield.Height = 80;
descriptionfield.Width = 240;
descriptionfield.Location = new Point (0, 20);
descriptionfield.TabIndex = 2;
descriptionfield.Name = "descriptionfield";
//log
TextBox outputfield = new TextBox ();
outputfield.Multiline = true;
outputfield.Width = 240;
outputfield.Height = 192;
outputfield.Location = new Point (0, 152);
outputfield.ReadOnly = true;
outputfield.Name = "outputfield";
var versionlist = new VersionList ();
//minecraft version
ComboBox versionbox = new ComboBox ();
versionbox.Width = 240;
versionbox.Height = 32;
versionbox.Location = new Point (0, 100);
versionbox.DropDownWidth = 256;
versionbox.DropDownStyle = ComboBoxStyle.DropDownList;
versionbox.Name = "versionbox";
foreach (var v in versionlist.versions) {
versionbox.Items.Add (v);
}
versionbox.SelectedIndex = 0;
//.minecraft subfolder
TextBox subfolder = new TextBox ();
subfolder.Height = 20;
subfolder.Width = 144;
subfolder.Location = new Point (96, 120);
subfolder.Name = "subfolder";
Label subfolder_label = new Label ();
subfolder_label.Text = "Profile subfolder:";
subfolder_label.Location = new Point (0, 124);
//vertical separator
Label vert_sep = new Label ();
vert_sep.AutoSize = false;
vert_sep.Height = 305;
vert_sep.Width = 2;
vert_sep.BorderStyle = BorderStyle.Fixed3D;
vert_sep.Location = new Point (243, 5);
//pack.png selection
Label preview_heading = new Label();
preview_heading.Text = "Select pack thumbnail";
preview_heading.Location = new Point (306, 16);
preview_heading.Width = 128;
preview_heading.TextAlign = ContentAlignment.MiddleCenter;
PictureBox preview_thumbnail = new PictureBox();
preview_thumbnail.Name = "preview_thumbnail";
preview_thumbnail.Width = 128;
preview_thumbnail.Height = 128;
preview_thumbnail.Location = new Point(306, 48);
preview_thumbnail.BorderStyle = BorderStyle.FixedSingle;
preview_thumbnail.SizeMode = PictureBoxSizeMode.StretchImage;
ContextMenu preview_context = new ContextMenu ();
MenuItem load_image = new MenuItem ();
load_image.Text = "Load image";
load_image.Click += new EventHandler (load_image_Click);
MenuItem clear_image = new MenuItem ();
clear_image.Text = "Clear image";
clear_image.Click += new EventHandler (clear_image_Click);
preview_context.MenuItems.Add (load_image);
preview_context.MenuItems.Add (clear_image);
preview_thumbnail.ContextMenu = preview_context;
TextBox preview_source = new TextBox ();
preview_source.Name = "preview_source";
preview_source.Width = 192;
preview_source.Location = new Point (274, 192);
preview_source.TextChanged += new EventHandler (preview_source_Change);
preview_source.MouseDoubleClick += new MouseEventHandler (preview_source_Click);
//tooltip
ToolTip tooltip1 = new ToolTip ();
tooltip1.AutoPopDelay = 7500;
tooltip1.InitialDelay = 1500;
tooltip1.ReshowDelay = 500;
tooltip1.ShowAlways = true;
tooltip1.SetToolTip (namefield, "Enter the name of your resource pack\n(Required)");
tooltip1.SetToolTip (descriptionfield, "Enter a description\n(Optional)");
tooltip1.SetToolTip (versionbox, "Select which Minecraft version RPCMC will use");
tooltip1.SetToolTip (subfolder, "Advanced:\nIf your launcher profiles use subfolders, enter the desired folder here\n(Optional)");
tooltip1.SetToolTip (preview_thumbnail, "Select a thumbnail image\n(Optional)");
tooltip1.SetToolTip (preview_source, "Type to select image\nDouble-click to open file window");
form.Controls.AddRange (new Control[] {
namefield,
startbutton,
descriptionfield,
outputfield,
versionbox,
subfolder,
subfolder_label,
vert_sep,
preview_heading,
preview_thumbnail,
preview_source
});
form.Show();
// ---- Run ---- //
Application.Run(form);
}
public static void preview_source_Change(object sender, EventArgs eventArgs)
{
TextBox preview_source = sender as TextBox;
Form form = preview_source.FindForm () as Form;
PictureBox preview_thumbnail = form.Controls ["preview_thumbnail"] as PictureBox;
preview_thumbnail.ImageLocation = preview_source.Text;
}
public static void preview_source_Click(object sender, EventArgs eventArgs)
{
TextBox preview_source = sender as TextBox;
Form form = preview_source.FindForm () as Form;
PictureBox preview_thumbnail = form.Controls ["preview_thumbnail"] as PictureBox;
OpenFileDialog select_image = new OpenFileDialog ();
select_image.Title = "Select pack thumbnail";
select_image.InitialDirectory = System.Environment.GetEnvironmentVariable ("AppData") + @"\.minecraft";
if (select_image.ShowDialog () == DialogResult.OK) {
preview_thumbnail.ImageLocation = select_image.FileName;
}
}
public static void load_image_Click(object sender, EventArgs eventArgs)
{
MenuItem load_image = sender as MenuItem;
var context = load_image.Parent as ContextMenu;
PictureBox preview_thumbnail = context.SourceControl as PictureBox;
OpenFileDialog select_image = new OpenFileDialog ();
select_image.Title = "Select pack thumbnail";
select_image.InitialDirectory = System.Environment.GetEnvironmentVariable ("AppData") + @"\.minecraft";
if (select_image.ShowDialog () == DialogResult.OK) {
preview_thumbnail.ImageLocation = select_image.FileName;
Form form = preview_thumbnail.FindForm () as Form;
TextBox preview_source = form.Controls ["preview_source"] as TextBox;
preview_source.Text = select_image.FileName;
}
}
public static void clear_image_Click(object sender, EventArgs eventArgs)
{
MenuItem clear_image = sender as MenuItem;
var context = clear_image.Parent as ContextMenu;
PictureBox preview_thumbnail = context.SourceControl as PictureBox;
preview_thumbnail.Image = null;
Form form = preview_thumbnail.FindForm () as Form;
TextBox preview_source = form.Controls ["preview_source"] as TextBox;
preview_source.Text = "";
}
public static void startbutton_Click(object sender, EventArgs eventArgs)
{
// ---- Get all necessary GUI items ---- //
Button button = sender as Button;
Form form = button.FindForm () as Form;
TextBox outputfield = form.Controls ["outputfield"] as TextBox;
TextBox namefield = form.Controls ["namefield"] as TextBox;
TextBox descriptionfield = form.Controls ["descriptionfield"] as TextBox;
ComboBox packformat = form.Controls ["packformat"]as ComboBox;
ComboBox versionbox = form.Controls ["versionbox"] as ComboBox;
TextBox subfolder = form.Controls ["subfolder"] as TextBox;
TextBox preview_source = form.Controls ["preview_source"] as TextBox;
// ---- pack_format, name, description, version ---- //
var name = namefield.Text;
var description = descriptionfield.Text;
if (description == "Description") {
description = "";
}
var jarversion = "";
try {
jarversion = versionbox.SelectedItem.ToString();
jarversion = jarversion + @"\" + jarversion;
} catch (NullReferenceException) {
jarversion = @"1.8\1.8";
}
//determine pack format depending on selected version
var version_regex = new Regex (@"1\.(\d{1,2})");
var version_match = version_regex.Match (jarversion);
var version_format = version_match.Groups [1].Value;
var version_format_number = Int32.Parse (version_format);
var pack_format = "3";
var version = "1.11.x +";
if (version_format_number < 9) {
pack_format = "1";
version = "1.6.x - 1.8.x";
} else if (version_format_number >= 9 && version_format_number <= 10 ) {
pack_format = "2";
version = "1.9.x - 1.10.x";
}
// ---- Remove invalid chars from name ---- //
string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
foreach (char c in invalid)
{
name = name.Replace(c.ToString(), "");
}
// ---- summary ---- //
output (Environment.NewLine + Environment.NewLine + "-- Summary --" + Environment.NewLine + "Name: " + name + Environment.NewLine + "Description: " + Environment.NewLine + description + Environment.NewLine + "Version: " + version, outputfield);
// ---- Create pack ---- //
new MCRPC (name, description, pack_format, outputfield, jarversion, subfolder.Text, preview_source.Text);
}
// ---- Output function, nothing more than a substitute for Control.Text += text ---- //
public static void output(string text, TextBox output)
{
output.Text += text;
}
}
}