vlocity-vinstall-gambas / src / Step3a3.class

' 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 sMountedList AS String
PRIVATE objRbs AS NEW Object[]
PRIVATE objContainters AS NEW Object[]
PRIVATE myProgs AS NEW Object[]
PRIVATE objTls AS NEW Object[]
PRIVATE objSliders AS NEW Object[]



PRIVATE SUB DISPLAY_RESIZABLE_PARTITIONS()
  
  DIM sDump, sPreMountList, sDfDump, sDrives, sPartition, sPartShort AS String
  DIM sResults, sDumparr, sLineArr AS String[]
  DIM sPost, sFinalList AS String
  DIM lFreeMB, lTotalMB, lUsedMB AS Long
  DIM PicDrive AS Picture
  DIM i, n AS Integer
  DIM rb AS RadioButton
  DIM pb AS ProgressBar
  DIM sl AS Slider
  DIM hb AS hpanel
  DIM tl AS TextLabel
  DIM hr AS Separator
  DIM picb AS PictureBox
  DIM hobox AS Panel
  DIM sFs AS String
  DIM bgc AS Integer
  DIM p AS Partition
  DIM reswidth AS Integer
  'DIM hostContainer AS ScrollView = ME.ScrollView1
  
  picDrive = Picture.Load("images/hdd.png")
  PRINT " ---\\_ Shrink existing partitions to make room for " & Main.Install.Name

    FOR EACH p IN Partitioner.Partitions
    IF (p.Size - (p.UsedSpace + UnitConv.gb_to_sector(4))) < UnitConv.gb_to_sector(4) THEN CONTINUE ' Only list partitions with at least 8GB of free space
    
            SELECT CASE p.CurrentFileSystem
              CASE "xfs", "jfs", "reiserfs", "hfsplus"
                'CONTINUE 
                bgc = Color.Magenta
              CASE "ntfs", "NTFS"
                bgc = &h66FF66
              CASE "fat32", "FAT32", "vfat", "VFAT"
                bgc = &h33FF33
              CASE "fat16", "FAT", "FAT16"
                bgc = &h009900
              CASE "ext2", "EXT2"
                bgc = &h99CCFF
              CASE "ext3", "EXT3"
                bgc = &h336699
              CASE ELSE 
                bgc = Color.DarkGreen
            END SELECT 
            
        ' begin creating the objects here
    rb = NEW RadioButton(ScrollView1) AS "PartitionOptions"
          WITH rb
            .Text = p.BlockDevice & p.Number & " - " & UnitConv.sector_to_gb(p.FreeSpace) & " GB Free" 'Trim(sLineArr[0]) & Space(1) & "-" & Space(1) & Trim(sLineArr[4]) & Space(1) & ("MB of free space") & " [ " & sFs & " ]"
            .tag = p.BlockDevice & p.Number
            .Height = 21
            .Expand = TRUE
          END WITH 
          objRbs.Add(rb)

        hb = NEW hpanel(ME.ScrollView1)
          WITH hb
            .Expand = TRUE
            .Height = 72
            .Tag = p.BlockDevice & p.Number
            .Visible = FALSE
          END WITH 
          objContainters.Add(hb)
        
          hr = NEW Separator(hb)
            WITH hr
              .Expand = TRUE
              .Height = 8
              .tag = p.BlockDevice & p.Number
            END WITH 
          hobox = NEW Panel(hb)
            WITH hobox
              .Height = 21
              .Tag = p.BlockDevice & p.Number
              .Expand = TRUE
              .Arrangement = Arrange.Row
              .Spacing = 2
              .BackColor = Color.LightBackground
            END WITH 
          
          tl = NEW TextLabel(hobox)
            WITH tl
              .BackColor = bgc
              .Expand = FALSE
              '.Text = ("Existing Data")
              SHELL "os-prober | grep \'^" & p.BlockDevice & p.Number & "\' | cut -f2 -d:" TO sDump
              IF Len(Trim(sDump)) > 0 THEN 
                .Text = Trim(sDump)
              ELSE 
                .Text = ("Existing Data")
              END IF
              .Width = .Parent.Width / 2
              '.Width = .Parent.Width - (((lUsedMB + (4 * 1024)) + (lFreeMB / 2) / lFreeMB) / 100) * 100
              .Width = .Parent.Width * (((p.UsedSpace + UnitConv.gb_to_sector(4)) / p.Size) / 100)
              reswidth = .Parent.Width = .Width
              .Height = .Parent.Height
              .Alignment = Align.Center
              .Raise()
              .Expand = TRUE
              '.Visible = TRUE
              .tag = .Parent.Tag
            END WITH 
            myProgs.Add(tl)
          tl = NEW TextLabel(hobox)
            WITH tl
              .Text = Main.Install.Name & Space(1) & Main.Install.Version
              .Height = .Parent.Height
              .Expand = TRUE
              .Alignment = Align.Center
              .Width = reswidth
              .Tag = .Parent.Tag & "R"
            END WITH 
            objTls.Add(tl)
        
          tl = NEW TextLabel(hb)
            WITH tl
              .Text = ("Total space for") & Space(1) & Main.Install.Name & Space(1) & ":" & Space(1)
              .Height = 21
              '.Width = .Parent.Width * 0.5
              .Alignment = Align.Left
              .BackColor = Color.Transparent
              .Expand = TRUE
              .tag = p.BlockDevice & p.Number
            END WITH 
              objTls.Add(tl)
        
          sl = NEW Slider(hb) AS "Slider"
            WITH sl
              .Tag = p.BlockDevice & p.Number
              .Height = 21
              .Expand = TRUE
              .Value = (p.UsedSpace / p.Size) * 100        
            END WITH 
            objSliders.Add(sl)
          hr = NEW Separator(hb)
          WITH hr
          .Expand = TRUE
          .Height = 4
          .Tag = p.BlockDevice & p.Number
          END WITH 
        

      NEXT       
      
            
