2005-07-21 23:08:23 +00:00
unit UnitInstall;
interface
uses SysUtils, Classes, Windows, Graphics, Forms, ShellAPI, Controls, Messages,
TlHelp32, IdFTPCommon, ComCtrls;
type TMod = ( modNone, modCS, modDoD, modTFC, modNS, modTS, modESF) ;
type TOS = ( osWindows, osLinux32, osLinux64) ;
procedure AddStatus( Text : String ; Color: TColor; ShowTime: Boolean = True ) ;
procedure AddDone( Additional: String = '' ) ;
2005-08-03 18:45:16 +00:00
procedure AddSkipped;
2005-08-04 23:46:22 +00:00
procedure AddNotFound;
2005-07-21 23:08:23 +00:00
function DelDir( Dir: string ) : Boolean ;
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 ;
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
function DelDir( Dir: string ) : Boolean ;
var Fos: TSHFileOpStruct;
begin
ZeroMemory( @ Fos, SizeOf( Fos) ) ;
with Fos do begin
wFunc : = FO_DELETE;
fFlags : = FOF_SILENT or FOF_NOCONFIRMATION;
pFrom : = PChar( Dir + #0 ) ;
end ;
Result : = ( ShFileOperation( fos) = 0 ) ;
end ;
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
frmMain. IdFTP. Put( eFile, eDestination) ;
2005-08-03 18:45:16 +00:00
AddDone;
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 ;
osLinux64: begin
if ExtractFileExt( eFile) = '.dll' then
Result : = True ;
if ExtractFileExt( eFile) = '.exe' then
Result : = True ;
if Pos( '_i386' , ExtractFileName( eFile) ) < > 0 then
Result : = True ;
end ;
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 ;
begin
AddStatus( 'Scanning for directories...' , clBlack) ;
with GetAllFiles( ExtractFilePath( ParamStr( 0 ) ) + 'files\*.*' , faDirectory, True , True ) do begin
DirList. Text : = Text ;
Free;
end ;
AddDone( 'found ' + IntToStr( DirList. Count) + ' directories..' ) ;
AddStatus( 'Scanning for files...' , clBlack) ;
with GetAllFiles( ExtractFilePath( ParamStr( 0 ) ) + 'files\*.*' , faAnyFile, True , False ) do begin
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;
if ( GetProcessID( 'Steam.exe' ) < > - 1 ) and ( SteamInstall) then begin
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
DirList[ i] : = Copy( DirList[ i] , Length( ExtractFilePath( ParamStr( 0 ) ) ) + 7 , Length( DirList[ i] ) ) ;
for i : = 0 to FileList. Count - 1 do
FileList[ i] : = Copy( FileList[ i] , Length( ExtractFilePath( ParamStr( 0 ) ) ) + 7 , Length( FileList[ i] ) ) ;
{ 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"' ) ;
eStr. Add( 'gamedll_linux "addons/metamod/dlls/metamod_i386.so"' ) ;
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
2005-08-03 18:45:16 +00:00
if Pos( 'esforce' , 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) ;
2005-07-21 23:08:23 +00:00
FileCopy( ExtractFilePath( ParamStr( 0 ) ) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 6 , Length( FileList[ i] ) ) , CopyConfig) ;
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) ;
2005-07-21 23:08:23 +00:00
FileCopy( ExtractFilePath( ParamStr( 0 ) ) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 9 , Length( FileList[ i] ) ) , CopyConfig) ;
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) ;
2005-07-21 23:08:23 +00:00
FileCopy( ExtractFilePath( ParamStr( 0 ) ) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 5 , Length( FileList[ i] ) ) , CopyConfig) ;
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) ;
2005-07-21 23:08:23 +00:00
FileCopy( ExtractFilePath( ParamStr( 0 ) ) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 5 , Length( FileList[ i] ) ) , CopyConfig) ;
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) ;
2005-07-21 23:08:23 +00:00
FileCopy( ExtractFilePath( ParamStr( 0 ) ) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 4 , Length( FileList[ i] ) ) , CopyConfig) ;
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) ;
2005-07-21 23:08:23 +00:00
FileCopy( ExtractFilePath( ParamStr( 0 ) ) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 4 , Length( FileList[ i] ) ) , CopyConfig) ;
end ;
end ;
modESF: begin
2005-08-03 18:45:16 +00:00
if Pos( 'esforce' , 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) ;
2005-07-21 23:08:23 +00:00
FileCopy( ExtractFilePath( ParamStr( 0 ) ) + 'files\' + FileList[ i] , ePath + 'addons\amxmodx\' + Copy( FileList[ i] , 4 , Length( FileList[ i] ) ) , CopyConfig) ;
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
eStr : = TStringList. Create;
eStr. Add( ';;Metamod plugins.ini' ) ;
2005-09-01 17:11:48 +00:00
eStr. Add( ';;AMX Mod X ' + VERSION) ;
2005-07-21 23:08:23 +00:00
if OS = osWindows then
eStr. Add( 'win32 addons\amxmodx\dlls\amxmodx_mm.dll' )
else if OS = osLinux32 then
2005-08-02 02:56:09 +00:00
eStr. Add( 'linux addons/amxmodx/dlls/amxmodx_mm_i386.so' )
2005-07-21 23:08:23 +00:00
else
2005-08-02 02:56:09 +00:00
eStr. Add( 'linux addons/amxmodx/dlls/amxmodx_mm_amd64.so' ) ;
2005-07-21 23:08:23 +00:00
eStr. SaveToFile( ePath + 'addons\metamod\plugins.ini' ) ;
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
MessageBox( frmMain. Handle, 'Failed to reconnect. Installation aborted.' , PChar( Application. Title) , MB_ICONSTOP) ;
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-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) ;
with GetAllFiles( ExtractFilePath( ParamStr( 0 ) ) + 'temp\*.*' , faDirectory, True , True ) do begin
DirList. Text : = Text ;
Free;
end ;
AddDone( 'found ' + IntToStr( DirList. Count) + ' directories..' ) ;
AddStatus( 'Scanning for files...' , clBlack) ;
with GetAllFiles( ExtractFilePath( ParamStr( 0 ) ) + 'temp\*.*' , faAnyFile, True , False ) do begin
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
DirList[ i] : = Copy( DirList[ i] , Length( ExtractFilePath( ParamStr( 0 ) ) ) + 6 , Length( DirList[ i] ) ) ;
for i : = 0 to FileList. Count - 1 do
FileList[ i] : = Copy( FileList[ i] , Length( ExtractFilePath( ParamStr( 0 ) ) ) + 6 , Length( FileList[ i] ) ) ;
// liblist.gam
2005-08-01 00:19:25 +00:00
CopyConfig : = True ;
2005-07-21 23:08:23 +00:00
AddStatus( 'Editing liblist.gam...' , clBlack) ;
eStr : = TStringList. Create;
eStr. LoadFromFile( ExtractFilePath( ParamStr( 0 ) ) + 'temp\liblist.gam' ) ;
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"' ) ;
FileSetAttr( ExtractFilePath( ParamStr( 0 ) ) + 'temp\liblist.gam' , 0 ) ;
eStr. SaveToFile( ExtractFilePath( ParamStr( 0 ) ) + 'temp\liblist.gam' ) ;
2005-08-01 00:19:25 +00:00
end
else 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 ;
2005-07-21 23:08:23 +00:00
end ;
2005-08-01 00:19:25 +00:00
2005-07-21 23:08:23 +00:00
eStr. Free;
AddDone;
ePath : = '/' ;
CurNode : = frmMain. trvDirectories. Selected;
repeat
ePath : = '/' + CurNode. Text + ePath;
CurNode : = CurNode. Parent;
until ( not Assigned( CurNode) ) ;
{ 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
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) ;
2005-08-04 23:46:22 +00:00
if FileExists( ExtractFilePath( ParamStr( 0 ) ) + 'temp\' + FileList[ i] ) then begin
frmMain. ggeItem. MaxValue : = FSize( ExtractFilePath( ParamStr( 0 ) ) + 'temp\' + FileList[ i] ) ;
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
2005-08-04 23:46:22 +00:00
UploadFile( ExtractFilePath( ParamStr( 0 ) ) + '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
frmMain. IdFTP. Size( 'CHMOD 444 liblist.gam' ) ;
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 ;
frmMain. ggeAll. Progress : = frmMain. ggeAll. MaxValue;
frmMain. ggeItem. Progress : = frmMain. ggeItem. MaxValue;
AddStatus( '' , clBlack, False ) ;
AddStatus( 'Finished installation!' , clBlack, False ) ;
DelDir( ExtractFilePath( ParamStr( 0 ) ) + 'temp' ) ;
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 .