Changeset 13


Ignore:
Timestamp:
Apr 2, 2016, 1:06:34 PM (9 years ago)
Author:
chronos
Message:
  • Modified: All drive dimensions are now stored in project file.
  • Added: Confirmation dialog for saving project on application exit.
  • Modified: ComboBox for selection of current drive now behaves correctly to update project parameters.
Location:
trunk
Files:
2 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/CoolDisk.lpi

    r12 r13  
    8383      </Item5>
    8484    </RequiredPackages>
    85     <Units Count="11">
     85    <Units Count="10">
    8686      <Unit0>
    8787        <Filename Value="CoolDisk.lpr"/>
     
    136136        <IsPartOfProject Value="True"/>
    137137      </Unit9>
    138       <Unit10>
    139         <Filename Value="Form/UFormDrive.pas"/>
    140         <IsPartOfProject Value="True"/>
    141         <ComponentName Value="FormDrive"/>
    142         <ResourceBaseClass Value="Form"/>
    143       </Unit10>
    144138    </Units>
    145139  </ProjectOptions>
  • trunk/CoolDisk.lpr

    r12 r13  
    1010  Forms, tachartlazaruspkg, UFormBenchmark, UProject,
    1111  UConfig, UBlockMap, UDriveScan, Common, TemplateGenerics, UFormOperation,
    12   UFormProject, UFormMain, UPhysDrive, UFormDrive
    13   { you can add units after this };
     12  UFormProject, UFormMain, UPhysDrive;
    1413
    1514{$R *.res}
     
    2221  Application.CreateForm(TFormOperation, FormOperation);
    2322  Application.CreateForm(TFormProject, FormProject);
    24   Application.CreateForm(TFormDrive, FormDrive);
    2523  Application.Run;
    2624end.
  • trunk/Form/UFormMain.lfm

    r12 r13  
    99  Menu = MainMenu1
    1010  OnClose = FormClose
     11  OnCloseQuery = FormCloseQuery
    1112  OnCreate = FormCreate
    1213  OnDestroy = FormDestroy
     
    1415  LCLVersion = '1.7'
    1516  object ButtonScan: TButton
    16     Left = 120
     17    Left = 16
    1718    Height = 25
    18     Top = 56
     19    Top = 104
    1920    Width = 75
    2021    Action = AScanStart
     
    2324  object Image1: TImage
    2425    Left = 592
    25     Height = 878
    26     Top = 10
     26    Height = 848
     27    Top = 40
    2728    Width = 1092
    2829    Anchors = [akTop, akLeft, akRight, akBottom]
     
    3738    ParentColor = False
    3839  end
    39   object LabelBlockSize: TLabel
     40  object LabelSectorSize: TLabel
    4041    Left = 256
    4142    Height = 24
     
    4546    ParentColor = False
    4647  end
    47   object LabelBlockCount: TLabel
     48  object LabelSectorCount: TLabel
    4849    Left = 256
    4950    Height = 24
     
    158159  end
    159160  object ButtonScan1: TButton
    160     Left = 17
     161    Left = 440
    161162    Height = 25
    162     Top = 56
    163     Width = 93
     163    Top = 48
     164    Width = 120
    164165    Action = AProjectOptions
    165166    TabOrder = 1
    166167  end
    167168  object ButtonScan2: TButton
    168     Left = 200
     169    Left = 104
    169170    Height = 25
    170     Top = 56
     171    Top = 104
    171172    Width = 75
    172173    Action = AScanStop
     
    190191  end
    191192  object Button2: TButton
    192     Left = 286
     193    Left = 192
    193194    Height = 25
    194     Top = 56
     195    Top = 104
    195196    Width = 107
    196197    Action = AScanContinue
     
    235236  end
    236237  object Button3: TButton
    237     Left = 16
     238    Left = 312
    238239    Height = 25
    239     Top = 96
    240     Width = 187
     240    Top = 104
     241    Width = 112
    241242    Action = AOperationOptions
    242     Caption = 'Options options'
    243243    TabOrder = 5
    244244  end
    245245  object ComboBoxDrive: TComboBox
    246     Left = 15
     246    Left = 8
    247247    Height = 38
    248     Top = 8
    249     Width = 464
     248    Top = 40
     249    Width = 416
    250250    ItemHeight = 0
    251251    OnChange = ComboBoxDriveChange
     
    253253    TabOrder = 6
    254254  end
     255  object ToolBar1: TToolBar
     256    Left = 0
     257    Height = 26
     258    Top = 0
     259    Width = 1703
     260    Caption = 'ToolBar1'
     261    Images = ImageList1
     262    TabOrder = 7
     263    object ToolButton1: TToolButton
     264      Left = 1
     265      Top = 2
     266      Action = AScanStart
     267    end
     268    object ToolButton2: TToolButton
     269      Left = 24
     270      Top = 2
     271      Action = AScanStop
     272    end
     273    object ToolButton3: TToolButton
     274      Left = 47
     275      Top = 2
     276      Action = AScanContinue
     277    end
     278  end
    255279  object Timer1: TTimer
    256280    Interval = 500
     
    274298      OnExecute = AProjectOptionsExecute
    275299    end
    276     object ABrowseDisk: TAction
     300    object ADriveSelect: TAction
    277301      Caption = 'Select...'
    278302    end
     
    319343  end
    320344  object MainMenu1: TMainMenu
     345    Images = ImageList1
    321346    left = 672
    322347    top = 504
     
    374399    top = 160
    375400  end
     401  object ImageList1: TImageList
     402    left = 672
     403    top = 573
     404  end
    376405end
  • trunk/Form/UFormMain.pas

    r12 r13  
    1414
    1515  TFormMain = class(TForm)
    16     ABrowseDisk: TAction;
     16    ADriveSelect: TAction;
    1717    AOperationOptions: TAction;
    1818    AFileClose: TAction;
     
    3434    ComboBoxDrive: TComboBox;
    3535    Image1: TImage;
     36    ImageList1: TImageList;
    3637    Label1: TLabel;
    3738    Label10: TLabel;
     
    4546    Label8: TLabel;
    4647    LabelElapsedTime: TLabel;
    47     LabelBlockSize: TLabel;
    48     LabelBlockCount: TLabel;
     48    LabelSectorSize: TLabel;
     49    LabelSectorCount: TLabel;
    4950    LabelBlockCurrent: TLabel;
    5051    LabelBlockDamaged: TLabel;
     
    7374    SaveDialog1: TSaveDialog;
    7475    Timer1: TTimer;
     76    ToolBar1: TToolBar;
     77    ToolButton1: TToolButton;
     78    ToolButton2: TToolButton;
     79    ToolButton3: TToolButton;
    7580    XMLConfig1: TXMLConfig;
    7681    procedure AExitExecute(Sender: TObject);
     
    8792    procedure ComboBoxDriveChange(Sender: TObject);
    8893    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     94    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
    8995    procedure FormCreate(Sender: TObject);
    9096    procedure FormDestroy(Sender: TObject);
     
    98104    RedrawPending: Boolean;
    99105    LastProjectFileName: string;
     106    LastDriveName: string;
    100107    procedure ReloadOperationList;
    101108    procedure ProjectOpen(FileName: string);
     
    107114  public
    108115    DriveList: TDriveList;
    109     DriveScan: TDriveScan;
    110116    Project: TProject;
    111117    procedure SaveConfig;
     
    126132
    127133resourcestring
    128   SProjectModified = '(modified)';
     134  SModifiedFlag = '(modified)';
    129135  SNewProject = 'New project';
    130136  SSelectDriveForScan = 'Select drive for scan';
     
    132138  SSaveProject = 'Save scan project';
    133139  SBytes = 'bytes';
     140  SProjectModified = 'Project modified';
     141  SProjectModifiedQuestion = 'Project was modified. Do you want to save it?';
    134142
    135143{ TFormMain }
     
    175183procedure TFormMain.AScanStopExecute(Sender: TObject);
    176184begin
    177   DriveScan.Stop;
    178   UpdateInterface;
     185  if Assigned(Project) and Assigned(Project.CurrentScan) then begin
     186    Project.CurrentScan.Stop;
     187    UpdateInterface;
     188  end;
    179189end;
    180190
    181191procedure TFormMain.ComboBoxDriveChange(Sender: TObject);
    182192begin
    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;
     193  if Project.DriveInfo.Path <> TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex]).Path then begin
     194    Project.DriveInfo.Assign(TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex]));
     195    Project.Modified := True;
     196    Project.CurrentScan.SectorCount := Project.DriveInfo.SectorCount;
     197    Project.CurrentScan.SectorSize := Project.DriveInfo.SectorSize;
     198    Project.CurrentScan.SectorStart := 0;
     199    Project.CurrentScan.SectorEnd := Project.CurrentScan.SectorCount - 1;
     200    Project.CurrentScan.Reset;
     201    UpdateInterface;
     202    Redraw;
     203  end;
    187204end;
    188205
     
    190207begin
    191208  LastBlockPos := 0;
    192   DriveScan.DriveName := TDriveInfo(DriveList[ComboBoxDrive.ItemIndex]).Path;
    193   DriveScan.Reset;
    194   DriveScan.SectorSize := Project.SectorSize;
    195   DriveScan.OnChange := DriveScanChange;
    196   DriveScan.OnTerminate := DriveScanTerminate;
    197   DriveScan.Start;
     209  Project.CurrentScan.DriveName := Project.DriveInfo.Path;
     210  Project.CurrentScan.SectorSize := Project.DriveInfo.SectorSize;
     211  Project.CurrentScan.Reset;
     212  Project.CurrentScan.OnChange := DriveScanChange;
     213  Project.CurrentScan.OnTerminate := DriveScanTerminate;
     214  Project.CurrentScan.Start;
    198215  Project.Modified := True;
    199216  UpdateInterface;
     
    212229procedure TFormMain.AScanContinueExecute(Sender: TObject);
    213230begin
    214   DriveScan.Start;
     231  Project.CurrentScan.Start;
    215232  Project.Modified := True;
    216233  UpdateInterface;
     
    224241procedure TFormMain.AFileCloseExecute(Sender: TObject);
    225242begin
    226   DriveScan := nil;
    227243  FreeAndNil(Project);
    228244  UpdateInterface;
     
    236252  Project.Modified := False;
    237253  Project.Scans.Add(TDriveScan.Create);
    238   DriveScan := TDriveScan(Project.Scans[0]);
    239 
    240   DriveScan.SectorStart := 0;
    241   DriveScan.SectorEnd := DriveScan.SectorCount - 1;
    242   DriveScan.Reset;
     254
     255  ComboBoxDrive.ItemIndex := DriveList.IndexOf(DriveList.FindByModel(Project.DriveInfo.Model));
     256  if (ComboBoxDrive.ItemIndex = -1) and (ComboBoxDrive.Items.Count > 0) then ComboBoxDrive.ItemIndex := 0;
     257  ComboBoxDriveChange(Self);
     258
    243259  Redraw;
    244260  UpdateInterface;
     
    279295procedure TFormMain.AOperationOptionsExecute(Sender: TObject);
    280296begin
    281   FormOperation.Load(DriveScan);
     297  FormOperation.Load(Project.CurrentScan);
    282298  if FormOperation.ShowModal = mrOk then begin
    283     FormOperation.Save(DriveScan);
     299    FormOperation.Save(Project.CurrentScan);
    284300    Project.Modified := True;
    285301    UpdateInterface;
     
    291307  AFileClose.Execute;
    292308  SaveConfig;
     309end;
     310
     311procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
     312var
     313  R: TModalResult;
     314begin
     315  if Assigned(Project) and Project.Modified then begin
     316    R := MessageDlg(SProjectModified, SProjectModifiedQuestion, mtConfirmation, [mbYes, mbNo, mbCancel], 0);
     317    if R = mrCancel then begin
     318      CanClose := False;
     319      Exit;
     320    end else
     321    if R = mrYes then begin
     322      AFileSave.Execute;
     323    end;
     324  end;
    293325end;
    294326
     
    315347      Picture.Bitmap.SetSize(Width, Height);
    316348    try
    317       DriveScan.Lock.Acquire;
     349      Project.CurrentScan.Lock.Acquire;
    318350      try
    319351        Picture.Bitmap.BeginUpdate(True);
    320         DriveScan.BlockMap.Draw(Picture.Bitmap.Canvas);
     352        Project.CurrentScan.BlockMap.Draw(Picture.Bitmap.Canvas);
    321353      finally
    322354        Picture.Bitmap.EndUpdate;
    323355      end;
    324       LabelSize.Caption := PrefixMultiplier.Add(DriveScan.BlockMap.SectorCount * DriveScan.SectorSize,
    325         BasePrefixMultipliers, SBytes);
    326       LabelSectorPerBlock.Caption := IntToStr(DriveScan.BlockMap.SectorPerBlock);
    327       LabelBlockSize.Caption := IntToStr(DriveScan.SectorSize) + ' ' + SBytes;
    328       LabelBlockCount.Caption := IntToStr(DriveScan.BlockMap.SectorCount);
    329       LabelBlockCurrent.Caption := IntToStr(DriveScan.SectorCurrent);
    330       LabelBlockDamaged.Caption := IntToStr(DriveScan.DamagedBlockCount);
     356      LabelSectorPerBlock.Caption := IntToStr(Project.CurrentScan.BlockMap.SectorPerBlock);
     357      LabelBlockCurrent.Caption := IntToStr(Project.CurrentScan.SectorCurrent);
     358      LabelBlockDamaged.Caption := IntToStr(Project.CurrentScan.DamagedBlockCount);
    331359    finally
    332       DriveScan.Lock.Release;
     360      Project.CurrentScan.Lock.Release;
    333361    end;
    334362    RedrawPending := False;
    335363  end;
    336364  try
    337     DriveScan.Lock.Acquire;
    338     if not DriveScan.Terminated then begin
    339       LabelElapsedTime.Caption := TimeToStr(DriveScan.GetElapsedTime);
    340       LabelEstimatedTime.Caption := TimeToStr((Now - DriveScan.TimeStart) /
    341         DriveScan.SectorCurrent * (DriveScan.BlockMap.SectorCount - DriveScan.SectorCurrent));
    342       LabelIOSpeed.Caption := PrefixMultiplier.Add((DriveScan.SectorCurrent - LastBlockPos) *
    343         DriveScan.SectorSize / (Timer1.Interval / 1000), BasePrefixMultipliers, 'B/s');
    344       LastBlockPos := DriveScan.SectorCurrent;
     365    Project.CurrentScan.Lock.Acquire;
     366    if not Project.CurrentScan.Terminated then begin
     367      LabelElapsedTime.Caption := TimeToStr(Project.CurrentScan.GetElapsedTime);
     368      LabelEstimatedTime.Caption := TimeToStr((Now - Project.CurrentScan.TimeStart) /
     369        Project.CurrentScan.SectorCurrent * (Project.CurrentScan.BlockMap.SectorCount - Project.CurrentScan.SectorCurrent));
     370      LabelIOSpeed.Caption := PrefixMultiplier.Add((Project.CurrentScan.SectorCurrent - LastBlockPos) *
     371        Project.CurrentScan.SectorSize / (Timer1.Interval / 1000), BasePrefixMultipliers, 'B/s');
     372      LastBlockPos := Project.CurrentScan.SectorCurrent;
    345373    end else begin
    346374      LabelElapsedTime.Caption := '';
     
    349377    end;
    350378  finally
    351     DriveScan.Lock.Release;
     379    Project.CurrentScan.Lock.Release;
    352380  end;
    353381  end else
     
    367395  Title: string;
    368396begin
    369   if Assigned(DriveScan) then begin
    370     AScanStart.Enabled := DriveScan.Terminated = True;
    371     AScanStop.Enabled := DriveScan.Terminated = False;
    372     AScanContinue.Enabled := (DriveScan.Terminated = True) and (DriveScan.SectorCurrent > DriveScan.SectorStart) and
    373       (DriveScan.SectorCurrent < DriveScan.SectorEnd);
     397  if Assigned(Project) and Assigned(Project.CurrentScan) then begin
     398    AScanStart.Enabled := Project.CurrentScan.Terminated = True;
     399    AScanStop.Enabled := Project.CurrentScan.Terminated = False;
     400    AScanContinue.Enabled := (Project.CurrentScan.Terminated = True) and
     401      (Project.CurrentScan.SectorCurrent > Project.CurrentScan.SectorStart) and
     402      (Project.CurrentScan.SectorCurrent < Project.CurrentScan.SectorEnd);
     403  end else begin
     404    AScanStart.Enabled := False;
     405    AScanStop.Enabled := False;
     406    AScanContinue.Enabled := False;
    374407  end;
    375408  AFileSave.Enabled := Assigned(Project) and Project.Modified;
    376409  AFileSaveAs.Enabled := Assigned(Project);
    377410  AFileClose.Enabled := Assigned(Project);
     411  ComboBoxDrive.Enabled := Assigned(Project);
     412  AProjectOptions.Enabled := Assigned(Project);;
     413  AOperationOptions.Enabled := Assigned(Project);;
    378414  ReloadOperationList;
    379415
     
    383419  Title := Title + Application.Title;
    384420  if Assigned(Project) and Project.Modified then
    385     Title := Title + ' ' + SProjectModified;
     421    Title := Title + ' ' + SModifiedFlag;
    386422  Caption := Title;
     423
     424  if Assigned(Project) then begin
     425    LabelSize.Caption := PrefixMultiplier.Add(Project.DriveInfo.Size,
     426      BasePrefixMultipliers, SBytes);
     427    LabelSectorCount.Caption := IntToStr(Project.DriveInfo.SectorCount);
     428    LabelSectorSize.Caption := IntToStr(Project.DriveInfo.SectorSize) + ' ' + SBytes;
     429  end else begin
     430    LabelSize.Caption := '';
     431    LabelSectorCount.Caption := '';
     432    LabelSectorSize.Caption := '';
     433  end;
    387434end;
    388435
    389436procedure TFormMain.SaveConfig;
    390437begin
    391   XMLConfig1.SetValue('DriveName', TDriveInfo(DriveList[ComboBoxDrive.ItemIndex]).Model);
     438  XMLConfig1.SetValue('DriveName', LastDriveName);
    392439  XMLConfig1.SetValue('LastProjectFileName', LastProjectFileName);
    393440end;
     
    395442procedure TFormMain.LoadConfig;
    396443begin
    397   ComboBoxDrive.ItemIndex := DriveList.IndexOf(DriveList.FindByModel(XMLConfig1.GetValue('DriveName', '')));
     444  LastDriveName := XMLConfig1.GetValue('DriveName', '');
    398445  LastProjectFileName := XMLConfig1.GetValue('LastProjectFileName', '');
    399446end;
     
    418465  AFileNew.Execute;
    419466  Project.LoadFromFile(FileName);
     467  ComboBoxDrive.ItemIndex := DriveList.IndexOf(DriveList.FindByModel(Project.DriveInfo.Model));
     468  if (ComboBoxDrive.ItemIndex = -1) and (ComboBoxDrive.Items.Count > 0) then ComboBoxDrive.ItemIndex := 0;
    420469  LastProjectFileName := FileName;
    421470  UpdateInterface;
     
    438487begin
    439488  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') + ')';
     489  DriveList.LoadToStrings(ComboBoxDrive.Items);
    447490end;
    448491
  • trunk/Form/UFormOperation.lfm

    r11 r13  
    7171    Width = 138
    7272    MaxValue = 100000
    73     MinValue = 1
    7473    OnChange = SpinEditFirstSectorChange
    7574    TabOrder = 4
     
    8281    Width = 138
    8382    MaxValue = 100000
    84     MinValue = 1
    8583    OnChange = SpinEditLastSectorChange
    8684    TabOrder = 5
  • trunk/Form/UFormProject.lfm

    r11 r13  
    11object FormProject: TFormProject
    22  Left = 537
    3   Height = 340
    4   Top = 492
    5   Width = 461
     3  Height = 392
     4  Top = 440
     5  Width = 612
    66  Caption = 'Project settings'
    7   ClientHeight = 340
    8   ClientWidth = 461
     7  ClientHeight = 392
     8  ClientWidth = 612
    99  LCLVersion = '1.7'
    1010  object SpinEditSectorSize: TSpinEdit
    1111    Left = 192
    1212    Height = 34
    13     Top = 56
     13    Top = 152
    1414    Width = 101
    1515    MaxValue = 100000
     
    2121    Left = 16
    2222    Height = 24
    23     Top = 64
     23    Top = 160
    2424    Width = 101
    2525    Caption = 'Sector size:'
     
    4444    TabOrder = 2
    4545  end
    46   object Edit1: TEdit
     46  object EditName: TEdit
    4747    Left = 192
    4848    Height = 34
     
    5050    Width = 240
    5151    TabOrder = 3
    52     Text = 'Edit1'
    5352  end
    5453  object Label2: TLabel
     
    6059    ParentColor = False
    6160  end
     61  object ComboBoxDrive: TComboBox
     62    Left = 192
     63    Height = 38
     64    Top = 56
     65    Width = 384
     66    ItemHeight = 0
     67    Style = csDropDownList
     68    TabOrder = 4
     69  end
     70  object Label3: TLabel
     71    Left = 16
     72    Height = 24
     73    Top = 64
     74    Width = 53
     75    Caption = 'Drive:'
     76    ParentColor = False
     77  end
     78  object Label4: TLabel
     79    Left = 16
     80    Height = 24
     81    Top = 112
     82    Width = 119
     83    Caption = 'Sector count:'
     84    ParentColor = False
     85  end
     86  object LabelSectorCount: TLabel
     87    Left = 192
     88    Height = 24
     89    Top = 112
     90    Width = 15
     91    Caption = '   '
     92    ParentColor = False
     93  end
    6294end
  • trunk/Form/UFormProject.pas

    r11 r13  
    1616    Button1: TButton;
    1717    Button2: TButton;
    18     Edit1: TEdit;
     18    ComboBoxDrive: TComboBox;
     19    EditName: TEdit;
    1920    Label1: TLabel;
    2021    Label2: TLabel;
     22    Label3: TLabel;
     23    Label4: TLabel;
     24    LabelSectorCount: TLabel;
    2125    SpinEditSectorSize: TSpinEdit;
    2226  private
     
    3337{$R *.lfm}
    3438
     39uses
     40  UFormMain;
     41
    3542{ TFormProject }
    3643
    3744procedure TFormProject.Load(Project: TProject);
    3845begin
    39   Edit1.Text := Project.Name;
    40   SpinEditSectorSize.Value := Project.SectorSize;
     46  FormMain.DriveList.LoadToStrings(ComboBoxDrive.Items);
     47  EditName.Text := Project.Name;
     48  SpinEditSectorSize.Value := Project.DriveInfo.SectorSize;
     49  ComboBoxDrive.ItemIndex := FormMain.DriveList.IndexOf(FormMain.DriveList.FindByModel(Project.DriveInfo.Model));
    4150end;
    4251
    4352procedure TFormProject.Save(Project: TProject);
    4453begin
    45   Project.Name := Edit1.Text;
    46   Project.SectorSize := SpinEditSectorSize.Value;
     54  Project.Name := EditName.Text;
     55  Project.DriveInfo.SectorSize := SpinEditSectorSize.Value;
    4756end;
    4857
  • trunk/Packages/Common/UXMLUtils.pas

    r4 r13  
    1212function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;
    1313procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer);
     14procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64);
    1415procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean);
    1516procedure WriteString(Node: TDOMNode; Name: string; Value: string);
    1617procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime);
    1718function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer;
     19function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64;
    1820function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean;
    1921function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string;
     
    142144end;
    143145
     146procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64);
     147var
     148  NewNode: TDOMNode;
     149begin
     150  NewNode := Node.OwnerDocument.CreateElement(Name);
     151  NewNode.TextContent := IntToStr(Value);
     152  Node.AppendChild(NewNode);
     153end;
     154
    144155procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean);
    145156var
     
    170181
    171182function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer;
     183var
     184  NewNode: TDOMNode;
     185begin
     186  Result := DefaultValue;
     187  NewNode := Node.FindNode(Name);
     188  if Assigned(NewNode) then
     189    Result := StrToInt(NewNode.TextContent);
     190end;
     191
     192function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64;
    172193var
    173194  NewNode: TDOMNode;
  • trunk/UDriveScan.pas

    r12 r13  
    3939    Lock: TCriticalSection;
    4040    BlockMap: TBlockMap;
    41     SectorSize: Integer;
    4241    TimeStart: TDateTime;
    4342    TimeEnd: TDateTime;
     
    4645    Mode: TRunMode;
    4746    WritePattern: Byte;
     47    SectorSize: Integer;
    4848    SectorStart: Integer;
    4949    SectorEnd: Integer;
     
    257257    WriteDateTime(Node, 'TimeStart', TimeStart);
    258258    WriteDateTime(Node, 'TimeEnd', TimeEnd);
     259    WriteInteger(Node, 'SectorSize', SectorSize);
     260    WriteInteger(Node, 'SectorCount', SectorCount);
    259261    WriteInteger(Node, 'SectorStart', SectorStart);
    260262    WriteInteger(Node, 'SectorEnd', SectorEnd);
     
    277279    TimeStart := ReadDateTime(Node, 'TimeStart', 0);
    278280    TimeEnd := ReadDateTime(Node, 'TimeEnd', 0);
    279     FSectorCurrent := ReadInteger(Node, 'SectorCurrent', 0);
     281    SectorSize := ReadInteger(Node, 'SectorSize', 512);
     282    SectorCount := ReadInteger(Node, 'SectorCount', 0);
    280283    SectorStart := ReadInteger(Node, 'SectorStart', 0);
    281284    SectorEnd := ReadInteger(Node, 'SectorEnd', SectorCount - 1);
     285    FSectorCurrent := ReadInteger(Node, 'SectorCurrent', 0);
    282286
    283287    NewNode := FindNode('SectorMap');
  • trunk/UPhysDrive.pas

    r12 r13  
    99
    1010type
     11
     12  { TDriveInfo }
     13
    1114  TDriveInfo = class
    1215    Model: string;
    1316    Size: Int64;
    1417    SectorCount: Int64;
     18    SectorSize: Integer;
    1519    Path: string;
     20    procedure Assign(Source: TDriveInfo);
    1621  end;
    1722
     
    2025  TDriveList = class(TObjectList)
    2126    function FindByModel(Model: string): TDriveInfo;
     27    procedure LoadToStrings(Strings: TStrings);
    2228    procedure Detect;
    2329  end;
    2430
    2531implementation
     32
     33uses
     34  UPrefixMultiplier;
     35
     36{ TDriveInfo }
     37
     38procedure TDriveInfo.Assign(Source: TDriveInfo);
     39begin
     40  Path := Source.Path;
     41  Model := Source.Model;
     42  Size := Source.Size;
     43  SectorCount := Source.SectorCount;
     44  SectorSize := Source.SectorSize;
     45end;
    2646
    2747{ TDriveList }
     
    3555  if I < Count then Result := TDriveInfo(Items[I])
    3656    else Result := nil;
     57end;
     58
     59procedure TDriveList.LoadToStrings(Strings: TStrings);
     60var
     61  I: Integer;
     62  PrefixMultiplier: TPrefixMultiplier;
     63begin
     64  PrefixMultiplier := TPrefixMultiplier.Create;
     65  try
     66    while Strings.Count > Count do
     67      Strings.Delete(Strings.Count - 1);
     68    while Strings.Count < Count do
     69      Strings.Add('');
     70    for I := 0 to Count - 1 do begin
     71      Strings[I] := TDriveInfo(Items[I]).Model + ' (' +
     72        PrefixMultiplier.Add(TDriveInfo(Items[I]).Size, BasePrefixMultipliers, 'B') + ')';
     73      Strings.Objects[I] := Items[I];
     74    end;
     75  finally
     76    PrefixMultiplier.Free;
     77  end;
    3778end;
    3879
     
    5798      NewDriveInfo := TDriveInfo.Create;
    5899      NewDriveInfo.Model := Trim(LoadFileToStr(List[I] + '/device/model'));
    59       NewDriveInfo.SectorCount := StrToInt(Trim(LoadFileToStr(List[I] + '/size')));
    60       NewDriveInfo.Size := NewDriveInfo.SectorCount * 512;
     100      NewDriveInfo.SectorSize := StrToInt(Trim(LoadFileToStr(List[I] + '/queue/physical_block_size')));
     101      NewDriveInfo.SectorCount := StrToInt(Trim(LoadFileToStr(List[I] + '/size'))) * 512 div NewDriveInfo.SectorSize;
     102      NewDriveInfo.Size := NewDriveInfo.SectorCount * NewDriveInfo.SectorSize;
    61103      NewDriveInfo.Path := '/dev/' + ExtractFileName(List[I]);
    62104      Add(NewDriveInfo);
  • trunk/UProject.pas

    r10 r13  
    66
    77uses
    8   Classes, SysUtils, Contnrs, DOM, XMLRead, XMLWrite, UXMLUtils, UDriveScan;
     8  Classes, SysUtils, Contnrs, DOM, XMLRead, XMLWrite, UXMLUtils, UDriveScan,
     9  UPhysDrive;
    910
    1011type
     
    1314
    1415  TProject = class
     16  private
     17    function GetCurrentScan: TDriveScan;
     18    function GetSectorCount: Integer;
     19  public
    1520    Name: string;
    1621    FileName: string;
    17     SectorSize: Integer;
    18     SectorCount: Integer;
    1922    Modified: Boolean;
    2023    Scans: TDriveScanList;
    21     DriveName: string;
     24    DriveInfo: TDriveInfo;
    2225    constructor Create;
    2326    destructor Destroy; override;
    2427    procedure LoadFromFile(FileName: string);
    2528    procedure SaveToFile(FileName: string);
     29    property SectorCount: Integer read GetSectorCount;
     30    property CurrentScan: TDriveScan read GetCurrentScan;
    2631  end;
    2732
     
    3540{ TProject }
    3641
     42function TProject.GetCurrentScan: TDriveScan;
     43begin
     44  if Scans.Count > 0 then Result := TDriveScan(Scans[Scans.Count - 1])
     45    else Result := nil;
     46end;
     47
     48function TProject.GetSectorCount: Integer;
     49begin
     50  Result := DriveInfo.SectorCount;
     51end;
     52
    3753constructor TProject.Create;
    3854begin
    39   SectorSize := 4096;
    4055  Scans := TDriveScanList.Create;
     56  DriveInfo := TDriveInfo.Create;
    4157end;
    4258
    4359destructor TProject.Destroy;
    4460begin
     61  FreeAndNil(DriveInfo);
    4562  FreeAndNil(Scans);
    4663  inherited Destroy;
     
    5976    AppendChild(RootNode);
    6077    with RootNode do begin
    61       WriteInteger(RootNode, 'SectorSize', SectorSize);
    62       WriteInteger(RootNode, 'SectorCount', SectorCount);
    63       WriteString(RootNode, 'DriveName', DriveName);
     78      WriteInteger(RootNode, 'SectorCount', DriveInfo.SectorCount);
     79      WriteInteger(RootNode, 'SectorSize', DriveInfo.SectorSize);
     80      WriteString(RootNode, 'DriveName', DriveInfo.Model);
     81      WriteString(RootNode, 'DrivePath', DriveInfo.Path);
     82      WriteInt64(RootNode, 'DriveSize', DriveInfo.Size);
    6483
    6584      NewNode := OwnerDocument.CreateElement('Scans');
     
    89108    RootNode := Doc.DocumentElement;
    90109    with RootNode do begin
    91       SectorSize := ReadInteger(RootNode, 'SectorSize', 4096);
    92       SectorCount := ReadInteger(RootNode, 'SectorCount', 0);
    93       DriveName := ReadString(RootNode, 'DriveName', '');
     110      DriveInfo.SectorSize := ReadInteger(RootNode, 'SectorSize', 4096);
     111      DriveInfo.SectorCount := ReadInteger(RootNode, 'SectorCount', 0);
     112      DriveInfo.Model := ReadString(RootNode, 'DriveName', '');
     113      DriveInfo.Path := ReadString(RootNode, 'DrivePath', '');
     114      DriveInfo.Size := ReadInt64(RootNode, 'DriveSize', 0);
    94115
    95116      NewNode := FindNode('Scans');
Note: See TracChangeset for help on using the changeset viewer.