'=============================================================================================            

  
END





PUBLIC SUB Slider_Change()
  
  DIM tlr, tl AS TextLabel
  DIM p, part AS Partition
  DIM Mini AS Long
  DIM MinPct AS Float
  
  
  
  FOR EACH p IN Partitioner.Partitions
    IF p.BlockDevice = Left(LAST.tag, Len("/dev/hda")) AND IF p.Number = Right(LAST.tag, Len(LAST.tag) - Len("/dev/hda")) THEN 
      part = p
      Mini = (part.UsedSpace + UnitConv.gb_to_sector(4))
    END IF
  NEXT 
  
  MinPct = (Mini / part.Size) * 100
  'LAST.Value = MinPct
  'PRINT MinPct & "%"
  

  
  FOR EACH tl IN myProgs
    IF tl.Tag = LAST.tag THEN 
      tl.Visible = TRUE
      tl.Expand = FALSE
      tl.Width = tl.Parent.Width * (LAST.Value / 100)
    END IF
  NEXT 
  
  FOR EACH tl IN objTls
    IF tl.Tag = LAST.tag THEN 
      tl.Text = ("Total space for") & Space(1) & Main.Install.Name & ":" & Space(1) 
      tl.Visible = TRUE
      tl.Expand = FALSE
    END IF
  NEXT 
  
  IF LAST.Value < MinPct THEN 
    'Message(("We can not resize this partition to this value because of the existing data in it."))
    LAST.Value = MinPct
    RETURN 
  END IF

  
END




PUBLIC SUB PartitionOptions_Click()
  
  DIM hb AS HPanel
  DIM sl AS Slider
  FOR EACH hb IN objContainters
    IF hb.tag = LAST.tag THEN 
      hb.visible = TRUE
    ELSE 
      hb.visible = FALSE
    END IF
  NEXT 
  FOR EACH sl IN objSliders
    IF sl.Tag = LAST.tag THEN 
      INC sl.Value
      DEC sl.Value
    END IF  
        NEXT 
END


PUBLIC SUB Form_Open()
DIM rb AS RadioButton
DIM p, Lrg AS Partition
DIM iMax AS Long
  Partitioner.detect_resizable_partitions()
  WAIT 
  PRINT Partitioner.Partitions.Count
  ME.tlbanner.Text = "<h2>" & ("Claim free space from existing partitions") & "</h2>"
  DISPLAY_RESIZABLE_PARTITIONS()

END


PUBLIC FUNCTION GetNExt() AS String
  
  RETURN "Step3a3a"
  
  
END



PUBLIC SUB StartUp() 
  

END
PUBLIC SUB GetSelection()
  
  DIM rb AS RadioButton
  DIM sl AS Slider
  DIM p AS Partition
  DIM sSlVal AS Integer
  
  FOR EACH rb IN objRbs
    IF rb.Value = TRUE THEN 
      FOR EACH sl IN objSliders
        IF sl.Tag = rb.Tag THEN 
          FOR EACH p IN Partitioner.Partitions
            IF p.BlockDevice = Left(sl.Tag, Len("/dev/hda")) AND IF p.Number = Right(sl.Tag, Len(sl.Tag) - Len("/dev/hda")) THEN 
              Partitioner.AutoTarget = NEW Partition
              Partitioner.AutoTarget.BlockDevice = p.BlockDevice
              Partitioner.AutoTarget.Number = p.Number
              Partitioner.AutoTarget.Size = p.Size * (sl.Value / 100)
              Partitioner.AutoTarget.Beginning = p.Beginning
              Partitioner.AutoTarget.Fin = Partitioner.AutoTarget.Beginning + Partitioner.AutoTarget.Size
            END IF
          NEXT 
        END IF
      NEXT 
    END IF
  NEXT 
            
     DEBUG "Partition selected to be resized : " & Partitioner.AutoTarget.BlockDevice & Partitioner.AutoTarget.Number & gb.NewLine & "Resize to " & UnitConv.sector_to_gb(Partitioner.AutoTarget.Size) & " GB"         
  
END

PUBLIC SUB OnExit()
  GetSelection()
END

PUBLIC SUB Form_Resize()

  'ME.HpnlChoices.Height = ME.ClientH - (ME.tlExp.top + ME.tlExp.Height + 12)
  ME.ScrollView1.Height = ME.ClientH - (ME.tlExp.Top + ME.tlExp.Height + 12)

END
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.