From bf9a4b4919c84a2153d42d9a0756106e51dcd6c8 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Fri, 18 Sep 2015 19:48:06 -0400 Subject: [PATCH] Run uninstall before installing. Removes old files. Still need version checker and deleting pyc/pyo files --- scripts/pyfa-setup.iss | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/scripts/pyfa-setup.iss b/scripts/pyfa-setup.iss index 588add45a..b3934d13c 100644 --- a/scripts/pyfa-setup.iss +++ b/scripts/pyfa-setup.iss @@ -105,4 +105,45 @@ begin begin Result := ''; end -end; \ No newline at end of file +end; + +function GetUninstallString: string; +var + sUnInstPath: string; + sUnInstallString: String; +begin + Result := ''; + sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{{3DA39096-C08D-49CD-90E0-1D177F32C8AA}_is1'); //Your App GUID/ID + sUnInstallString := ''; + if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then + RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString); + Result := sUnInstallString; +end; + +function IsUpgrade: Boolean; +begin + Result := (GetUninstallString() <> ''); +end; + +function InitializeSetup: Boolean; +var + V: Integer; + iResultCode: Integer; + sUnInstallString: string; +begin + Result := True; // in case when no previous version is found + if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\{3DA39096-C08D-49CD-90E0-1D177F32C8AA}_is1', 'UninstallString') then //Your App GUID/ID + begin + V := MsgBox(ExpandConstant('An old version of pyfa was detected. Due to recent changes in the application structure, you must uninstall the previous version first. Do you want to uninstall it?'), mbInformation, MB_YESNO); //Custom Message if App installed + if V = IDYES then + begin + sUnInstallString := GetUninstallString(); + sUnInstallString := RemoveQuotes(sUnInstallString); + Exec(ExpandConstant(sUnInstallString), '', '', SW_SHOW, ewWaitUntilTerminated, iResultCode); + Result := True; //if you want to proceed after uninstall + //Exit; //if you want to quit after uninstall + end + else + Result := False; //when older version present and not uninstalled + end; +end;