📄 is_main.pas
字号:
(* is_main.pas: Pascal Scripts routines for Inno Setup Windows installer. * ==================================================================== * Copyright (c) 2000-2005 CollabNet. All rights reserved. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://subversion.tigris.org/license-1.html. * If newer versions of this license are posted there, you may use a * newer version instead, at your option. * * This software consists of voluntary contributions made by many * individuals. For exact contribution history, see the revision * history and logs, available at http://subversion.tigris.org/. * ==================================================================== *)// ****************************************************************************// Global variablesvar // Required dlls g_bMsVcpNotFound: Boolean; // Visual C++ 6.0 Runtimes g_bShFolderNotFound: Boolean; // shfolder.dll // Apache g_bHandleApache: Boolean; g_sApachePath: String; g_sApachePathBin: String; g_sApachePathConf: String;const // Visual C++ 6.0 Runtime file related FILE_MSVCPDLL = 'msvcp60.dll'; URL_VCREDIST = 'http://support.microsoft.com/support/kb/articles/Q259/4/03.ASP'; // shfolder.dll related FILE_SHFOLDERDLL = 'shfolder.dll'; URL_SHFREDIST = 'http://download.microsoft.com/download/platformsdk/Redist/5.50.4027.300/W9XNT4/EN-US/shfinst.EXE'; // Apache REG_KEY_APACHE_SERVICE = 'SYSTEM\CurrentControlSet\Services\Apache2'; APACHE_VER_MIN = '{#= apache_ver_min}'; // Status codes for modules in httpd.conf STATUS_NONE = 0; STATUS_DISABLED = 1; STATUS_ENABLED = 2;// ****************************************************************************// Name: BackslashToSlash// Purpose: Turning back slashes into slashes. This function is stolen// shamelessly from the Inno help file.// NOTE: For some unknown reason, this function has to stay here before// other functions in order to avoid compile errors from the setup// program. I don't not why, ..anyone?function BackslashToSlash(const S: String): String;var I: Integer;begin Result := S; I := 1; while I <= Length(Result) do begin if Result[I] = '\' then Result[I] := '/'; // Go to the next character. But do not simply increment I by 1. // Increment by CharLength() in case Result[I] is a double-byte character. I := I + CharLength(Result, I); end;end;///////////////////////////////////////////////////////////////////////////////// APACHE related stuff// ****************************************************************************// Name: ApachePathParent// Purpose: Returns the path of Apache parent folder.function ApachePathParent(): String;var sApachePathParent: String; iLengthString: Integer; iPosK: Integer;begin if RegKeyExists(HKLM, REG_KEY_APACHE_SERVICE) and UsingWinNT then begin // Set g_sApachePathBin RegQueryStringValue(HKLM, REG_KEY_APACHE_SERVICE, 'ImagePath', sApachePathParent); // Remove the run command and strip quotes away from g_sApachePathBin iPosK := Pos('-k', sApachePathParent); iLengthString := Length(sApachePathParent); Delete(sApachePathParent, iLengthString - (iLengthString - iPosK), iPosK); sApachePathParent := RemoveQuotes(sApachePathParent); // Strip basename twice so only the Apache parent path is left sApachePathParent := ExtractFileDir(sApachePathParent); sApachePathParent := ExtractFileDir(sApachePathParent); end; // Function variables Result := sApachePathParent;end;// ****************************************************************************// Name: ApacheTask// Purpose: Decide if we should handle the Apache Server or notfunction ApacheTask(): Boolean;begin Result:= UsingWinNT and not (ApachePathParent = '');end;// ****************************************************************************// Name: ApacheBinFound// Purpose: Checks if bin\apache.exe excists in Apache's parent folder.// Returns True if Yes and False if Nofunction ApacheBinFound(): Boolean;var sApacheBinary: String;begin sApacheBinary := ApachePathParent() + '\bin\apache.exe'; if FileExists(sApacheBinary) then begin Result:= True; end else begin Result:= False; end;end;// ****************************************************************************// Name: ApacheServiceStop// Purpose: Stopping the Apache Serviceprocedure ApacheServiceStop();var bRetVal: Boolean; ErrorCode: Integer;begin bRetVal := Exec('cmd.exe', '/C apache -k stop', g_sApachePathBin, SW_HIDE, ewWaitUntilTerminated, ErrorCode);end;// ****************************************************************************// Name: ApacheServiceStart// Purpose: Starting the Apache Serviceprocedure ApacheServiceStart();var bRetVal: Boolean; ErrorCode: Integer;begin bRetVal := Exec('cmd.exe', '/C apache -k start', g_sApachePathBin, SW_HIDE, ewWaitUntilTerminated, ErrorCode);end;// ****************************************************************************// Name: ApacheModuleStatus// Purpose: Identifying if a module is in a string and returning it's statusFunction ApacheModuleStatus(sLine: String): Integer;var iStatus: Integer; iPosSharp, iPosModule: Integer;begin iStatus:= STATUS_NONE; iPosSharp := Pos('#', sLine); iPosModule := Pos('LoadModule ', sLine); if Pos('foo_module ', sLine) = 0 then begin if (iPosSharp > 0) and (iPosModule > iPosSharp) then begin iStatus := STATUS_DISABLED; end else begin iStatus := STATUS_ENABLED; end; end; Result := iStatus;end;// ****************************************************************************// Name: ApacheModuleName// Purpose: Extracting and returning a module name from a stringFunction ApacheModuleName(sLine: String): String;var iPosModNameStart, iPosModNameEnd: Integer; iCharNum: Integer; sModuleName : String;begin iPosModNameStart := (Pos('modules/mod_', sLine) + 12); iPosModNameEnd := (Pos('.so', sLine) - 1); sModuleName := ''; iCharNum := iPosModNameStart; for iCharNum := iPosModNameStart to iPosModNameEnd do begin sModuleName := sModuleName + StrGet(sLine, iCharNum); end; sModuleName := sModuleName + '_module'; Result := sModuleName;end;// ****************************************************************************// Name: ApacheConfFileEdit// Purpose: Checking if the httpd.conf (Subversion related modules) file// if needed.procedure ApacheConfFileEdit(aHttpdConf: TArrayOfString; iPosFileModules, iPosFileModulesPost, iPosModDav, iStatusModDav, iPosModDavSvn, iStatusModDavSvn, iPosModAuthzSvn, iStatusModAuthzSvn: Integer);var sConfFileName, sTimeString: String; sModuleDir, sLoadModDav, sLoadModDavSvn, sLoadModAuthzSvn: String;begin sConfFileName := g_sApachePathConf + '\httpd.conf'; sTimeString := GetDateTimeString('yyyy/mm/dd hh:mm:ss', '-', ':'); sModuleDir := ExpandConstant('{app}'); sModuleDir := sModuleDir + '\bin'; sModuleDir := BackslashToSlash(sModuleDir); sLoadModDav := 'LoadModule dav_module modules/mod_dav.so'; sLoadModDavSvn := 'LoadModule dav_svn_module "' + sModuleDir + '/mod_dav_svn.so"'; sLoadModAuthzSvn := 'LoadModule authz_svn_module "' + sModuleDir + '/mod_authz_svn.so"'; //Backup the current httpd.conf FileCopy (sConfFileName, sConfFileName + '-svn-' + sTimeString + '.bak', False); // Add the modules if they're not there if (iStatusModDav = STATUS_NONE) then begin if iPosModDav = 0 then begin iPosModDav := iPosFileModules + 10; end; aHttpdConf[iPosModDav] := aHttpdConf[iPosModDav] + #13#10 + sLoadModDav; end; if (iStatusModDavSvn = STATUS_NONE) then aHttpdConf[iPosFileModulesPost -1] := aHttpdConf[iPosFileModulesPost -1] + #13#10 + sLoadModDavSvn; if (iStatusModAuthzSvn = STATUS_NONE) then aHttpdConf[iPosFileModulesPost -1] := aHttpdConf[iPosFileModulesPost -1] + #13#10 + sLoadModAuthzSvn; // Enable modules if disabled ******************************** if (iStatusModDav = STATUS_DISABLED) then aHttpdConf[iPosModDav] := sLoadModDav; if (iStatusModDavSvn = STATUS_DISABLED) then aHttpdConf[iPosModDavSvn] := sLoadModDavSvn; if (iStatusModAuthzSvn = STATUS_DISABLED) then aHttpdConf[iPosModAuthzSvn] := sLoadModAuthzSvn; SaveStringsToFile(sConfFileName, aHttpdConf, False);end;// ****************************************************************************// Name: ApacheConfFileHandle// Purpose: Checking if the httpd.conf (Subversion related modules) file should// be edited and sets some data for further proccessing if needed.procedure ApacheConfFileHandle();var aHttpdConf : TArrayOfString; sConfFileName: String; sCurrentLine: String; iLineNum, iArrayLen: Integer; iPosFileModules, iPosFileModulesPost : Integer; iPosModDav, iPosModDavSvn, iPosModAuthzSvn: Integer; iStatusModDav, iStatusModDavSvn, iStatusModAuthzSvn: Integer;begin iStatusModDav := STATUS_NONE; iStatusModDavSvn := STATUS_NONE; iStatusModAuthzSvn := STATUS_NONE; sConfFileName:= g_sApachePathConf + '\httpd.conf'; //Load the httpd.conf to the aHttpdConf array and init vars LoadStringsFromFile(sConfFileName, aHttpdConf); iArrayLen := GetArrayLength(aHttpdConf)-1; // Check httpd.conf line by line
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -