Skip to content

Commit e46bd09

Browse files
installer now:
- checks if .xlam exists and is in use - uninstalls previous version if found - installs to local user thereby not requiring admin priviledges
1 parent e01f929 commit e46bd09

File tree

1 file changed

+69
-9
lines changed

1 file changed

+69
-9
lines changed

installer/setup.iss

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
33

44
#define MyAppName "ExcelPython"
5-
#define MyAppVersion "2.0.7"
5+
#define MyAppVersion "2.0.8"
66
#define MyAppPublisher "ericremoreynolds"
77
#define MyAppURL "https://github.com/ericremoreynolds/excelpython"
88

@@ -23,8 +23,8 @@ OutputBaseFilename=excelpython-{#MyAppVersion}
2323
Compression=lzma
2424
SolidCompression=yes
2525
DefaultDirName={code:DefAppFolder}
26-
UninstallFilesDir={pf}\ExcelPython
27-
26+
UninstallFilesDir={userappdata}\ExcelPython
27+
PrivilegesRequired=lowest
2828
DirExistsWarning=no
2929

3030
[Languages]
@@ -36,8 +36,6 @@ Name: "{app}\xlpython"
3636
[Files]
3737
Source: "..\addin\xlpython.xlam"; DestDir: "{app}"; Flags: ignoreversion
3838
Source: "..\addin\xlpython\*"; DestDir: "{app}\xlpython"; Flags: ignoreversion recursesubdirs createallsubdirs
39-
; Source: IssProc.dll; DestDir: "{tmp}"; Flags: dontcopy
40-
; Source: IssProc.dll; DestDir: "{pf}\ExcelPython"
4139

4240
[Code]
4341
Function DefAppFolder(Param: String): String;
@@ -81,9 +79,23 @@ Var
8179
FileHandle: THandle;
8280
Begin
8381
Result := False;
84-
FileHandle := CreateFile(FileName, GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
85-
Result := (FileHandle <> INVALID_HANDLE_VALUE);
86-
If Result Then CloseHandle(FileHandle);
82+
If Not FileExists(FileName) Then Begin
83+
Result := True;
84+
End Else Begin
85+
FileHandle := CreateFile(FileName, GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
86+
Result := (FileHandle <> INVALID_HANDLE_VALUE);
87+
If Result Then CloseHandle(FileHandle);
88+
End;
89+
End;
90+
91+
Function InitializeSetup(): Boolean;
92+
Begin
93+
If CanDelete(DefAppFolder('') + '\xlpython.xlam') Then Begin
94+
Result := true;
95+
End Else Begin
96+
MsgBox('ExcelPython appears to be in use - please make sure you close all instances of Excel before proceeding.', mbError, MB_OK)
97+
Result := false;
98+
End;
8799
End;
88100
89101
// Ensure that the add-in can be deleted
@@ -93,8 +105,56 @@ begin
93105
If CanDelete(ExpandConstant('{app}\xlpython.xlam')) Then Begin
94106
Result := true;
95107
End Else Begin
96-
MsgBox('ExcelPython appears to be in use - please make sure you close all instances of Excel before uninstalling.', mbError, MB_OK)
108+
MsgBox('ExcelPython appears to be in use - please make sure you close all instances of Excel before proceeding.', mbError, MB_OK)
97109
Result := false;
98110
End;
99111
end;
100112
113+
/////////////////////////////////////////////////////////////////////
114+
function GetUninstallString(): String;
115+
var
116+
sUnInstPath: String;
117+
sUnInstallString: String;
118+
begin
119+
sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');
120+
sUnInstallString := '';
121+
if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
122+
RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
123+
Result := sUnInstallString;
124+
end;
125+
126+
127+
/////////////////////////////////////////////////////////////////////
128+
function UnInstallOldVersion(): Integer;
129+
var
130+
sUnInstallString: String;
131+
iResultCode: Integer;
132+
begin
133+
// Return Values:
134+
// 1 - uninstall string is empty
135+
// 2 - error executing the UnInstallString
136+
// 3 - successfully executed the UnInstallString
137+
138+
// default return value
139+
Result := 0;
140+
141+
// get the uninstall string of the old app
142+
sUnInstallString := GetUninstallString();
143+
if sUnInstallString <> '' then begin
144+
sUnInstallString := RemoveQuotes(sUnInstallString);
145+
if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
146+
Result := 3
147+
else
148+
Result := 2;
149+
end else
150+
Result := 1;
151+
end;
152+
153+
/////////////////////////////////////////////////////////////////////
154+
Procedure CurStepChanged(CurStep: TSetupStep);
155+
Begin
156+
If (CurStep=ssInstall) Then Begin
157+
UnInstallOldVersion();
158+
End;
159+
End;
160+

0 commit comments

Comments
 (0)