procedure TFormCreateIso.ripDrive(
const driveRoot, fileIso:
String);
const
chunk_size = 4096 * 10;
var
buffer:PChar;
_fileHandle,bytesReaded,Written:LongWord;
_totBytes:int64;
_r:boolean;
fp:
file of byte;
begin
cmrip.Enabled:=false;
cmClose.Enabled:=false;
cmStop.Enabled:=false;
GetMem(buffer,chunk_size);
_fileHandle:=CreateFile(PChar('
\\.\' + driveRoot),GENERIC_READ,0,
nil,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL
or FILE_FLAG_SEQUENTIAL_SCAN,0);
bytesReaded:=chunk_size;
_totBytes:=0;
_r:=true;
stopRun:=false;
try
if _fileHandle = INVALID_HANDLE_VALUE
then
begin
raise Exception.Create('
Errore opening: ' + '
\\.\' + driveRoot);
exit;
end;
AssignFile(fp,fileIso);
Rewrite(fp);
Written:=chunk_size;
while (bytesReaded = chunk_size)
and (_r)
and (Written = chunk_size)
and (
not stopRun)
do
begin
_r:=ReadFile(_fileHandle,buffer^,chunk_size,bytesReaded,
nil);
BlockWrite(fp,buffer^,chunk_size,Written);
Inc(_totBytes,bytesReaded);
if _totBytes
mod (chunk_size * 10) = 0
then
begin
lblTot.Caption:=IntToStr(_totBytes);
Application.ProcessMessages;
end;
end;
finally
CloseFile(fp);
if _fileHandle <> INVALID_HANDLE_VALUE
then
CloseHandle(_fileHandle);
if buffer <>
nil then FreeMem(buffer);
cmrip.Enabled:=True;
cmClose.Enabled:=True;
cmStop.Enabled:=True;
end;
end;