-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.vb
More file actions
253 lines (226 loc) · 10.5 KB
/
Copy pathInterface.vb
File metadata and controls
253 lines (226 loc) · 10.5 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
'This class's imports and settings.
Option Compare Binary
Option Explicit On
Option Infer Off
Option Strict On
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Environment
Imports System.IO
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
'This class contains this program's interface.
Public Class InterfaceWindow
Private ReadOnly SUPPORTED_IMAGES As New List(Of String)({".bmp", ".emf", ".gif", ".ico", ".jpg", ".jpeg", ".png", ".tif", ".tiff", ".wmf"}) 'Defines the extensions of the supported image file types.
'This procedure initializes this window.
Public Sub New()
Try
InitializeComponent()
My.Application.ChangeCulture("en-US")
With My.Computer.Screen.WorkingArea
Me.Size = New Size(CInt(.Width / 1.1), CInt(.Height / 1.1))
End With
Me.Text = ProgramInformation()
ToolTip.SetToolTip(DataBox, "Drag a file into this window to view it.")
UpdateDataBox(, NewDataBox:=DataBox)
Catch ExceptionO As Exception
DisplayException(ExceptionO)
End Try
End Sub
'This procedure closes this window.
Private Sub CloseMenu_Click(sender As Object, e As EventArgs) Handles CloseMenu.Click
Try
Me.Close()
Catch ExceptionO As Exception
DisplayException(ExceptionO)
End Try
End Sub
'This procedure gives the command to load the file dropped into the data box.
Private Sub DataBox_DragDrop(sender As Object, e As DragEventArgs) Handles DataBox.DragDrop
Try
If e.Data.GetDataPresent(DataFormats.FileDrop) Then DataFile(DirectCast(e.Data.GetData(DataFormats.FileDrop), String()).First)
Catch ExceptionO As Exception
DisplayException(ExceptionO)
End Try
End Sub
'This procedure handles objects being dragged into the data box.
Private Sub DataBox_DragEnter(sender As Object, e As DragEventArgs) Handles DataBox.DragEnter
Try
If e.Data.GetDataPresent(DataFormats.FileDrop) Then e.Effect = DragDropEffects.All
Catch ExceptionO As Exception
DisplayException(ExceptionO)
End Try
End Sub
'This procedure displays the export file dialog.
Private Sub ExportFilesMenu_Click(sender As Object, e As EventArgs) Handles ExportFilesMenu.Click
Try
If DataFile() Is Nothing Then
MessageBox.Show("No open file to export.", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Try
Static PathO As String = Nothing
With New FolderBrowserDialog With {.SelectedPath = PathO}
If TypeOf DataFile() Is ActorClass Then
If .ShowDialog = DialogResult.OK Then
PathO = .SelectedPath
DirectCast(DataFile(), ActorClass).Export(PathO)
End If
ElseIf TypeOf DataFile() Is ArchiveClass Then
If .ShowDialog = DialogResult.OK Then
PathO = .SelectedPath
DirectCast(DataFile(), ArchiveClass).Export(PathO)
End If
ElseIf TypeOf DataFile() Is CartoonersClass Then
If .ShowDialog = DialogResult.OK Then
PathO = .SelectedPath
DirectCast(DataFile(), CartoonersClass).Export(PathO)
End If
ElseIf TypeOf DataFile() Is LBMImageClass Then
If .ShowDialog = DialogResult.OK Then
PathO = .SelectedPath
DirectCast(DataFile(), LBMImageClass).Export(PathO)
End If
ElseIf TypeOf DataFile() Is MusicClass Then
If .ShowDialog = DialogResult.OK Then
PathO = .SelectedPath
DirectCast(DataFile(), MusicClass).Export(PathO)
End If
ElseIf TypeOf DataFile() Is ScriptClass Then
If .ShowDialog = DialogResult.OK Then
PathO = .SelectedPath
DirectCast(DataFile(), ScriptClass).Export(PathO)
End If
Else
MessageBox.Show("The current file does not support exporting data.", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End With
Catch ExceptionO As Exception
DisplayException(ExceptionO)
End Try
End If
Catch ExceptionO As Exception
DisplayException(ExceptionO)
End Try
End Sub
'This procedure displays the file format information file.
Private Sub FileFormatsMenu_Click(sender As Object, e As EventArgs) Handles FileFormatsMenu.Click
Try
UpdateDataBox(My.Resources.Cartooners_File_Formats)
Catch ExceptionO As Exception
DisplayException(ExceptionO)
End Try
End Sub
'This procedure displays the help file.
Private Sub HelpMenu_Click(sender As Object, e As EventArgs) Handles HelpMenu.Click
Try
UpdateDataBox(My.Resources.Cartooners_File_Viewer_Help)
Catch ExceptionO As Exception
DisplayException(ExceptionO)
End Try
End Sub
'This procedure displays information about this program.
Private Sub InformationMenu_Click(sender As Object, e As EventArgs) Handles InformationMenu.Click
Try
With My.Application.Info
MessageBox.Show(.Description, ProgramInformation(), MessageBoxButtons.OK, MessageBoxIcon.Information)
End With
Catch ExceptionO As Exception
DisplayException(ExceptionO)
End Try
End Sub
'This procedure gives the command to display the help.
Private Sub InterfaceWindow_Load(sender As Object, e As EventArgs) Handles Me.Load
Try
HelpMenu.PerformClick()
If GetCommandLineArgs.Count > 1 Then DataFile(GetCommandLineArgs(1))
Catch ExceptionO As Exception
DisplayException(ExceptionO)
End Try
End Sub
'This procedure displays the load file dialog.
Private Sub LoadFileMenu_Click(sender As Object, e As EventArgs) Handles LoadFileMenu.Click
Try
Dim Filter As New StringBuilder
Static FilterIndex As Integer = 1
Filter.Append("Actor files (*.act)|*.act|")
Filter.Append("Archive files (*.pea)|*.pea|")
Filter.Append("Executable files (*.exe)|*.exe|")
Filter.Append("Image files (")
SUPPORTED_IMAGES.ForEach(Sub(Item As String) Filter.Append(If(Item = Nothing, "", $"*{Item};")))
Filter.Append(")|")
SUPPORTED_IMAGES.ForEach(Sub(Item As String) Filter.Append(If(Item = Nothing, "", $"*{Item};")))
Filter.Append("|")
Filter.Append("Installation script files (*.iea)|*.iea|")
Filter.Append("LBM files (*.bbm;*.iff;*.lbm)|*.bbm;.iff;*.lbm|")
Filter.Append("Movie files (*.mov)|*.mov|")
Filter.Append("Music files (*.mus)|*.mus|")
Filter.Append("Preference files (*.inf)|*.inf|")
Filter.Append("Printer driver files(*.lpt)|*.lpt|")
Filter.Append("Sound card driver files(*.smb)|*.smb|")
Filter.Append("Template files(*.txt)|*.txt")
With New OpenFileDialog With {.CheckFileExists = True, .FileName = Nothing, .Filter = Filter.ToString(), .FilterIndex = FilterIndex}
If Not .ShowDialog() = DialogResult.Cancel Then
DataFile(.FileName)
FilterIndex = .FilterIndex
End If
End With
Catch ExceptionO As Exception
DisplayException(ExceptionO)
End Try
End Sub
'This procedure returns the specified data file.
Private Function DataFile(Optional NewPath As String = Nothing) As DataFileClass
Try
Dim DataFileFromTemplate As DataFileClass = Nothing
Dim Extension As String = Nothing
Static CurrentDataFile As DataFileClass = Nothing
Static CurrentPath As String = Nothing
If Not NewPath = Nothing Then
NewPath = NewPath.Trim(""""c)
Extension = Path.GetExtension(NewPath)
Select Case Extension.ToLower()
Case ".act"
CurrentDataFile = New ActorClass(NewPath, DataFileMenu)
Case ".exe"
CurrentDataFile = New CartoonersClass(NewPath, DataFileMenu)
Case ".iea"
CurrentDataFile = New ScriptClass(NewPath, DataFileMenu)
Case ".inf"
CurrentDataFile = New PreferencesClass(NewPath, DataFileMenu)
Case ".bbm", ".lbm"
CurrentDataFile = New LBMImageClass(NewPath, DataFileMenu)
Case ".lpt"
CurrentDataFile = New PrinterDriverClass(NewPath, DataFileMenu)
Case ".mov"
CurrentDataFile = New MovieClass(NewPath, DataFileMenu)
Case ".mus"
CurrentDataFile = New MusicClass(NewPath, DataFileMenu)
Case ".pea"
CurrentDataFile = New ArchiveClass(NewPath, DataFileMenu)
Case ".smb"
CurrentDataFile = New SoundCardDriverClass(NewPath, DataFileMenu)
Case ".txt"
DataFileFromTemplate = GetDataFileFromTemplate(NewPath, DataFileMenu)
If DataFileFromTemplate IsNot Nothing Then CurrentDataFile = DataFileFromTemplate
Case Else
If SUPPORTED_IMAGES.IndexOf(Extension.ToLower()) >= 0 Then
CurrentDataFile = New LBMImageClass(NewPath, DataFileMenu)
Else
If Not NewPath.Trim() = Nothing Then
MessageBox.Show($"Unsupported file type for: ""{NewPath}""", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
NewPath = Nothing
End If
End If
End Select
If NewPath IsNot Nothing Then CurrentPath = NewPath
Me.Text = $"{ProgramInformation()} - ""{If(CurrentDataFile Is Nothing, Nothing, CurrentPath)}"""
End If
Return CurrentDataFile
Catch ExceptionO As Exception
DisplayException(ExceptionO)
End Try
Return Nothing
End Function
End Class