-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.module
340 lines (283 loc) · 12.5 KB
/
Utils.module
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
' Gambas module file
' ### SYSTEMWIDE SUBROUTINES ###
PUBLIC SUB DrivePartInfo()
' Get available drives and partitions with fdisk:
DIM sTemp AS String
Global.DiskInfo.Clear
Global.PartInfo.Clear
IF Global.SimulationMode = FALSE THEN
EXEC ["fdisk", "-l"] TO sTemp
ELSE
' 4 debug:
' English:
sTemp = Chr$(10)
sTemp = sTemp & "Disk /dev/hda: 40,0 GB, 40060403712 bytes" & Chr$(10)
sTemp = sTemp & "255 heads, 63 sectors/track, 4870 cylinders" & Chr$(10)
sTemp = sTemp & "Units = cylinders of 16065 * 512 = 8225280 bytes" & Chr$(10)
sTemp = sTemp & Chr$(10)
sTemp = sTemp & " Device Boot Start End Blocks Id System" & Chr$(10)
sTemp = sTemp & "/dev/hda1 * 1 1044 8385898+ 7 HPFS/NTFS" & Chr$(10)
sTemp = sTemp & "/dev/hda2 1045 1110 530145 82 Linux swap" & Chr$(10)
sTemp = sTemp & "/dev/hda4 1111 4870 30202200 f W95 Ext'd (LBA)" & Chr$(10)
sTemp = sTemp & "/dev/hda5 1111 2415 10482381 83 Linux" & Chr$(10)
sTemp = sTemp & "/dev/hda6 2416 4219 14490598+ c W95 FAT32 (LBA)" & Chr$(10)
sTemp = sTemp & "/dev/hda7 4220 4870 5229126 83 Linux" & Chr$(10)
sTemp = sTemp & Chr$(10)
sTemp = sTemp & "Disk /dev/sda: 258.0 MB, 258473984 bytes" & Chr$(10)
sTemp = sTemp & "8 heads, 62 sectors/track, 1017 cylinders" & Chr$(10)
sTemp = sTemp & "Units = cylinders of 496 * 512 = 253952 bytes" & Chr$(10)
sTemp = sTemp & Chr$(10)
sTemp = sTemp & " Device Boot Start End Blocks Id System" & Chr$(10)
sTemp = sTemp & "/dev/sda1 1 1017 252185 b W95 FAT32" & Chr$(10)
' Spanish:
'sTemp = Chr$(10)
'sTemp = sTemp & "Disco /dev/hda: 40.0 GB, 40060403712 bytes" & Chr$(10)
'sTemp = sTemp & "255 cabezas, 63 sectores/pista, 4870 cilindros" & Chr$(10)
'sTemp = sTemp & "Unidades = cilindros de 16065 * 512 = 8225280 bytes" & Chr$(10)
'sTemp = sTemp & Chr$(10)
'sTemp = sTemp & "Disposit. Inicio Comienzo Fin Bloques Id Sistema" & Chr$(10)
'sTemp = sTemp & "/dev/hda1 * 1 1044 8385898+ 7 HPFS/NTFS" & Chr$(10)
'sTemp = sTemp & "/dev/hda2 1045 1110 530145 82 Linux swap" & Chr$(10)
'sTemp = sTemp & "/dev/hda4 1111 4870 30202200 f W95 Ext'd (LBA)" & Chr$(10)
'sTemp = sTemp & "/dev/hda5 1111 2415 10482381 83 Linux" & Chr$(10)
'sTemp = sTemp & "/dev/hda6 2416 4219 14490598+ c W95 FAT32 (LBA)" & Chr$(10)
'sTemp = sTemp & "/dev/hda7 4220 4870 5229126 83 Linux" & Chr$(10)
'sTemp = sTemp & Chr$(10)
'sTemp = sTemp & "Disco /dev/sda: 258 MB, 258473984 bytes" & Chr$(10)
'sTemp = sTemp & "8 cabezas, 62 sectores/pista, 1017 cilindros" & Chr$(10)
'sTemp = sTemp & "Unidades = cilindros de 496 * 512 = 253952 bytes" & Chr$(10)
'sTemp = sTemp & Chr$(10)
'sTemp = sTemp & "Disposit. Inicio Comienzo Fin Bloques Id Sistema" & Chr$(10)
'sTemp = sTemp & "/dev/sda1 1 1017 252185 b W95 FAT32" & Chr$(10)
ENDIF
' Parse what fdisk has to say:
ProcessDiskInfo(sTemp)
END
PUBLIC SUB ProcessDiskInfo(sTemp AS String)
' Parse what fdisk has to say, including other commands for useful hard-drive/partition information
DIM vDI AS NEW cDiskInfo
DIM vPI AS NEW cPartInfo
DIM arrTemp1 AS NEW String[]
DIM arrTemp2 AS NEW String[]
DIM arrTemp3 AS NEW String[]
DIM sTemp2 AS String
DIM iDisk AS Long
DIM iPart AS Long
DIM iDiskUsedBytes AS Long
DIM pos AS Long
DIM n AS Long, m AS Long
DIM pcounter AS Long
' 4 debug:
IF Global.DebugMode = TRUE THEN
message.Info("Working in Simulation Mode..." & gb.NewLine & sTemp)
ENDIF
' Parse fdisk
arrTemp1 = Split(sTemp, Chr$(10))
FOR n = 0 TO arrTemp1.Max
pos = InStr(arrTemp1[n], "/dev/")
IF pos = 1 ' Parse a partition.
vPI = NEW cPartInfo
arrTemp2 = Split(arrTemp1[n], Space$(1), "", TRUE)
vPI.Device = arrTemp2[0]
IF Trim(arrTemp2[1]) = "*" THEN
vPI.Bootable = TRUE
vPI.StartBlock = arrTemp2[2]
vPI.EndBlock = arrTemp2[3]
IF Right$(arrTemp2[4]) = "+" THEN
vPI.Bytes = CLng(Val(Left$(arrTemp2[4], Len(arrTemp2[4]) - 1))) * 1024
ELSE
vPI.Bytes = CLng(Val(arrTemp2[4])) * 1024
ENDIF
vPI.ID = arrTemp2[5]
ELSE
vPI.Bootable = FALSE
vPI.StartBlock = arrTemp2[1]
vPI.EndBlock = arrTemp2[2]
IF Right$(arrTemp2[3]) = "+" THEN
vPI.Bytes = CLng(Val(Left$(arrTemp2[3], Len(arrTemp2[3]) - 1))) * 1024
ELSE
vPI.Bytes = CLng(Val(arrTemp2[3])) * 1024
ENDIF
vPI.ID = arrTemp2[4]
ENDIF
'Get filesystem information from "disktype"
IF Functions.getPartType(vPI.ID) = "Extended" THEN
vPI.FileSystem = "Extended"
ELSE IF Functions.getPartType(vPI.ID) = "HPFS/NTFS" THEN
vPI.FileSystem = "NTFS"
ELSE
SHELL "disktype " & vPI.Device TO sTemp2
sTemp2 = Trim$(sTemp2)
arrTemp3 = Split(sTemp2, Chr$(10))
vPI.FileSystem = Trim$(Left$(arrTemp3[2], InStr(arrTemp3[2], Space$(1))))
ENDIF
'Get free space information for each partition based on the filesystem
IF vPI.FileSystem = "Blank" THEN
vPI.FreeBytes = vPI.Bytes
ELSE
vPI.FreeBytes = Functions.getFreePartSpace(vPI.Device, vPI.FileSystem)
ENDIF
Global.PartInfo.Push(vPI)
ELSE IF pos > 1 ' Parse a disk drive.
vDI = NEW cDiskInfo
arrTemp2 = Split(arrTemp1[n], ":,", "", TRUE)
vDI.Device = Trim$(Mid$(arrTemp2[0], InStr(arrTemp2[0], "/dev")))
IF Val(arrTemp2[2]) > 0 THEN
vDI.Bytes = Val(arrTemp2[2])
ELSE
vDI.Bytes = Val(arrTemp2[3])
ENDIF
Global.DiskInfo.Push(vDI)
ELSE ' Nothing.
END IF
NEXT
'Get unallocated space on the hard-drives (it would be cool to have this in the main FOR loop...
'but its only possible after knowing each partiton's size)
FOR iDisk = 0 TO Global.DiskInfo.Max
iDiskUsedBytes = 0 'Reset the used-bytes counter
FOR iPart = 0 TO Global.PartInfo.Max
IF InStr(Global.PartInfo[iPart].Device, Global.DiskInfo[iDisk].Device) THEN
IF Global.PartInfo[iPart].FileSystem <> "Extended" THEN 'Ignore extended partitions, only account for primary and logical ones
iDiskUsedBytes = iDiskUsedBytes + Global.PartInfo[iPart].Bytes
ENDIF
ENDIF
NEXT
Global.DiskInfo[iDisk].UnallocatedBytes = Global.DiskInfo[iDisk].Bytes - iDiskUsedBytes
'PRINT global.DiskInfo[iDisk].UnallocatedBytes 'for debug
NEXT
' 4 debug:
IF Global.DebugMode = TRUE THEN
FOR n = 0 TO Global.DiskInfo.Max
frmGo.TextLabel1.Text &= Global.DiskInfo[n].Device & ": " & Global.DiskInfo[n].Bytes & " bytes" & " <br>"
NEXT
frmGo.TextLabel1.Text &= "<br>"
FOR n = 0 TO Global.PartInfo.Max
frmGo.TextLabel1.Text &= Global.PartInfo[n].Device & " <br>"
frmGo.TextLabel1.Text &= "Bootable= " & Str(Global.PartInfo[n].Bootable) & " <br>"
frmGo.TextLabel1.Text &= "Start block= " & Global.PartInfo[n].StartBlock & " <br>"
frmGo.TextLabel1.Text &= "End block= " & Global.PartInfo[n].EndBlock & " <br>"
frmGo.TextLabel1.Text &= "Num. Blocks= " & Global.PartInfo[n].Blocks & " <br>"
frmGo.TextLabel1.Text &= "Part. ID= " & Global.PartInfo[n].ID & ", " & Functions.getPartType(Global.PartInfo[n].ID) & " <br>"
frmGo.TextLabel1.Text &= "<br>"
NEXT
ENDIF
END
PUBLIC SUB GetSysMemory()
'Find system memory by reading the first line of /proc/meminfo
DIM hMemInfo AS File
DIM sLine AS String
OPEN "/proc/meminfo" FOR READ AS #hMemInfo
LINE INPUT #hMemInfo, sLine
CLOSE hMemInfo
sLine = Trim$(Mid$(Left$(sLine, RInStr(sLine, " ")), InStr(sLine, " "))) 'Isolate the memory size string (which is in KB)
Global.SysMemory = Val(sLine) * 1024 'Convert the value to bytes
END
PUBLIC SUB GetPkgInfo()
DIM vPKG AS NEW cPackageInfo
DIM hConfFile AS File
DIM sLine AS String
DIM i AS Integer
'Parse the bulk and config packages first (these are the most important)
OPEN Global.SOURCE & "veclinux/SETUP.CONF" FOR READ AS #hConfFile
WHILE NOT Eof(hConfFile)
LINE INPUT #hConfFile, sLine
vPKG = NEW cPackageInfo
'The parser needs to understand bash-like comments, so ignore anything to the right of a hash (#):
IF InStr(sLine, "#") THEN
sLine = Trim(Right(sLine, InStr(sLine, "#") - 1))
ENDIF
'Here is an example of what is going to be parsed by this section:
' BULK0='required/veclinux.tlz:971650:Base system (Base System)'
' BULK3='optional/dev.tlz:431371:dev tools (gcc, make, etc)'
' CONF1='required/vlconfig2.tlz:17613:Base system (config Files)'
IF InStr(sLine, "BULK") OR InStr(sLine, "CONF") THEN
vPKG.Selected = TRUE
vPKG.Name = Mid(Left(sLine, InStr(sLine, ":") - 1), InStr(sLine, "/") + 1)
vPKG.Category = Mid(Left(sLine, InStr(sLine, "/") - 1), InStr(sLine, "'") + 1)
vPKG.Comment = Mid(Left(sLine, RInStr(sLine, "'") - 1), RInStr(sLine, ":") + 1)
vPKG.Path = Global.SOURCE & "veclinux/" & vPKG.Category & "/" & vPKG.Name
vPKG.UncompSize = Val(Mid(Left(sLine, RInStr(sLine, ":") - 1), InStr(sLine, ":") + 1)) * 1024
Global.PkgTotalSize = Global.PkgTotalSize + vPKG.UncompSize
Global.PackageInfo.Push(vPKG)
ENDIF
WEND
CLOSE #hConfFile
'Parse the "extra" packages
'To see what the PACKAGES.TXT file looks like, visit one of the
'VL repositories (eg: http://vectorlinux.osuosl.org/veclinux-5.8/packages)
'or mount a VL installation CD and take a look inside.
OPEN Global.SOURCE & "packages/PACKAGES.TXT" FOR READ AS #hConfFile
vPKG = NEW cPackageInfo
WHILE NOT Eof(hConfFile)
LINE INPUT #hConfFile, sLine
vPKG.Selected = TRUE
vPKG.Category = "extra"
vPKG.Comment = ""
IF InStr(sLine, "PACKAGE NAME") THEN
vPKG.Name = Trim(Mid(sLine, InStr(sLine, ":") + 1))
ELSE IF InStr(sLine, "LOCATION") THEN
vPKG.Path = Global.SOURCE & "packages/" & Trim(Mid(sLine, InStr(sLine, "/") + 1)) & "/" & vPKG.Name
ELSE IF InStr(sLine, "SIZE (uncompressed)") THEN
vPKG.UncompSize = Val(Trim$(Mid(Left(sLine, RInStr(sLine, "K") - 1), InStr(sLine, ":") + 1))) * 1024
Global.PkgTotalSize = Global.PkgTotalSize + vPKG.UncompSize
ELSE IF Trim(sLine) = "" THEN 'An empty line marks the end of the package info, so push the data before moving on
Global.PackageInfo.Push(vPKG)
vPKG = NEW cPackageInfo
ENDIF
WEND
CLOSE #hConfFile
'For debugging
' FOR i = 0 TO Global.PackageInfo.Max
' PRINT Global.PackageInfo[i].Name
' PRINT Global.PackageInfo[i].Category
' PRINT Global.PackageInfo[i].Comment
' PRINT Global.PackageInfo[i].Path
' PRINT Global.PackageInfo[i].Size
' PRINT "-----"
' NEXT
END
PUBLIC SUB DoAutoInstall(txtlabel AS TextLabel) 'the textlabel indicates where information needs to be written to
txtlabel.Text &= "<br>Erasing partition table on " & global.installDrive & "..."
IF Functions.ErasePartTable(global.installDrive) = TRUE THEN
txtlabel.Text &= "<b><font color=00CC00>OK</font></b>"
ELSE
txtlabel.Text &= "<b><font color=FF0000>FAILED</font></b>"
RETURN
ENDIF
END
PUBLIC SUB BUTTdisable()
' Disable all frmMain buttons:
' Save state first:
BUTTsave
' Then disable:
frmMain.btnMain1.Enabled = FALSE
frmMain.btnMain2.Enabled = FALSE
frmMain.btnMain3.Enabled = FALSE
frmMain.btnMain4.Enabled = FALSE
frmMain.btnMain5.Enabled = FALSE
frmMain.btnMain6.Enabled = FALSE
frmMain.btnTools.Enabled = FALSE
frmMain.btnExit.Enabled = FALSE
END
PUBLIC SUB BUTTsave()
' Save state of all frmMain buttons:
frmMain.btnMain1.Tag = frmMain.btnMain1.Enabled
frmMain.btnMain2.Tag = frmMain.btnMain2.Enabled
frmMain.btnMain3.Tag = frmMain.btnMain3.Enabled
frmMain.btnMain4.Tag = frmMain.btnMain4.Enabled
frmMain.btnMain5.Tag = frmMain.btnMain5.Enabled
frmMain.btnMain6.Tag = frmMain.btnMain6.Enabled
frmMain.btnTools.Tag = frmMain.btnTools.Enabled
frmMain.btnExit.Tag = frmMain.btnExit.Enabled
END
PUBLIC SUB BUTTrest()
' Restore saved state of all frmMain buttons:
frmMain.btnMain1.Enabled = frmMain.btnMain1.Tag
frmMain.btnMain2.Enabled = frmMain.btnMain2.Tag
frmMain.btnMain3.Enabled = frmMain.btnMain3.Tag
frmMain.btnMain4.Enabled = frmMain.btnMain4.Tag
frmMain.btnMain5.Enabled = frmMain.btnMain5.Tag
frmMain.btnMain6.Enabled = frmMain.btnMain6.Tag
frmMain.btnTools.Enabled = frmMain.btnTools.Tag
frmMain.btnExit.Enabled = frmMain.btnExit.Tag
END