Changeset 10 for trunk


Ignore:
Timestamp:
Apr 2, 2016, 12:02:59 AM (9 years ago)
Author:
chronos
Message:
  • Added support for continue previous stopped scan.
  • Modified: Allow to scan only part of drive by specifiing start and end sector.
  • Added: Table showing list of operations in project.
  • Added: Allow to create new project and close project.
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/CoolDisk.lpi

    r8 r10  
    8383      </Item5>
    8484    </RequiredPackages>
    85     <Units Count="8">
     85    <Units Count="9">
    8686      <Unit0>
    8787        <Filename Value="CoolDisk.lpr"/>
     
    106106        <IsPartOfProject Value="True"/>
    107107        <ComponentName Value="FormProject"/>
     108        <HasResources Value="True"/>
    108109        <ResourceBaseClass Value="Form"/>
    109110      </Unit3>
     
    124125        <IsPartOfProject Value="True"/>
    125126      </Unit7>
     127      <Unit8>
     128        <Filename Value="Form/UFormOperation.pas"/>
     129        <IsPartOfProject Value="True"/>
     130        <ComponentName Value="FormOperation"/>
     131        <ResourceBaseClass Value="Form"/>
     132      </Unit8>
    126133    </Units>
    127134  </ProjectOptions>
  • trunk/CoolDisk.lpr

    r4 r10  
    99  Interfaces, // this includes the LCL widgetset
    1010  Forms, tachartlazaruspkg, UFormMain, UFormBenchmark, UFormProject, UProject,
    11   UConfig, UBlockMap, UDriveScan, Common, TemplateGenerics
     11  UConfig, UBlockMap, UDriveScan, Common, TemplateGenerics, UFormOperation
    1212  { you can add units after this };
    1313
     
    2020  Application.CreateForm(TFormBenchmark, FormBenchmark);
    2121  Application.CreateForm(TFormProject, FormProject);
     22  Application.CreateForm(TFormOperation, FormOperation);
    2223  Application.Run;
    2324end.
  • trunk/UBlockMap.pas

    r7 r10  
    182182      TChange(FChanges[ChangeIndex + 1]).Index := Index + 1;
    183183      TChange(FChanges[ChangeIndex + 1]).Value := Change.Value;
    184       if ChangeIndex = 0 then
     184      if ChangeIndex = 0 then begin
     185        TChange(FChanges[ChangeIndex]).Index := Index;
    185186        TChange(FChanges[ChangeIndex]).Value := AValue;
     187        FChanges.Insert(ChangeIndex, TChange.Create);
     188        TChange(FChanges[ChangeIndex]).Index := 0;
     189        TChange(FChanges[ChangeIndex]).Value := bsNone;
     190      end;
    186191    end else raise Exception.Create(SUnexpectedCombination);
    187192  end else raise Exception.Create(Format(SIndexOutOfRange, [Index]));
     
    202207  // Cut changes outside of max sector count
    203208  I := FChanges.Count - 1;
    204   while TChange(FChanges[I]).Index >= FSectorCount do Dec(I);
    205   if TChange(FChanges[I]).Index >= FSectorCount then FChanges.Count := I;
     209  while (I >= 0) and (TChange(FChanges[I]).Index >= FSectorCount) do Dec(I);
     210  if (I >= 0) and (TChange(FChanges[I]).Index >= FSectorCount) then FChanges.Count := I;
    206211
    207212  UpdateBlockSize;
     
    330335  I: Integer;
    331336begin
    332   WriteInteger(Node, 'SectorCount', SectorCount);
    333 
    334337  NewNode := Node.OwnerDocument.CreateElement('Changes');
    335338  Node.AppendChild(NewNode);
     
    348351  NewChange: TChange;
    349352begin
    350   SectorCount := ReadInteger(Node, 'SectorCount', 0);
    351 
    352353  NewNode := Node.FindNode('Changes');
    353354  if Assigned(NewNode) then begin
  • trunk/UDriveScan.pas

    r8 r10  
    2525  TDriveScan = class
    2626  private
     27    FDriveName: string;
    2728    FOnChange: TNotifyEvent;
    2829    FOnTerminate: TNotifyEvent;
     30    FSectorCurrent: Integer;
    2931    ScanThread: TScanThread;
    3032    procedure DoChange;
    3133    procedure DoTerminate;
     34    function GetSectorCount: Integer;
    3235    procedure Run;
     36    procedure SetDriveName(AValue: string);
     37    procedure SetSectorCount(AValue: Integer);
    3338  public
    3439    Lock: TCriticalSection;
    3540    BlockMap: TBlockMap;
    3641    SectorSize: Integer;
    37     SectorCurrent: Integer;
    3842    TimeStart: TDateTime;
    3943    TimeEnd: TDateTime;
    4044    Terminated: Boolean;
    4145    DamagedBlockCount: Integer;
    42     Drive: string;
    4346    Mode: TRunMode;
    4447    WritePattern: Byte;
     48    SectorStart: Integer;
     49    SectorEnd: Integer;
    4550    function GetElapsedTime: TDateTime;
     51    procedure CheckDrive;
     52    procedure Reset;
    4653    procedure Start;
    4754    procedure Stop;
     
    5057    procedure SaveToNode(Node: TDOMNode);
    5158    procedure LoadFromNode(Node: TDOMNode);
     59    property SectorCurrent: Integer read FSectorCurrent;
     60    property DriveName: string read FDriveName write SetDriveName;
    5261    property OnTerminate: TNotifyEvent read FOnTerminate write FOnTerminate;
    5362    property OnChange: TNotifyEvent read FOnChange write FOnChange;
     63    property SectorCount: Integer read GetSectorCount write SetSectorCount;
    5464  end;
    5565
     
    114124procedure TDriveScan.DoTerminate;
    115125begin
     126
    116127  if Assigned(FOnTerminate) then FOnTerminate(Self);
     128end;
     129
     130function TDriveScan.GetSectorCount: Integer;
     131begin
     132  Result := BlockMap.SectorCount;
    117133end;
    118134
     
    121137  if TimeEnd <> 0 then Result := TimeEnd - TimeStart
    122138    else Result := Now - TimeStart;
     139end;
     140
     141procedure TDriveScan.CheckDrive;
     142var
     143  F: TFileStream;
     144begin
     145  if FileExists(DriveName) then begin
     146    F := TFileStream.Create(DriveName, fmOpenRead);
     147    try
     148      BlockMap.SectorCount := F.Size div SectorSize;
     149    finally
     150      F.Free;
     151    end;
     152  end else BlockMap.SectorCount := 0;
     153end;
     154
     155procedure TDriveScan.Reset;
     156begin
     157  TimeStart := Now;
     158  DamagedBlockCount := 0;
     159  BlockMap.Clear;
     160  FSectorCurrent := SectorStart;
    123161end;
    124162
     
    138176  RealSize: Integer;
    139177  Buffer: array of Byte;
    140   I: Integer;
    141178begin
    142179  try
    143180  Lock.Acquire;
    144   TimeStart := Now;
    145181  Terminated := False;
    146   DamagedBlockCount := 0;
    147   if Mode = rmRead then F := TFileStream.Create(Drive, fmOpenRead)
    148     else if Mode = rmWrite then F := TFileStream.Create(Drive, fmOpenReadWrite);
    149   BlockMap.SectorCount := F.Size div SectorSize;
    150   BlockMap.Clear;
     182  if Mode = rmRead then F := TFileStream.Create(DriveName, fmOpenRead)
     183    else if Mode = rmWrite then F := TFileStream.Create(DriveName, fmOpenReadWrite);
     184  try
    151185  SetLength(Buffer, SectorSize);
    152186  if Mode = rmWrite then
    153187    FillChar(Buffer[0], Length(Buffer), WritePattern);
    154   for I := 0 to BlockMap.SectorCount - 1 do begin
    155     SectorCurrent := I;
     188  while FSectorCurrent < SectorEnd do begin
    156189    try
    157190      Lock.Release;
     
    163196        //Sleep(1);
    164197      end else begin
    165         F.Position := I * SectorSize;
     198        F.Position := FSectorCurrent * SectorSize;
    166199        if Mode = rmRead then RealSize := F.Read(Buffer[0], SectorSize)
    167200          else if Mode = rmWrite then RealSize := F.Write(Buffer[0], SectorSize)
     
    172205    end;
    173206    if RealSize <> SectorSize then begin
    174       BlockMap.Sectors[I] := bsDamaged;
     207      BlockMap.Sectors[FSectorCurrent] := bsDamaged;
    175208      Inc(DamagedBlockCount);
    176     end else BlockMap.Sectors[I] := bsOk;
     209    end else BlockMap.Sectors[FSectorCurrent] := bsOk;
     210    Inc(FSectorCurrent);
    177211    if Terminated then Break;
    178212  end;
    179   F.Free;
    180 
     213  finally
     214    F.Free;
     215  end;
    181216  finally
    182217    Lock.Release;
     
    185220  DoChange;
    186221  Terminated := True;
    187   DoTerminate;
     222  ScanThread.Synchronize(DoTerminate);
     223end;
     224
     225procedure TDriveScan.SetDriveName(AValue: string);
     226begin
     227  if FDriveName = AValue then Exit;
     228  FDriveName := AValue;
     229  CheckDrive;
     230end;
     231
     232procedure TDriveScan.SetSectorCount(AValue: Integer);
     233begin
     234  if BlockMap.SectorCount = AValue then Exit;
     235  BlockMap.SectorCount := AValue;
    188236end;
    189237
     
    204252  SectorSize := 4096;
    205253  Terminated := True;
     254  Reset;
    206255end;
    207256
     
    221270    WriteInteger(Node, 'DamagedBlockCount', DamagedBlockCount);
    222271    WriteInteger(Node, 'WritePattern', WritePattern);
    223     WriteString(Node, 'DriveName', Drive);
     272    WriteString(Node, 'DriveName', DriveName);
    224273    WriteDateTime(Node, 'TimeStart', TimeStart);
    225274    WriteDateTime(Node, 'TimeEnd', TimeEnd);
     275    WriteInteger(Node, 'SectorStart', SectorStart);
     276    WriteInteger(Node, 'SectorEnd', SectorEnd);
     277    WriteInteger(Node, 'SectorCurrent', FSectorCurrent);
    226278
    227279    NewNode := OwnerDocument.CreateElement('SectorMap');
     
    238290    DamagedBlockCount := ReadInteger(Node, 'DamagedBlockCount', 0);
    239291    WritePattern := ReadInteger(Node, 'WritePattern', 0);
    240     Drive := ReadString(Node, 'DriveName', '');
     292    DriveName := ReadString(Node, 'DriveName', '');
    241293    TimeStart := ReadDateTime(Node, 'TimeStart', 0);
    242294    TimeEnd := ReadDateTime(Node, 'TimeEnd', 0);
     295    FSectorCurrent := ReadInteger(Node, 'SectorCurrent', 0);
     296    SectorStart := ReadInteger(Node, 'SectorStart', 0);
     297    SectorEnd := ReadInteger(Node, 'SectorEnd', SectorCount - 1);
    243298
    244299    NewNode := FindNode('SectorMap');
  • trunk/UFormMain.lfm

    r9 r10  
    1313  OnShow = FormShow
    1414  LCLVersion = '1.7'
    15   object ListView1: TListView
    16     Left = 16
    17     Height = 390
    18     Top = 136
    19     Width = 552
    20     Columns = <   
    21       item
    22       end   
    23       item
    24         Width = 482
    25       end>
    26     TabOrder = 0
    27   end
    2815  object ButtonScan: TButton
    2916    Left = 120
     
    3219    Width = 75
    3320    Action = AScanStart
    34     TabOrder = 1
     21    TabOrder = 0
    3522  end
    3623  object Image1: TImage
     
    175162    Top = 56
    176163    Width = 93
    177     Action = AScanOptions
    178     TabOrder = 2
     164    Action = AProjectOptions
     165    TabOrder = 1
    179166  end
    180167  object ButtonScan2: TButton
     
    184171    Width = 75
    185172    Action = AScanStop
    186     TabOrder = 3
     173    TabOrder = 2
    187174  end
    188175  object Button1: TButton
     
    192179    Width = 91
    193180    Action = ABrowseDisk
    194     TabOrder = 4
     181    TabOrder = 3
    195182  end
    196183  object EditDrive: TEdit
     
    199186    Top = 8
    200187    Width = 448
    201     TabOrder = 5
    202   end
    203   object ComboBoxRunMode: TComboBox
    204     Left = 17
    205     Height = 34
    206     Top = 88
    207     Width = 247
    208     ItemHeight = 0
    209     ItemIndex = 0
    210     Items.Strings = (
    211       'Read test'
    212       'Write test'
    213     )
    214     Style = csDropDownList
    215     TabOrder = 6
    216     Text = 'Read test'
    217   end
    218   object Label9: TLabel
    219     Left = 286
    220     Height = 24
    221     Top = 95
    222     Width = 121
    223     Caption = 'Data pattern:'
    224     ParentColor = False
    225   end
    226   object EditPattern: TEdit
    227     Left = 440
    228     Height = 34
    229     Top = 88
    230     Width = 80
    231     TabOrder = 7
    232     Text = '0xff'
     188    TabOrder = 4
    233189  end
    234190  object Label10: TLabel
     
    247203    Caption = '  '
    248204    ParentColor = False
     205  end
     206  object Button2: TButton
     207    Left = 286
     208    Height = 25
     209    Top = 56
     210    Width = 107
     211    Action = AScanContinue
     212    TabOrder = 5
     213  end
     214  object ListView1: TListView
     215    Left = 17
     216    Height = 414
     217    Top = 168
     218    Width = 567
     219    Columns = <   
     220      item
     221        Caption = 'Name'
     222      end   
     223      item
     224        Caption = 'Time start'
     225      end   
     226      item
     227        Caption = 'Time end'
     228      end   
     229      item
     230        Caption = 'First sector'
     231      end   
     232      item
     233        Caption = 'Last sector'
     234        Width = 347
     235      end>
     236    OwnerData = True
     237    ReadOnly = True
     238    RowSelect = True
     239    TabOrder = 6
     240    ViewStyle = vsReport
     241    OnData = ListView1Data
     242  end
     243  object Label11: TLabel
     244    Left = 17
     245    Height = 24
     246    Top = 141
     247    Width = 107
     248    Caption = 'Operations:'
     249    ParentColor = False
     250  end
     251  object Button3: TButton
     252    Left = 16
     253    Height = 25
     254    Top = 96
     255    Width = 187
     256    Action = AOperationOptions
     257    Caption = 'Options options'
     258    TabOrder = 7
    249259  end
    250260  object Timer1: TTimer
     
    265275      OnExecute = AScanStopExecute
    266276    end
    267     object AScanOptions: TAction
     277    object AProjectOptions: TAction
    268278      Caption = 'Options'
    269       OnExecute = AScanOptionsExecute
     279      OnExecute = AProjectOptionsExecute
    270280    end
    271281    object ABrowseDisk: TAction
     
    282292    end
    283293    object AFileOpen: TAction
    284       Caption = 'Open'
     294      Caption = 'Open...'
    285295      OnExecute = AFileOpenExecute
    286296    end
     
    289299      OnExecute = AFileSaveExecute
    290300    end
     301    object AScanContinue: TAction
     302      Caption = 'Continue'
     303      OnExecute = AScanContinueExecute
     304    end
     305    object AFileNew: TAction
     306      Caption = 'New'
     307      OnExecute = AFileNewExecute
     308    end
     309    object AFileClose: TAction
     310      Caption = 'Close'
     311      OnExecute = AFileCloseExecute
     312    end
     313    object AOperationOptions: TAction
     314      Caption = 'Options'
     315      OnExecute = AOperationOptionsExecute
     316    end
    291317  end
    292318  object OpenDialog1: TOpenDialog
     
    303329    object MenuItem1: TMenuItem
    304330      Caption = 'File'
     331      object MenuItem10: TMenuItem
     332        Action = AFileNew
     333      end
    305334      object MenuItem2: TMenuItem
    306335        Action = AFileOpen
     
    311340      object MenuItem3: TMenuItem
    312341        Action = AFileSaveAs
     342      end
     343      object MenuItem11: TMenuItem
     344        Action = AFileClose
     345      end
     346      object MenuItem15: TMenuItem
     347        Action = AProjectOptions
     348      end
     349      object MenuItem12: TMenuItem
     350        Caption = '-'
    313351      end
    314352      object MenuItem4: TMenuItem
     
    324362        Action = AScanStop
    325363      end
     364      object MenuItem13: TMenuItem
     365        Action = AScanContinue
     366      end
     367      object MenuItem14: TMenuItem
     368        Caption = '-'
     369      end
    326370      object MenuItem8: TMenuItem
    327         Action = AScanOptions
     371        Action = AOperationOptions
    328372      end
    329373    end
  • trunk/UFormMain.pas

    r9 r10  
    1515  TFormMain = class(TForm)
    1616    ABrowseDisk: TAction;
     17    AOperationOptions: TAction;
     18    AFileClose: TAction;
     19    AFileNew: TAction;
     20    AScanContinue: TAction;
    1721    AFileSave: TAction;
    1822    AFileOpen: TAction;
    1923    AFileSaveAs: TAction;
    2024    AExit: TAction;
    21     AScanOptions: TAction;
     25    AProjectOptions: TAction;
    2226    AScanStart: TAction;
    2327    AScanStop: TAction;
    2428    ActionList1: TActionList;
    2529    Button1: TButton;
     30    Button2: TButton;
     31    Button3: TButton;
    2632    ButtonScan: TButton;
    2733    ButtonScan1: TButton;
    2834    ButtonScan2: TButton;
    29     ComboBoxRunMode: TComboBox;
    30     EditPattern: TEdit;
    3135    EditDrive: TEdit;
    3236    Image1: TImage;
    3337    Label1: TLabel;
    3438    Label10: TLabel;
     39    Label11: TLabel;
    3540    Label2: TLabel;
    3641    Label3: TLabel;
     
    4045    Label7: TLabel;
    4146    Label8: TLabel;
    42     Label9: TLabel;
    4347    LabelElapsedTime: TLabel;
    4448    LabelBlockSize: TLabel;
     
    5357    MainMenu1: TMainMenu;
    5458    MenuItem1: TMenuItem;
     59    MenuItem10: TMenuItem;
     60    MenuItem11: TMenuItem;
     61    MenuItem12: TMenuItem;
     62    MenuItem13: TMenuItem;
     63    MenuItem14: TMenuItem;
     64    MenuItem15: TMenuItem;
    5565    MenuItem2: TMenuItem;
    5666    MenuItem3: TMenuItem;
     
    6777    procedure ABrowseDiskExecute(Sender: TObject);
    6878    procedure AExitExecute(Sender: TObject);
     79    procedure AFileCloseExecute(Sender: TObject);
     80    procedure AFileNewExecute(Sender: TObject);
    6981    procedure AFileOpenExecute(Sender: TObject);
    7082    procedure AFileSaveAsExecute(Sender: TObject);
    7183    procedure AFileSaveExecute(Sender: TObject);
    72     procedure AScanOptionsExecute(Sender: TObject);
     84    procedure AOperationOptionsExecute(Sender: TObject);
     85    procedure AProjectOptionsExecute(Sender: TObject);
     86    procedure AScanContinueExecute(Sender: TObject);
    7387    procedure AScanStartExecute(Sender: TObject);
    7488    procedure AScanStopExecute(Sender: TObject);
     
    7892    procedure FormShow(Sender: TObject);
    7993    procedure Image1Resize(Sender: TObject);
     94    procedure ListView1Data(Sender: TObject; Item: TListItem);
    8095    procedure Timer1Timer(Sender: TObject);
    8196  private
     
    8499    RedrawPending: Boolean;
    85100    LastProjectFileName: string;
     101    procedure ReloadOperationList;
     102    procedure CheckDrive;
    86103    procedure ProjectOpen(FileName: string);
    87104    procedure DriveScanChange(Sender: TObject);
     
    107124
    108125uses
    109   UFormProject;
     126  UFormProject, UFormOperation;
    110127
    111128resourcestring
    112129  SProjectModified = '(modified)';
     130  SNewProject = 'New project';
     131  SSelectDriveForScan = 'Select drive for scan';
     132  SOpenStoredProject = 'Open stored scan project';
     133  SSaveProject = 'Save scan project';
     134  SBytes = 'bytes';
     135
     136const
     137  DefaultDriveName = '/dev/sda';
    113138
    114139{ TFormMain }
     
    120145    ProjectOpen(LastProjectFileName)
    121146  else begin
     147    AFileNew.Execute;
    122148    Redraw;
    123149    UpdateInterface;
     
    130156end;
    131157
     158procedure TFormMain.ListView1Data(Sender: TObject; Item: TListItem);
     159begin
     160  if (Item.Index >= 0) and (Item.Index < Project.Scans.Count) then
     161  with TDriveScan(Project.Scans[Item.Index]) do begin
     162    Item.Caption := IntToStr(Item.Index);
     163    Item.SubItems.Add(DateTimeToStr(TimeStart));
     164    Item.SubItems.Add(DateTimeToStr(TimeEnd));
     165    Item.SubItems.Add(IntToStr(SectorStart));
     166    Item.SubItems.Add(IntToStr(SectorEnd));
     167  end;
     168end;
     169
    132170procedure TFormMain.FormCreate(Sender: TObject);
    133171begin
    134172  PrefixMultiplier := TPrefixMultiplier.Create;
    135   Project := TProject.Create;
    136   Project.Scans.Add(TDriveScan.Create);
    137   DriveScan := TDriveScan(Project.Scans[0]);
     173  EditDrive.Text := DefaultDriveName;
     174  XMLConfig1.Filename := 'config.xml';
     175  Project := nil;
     176end;
     177
     178procedure TFormMain.AScanStopExecute(Sender: TObject);
     179begin
     180  DriveScan.Stop;
     181  UpdateInterface;
     182end;
     183
     184procedure TFormMain.AScanStartExecute(Sender: TObject);
     185begin
     186  LastBlockPos := 0;
     187  DriveScan.DriveName := EditDrive.Text;
     188  DriveScan.Reset;
     189  DriveScan.SectorSize := Project.SectorSize;
    138190  DriveScan.OnChange := DriveScanChange;
    139191  DriveScan.OnTerminate := DriveScanTerminate;
    140   EditDrive.Text := '/dev/sdb';
    141   XMLConfig1.Filename := 'config.xml';
    142 end;
    143 
    144 procedure TFormMain.AScanStopExecute(Sender: TObject);
    145 begin
    146   DriveScan.Stop;
    147   UpdateInterface;
    148 end;
    149 
    150 procedure TFormMain.AScanStartExecute(Sender: TObject);
    151 begin
    152   LastBlockPos := 0;
    153   DriveScan.Drive := EditDrive.Text;
    154   DriveScan.SectorSize := Project.SectorSize;
    155   DriveScan.Mode := TRunMode(ComboBoxRunMode.ItemIndex);
    156   DriveScan.WritePattern := StrToInt(EditPattern.Text);
    157192  DriveScan.Start;
    158193  Project.Modified := True;
     
    160195end;
    161196
    162 procedure TFormMain.AScanOptionsExecute(Sender: TObject);
    163 begin
     197procedure TFormMain.AProjectOptionsExecute(Sender: TObject);
     198begin
     199  CheckDrive;
    164200  FormProject.Load(Project);
    165201  if FormProject.ShowModal = mrOk then begin
    166202    FormProject.Save(Project);
    167   end;
     203    Project.Modified := True;
     204    UpdateInterface;
     205  end;
     206end;
     207
     208procedure TFormMain.AScanContinueExecute(Sender: TObject);
     209begin
     210  DriveScan.Start;
     211  Project.Modified := True;
     212  UpdateInterface;
    168213end;
    169214
    170215procedure TFormMain.ABrowseDiskExecute(Sender: TObject);
    171216begin
    172   OpenDialog1.Title := 'Select drive for scan';
     217  OpenDialog1.Title := SSelectDriveForScan;
    173218  OpenDialog1.DefaultExt := '';
    174219  OpenDialog1.FileName := EditDrive.Text;
     
    182227end;
    183228
     229procedure TFormMain.AFileCloseExecute(Sender: TObject);
     230begin
     231  DriveScan := nil;
     232  FreeAndNil(Project);
     233  UpdateInterface;
     234end;
     235
     236procedure TFormMain.AFileNewExecute(Sender: TObject);
     237begin
     238  AFileClose.Execute;
     239  Project := TProject.Create;
     240  Project.FileName := SNewProject;
     241  Project.Modified := False;
     242  Project.Scans.Add(TDriveScan.Create);
     243  DriveScan := TDriveScan(Project.Scans[0]);
     244
     245  CheckDrive;
     246  DriveScan.SectorStart := 0;
     247  DriveScan.SectorEnd := DriveScan.SectorCount - 1;
     248  DriveScan.Reset;
     249  Redraw;
     250  UpdateInterface;
     251end;
     252
    184253procedure TFormMain.AFileOpenExecute(Sender: TObject);
    185254begin
    186   OpenDialog1.Title := 'Open stored scan project';
     255  OpenDialog1.Title := SOpenStoredProject;
    187256  OpenDialog1.DefaultExt := '.cdp';
     257  if Assigned(Project) then
     258    OpenDialog1.FileName := Project.FileName;
    188259  if OpenDialog1.Execute then begin
    189260    ProjectOpen(OpenDialog1.FileName);
     
    193264procedure TFormMain.AFileSaveAsExecute(Sender: TObject);
    194265begin
    195   SaveDialog1.Title := 'Save scan project';
     266  SaveDialog1.Title := SSaveProject;
    196267  SaveDialog1.DefaultExt := '.cdp';
     268  SaveDialog1.FileName := Project.FileName;
    197269  if SaveDialog1.Execute then begin
    198270    Project.SaveToFile(SaveDialog1.FileName);
     271    UpdateInterface;
    199272  end;
    200273end;
     
    204277  if not FileExists(Project.FileName) then
    205278    AFileSaveAs.Execute
    206     else Project.SaveToFile(Project.FileName);
     279    else begin
     280      Project.SaveToFile(Project.FileName);
     281      UpdateInterface;
     282    end;
     283end;
     284
     285procedure TFormMain.AOperationOptionsExecute(Sender: TObject);
     286begin
     287  FormOperation.Load(DriveScan);
     288  if FormOperation.ShowModal = mrOk then begin
     289    FormOperation.Save(DriveScan);
     290    Project.Modified := True;
     291    UpdateInterface;
     292  end;
    207293end;
    208294
    209295procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    210296begin
     297  AFileClose.Execute;
    211298  SaveConfig;
    212299end;
     
    215302begin
    216303  Timer1.Enabled := False;
    217   FreeAndNil(Project);
     304  if Assigned(Project) then FreeAndNil(Project);
    218305  FreeAndNil(PrefixMultiplier);
    219306end;
     
    227314procedure TFormMain.DoDraw;
    228315begin
     316  if Assigned(Project) then begin
    229317  if RedrawPending then
    230318  with Image1 do begin
     
    240328      end;
    241329      LabelSize.Caption := PrefixMultiplier.Add(DriveScan.BlockMap.SectorCount * DriveScan.SectorSize,
    242         BasePrefixMultipliers, 'bytes');
     330        BasePrefixMultipliers, SBytes);
    243331      LabelSectorPerBlock.Caption := IntToStr(DriveScan.BlockMap.SectorPerBlock);
    244       LabelBlockSize.Caption := IntToStr(DriveScan.SectorSize) + ' bytes';
     332      LabelBlockSize.Caption := IntToStr(DriveScan.SectorSize) + ' ' + SBytes;
    245333      LabelBlockCount.Caption := IntToStr(DriveScan.BlockMap.SectorCount);
    246334      LabelBlockCurrent.Caption := IntToStr(DriveScan.SectorCurrent);
     
    268356    DriveScan.Lock.Release;
    269357  end;
     358  end else
     359  with Image1 do begin
     360    if (Width <> Picture.Bitmap.Width) or (Height <> Picture.Bitmap.Height) then
     361      Picture.Bitmap.SetSize(Width, Height);
     362    with Picture.Bitmap.Canvas do begin
     363      Brush.Style := bsSolid;
     364      Brush.Color := clSilver;
     365      FillRect(0, 0, Width, Height);
     366    end;
     367  end;
    270368end;
    271369
     
    277375    AScanStart.Enabled := DriveScan.Terminated = True;
    278376    AScanStop.Enabled := DriveScan.Terminated = False;
     377    AScanContinue.Enabled := (DriveScan.Terminated = True) and (DriveScan.SectorCurrent > DriveScan.SectorStart) and
     378      (DriveScan.SectorCurrent < DriveScan.SectorEnd);
    279379  end;
    280380  AFileSave.Enabled := Assigned(Project) and Project.Modified;
    281381  AFileSaveAs.Enabled := Assigned(Project);
     382  AFileClose.Enabled := Assigned(Project);
     383  ReloadOperationList;
    282384
    283385  Title := '';
     
    298400procedure TFormMain.LoadConfig;
    299401begin
    300   EditDrive.Text := XMLConfig1.GetValue('DriveName', '/dev/sda');
     402  EditDrive.Text := XMLConfig1.GetValue('DriveName', DefaultDriveName);
    301403  LastProjectFileName := XMLConfig1.GetValue('LastProjectFileName', '');
    302404end;
     
    307409end;
    308410
     411procedure TFormMain.ReloadOperationList;
     412begin
     413  if Assigned(Project) then begin
     414    ListView1.Items.Count := Project.Scans.Count;
     415  end else begin
     416    ListView1.Items.Count := 0;
     417  end;
     418  ListView1.Refresh;
     419end;
     420
     421procedure TFormMain.CheckDrive;
     422begin
     423  DriveScan.CheckDrive;
     424  Project.SectorCount := DriveScan.SectorCount;
     425end;
     426
    309427procedure TFormMain.ProjectOpen(FileName: string);
    310428begin
     429  AFileNew.Execute;
    311430  Project.LoadFromFile(FileName);
    312431  LastProjectFileName := FileName;
  • trunk/UFormProject.lfm

    r1 r10  
    44  Top = 492
    55  Width = 461
    6   Caption = 'FormProject'
     6  Caption = 'Project settings'
    77  ClientHeight = 340
    88  ClientWidth = 461
    9   LCLVersion = '1.6.0.4'
     9  LCLVersion = '1.7'
    1010  object SpinEditSectorSize: TSpinEdit
    11     Left = 184
     11    Left = 192
    1212    Height = 34
    13     Top = 16
    14     Width = 138
     13    Top = 56
     14    Width = 101
    1515    MaxValue = 100000
    1616    MinValue = 1
     
    2121    Left = 16
    2222    Height = 24
    23     Top = 16
     23    Top = 64
    2424    Width = 101
    2525    Caption = 'Sector size:'
     
    4444    TabOrder = 2
    4545  end
    46   object SpinEditFirstSector: TSpinEdit
    47     Left = 184
     46  object Edit1: TEdit
     47    Left = 192
    4848    Height = 34
    49     Top = 56
    50     Width = 138
    51     MaxValue = 100000
    52     MinValue = 1
     49    Top = 8
     50    Width = 240
    5351    TabOrder = 3
    54     Value = 1
     52    Text = 'Edit1'
    5553  end
    5654  object Label2: TLabel
    5755    Left = 16
    5856    Height = 24
    59     Top = 56
    60     Width = 105
    61     Caption = 'First sector:'
    62     ParentColor = False
    63   end
    64   object SpinEditLastSector: TSpinEdit
    65     Left = 184
    66     Height = 34
    67     Top = 96
    68     Width = 138
    69     MaxValue = 100000
    70     MinValue = 1
    71     TabOrder = 4
    72     Value = 1
    73   end
    74   object Label3: TLabel
    75     Left = 16
    76     Height = 24
    77     Top = 96
    78     Width = 81
    79     Caption = 'Last size:'
     57    Top = 16
     58    Width = 60
     59    Caption = 'Name:'
    8060    ParentColor = False
    8161  end
  • trunk/UFormProject.pas

    r1 r10  
    1616    Button1: TButton;
    1717    Button2: TButton;
     18    Edit1: TEdit;
    1819    Label1: TLabel;
    1920    Label2: TLabel;
    20     Label3: TLabel;
    2121    SpinEditSectorSize: TSpinEdit;
    22     SpinEditFirstSector: TSpinEdit;
    23     SpinEditLastSector: TSpinEdit;
    2422  private
    25     { private declarations }
    2623  public
    2724    procedure Load(Project: TProject);
     
    4037procedure TFormProject.Load(Project: TProject);
    4138begin
     39  Edit1.Text := Project.Name;
    4240  SpinEditSectorSize.Value := Project.SectorSize;
    43   SpinEditFirstSector.Value := Project.FirstSector;
    44   SpinEditLastSector.Value := Project.LastSector;
    4541end;
    4642
    4743procedure TFormProject.Save(Project: TProject);
    4844begin
     45  Project.Name := Edit1.Text;
    4946  Project.SectorSize := SpinEditSectorSize.Value;
    50   Project.FirstSector := SpinEditFirstSector.Value;
    51   Project.LastSector := SpinEditLastSector.Value;
    5247end;
    5348
  • trunk/UProject.pas

    r9 r10  
    1515    Name: string;
    1616    FileName: string;
    17     FirstSector: Integer;
    18     LastSector: Integer;
    1917    SectorSize: Integer;
    2018    SectorCount: Integer;
    2119    Modified: Boolean;
    2220    Scans: TDriveScanList;
     21    DriveName: string;
    2322    constructor Create;
    2423    destructor Destroy; override;
     
    6160    with RootNode do begin
    6261      WriteInteger(RootNode, 'SectorSize', SectorSize);
     62      WriteInteger(RootNode, 'SectorCount', SectorCount);
     63      WriteString(RootNode, 'DriveName', DriveName);
    6364
    6465      NewNode := OwnerDocument.CreateElement('Scans');
     
    8990    with RootNode do begin
    9091      SectorSize := ReadInteger(RootNode, 'SectorSize', 4096);
     92      SectorCount := ReadInteger(RootNode, 'SectorCount', 0);
     93      DriveName := ReadString(RootNode, 'DriveName', '');
    9194
    9295      NewNode := FindNode('Scans');
Note: See TracChangeset for help on using the changeset viewer.