installer/UnitPackSystem.pas
changeset 411 7c1526f514b3
parent 268 dffb9ead7cfd
child 425 8957217cdfba
     1.1 --- a/installer/UnitPackSystem.pas	Wed Oct 10 08:56:00 2007 +0000
     1.2 +++ b/installer/UnitPackSystem.pas	Wed Oct 10 21:48:44 2007 +0000
     1.3 @@ -4,11 +4,11 @@
     1.4  
     1.5  uses SysUtils, Classes, Zlib;
     1.6  
     1.7 -procedure CompressFiles(Files : TStrings; const Filename : String);
     1.8 -function DecompressStream(Stream : TMemoryStream; DestDirectory : String): Boolean;
     1.9 +procedure CompressFiles(Files: TStrings; const Filename: String);
    1.10 +function DecompressStream(Stream: TMemoryStream; DestDirectory: String; const Source: Boolean): Boolean;
    1.11  function AttachToFile(const AFileName: string; MemoryStream: TMemoryStream; Version: String): Boolean;
    1.12  function LoadFromFile(const AFileName: string; MemoryStream: TMemoryStream): Boolean;
    1.13 -function Unpack: Boolean;
    1.14 +function Unpack(const Source: Boolean): Boolean;
    1.15  function GetVersion: String;
    1.16  
    1.17  implementation
    1.18 @@ -68,7 +68,8 @@
    1.19      DeleteFile('tmp');
    1.20    end;
    1.21  end;
    1.22 -function DecompressStream(Stream : TMemoryStream; DestDirectory : String): Boolean;
    1.23 +
    1.24 +function DecompressStream(Stream : TMemoryStream; DestDirectory : String; const Source: Boolean): Boolean;
    1.25  var
    1.26    dest,s : String;
    1.27    decompr : TDecompressionStream;
    1.28 @@ -82,23 +83,26 @@
    1.29    try
    1.30      { number of files }
    1.31      Stream.Read(c,SizeOf(c));
    1.32 -    for i := 1 to c do
    1.33 -    begin
    1.34 +    for i := 1 to c do begin
    1.35        { read filename }
    1.36        Stream.Read(l,SizeOf(l));
    1.37        SetLength(s,l);
    1.38        Stream.Read(s[1],l);
    1.39 -      { read filesize }
    1.40 -      Stream.Read(l,SizeOf(l));
    1.41 -      { decompress the files and store it }
    1.42 -      s := dest+s; //include the path
    1.43 -      outfile := TFileStream.Create(s,fmCreate);
    1.44 -      decompr := TDecompressionStream.Create(Stream);
    1.45 -      try
    1.46 -        outfile.CopyFrom(decompr,l);
    1.47 -      finally
    1.48 -        outfile.Free;
    1.49 -        decompr.Free;
    1.50 +      { check if this is the right file }
    1.51 +      if ((Pos('.source', s) <> 0) and (Source)) or ((Pos('.orangebox', s) <> 0) and (not Source)) then begin
    1.52 +        { remove extension and read filesize }
    1.53 +        s := ChangeFileExt(s, '');
    1.54 +        Stream.Read(l,SizeOf(l));
    1.55 +        { decompress the files and store it }
    1.56 +        s := dest+s; //include the path
    1.57 +        outfile := TFileStream.Create(s,fmCreate);
    1.58 +        decompr := TDecompressionStream.Create(Stream);
    1.59 +        try
    1.60 +          outfile.CopyFrom(decompr,l);
    1.61 +        finally
    1.62 +          outfile.Free;
    1.63 +          decompr.Free;
    1.64 +        end;
    1.65        end;
    1.66      end;
    1.67    finally
    1.68 @@ -177,14 +181,14 @@
    1.69  
    1.70  { Unpack function }
    1.71  
    1.72 -function Unpack: Boolean;
    1.73 +function Unpack(const Source: Boolean): Boolean;
    1.74  var eStream: TMemoryStream;
    1.75  begin
    1.76    eStream := TMemoryStream.Create;
    1.77    try
    1.78      // Get ZIP
    1.79      LoadFromFile(ParamStr(0), eStream);
    1.80 -    DecompressStream(eStream, ExtractFilePath(ParamStr(0))); // Unpack files
    1.81 +    DecompressStream(eStream, ExtractFilePath(ParamStr(0)), Source); // Unpack files
    1.82  
    1.83      Result := True;
    1.84    except