Ignore:
Timestamp:
Apr 2, 2016, 11:08:30 AM (9 years ago)
Author:
chronos
Message:
  • Added: Available block drives detection under Linux.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Form/UFormMain.pas

    r11 r12  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    99  Menus, ComCtrls, ExtCtrls, ActnList, dateutils, syncobjs, UProject,
    10   UDriveScan, UPrefixMultiplier, XMLConf;
     10  UDriveScan, UPrefixMultiplier, XMLConf, UPhysDrive;
    1111
    1212type
     
    2727    AScanStop: TAction;
    2828    ActionList1: TActionList;
    29     Button1: TButton;
    3029    Button2: TButton;
    3130    Button3: TButton;
     
    3332    ButtonScan1: TButton;
    3433    ButtonScan2: TButton;
    35     EditDrive: TEdit;
     34    ComboBoxDrive: TComboBox;
    3635    Image1: TImage;
    3736    Label1: TLabel;
     
    7574    Timer1: TTimer;
    7675    XMLConfig1: TXMLConfig;
    77     procedure ABrowseDiskExecute(Sender: TObject);
    7876    procedure AExitExecute(Sender: TObject);
    7977    procedure AFileCloseExecute(Sender: TObject);
     
    8785    procedure AScanStartExecute(Sender: TObject);
    8886    procedure AScanStopExecute(Sender: TObject);
     87    procedure ComboBoxDriveChange(Sender: TObject);
    8988    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    9089    procedure FormCreate(Sender: TObject);
     
    10099    LastProjectFileName: string;
    101100    procedure ReloadOperationList;
    102     procedure CheckDrive;
    103101    procedure ProjectOpen(FileName: string);
    104102    procedure DriveScanChange(Sender: TObject);
     
    108106    procedure UpdateInterface;
    109107  public
     108    DriveList: TDriveList;
    110109    DriveScan: TDriveScan;
    111110    Project: TProject;
     
    134133  SBytes = 'bytes';
    135134
    136 const
    137   DefaultDriveName = '/dev/sda';
    138 
    139135{ TFormMain }
    140136
    141137procedure TFormMain.FormShow(Sender: TObject);
    142138begin
     139  Detect;
    143140  LoadConfig;
    144141  if FileExists(LastProjectFileName) then
     
    171168begin
    172169  PrefixMultiplier := TPrefixMultiplier.Create;
    173   EditDrive.Text := DefaultDriveName;
    174170  XMLConfig1.Filename := 'config.xml';
    175171  Project := nil;
     172  DriveList := TDriveList.Create;
    176173end;
    177174
     
    182179end;
    183180
     181procedure TFormMain.ComboBoxDriveChange(Sender: TObject);
     182begin
     183  DriveScan.SectorCount := TDriveInfo(DriveList[ComboBoxDrive.ItemIndex]).SectorCount;
     184  DriveScan.DriveName := TDriveInfo(DriveList[ComboBoxDrive.ItemIndex]).Path;
     185  DriveScan.SectorStart := 0;
     186  DriveScan.SectorEnd := DriveScan.SectorCount - 1;
     187end;
     188
    184189procedure TFormMain.AScanStartExecute(Sender: TObject);
    185190begin
    186191  LastBlockPos := 0;
    187   DriveScan.DriveName := EditDrive.Text;
     192  DriveScan.DriveName := TDriveInfo(DriveList[ComboBoxDrive.ItemIndex]).Path;
    188193  DriveScan.Reset;
    189194  DriveScan.SectorSize := Project.SectorSize;
     
    197202procedure TFormMain.AProjectOptionsExecute(Sender: TObject);
    198203begin
    199   CheckDrive;
    200204  FormProject.Load(Project);
    201205  if FormProject.ShowModal = mrOk then begin
     
    211215  Project.Modified := True;
    212216  UpdateInterface;
    213 end;
    214 
    215 procedure TFormMain.ABrowseDiskExecute(Sender: TObject);
    216 begin
    217   OpenDialog1.Title := SSelectDriveForScan;
    218   OpenDialog1.DefaultExt := '';
    219   OpenDialog1.FileName := EditDrive.Text;
    220   if OpenDialog1.Execute then
    221     EditDrive.Text := OpenDialog1.FileName;
    222217end;
    223218
     
    243238  DriveScan := TDriveScan(Project.Scans[0]);
    244239
    245   CheckDrive;
    246240  DriveScan.SectorStart := 0;
    247241  DriveScan.SectorEnd := DriveScan.SectorCount - 1;
     
    304298  if Assigned(Project) then FreeAndNil(Project);
    305299  FreeAndNil(PrefixMultiplier);
     300  FreeAndNil(DriveList);
    306301end;
    307302
     
    394389procedure TFormMain.SaveConfig;
    395390begin
    396   XMLConfig1.SetValue('DriveName', EditDrive.Text);
     391  XMLConfig1.SetValue('DriveName', TDriveInfo(DriveList[ComboBoxDrive.ItemIndex]).Model);
    397392  XMLConfig1.SetValue('LastProjectFileName', LastProjectFileName);
    398393end;
     
    400395procedure TFormMain.LoadConfig;
    401396begin
    402   EditDrive.Text := XMLConfig1.GetValue('DriveName', DefaultDriveName);
     397  ComboBoxDrive.ItemIndex := DriveList.IndexOf(DriveList.FindByModel(XMLConfig1.GetValue('DriveName', '')));
    403398  LastProjectFileName := XMLConfig1.GetValue('LastProjectFileName', '');
    404399end;
     
    419414end;
    420415
    421 procedure TFormMain.CheckDrive;
    422 begin
    423   DriveScan.CheckDrive;
    424   Project.SectorCount := DriveScan.SectorCount;
    425 end;
    426 
    427416procedure TFormMain.ProjectOpen(FileName: string);
    428417begin
     
    445434
    446435procedure TFormMain.Detect;
    447 begin
    448 
     436var
     437  I: Integer;
     438begin
     439  DriveList.Detect;
     440  while ComboBoxDrive.Items.Count > DriveList.Count do
     441    ComboBoxDrive.Items.Delete(ComboBoxDrive.Items.Count - 1);
     442  while ComboBoxDrive.Items.Count < DriveList.Count do
     443    ComboBoxDrive.Items.Add('');
     444  for I := 0 to DriveList.Count - 1 do
     445    ComboBoxDrive.Items[I] := TDriveInfo(DriveList[I]).Model + ' (' +
     446      PrefixMultiplier.Add(TDriveInfo(DriveList[I]).Size, BasePrefixMultipliers, 'B') + ')';
    449447end;
    450448
Note: See TracChangeset for help on using the changeset viewer.