Source

vlocity-vinstall-gambas / Vlocity / Step6.class

Full commit
  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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
' Gambas class file
'    This file is part of vinstall-ng

'    vinstall-ng is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    vinstall-ng  is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with vinstall-ng.  If not, see <http://www.gnu.org/licenses/>.
PRIVATE bBtnUpdate AS Boolean
PUBLIC SelectedPart AS String

PRIVATE cb AS ComboBox
PRIVATE x AS Integer
PRIVATE y AS Integer
PUBLIC objMntPoints AS Object[]
PUBLIC objFS AS Object[]

PUBLIC FUNCTION GetNext() AS String
  
  IF FMain.bConfMode = TRUE THEN 
    'Message.Warning("Running in config mode... I will now genrate the boot menu objects." & gb.NewLine & "This will take a few seconds.")
    MdlMain.Set_App_Status("Running in config mode.. Now creating bootmenu objects", 10)
    WAIT 0.25
    MdlBootMngr.CREATE_MENU_ENTRY_OBJECTS
    RETURN "Conf0"
  ELSE 
    RETURN "Step7"
  END IF

  
END

PUBLIC SUB OnExit()
  
  ' DIM n AS Integer
  ' DIM sFmtAs, sList, sPartAddr AS String
  ' ClsGlobal.sVitalPartList = ""
  ' ClsGlobal.sWapPartList = ""
  read_partition_selection()
  

    ' FOR n = 1 TO gvPartListing.Rows.Count - 1
    '   IF gvPartListing[n, 2].Text THEN 
    '     sPartAddr = gvPartListing[n, 2].Text
    '     IF gvPartListing[n, 4].Text THEN 
    '       sFmtAs = gvPartListing[n, 4].Text
    '     ELSE 
    '       sFmtAs = gvPartListing[n, 5].Text
    '     END IF
    '   END IF
    '   sList = sList & sPartAddr & "," & sFmtAs & ";"
    '   'Message(gvPartListing[n, 0].Text & gb.NewLine & gvPartListing[n, 2].Text & gb.NewLine & sFmtAs)
    '   
    ' NEXT 
    ' ME.read_partition_selection
    'Message(ClsGlobal.sVitalPartList)
   ' sList = Trim(Left(sList, Len(sList) - 1))
  'ClsGlobal.sVitalPartList = Trim(sList)
  'Message(ClsGlobal.sVitalPartList)
END

PUBLIC SUB StartUp()
  
  ME.Resize(ClsGlobal.fRunningMainForm.Pnlstack.Width, ClsGlobal.fRunningMainForm.PnlStack.Height)
  
END

PUBLIC SUB PREPARE_PARTITION_LISTING()
DIM i AS Integer
  WITH ME.gvPartListing
    .Columns.Count = 7
    .Rows.count = 1
  END WITH 
  
  gvhdr.Rows.Count = 1
  gvhdr.Columns.Count = 7
  gvhdr[0, 0].Text = ("Partition")
  gvhdr[0, 1].Text = ("Size")
  gvhdr[0, 2].Text = ("Mount Point")
  gvhdr[0, 4].Text = ("Format As")
  gvhdr[0, 6].Text = ("Current Filesystem")
  
  FOR i = 0 TO gvhdr.Columns.Count - 1
    gvhdr[0, i].BackColor = Color.LightBackground
    gvhdr[0, i].Font.Bold = TRUE
  NEXT 
  
  gvhdr.Columns[0].Width = 120
  gvhdr.Columns[1].Width = 120
  gvhdr.Columns[2].Width = 150
  gvhdr.Columns[3].Width = 12
  gvhdr.Columns[4].Width = 150
  gvhdr.Columns[5].Width = 1
  
  

    gvPartListing.Columns[0].Width = 120

    gvPartListing.Columns[1].Width = 120

    gvPartListing.Columns[2].Width = 150

    gvPartListing.Columns[3].Width = 12

    gvPartListing.Columns[4].Width = 150

    gvPartListing.Columns[5].Width = 1

    ClsGlobal.fRunningMainForm.btnext.enabled = FALSE
  END
  
