Changeset 13 for trunk/UPhysDrive.pas


Ignore:
Timestamp:
Apr 2, 2016, 1:06:34 PM (8 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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.