Changeset 13 for trunk/Form/UFormMain.pas
- Timestamp:
- Apr 2, 2016, 1:06:34 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Form/UFormMain.pas
r12 r13 14 14 15 15 TFormMain = class(TForm) 16 A BrowseDisk: TAction;16 ADriveSelect: TAction; 17 17 AOperationOptions: TAction; 18 18 AFileClose: TAction; … … 34 34 ComboBoxDrive: TComboBox; 35 35 Image1: TImage; 36 ImageList1: TImageList; 36 37 Label1: TLabel; 37 38 Label10: TLabel; … … 45 46 Label8: TLabel; 46 47 LabelElapsedTime: TLabel; 47 Label BlockSize: TLabel;48 Label BlockCount: TLabel;48 LabelSectorSize: TLabel; 49 LabelSectorCount: TLabel; 49 50 LabelBlockCurrent: TLabel; 50 51 LabelBlockDamaged: TLabel; … … 73 74 SaveDialog1: TSaveDialog; 74 75 Timer1: TTimer; 76 ToolBar1: TToolBar; 77 ToolButton1: TToolButton; 78 ToolButton2: TToolButton; 79 ToolButton3: TToolButton; 75 80 XMLConfig1: TXMLConfig; 76 81 procedure AExitExecute(Sender: TObject); … … 87 92 procedure ComboBoxDriveChange(Sender: TObject); 88 93 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 94 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); 89 95 procedure FormCreate(Sender: TObject); 90 96 procedure FormDestroy(Sender: TObject); … … 98 104 RedrawPending: Boolean; 99 105 LastProjectFileName: string; 106 LastDriveName: string; 100 107 procedure ReloadOperationList; 101 108 procedure ProjectOpen(FileName: string); … … 107 114 public 108 115 DriveList: TDriveList; 109 DriveScan: TDriveScan;110 116 Project: TProject; 111 117 procedure SaveConfig; … … 126 132 127 133 resourcestring 128 S ProjectModified= '(modified)';134 SModifiedFlag = '(modified)'; 129 135 SNewProject = 'New project'; 130 136 SSelectDriveForScan = 'Select drive for scan'; … … 132 138 SSaveProject = 'Save scan project'; 133 139 SBytes = 'bytes'; 140 SProjectModified = 'Project modified'; 141 SProjectModifiedQuestion = 'Project was modified. Do you want to save it?'; 134 142 135 143 { TFormMain } … … 175 183 procedure TFormMain.AScanStopExecute(Sender: TObject); 176 184 begin 177 DriveScan.Stop; 178 UpdateInterface; 185 if Assigned(Project) and Assigned(Project.CurrentScan) then begin 186 Project.CurrentScan.Stop; 187 UpdateInterface; 188 end; 179 189 end; 180 190 181 191 procedure TFormMain.ComboBoxDriveChange(Sender: TObject); 182 192 begin 183 DriveScan.SectorCount := TDriveInfo(DriveList[ComboBoxDrive.ItemIndex]).SectorCount; 184 DriveScan.DriveName := TDriveInfo(DriveList[ComboBoxDrive.ItemIndex]).Path; 185 DriveScan.SectorStart := 0; 186 DriveScan.SectorEnd := DriveScan.SectorCount - 1; 193 if Project.DriveInfo.Path <> TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex]).Path then begin 194 Project.DriveInfo.Assign(TDriveInfo(ComboBoxDrive.Items.Objects[ComboBoxDrive.ItemIndex])); 195 Project.Modified := True; 196 Project.CurrentScan.SectorCount := Project.DriveInfo.SectorCount; 197 Project.CurrentScan.SectorSize := Project.DriveInfo.SectorSize; 198 Project.CurrentScan.SectorStart := 0; 199 Project.CurrentScan.SectorEnd := Project.CurrentScan.SectorCount - 1; 200 Project.CurrentScan.Reset; 201 UpdateInterface; 202 Redraw; 203 end; 187 204 end; 188 205 … … 190 207 begin 191 208 LastBlockPos := 0; 192 DriveScan.DriveName := TDriveInfo(DriveList[ComboBoxDrive.ItemIndex]).Path;193 DriveScan.Reset;194 DriveScan.SectorSize := Project.SectorSize;195 DriveScan.OnChange := DriveScanChange;196 DriveScan.OnTerminate := DriveScanTerminate;197 DriveScan.Start;209 Project.CurrentScan.DriveName := Project.DriveInfo.Path; 210 Project.CurrentScan.SectorSize := Project.DriveInfo.SectorSize; 211 Project.CurrentScan.Reset; 212 Project.CurrentScan.OnChange := DriveScanChange; 213 Project.CurrentScan.OnTerminate := DriveScanTerminate; 214 Project.CurrentScan.Start; 198 215 Project.Modified := True; 199 216 UpdateInterface; … … 212 229 procedure TFormMain.AScanContinueExecute(Sender: TObject); 213 230 begin 214 DriveScan.Start;231 Project.CurrentScan.Start; 215 232 Project.Modified := True; 216 233 UpdateInterface; … … 224 241 procedure TFormMain.AFileCloseExecute(Sender: TObject); 225 242 begin 226 DriveScan := nil;227 243 FreeAndNil(Project); 228 244 UpdateInterface; … … 236 252 Project.Modified := False; 237 253 Project.Scans.Add(TDriveScan.Create); 238 DriveScan := TDriveScan(Project.Scans[0]); 239 240 DriveScan.SectorStart:= 0;241 DriveScan.SectorEnd := DriveScan.SectorCount - 1;242 DriveScan.Reset; 254 255 ComboBoxDrive.ItemIndex := DriveList.IndexOf(DriveList.FindByModel(Project.DriveInfo.Model)); 256 if (ComboBoxDrive.ItemIndex = -1) and (ComboBoxDrive.Items.Count > 0) then ComboBoxDrive.ItemIndex := 0; 257 ComboBoxDriveChange(Self); 258 243 259 Redraw; 244 260 UpdateInterface; … … 279 295 procedure TFormMain.AOperationOptionsExecute(Sender: TObject); 280 296 begin 281 FormOperation.Load( DriveScan);297 FormOperation.Load(Project.CurrentScan); 282 298 if FormOperation.ShowModal = mrOk then begin 283 FormOperation.Save( DriveScan);299 FormOperation.Save(Project.CurrentScan); 284 300 Project.Modified := True; 285 301 UpdateInterface; … … 291 307 AFileClose.Execute; 292 308 SaveConfig; 309 end; 310 311 procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean); 312 var 313 R: TModalResult; 314 begin 315 if Assigned(Project) and Project.Modified then begin 316 R := MessageDlg(SProjectModified, SProjectModifiedQuestion, mtConfirmation, [mbYes, mbNo, mbCancel], 0); 317 if R = mrCancel then begin 318 CanClose := False; 319 Exit; 320 end else 321 if R = mrYes then begin 322 AFileSave.Execute; 323 end; 324 end; 293 325 end; 294 326 … … 315 347 Picture.Bitmap.SetSize(Width, Height); 316 348 try 317 DriveScan.Lock.Acquire;349 Project.CurrentScan.Lock.Acquire; 318 350 try 319 351 Picture.Bitmap.BeginUpdate(True); 320 DriveScan.BlockMap.Draw(Picture.Bitmap.Canvas);352 Project.CurrentScan.BlockMap.Draw(Picture.Bitmap.Canvas); 321 353 finally 322 354 Picture.Bitmap.EndUpdate; 323 355 end; 324 LabelSize.Caption := PrefixMultiplier.Add(DriveScan.BlockMap.SectorCount * DriveScan.SectorSize, 325 BasePrefixMultipliers, SBytes); 326 LabelSectorPerBlock.Caption := IntToStr(DriveScan.BlockMap.SectorPerBlock); 327 LabelBlockSize.Caption := IntToStr(DriveScan.SectorSize) + ' ' + SBytes; 328 LabelBlockCount.Caption := IntToStr(DriveScan.BlockMap.SectorCount); 329 LabelBlockCurrent.Caption := IntToStr(DriveScan.SectorCurrent); 330 LabelBlockDamaged.Caption := IntToStr(DriveScan.DamagedBlockCount); 356 LabelSectorPerBlock.Caption := IntToStr(Project.CurrentScan.BlockMap.SectorPerBlock); 357 LabelBlockCurrent.Caption := IntToStr(Project.CurrentScan.SectorCurrent); 358 LabelBlockDamaged.Caption := IntToStr(Project.CurrentScan.DamagedBlockCount); 331 359 finally 332 DriveScan.Lock.Release;360 Project.CurrentScan.Lock.Release; 333 361 end; 334 362 RedrawPending := False; 335 363 end; 336 364 try 337 DriveScan.Lock.Acquire;338 if not DriveScan.Terminated then begin339 LabelElapsedTime.Caption := TimeToStr( DriveScan.GetElapsedTime);340 LabelEstimatedTime.Caption := TimeToStr((Now - DriveScan.TimeStart) /341 DriveScan.SectorCurrent * (DriveScan.BlockMap.SectorCount - DriveScan.SectorCurrent));342 LabelIOSpeed.Caption := PrefixMultiplier.Add(( DriveScan.SectorCurrent - LastBlockPos) *343 DriveScan.SectorSize / (Timer1.Interval / 1000), BasePrefixMultipliers, 'B/s');344 LastBlockPos := DriveScan.SectorCurrent;365 Project.CurrentScan.Lock.Acquire; 366 if not Project.CurrentScan.Terminated then begin 367 LabelElapsedTime.Caption := TimeToStr(Project.CurrentScan.GetElapsedTime); 368 LabelEstimatedTime.Caption := TimeToStr((Now - Project.CurrentScan.TimeStart) / 369 Project.CurrentScan.SectorCurrent * (Project.CurrentScan.BlockMap.SectorCount - Project.CurrentScan.SectorCurrent)); 370 LabelIOSpeed.Caption := PrefixMultiplier.Add((Project.CurrentScan.SectorCurrent - LastBlockPos) * 371 Project.CurrentScan.SectorSize / (Timer1.Interval / 1000), BasePrefixMultipliers, 'B/s'); 372 LastBlockPos := Project.CurrentScan.SectorCurrent; 345 373 end else begin 346 374 LabelElapsedTime.Caption := ''; … … 349 377 end; 350 378 finally 351 DriveScan.Lock.Release;379 Project.CurrentScan.Lock.Release; 352 380 end; 353 381 end else … … 367 395 Title: string; 368 396 begin 369 if Assigned(DriveScan) then begin 370 AScanStart.Enabled := DriveScan.Terminated = True; 371 AScanStop.Enabled := DriveScan.Terminated = False; 372 AScanContinue.Enabled := (DriveScan.Terminated = True) and (DriveScan.SectorCurrent > DriveScan.SectorStart) and 373 (DriveScan.SectorCurrent < DriveScan.SectorEnd); 397 if Assigned(Project) and Assigned(Project.CurrentScan) then begin 398 AScanStart.Enabled := Project.CurrentScan.Terminated = True; 399 AScanStop.Enabled := Project.CurrentScan.Terminated = False; 400 AScanContinue.Enabled := (Project.CurrentScan.Terminated = True) and 401 (Project.CurrentScan.SectorCurrent > Project.CurrentScan.SectorStart) and 402 (Project.CurrentScan.SectorCurrent < Project.CurrentScan.SectorEnd); 403 end else begin 404 AScanStart.Enabled := False; 405 AScanStop.Enabled := False; 406 AScanContinue.Enabled := False; 374 407 end; 375 408 AFileSave.Enabled := Assigned(Project) and Project.Modified; 376 409 AFileSaveAs.Enabled := Assigned(Project); 377 410 AFileClose.Enabled := Assigned(Project); 411 ComboBoxDrive.Enabled := Assigned(Project); 412 AProjectOptions.Enabled := Assigned(Project);; 413 AOperationOptions.Enabled := Assigned(Project);; 378 414 ReloadOperationList; 379 415 … … 383 419 Title := Title + Application.Title; 384 420 if Assigned(Project) and Project.Modified then 385 Title := Title + ' ' + S ProjectModified;421 Title := Title + ' ' + SModifiedFlag; 386 422 Caption := Title; 423 424 if Assigned(Project) then begin 425 LabelSize.Caption := PrefixMultiplier.Add(Project.DriveInfo.Size, 426 BasePrefixMultipliers, SBytes); 427 LabelSectorCount.Caption := IntToStr(Project.DriveInfo.SectorCount); 428 LabelSectorSize.Caption := IntToStr(Project.DriveInfo.SectorSize) + ' ' + SBytes; 429 end else begin 430 LabelSize.Caption := ''; 431 LabelSectorCount.Caption := ''; 432 LabelSectorSize.Caption := ''; 433 end; 387 434 end; 388 435 389 436 procedure TFormMain.SaveConfig; 390 437 begin 391 XMLConfig1.SetValue('DriveName', TDriveInfo(DriveList[ComboBoxDrive.ItemIndex]).Model);438 XMLConfig1.SetValue('DriveName', LastDriveName); 392 439 XMLConfig1.SetValue('LastProjectFileName', LastProjectFileName); 393 440 end; … … 395 442 procedure TFormMain.LoadConfig; 396 443 begin 397 ComboBoxDrive.ItemIndex := DriveList.IndexOf(DriveList.FindByModel(XMLConfig1.GetValue('DriveName', '')));444 LastDriveName := XMLConfig1.GetValue('DriveName', ''); 398 445 LastProjectFileName := XMLConfig1.GetValue('LastProjectFileName', ''); 399 446 end; … … 418 465 AFileNew.Execute; 419 466 Project.LoadFromFile(FileName); 467 ComboBoxDrive.ItemIndex := DriveList.IndexOf(DriveList.FindByModel(Project.DriveInfo.Model)); 468 if (ComboBoxDrive.ItemIndex = -1) and (ComboBoxDrive.Items.Count > 0) then ComboBoxDrive.ItemIndex := 0; 420 469 LastProjectFileName := FileName; 421 470 UpdateInterface; … … 438 487 begin 439 488 DriveList.Detect; 440 while ComboBoxDrive.Items.Count > DriveList.Count do 441 ComboBoxDrive.Items.Delete(ComboBoxDrive.Items.Count - 1); 442 while ComboBoxDrive.Items.Count < DriveList.Count do 443 ComboBoxDrive.Items.Add(''); 444 for I := 0 to DriveList.Count - 1 do 445 ComboBoxDrive.Items[I] := TDriveInfo(DriveList[I]).Model + ' (' + 446 PrefixMultiplier.Add(TDriveInfo(DriveList[I]).Size, BasePrefixMultipliers, 'B') + ')'; 489 DriveList.LoadToStrings(ComboBoxDrive.Items); 447 490 end; 448 491
Note:
See TracChangeset
for help on using the changeset viewer.