PRIVATE SUB LIST_SWAP_SPACE()
  
  DIM sDUmp, s AS String
  DIM arr, $line AS String[]
  DIM i, n AS Integer
  DIM p AS Partition
  
  Main.Swaps_in_host.Clear()
    SHELL "probepart | grep -i \'swap\' | grep ^/dev | tr -s \' \',\"\"" TO sdump
    IF Len(Trim(sdump)) <= 0 THEN RETURN 
    arr = Split(Trim(sdump), gb.NewLine)
      FOR i = 0 TO arr.Max
          $line = Split(Trim(arr[i]), " ")
        p = NEW Partition
        p.BlockDevice = Trim($line[0])
        p.IsUsed = TRUE
        n = Right(p.BlockDevice, Len(p.BlockDevice) - Len("/dev/hda"))
          IF n < 9 THEN s = Space(1)
          SHELL "parted " & Left(p.BlockDevice, Len("/dev/hda")) & Space(1) & " -s \'print\' | grep \"^" & s & n & "\"|tr -s \' \',\"\" | cut -f5 -d \' \'" TO sdump
          p.RawSize = Trim(sdump)
        'p.RawSize = UnitConv.sector_to_mb(Replace($line[3], "+", "")) & "MB"
        p.CurrentFileSystem = "Swap Space"
        Main.Swaps_in_host.Add(p)
      
      NEXT 
    
    i = gvPartListing.Rows.Count - 2
    
      FOR EACH p IN Main.Swaps_in_host
      
        INC gvPartListing.Rows.Count
         gvPartListing[i, 0].Text = p.BlockDevice
         gvPartListing[i, 1].Text = p.RawSize
         gvPartListing[i, 4].Text = p.CurrentFileSystem
         gvPartListing[i, 0].BackColor = Color.LightGray
                gvPartListing[i, 1].BackColor = Color.LightGray
                gvPartListing[i, 2].BackColor = Color.LightGray
                gvPartListing[i, 2].Text = ("Swap")
                gvPartListing[i, 3].BackColor = Color.LightGray
                gvPartListing[i, 4].BackColor = Color.LightGray
                gvPartListing[i, 5].BackColor = Color.LightGray
                gvPartListing[i, 6].BackColor = Color.LightGray
                INC i
                INC gvPartListing.Rows.Count
      NEXT 
  
  
END

PRIVATE SUB Cleanup_Empty_rows()
  
  DIM i AS Integer
    i = gvPartListing.Rows.Count - 1
    REPEAT 
      'i = gvPartListing.Rows.Count - 1
        IF Len(gvPartListing[i, 0].Text) <= 0 THEN 
          DEC gvPartListing.Rows.Count
          DEC i
        END IF
    UNTIL Len(gvPartListing[i, 0].Text) > 0 
      
  
END

  
PRIVATE SUB LIST_PARTITION_OBJECTS()
  
  DIM p AS Partition
  DIM i, irow AS Integer
  
  INC ME.gvPartListing.Rows.Count
  irow = 0
  FOR EACH p IN Main.Partitions_In_Host
    'INC ME.gvPartListing.Rows.Count
    ME.gvPartListing[irow, 0].Text = p.BlockDevice
    ME.gvPartListing[irow, 1].Text = p.RawSize
    ME.gvPartListing[irow, 2].Text = ("Not Used")
    ME.gvPartListing[irow, 4].text = ("Not Formatted") 'p.CurrentFileSystem
    ME.gvPartListing[irow, 6].Text = p.CurrentFileSystem
    INC irow
    INC gvPartListing.Rows.Count
    
  NEXT 
  
END


PUBLIC FUNCTION CheckEntry(sEntry AS String, iCurrRow AS Integer) AS Integer
  
  DIM irow AS Integer '= 2
   irow = 0
      REPEAT 
        IF irow <> iCurrRow THEN 
          IF gvPartListing[irow, 2].Text AND gvPartListing[irow, 2].Text = sEntry THEN 
            Message.Error(("You have already selected") & Space(1) & gvPartListing[irow, 0].Text & Space(1) & ("as your") & Space(1) & Trim(sEntry) & Space(1) & ("partition.") & gb.NewLine &
           ("Please select only one partition for this purpose"))          
            RETURN 1
          END IF
        END IF
        INC irow
    UNTIL irow = gvPartListing.Rows.count - 1
    RETURN 0
  
END



PUBLIC SUB MOUNT_TARGET_PARTITIONS()
  
  DIM i, n AS Integer
  DIM spart, sMntPoint, sfs AS String
  DIM sEntry AS String[]
    FOR i = 0 TO Main.Install.Partitions.Max
      sEntry = Split(Trim(Main.Install.Partitions[i]), "-")
      spart = sEntry[0]
      sMntPoint = sEntry[2]
      sfs = sEntry[3]
        IF NOT sfs THEN ' not formatted... let's find the current fs
          FOR n = 2 TO gvPartListing.Rows.Count - 1
            IF gvPartListing[n, 0].Text = spart THEN 
              sfs = Trim(gvPartListing[n, 5].Text)
            END IF
          NEXT 
        END IF
    NEXT 
  
