-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.vb
More file actions
388 lines (323 loc) · 11.6 KB
/
MainForm.vb
File metadata and controls
388 lines (323 loc) · 11.6 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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
Imports System.Runtime.InteropServices
Imports System.Drawing.Graphics
Imports System.Drawing.Imaging
Imports System.IO
Imports System.IO.Compression
Imports System.Text
Imports ICSharpCode.SharpZipLib.Zip
Public Partial Class MainForm
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function GetClientRect(ByVal hWnd As System.IntPtr, ByRef lpRECT As Rectangle) As Integer
End Function
Private Declare Auto Function IsIconic Lib "user32.dll" (ByVal hwnd As IntPtr) As Boolean
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function IsWindowVisible(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Integer) As Integer
Public Shared logo As Bitmap
Public Shared gamescreen As Bitmap
Public Sub New()
Me.InitializeComponent()
Me.AllowDrop = True
PictureBox1.AllowDrop = True
PictureBox2.AllowDrop = True
End Sub
Sub Button1Click(sender As Object, e As EventArgs)
Dim players As Process() = Process.GetProcessesByName("flashplayer")
If(players.Length = 0) Then
MessageBox.Show("No Flash Players detected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim player = players(0).MainWindowHandle
Dim pic As New Rectangle
GetClientRect(player, pic)
Dim screenshot As New ScreenShot.ScreenCapture
Dim image As Bitmap = screenshot.CaptureWindow(player)
Dim border As Integer = (image.Width - pic.Width) / 2
Dim top As Integer = image.Height - pic.Height - border
Dim crop As Rectangle = New Rectangle(border, top, pic.Width, pic.Height)
If(IsIconic(player) Or crop.IsEmpty Or crop.Width = 0 Or crop.Height = 0) Then
MessageBox.Show("Please make sure the Flash Player is not minimized", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
SetForegroundWindow(player)
SendKeys.SendWait("~")
Else
logo = image.Clone(crop, image.PixelFormat)
PictureBox1.Image = logo
End If
End Sub
Sub Button2Click(sender As Object, e As EventArgs)
' Dim players As Process() = Process.GetProcessesByName("flashplayer_31_sa")
Dim players As Process() = Process.GetProcessesByName("flashplayer")
If(players.Length = 0) Then
MessageBox.Show("No Flash Players detected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim player = players(0).MainWindowHandle
Dim pic As New Rectangle
GetClientRect(player, pic)
Dim screenshot As New ScreenShot.ScreenCapture
Dim image As Bitmap = screenshot.CaptureWindow(player)
Dim border As Integer = (image.Width - pic.Width) / 2
Dim top As Integer = image.Height - pic.Height - border
Dim crop As Rectangle = New Rectangle(border, top, pic.Width, pic.Height)
If(IsIconic(player) Or crop.IsEmpty Or crop.Width = 0 Or crop.Height = 0) Then
MessageBox.Show("Please make sure the Flash Player is not minimized", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
SetForegroundWindow(player)
SendKeys.SendWait("~")
Else
gamescreen = image.Clone(crop, image.PixelFormat)
PictureBox2.Image = gamescreen
End If
End Sub
Sub Button3Click(sender As Object, e As EventArgs)
Dim crop As Crop = New Crop
If(logo Is Nothing) Then
MessageBox.Show("No image to crop", "Crop", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
crop.Show()
End If
End Sub
Public Function CheckMeta() As Boolean
Dim title = TextBox1.Text.Trim()
Dim status = ComboBox2.Text.Trim()
Dim genre = ComboBox1.Text.Trim()
Dim playmode = ComboBox3.Text.Trim()
Dim source = TextBox7.Text.Trim()
Dim launchcommand = TextBox4.Text.Trim()
If(logo Is Nothing) Then
MessageBox.Show("Logo is required", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
End If
If(gamescreen Is Nothing) Then
MessageBox.Show("Screenshot is required", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
End If
If(title.Length = 0) Then
MessageBox.Show("Title cannot be blank", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
End If
If(launchcommand.Length = 0) Then
MessageBox.Show("Command cannot be blank", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
End If
If(launchcommand.StartsWith("https://")) Then
MessageBox.Show("Do not use HTTPS for the launch command", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
End If
If(source.Length = 0) Then
MessageBox.Show("Source cannot be blank", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
End If
If(genre.Length = 0 Or genre = "Genre") Then
MessageBox.Show("Please specify a genre", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
End If
If(playmode.Length = 0 Or playmode = "Playmode") Then
MessageBox.Show("Please specify a playmode", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
End If
If(status.Length = 0 Or status = "Status") Then
MessageBox.Show("Please specify a status", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
End If
Return True
End Function
Public Function CreateMeta() As String
Dim title = TextBox1.Text.Trim()
Dim series = TextBox2.Text.Trim()
Dim developer = TextBox5.Text.Trim()
Dim publisher = TextBox6.Text.Trim()
Dim status = ComboBox2.Text.Trim()
Dim extreme = "No"
Dim genre = ComboBox1.Text.Trim()
Dim playmode = ComboBox3.Text.Trim()
Dim source = TextBox7.Text.Trim()
Dim launchcommand = TextBox4.Text.Trim()
Dim notes = TextBox3.Text.Trim().Replace(vbCrLf, "
")
Dim authornotes = TextBox8.Text.Trim().Replace(vbCrLf, "
")
If(CheckBox1.Checked) Then
extreme = "Yes"
End If
Dim meta = _
"Title: " + title + vbCrLf + _
"Series: " + series + vbCrLf + _
"Developer: " + developer + vbCrLf + _
"Publisher: " + publisher + vbCrLf + _
"Status: " + status + vbCrLf + _
"Extreme: " + extreme + vbCrLf + _
"Genre: " + genre + vbCrLf + _
"Source: " + source + vbCrLf + _
"Launch Command: " + launchcommand + vbCrLf + _
"Notes: " + notes + vbCrLf + _
"Author Notes: " + authornotes
'MessageBox.Show(meta)
Return meta
End Function
Sub Button4Click(sender As Object, e As EventArgs)
If(CheckMeta()) Then
Dim title = TextBox1.Text.Trim()
'Create curation files
Dim logostream = New MemoryStream()
logo.Save(logostream, ImageFormat.Png)
Dim screenshotstream = New MemoryStream()
gamescreen.Save(screenshotstream, ImageFormat.Png)
Dim meta = Encoding.UTF8.GetBytes(CreateMeta())
'Get folder where all of the game contents are
Dim folder As New FolderBrowserDialog
folder.Description = "Please choose the content folder"
folder.ShowNewFolderButton = False
If(folder.ShowDialog() = DialogResult.Cancel) Then
Exit Sub
End If
If(Directory.Exists(folder.SelectedPath) = False) Then
MessageBox.Show("Could not find directory", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim content = Directory.GetParent(folder.SelectedPath).ToString()
'Grab a list of all files to be added. Warn if there are too many
Dim files As New List(Of String)
CompressFolder(folder.SelectedPath, content, files)
If(files.Count >= 100) Then
Dim action = MessageBox.Show("There are more than 100 files in the selected folder (" + files.Count.ToString() + " files). Is this a multi-asset game?" + vbCrLf + vbCrLf + "Click Yes to proceed", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
If(action = DialogResult.No) Then
Exit Sub
End If
End If
'Get zip file name
Dim SaveAs As New SaveFileDialog
SaveAs.DefaultExt = ".zip"
SaveAs.OverwritePrompt = True
SaveAs.Title = "Save curated ZIP file"
SaveAs.Filter = "ZIP file|*.zip"
SaveAs.FileName = TextBox1.Text
SaveAs.ShowDialog()
'Create zip file
Dim output As New MemoryStream
Dim zipstream As New ZipOutputStream(output)
zipstream.SetLevel(9)
AddFile(title + "\logo.png", logostream.ToArray(), zipstream)
AddFile(title + "\ss.png", screenshotstream.ToArray(), zipstream)
AddFile(title + "\meta.txt", meta, zipstream)
For Each newfile In files
Dim addtozip = File.ReadAllBytes(content + "\" + newfile)
AddFile(title + "\content\" + newfile, addtozip, zipstream)
Next
zipstream.Close()
File.WriteAllBytes(SaveAs.FileName, output.ToArray())
End If
End Sub
Sub MainFormLoad(sender As Object, e As EventArgs)
Dim genres As String() = _
{"""Quiz""", _
"Action", _
"Adult", _
"Adventure", _
"Animation", _
"Arcade", _
"Artillery", _
"Brawler", _
"Card", _
"Choose Your Own Adventure", _
"Dating Sim", _
"Dress Up", _
"Driving", _
"Escape the Room", _
"Fighting", _
"Find", _
"Gambling", _
"Horror", _
"Motocross", _
"Pinball", _
"Platformer", _
"Pong", _
"Puzzle", _
"Quiz", _
"Racing", _
"Rhythm", _
"Rock Paper Scissors", _
"RPG", _
"Runner", _
"Seizure-Inducing", _
"Shooter", _
"Simulation", _
"Sports", _
"Strategy", _
"Tower Defense", _
"Toy", _
"Tutorial", _
"Typing", _
"Variety", _
"Visual Novel", _
"Walkright", _
"WTF"}
ComboBox1.Items.AddRange(genres)
End Sub
Sub Button5Click(sender As Object, e As EventArgs)
If(MessageBox.Show("Are you sure you wish to reset all fields?", "Reset", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = DialogResult.Yes) Then
PictureBox1.Image = Nothing
PictureBox2.Image = Nothing
logo = Nothing
gamescreen = Nothing
TextBox1.Text = ""
TextBox2.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
ComboBox2.Text = "Status"
CheckBox1.Checked = False
ComboBox1.Text = "Genre"
ComboBox3.Text = "Playmode"
TextBox7.Text = ""
TextBox4.Text = ""
TextBox3.Text = ""
TextBox8.Text = ""
End If
End Sub
Sub Button6Click(sender As Object, e As EventArgs)
Clipboard.SetText(TextBox1.Text)
End Sub
Public Sub AddFile(filename As String, content As Byte(), zipfile As ZipOutputStream)
Dim newentry As New ZipEntry(filename)
newentry.DateTime = DateTime.Now
zipfile.PutNextEntry(newentry)
zipfile.Write(content, 0, content.Length)
zipfile.CloseEntry()
End Sub
Public Sub CompressFolder(path As String, ByRef root As String, ByRef output As List(Of String))
Dim files = Directory.GetFiles(path)
For Each filename In files
Dim fi = New FileInfo(filename)
Dim entryname = filename.Substring(0)
'entryname = ZipEntry.CleanName(entryname)
output.Add(entryname.Substring(root.Length + 1))
Next
Dim folders = Directory.GetDirectories(path)
For Each folder In folders
CompressFolder(folder, root, output)
Next
End Sub
Sub TextBox3KeyDown(sender As Object, e As KeyEventArgs)
If(e.Control And e.KeyCode = Keys.A) Then
TextBox3.SelectAll()
End If
End Sub
Sub PictureBox1DragEnter(sender As Object, e As DragEventArgs)
If(e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Sub PictureBox1DragDrop(sender As Object, e As DragEventArgs)
Dim files() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())
logo = Image.FromFile(files(0))
PictureBox1.Image = logo
End Sub
Sub PictureBox2DragEnter(sender As Object, e As DragEventArgs)
If(e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Sub PictureBox2DragDrop(sender As Object, e As DragEventArgs)
Dim files() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())
gamescreen = Image.FromFile(files(0))
PictureBox2.Image = gamescreen
End Sub
End Class