Source

vinstall-gambas / src / FrmUsePartition.class

Full commit
' 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 ClearFs AS Boolean

PUBLIC SUB Run() AS Boolean

  RETURN NOT ME.ShowModal()

END

PUBLIC SUB btnOK_Click()
  ClsGlobal.PRMntFs = Trim(ME.ComboBox2.Text)
  ClsGlobal.PRMntPoint = Trim(ME.ComboBox1.Text)
  
  ME.Close(TRUE)

END

PUBLIC SUB btnCancel_Click()

  ME.Close

END


PUBLIC SUB Form_Open()

DIM p AS Partition
DIM bf AS Boolean
DIM fs AS String


ME.Title = ("Select  how to use partition")
  TextLabel1.text = "<b>" & ("Select how") & Space(1) & Main.Install.Name & Space(1) & ("should use") & Space(1) & ClsGlobal.PSel & Space(1) & "</b>"
  TextLabel2.Text = ("Partition Size:") & Space(1) & ClsGlobal.PSelSize '& Space(1) & "(" & p.CurrentFileSystem & ")"
  ME.TextLabel3.Width = MdlObjSizer.get_object_width(ME.TextLabel4.Text)
  ME.TextLabel4.Width = ME.TextLabel3.Width
  ME.ComboBox2.ReadOnly = TRUE
  ME.ComboBox1.ReadOnly = TRUE
  FOR EACH p IN Main.Swaps_in_host
    IF p.BlockDevice = ClsGlobal.PSel THEN bf = TRUE
  NEXT 
    IF bf = TRUE THEN ' this is a swap partition
    ME.TextLabel3.Text = ("Use as:")
      ME.ComboBox1.List = [("Not Used"), ("Swap")]
      ME.ComboBox2.Enabled = FALSE
      ME.ComboBox2.List = [("Swap Space")]
      ME.TextLabel2.Text = ME.TextLabel2.Text & Space(1) & "(" & p.CurrentFileSystem & ")"
      'ME.TextLabel5.Text = "<b>" & ("Current filesystem:") & "</b>" & Space(1) & ("swap space")
    ELSE      
      FOR EACH p IN Main.Partitions_In_Host
        IF p.BlockDevice = ClsGlobal.PSel THEN 
          fs = p.CurrentFileSystem
          BREAK 
        END IF
      NEXT  
      'ME.TextLabel5.Text = "<b>" & ("Current filesystem:") & "</b>" & Space(1) & fs
      ME.TextLabel2.Text = ME.TextLabel2.Text & Space(1) & "(" & p.CurrentFileSystem & ")"
    IF ClsGlobal.PSel = Main.SelectedSrc.HostDevice THEN 
      ME.ComboBox1.List = [("Not Used"), Replace(ClsGlobal.PSel, "/dev", "/mnt")]
    ELSE 
      ME.ComboBox1.List = [("Not Used"), "/", "/home", "/usr", "/opt", "/tmp", "/var", "/boot", Replace(ClsGlobal.PSel, "/dev", "/mnt"), ("Other")]
    END IF
    ME.ComboBox2.List = [("Not Formatted"), "ext2", "ext3", "ext4", "jfs", "xfs", "reiserfs"]
  END IF
  
  btnok.Enabled = TRUE  

END

PUBLIC SUB ComboBox1_Click()
DIM p AS String
DIM i, ti AS Partition
  FOR EACH i IN main.Partitions_In_Host
    IF i.BlockDevice = ClsGlobal.PSel THEN
      ti = i
      BREAK 
    END IF
  NEXT 
      
  
  p = Verify_MountPoint(Trim(LAST.text), ClsGlobal.PSel)
  IF Len(Trim(p)) > 0 THEN 
    Message.Error(("You have already selected") & Space(1) & p & Space(1) & ("to be used as") & Space(1) & Trim(LAST.text) & "." & gb.NewLine &
    ("Please selecte another mount point for this partition, or you may go back and clear the settings for") & Space(1) & p)
    btnok.Enabled = FALSE
    ME.ComboBox1.Popup()
  ELSE 
    btnok.Enabled = TRUE
  END IF
    
    
    IF InStr(Trim(LAST.text), "/") AND IF InStr(Trim(LAST.text), "mnt") = FALSE THEN
    
    IF ComboBox2.Find(ti.CurrentFileSystem) = -1 THEN
      Message.Error(ti.CurrentFileSystem & Space(1) & ("is not a supported filesystem for linux partitions.") & gb.NewLine &
      ("Please select a filesystem from the dropdown below. All existing data in") & Space(1) & ti.BlockDevice & Space(1) & ("will be destroyed."))
      ClearFs = FALSE
      btnok.Enabled = FALSE
      ComboBox2.Popup()
    END IF
    END IF
  IF Trim(LAST.text) = ("Other") THEN 
    LAST.ReadOnly = FALSE
    LAST.text = ""
      Message.Info(("Enter mountpoint for this partition here in the dropdown box"))
  ELSE 
    LAST.ReadOnly = TRUE
  END IF
      

END
PUBLIC FUNCTION Verify_MountPoint(sMntPoint AS String, sPart AS String) AS String
  
  DIM p AS Partition
    
    IF ME.ComboBox2.Enabled = FALSE THEN RETURN  'this is a swap partition, no problem there. 
      FOR EACH p IN Main.Partitions_In_Host
        IF p.BlockDevice <> sPart THEN 
          IF p.IsUsed = TRUE THEN 
            IF p.SelectedMountpoint = sMntPoint THEN 
              RETURN p.BlockDevice
            END IF
          END IF
        ENDIF 
      NEXT 
    RETURN 
  
END




PUBLIC SUB ComboBox2_Click()

  IF ClearFs = FALSE THEN
    
    IF Trim(LAST.text) = ("Not Formatted") THEN 
      btnok.Enabled = FALSE
      
    ELSE
      btnok.Enabled = TRUE
    END IF
END IF
    

END