END


PUBLIC SUB read_partition_selection()
  
  DIM p AS Partition
  
  Main.Install.Partitions.Clear()
  
    FOR EACH p IN Main.Partitions_In_Host
      IF p.IsUsed = TRUE THEN 
        DEBUG "Select partition " & p.BlockDevice & Space(1) & "as" & Space(1) & p.SelectedMountpoint & Space(1) & p.SelectedFilesystem
        Main.Install.Partitions.add(p.BlockDevice & "-" & p.RawSize & "-" & p.SelectedMountpoint & "-" & p.SelectedFilesystem)
        SHELL "mkdir -p " & Main.Install.TargetMount &/ p.SelectedMountpoint WAIT 
        IF p.SelectedMountpoint = "/" THEN 
          Main.Install.Root = p.BlockDevice
          Main.Install.RootPartition = p.BlockDevice
        END IF
      END IF
    NEXT 
    
    ' read swap partitions
    FOR EACH p IN Main.Swaps_in_host
      IF p.IsUsed = TRUE THEN 
        DEBUG "Select swap partition " & p.BlockDevice & Space(1) & "for target install. Total size=" & p.RawSize
          Main.Install.Partitions.Add(p.BlockDevice & "-" & p.RawSize & "-swap-linux-swap")
          IF Main.TargetSwaps.Find(p.BlockDevice) = -1 THEN Main.TargetSwaps.Push(p.BlockDevice)
      END IF
    NEXT 
  
END


PUBLIC SUB read_partition_selection_unused()
  
  DIM CB AS ComboBox
  DIM i, irow AS Integer
  DIM spart, sformat, ssize, smntpoint AS String
    FOR EACH cb IN objMntPoints
      IF cb.Text <> ("Not Used") THEN 
        FOR irow = 2 TO gvPartListing.Rows.Count - 1
          IF gvPartListing[irow, 0].Text = cb.Tag THEN 
            spart = gvPartListing[irow, 0].Text
            sformat = gvPartListing[irow, 4].Text
            smntpoint = LCase(gvPartListing[irow, 2].Text)
            ssize = gvPartListing[irow, 1].Text
            Main.Install.Partitions.Add(spart & "-" & ssize & "-" & cb.Text & "-" & sformat)
          END IF
        NEXT 
      END IF
    NEXT 
        
          PRINT ("Partitions selected:")
  FOR i = 0 TO Main.Install.Partitions.Max
    PRINT Main.Install.Partitions[i]
  NEXT 
  
    
  
END


PUBLIC SUB read_partition_selection_OLD()
  
  DIM spart, sformat, sSize, sMntPoint AS String
  DIM i, irow AS Integer
  DIM cbox, cb AS ComboBox
  
  Main.Install.Partitions.Clear() ' clear the array to avoid double entries
    FOR irow = 2 TO gvPartListing.Rows.Count - 1
      'IF Trim(gvPartListing[irow, 2].Text) AND Trim(gvPartListing[irow, 2].Text) <> ("Not Used") THEN 
      'IF Trim(gvPartListing[irow, 2].Text) <> ("Not Used") OR InStr(gvPartListing[irow, 2].Text, "/") THEN 
      'IF Trim(gvPartListing[irow, 2].Text) <> ("Not Used") THEN 
      IF Len(gvPartListing[irow, 2].Text) > 0 THEN 
        spart = Trim(gvPartListing[irow, 0].Text)
        sSize = Trim(gvPartListing[irow, 1].Text)
        sMntPoint = Trim(gvPartListing[irow, 2].Text)
        sformat = Trim(gvPartListing[irow, 4].Text)
        Main.Install.Partitions.Add(spart & "-" & sSize & "-" & sMntPoint & "-" & sformat)
        IF sformat LIKE ("swap") THEN Main.Install.Partitions.Add(spart & "-" & sSize & "-" & ("swap") & "-" & "linux-swap")
          
        IF Len(Trim(sMntPoint)) = 1 THEN 
          Main.Install.Root = spart
          Main.Install.RootPartition = spart
        END IF
      END IF
    NEXT 
  
  PRINT ("Partitions selected:")
  FOR i = 0 TO Main.Install.Partitions.Max
    PRINT Main.Install.Partitions[i]
  NEXT 
  
END



