source: trunk/Forms/UFormMain.pas

Last change on this file was 41, checked in by chronos, 6 years ago
  • Modified: Build under Lazarus 2.0.
  • Modified: Used .lrj files instead of .lrt files.
  • Modified: Removed TemplateGenerics package.
File size: 19.7 KB
Line 
1unit UFormMain;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, TAGraph, TASeries, Forms, Controls, Graphics,
9 Dialogs, StdCtrls, Menus, ComCtrls, ExtCtrls, ActnList, dateutils, syncobjs,
10 UProject, UDriveScan, UPrefixMultiplier, ULastOpenedList, UPersistentForm,
11 XMLConf, UPhysDrive;
12
13type
14 { TFormMain }
15
16 TFormMain = class(TForm)
17 AShowSettings: TAction;
18 AShowAbout: TAction;
19 AOperationAdd: TAction;
20 AOperationRemove: TAction;
21 AViewToolbar: TAction;
22 ADriveSelect: TAction;
23 AOperationOptions: TAction;
24 AFileClose: TAction;
25 AFileNew: TAction;
26 AScanContinue: TAction;
27 AFileSave: TAction;
28 AFileOpen: TAction;
29 AFileSaveAs: TAction;
30 AExit: TAction;
31 AProjectOptions: TAction;
32 AScanStart: TAction;
33 AScanStop: TAction;
34 ActionList1: TActionList;
35 Button1: TButton;
36 Button2: TButton;
37 Button3: TButton;
38 Button4: TButton;
39 ButtonScan: TButton;
40 ButtonScan1: TButton;
41 ButtonScan2: TButton;
42 ChartSpeed: TChart;
43 ChartSpeedLineSeriesAvg: TLineSeries;
44 ChartSpeedLineSeriesMin: TLineSeries;
45 ChartSpeedLineSeriesMax: TLineSeries;
46 ComboBoxDrive: TComboBox;
47 Image1: TImage;
48 Label1: TLabel;
49 Label10: TLabel;
50 Label11: TLabel;
51 Label2: TLabel;
52 Label3: TLabel;
53 Label4: TLabel;
54 Label5: TLabel;
55 Label6: TLabel;
56 Label7: TLabel;
57 Label8: TLabel;
58 LabelBlockCurrent: TLabel;
59 LabelBlockDamaged: TLabel;
60 LabelElapsedTime: TLabel;
61 LabelEstimatedTime: TLabel;
62 LabelIOSpeed: TLabel;
63 LabelSectorCount: TLabel;
64 LabelSectorPerBlock: TLabel;
65 LabelSectorSize: TLabel;
66 LabelSize: TLabel;
67 LastOpenedList1: TLastOpenedList;
68 ListView1: TListView;
69 MainMenu1: TMainMenu;
70 MenuItem1: TMenuItem;
71 MenuItem10: TMenuItem;
72 MenuItem11: TMenuItem;
73 MenuItem12: TMenuItem;
74 MenuItem13: TMenuItem;
75 MenuItem14: TMenuItem;
76 MenuItem15: TMenuItem;
77 MenuItem16: TMenuItem;
78 MenuItem17: TMenuItem;
79 MenuItem18: TMenuItem;
80 MenuItem19: TMenuItem;
81 MenuItem20: TMenuItem;
82 MenuItem21: TMenuItem;
83 MenuItem22: TMenuItem;
84 MenuItem23: TMenuItem;
85 MenuItemOpenRecent: TMenuItem;
86 MenuItem2: TMenuItem;
87 MenuItem3: TMenuItem;
88 MenuItem4: TMenuItem;
89 MenuItem5: TMenuItem;
90 MenuItem6: TMenuItem;
91 MenuItem7: TMenuItem;
92 MenuItem8: TMenuItem;
93 MenuItem9: TMenuItem;
94 OpenDialog1: TOpenDialog;
95 PageControl1: TPageControl;
96 Panel2: TPanel;
97 Panel3: TPanel;
98 Panel4: TPanel;
99 PopupMenu1: TPopupMenu;
100 SaveDialog1: TSaveDialog;
101 Splitter1: TSplitter;
102 Splitter2: TSplitter;
103 TabSheetSectors: TTabSheet;
104 TabSheetSpeed: TTabSheet;
105 Timer1: TTimer;
106 ToolBar1: TToolBar;
107 ToolButton1: TToolButton;
108 ToolButton2: TToolButton;
109 ToolButton3: TToolButton;
110 procedure AExitExecute(Sender: TObject);
111 procedure AFileCloseExecute(Sender: TObject);
112 procedure AFileNewExecute(Sender: TObject);
113 procedure AFileOpenExecute(Sender: TObject);
114 procedure AFileSaveAsExecute(Sender: TObject);
115 procedure AFileSaveExecute(Sender: TObject);
116 procedure AOperationAddExecute(Sender: TObject);
117 procedure AOperationOptionsExecute(Sender: TObject);
118 procedure AOperationRemoveExecute(Sender: TObject);
119 procedure AProjectOptionsExecute(Sender: TObject);
120 procedure AScanContinueExecute(Sender: TObject);
121 procedure AScanStartExecute(Sender: TObject);
122 procedure AScanStopExecute(Sender: TObject);
123 procedure AShowAboutExecute(Sender: TObject);
124 procedure AShowSettingsExecute(Sender: TObject);
125 procedure AViewToolbarExecute(Sender: TObject);
126 procedure ComboBoxDriveChange(Sender: TObject);
127 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
128 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
129 procedure FormCreate(Sender: TObject);
130 procedure FormDestroy(Sender: TObject);
131 procedure FormShow(Sender: TObject);
132 procedure Image1Resize(Sender: TObject);
133 procedure ListView1Data(Sender: TObject; Item: TListItem);
134 procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
135 Selected: Boolean);
136 procedure Timer1Timer(Sender: TObject);
137 private
138 PrefixMultiplier: TPrefixMultiplier;
139 LastBlockPos: Integer;
140 RedrawPending: Boolean;
141 LastDriveName: string;
142 ShowToolBar: Boolean;
143 procedure OpenRecentClick(Sender: TObject);
144 procedure ReloadOperationList;
145 procedure ProjectOpen(FileName: string);
146 procedure DriveScanChange(Sender: TObject);
147 procedure DriveScanTerminate(Sender: TObject);
148 procedure Redraw(Delayed: Boolean = False);
149 procedure DoDraw;
150 procedure UpdateInterface;
151 procedure UpdateSpeedChart;
152 public
153 procedure SaveConfig;
154 procedure LoadConfig;
155 procedure Detect;
156 procedure ShowBuffer(Buffer: array of Byte);
157 end;
158
159var
160 FormMain: TFormMain;
161
162
163implementation
164
165{$R *.lfm}
166
167uses
168 UCore, UFormProject, UFormOperation, UFormAbout, UFormSettings;
169
170resourcestring
171 SModifiedFlag = '(modified)';
172 SNewProject = 'New project';
173 SOpenStoredProject = 'Open stored scan project';
174 SSaveProject = 'Save scan project';
175 SBytes = 'bytes';
176 SProjectModified = 'Project modified';
177 SProjectModifiedQuestion = 'Project was modified. Do you want to save it?';
178
179{ TFormMain }
180
181procedure TFormMain.FormShow(Sender: TObject);
182begin
183 Detect;
184 LoadConfig;
185 Core.LoadConfig;
186 Core.PersistentForm1.Load(Self);
187 if (LastOpenedList1.Items.Count > 0) and FileExists(LastOpenedList1.Items[0]) then
188 ProjectOpen(LastOpenedList1.Items[0])
189 else begin
190 AFileNew.Execute;
191 Redraw;
192 UpdateInterface;
193 end;
194 PageControl1.TabIndex := 0;
195end;
196
197procedure TFormMain.Image1Resize(Sender: TObject);
198begin
199 Redraw;
200end;
201
202procedure TFormMain.ListView1Data(Sender: TObject; Item: TListItem);
203begin
204 with Core.Project do
205 if (Item.Index >= 0) and (Item.Index < Scans.Count) then
206 with TDriveScan(Scans[Scans.Count - 1 - Item.Index]) do begin
207 Item.Caption := GetName;
208 Item.Data := TDriveScan(Scans[Scans.Count - 1 - Item.Index]);
209 Item.SubItems.Add(DateTimeToStr(TimeStart));
210 Item.SubItems.Add(DateTimeToStr(TimeEnd));
211 Item.SubItems.Add(IntToStr(SectorStart));
212 Item.SubItems.Add(IntToStr(SectorEnd));
213 end;
214end;
215
216procedure TFormMain.ListView1SelectItem(Sender: TObject; Item: TListItem;
217 Selected: Boolean);
218begin
219 if Selected then begin
220 Core.Project.CurrentScan := TDriveScan(Item.Data);
221 Redraw;
222 ReloadOperationList;
223 end;
224end;
225
226procedure TFormMain.FormCreate(Sender: TObject);
227begin
228 PrefixMultiplier := TPrefixMultiplier.Create(nil);
229end;
230
231procedure TFormMain.AScanStopExecute(Sender: TObject);
232begin
233 if Assigned(Core.Project) and Assigned(Core.Project.CurrentScan) then begin
234 Core.Project.CurrentScan.Stop;
235 UpdateInterface;
236 end;
237end;
238
239procedure TFormMain.AShowAboutExecute(Sender: TObject);
240begin
241 FormAbout := TFormAbout.Create(nil);
242 try
243 FormAbout.ApplicationInfo := Core.ApplicationInfo1;
244 FormAbout.ShowModal;
245 finally
246 FreeAndNil(FormAbout);
247 end;
248end;
249
250procedure TFormMain.AShowSettingsExecute(Sender: TObject);
251begin
252 FormSettings := TFormSettings.Create(nil);
253 try
254 FormSettings.Load;
255 if FormSettings.ShowModal = mrOK then
256 FormSettings.Save;
257 finally
258 FreeAndNil(FormSettings);
259 end;
260end;
261
262procedure TFormMain.AViewToolbarExecute(Sender: TObject);
263begin
264 ShowToolBar := not ShowToolBar;
265 ToolBar1.Visible := ShowToolBar;
266 AViewToolbar.Checked := ShowToolBar;
267end;
268
269procedure TFormMain.ComboBoxDriveChange(Sender: TObject);
270begin
271 with Core.Project do
272 if (ComboBoxDrive.ItemIndex <> -1) and (DriveInfo.Path <> TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex]).Path) then begin
273 with TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex]) do
274 if Kind = dkFile then begin
275 OpenDialog1.FileName := Path;
276 if OpenDialog1.Execute and FileExists(OpenDialog1.FileName) then begin
277 Path := OpenDialog1.FileName;
278 Size := FileSize(Path);
279 Model := OpenDialog1.FileName;
280 SectorSize := 4096;
281 Core.DriveList.LoadToStrings(ComboBoxDrive.Items);
282 end;
283 end;
284 DriveInfo.Assign(TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex]));
285 Modified := True;
286 Core.Project.ScanProfile.LoadFromDriveInfo(DriveInfo);
287 UpdateInterface;
288 Redraw;
289 end;
290end;
291
292procedure TFormMain.AScanStartExecute(Sender: TObject);
293begin
294 LastBlockPos := 0;
295 with Core.Project do begin
296 Core.Project.Scans.Add(TDriveScan.Create);
297 Core.Project.CurrentScan := TDriveScan(Core.Project.Scans.Last);
298 CurrentScan.DriveName := DriveInfo.Path;
299 CurrentScan.SectorCount := DriveInfo.SectorCount;
300 CurrentScan.SectorSize := DriveInfo.SectorSize;
301 Core.Project.ScanProfile.SectorCount := Core.Project.DriveInfo.SectorCount;
302 CurrentScan.LoadProfile(Core.Project.ScanProfile);;
303 CurrentScan.Reset;
304 CurrentScan.OnChange := DriveScanChange;
305 CurrentScan.OnTerminate := DriveScanTerminate;
306 CurrentScan.Start;
307 Modified := True;
308 end;
309 UpdateInterface;
310end;
311
312procedure TFormMain.AProjectOptionsExecute(Sender: TObject);
313begin
314 FormProject.Load(Core.Project);
315 if FormProject.ShowModal = mrOk then begin
316 FormProject.Save(Core.Project);
317 Core.Project.Modified := True;
318 UpdateInterface;
319 end;
320end;
321
322procedure TFormMain.AScanContinueExecute(Sender: TObject);
323begin
324 Core.Project.CurrentScan.Start;
325 Core.Project.Modified := True;
326 UpdateInterface;
327end;
328
329procedure TFormMain.AExitExecute(Sender: TObject);
330begin
331 Close;
332end;
333
334procedure TFormMain.AFileCloseExecute(Sender: TObject);
335begin
336 FreeAndNil(Core.Project);
337 UpdateInterface;
338end;
339
340procedure TFormMain.AFileNewExecute(Sender: TObject);
341begin
342 AFileClose.Execute;
343 Core.Project := TProject.Create;
344 Core.Project.FileName := SNewProject;
345 Core.Project.Modified := False;
346
347 ComboBoxDrive.ItemIndex := Core.DriveList.IndexOf(Core.DriveList.FindByModel(Core.Project.DriveInfo.Model));
348 if (ComboBoxDrive.ItemIndex = -1) and (ComboBoxDrive.Items.Count > 0) then ComboBoxDrive.ItemIndex := 0;
349 if ComboBoxDrive.ItemIndex <> -1 then
350 Core.Project.DriveInfo.Assign(TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex]));
351 Core.Project.ScanProfile.LoadFromDriveInfo(Core.Project.DriveInfo);
352
353 Redraw;
354 UpdateInterface;
355end;
356
357procedure TFormMain.AFileOpenExecute(Sender: TObject);
358begin
359 OpenDialog1.Title := SOpenStoredProject;
360 OpenDialog1.DefaultExt := '.cdp';
361 if Assigned(Core.Project) then
362 OpenDialog1.FileName := Core.Project.FileName;
363 if OpenDialog1.Execute then begin
364 ProjectOpen(OpenDialog1.FileName);
365 end;
366end;
367
368procedure TFormMain.AFileSaveAsExecute(Sender: TObject);
369begin
370 SaveDialog1.Title := SSaveProject;
371 SaveDialog1.DefaultExt := '.cdp';
372 SaveDialog1.FileName := Core.Project.FileName;
373 if SaveDialog1.Execute then begin
374 Core.Project.SaveToFile(SaveDialog1.FileName);
375 LastOpenedList1.AddItem(SaveDialog1.FileName);
376 LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, OpenRecentClick);
377 UpdateInterface;
378 end;
379end;
380
381procedure TFormMain.AFileSaveExecute(Sender: TObject);
382begin
383 if not FileExists(Core.Project.FileName) then
384 AFileSaveAs.Execute
385 else begin
386 Core.Project.SaveToFile(Core.Project.FileName);
387 LastOpenedList1.AddItem(SaveDialog1.FileName);
388 LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, OpenRecentClick);
389 UpdateInterface;
390 end;
391end;
392
393procedure TFormMain.AOperationAddExecute(Sender: TObject);
394var
395 NewOperation: TDriveScan;
396begin
397 with Core.Project do begin
398 NewOperation := TDriveScan.Create;
399 Scans.Add(NewOperation);
400 CurrentScan := TDriveScan(Scans.Last);
401 CurrentScan.LoadProfile(ScanProfile);
402 CurrentScan.Mode := rmNone;
403 ReloadOperationList;
404 Redraw;
405 Core.Project.Modified := True;
406 end;
407end;
408
409procedure TFormMain.AOperationOptionsExecute(Sender: TObject);
410begin
411 Core.Project.ScanProfile.SectorCount := Core.Project.DriveInfo.SectorCount;
412 FormOperation.Load(Core.Project.ScanProfile);
413 if FormOperation.ShowModal = mrOk then begin
414 FormOperation.Save(Core.Project.ScanProfile);
415 Core.Project.Modified := True;
416 UpdateInterface;
417 end;
418end;
419
420procedure TFormMain.AOperationRemoveExecute(Sender: TObject);
421begin
422 Core.Project.CurrentScan := nil;
423 Core.Project.Scans.Remove(ListView1.Selected.Data);
424 ReloadOperationList;
425 Redraw;
426 Core.Project.Modified := True;
427end;
428
429procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
430begin
431 AFileClose.Execute;
432 SaveConfig;
433 Core.SaveConfig;
434 Core.PersistentForm1.Save(Self);
435end;
436
437procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
438var
439 R: TModalResult;
440begin
441 if Assigned(Core.Project) and Core.Project.Modified then begin
442 R := MessageDlg(SProjectModified, SProjectModifiedQuestion, mtConfirmation, [mbYes, mbNo, mbCancel], 0);
443 if R = mrCancel then begin
444 CanClose := False;
445 Exit;
446 end else
447 if R = mrYes then begin
448 AFileSave.Execute;
449 end;
450 end;
451end;
452
453procedure TFormMain.FormDestroy(Sender: TObject);
454begin
455 Timer1.Enabled := False;
456 FreeAndNil(PrefixMultiplier);
457end;
458
459procedure TFormMain.Redraw(Delayed: Boolean = False);
460begin
461 RedrawPending := True;
462 if not Delayed then DoDraw;
463end;
464
465procedure TFormMain.DoDraw;
466begin
467 if Assigned(Core.Project) and Assigned(Core.Project.CurrentScan) then
468 with Core.Project do begin
469 if RedrawPending then
470 with Image1 do begin
471 if (Width <> Picture.Bitmap.Width) or (Height <> Picture.Bitmap.Height) then
472 Picture.Bitmap.SetSize(Width, Height);
473 try
474 Core.Project.CurrentScan.Lock.Acquire;
475 try
476 Picture.Bitmap.BeginUpdate(True);
477 CurrentScan.BlockMap.Draw(Picture.Bitmap.Canvas);
478 finally
479 Picture.Bitmap.EndUpdate;
480 end;
481 LabelSectorPerBlock.Caption := IntToStr(CurrentScan.BlockMap.SectorPerBlock);
482 LabelBlockCurrent.Caption := IntToStr(CurrentScan.SectorCurrent);
483 LabelBlockDamaged.Caption := IntToStr(CurrentScan.DamagedBlockCount);
484 finally
485 CurrentScan.Lock.Release;
486 end;
487 RedrawPending := False;
488 end;
489 try
490 CurrentScan.Lock.Acquire;
491 if not CurrentScan.Terminated then begin
492 LabelElapsedTime.Caption := TimeToStr(CurrentScan.GetElapsedTime);
493 LabelEstimatedTime.Caption := TimeToStr((Now - CurrentScan.TimeStart) /
494 CurrentScan.SectorCurrent * (CurrentScan.BlockMap.SectorCount - CurrentScan.SectorCurrent));
495 LabelIOSpeed.Caption := PrefixMultiplier.Add((CurrentScan.SectorCurrent - LastBlockPos) *
496 CurrentScan.SectorSize / (Timer1.Interval / 1000), BasePrefixMultipliers, 'B/s');
497 LastBlockPos := CurrentScan.SectorCurrent;
498 end else begin
499 LabelElapsedTime.Caption := '';
500 LabelEstimatedTime.Caption := '';
501 LabelIOSpeed.Caption := '';
502 end;
503 finally
504 CurrentScan.Lock.Release;
505 end;
506 UpdateSpeedChart;
507 end else
508 with Image1 do begin
509 if (Width <> Picture.Bitmap.Width) or (Height <> Picture.Bitmap.Height) then
510 Picture.Bitmap.SetSize(Width, Height);
511 with Picture.Bitmap.Canvas do begin
512 Brush.Style := bsSolid;
513 Brush.Color := clSilver;
514 FillRect(0, 0, Width, Height);
515 end;
516 end;
517end;
518
519procedure TFormMain.UpdateInterface;
520var
521 Title: string;
522begin
523 with Core do begin
524 if Assigned(Project) then begin
525 AScanStart.Enabled := (Assigned(Project.CurrentScan) and (Project.CurrentScan.Terminated = True)) or not Assigned(Project.CurrentScan);
526 AScanStop.Enabled := Assigned(Project.CurrentScan) and (Project.CurrentScan.Terminated = False);
527 AScanContinue.Enabled := Assigned(Project.CurrentScan) and (Project.CurrentScan.Terminated = True) and
528 (Project.CurrentScan.SectorCurrent > Project.CurrentScan.SectorStart) and
529 (Project.CurrentScan.SectorCurrent < Project.CurrentScan.SectorEnd);
530 end else begin
531 AScanStart.Enabled := False;
532 AScanStop.Enabled := False;
533 AScanContinue.Enabled := False;
534 end;
535 AFileSave.Enabled := Assigned(Project) and Project.Modified;
536 AFileSaveAs.Enabled := Assigned(Project);
537 AFileClose.Enabled := Assigned(Project);
538 ComboBoxDrive.Enabled := Assigned(Project);
539 AProjectOptions.Enabled := Assigned(Project);;
540 AOperationOptions.Enabled := Assigned(Project);;
541 ReloadOperationList;
542
543 Title := '';
544 if Assigned(Project) then
545 Title := Title + ExtractFileName(Project.FileName) + ' - ';
546 Title := Title + Application.Title;
547 if Assigned(Project) and Project.Modified then
548 Title := Title + ' ' + SModifiedFlag;
549 Caption := Title;
550
551 if Assigned(Project) then begin
552 LabelSize.Caption := PrefixMultiplier.Add(Project.DriveInfo.Size,
553 BasePrefixMultipliers, SBytes);
554 LabelSectorCount.Caption := IntToStr(Project.DriveInfo.SectorCount);
555 LabelSectorSize.Caption := PrefixMultiplier.Add(Project.DriveInfo.SectorSize, BasePrefixMultipliers, SBytes);
556 end else begin
557 LabelSize.Caption := '';
558 LabelSectorCount.Caption := '';
559 LabelSectorSize.Caption := '';
560 end;
561 end;
562end;
563
564procedure TFormMain.UpdateSpeedChart;
565var
566 I: Integer;
567begin
568 if TabSheetSpeed.Visible then
569 if Assigned(Core.Project) then
570 with Core.Project do
571 if Assigned(CurrentScan) then
572 with CurrentScan do begin
573 ChartSpeed.BottomAxis.Range.UseMax := True;
574 ChartSpeed.BottomAxis.Range.Max := Length(SpeedSteps);
575 ChartSpeedLineSeriesAvg.Clear;
576 ChartSpeedLineSeriesMin.Clear;
577 ChartSpeedLineSeriesMax.Clear;
578 for I := 0 to Length(SpeedSteps) - 1 do
579 if not SpeedSteps[I].Null then begin
580 ChartSpeedLineSeriesAvg.AddXY(I, SpeedSteps[I].Average / (1024 * 1024));
581 ChartSpeedLineSeriesMin.AddXY(I, SpeedSteps[I].Min / (1024 * 1024));
582 ChartSpeedLineSeriesMax.AddXY(I, SpeedSteps[I].Max / (1024 * 1024));
583 end;
584 end;
585end;
586
587procedure TFormMain.SaveConfig;
588begin
589 Core.XMLConfig1.SetValue('DriveName', UnicodeString(LastDriveName));
590 LastOpenedList1.SaveToXMLConfig(Core.XMLConfig1, 'RecentProjects');
591 Core.XMLConfig1.SetValue('ShowToolBar', ShowToolBar);
592end;
593
594procedure TFormMain.LoadConfig;
595begin
596 LastDriveName := string(Core.XMLConfig1.GetValue('DriveName', UnicodeString('')));
597 LastOpenedList1.LoadFromXMLConfig(Core.XMLConfig1, 'RecentProjects');
598 ShowToolBar := Core.XMLConfig1.GetValue('ShowToolBar', False);
599 ToolBar1.Visible := ShowToolBar;
600 AViewToolbar.Checked := ShowToolBar;
601end;
602
603procedure TFormMain.Timer1Timer(Sender: TObject);
604begin
605 Redraw;
606end;
607
608procedure TFormMain.OpenRecentClick(Sender: TObject);
609begin
610 ProjectOpen(TMenuItem(Sender).Caption);
611end;
612
613procedure TFormMain.ReloadOperationList;
614begin
615 if Assigned(Core.Project) then begin
616 ListView1.Items.Count := Core.Project.Scans.Count;
617 end else begin
618 ListView1.Items.Count := 0;
619 end;
620 ListView1.Refresh;
621
622 AOperationRemove.Enabled := Assigned(ListView1.Selected);
623end;
624
625procedure TFormMain.ProjectOpen(FileName: string);
626begin
627 AFileNew.Execute;
628 Core.Project.LoadFromFile(FileName);
629 ComboBoxDrive.ItemIndex := Core.DriveList.IndexOf(Core.DriveList.FindByModel(Core.Project.DriveInfo.Model));
630 if (ComboBoxDrive.ItemIndex = -1) and (ComboBoxDrive.Items.Count > 0) then ComboBoxDrive.ItemIndex := 0;
631 LastOpenedList1.AddItem(FileName);
632 LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, OpenRecentClick);
633 UpdateInterface;
634 Redraw;
635end;
636
637procedure TFormMain.DriveScanChange(Sender: TObject);
638begin
639 RedrawPending := True;
640end;
641
642procedure TFormMain.DriveScanTerminate(Sender: TObject);
643begin
644 UpdateInterface;
645end;
646
647procedure TFormMain.Detect;
648begin
649 Core.DriveList.Detect;
650 Core.DriveList.LoadToStrings(ComboBoxDrive.Items);
651end;
652
653procedure TFormMain.ShowBuffer(Buffer: array of Byte);
654const
655 BytePerRow = 16;
656var
657 Row: string;
658 I: Integer;
659 Item: TListItem;
660begin
661 ListView1.Clear;
662 Row := '';
663 for I := 0 to Length(Buffer) do begin
664 Row := Row + IntToHex(Buffer[I], 2) + ' ';
665 if ((I mod BytePerRow) = (BytePerRow - 1)) or (I = (Length(Buffer) - 1)) then begin
666 Item := ListView1.Items.Add;
667 Item.Caption := '';
668 Item.SubItems.Add(Row);
669 Row := '';
670 end;
671 end;
672end;
673
674end.
675
Note: See TracBrowser for help on using the repository browser.