function SplitFile(Filename, DestFolder:
string; SplitSize, CntParts: Int64): Int64;
const
//BLOCKSIZE = 1048544;
BLOCKSIZE = 32767;
resourcestring
ChangeDiskMsg = '
Legen sie die nächste Diskette in Laufwerk a: ein.';
var
hFile : THandle;
SizeOfFile : Int64;
// >4GB
hPart : THandle;
Loop : Cardinal;
Partname :
string;
MemBuffer :
array[0..BLOCKSIZE - 1]
of Byte;
BytesToRead, BytesRead, BytesWritten: Int64;
TotalBytesRead, OverallBytesRead: Int64;
ProgressCurrent, ProgressOld: Cardinal;
begin
bRunning := 1;
OverallBytesRead := 0;
SizeOfFile := GetFileSize(PChar(Filename));
hFile := FileOpen(Filename, $0000);
if hFile <> INVALID_HANDLE_VALUE
then
begin
for Loop := 1
to CntParts
do
begin
// Reset variables
TotalBytesRead := 0;
ProgressOld := 0;
BytesToRead := SplitSize;
// build filename of the parts
Partname := DestFolder + '
\' + ExtractFilename(Filename) + Format('
.%3.3d', [Loop]);
if FileExists(Partname)
then
DeleteFile(PChar(Partname));
hPart := FileCreate(Partname);
if hPart <> INVALID_HANDLE_VALUE
then
begin
repeat
BytesRead := FileRead(hFile, MemBuffer, Min(sizeof(MemBuffer), BytesToRead));
BytesWritten := FileWrite(hPart, MemBuffer, BytesRead);
Dec(BytesToRead, sizeof(MemBuffer));
// progress stuff ////////////////////////////////////////////////////
TotalBytesRead := TotalBytesRead + BytesWritten;
OverallBytesRead := OverallBytesRead + BytesWritten;
ProgressCurrent := (OverallBytesRead * 100)
div SizeOfFile;
if ProgressCurrent <> ProgressOld
then
begin
ProgressOld := ProgressCurrent;
end;
SendMessage(hApp, FSM_PROGRESS, ProgressCurrent, Integer(PChar(Partname)));
//////////////////////////////////////////////////////////////////////
until (BytesToRead <= 0)
or (bRunning = 0);
end;
FileClose(hPart);
if bRunning = 0
then
Break;
if (DestFolder = '
a:\')
and (Loop < CntParts)
then
begin
if MessageBox(0, PChar(ChangeDiskMsg), APPNAME, MB_ICONINFORMATION
or MB_OKCANCEL) = ID_CANCEL
then
begin
bRunning := 0;
break;
end;
end;
end;
FileClose(hFile);
end;
SendMessage(hApp, FSM_FINISH, 0, GetLastError());
result := GetLastError();
end;