function SplitFile(Filename, DestFolder:
string; SplitSize, CntParts: Cardinal):
Integer;
const
BLOCKSIZE = 32767;
resourcestring
ChangeDiskMsg = '
Legen sie die nächste Diskette in Laufwerk a: ein.';
var
hFile: Integer;
SizeOfFile: Cardinal;
hPart: Integer;
Loop: Integer;
Partname:
string;
MemBuffer:
array[0..BLOCKSIZE - 1]
of Byte;
BytesToRead, BytesRead, BytesWritten: Integer;
TotalBytesRead, OverallBytesRead: Int64;
ProgressCurrent, ProgressOld: Cardinal;
begin
bRunning := 1;
OverallBytesRead := 0;
SizeOfFile := GetFileSize(PChar(Filename));
hFile := FileOpen(Filename, $0000);
if hFile <> -1
then
begin
for Loop := 1
to CntParts
do
begin
// Reset variables
TotalBytesRead := 0;
ProgressOld := 0;
BytesToRead := SplitSize * 1024;
// build filename of the parts
Partname := DestFolder + '
\' + CutPathname(Filename) + Format('
.%3.3d',
[Loop]);
if FileExists(Partname)
then
DeleteFile(PChar(Partname));
hPart := FileCreate(Partname);
if hPart <> -1
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;
//sleep(150);
if ProgressCurrent <> ProgressOld
then
begin
ProgressOld := ProgressCurrent;
SendMessage(hApp, FSM_PROGRESS, ProgressCurrent,
Integer(PChar(Partname)));
end;
//////////////////////////////////////////////////////////////////////
until (BytesToRead < 0)
or (bRunning = 0);
end;
FileClose(hPart);
if DestFolder = '
a:'
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;