2005-07-21 23:08:23 +00:00
unit UnitInstall;
interface
uses SysUtils, Classes, Windows, Graphics, Forms, ShellAPI, Controls, Messages,
2006-12-09 18:23:52 +00:00
TlHelp32, IdFTPCommon, ComCtrls, Dialogs, JclFileUtils;
2005-07-21 23:08:23 +00:00
type TMod = ( modNone, modCS, modDoD, modTFC, modNS, modTS, modESF) ;
2006-12-19 19:50:20 +00:00
type TOS = ( osWindows, osLinux32{, osLinux64} ) ;
2005-07-21 23:08:23 +00:00
procedure AddStatus( Text : String ; Color: TColor; ShowTime: Boolean = True ) ;
procedure AddDone( Additional: String = '' ) ;
2005-08-03 18:45:16 +00:00
procedure AddSkipped;
2007-02-05 21:13:15 +00:00
procedure AddFailed;
2005-08-04 23:46:22 +00:00
procedure AddNotFound;
2005-07-21 23:08:23 +00:00
procedure MakeDir( Dir: String ) ;
procedure DownloadFile( eFile: String ; eDestination: String ) ;
procedure BasicInstallation( ePath: String ; eMod: TMod; SteamInstall: Boolean ; OS: TOS) ;
procedure InstallDedicated( eModPath: String ; eMod: TMod; UseSteam: Boolean ) ;
procedure InstallListen( ePath: String ; eMod: TMod) ;
procedure InstallCustom( ePath: String ; eMod: TMod; eOS: TOS) ;
procedure InstallFTP( eMod: TMod; OS: TOS) ;
var StartTime: TDateTime;
SteamPath: String ;
StandaloneServer: String ;
Cancel: Boolean = False ;
FileList: TStringList;
DirList: TStringList;
implementation
uses UnitfrmMain, UnitfrmProxy, UnitFunctions, UnitScanMods;
// useful stuff
function InstallTime: String ;
begin
2005-07-24 19:27:36 +00:00
Result : = FormatDateTime( 'HH:MM:SS' , Now - StartTime) ;
2005-07-21 23:08:23 +00:00
end ;
procedure AddStatus( Text : String ; Color: TColor; ShowTime: Boolean = True ) ;
begin
frmMain. rtfDetails. SelStart : = Length( frmMain. rtfDetails. Text ) ;
if ShowTime then begin
frmMain. rtfDetails. SelAttributes. Color : = clBlack;
if frmMain. rtfDetails. Text = '' then
frmMain. rtfDetails. SelText : = '[' + InstallTime + '] '
else
frmMain. rtfDetails. SelText : = #13 #10 + '[' + InstallTime + '] ' ;
frmMain. rtfDetails. SelStart : = Length( frmMain. rtfDetails. Text ) ;
end
else
frmMain. rtfDetails. SelText : = #13 #10 ;
frmMain. rtfDetails. SelStart : = Length( frmMain. rtfDetails. Text ) ;
frmMain. rtfDetails. SelAttributes. Color : = Color;
frmMain. rtfDetails. SelText : = Text ;
frmMain. rtfDetails. Perform( WM_VSCROLL, SB_BOTTOM, 0 ) ;
frmMain. Repaint;
Application. ProcessMessages;
end ;
procedure AddDone( Additional: String = '' ) ;
begin
frmMain. rtfDetails. SelStart : = Length( frmMain. rtfDetails. Text ) ;
frmMain. rtfDetails. SelAttributes. Color : = clGreen;
if Additional = '' then
frmMain. rtfDetails. SelText : = ' Done.'
else
frmMain. rtfDetails. SelText : = ' Done, ' + Additional + '.' ;
2005-08-03 18:45:16 +00:00
frmMain. rtfDetails. Perform( WM_VSCROLL, SB_BOTTOM, 0 ) ;
frmMain. Repaint;
Application. ProcessMessages;
end ;
procedure AddSkipped;
begin
frmMain. rtfDetails. SelStart : = Length( frmMain. rtfDetails. Text ) ;
2005-08-04 23:46:22 +00:00
frmMain. rtfDetails. SelAttributes. Color : = $004080FF ; // orange
2005-08-03 18:45:16 +00:00
frmMain. rtfDetails. SelText : = ' Skipped.' ;
frmMain. rtfDetails. Perform( WM_VSCROLL, SB_BOTTOM, 0 ) ;
2005-07-21 23:08:23 +00:00
frmMain. Repaint;
Application. ProcessMessages;
end ;
2007-02-05 21:13:15 +00:00
procedure AddFailed;
begin
frmMain. rtfDetails. SelStart : = Length( frmMain. rtfDetails. Text ) ;
frmMain. rtfDetails. SelAttributes. Color : = clMaroon;
frmMain. rtfDetails. SelText : = ' Failed.' ;
frmMain. rtfDetails. Perform( WM_VSCROLL, SB_BOTTOM, 0 ) ;
frmMain. Repaint;
Application. ProcessMessages;
end ;
2005-08-04 23:46:22 +00:00
procedure AddNotFound;
begin
frmMain. rtfDetails. SelStart : = Length( frmMain. rtfDetails. Text ) ;
frmMain. rtfDetails. SelAttributes. Color : = clRed;
frmMain. rtfDetails. SelText : = ' Not found.' ;
frmMain. rtfDetails. Perform( WM_VSCROLL, SB_BOTTOM, 0 ) ;
frmMain. Repaint;
Application. ProcessMessages;
end ;
2005-07-21 23:08:23 +00:00
procedure MakeDir( Dir: String ) ;
begin
try
if not DirectoryExists( Dir) then
ForceDirectories( Dir) ;
except
Application. ProcessMessages;
end ;
end ;
2005-08-04 23:46:22 +00:00
procedure FileCopy( Source, Destination: String ; CopyConfig: Boolean ; AddStatus: Boolean = True ) ;
2005-07-21 23:08:23 +00:00
begin
2005-08-04 23:46:22 +00:00
if ( not CopyConfig) and ( Pos( 'config' , Source) < > 0 ) then begin
if AddStatus then
AddSkipped;
2005-07-21 23:08:23 +00:00
exit;
2005-08-04 23:46:22 +00:00
end ;
2005-07-21 23:08:23 +00:00
2005-08-04 23:46:22 +00:00
if not FileExists( Source) then begin
if AddStatus then
AddNotFound;
exit;
2005-07-21 23:08:23 +00:00
end ;
try
2005-08-04 23:46:22 +00:00
if FileExists( Destination) then
DeleteFile( PChar( Destination) ) ;
2005-07-21 23:08:23 +00:00
CopyFile( PChar( Source) , PChar( Destination) , False ) ;
except
Application. ProcessMessages;
end ;
2005-08-04 23:46:22 +00:00
if AddStatus then
AddDone;
2005-07-21 23:08:23 +00:00
end ;
procedure DownloadFile( eFile: String ; eDestination: String ) ;
var TransferType: TIdFTPTransferType;
begin
// much better when files are transfered with the correct transfer type...
TransferType : = ftBinary;
if ExtractFileExt( LowerCase( eFile) ) = '.txt' then TransferType : = ftASCII;
if ExtractFileExt( LowerCase( eFile) ) = '.cfg' then TransferType : = ftASCII;
if ExtractFileExt( LowerCase( eFile) ) = '.ini' then TransferType : = ftASCII;
if ExtractFileExt( LowerCase( eFile) ) = '.sma' then TransferType : = ftASCII;
if ExtractFileExt( LowerCase( eFile) ) = '.inc' then TransferType : = ftASCII;
if ExtractFileExt( LowerCase( eFile) ) = '.gam' then TransferType : = ftASCII;
if frmMain. IdFTP. TransferType < > TransferType then
frmMain. IdFTP. TransferType : = TransferType;
// download the file
frmMain. IdFTP. Get( eFile, eDestination, True ) ;
end ;
procedure UploadFile( eFile: String ; eDestination: String ; CopyConfig: Boolean = True ) ;
var TransferType: TIdFTPTransferType;
begin
2005-08-03 18:45:16 +00:00
if ( Pos( 'config' , eFile) > 0 ) and ( not CopyConfig) then begin
AddSkipped;
exit;
end ;
2005-07-21 23:08:23 +00:00
eDestination : = StringReplace( eDestination, '\' , '/' , [ rfReplaceAll] ) ;
// the same as in DownloadFile()
TransferType : = ftBinary;
if ExtractFileExt( LowerCase( eFile) ) = '.txt' then TransferType : = ftASCII;
if ExtractFileExt( LowerCase( eFile) ) = '.cfg' then TransferType : = ftASCII;
if ExtractFileExt( LowerCase( eFile) ) = '.ini' then TransferType : = ftASCII;
if ExtractFileExt( LowerCase( eFile) ) = '.sma' then TransferType : = ftASCII;
if ExtractFileExt( LowerCase( eFile) ) = '.inc' then TransferType : = ftASCII;
if ExtractFileExt( LowerCase( eFile) ) = '.gam' then TransferType : = ftASCII;
if frmMain. IdFTP. TransferType < > TransferType then
frmMain. IdFTP. TransferType : = TransferType;
// upload the file
2007-02-05 21:13:15 +00:00
try
frmMain. IdFTP. Put( eFile, eDestination) ;
AddDone;
except
AddFailed;
end ;
2005-07-21 23:08:23 +00:00
end ;
procedure FTPMakeDir( eDir: String ) ;
begin
eDir : = StringReplace( eDir, '\' , '/' , [ rfReplaceAll] ) ;
try
frmMain. IdFTP. MakeDir( eDir) ;
except
Application. ProcessMessages;
end ;
end ;
function FSize( eFile: String ) : Cardinal ;
var eRec: TSearchRec;
begin
if FindFirst( eFile, faAnyFile, eRec) = 0 then
Result : = eRec. Size
else
Result : = 0 ;
end ;
function IsForbidden( eFile: String ; eOS: TOS) : Boolean ;
begin
Result : = False ;
case eOS of
osWindows: begin
if ExtractFileExt( eFile) = '.so' then
Result : = True ;
end ;
osLinux32: begin
if ExtractFileExt( eFile) = '.dll' then
Result : = True ;
if ExtractFileExt( eFile) = '.exe' then
Result : = True ;
if Pos( '_amd64' , ExtractFileName( eFile) ) < > 0 then
Result : = True ;
end ;
2006-12-19 19:50:20 +00:00
{ osLinux64: begin
2005-07-21 23:08:23 +00:00
if ExtractFileExt( eFile) = '.dll' then
Result : = True ;
if ExtractFileExt( eFile) = '.exe' then
Result : = True ;
if Pos( '_i386' , ExtractFileName( eFile) ) < > 0 then
Result : = True ;
2006-12-19 19:50:20 +00:00
end ; }
2005-07-21 23:08:23 +00:00
end ;
end ;
// stuff for killing processes
function GetProcessID( sProcName: String ) : Integer ;
var
hProcSnap: THandle;
pe32: TProcessEntry32;
begin
result : = - 1 ;
hProcSnap : = CreateToolHelp32SnapShot( TH32CS_SNAPPROCESS, 0 ) ;
if hProcSnap = INVALID_HANDLE_VALUE then
exit;
pe32. dwSize : = SizeOf( ProcessEntry32) ;
if Process32First( hProcSnap, pe32) = true then begin
while Process32Next( hProcSnap, pe32) = true do begin
if pos( sProcName, pe32. szExeFile) < > 0 then
result : = pe32. th32ProcessID;
end ;
end ;
CloseHandle( hProcSnap) ;
end ;
procedure KillProcess( dwProcID: DWORD) ;
var
hProcess : Cardinal ;
dw : DWORD;
begin
hProcess : = OpenProcess( SYNCHRONIZE or PROCESS_TERMINATE, False , dwProcID) ;
TerminateProcess( hProcess, 0 ) ;
dw : = WaitForSingleObject( hProcess, 5 0 0 0 ) ;
case dw of
WAIT_TIMEOUT: begin
CloseHandle( hProcess) ;
exit;
end ;
WAIT_FAILED: begin
RaiseLastOSError;
CloseHandle( hProcess) ;
exit;
end ;
end ;
CloseHandle( hProcess) ;
end ;
// Installation here
{ Basic Installation }
procedure BasicInstallation( ePath: String ; eMod: TMod; SteamInstall: Boolean ; OS: TOS) ;
var eStr: TStringList;
i: integer ;
CopyConfig: Boolean ;
2006-09-11 16:53:26 +00:00
UpdatePluginsIni: Boolean ;
2005-07-21 23:08:23 +00:00
begin
AddStatus( 'Scanning for directories...' , clBlack) ;
2007-03-05 21:37:48 +00:00
with GetAllFiles( ExtractFilePath( Application. ExeName) + 'files\*.*' , faDirectory, True , True ) do begin
2005-07-21 23:08:23 +00:00
DirList. Text : = Text ;
Free;
end ;
AddDone( 'found ' + IntToStr( DirList. Count) + ' directories..' ) ;
AddStatus( 'Scanning for files...' , clBlack) ;
2007-03-05 21:37:48 +00:00
with GetAllFiles( ExtractFilePath( Application. ExeName) + 'files\*.*' , faAnyFile, True , False ) do begin
2005-07-21 23:08:23 +00:00
FileList. Text : = Text ;
Free;
end ;
AddDone( 'found ' + IntToStr( FileList. Count) + ' files..' ) ;
AddStatus( '' , clBlack, False ) ;
frmMain. ggeAll. MaxValue : = DirList. Count + FileList. Count;
frmMain. ggeItem. MaxValue : = DirList. Count;
2006-07-22 01:08:36 +00:00
if ( SteamInstall) and ( GetProcessID( 'Steam.exe' ) < > - 1 ) then begin
2005-07-21 23:08:23 +00:00
if MessageBox( frmMain. Handle, 'Steam is still running. It is necersarry to shut it down before you install AMX Mod X. Shut it down now?' , PChar( frmMain. Caption) , MB_ICONQUESTION + MB_YESNO) = mrYes then begin
AddStatus( 'Shutting down Steam...' , clBlack, False ) ;
if GetProcessID( 'Steam.exe' ) = - 1 then
AddDone
else
KillProcess( GetProcessID( 'Steam.exe' ) ) ;
while GetProcessID( 'Steam.exe' ) < > - 1 do begin // sure is sure...
Sleep( 5 0 ) ;
Application. ProcessMessages;
end ;
AddDone;
end
else begin
Application. Terminate;
exit;
end ;
end ;
CopyConfig : = True ;
if DirectoryExists( ePath + 'addons\amxmodx' ) then begin
case MessageBox( frmMain. Handle, 'An AMX Mod X installation was already detected. If you choose to reinstall, your configuration files will be erased. Click Yes to continue, No to Upgrade, or Cancel to abort the install.' , PChar( frmMain. Caption) , MB_ICONQUESTION + MB_YESNOCANCEL) of
mrNo: CopyConfig : = False ;
mrCancel: begin
Application. Terminate;
exit;
end ;
end ;
end ;
for i : = 0 to DirList. Count - 1 do
2007-03-05 21:37:48 +00:00
DirList[ i] : = Copy( DirList[ i] , Length( ExtractFilePath( Application. ExeName) ) + 7 , Length( DirList[ i] ) ) ;
2005-07-21 23:08:23 +00:00
for i : = 0 to FileList. Count - 1 do
2007-03-05 21:37:48 +00:00
FileList[ i] : = Copy( FileList[ i] , Length( ExtractFilePath( Application. ExeName) ) + 7 , Length( FileList[ i] ) ) ;
2005-07-21 23:08:23 +00:00
{ liblist.gam }
if not FileExists( ePath + 'liblist.gam' ) then begin
if MessageBox( frmMain. Handle, 'The file "liblist.gam" couldn' 't be found. Continue installation?' , PChar( frmMain. Caption) , MB_ICONQUESTION + MB_YESNO) = mrNo then begin
AddStatus( 'Installation canceled by user!' , clRed, False ) ;
Screen. Cursor : = crDefault;
Cancel : = True ;
exit;
end ;
end
else begin
AddStatus( 'Editing liblist.gam...' , clBlack) ;
eStr : = TStringList. Create;
eStr. LoadFromFile( ePath + 'liblist.gam' ) ;
if eStr. IndexOf( 'gamedll "addons\metamod\dlls\metamod.dll"' ) = - 1 then begin
for i : = 0 to eStr. Count - 1 do begin
if Pos( 'gamedll' , TrimLeft( eStr[ i] ) ) = 1 then
eStr[ i] : = '//' + eStr[ i] ;
end ;
eStr. Add( 'gamedll "addons\metamod\dlls\metamod.dll"' ) ;
2006-12-19 19:50:20 +00:00
//if OS = osLinux64 then
// eStr.Add('gamedll_linux "addons/metamod/dlls/metamod_amd64.so"')
//else
eStr. Add( 'gamedll_linux "addons/metamod/dlls/metamod_i386.so"' ) ;
2005-07-21 23:08:23 +00:00
FileSetAttr( ePath + 'liblist.gam' , 0 ) ;
eStr. SaveToFile( ePath + 'liblist.gam' ) ;
FileSetAttr( ePath + 'liblist.gam' , faReadOnly) ; // important for listen servers
2005-08-04 23:46:22 +00:00
AddDone;
end
else
AddSkipped;
2005-07-21 23:08:23 +00:00
eStr. Free;
{ create directories }
AddStatus( 'Creating directories...' , clBlack) ;
end ;
// metamod...
MakeDir( ePath + 'addons' ) ;
MakeDir( ePath + 'addons\amxmodx' ) ;
MakeDir( ePath + 'addons\metamod' ) ;
MakeDir( ePath + 'addons\metamod\dlls' ) ;
// rest...
for i : = 0 to DirList. Count - 1 do begin
2006-01-29 17:24:49 +00:00
if Cancel then begin
AddStatus( '' , clBlack, False ) ;
AddStatus( 'Installation canceled by user!' , clBlack, False ) ;
2005-07-21 23:08:23 +00:00
exit;
2006-01-29 17:24:49 +00:00
end ;
2005-07-21 23:08:23 +00:00
if Pos( 'base' , DirList[ i] ) = 1 then begin
MakeDir( ePath + 'addons\amxmodx\' + Copy( DirList[ i] , 6 , Length( DirList[ i] ) ) ) ;
AddStatus( 'Created directory: addons\amxmodx\' + Copy( DirList[ i] , 6 , Length( DirList[ i] ) ) , clBlack) ;
end ;
case eMod of
modCS: begin
if Pos( 'cstrike' , DirList[ i] ) = 1 then begin
MakeDir( ePath + 'addons\amxmodx\' + Copy( DirList[ i] , 9 , Length( DirList[ i] ) ) ) ;
AddStatus( 'Created directory: addons\amxmodx\' + Copy( DirList[ i] , 9 , Length( DirList[ i] ) ) , clBlack) ;
end ;
end ;
modDoD: begin
if Pos( 'dod' , DirList[ i] ) = 1 then begin
MakeDir( ePath + 'addons\amxmodx\' + Copy( DirList[ i] , 5 , Length( DirList[ i] ) ) ) ;
AddStatus( 'Created directory: addons\amxmodx\' + Copy( DirList[ i] , 5 , Length( DirList[ i] ) ) , clBlack) ;
end ;
end ;
modTFC: begin
if Pos( 'tfc' , DirList[ i] ) = 1 then begin
MakeDir( ePath + 'addons\amxmodx\' + Copy( DirList[ i] , 5 , Length( DirList[ i] ) ) ) ;
AddStatus( 'Created directory: addons\amxmodx\' + Copy( DirList[ i] , 5 , Length( DirList[ i] ) ) , clBlack) ;
end ;
end ;
modNS: begin
if Pos( 'ns' , DirList[ i] ) = 1 then begin
MakeDir( ePath + 'addons\amxmodx\' + Copy( DirList[ i] , 4 , Length( DirList[ i] ) ) ) ;
AddStatus( 'Created directory: addons\amxmodx\' + Copy( DirList[ i] , 4 , Length( DirList[ i] ) ) , clBlack) ;
end ;
end ;
modTS: begin
if Pos( 'ts' , DirList[ i] ) = 1 then begin
MakeDir( ePath + 'addons\amxmodx\' + Copy( DirList[ i] , 4 , Length( DirList[ i] ) ) ) ;
AddStatus( 'Created directory: addons\amxmodx\' + Copy( DirList[ i] , 4 , Length( DirList[ i] ) ) , clBlack) ;
end ;
end ;
modESF: begin
2006-07-22 01:08:36 +00:00
if Pos( 'esf' , DirList[ i] ) = 1 then begin
2005-07-21 23:08:23 +00:00
MakeDir( ePath + 'addons\amxmodx\' + Copy( DirList[ i] , 4 , Length( DirList[ i] ) ) ) ;
AddStatus( 'Created directory: addons\amxmodx\' + Copy( DirList[ i] , 4 , Length( DirList[ i] ) ) , clBlack) ;
end ;
end ;
end ;
frmMain. ggeAll. Progress : = i;
frmMain. ggeItem. Progress : = i;
end ;
frmMain. ggeItem. MaxValue : = FileList. Count;
{ copy all files }
AddStatus( '' , clBlack, False ) ;
AddStatus( 'Copying files...' , clBlack) ;
for i : = 0 to FileList. Count - 1 do begin
2006-01-29 17:24:49 +00:00
if Cancel then begin
AddStatus( '' , clBlack, False ) ;
AddStatus( 'Installation canceled by user!' , clBlack, False ) ;
2005-07-21 23:08:23 +00:00
exit;
2006-01-29 17:24:49 +00:00
end ;
2005-07-21 23:08:23 +00:00
if not IsForbidden( FileList[ i] , OS) then begin
if Pos( 'base' , FileList[ i] ) = 1 then begin
2005-08-04 23:46:22 +00:00
AddStatus( 'Copying file: addons\amxmodx\' + Copy( FileList[ i] , 6 , Length( FileList[ i] ) ) , clBlack) ;
2007-03-05 21:37:48 +00:00
FileCopy( ExtractFilePath( Application. ExeName) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 6 , Length( FileList[ i] ) ) , CopyConfig) ;
2005-07-21 23:08:23 +00:00
end ;
2005-08-04 23:46:22 +00:00
2005-07-21 23:08:23 +00:00
case eMod of
modCS: begin
if Pos( 'cstrike' , FileList[ i] ) = 1 then begin
2005-08-04 23:46:22 +00:00
AddStatus( 'Copying file: addons\amxmodx\' + Copy( FileList[ i] , 9 , Length( FileList[ i] ) ) , clBlack) ;
2007-03-05 21:37:48 +00:00
FileCopy( ExtractFilePath( Application. ExeName) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 9 , Length( FileList[ i] ) ) , CopyConfig) ;
2005-07-21 23:08:23 +00:00
end ;
end ;
modDoD: begin
if Pos( 'dod' , FileList[ i] ) = 1 then begin
2005-08-04 23:46:22 +00:00
AddStatus( 'Copying file: addons\amxmodx\' + Copy( FileList[ i] , 5 , Length( FileList[ i] ) ) , clBlack) ;
2007-03-05 21:37:48 +00:00
FileCopy( ExtractFilePath( Application. ExeName) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 5 , Length( FileList[ i] ) ) , CopyConfig) ;
2005-07-21 23:08:23 +00:00
end ;
end ;
modTFC: begin
if Pos( 'tfc' , FileList[ i] ) = 1 then begin
2005-08-04 23:46:22 +00:00
AddStatus( 'Copying file: addons\amxmodx\' + Copy( FileList[ i] , 5 , Length( FileList[ i] ) ) , clBlack) ;
2007-03-05 21:37:48 +00:00
FileCopy( ExtractFilePath( Application. ExeName) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 5 , Length( FileList[ i] ) ) , CopyConfig) ;
2005-07-21 23:08:23 +00:00
end ;
end ;
modNS: begin
if Pos( 'ns' , FileList[ i] ) = 1 then begin
2005-08-04 23:46:22 +00:00
AddStatus( 'Copying file: addons\amxmodx\' + Copy( FileList[ i] , 4 , Length( FileList[ i] ) ) , clBlack) ;
2007-03-05 21:37:48 +00:00
FileCopy( ExtractFilePath( Application. ExeName) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 4 , Length( FileList[ i] ) ) , CopyConfig) ;
2005-07-21 23:08:23 +00:00
end ;
end ;
modTS: begin
if Pos( 'ts' , FileList[ i] ) = 1 then begin
2005-08-04 23:46:22 +00:00
AddStatus( 'Copying file: addons\amxmodx\' + Copy( FileList[ i] , 4 , Length( FileList[ i] ) ) , clBlack) ;
2007-03-05 21:37:48 +00:00
FileCopy( ExtractFilePath( Application. ExeName) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 4 , Length( FileList[ i] ) ) , CopyConfig) ;
2005-07-21 23:08:23 +00:00
end ;
end ;
modESF: begin
2006-07-22 01:08:36 +00:00
if Pos( 'esf' , FileList[ i] ) = 1 then begin
2006-07-22 11:46:43 +00:00
AddStatus( 'Copying file: addons\amxmodx\' + Copy( FileList[ i] , 5 , Length( FileList[ i] ) ) , clBlack) ;
2007-03-05 21:37:48 +00:00
FileCopy( ExtractFilePath( Application. ExeName) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 4 , Length( FileList[ i] ) ) , CopyConfig) ;
2005-07-21 23:08:23 +00:00
end ;
end ;
end ;
end ;
frmMain. ggeAll. Progress : = frmMain. ggeAll. Progress + 1 ;
frmMain. ggeItem. Progress : = i;
end ;
{ metamod }
2005-08-04 23:46:22 +00:00
AddStatus( 'Copying Metamod...' , clBlack) ;
FileCopy( ePath + 'addons\amxmodx\dlls\metamod.dll' , ePath + '\addons\metamod\dlls\metamod.dll' , CopyConfig, False ) ;
FileCopy( ePath + '\addons\amxmodx\dlls\metamod_i386.so' , ePath + '\addons\metamod\dlls\metamod_i386.so' , CopyConfig, False ) ;
FileCopy( ePath + '\addons\amxmodx\dlls\metamod_amd64.so' , ePath + '\addons\metamod\dlls\metamod_amd64.so' , CopyConfig, False ) ;
2005-07-21 23:08:23 +00:00
try
if FileExists( ePath + '\addons\amxmodx\dlls\metamod.dll' ) then DeleteFile( PChar( ePath + '\addons\amxmodx\dlls\metamod.dll' ) ) ;
if FileExists( ePath + '\addons\amxmodx\dlls\metamod_amd64.so' ) then DeleteFile( PChar( ePath + '\addons\amxmodx\dlls\metamod_amd64.so' ) ) ;
if FileExists( ePath + '\addons\amxmodx\dlls\metamod_i386.so' ) then DeleteFile( PChar( ePath + '\addons\amxmodx\dlls\metamod_i386.so' ) ) ;
finally
2006-09-11 16:53:26 +00:00
UpdatePluginsIni : = True ;
2005-07-21 23:08:23 +00:00
eStr : = TStringList. Create;
2006-09-11 16:53:26 +00:00
// check if we need to modify mm's plugins.ini
2006-09-13 21:11:53 +00:00
if ( FileExists( ePath + 'addons\metamod\plugins.ini' ) ) then begin
eStr. LoadFromFile( ePath + 'addons\metamod\plugins.ini' ) ;
2006-09-11 16:53:26 +00:00
if OS = osWindows then begin
2006-09-16 23:26:24 +00:00
if ( Pos( 'addons\amxmodx\dlls\amxmodx_mm.dll' , eStr. Text ) < > 0 ) then
2006-09-11 16:53:26 +00:00
UpdatePluginsIni : = False ;
end
else if OS = osLinux32 then begin
2006-09-16 23:26:24 +00:00
if ( Pos( 'addons/amxmodx/dlls/amxmodx_mm_i386.so' , eStr. Text ) < > 0 ) then
2006-09-11 16:53:26 +00:00
UpdatePluginsIni : = False ;
end
else begin
2006-09-16 23:26:24 +00:00
if ( Pos( 'addons/amxmodx/dlls/amxmodx_mm_amd64.so' , eStr. Text ) < > 0 ) then
2006-09-11 16:53:26 +00:00
UpdatePluginsIni : = False ;
end ;
2006-03-18 20:03:34 +00:00
end
2006-09-11 16:53:26 +00:00
// create a header :o
2006-03-18 20:03:34 +00:00
else begin
2006-09-11 16:53:26 +00:00
eStr. Add( ';; Metamod plugins.ini' ) ;
eStr. Add( '; AMX Mod X ' + VERSION) ;
end ;
// if there's no
2006-09-13 21:11:53 +00:00
if ( UpdatePluginsIni) then begin
2006-09-11 16:53:26 +00:00
if OS = osWindows then begin
2006-09-13 21:11:53 +00:00
eStr. Add( '' ) ;
2006-09-11 16:53:26 +00:00
eStr. Add( 'win32 addons\amxmodx\dlls\amxmodx_mm.dll' ) ;
eStr. Add( '; Enable this instead for binary logging' ) ;
eStr. Add( '; win32 addons\amxmodx\dlls\amxmodx_bl_mm.dll' ) ;
end
else if OS = osLinux32 then begin
2006-09-13 21:11:53 +00:00
eStr. Add( '' ) ;
2006-09-11 16:53:26 +00:00
eStr. Add( 'linux addons/amxmodx/dlls/amxmodx_mm_i386.so' ) ;
eStr. Add( '; Enable this instead for binary logging' ) ;
eStr. Add( '; linux addons/amxmodx/dlls/amxmodx_bl_mm_i386.so' ) ;
end
else begin
2006-09-13 21:11:53 +00:00
eStr. Add( '' ) ;
2006-09-11 16:53:26 +00:00
eStr. Add( 'linux addons/amxmodx/dlls/amxmodx_mm_amd64.so' ) ;
eStr. Add( '; Enable this instead for binary logging' ) ;
eStr. Add( '; linux addons/amxmodx/dlls/amxmodx_bl_mm_amd64.so' ) ;
end ;
2006-03-18 20:03:34 +00:00
end ;
2006-09-13 21:11:53 +00:00
eStr. SaveToFile( ePath + 'addons\metamod\plugins.ini' ) ;
2005-07-21 23:08:23 +00:00
eStr. Free;
end ;
2005-08-04 23:46:22 +00:00
AddDone;
2005-07-21 23:08:23 +00:00
// finish...
frmMain. ggeAll. Progress : = frmMain. ggeAll. MaxValue;
frmMain. ggeItem. Progress : = frmMain. ggeItem. MaxValue;
AddStatus( '' , clBlack, False ) ;
AddStatus( 'Finished installation!' , clBlack, False ) ;
frmMain. cmdNext. Enabled : = True ;
frmMain. cmdCancel. Hide;
Screen. Cursor : = crDefault;
end ;
{ Dedicated Server }
procedure InstallDedicated( eModPath: String ; eMod: TMod; UseSteam: Boolean ) ;
begin
StartTime : = Now;
Screen. Cursor : = crHourGlass;
AddStatus( 'Starting installation on dedicated server...' , clBlack) ;
BasicInstallation( eModPath, eMod, UseSteam, osWindows) ;
end ;
{ Listen Server }
procedure InstallListen( ePath: String ; eMod: TMod) ;
begin
StartTime : = Now;
Screen. Cursor : = crHourGlass;
AddStatus( 'Starting installation on the listen server...' , clBlack) ;
BasicInstallation( ePath, eMod, True , osWindows) ;
end ;
{ Custom mod }
procedure InstallCustom( ePath: String ; eMod: TMod; eOS: TOS) ;
begin
StartTime : = Now;
Screen. Cursor : = crHourGlass;
AddStatus( 'Starting AMX Mod X installation...' , clBlack) ;
BasicInstallation( ePath, eMod, False , eOS) ;
end ;
{ FTP }
procedure InstallFTP( eMod: TMod; OS: TOS) ;
2005-08-04 23:46:22 +00:00
function DoReconnect: Boolean ;
begin
Result : = False ;
if MessageBox( frmMain. Handle, 'You have been disconnected due to an error. Try to reconnect?' , PChar( Application. Title) , MB_ICONQUESTION + MB_YESNO) = mrYes then begin
try
frmMain. IdFTP. Connect;
Result : = True ;
except
2007-02-14 18:55:42 +00:00
MessageBox( frmMain. Handle, 'Failed to reconnect. Installation has been aborted.' , PChar( Application. Title) , MB_ICONSTOP) ;
2005-08-04 23:46:22 +00:00
end ;
end ;
end ;
label CreateAgain;
label UploadAgain;
2005-07-21 23:08:23 +00:00
var eStr: TStringList;
i: integer ;
ePath: String ;
CurNode: TTreeNode;
2005-08-01 00:19:25 +00:00
CopyConfig: Boolean ;
2005-08-04 23:46:22 +00:00
eGoBack: Boolean ;
2005-07-21 23:08:23 +00:00
begin
2006-07-22 11:46:43 +00:00
eGoBack : = False ;
2006-09-13 21:11:53 +00:00
ePath : = '/' ;
CurNode : = frmMain. trvDirectories. Selected;
2006-12-09 18:23:52 +00:00
if ( Assigned( CurNode) ) then begin
repeat
ePath : = '/' + CurNode. Text + ePath;
CurNode : = CurNode. Parent;
until ( not Assigned( CurNode) ) ;
end ;
2006-01-29 17:24:49 +00:00
Screen. Cursor : = crAppStart;
2005-07-21 23:08:23 +00:00
frmMain. cmdCancel. Show;
2006-01-29 17:24:49 +00:00
frmMain. cmdCancel. Caption : = '&Cancel' ;
2005-07-21 23:08:23 +00:00
frmMain. cmdNext. Hide;
Screen. Cursor : = crHourGlass;
AddStatus( 'Scanning for directories...' , clBlack) ;
2007-03-05 21:37:48 +00:00
with GetAllFiles( ExtractFilePath( Application. ExeName) + 'temp\*.*' , faDirectory, True , True ) do begin
2005-07-21 23:08:23 +00:00
DirList. Text : = Text ;
Free;
end ;
AddDone( 'found ' + IntToStr( DirList. Count) + ' directories..' ) ;
AddStatus( 'Scanning for files...' , clBlack) ;
2007-03-05 21:37:48 +00:00
with GetAllFiles( ExtractFilePath( Application. ExeName) + 'temp\*.*' , faAnyFile, True , False ) do begin
2005-07-21 23:08:23 +00:00
FileList. Text : = Text ;
Free;
end ;
AddDone( 'found ' + IntToStr( FileList. Count) + ' files..' ) ;
AddStatus( '' , clBlack, False ) ;
frmMain. ggeAll. MaxValue : = DirList. Count + FileList. Count;
frmMain. ggeItem. MaxValue : = DirList. Count;
for i : = 0 to DirList. Count - 1 do
2007-03-05 21:37:48 +00:00
DirList[ i] : = Copy( DirList[ i] , Length( ExtractFilePath( Application. ExeName) ) + 6 , Length( DirList[ i] ) ) ;
2005-07-21 23:08:23 +00:00
for i : = 0 to FileList. Count - 1 do
2007-03-05 21:37:48 +00:00
FileList[ i] : = Copy( FileList[ i] , Length( ExtractFilePath( Application. ExeName) ) + 6 , Length( FileList[ i] ) ) ;
2005-07-21 23:08:23 +00:00
2005-08-01 00:19:25 +00:00
CopyConfig : = True ;
2006-09-13 21:11:53 +00:00
AddStatus( 'Checking for previous AMX Mod X installation...' , clBlack) ;
// well, check it
try
frmMain. IdFTP. ChangeDir( ePath + 'addons/amxmodx/' ) ;
case MessageBox( frmMain. Handle, 'An AMX Mod X installation was already detected. If you choose to reinstall, your configuration files will be erased. Click Yes to continue, No to Upgrade, or Cancel to abort the installation.' , PChar( frmMain. Caption) , MB_ICONQUESTION + MB_YESNOCANCEL) of
mrNo: CopyConfig : = False ;
mrCancel: begin
Application. Terminate;
exit;
end ;
end ;
except
// nope, no installation found
end ;
// liblist.gam
2005-07-21 23:08:23 +00:00
AddStatus( 'Editing liblist.gam...' , clBlack) ;
eStr : = TStringList. Create;
2007-03-05 21:37:48 +00:00
eStr. LoadFromFile( ExtractFilePath( Application. ExeName) + 'temp\liblist.gam' ) ;
2005-07-21 23:08:23 +00:00
if eStr. IndexOf( 'gamedll "addons\metamod\dlls\metamod.dll"' ) = - 1 then begin
2006-01-29 17:24:49 +00:00
if Cancel then begin
AddStatus( '' , clBlack, False ) ;
AddStatus( 'Installation canceled by user!' , clBlack, False ) ;
2005-07-21 23:08:23 +00:00
exit;
2006-01-29 17:24:49 +00:00
end ;
2005-07-21 23:08:23 +00:00
for i : = 0 to eStr. Count - 1 do begin
if Pos( 'gamedll' , TrimLeft( eStr[ i] ) ) = 1 then
eStr[ i] : = '//' + eStr[ i] ;
end ;
if frmMain. optWindows. Checked then
eStr. Add( 'gamedll "addons\metamod\dlls\metamod.dll"' )
else if frmMain. optLinux32. Checked then
eStr. Add( 'gamedll_linux "addons/metamod/dlls/metamod_i386.so"' )
else
eStr. Add( 'gamedll_linux "addons/metamod/dlls/metamod_amd64.so"' ) ;
2007-03-05 21:37:48 +00:00
FileSetAttr( ExtractFilePath( Application. ExeName) + 'temp\liblist.gam' , 0 ) ;
eStr. SaveToFile( ExtractFilePath( Application. ExeName) + 'temp\liblist.gam' ) ;
2005-07-21 23:08:23 +00:00
end ;
eStr. Free;
AddDone;
{ create directories }
AddStatus( 'Creating directories...' , clBlack) ;
// rest...
for i : = 0 to DirList. Count - 1 do begin
2006-01-29 17:24:49 +00:00
if Cancel then begin
AddStatus( '' , clBlack, False ) ;
AddStatus( 'Installation canceled by user!' , clBlack, False ) ;
2005-07-21 23:08:23 +00:00
exit;
2006-01-29 17:24:49 +00:00
end ;
2005-07-21 23:08:23 +00:00
2005-08-04 23:46:22 +00:00
AddStatus( 'Creating directory: ' + DirList[ i] , clBlack) ;
CreateAgain:
try
eGoBack : = False ;
FTPMakeDir( ePath + DirList[ i] ) ;
except
on E: Exception do begin
2006-01-29 17:24:49 +00:00
if Cancel then begin
AddStatus( '' , clBlack, False ) ;
AddStatus( 'Installation canceled by user!' , clBlack, False ) ;
exit;
end ;
2005-08-04 23:46:22 +00:00
if frmMain. IdFTP. Connected then begin
if MessageBox( frmMain. Handle, PChar( 'An error occured while creating "' + FileList[ i] + '"!' + #13 + E. Message + #13 + #13 + 'Retry?' ) , PChar( Application. Title) , MB_ICONSTOP + MB_YESNO) = mrYes then
eGoBack : = True
else begin
Screen. Cursor : = crDefault;
Application. Terminate;
exit;
end ;
end
else if not DoReconnect then
exit
else
eGoBack : = True ;
end ;
end ;
if eGoBack then
2007-02-14 18:55:42 +00:00
goto CreateAgain;
2005-07-21 23:08:23 +00:00
2005-08-04 23:46:22 +00:00
AddDone;
2005-07-21 23:08:23 +00:00
frmMain. ggeAll. Progress : = i;
frmMain. ggeItem. Progress : = i;
end ;
{ upload files }
frmMain. tmrSpeed. Enabled : = True ;
AddStatus( '' , clBlack, False ) ;
AddStatus( 'Uploading files...' , clBlack) ;
AddStatus( '' , clBlack, False ) ;
for i : = 0 to FileList. Count - 1 do begin
2006-01-29 17:24:49 +00:00
if Cancel then begin
AddStatus( '' , clBlack, False ) ;
AddStatus( 'Installation canceled by user!' , clBlack, False ) ;
2005-07-21 23:08:23 +00:00
exit;
2006-01-29 17:24:49 +00:00
end ;
2005-07-21 23:08:23 +00:00
2005-08-04 23:46:22 +00:00
if not IsForbidden( FileList[ i] , OS) then begin
2005-07-21 23:08:23 +00:00
AddStatus( 'Uploading file: ' + FileList[ i] , clBlack) ;
2007-03-05 21:37:48 +00:00
if FileExists( ExtractFilePath( Application. ExeName) + 'temp\' + FileList[ i] ) then begin
frmMain. ggeItem. MaxValue : = FSize( ExtractFilePath( Application. ExeName) + 'temp\' + FileList[ i] ) ;
2005-08-04 23:46:22 +00:00
UploadAgain:
try
eGoBack : = False ;
2005-09-01 17:11:48 +00:00
2005-09-11 15:45:42 +00:00
try
if FileList[ i] = 'liblist.gam' then
frmMain. IdFTP. Site( 'CHMOD 744 liblist.gam' ) ;
except
AddStatus( 'Warning: CHMOD not supported.' , clMaroon) ;
end ;
2005-09-01 17:11:48 +00:00
2007-03-05 21:37:48 +00:00
UploadFile( ExtractFilePath( Application. ExeName) + 'temp\' + FileList[ i] , ePath + FileList[ i] , CopyConfig) ;
2005-09-01 17:11:48 +00:00
2005-09-11 15:45:42 +00:00
try
if FileList[ i] = 'liblist.gam' then
2006-09-20 15:12:49 +00:00
frmMain. IdFTP. Site( 'CHMOD 444 liblist.gam' ) ;
2005-09-11 15:45:42 +00:00
except
AddStatus( 'Warning: CHMOD not supported.' , clMaroon) ;
end ;
2005-08-04 23:46:22 +00:00
except
on E: Exception do begin
2006-01-29 17:24:49 +00:00
if Cancel then begin
AddStatus( '' , clBlack, False ) ;
AddStatus( 'Installation canceled by user!' , clBlack, False ) ;
exit;
end ;
2005-08-04 23:46:22 +00:00
if frmMain. IdFTP. Connected then begin
if MessageBox( frmMain. Handle, PChar( 'An error occured while uploading "' + FileList[ i] + '"!' + #13 + E. Message + #13 + #13 + 'Retry?' ) , PChar( Application. Title) , MB_ICONSTOP + MB_YESNO) = mrYes then
eGoBack : = True
else begin
Screen. Cursor : = crDefault;
Application. Terminate;
exit;
end ;
end
else if not DoReconnect then
exit
else
eGoBack : = True ;
end ;
2005-07-21 23:08:23 +00:00
end ;
2005-08-04 23:46:22 +00:00
if eGoBack then
goto UploadAgain;
end
else
AddNotFound;
2005-07-21 23:08:23 +00:00
end ;
frmMain. ggeAll. Progress : = frmMain. ggeAll. Progress + 1 ;
2005-08-04 23:46:22 +00:00
frmMain. ggeItem. Progress : = 0 ;
2005-07-21 23:08:23 +00:00
end ;
2006-09-11 16:53:26 +00:00
AddStatus( '' , clBlack, False ) ;
2006-09-16 23:26:24 +00:00
AddStatus( 'Cleaning up installation...' , clBlack, False ) ;
2007-03-05 21:37:48 +00:00
if ( DirectoryExists( ExtractFilePath( Application. ExeName) + 'temp' ) ) then
DelTree( ExtractFilePath( Application. ExeName) + 'temp' ) ;
2006-09-11 16:53:26 +00:00
AddDone;
2005-07-21 23:08:23 +00:00
frmMain. ggeAll. Progress : = frmMain. ggeAll. MaxValue;
frmMain. ggeItem. Progress : = frmMain. ggeItem. MaxValue;
AddStatus( '' , clBlack, False ) ;
AddStatus( 'Finished installation!' , clBlack, False ) ;
frmMain. tmrSpeed. Enabled : = False ;
Screen. Cursor : = crDefault;
frmMain. cmdNext. Enabled : = True ;
frmMain. cmdCancel. Hide;
frmMain. cmdNext. Show;
frmMain. tmrSpeed. Enabled : = False ;
frmMain. Caption : = Application. Title;
end ;
end .