Changeset 2 for trunk


Ignore:
Timestamp:
Mar 25, 2016, 10:24:04 PM (9 years ago)
Author:
chronos
Message:
  • Added: Ability to write data with defined byte pattern.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore set to
      CoolDisk
      lib
      CoolDisk.lps
  • trunk/UFormMain.lfm

    r1 r2  
    201201    TabOrder = 5
    202202  end
     203  object ComboBoxRunMode: TComboBox
     204    Left = 17
     205    Height = 38
     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'
     233  end
    203234  object MainMenu1: TMainMenu
    204235    left = 323
  • trunk/UFormMain.pas

    r1 r2  
    4848  end;
    4949
     50  TRunMode = (rmRead, rmWrite);
     51
    5052  { TDriveScan }
    5153
     
    6668    DamagedBlockCount: Integer;
    6769    Drive: string;
     70    Mode: TRunMode;
     71    WritePattern: Byte;
    6872    function GetElapsedTime: TDateTime;
    69     procedure Scan;
     73    procedure Run;
    7074    constructor Create;
    7175    destructor Destroy; override;
     
    9397    ButtonScan1: TButton;
    9498    ButtonScan2: TButton;
     99    ComboBoxRunMode: TComboBox;
     100    EditPattern: TEdit;
    95101    EditDrive: TEdit;
    96102    Image1: TImage;
     
    103109    Label7: TLabel;
    104110    Label8: TLabel;
     111    Label9: TLabel;
    105112    LabelElapsedTime: TLabel;
    106113    LabelBlockSize: TLabel;
     
    155162procedure TScanThread.Execute;
    156163begin
    157   TFormMain(Form).DriveScan.Scan;
     164  TFormMain(Form).DriveScan.Run;
    158165end;
    159166
     
    313320end;
    314321
    315 procedure TDriveScan.Scan;
     322procedure TDriveScan.Run;
    316323var
    317324  F: TFileStream;
    318   ReadSize: Integer;
     325  RealSize: Integer;
    319326  Buffer: array of Byte;
    320327  I: Integer;
     
    325332  Terminated := False;
    326333  DamagedBlockCount := 0;
    327   F := TFileStream.Create(Drive, fmOpenRead);
     334  if Mode = rmRead then F := TFileStream.Create(Drive, fmOpenRead)
     335    else if Mode = rmWrite then F := TFileStream.Create(Drive, fmOpenReadWrite);
    328336  BlockMap.SectorCount := F.Size div SectorSize;
    329337  BlockMap.Clear;
    330338  SetLength(Buffer, SectorSize);
     339  if Mode = rmWrite then
     340    FillChar(Buffer[0], Length(Buffer), WritePattern);
    331341  for I := 0 to BlockMap.SectorCount - 1 do begin
    332342    SectorCurrent := I;
     
    336346
    337347      if ConfigTest then begin
    338         if Random < 0.000001 then ReadSize := 0
    339           else ReadSize := SectorSize;
     348        if Random < 0.000001 then RealSize := 0
     349          else RealSize := SectorSize;
    340350        //Sleep(1);
    341351      end else begin
    342352        F.Position := I * SectorSize;
    343         ReadSize := F.Read(Buffer[0], SectorSize);
     353        if Mode = rmRead then RealSize := F.Read(Buffer[0], SectorSize)
     354          else if Mode = rmWrite then RealSize := F.Write(Buffer[0], SectorSize)
     355          else raise Exception.Create('Unknwon run mode');
    344356      end;
    345357    finally
    346358      Lock.Acquire;
    347359    end;
    348     if ReadSize <> SectorSize then begin
     360    if RealSize <> SectorSize then begin
    349361      BlockMap.Sectors[I] := bsDamaged;
    350362      Inc(DamagedBlockCount);
     
    416428  DriveScan.SectorSize := Project.SectorSize;
    417429  DriveScan.Terminated := False;
     430  DriveScan.Mode := TRunMode(ComboBoxRunMode.ItemIndex);
     431  DriveScan.WritePattern := StrToInt(EditPattern.Text);
    418432  ScanThread.Start;
    419433  UpdateInterface;
  • trunk/UProject.pas

    r1 r2  
    2929constructor TProject.Create;
    3030begin
    31   SectorSize := 512;
     31  SectorSize := 4096;
    3232end;
    3333
Note: See TracChangeset for help on using the changeset viewer.