Ignore:
Timestamp:
Apr 2, 2016, 8:18:30 PM (8 years ago)
Author:
chronos
Message:
  • Added: Ability to add and remove scan operation.
  • Modified: XMLConfig moved from TMainForm to TCore as more proper place for general object.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Form/UFormMain.pas

    r15 r16  
    1515
    1616  TFormMain = class(TForm)
     17    AOperationAdd: TAction;
     18    AOperationRemove: TAction;
     19    AViewToolbar: TAction;
    1720    ADriveSelect: TAction;
    1821    AOperationOptions: TAction;
     
    2831    AScanStop: TAction;
    2932    ActionList1: TActionList;
     33    Button1: TButton;
    3034    Button2: TButton;
    3135    Button3: TButton;
     36    Button4: TButton;
    3237    ButtonScan: TButton;
    3338    ButtonScan1: TButton;
     
    3540    ComboBoxDrive: TComboBox;
    3641    Image1: TImage;
    37     ImageList1: TImageList;
    3842    Label1: TLabel;
    3943    Label10: TLabel;
     
    4650    Label7: TLabel;
    4751    Label8: TLabel;
    48     LabelElapsedTime: TLabel;
    49     LabelSectorSize: TLabel;
    50     LabelSectorCount: TLabel;
    5152    LabelBlockCurrent: TLabel;
    5253    LabelBlockDamaged: TLabel;
     54    LabelElapsedTime: TLabel;
    5355    LabelEstimatedTime: TLabel;
    5456    LabelIOSpeed: TLabel;
     57    LabelSectorCount: TLabel;
     58    LabelSectorPerBlock: TLabel;
     59    LabelSectorSize: TLabel;
    5560    LabelSize: TLabel;
    56     LabelSectorPerBlock: TLabel;
    5761    LastOpenedList1: TLastOpenedList;
    5862    ListView1: TListView;
     
    6569    MenuItem14: TMenuItem;
    6670    MenuItem15: TMenuItem;
     71    MenuItem16: TMenuItem;
     72    MenuItem17: TMenuItem;
     73    MenuItem18: TMenuItem;
     74    MenuItem19: TMenuItem;
    6775    MenuItemOpenRecent: TMenuItem;
    6876    MenuItem2: TMenuItem;
     
    7583    MenuItem9: TMenuItem;
    7684    OpenDialog1: TOpenDialog;
     85    Panel1: TPanel;
     86    Panel2: TPanel;
     87    PopupMenu1: TPopupMenu;
    7788    SaveDialog1: TSaveDialog;
     89    Splitter1: TSplitter;
    7890    Timer1: TTimer;
    7991    ToolBar1: TToolBar;
     
    8193    ToolButton2: TToolButton;
    8294    ToolButton3: TToolButton;
    83     XMLConfig1: TXMLConfig;
    8495    procedure AExitExecute(Sender: TObject);
    8596    procedure AFileCloseExecute(Sender: TObject);
     
    8899    procedure AFileSaveAsExecute(Sender: TObject);
    89100    procedure AFileSaveExecute(Sender: TObject);
     101    procedure AOperationAddExecute(Sender: TObject);
    90102    procedure AOperationOptionsExecute(Sender: TObject);
     103    procedure AOperationRemoveExecute(Sender: TObject);
    91104    procedure AProjectOptionsExecute(Sender: TObject);
    92105    procedure AScanContinueExecute(Sender: TObject);
    93106    procedure AScanStartExecute(Sender: TObject);
    94107    procedure AScanStopExecute(Sender: TObject);
     108    procedure AViewToolbarExecute(Sender: TObject);
    95109    procedure ComboBoxDriveChange(Sender: TObject);
    96110    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     
    101115    procedure Image1Resize(Sender: TObject);
    102116    procedure ListView1Data(Sender: TObject; Item: TListItem);
     117    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
     118      Selected: Boolean);
    103119    procedure Timer1Timer(Sender: TObject);
    104120  private
     
    107123    RedrawPending: Boolean;
    108124    LastDriveName: string;
     125    ShowToolBar: Boolean;
    109126    procedure OpenRecentClick(Sender: TObject);
    110127    procedure ReloadOperationList;
     
    165182procedure TFormMain.ListView1Data(Sender: TObject; Item: TListItem);
    166183begin
    167   if (Item.Index >= 0) and (Item.Index < Core.Project.Scans.Count) then
    168   with TDriveScan(Core.Project.Scans[Item.Index]) do begin
     184  with Core.Project do
     185  if (Item.Index >= 0) and (Item.Index < Scans.Count) then
     186  with TDriveScan(Scans[Item.Index]) do begin
    169187    Item.Caption := IntToStr(Item.Index);
     188    Item.Data := TDriveScan(Scans[Item.Index]);
    170189    Item.SubItems.Add(DateTimeToStr(TimeStart));
    171190    Item.SubItems.Add(DateTimeToStr(TimeEnd));
     
    175194end;
    176195
     196procedure TFormMain.ListView1SelectItem(Sender: TObject; Item: TListItem;
     197  Selected: Boolean);
     198begin
     199  Core.Project.CurrentScan := TDriveScan(Item.Data);
     200  Redraw;
     201  ReloadOperationList;
     202end;
     203
    177204procedure TFormMain.FormCreate(Sender: TObject);
    178205begin
    179206  PrefixMultiplier := TPrefixMultiplier.Create;
    180   XMLConfig1.Filename := 'config.xml';
    181207end;
    182208
     
    187213    UpdateInterface;
    188214  end;
     215end;
     216
     217procedure TFormMain.AViewToolbarExecute(Sender: TObject);
     218begin
     219  ShowToolBar := not ShowToolBar;
     220  ToolBar1.Visible := ShowToolBar;
     221  AViewToolbar.Checked := ShowToolBar;
    189222end;
    190223
     
    255288  Core.Project.Modified := False;
    256289  Core.Project.Scans.Add(TDriveScan.Create);
     290  Core.Project.CurrentScan := TDriveScan(Core.Project.Scans.Last);
    257291
    258292  ComboBoxDrive.ItemIndex := Core.DriveList.IndexOf(Core.DriveList.FindByModel(Core.Project.DriveInfo.Model));
     
    300334end;
    301335
     336procedure TFormMain.AOperationAddExecute(Sender: TObject);
     337var
     338  NewOperation: TDriveScan;
     339begin
     340  with Core.Project do begin
     341    NewOperation := TDriveScan.Create;
     342    Scans.Add(NewOperation);
     343    CurrentScan := TDriveScan(Scans.Last);
     344    ReloadOperationList;
     345    Redraw;
     346    Core.Project.Modified := True;
     347  end;
     348end;
     349
    302350procedure TFormMain.AOperationOptionsExecute(Sender: TObject);
    303351begin
     
    308356    UpdateInterface;
    309357  end;
     358end;
     359
     360procedure TFormMain.AOperationRemoveExecute(Sender: TObject);
     361begin
     362  Core.Project.CurrentScan := nil;
     363  Core.Project.Scans.Remove(ListView1.Selected.Data);
     364  ReloadOperationList;
     365  Redraw;
     366  Core.Project.Modified := True;
    310367end;
    311368
     
    347404procedure TFormMain.DoDraw;
    348405begin
    349   if Assigned(Core.Project) then
     406  if Assigned(Core.Project) and Assigned(Core.Project.CurrentScan) then
    350407  with Core.Project do begin
    351   if RedrawPending then
    352   with Image1 do begin
    353     if (Width <> Picture.Bitmap.Width) or (Height <> Picture.Bitmap.Height) then
    354       Picture.Bitmap.SetSize(Width, Height);
     408    if RedrawPending then
     409    with Image1 do begin
     410      if (Width <> Picture.Bitmap.Width) or (Height <> Picture.Bitmap.Height) then
     411        Picture.Bitmap.SetSize(Width, Height);
     412      try
     413        Core.Project.CurrentScan.Lock.Acquire;
     414        try
     415          Picture.Bitmap.BeginUpdate(True);
     416          CurrentScan.BlockMap.Draw(Picture.Bitmap.Canvas);
     417        finally
     418          Picture.Bitmap.EndUpdate;
     419        end;
     420        LabelSectorPerBlock.Caption := IntToStr(CurrentScan.BlockMap.SectorPerBlock);
     421        LabelBlockCurrent.Caption := IntToStr(CurrentScan.SectorCurrent);
     422        LabelBlockDamaged.Caption := IntToStr(CurrentScan.DamagedBlockCount);
     423      finally
     424        CurrentScan.Lock.Release;
     425      end;
     426      RedrawPending := False;
     427    end;
    355428    try
    356       Core.Project.CurrentScan.Lock.Acquire;
    357       try
    358         Picture.Bitmap.BeginUpdate(True);
    359         CurrentScan.BlockMap.Draw(Picture.Bitmap.Canvas);
    360       finally
    361         Picture.Bitmap.EndUpdate;
     429      CurrentScan.Lock.Acquire;
     430      if not CurrentScan.Terminated then begin
     431        LabelElapsedTime.Caption := TimeToStr(CurrentScan.GetElapsedTime);
     432        LabelEstimatedTime.Caption := TimeToStr((Now - CurrentScan.TimeStart) /
     433          CurrentScan.SectorCurrent * (CurrentScan.BlockMap.SectorCount - CurrentScan.SectorCurrent));
     434        LabelIOSpeed.Caption := PrefixMultiplier.Add((CurrentScan.SectorCurrent - LastBlockPos) *
     435          CurrentScan.SectorSize / (Timer1.Interval / 1000), BasePrefixMultipliers, 'B/s');
     436        LastBlockPos := CurrentScan.SectorCurrent;
     437      end else begin
     438        LabelElapsedTime.Caption := '';
     439        LabelEstimatedTime.Caption := '';
     440        LabelIOSpeed.Caption := '';
    362441      end;
    363       LabelSectorPerBlock.Caption := IntToStr(CurrentScan.BlockMap.SectorPerBlock);
    364       LabelBlockCurrent.Caption := IntToStr(CurrentScan.SectorCurrent);
    365       LabelBlockDamaged.Caption := IntToStr(CurrentScan.DamagedBlockCount);
    366442    finally
    367443      CurrentScan.Lock.Release;
    368444    end;
    369     RedrawPending := False;
    370   end;
    371   try
    372     CurrentScan.Lock.Acquire;
    373     if not CurrentScan.Terminated then begin
    374       LabelElapsedTime.Caption := TimeToStr(CurrentScan.GetElapsedTime);
    375       LabelEstimatedTime.Caption := TimeToStr((Now - CurrentScan.TimeStart) /
    376         CurrentScan.SectorCurrent * (CurrentScan.BlockMap.SectorCount - CurrentScan.SectorCurrent));
    377       LabelIOSpeed.Caption := PrefixMultiplier.Add((CurrentScan.SectorCurrent - LastBlockPos) *
    378         CurrentScan.SectorSize / (Timer1.Interval / 1000), BasePrefixMultipliers, 'B/s');
    379       LastBlockPos := CurrentScan.SectorCurrent;
    380     end else begin
    381       LabelElapsedTime.Caption := '';
    382       LabelEstimatedTime.Caption := '';
    383       LabelIOSpeed.Caption := '';
    384     end;
    385   finally
    386     CurrentScan.Lock.Release;
    387   end;
    388445  end else
    389446  with Image1 do begin
     
    445502procedure TFormMain.SaveConfig;
    446503begin
    447   XMLConfig1.SetValue('DriveName', LastDriveName);
    448   LastOpenedList1.SaveToXMLConfig(XMLConfig1, 'RecentProjects');
     504  Core.XMLConfig1.SetValue('DriveName', LastDriveName);
     505  LastOpenedList1.SaveToXMLConfig(Core.XMLConfig1, 'RecentProjects');
     506  Core.XMLConfig1.SetValue('ShowToolBar', ShowToolBar);
    449507end;
    450508
    451509procedure TFormMain.LoadConfig;
    452510begin
    453   LastDriveName := XMLConfig1.GetValue('DriveName', '');
    454   LastOpenedList1.LoadFromXMLConfig(XMLConfig1, 'RecentProjects');
     511  LastDriveName := Core.XMLConfig1.GetValue('DriveName', '');
     512  LastOpenedList1.LoadFromXMLConfig(Core.XMLConfig1, 'RecentProjects');
     513  ShowToolBar := Core.XMLConfig1.GetValue('ShowToolBar', False);
     514  ToolBar1.Visible := ShowToolBar;
     515  AViewToolbar.Checked := ShowToolBar;
    455516end;
    456517
     
    473534  end;
    474535  ListView1.Refresh;
     536
     537  AOperationRemove.Enabled := Assigned(ListView1.Selected);
    475538end;
    476539
Note: See TracChangeset for help on using the changeset viewer.