Created
July 27, 2012 02:01
-
-
Save lextm/3185774 to your computer and use it in GitHub Desktop.
Inno Setup script sample for advanced part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Code] | |
// function IsModuleLoaded to call at install time | |
// added also setuponly flag | |
function IsModuleLoaded(modulename: String ): Boolean; | |
external 'IsModuleLoaded@files:psvince.dll stdcall setuponly'; | |
// function IsModuleLoadedU to call at uninstall time | |
// added also uninstallonly flag | |
function IsModuleLoadedU(modulename: String ): Boolean; | |
external 'IsModuleLoaded@{app}\psvince.dll stdcall uninstallonly' ; | |
function GetNumber(var temp: String): Integer; | |
var | |
part: String; | |
pos1: Integer; | |
begin | |
if Length(temp) = 0 then | |
begin | |
Result := -1; | |
Exit; | |
end; | |
pos1 := Pos('.', temp); | |
if (pos1 = 0) then | |
begin | |
Result := StrToInt(temp); | |
temp := ''; | |
end | |
else | |
begin | |
part := Copy(temp, 1, pos1 - 1); | |
temp := Copy(temp, pos1 + 1, Length(temp)); | |
Result := StrToInt(part); | |
end; | |
end; | |
function CompareInner(var temp1, temp2: String): Integer; | |
var | |
num1, num2: Integer; | |
begin | |
num1 := GetNumber(temp1); | |
num2 := GetNumber(temp2); | |
if (num1 = -1) or (num2 = -1) then | |
begin | |
Result := 0; | |
Exit; | |
end; | |
if (num1 > num2) then | |
begin | |
Result := 1; | |
end | |
else if (num1 < num2) then | |
begin | |
Result := -1; | |
end | |
else | |
begin | |
Result := CompareInner(temp1, temp2); | |
end; | |
end; | |
function CompareVersion(str1, str2: String): Integer; | |
var | |
temp1, temp2: String; | |
begin | |
temp1 := str1; | |
temp2 := str2; | |
Result := CompareInner(temp1, temp2); | |
end; | |
function InitializeSetup(): Boolean; | |
var | |
oldVersion: String; | |
uninstaller: String; | |
ErrorCode: Integer; | |
begin | |
if IsModuleLoaded( 'bds.exe' ) then | |
begin | |
MsgBox( 'CodeGear RAD Studio is running, please close it and run setup again.', | |
mbError, MB_OK ); | |
Result := False; | |
Exit; | |
end; | |
if RegKeyExists(HKEY_LOCAL_MACHINE, | |
'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppID}_is1') then | |
begin | |
RegQueryStringValue(HKEY_LOCAL_MACHINE, | |
'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppID}_is1', | |
'DisplayVersion', oldVersion); | |
if (CompareVersion(oldVersion, '{#MyAppVersion}') < 0) then | |
begin | |
if MsgBox('Version ' + oldVersion + ' of Code Beautifier Collection is already installed. Continue to use this old version?', | |
mbConfirmation, MB_YESNO) = IDYES then | |
begin | |
Result := False; | |
end | |
else | |
begin | |
RegQueryStringValue(HKEY_LOCAL_MACHINE, | |
'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppID}_is1', | |
'UninstallString', uninstaller); | |
ShellExec('runas', uninstaller, '/SILENT', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode); | |
if (ErrorCode <> 0) then | |
begin | |
MsgBox( 'Failed to uninstall Code Beautifier Collection version ' + oldVersion + '. Please restart Windows and run setup again.', | |
mbError, MB_OK ); | |
Result := False; | |
end | |
else | |
begin | |
Result := True; | |
end; | |
end; | |
end | |
else | |
begin | |
MsgBox('Version ' + oldVersion + ' of Code Beautifier Collection is already installed. This installer will exit.', | |
mbInformation, MB_OK); | |
Result := False; | |
end; | |
end | |
else | |
begin | |
Result := True; | |
end; | |
end; | |
function InitializeUninstall(): Boolean; | |
begin | |
// check if notepad is running | |
if IsModuleLoadedU( 'bds.exe' ) then | |
begin | |
MsgBox( 'CodeGear RAD Studio is running, please close it and run again uninstall.', | |
mbError, MB_OK ); | |
Result := false; | |
end | |
else Result := true; | |
// Unload the DLL, otherwise the dll psvince is not deleted | |
UnloadDLL(ExpandConstant('{app}\psvince.dll')); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment