-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfrmMain.vb
420 lines (344 loc) · 17 KB
/
frmMain.vb
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
Public Class frmMain
Public Sub LoadSettings()
Dim VMNames() As String = Split(My.Settings.VMNames, ",")
Dim VMRoutes() As String = Split(My.Settings.VMRoutes, ",")
Dim VMIcons() As String = Split(My.Settings.VMIcons, ",")
Dim VMTypes() As String = Split(My.Settings.VMType, ",")
If Microsoft.VisualBasic.Command = "/debug" Then
Me.mnuFileDebug.Visible = True
Else
Me.mnuFileDebug.Visible = False
End If
If VMNames.Length > 1 Then
For x As Integer = 0 To VMNames.Length - 2
If VMIcons(x) = -1 Or VMIcons(x) = "" Then
VMIcons(x) = 0
End If
With VMList.Items.Add(VMNames(x))
.StateImageIndex = 0
.SubItems.Add(VMRoutes(x))
.SubItems.Add(VMTypes(x))
End With
Next
End If
End Sub
Public Sub SaveSettings()
Dim VMNames As String = ""
Dim VMIcons As String = ""
Dim VMRoutes As String = ""
Dim VMTypes As String = ""
Dim CustomIcons As String = ""
For x As Integer = 0 To VMList.Items.Count - 1
If VMList.Items(x).StateImageIndex = -1 Then
VMList.Items(x).StateImageIndex = 0
End If
Next
For x As Integer = 0 To VMList.Items.Count - 1
VMNames = VMNames & VMList.Items(x).Text & ","
VMIcons = VMIcons & VMList.Items(x).StateImageIndex & ","
VMRoutes = VMRoutes & VMList.Items(x).SubItems(1).Text & ","
VMTypes = VMTypes & VMList.Items(x).SubItems(2).Text & ","
Next
My.Settings.VMNames = VMNames
My.Settings.VMIcons = VMIcons
My.Settings.VMRoutes = VMRoutes
My.Settings.VMType = VMTypes
My.Settings.Save()
End Sub
Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Me.Visible = False
End Sub
Private Sub frmMain_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
GetSysInfo()
VirtualMacTray.Visible = True
LoadSettings()
End Sub
Private Sub frmMain_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
SaveSettings()
If Me.WindowState <> System.Windows.Forms.FormWindowState.Minimized Then
SaveSetting(My.Application.Info.Title, "Settings", "MainLeft", CStr(VB6.PixelsToTwipsX(Me.Left)))
SaveSetting(My.Application.Info.Title, "Settings", "MainTop", CStr(VB6.PixelsToTwipsY(Me.Top)))
SaveSetting(My.Application.Info.Title, "Settings", "MainWidth", CStr(VB6.PixelsToTwipsX(Me.Width)))
SaveSetting(My.Application.Info.Title, "Settings", "MainHeight", CStr(VB6.PixelsToTwipsY(Me.Height)))
End If
End Sub
Public Sub StartEmulation(ByVal ConfigPath As String)
Dim Reader As New System.IO.StreamReader(ConfigPath, True)
Dim Line As String
Dim Lines As New ArrayList
Do
Line = Reader.ReadLine()
If Not Line Is Nothing Then
Lines.Add(Line)
End If
Loop Until Line Is Nothing
Reader.Close()
If My.Settings.TestWindow = True Then
frmVirtualMacintosh.Show()
Exit Sub
End If
Select Case VMList.FocusedItem.SubItems(2).Text
Case "vMac"
If My.Computer.FileSystem.FileExists(My.Settings.vMacPath) = True Then
frmVirtualMacintosh.Text = VMList.Items(VMList.FocusedItem.Index).Text & " - Virtual Mac"
Shell(My.Settings.vMacPath & " " & Chr(34) & Lines(0) & Chr(34), AppWinStyle.NormalFocus)
End If
Case "BII"
If My.Computer.FileSystem.FileExists(My.Settings.BasiliskPath) = True Then
Shell(My.Settings.BasiliskPath & " " & Chr(34) & VMList.FocusedItem.SubItems(1).Text & Chr(34), AppWinStyle.NormalFocus)
End If
Case "SheepShaver"
If My.Computer.FileSystem.FileExists(My.Settings.SheepShaverPath) = True Then
Shell(My.Settings.SheepShaverPath & " " & Chr(34) & VMList.FocusedItem.SubItems(1).Text & Chr(34), AppWinStyle.NormalFocus)
End If
Case "PearPC"
If My.Computer.FileSystem.FileExists(My.Settings.PearPCPath) = True Then
MsgBox("cmd.exe /k " & My.Settings.PearPCPath & " " & Chr(34) & VMList.FocusedItem.SubItems(1).Text & Chr(34))
Shell("cmd.exe /k " & My.Settings.PearPCPath & " " & Chr(34) & VMList.FocusedItem.SubItems(1).Text & Chr(34), AppWinStyle.NormalFocus)
End If
Case "QEMU"
If My.Computer.FileSystem.FileExists(My.Settings.QEMUPath) = True Then
Shell(My.Settings.QEMUPath & " " & Lines(0), AppWinStyle.NormalFocus)
End If
End Select
End Sub
Public Sub EnableButtons()
mnuActionStart.Enabled = True
'mnuActionPause.Enabled = True
'mnuActionRestart.Enabled = True
mnuActionRemove.Enabled = True
mnuActionSettings.Enabled = True
'mnuActionProperties.Enabled = True
ButtonSettings.Enabled = True
ButtonRemove.Enabled = True
ButtonStart.Enabled = True
End Sub
Public Sub RemoveSelectedMac()
'Declarations
Dim Selection As Boolean
Dim Answer As Short
'Checks that you have a machine selected
If VMList.FocusedItem.Index <> -1 Then
Selection = True
End If
'Asks you if you really want to delete the machine
If Selection = True Then
Answer = MsgBox("Are you sure you want to remove ''" & VMList.Items(VMList.FocusedItem.Index).Text & "'' Mac from the Virtual Mac Console?", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "Virtual Mac")
'If you don't want that old Mac Plus, this
'is where it's deleted and recycled (Maybe)
If Answer = 6 Then
'Let's ask if user wants to keep files
If MsgBox("Do you want to delete the associated files? This will delete ALL the files in the folder ''" & VMList.FocusedItem.Text & "''", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "Delete files") = MsgBoxResult.Yes Then
'If user needs disk space...
My.Computer.FileSystem.DeleteDirectory(System.IO.Path.GetDirectoryName(VMList.FocusedItem.SubItems(1).Text), FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin, FileIO.UICancelOption.DoNothing)
VMList.Items.RemoveAt(VMList.FocusedItem.Index)
DisableButtons() 'Disable the buttons
Else
'If user just gets annoyed with the item but wants the files...
VMList.Items.RemoveAt(VMList.FocusedItem.Index)
DisableButtons() 'Disable the buttons
End If
End If
End If
End Sub
Private Sub NewMac_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ButtonNewM.Click
frmNewMac.Show()
End Sub
Private Sub Remove_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ButtonRemove.Click
RemoveSelectedMac()
End Sub
Private Sub Settings_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ButtonSettings.Click
OpenSettings()
End Sub
Private Sub Start_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ButtonStart.Click
StartEmulation(VMList.FocusedItem.SubItems(1).Text)
End Sub
Public Sub DisableButtons()
mnuActionStart.Enabled = False
mnuActionPause.Enabled = False
mnuActionRestart.Enabled = False
mnuActionRemove.Enabled = False
mnuActionSettings.Enabled = False
mnuActionProperties.Enabled = False
ButtonSettings.Enabled = False
ButtonRemove.Enabled = False
ButtonStart.Enabled = False
End Sub
Public Sub UnloadAll()
If frmVirtualMacintosh.Visible = True Then
frmVirtualMacintosh.Close()
End If
If frmOptions.Visible = True Then
frmOptions.Close()
End If
If frmSettingsSheepVM.Visible = True Then
frmSettingsSheepVM.Close()
End If
If frmNewMac.Visible = True Then
frmNewMac.Close()
End If
'If frmNewDisk.Visible = True Then
'frmNewDisk.Close()
'End If
Me.Close()
End
End Sub
Private Sub IconNewMac_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrayNewMac.Click
frmNewMac.Show()
frmNewMac.Focus()
End Sub
Private Sub IconNewDisk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrayNewDisk.Click
'frmNewDisk.Show()
End Sub
Private Sub IconOptions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrayOptions.Click
frmOptions.Show()
End Sub
Private Sub IconExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrayExit.Click
frmVirtualMacintosh.Close()
frmNewMac.Close()
'frmNewDisk.Close()
frmSplash.Close()
frmSettingsSheepVM.Close()
frmOptions.Close()
frmAbout.Close()
Me.Close()
End Sub
Private Sub TrayShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrayShow.Click
Me.Visible = True
Me.ShowInTaskbar = True
Me.WindowState = FormWindowState.Normal
Me.Show()
Me.BringToFront()
End Sub
Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
Me.ShowInTaskbar = False
Me.Visible = False
End If
Me.Width = 371
End Sub
Private Sub VirtualMacTray_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles VirtualMacTray.MouseDoubleClick
Me.Visible = True
Me.ShowInTaskbar = True
Me.WindowState = FormWindowState.Normal
Me.Show()
Me.BringToFront()
End Sub
Private Sub VMList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles VMList.Click
EnableButtons()
End Sub
Private Sub ChangeIcon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNewIcon.Click
Dim User As Integer = MacIcons.Images.Count
Dim Picture As System.Drawing.Image
Browser.Filter = "Picture files(*.jpg;*.png;*.bmp;*.ico)|*.jpg;*.png;*.bmp;*.ico|All files (*.*)|*.*"
Browser.ShowDialog()
If Not Browser.FileName = "" Then
Picture = Image.FromFile(Browser.FileName)
MacIcons.Images.Add(User, Picture)
VMList.FocusedItem.StateImageIndex = User
End If
End Sub
Private Sub mnuFileOptions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileOptions.Click
frmOptions.Show()
End Sub
Private Sub mnuHelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpAbout.Click
frmAbout.Show()
End Sub
Private Sub mnuFileDebug_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileDebug.Click
frmDebug.Show()
End Sub
Private Sub mnuFileNewMac_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileNewMac.Click
frmNewMac.Show()
End Sub
Private Sub mnuFileNewDisk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileNewDisk.Click
frmNewDisk.Show()
End Sub
Private Sub VMList_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles VMList.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
Dim x As String = CType(e.Data.GetData(DataFormats.FileDrop, True), String())(0)
ConfigFileHandler.CreateFromFile(DetectEmulator, x, InputBox("Write the name for the new Mac", "Creating new Mac from a file"))
Cursor = Cursors.Default
End If
End Sub
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpCrash.Click
'This instruction is WRONG purposedly, it's for crashing the program. This will be used for handling crashes
Dim x() As String = Split("crashing,instruction", ",")
MsgBox(x(3))
End Sub
Private Sub VMList_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles VMList.DragEnter
e.Effect = e.AllowedEffect And DragDropEffects.Copy
End Sub
Public Function DetectEmulator() As String
Dim Emulator As String = "Unknown"
Dim EmulatorDialog As New Form
Dim OKButton As New Button
Dim CancelButton As New Button
Dim EmulatorTypes As New ComboBox
EmulatorTypes.Items.Add("Basilisk II preferences file")
EmulatorTypes.Items.Add("SheepShaver preferences file")
EmulatorTypes.Items.Add("PearPC config file")
EmulatorTypes.Items.Add("QEMU Batch")
EmulatorTypes.SelectedIndex = 0
EmulatorTypes.DropDownStyle = ComboBoxStyle.DropDownList
EmulatorDialog.Width = 400
EmulatorDialog.Height = 160
EmulatorDialog.FormBorderStyle = Forms.FormBorderStyle.FixedDialog
EmulatorDialog.Controls.Add(OKButton)
EmulatorDialog.Controls.Add(CancelButton)
EmulatorDialog.Controls.Add(EmulatorTypes)
EmulatorTypes.Left = (EmulatorDialog.Width / 2) - (EmulatorTypes.Width / 2)
EmulatorTypes.Top = 40
OKButton.Top = EmulatorDialog.Height - OKButton.Height - 30
OKButton.Left = EmulatorDialog.Width - OKButton.Width - CancelButton.Width - 20
CancelButton.Top = EmulatorDialog.Height - CancelButton.Height - 30
CancelButton.Left = EmulatorDialog.Width - CancelButton.Width - 20
EmulatorDialog.ShowDialog()
Select Case EmulatorTypes.SelectedIndex
Case 0
Emulator = "vMac"
Case 1
Emulator = "BII"
Case 2
Emulator = "ShhepShaver"
Case 3
Emulator = "PearPC"
Case 4
Emulator = "QEMU"
End Select
Return Emulator
End Function
Public Sub OpenSettings()
Select Case VMList.FocusedItem.SubItems(2).Text
Case "vMac"
' frmSettingsPearPCVM.Text = Replace(frmSettingsPearPCVM.Text, "%s", VMList.FocusedItem.Text)
' frmSettingsPearPCVM.LoadSettingsFrom(VMList.FocusedItem.SubItems(1).Text)
' frmSettingsPearPCVM.Show()
Case "BII"
frmSettingsBasiliskVM.Text = Replace(frmSettingsBasiliskVM.Text, "%s", VMList.FocusedItem.Text)
frmSettingsBasiliskVM.LoadSettingsFrom(VMList.FocusedItem.Index)
frmSettingsBasiliskVM.Show()
Case "SheepShaver"
frmSettingsSheepVM.Text = Replace(frmSettingsSheepVM.Text, "%s", VMList.FocusedItem.Text)
frmSettingsSheepVM.LoadSettingsFrom(VMList.FocusedItem.Index)
frmSettingsSheepVM.Show()
Case "QEMU"
frmSettingsQemuVM.Text = Replace(frmSettingsSheepVM.Text, "%s", VMList.FocusedItem.Text)
'frmSettingsQemuVM.LoadSettingsFrom(VMList.FocusedItem.Index)
frmSettingsQemuVM.Show()
Case "PearPC"
frmSettingsPearPCVM.Text = Replace(frmSettingsSheepVM.Text, "%s", VMList.FocusedItem.Text)
frmSettingsPearPCVM.LoadSettingsFrom(VMList.FocusedItem.Index)
frmSettingsPearPCVM.Show()
End Select
End Sub
Private Sub mnuActionSettings_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuActionSettings.Click
OpenSettings()
End Sub
Private Sub mnuHelpContents_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpContents.Click
frmHelp.Show()
End Sub
Private Sub mnuHelpOnline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpOnline.Click
Process.Start("https://edsonarmando.000webhostapp.com/personal/virtualmac/")
End Sub
End Class