added dynamic version feature
authorChristian Hammacher <bmasterc@gmail.com>
Thu Nov 30 22:53:20 2006 +0000 (2006-11-30)
changeset 268dffb9ead7cfd
parent 267 169f3b25de6a
child 269 f241c05cb154
added dynamic version feature
installer/Attach.dpr
installer/Attach.exe
installer/MMS_Installer.dpr
installer/MMS_Installer.exe
installer/UnitPackSystem.pas
installer/UnitfrmMain.dfm
installer/UnitfrmMain.pas
     1.1 --- a/installer/Attach.dpr	Thu Nov 30 20:52:46 2006 +0000
     1.2 +++ b/installer/Attach.dpr	Thu Nov 30 22:53:20 2006 +0000
     1.3 @@ -7,6 +7,7 @@
     1.4  
     1.5  var eStream: TMemoryStream;
     1.6      eFiles: TStringList;
     1.7 +    Version: String;
     1.8  begin
     1.9    WriteLn('// File attacher for the MM:S installer');
    1.10    WriteLn('// by Basic-Master');
    1.11 @@ -41,6 +42,14 @@
    1.12      ReadLn;
    1.13      exit;
    1.14    end;
    1.15 +  { Get version number }
    1.16 +  WriteLn('// Please enter the version number:');
    1.17 +  ReadLn(Version);
    1.18 +  if (Trim(Version) = '') then begin
    1.19 +    WriteLn('// Error: Invalid version number!');
    1.20 +    ReadLn;
    1.21 +    exit;
    1.22 +  end;
    1.23    { Compress files }
    1.24    WriteLn('// Compressing files...');
    1.25    eFiles := TStringList.Create;
    1.26 @@ -51,7 +60,7 @@
    1.27    CompressFiles(eFiles, ExtractFilePath(ParamStr(0)) + 'temp.zip');
    1.28    eStream.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'temp.zip');
    1.29    WriteLn('// Attaching output to MMS_Installer.exe...');
    1.30 -  AttachToFile(ExtractFilePath(ParamStr(0)) + 'MMS_Installer.exe', eStream);
    1.31 +  AttachToFile(ExtractFilePath(ParamStr(0)) + 'MMS_Installer.exe', eStream, Version);
    1.32    DeleteFile(ExtractFilePath(ParamStr(0)) + 'temp.zip');
    1.33    eStream.Free;
    1.34    WriteLn('// Done.');
     2.1 Binary file installer/Attach.exe has changed
     3.1 --- a/installer/MMS_Installer.dpr	Thu Nov 30 20:52:46 2006 +0000
     3.2 +++ b/installer/MMS_Installer.dpr	Thu Nov 30 22:53:20 2006 +0000
     3.3 @@ -26,6 +26,7 @@
     3.4    Application.Initialize;
     3.5    Application.Title := 'Metamod:Source Installer';
     3.6    Application.CreateForm(TfrmMain, frmMain);
     3.7 +  UnitfrmMain.VERSION := GetVersion;
     3.8    frmMain.lblWelcome.Caption := 'Welcome to the Metamod:Source ' + VERSION + ' Setup Wizard';
     3.9    frmMain.lblInfo1.Caption := 'This wizard will guide you through the installation of Metamod:Source ' + VERSION + '.';
    3.10    frmMain.lblSubTitle1.Caption := 'Please review the following license terms before installing Metamod:Source ' + VERSION + '.';
     4.1 Binary file installer/MMS_Installer.exe has changed
     5.1 --- a/installer/UnitPackSystem.pas	Thu Nov 30 20:52:46 2006 +0000
     5.2 +++ b/installer/UnitPackSystem.pas	Thu Nov 30 22:53:20 2006 +0000
     5.3 @@ -6,12 +6,15 @@
     5.4  
     5.5  procedure CompressFiles(Files : TStrings; const Filename : String);
     5.6  function DecompressStream(Stream : TMemoryStream; DestDirectory : String): Boolean;
     5.7 -function AttachToFile(const AFileName: string; MemoryStream: TMemoryStream): Boolean;
     5.8 +function AttachToFile(const AFileName: string; MemoryStream: TMemoryStream; Version: String): Boolean;
     5.9  function LoadFromFile(const AFileName: string; MemoryStream: TMemoryStream): Boolean;
    5.10  function Unpack: Boolean;
    5.11 +function GetVersion: String;
    5.12  
    5.13  implementation
    5.14  
    5.15 +uses UnitfrmMain;
    5.16 +
    5.17  procedure CompressFiles(Files : TStrings; const Filename : String);
    5.18  var
    5.19    infile, outfile, tmpFile : TFileStream;
    5.20 @@ -103,7 +106,7 @@
    5.21    end;
    5.22  end;
    5.23  
    5.24 -function AttachToFile(const AFileName: string; MemoryStream: TMemoryStream): Boolean;
    5.25 +function AttachToFile(const AFileName: string; MemoryStream: TMemoryStream; Version: String): Boolean;
    5.26  var
    5.27    aStream: TFileStream;
    5.28    iSize: Integer;
    5.29 @@ -124,6 +127,10 @@
    5.30      // die Streamgr÷▀e speichern
    5.31      iSize := MemoryStream.Size + SizeOf(Integer);
    5.32      aStream.Write(iSize, SizeOf(iSize));
    5.33 +    // save version number+length
    5.34 +    iSize := aStream.Position;
    5.35 +    aStream.Write(Version[1], Length(Version));
    5.36 +    aStream.Write(iSize, SizeOf(iSize));
    5.37    finally
    5.38      aStream.Free;
    5.39    end;
    5.40 @@ -132,15 +139,21 @@
    5.41  
    5.42  function LoadFromFile(const AFileName: string; MemoryStream: TMemoryStream): Boolean;
    5.43  var
    5.44 -  aStream: TFileStream;
    5.45 +  aStream: TMemoryStream;
    5.46    iSize: Integer;
    5.47 +  EndPos: Integer;
    5.48  begin
    5.49    Result := False;
    5.50    if not FileExists(AFileName) then
    5.51      Exit;
    5.52  
    5.53    try
    5.54 -    aStream := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyWrite);
    5.55 +    aStream := TMemoryStream.Create;
    5.56 +    aStream.LoadFromFile(AFileName);
    5.57 +    // drop version part
    5.58 +    aStream.Seek(-SizeOf(Integer), soFromEnd);
    5.59 +    aStream.Read(EndPos, SizeOf(Integer));
    5.60 +    aStream.SetSize(EndPos);
    5.61      // seek to position where Stream-Size is saved
    5.62      // zur Position seeken wo Streamgr÷▀e gespeichert
    5.63      aStream.Seek(-SizeOf(Integer), soFromEnd);
    5.64 @@ -169,7 +182,8 @@
    5.65  begin
    5.66    eStream := TMemoryStream.Create;
    5.67    try
    5.68 -    LoadFromFile(ParamStr(0), eStream); // Get ZIP
    5.69 +    // Get ZIP
    5.70 +    LoadFromFile(ParamStr(0), eStream);
    5.71      DecompressStream(eStream, ExtractFilePath(ParamStr(0))); // Unpack files
    5.72  
    5.73      Result := True;
    5.74 @@ -179,4 +193,19 @@
    5.75    eStream.Free;
    5.76  end;
    5.77  
    5.78 +function GetVersion: String;
    5.79 +var FileStream: TFileStream;
    5.80 +    EndPos, Size: Integer;
    5.81 +    Version: String;
    5.82 +begin
    5.83 +   FileStream := TFileStream.Create(ParamStr(0), fmOpenRead or fmShareDenyWrite);
    5.84 +   FileStream.Seek(-SizeOf(Integer), soFromEnd);
    5.85 +   FileStream.Read(EndPos, SizeOf(EndPos));
    5.86 +   FileStream.Position := EndPos;
    5.87 +   Size := FileStream.Size - EndPos - SizeOf(Integer);
    5.88 +   SetString(Result, nil, Size);
    5.89 +   FileStream.Read(Pointer(Result)^, Size); // YAMS
    5.90 +   FileStream.Free;
    5.91 +end;
    5.92 +
    5.93  end.
     6.1 --- a/installer/UnitfrmMain.dfm	Thu Nov 30 20:52:46 2006 +0000
     6.2 +++ b/installer/UnitfrmMain.dfm	Thu Nov 30 22:53:20 2006 +0000
     6.3 @@ -68,7 +68,7 @@
     6.4      Top = 0
     6.5      Width = 527
     6.6      Height = 314
     6.7 -    ActivePage = jspLicense
     6.8 +    ActivePage = jspWelcome
     6.9      PropagateEnable = False
    6.10      Align = alClient
    6.11      OnChange = jplWizardChange
     7.1 --- a/installer/UnitfrmMain.pas	Thu Nov 30 20:52:46 2006 +0000
     7.2 +++ b/installer/UnitfrmMain.pas	Thu Nov 30 22:53:20 2006 +0000
     7.3 @@ -132,7 +132,7 @@
     7.4  var
     7.5    frmMain: TfrmMain;
     7.6  
     7.7 -var VERSION: String = '1.3d';
     7.8 +var VERSION: String = '<none>';
     7.9  
    7.10  implementation
    7.11