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}
2323Compression = lzma
2424SolidCompression = yes
2525DefaultDirName = {code:DefAppFolder}
26- UninstallFilesDir = {pf } \ExcelPython
27-
26+ UninstallFilesDir = {userappdata }\ExcelPython
27+ PrivilegesRequired = lowest
2828DirExistsWarning = no
2929
3030[Languages]
@@ -36,8 +36,6 @@ Name: "{app}\xlpython"
3636[Files]
3737Source : " ..\addin\xlpython.xlam" ; DestDir : " {app} " ; Flags : ignoreversion
3838Source : " ..\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]
4341Function DefAppFolder (Param: String): String;
8179 FileHandle: THandle;
8280Begin
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 ;
8799End ;
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 ;
99111end ;
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