Changeset 28


Ignore:
Timestamp:
Apr 7, 2016, 7:01:24 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Dynamically calculate sector count from drive size and sector size.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/CoolDisk.lpi

    r21 r28  
    3434              <SyntaxMode Value="Delphi"/>
    3535              <CStyleOperator Value="False"/>
     36              <AllowLabel Value="False"/>
    3637              <CPPInline Value="False"/>
    3738            </SyntaxOptions>
     
    4041            <SmartLinkUnit Value="True"/>
    4142            <Optimizations>
    42               <OptimizationLevel Value="2"/>
     43              <OptimizationLevel Value="3"/>
    4344            </Optimizations>
    4445          </CodeGeneration>
     
    4748              <GenerateDebugInfo Value="False"/>
    4849            </Debugging>
     50            <LinkSmart Value="True"/>
    4951            <Options>
    5052              <Win32>
     
    158160      <SyntaxOptions>
    159161        <SyntaxMode Value="Delphi"/>
     162        <CStyleOperator Value="False"/>
    160163        <IncludeAssertionCode Value="True"/>
     164        <AllowLabel Value="False"/>
     165        <CPPInline Value="False"/>
    161166      </SyntaxOptions>
    162167    </Parsing>
  • trunk/Form/UFormMain.pas

    r27 r28  
    247247        Model := OpenDialog1.FileName;
    248248        SectorSize := 4096;
    249         SectorCount := Size div SectorSize;
    250249        Core.DriveList.LoadToStrings(ComboBoxDrive.Items);
    251250      end;
     
    319318    Core.Project.DriveInfo.Assign(TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex]));
    320319  Core.Project.ScanProfile.LoadFromDriveInfo(Core.Project.DriveInfo);
    321 
    322320
    323321  Redraw;
  • trunk/UPhysDrive.pas

    r21 r28  
    66
    77uses
    8   Classes, SysUtils, Contnrs, UFindFile, UCommon
     8  Classes, SysUtils, Contnrs, UFindFile, UCommon, Math
    99  {$IFDEF Windows},ActiveX,ComObj,Variants
    1010  {$ENDIF};
     
    1616
    1717  TDriveInfo = class
     18  private
     19    FSectorSize: Integer;
     20    FSectorCount: Int64;
     21    FSize: Int64;
     22    function GetSectorCount: Int64;
     23    procedure SetSectorSize(AValue: Integer);
     24    procedure SetSize(AValue: Int64);
     25  public
    1826    Kind: TDriveKind;
    1927    Model: string;
    20     Size: Int64;
    21     SectorCount: Int64;
    22     SectorSize: Integer;
    2328    Path: string;
     29    constructor Create;
    2430    procedure Assign(Source: TDriveInfo);
     31    property SectorSize: Integer read FSectorSize write SetSectorSize;
     32    property SectorCount: Int64 read GetSectorCount;
     33    property Size: Int64 read FSize write SetSize;
    2534  end;
    2635
     
    4251  UPrefixMultiplier;
    4352
     53resourcestring
     54  SMinSectorSize = 'Minimum sector size is 1';
     55
    4456{ TDriveInfo }
     57
     58procedure TDriveInfo.SetSectorSize(AValue: Integer);
     59begin
     60  if FSectorSize = AValue then Exit;
     61  if Avalue < 1 then
     62    raise Exception.Create(SMinSectorSize);
     63  FSectorSize := AValue;
     64  FSectorCount := Ceil(FSize / FSectorSize);
     65end;
     66
     67function TDriveInfo.GetSectorCount: Int64;
     68begin
     69  Result := Ceil(FSize / FSectorSize);
     70end;
     71
     72procedure TDriveInfo.SetSize(AValue: Int64);
     73begin
     74  if FSize=AValue then Exit;
     75  FSize:=AValue;
     76end;
     77
     78constructor TDriveInfo.Create;
     79begin
     80  FSectorSize := 1;
     81end;
    4582
    4683procedure TDriveInfo.Assign(Source: TDriveInfo);
     
    4986  Model := Source.Model;
    5087  Size := Source.Size;
    51   SectorCount := Source.SectorCount;
     88  FSectorCount := Source.FSectorCount;
    5289  SectorSize := Source.SectorSize;
    5390end;
     
    108145      NewDriveInfo.Model := Trim(LoadFileToStr(List[I] + '/device/model'));
    109146      NewDriveInfo.SectorSize := StrToInt(Trim(LoadFileToStr(List[I] + '/queue/physical_block_size')));
    110       NewDriveInfo.SectorCount := StrToInt(Trim(LoadFileToStr(List[I] + '/size'))) * 512 div NewDriveInfo.SectorSize;
    111       NewDriveInfo.Size := NewDriveInfo.SectorCount * NewDriveInfo.SectorSize;
     147      NewDriveInfo.Size := StrToInt(Trim(LoadFileToStr(List[I] + '/size'))) * 512;
    112148      NewDriveInfo.Path := '/dev/' + ExtractFileName(List[I]);
    113149      Add(NewDriveInfo);
     
    123159  NewDriveInfo.Model := 'File';
    124160  NewDriveInfo.SectorSize := 4096;
    125   NewDriveInfo.SectorCount := 0;
    126161  NewDriveInfo.Size := 0;
    127162  NewDriveInfo.Path := '';
  • trunk/UProject.pas

    r19 r28  
    120120    with RootNode do begin
    121121      DriveInfo.SectorSize := ReadInteger(RootNode, 'SectorSize', 4096);
    122       DriveInfo.SectorCount := ReadInteger(RootNode, 'SectorCount', 0);
    123122      ScanProfile.SectorCount := DriveInfo.SectorCount;
    124123      DriveInfo.Model := ReadString(RootNode, 'DriveName', '');
Note: See TracChangeset for help on using the changeset viewer.