Connected to this thread (
http://www.lazarus.freepascal.org/index.php/topic,12230.0.html) but slightly different, thus the new question.
I have a Button and a ListBox on my form. When the button is pressed the ListBox is populated with all
logical drives on the computer. I have an OnClick event for the ListBox for whatever logical drive the user clicks with his mouse. I then want the program to hash that chosen drive using the SHA1Hash and SHA1Print functions.
Initially, I realised the generated hash was that of the string representation of the drive letter, i.e the hash of chars "C:\" (because I passed it ListBox1.Items[index]).
So I then added a TFileSearcher element to the mix as I've used that successfully for recursively finding files and then hashing them. As far as I can tell though, in this newer implementation that I'm trying, it seems to find all the files on the chosen drive and shows me the final hash value of the final file it finds.
So, how can I get my program to hash the actual logical drive (i.e. the whole partition) that is represented by the content of ListBox1.Items[index], i.e. Drive C:\, D:\ or whatever?
My code so far (which gives me the final hash of the final file, not the volume):
procedure TForm1.ListBox1Click(Sender: TObject);
var
index : integer;
FS : TFileSearcher;
DriveToHash, DriveHashValue : string;
begin
index := ListBox1.ItemIndex;
if MessageDlg('Hash selected drive?', 'Are you sure you wish to hash "'+ ListBox1.Items[index] + '"',
mtConfirmation, [mbYes, mbNo],0) = mrYes
then
begin
FS := TFileSearcher.Create;
DriveToHash := (ListBox1.Items[index]);
FS.Search(DriveToHash, '*.*', True);
DriveHashValue := SHA1Print(SHA1File(DriveToHash));
FS.Free;
ShowMessage(DriveHashValue);
end;
end;