Menu

[r7]: / GCGB / FileIO.vb  Maximize  Restore  History

Download this file

305 lines (245 with data), 10.8 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
'
' Created by SharpDevelop.
' User: Administrator
' Date: 7/08/2006
' Time: 3:47 PM
'
' To change this template use Tools | Options | Coding | Edit Standard Headers.
'
Imports System
Imports System.Drawing
Imports System.IO
Imports System.Windows.Forms
Imports System.Collections
Namespace Great_Cow_Graphical_BASIC
Public Class FileIO
Inherits System.Windows.Forms.Form
Shared Public Sub LoadCommands
'Also reads Constant Lists
Dim TempData As String
Dim ItemName As String
Dim ItemValue As String
Dim ConstantLocation As Integer
Dim ReadType As Integer '0=Command, 1=Constant, 2=Category, 4 = config
Dim ParamNo, ParamCount As Integer
Dim CurrentDevice As HardwareDevice
Dim CurrentDeviceSetting As HardwareDeviceSetting
Dim CurrentFunction As GCBFunction
Dim CurrentConstGroup As ConstGroup
Dim CurrentCommand As GCBCommand
MainForm.CommandList = New ArrayList
MainForm.IconCategory = New ArrayList
Dim ReadFile As New StreamReader(MainForm.InstallDir + MainForm.FilenameCommands)
Do While ReadFile.Peek() <> -1
TempData = ReadFile.ReadLine().Trim
If TempData.IndexOf("'") <> -1 Then TempData = TempData.Substring(0, TempData.IndexOf("'"))
If TempData = "" Then GoTo LineRead
If TempData.ToUpper.Trim = "[CATEGORIES]" Then
ReadType = 2
ElseIf TempData.ToUpper.IndexOf("[COM_") <> -1 Then
ReadType = 0
ItemName = TempData.Substring(5)
ItemName = ItemName.Substring(0,ItemName.IndexOf("]"))
CurrentCommand = New GCBCommand
MainForm.CommandList.Add(CurrentCommand)
With CurrentCommand
.Name = ItemName
.HelpPage = ""
.MatchSyntax = ""
.MatchIcon = ""
.Params = 0
.OnlyIn = ""
End With
ElseIf TempData.ToUpper.IndexOf("[CGR_") <> -1 Then
ReadType = 1
'MainForm.ConstantCount += 1
ItemName = TempData.Substring(5)
ItemName = ItemName.Substring(0,ItemName.IndexOf("]"))
'MainForm.ConstantList(MainForm.ConstantCount, 0) = ItemName
'ConstantLocation = 0
CurrentConstGroup = New ConstGroup(ItemName)
MainForm.ConstantGroups.Add(CurrentConstGroup)
ElseIf TempData.ToUpper.IndexOf("[CONF_") <> -1 Then
ReadType = 4
ItemName = TempData.Substring(5)
ItemName = ItemName.Substring(0,ItemName.IndexOf("]"))
'MainForm.HardwareCount += 1
'MainForm.HardwareConf(MainForm.HardwareCount, 0, 0) = ItemName.Trim.ToUpper
CurrentDevice = New HardwareDevice
CurrentDevice.CodeName = ItemName
MainForm.HardwareConf.Add(CurrentDevice)
ElseIf TempData.ToUpper.IndexOf("[FN_") <> -1 Then
ReadType = 5
ItemName = TempData.Substring(4)
ItemName = ItemName.Substring(0, ItemName.IndexOf("]"))
'MainForm.SysFunctions += 1
'MainForm.SysFunction(MainForm.SysFunctions) = New GCBFunction(ItemName.Trim)
'MainForm.SysFunction(MainForm.SysFunctions).Params = 0
CurrentFunction = New GCBFunction(ItemName.Trim)
MainForm.GCBFunctions.Add(CurrentFunction)
ElseIf ReadType = 0 Then
If TempData.IndexOf("=") <> -1 Then
ItemName = TempData.Substring(0,TempData.IndexOf("=")).ToLower.Trim
ItemValue = TempData.Substring(TempData.IndexOf("=") + 1).Trim
'Name is set above
With CurrentCommand
If ItemName = "syntax" then .Syntax = ItemValue
If ItemName = "icon" then .Icon = ItemValue
If ItemName = "match" Then
.MatchSyntax = ItemValue.SubString(0, ItemValue.IndexOf(",")).Trim
.MatchIcon = ItemValue.SubString(ItemValue.IndexOf(",") + 1).Trim
End If
If ItemName = "onlyin" Then .OnlyIn = ItemValue
If ItemName = "category" Then .Category = ItemValue
If ItemName = "help" then .HelpPage = ItemValue
If ItemName = "constraint" Then
.Constraints.Add(New ParamConstraint(ItemValue))
End If
If ItemName = "tooltip" Then .Tooltip = ItemValue
If ItemName.Substring(0,1) = "p" Then
ParamNo = ItemName.Substring(1)
.Param(ParamNo) = New GCBCommandParam
With .Param(ParamNo)
.Name = ItemValue.Substring(0,ItemValue.IndexOf(",")).Trim
ItemValue = ItemValue.Substring(ItemValue.IndexOf(",") + 1).Trim
.ParamType = ItemValue.Substring(0,ItemValue.IndexOf(",")).Trim
ItemValue = ItemValue.Substring(ItemValue.IndexOf(",") + 1).Trim
.Description = ItemValue.Trim
End With
.Params += 1
'MessageBox.Show(ParamNo.ToString, "Message", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1)
End If
End With
End If
ElseIf ReadType = 1 Then
'Constant groups
'ConstantLocation += 1
'MainForm.ConstantList(MainForm.ConstantCount, ConstantLocation) = TempData
If TempData.Trim <> "" Then
CurrentConstGroup.Items.Add(TempData.Trim)
End If
ElseIf ReadType = 2 Then
MainForm.IconCategory.Add(TempData)
ElseIf ReadType = 4 Then
'Data is name of config set
If TempData.ToLower.StartsWith("name") And TempData.ToLower.IndexOf("=") <> -1 Then
CurrentDevice.Name = TempData.Substring(TempData.IndexOf("=") + 1).Trim
Goto LineRead
End If
'Data is part of the set
'MainForm.HConfCount(MainForm.HardwareCount) += 1
CurrentDeviceSetting = New HardwareDeviceSetting
CurrentDevice.Settings.Add(CurrentDeviceSetting)
'Condition
CurrentDeviceSetting.Condition = TempData.Substring(0, TempData.IndexOf(";")).Trim
TempData = TempData.Substring(TempData.IndexOf(";") + 1).Trim
'Name
CurrentDeviceSetting.Name = TempData.Substring(0, TempData.IndexOf(";")).Trim
TempData = TempData.Substring(TempData.IndexOf(";") + 1).Trim
'Constant
CurrentDeviceSetting.Constant = TempData.Substring(0, TempData.IndexOf(";")).Trim
TempData = TempData.Substring(TempData.IndexOf(";") + 1).Trim
'Type
CurrentDeviceSetting.ParamType = TempData
'Functions
ElseIf ReadType = 5 Then
If TempData.IndexOf("=") <> -1 Then
ItemName = TempData.Substring(0,TempData.IndexOf("=")).ToLower.Trim
ItemValue = TempData.Substring(TempData.IndexOf("=")+1).Trim
'Name is set above
With CurrentFunction
If ItemName = "returns" Then .ReturnType = ItemValue
If ItemName = "desc" then .Description = ItemValue
If ItemName = "help" then .HelpPage = ItemValue
If ItemName.Substring(0,1) = "p" Then
'ParamNo = ItemName.Substring(1)
Dim thisParam As New GCBCommandParam
.Params.Add(thisParam)
With thisParam
.Name = ItemValue.Substring(0,ItemValue.IndexOf(",")).Trim
ItemValue = ItemValue.Substring(ItemValue.IndexOf(",") + 1).Trim
.ParamType = ItemValue.Substring(0,ItemValue.IndexOf(",")).Trim
ItemValue = ItemValue.Substring(ItemValue.IndexOf(",") + 1).Trim
.Description = ItemValue.Trim
End With
'MessageBox.Show(ParamNo.ToString, "Message", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1)
End If
End With
End If
End If
LineRead:
Loop
ReadFile.Close()
'Find hardware settings that control others
Dim ParentSetting As String
Dim ConditionSetting As HardwareDeviceSetting
For Each CurrentDevice In MainForm.HardwareConf
For Each CurrentDeviceSetting In CurrentDevice.Settings
'Get item conditions
TempData = CurrentDeviceSetting.Condition
If TempData <> "all" And TempData.IndexOf(" ") <> -1 Then
'Find controlling item
ParentSetting = TempData.Substring(0, TempData.IndexOf(" ")).Trim
For Each ConditionSetting In CurrentDevice.Settings
If ParentSetting = ConditionSetting.Constant Then
ConditionSetting.ControlsOther = True
Exit For
End If
Next
End If
Next
Next
End Sub
Public Shared Sub LoadConverters
'Load list of external file type converters
Dim ConverterDir As New IO.DirectoryInfo(MainForm.InstallDir + Mainform.FilenameConverters)
Dim ConverterList As IO.FileInfo() = ConverterDir.GetFiles()
Dim ConverterFileName As IO.FileInfo
'Find .ini files in converters directory
MainForm.FileConverters.Clear
For Each ConverterFileName In ConverterList
If ConverterFileName.FullName.ToLower.EndsWith(".ini") Then
MainForm.FileConverters.Add(New FileConverter(MainForm.InstallDir + Mainform.FilenameConverters, ConverterFileName.FullName))
End If
Next
End Sub
Public Shared Sub LoadIcons
Dim TempData As String
Dim IconName As String
Dim DataName, DataValue As String
Dim CurrIcon As GCBIcon
MainForm.IconList = New ArrayList
Dim ReadFile As New StreamReader(MainForm.InstallDir + MainForm.FilenameIcons)
Do While ReadFile.Peek() <> -1
TempData = ReadFile.ReadLine.Trim
If TempData.IndexOf("'") <> -1 Then TempData = TempData.Substring(0, TempData.IndexOf("'"))
If TempData.StartsWith("[") Then
CurrIcon = New GCBIcon(TempData.Substring(1, TempData.Length - 2))
MainForm.IconList.Add(CurrIcon)
Else If TempData.IndexOf("=") <> -1 Then
DataName = TempData.Substring(0, TempData.IndexOf("=")).Trim.ToLower
DataValue = TempData.Substring(TempData.IndexOf("=") + 1).Trim
With CurrIcon
If DataName = "texture" Then
.Texture = Lowlevel.AddFullPath(DataValue, MainForm.InstallDir + MainForm.FilenameIconsDir)
Else If DataName = "lines" Then
Else If DataName = "joiner" Then
.HasJoiner = Preferences.PrefIsYes(DataValue)
Else If DataName.StartsWith("line") Then
.Lines += 1
.Line(.Lines) = DataValue
Else If DataName = "colour" Then
.TextColour = DataValue
Else If DataName = "size" Then
.XSize = DataValue.Substring(0, DataValue.IndexOf(","))
.YSize = DataValue.Substring(DataValue.IndexOf(",") + 1)
End If
End With
End If
Loop
ReadFile.Close
End Sub
Public Sub New()
End Sub
End Class
End Namespace
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.