ADD: Verify file with manually input checksum (patch by Rustem with some modifications)

This commit is contained in:
Alexander Koblov 2013-10-19 12:52:17 +00:00
commit 46c0995df6
4 changed files with 84 additions and 5 deletions

View file

@ -3,7 +3,7 @@
-------------------------------------------------------------------------
Calculate check sum dialog
Copyright (C) 2009-2011 Koblov Alexander (Alexx2000@mail.ru)
Copyright (C) 2009-2013 Alexander Koblov (alexx2000@mail.ru)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -43,6 +43,7 @@ type
lblSaveTo: TLabel;
procedure cbSeparateFileChange(Sender: TObject);
procedure cmbHashAlgorithmChange(Sender: TObject);
procedure edtSaveToChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
@ -55,12 +56,15 @@ type
function ShowCalcCheckSum(var sFileName: UTF8String; out SeparateFile: Boolean;
out HashAlgorithm: THashAlgorithm): Boolean;
function ShowCalcVerifyCheckSum(out Hash: String;
out HashAlgorithm: THashAlgorithm): Boolean;
implementation
{$R *.lfm}
uses
uGlobs;
uGlobs, uLng;
function ShowCalcCheckSum(var sFileName: UTF8String; out SeparateFile: Boolean;
out HashAlgorithm: THashAlgorithm): Boolean;
@ -81,6 +85,34 @@ begin
end;
end;
function ShowCalcVerifyCheckSum(out Hash: String;
out HashAlgorithm: THashAlgorithm): Boolean;
begin
with TfrmCheckSumCalc.Create(Application) do
try
OnShow:= nil;
SessionProperties:= EmptyStr;
Caption:= rsCheckSumVerifyTitle;
cbSeparateFile.Visible:= False;
cmbHashAlgorithm.OnChange:= nil;
edtSaveTo.OnChange:= @edtSaveToChange;
lblSaveTo.Caption:= rsCheckSumVerifyText;
cmbHashAlgorithm.Anchors:= [akTop, akLeft, akRight];
cmbHashAlgorithm.AnchorSide[akRight].Side:= asrRight;
cmbHashAlgorithm.AnchorSide[akRight].Control:= edtSaveTo;
Result:= (ShowModal = mrOK);
if Result then
begin
Hash:= Trim(edtSaveTo.Text);
Result:= Length(Hash) > 0;
HashAlgorithm:= THashAlgorithm(cmbHashAlgorithm.ItemIndex);
end;
finally
Free;
end;
end;
{ TfrmCheckSumCalc }
procedure TfrmCheckSumCalc.cbSeparateFileChange(Sender: TObject);
@ -97,6 +129,18 @@ begin
edtSaveTo.Text:= ChangeFileExt(edtSaveTo.Text, '.' + HashFileExt[FAlgorithm]);
end;
procedure TfrmCheckSumCalc.edtSaveToChange(Sender: TObject);
begin
case Length(Trim(edtSaveTo.Text)) of
8: cmbHashAlgorithm.ItemIndex:= Integer(HASH_SFV);
32: cmbHashAlgorithm.ItemIndex:= Integer(HASH_MD5);
40: cmbHashAlgorithm.ItemIndex:= Integer(HASH_SHA1);
64: cmbHashAlgorithm.ItemIndex:= Integer(HASH_SHA256);
96: cmbHashAlgorithm.ItemIndex:= Integer(HASH_SHA384);
128: cmbHashAlgorithm.ItemIndex:= Integer(HASH_SHA512);
end;
end;
procedure TfrmCheckSumCalc.FormCreate(Sender: TObject);
var
I: THashAlgorithm;

View file

@ -202,6 +202,27 @@ var
Entry: TChecksumEntry;
begin
FFullFilesTree := TFiles.Create(Files.Path);
if Length(TargetPath) > 0 then
begin
aFileToVerify := Files[0].Clone;
with FStatistics do
begin
TotalFiles := TotalFiles + 1;
TotalBytes := TotalBytes + aFileToVerify.Size;
end;
FFullFilesTree.Add(aFileToVerify);
Entry := TChecksumEntry.Create;
FChecksumsList.Add(Entry);
Entry.Checksum := TargetPath;
Entry.Algorithm := Algorithm;
CheckOperationState;
Exit;
end;
FChecksumsList.Clear;
for CurrentFileIndex := 0 to Files.Count - 1 do
begin

View file

@ -357,6 +357,9 @@ resourcestring
// MultiRename dialog
rsMulRenFileNameStyleList = 'No change;UPPERCASE;lowercase;First char uppercase;' +
'First Char Of Every Word Uppercase;';
// CheckSumCalcVerify dialog
rsCheckSumVerifyTitle = 'Verify checksum';
rsCheckSumVerifyText = 'Enter checksum and select algorithm:';
// Drive status
rsDriveNoMedia = '<no media>';
rsDriveNoLabel = '<no label>';

View file

@ -1725,7 +1725,9 @@ end;
procedure TMainCommands.cm_CheckSumVerify(const Params: array of string);
var
I: Integer;
Hash: String;
SelectedFiles: TFiles;
Algorithm: THashAlgorithm;
Operation: TFileSourceCalcChecksumOperation;
begin
// This will work only for filesystem.
@ -1753,15 +1755,24 @@ begin
for I := 0 to SelectedFiles.Count - 1 do // find files in selection
if not FileExtIsHash(SelectedFiles[I].Extension) then
begin
msgError(rsMsgSelectOnlyCheckSumFiles);
Exit;
if (SelectedFiles.Count > 1) or (SelectedFiles[I].IsDirectory) or
(SelectedFiles[I].IsLinkToDirectory) then
begin
msgError(rsMsgSelectOnlyCheckSumFiles);
Exit;
end
else begin
if not ShowCalcVerifyCheckSum(Hash, Algorithm) then
Exit;
end
end;
Operation := ActiveFrame.FileSource.CreateCalcChecksumOperation(
SelectedFiles, '', '') as TFileSourceCalcChecksumOperation;
SelectedFiles, Hash, '') as TFileSourceCalcChecksumOperation;
if Assigned(Operation) then
begin
Operation.Algorithm := Algorithm;
Operation.AddStateChangedListener([fsosStopped], @OnCalcChecksumStateChanged);
Operation.Mode := checksum_verify;