PUBLIC SUB Form_Open()

  ME.tlbanner.Text = "<h2>" & ("Select which partitions to use for installation") & "</h2>"
  ME.TextLabel1.Text = ("Select partitions by clicking on them, and changing their properties.")
  ClsGlobal.fRunningMainForm.btnext.enabled = FALSE
  ME.PREPARE_PARTITION_LISTING()
  'ME.LIST_PARTITIONS()
  LIST_PARTITION_OBJECTS()
  LIST_SWAP_SPACE()
  Cleanup_Empty_rows()
  ClsGlobal.fRunningMainForm.btnext.enabled = FALSE
  MdlMain.Set_App_Status("")
END

PUBLIC SUB Form_Resize()

  'ME.gvPartListing.Height = gvPartListing.Parent.Height
  'ME.Panel1.Height = ME.ClientH - (ME.HPanel1.Top + ME.HPanel1.Height + hbox1.Height + 8)
  'ME.gvPartListing.Resize(gvPartListing.Parent.Width, gvPartListing.Parent.Height - hbox2.Height - 8)

END

PRIVATE FUNCTION Update_NextBtn_Status() AS Boolean
DIM p AS Partition
DIM b AS Boolean

IF bBtnUpdate = FALSE THEN RETURN 
  FOR EACH p IN Main.Partitions_In_Host
    IF p.IsUsed = TRUE THEN 
        IF p.SelectedMountpoint = "/" THEN 
          b = TRUE
          BREAK 
        ELSE 
          b = FALSE
        END IF
    END IF
  NEXT 
  bBtnUpdate = FALSE
  RETURN b
        
  
END



PUBLIC SUB gvPartListing_Click()
  DIM p AS Partition

  'IF LAST.column > 1 THEN RETURN 
  'IF LAST.row < 2 THEN RETURN 

  ClsGlobal.PSel = gvPartListing[LAST.row, 0].Text
  ClsGlobal.PSelSize = gvPartListing[LAST.row, 1].Text
  
  
  IF FrmUsePartition.Run() THEN RETURN 
  bBtnUpdate = TRUE
    IF ClsGlobal.PRMntPoint = ("Not Used") THEN 
      IF InStr(gvPartListing[LAST.row, 4].Text, ("Swap")) THEN 
        FOR EACH p IN Main.Swaps_in_host
          IF p.BlockDevice = gvPartListing[LAST.row, 0].Text THEN p.IsUsed = FALSE
        NEXT 
      ELSE 
        FOR EACH p IN Main.Partitions_In_Host
          IF p.BlockDevice = gvPartListing[LAST.row, 0].Text THEN p.IsUsed = FALSE
        NEXT 
      END IF
      gvPartListing[LAST.row, 2].Text = ClsGlobal.PRMntPoint
      gvPartListing[LAST.row, 4].Text = ("Not Formatted")
      RETURN ' return if the partition was de-selected
  END IF
  
  IF InStr(gvPartListing[LAST.row, 4].Text, ("Swap")) THEN ' this is a swap partition
  'IF ClsGlobal.PRMntFs LIKE "swap" THEN 
      'Message("Jacking with swap partition ")
      FOR EACH p IN Main.Swaps_in_host
        IF p.BlockDevice = gvPartListing[LAST.row, 0].Text THEN 
          IF ClsGlobal.PRMntPoint <> ("Not Used") THEN p.IsUsed = TRUE
          IF ClsGlobal.PRMntPoint = ("Not Used") THEN p.IsUsed = FALSE
            
        END IF
      NEXT 
      
      
  ELSE 
  
    FOR EACH p IN Main.Partitions_In_Host
      IF p.BlockDevice = gvPartListing[LAST.row, 0].Text THEN 
        IF ClsGlobal.PRMntPoint <> ("Not Used") THEN 
          p.IsUsed = TRUE
          p.SelectedMountpoint = ClsGlobal.PRMntPoint
          p.SelectedFilesystem = ClsGlobal.PRMntFs
        IF ClsGlobal.PRMntFs <> ("Not Formatted") THEN 
          p.ToFormat = FALSE
        ELSE 
          p.ToFormat = TRUE
        END IF
        END IF
      END IF
    NEXT 
  END IF
      
  ME.gvPartListing[LAST.row, 2].Text = ClsGlobal.PRMntPoint
  ME.gvPartListing[LAST.row, 4].Text = ClsGlobal.PRMntFs
  
   
  gvPartListing.Refresh()
  ClsGlobal.fRunningMainForm.btnext.enabled = Update_NextBtn_Status()
  
  RETURN 
 
END