1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
procedure TForm1.Button3Click(Sender: TObject);
var
Stream1,Stream2 : TStream;
NbFichier : longint;
i, i2,i3, FileSize, FilePos, Taille : integer;
filepath : array[0..127] of AnsiChar;
chemin : string;
Vide : AnsiChar;
begin
NbFichier := Stringgrid1.RowCount-1;
Stream1:=TFileStream.Create(Edit1.Text,fmOpenRead);
try
Stream2:=TFileStream.Create('d:\2.wad',fmOpenWrite or FMCreate);
Stream2.Position :=0;
Stream2.Write(NbFichier,4);
for I := 1 to NbFichier do
begin
Stream2.Position := 4 + ((i-1)*136);
Chemin := StringGrid1.Cells[1,i]+StringGrid1.Cells[0,i];
for i2:= 1 to length(filepath) do
begin
if i2 <= length(chemin) then filepath[i2-1] := AnsiChar(Chemin[i2])
else filepath[i2-1] := #0
end;
FileSize := StrToInt(StringGrid1.Cells[2,i]);
FilePos := StrToInt(StringGrid1.Cells[3,i]);
Stream2.Write(FilePath,Length(FilePath));
Stream2.Write(Vide,4);
Stream2.Write(FileSize,4);
end;
for I3 := 1 to NbFichier do
begin
Taille := 0;
FileSize := StrToInt(StringGrid1.Cells[2,i3]);
FilePos := StrToInt(StringGrid1.Cells[3,i3]);
Stream2.Position := Stream2.Size;
Stream1.Position:=FilePos;
Stream2.CopyFrom(Stream1,FileSize);
if i3 < NbFichier then
begin
vide := #0;
Stream2.Write(vide,1);
end;
Stream2.Position := 4 + ((i3)*128);
Taille := Stream2.Size - FileSize -1;
Showmessage (IntToStr(Taille)); <-- La variable Taille renvoie la bonne donnée.
Stream2.Write(Taille,4); <-- Ecrit la bonne variable taille pour la première boucle mais pas les suivantes :(
end;
finally
Stream2.Destroy;
Stream1.Destroy;
end;
end; |
Partager