Changeset 15 for trunk/Form


Ignore:
Timestamp:
Apr 2, 2016, 1:39:42 PM (9 years ago)
Author:
chronos
Message:
  • Added: UCore unit as main application unit. UFormMain serve for as main form interface.
  • Added: Remember main form dimensions.
Location:
trunk/Form
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Form/UFormMain.lfm

    r14 r15  
    2323  end
    2424  object Image1: TImage
    25     Left = 592
    26     Height = 848
     25    Left = 600
     26    Height = 856
    2727    Top = 40
    2828    Width = 1092
     
    408408  object LastOpenedList1: TLastOpenedList
    409409    MaxCount = 10
    410     left = 906
    411     top = 167
     410    left = 904
     411    top = 144
    412412  end
    413413end
  • trunk/Form/UFormMain.pas

    r14 r15  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    99  Menus, ComCtrls, ExtCtrls, ActnList, dateutils, syncobjs, UProject,
    10   UDriveScan, UPrefixMultiplier, ULastOpenedList, XMLConf, UPhysDrive;
     10  UDriveScan, UPrefixMultiplier, ULastOpenedList, UPersistentForm, XMLConf,
     11  UPhysDrive;
    1112
    1213type
     
    115116    procedure UpdateInterface;
    116117  public
    117     DriveList: TDriveList;
    118     Project: TProject;
    119118    procedure SaveConfig;
    120119    procedure LoadConfig;
     
    131130
    132131uses
    133   UFormProject, UFormOperation;
     132  UCore, UFormProject, UFormOperation;
    134133
    135134resourcestring
     
    149148  Detect;
    150149  LoadConfig;
     150  Core.PersistentForm1.Load(Self);
    151151  if (LastOpenedList1.Items.Count > 0) then
    152152    ProjectOpen(LastOpenedList1.Items[0])
     
    165165procedure TFormMain.ListView1Data(Sender: TObject; Item: TListItem);
    166166begin
    167   if (Item.Index >= 0) and (Item.Index < Project.Scans.Count) then
    168   with TDriveScan(Project.Scans[Item.Index]) do begin
     167  if (Item.Index >= 0) and (Item.Index < Core.Project.Scans.Count) then
     168  with TDriveScan(Core.Project.Scans[Item.Index]) do begin
    169169    Item.Caption := IntToStr(Item.Index);
    170170    Item.SubItems.Add(DateTimeToStr(TimeStart));
     
    179179  PrefixMultiplier := TPrefixMultiplier.Create;
    180180  XMLConfig1.Filename := 'config.xml';
    181   Project := nil;
    182   DriveList := TDriveList.Create;
    183181end;
    184182
    185183procedure TFormMain.AScanStopExecute(Sender: TObject);
    186184begin
    187   if Assigned(Project) and Assigned(Project.CurrentScan) then begin
    188     Project.CurrentScan.Stop;
     185  if Assigned(Core.Project) and Assigned(Core.Project.CurrentScan) then begin
     186    Core.Project.CurrentScan.Stop;
    189187    UpdateInterface;
    190188  end;
     
    193191procedure TFormMain.ComboBoxDriveChange(Sender: TObject);
    194192begin
    195   if Project.DriveInfo.Path <> TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex]).Path then begin
    196     Project.DriveInfo.Assign(TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex]));
    197     Project.Modified := True;
    198     Project.CurrentScan.SectorCount := Project.DriveInfo.SectorCount;
    199     Project.CurrentScan.SectorSize := Project.DriveInfo.SectorSize;
    200     Project.CurrentScan.SectorStart := 0;
    201     Project.CurrentScan.SectorEnd := Project.CurrentScan.SectorCount - 1;
    202     Project.CurrentScan.Reset;
     193  with Core.Project do
     194  if DriveInfo.Path <> TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex]).Path then begin
     195    DriveInfo.Assign(TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex]));
     196    Modified := True;
     197    CurrentScan.SectorCount := DriveInfo.SectorCount;
     198    CurrentScan.SectorSize := DriveInfo.SectorSize;
     199    CurrentScan.SectorStart := 0;
     200    CurrentScan.SectorEnd := CurrentScan.SectorCount - 1;
     201    CurrentScan.Reset;
    203202    UpdateInterface;
    204203    Redraw;
     
    209208begin
    210209  LastBlockPos := 0;
    211   Project.CurrentScan.DriveName := Project.DriveInfo.Path;
    212   Project.CurrentScan.SectorSize := Project.DriveInfo.SectorSize;
    213   Project.CurrentScan.Reset;
    214   Project.CurrentScan.OnChange := DriveScanChange;
    215   Project.CurrentScan.OnTerminate := DriveScanTerminate;
    216   Project.CurrentScan.Start;
    217   Project.Modified := True;
     210  with Core.Project do begin
     211    CurrentScan.DriveName := DriveInfo.Path;
     212    CurrentScan.SectorSize := DriveInfo.SectorSize;
     213    CurrentScan.Reset;
     214    CurrentScan.OnChange := DriveScanChange;
     215    CurrentScan.OnTerminate := DriveScanTerminate;
     216    CurrentScan.Start;
     217    Modified := True;
     218  end;
    218219  UpdateInterface;
    219220end;
     
    221222procedure TFormMain.AProjectOptionsExecute(Sender: TObject);
    222223begin
    223   FormProject.Load(Project);
     224  FormProject.Load(Core.Project);
    224225  if FormProject.ShowModal = mrOk then begin
    225     FormProject.Save(Project);
    226     Project.Modified := True;
     226    FormProject.Save(Core.Project);
     227    Core.Project.Modified := True;
    227228    UpdateInterface;
    228229  end;
     
    231232procedure TFormMain.AScanContinueExecute(Sender: TObject);
    232233begin
    233   Project.CurrentScan.Start;
    234   Project.Modified := True;
     234  Core.Project.CurrentScan.Start;
     235  Core.Project.Modified := True;
    235236  UpdateInterface;
    236237end;
     
    243244procedure TFormMain.AFileCloseExecute(Sender: TObject);
    244245begin
    245   FreeAndNil(Project);
     246  FreeAndNil(Core.Project);
    246247  UpdateInterface;
    247248end;
     
    250251begin
    251252  AFileClose.Execute;
    252   Project := TProject.Create;
    253   Project.FileName := SNewProject;
    254   Project.Modified := False;
    255   Project.Scans.Add(TDriveScan.Create);
    256 
    257   ComboBoxDrive.ItemIndex := DriveList.IndexOf(DriveList.FindByModel(Project.DriveInfo.Model));
     253  Core.Project := TProject.Create;
     254  Core.Project.FileName := SNewProject;
     255  Core.Project.Modified := False;
     256  Core.Project.Scans.Add(TDriveScan.Create);
     257
     258  ComboBoxDrive.ItemIndex := Core.DriveList.IndexOf(Core.DriveList.FindByModel(Core.Project.DriveInfo.Model));
    258259  if (ComboBoxDrive.ItemIndex = -1) and (ComboBoxDrive.Items.Count > 0) then ComboBoxDrive.ItemIndex := 0;
    259260  ComboBoxDriveChange(Self);
     
    267268  OpenDialog1.Title := SOpenStoredProject;
    268269  OpenDialog1.DefaultExt := '.cdp';
    269   if Assigned(Project) then
    270     OpenDialog1.FileName := Project.FileName;
     270  if Assigned(Core.Project) then
     271    OpenDialog1.FileName := Core.Project.FileName;
    271272  if OpenDialog1.Execute then begin
    272273    ProjectOpen(OpenDialog1.FileName);
     
    278279  SaveDialog1.Title := SSaveProject;
    279280  SaveDialog1.DefaultExt := '.cdp';
    280   SaveDialog1.FileName := Project.FileName;
     281  SaveDialog1.FileName := Core.Project.FileName;
    281282  if SaveDialog1.Execute then begin
    282     Project.SaveToFile(SaveDialog1.FileName);
     283    Core.Project.SaveToFile(SaveDialog1.FileName);
    283284    LastOpenedList1.AddItem(SaveDialog1.FileName);
    284285    LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, OpenRecentClick);
     
    289290procedure TFormMain.AFileSaveExecute(Sender: TObject);
    290291begin
    291   if not FileExists(Project.FileName) then
     292  if not FileExists(Core.Project.FileName) then
    292293    AFileSaveAs.Execute
    293294    else begin
    294       Project.SaveToFile(Project.FileName);
     295      Core.Project.SaveToFile(Core.Project.FileName);
    295296      LastOpenedList1.AddItem(SaveDialog1.FileName);
    296297      LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, OpenRecentClick);
     
    301302procedure TFormMain.AOperationOptionsExecute(Sender: TObject);
    302303begin
    303   FormOperation.Load(Project.CurrentScan);
     304  FormOperation.Load(Core.Project.CurrentScan);
    304305  if FormOperation.ShowModal = mrOk then begin
    305     FormOperation.Save(Project.CurrentScan);
    306     Project.Modified := True;
     306    FormOperation.Save(Core.Project.CurrentScan);
     307    Core.Project.Modified := True;
    307308    UpdateInterface;
    308309  end;
     
    313314  AFileClose.Execute;
    314315  SaveConfig;
     316  Core.PersistentForm1.Save(Self);
    315317end;
    316318
     
    319321  R: TModalResult;
    320322begin
    321   if Assigned(Project) and Project.Modified then begin
     323  if Assigned(Core.Project) and Core.Project.Modified then begin
    322324    R := MessageDlg(SProjectModified, SProjectModifiedQuestion, mtConfirmation, [mbYes, mbNo, mbCancel], 0);
    323325    if R = mrCancel then begin
     
    334336begin
    335337  Timer1.Enabled := False;
    336   if Assigned(Project) then FreeAndNil(Project);
    337338  FreeAndNil(PrefixMultiplier);
    338   FreeAndNil(DriveList);
    339339end;
    340340
     
    347347procedure TFormMain.DoDraw;
    348348begin
    349   if Assigned(Project) then begin
     349  if Assigned(Core.Project) then
     350  with Core.Project do begin
    350351  if RedrawPending then
    351352  with Image1 do begin
     
    353354      Picture.Bitmap.SetSize(Width, Height);
    354355    try
    355       Project.CurrentScan.Lock.Acquire;
     356      Core.Project.CurrentScan.Lock.Acquire;
    356357      try
    357358        Picture.Bitmap.BeginUpdate(True);
    358         Project.CurrentScan.BlockMap.Draw(Picture.Bitmap.Canvas);
     359        CurrentScan.BlockMap.Draw(Picture.Bitmap.Canvas);
    359360      finally
    360361        Picture.Bitmap.EndUpdate;
    361362      end;
    362       LabelSectorPerBlock.Caption := IntToStr(Project.CurrentScan.BlockMap.SectorPerBlock);
    363       LabelBlockCurrent.Caption := IntToStr(Project.CurrentScan.SectorCurrent);
    364       LabelBlockDamaged.Caption := IntToStr(Project.CurrentScan.DamagedBlockCount);
     363      LabelSectorPerBlock.Caption := IntToStr(CurrentScan.BlockMap.SectorPerBlock);
     364      LabelBlockCurrent.Caption := IntToStr(CurrentScan.SectorCurrent);
     365      LabelBlockDamaged.Caption := IntToStr(CurrentScan.DamagedBlockCount);
    365366    finally
    366       Project.CurrentScan.Lock.Release;
     367      CurrentScan.Lock.Release;
    367368    end;
    368369    RedrawPending := False;
    369370  end;
    370371  try
    371     Project.CurrentScan.Lock.Acquire;
    372     if not Project.CurrentScan.Terminated then begin
    373       LabelElapsedTime.Caption := TimeToStr(Project.CurrentScan.GetElapsedTime);
    374       LabelEstimatedTime.Caption := TimeToStr((Now - Project.CurrentScan.TimeStart) /
    375         Project.CurrentScan.SectorCurrent * (Project.CurrentScan.BlockMap.SectorCount - Project.CurrentScan.SectorCurrent));
    376       LabelIOSpeed.Caption := PrefixMultiplier.Add((Project.CurrentScan.SectorCurrent - LastBlockPos) *
    377         Project.CurrentScan.SectorSize / (Timer1.Interval / 1000), BasePrefixMultipliers, 'B/s');
    378       LastBlockPos := Project.CurrentScan.SectorCurrent;
     372    CurrentScan.Lock.Acquire;
     373    if not CurrentScan.Terminated then begin
     374      LabelElapsedTime.Caption := TimeToStr(CurrentScan.GetElapsedTime);
     375      LabelEstimatedTime.Caption := TimeToStr((Now - CurrentScan.TimeStart) /
     376        CurrentScan.SectorCurrent * (CurrentScan.BlockMap.SectorCount - CurrentScan.SectorCurrent));
     377      LabelIOSpeed.Caption := PrefixMultiplier.Add((CurrentScan.SectorCurrent - LastBlockPos) *
     378        CurrentScan.SectorSize / (Timer1.Interval / 1000), BasePrefixMultipliers, 'B/s');
     379      LastBlockPos := CurrentScan.SectorCurrent;
    379380    end else begin
    380381      LabelElapsedTime.Caption := '';
     
    383384    end;
    384385  finally
    385     Project.CurrentScan.Lock.Release;
     386    CurrentScan.Lock.Release;
    386387  end;
    387388  end else
     
    401402  Title: string;
    402403begin
     404  with Core do begin
    403405  if Assigned(Project) and Assigned(Project.CurrentScan) then begin
    404406    AScanStart.Enabled := Project.CurrentScan.Terminated = True;
     
    438440    LabelSectorSize.Caption := '';
    439441  end;
     442  end;
    440443end;
    441444
     
    464467procedure TFormMain.ReloadOperationList;
    465468begin
    466   if Assigned(Project) then begin
    467     ListView1.Items.Count := Project.Scans.Count;
     469  if Assigned(Core.Project) then begin
     470    ListView1.Items.Count := Core.Project.Scans.Count;
    468471  end else begin
    469472    ListView1.Items.Count := 0;
     
    475478begin
    476479  AFileNew.Execute;
    477   Project.LoadFromFile(FileName);
    478   ComboBoxDrive.ItemIndex := DriveList.IndexOf(DriveList.FindByModel(Project.DriveInfo.Model));
     480  Core.Project.LoadFromFile(FileName);
     481  ComboBoxDrive.ItemIndex := Core.DriveList.IndexOf(Core.DriveList.FindByModel(Core.Project.DriveInfo.Model));
    479482  if (ComboBoxDrive.ItemIndex = -1) and (ComboBoxDrive.Items.Count > 0) then ComboBoxDrive.ItemIndex := 0;
    480483  LastOpenedList1.AddItem(FileName);
     
    496499procedure TFormMain.Detect;
    497500begin
    498   DriveList.Detect;
    499   DriveList.LoadToStrings(ComboBoxDrive.Items);
     501  Core.DriveList.Detect;
     502  Core.DriveList.LoadToStrings(ComboBoxDrive.Items);
    500503end;
    501504
  • trunk/Form/UFormProject.pas

    r13 r15  
    3838
    3939uses
    40   UFormMain;
     40  UCore;
    4141
    4242{ TFormProject }
     
    4444procedure TFormProject.Load(Project: TProject);
    4545begin
    46   FormMain.DriveList.LoadToStrings(ComboBoxDrive.Items);
     46  Core.DriveList.LoadToStrings(ComboBoxDrive.Items);
    4747  EditName.Text := Project.Name;
    4848  SpinEditSectorSize.Value := Project.DriveInfo.SectorSize;
    49   ComboBoxDrive.ItemIndex := FormMain.DriveList.IndexOf(FormMain.DriveList.FindByModel(Project.DriveInfo.Model));
     49  ComboBoxDrive.ItemIndex := Core.DriveList.IndexOf(Core.DriveList.FindByModel(Project.DriveInfo.Model));
    5050end;
    5151
Note: See TracChangeset for help on using the changeset viewer.