correct uninstall string in registry (#347)

This commit is contained in:
Cyano Hao 2024-03-30 10:35:45 +08:00 committed by GitHub
parent 9a99781549
commit 89423870dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 85 additions and 39 deletions

View File

@ -323,16 +323,16 @@ bool isGreenEdition()
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (!gIsGreenEditionInited) { if (!gIsGreenEditionInited) {
QString appPath = QApplication::instance()->applicationDirPath(); QString appPath = QApplication::instance()->applicationDirPath();
appPath = excludeTrailingPathDelimiter(appPath); appPath = excludeTrailingPathDelimiter(localizePath(appPath));
QString keyString = R"(Software\Microsoft\Windows\CurrentVersion\Uninstall\RedPanda-C++)"; QString keyString = R"(Software\Microsoft\Windows\CurrentVersion\Uninstall\RedPanda-C++)";
QString systemInstallPath; QString systemInstallPath;
readRegistry(HKEY_LOCAL_MACHINE, keyString, "UninstallString", systemInstallPath); readRegistry(HKEY_LOCAL_MACHINE, keyString, "InstallLocation", systemInstallPath);
if (!systemInstallPath.isEmpty()) if (!systemInstallPath.isEmpty())
systemInstallPath = excludeTrailingPathDelimiter(extractFileDir(systemInstallPath)); systemInstallPath = excludeTrailingPathDelimiter(systemInstallPath);
QString userInstallPath; QString userInstallPath;
readRegistry(HKEY_CURRENT_USER, keyString, "UninstallString", userInstallPath); readRegistry(HKEY_CURRENT_USER, keyString, "InstallLocation", userInstallPath);
if (!userInstallPath.isEmpty()) if (!userInstallPath.isEmpty())
userInstallPath = excludeTrailingPathDelimiter(extractFileDir(userInstallPath)); userInstallPath = excludeTrailingPathDelimiter(userInstallPath);
gIsGreenEdition = appPath.compare(systemInstallPath, Qt::CaseInsensitive) != 0 && gIsGreenEdition = appPath.compare(systemInstallPath, Qt::CaseInsensitive) != 0 &&
appPath.compare(userInstallPath, Qt::CaseInsensitive) != 0; appPath.compare(userInstallPath, Qt::CaseInsensitive) != 0;
gIsGreenEditionInited = true; gIsGreenEditionInited = true;

View File

@ -10,7 +10,8 @@ LangString MessageSectionShortcuts 1033 "Create shortcuts to Red Panda
LangString MessageSectionCompress 1033 "Compress the Red Panda C++ installation directory (requires Windows 10 or later)" LangString MessageSectionCompress 1033 "Compress the Red Panda C++ installation directory (requires Windows 10 or later)"
LangString MessageSectionConfig 1033 "Remove all leftover configuration files from previous installs" LangString MessageSectionConfig 1033 "Remove all leftover configuration files from previous installs"
LangString MessageUninstallText 1033 "This program will uninstall Red Panda C++, continue?" LangString MessageUninstallText 1033 "This program will uninstall Red Panda C++, continue?"
LangString MessageUninstallExisting 1033 " Red Panda C++ is already installed. $\n$\nClick OK to remove the previous version or Cancel to cancel the installation." LangString MessageUninstallV2 1033 " Red Panda C++ is already installed. $\n$\nClick OK to remove the previous version or Cancel to cancel the installation."
LangString MessageUninstallingExisting 1033 "Removing the previous version..."
LangString MessageCompressing 1033 "Compressing the Red Panda C++ installation directory..." LangString MessageCompressing 1033 "Compressing the Red Panda C++ installation directory..."
LangString MessageRemoveConfig 1033 "Do you want to remove all the remaining configuration files?" LangString MessageRemoveConfig 1033 "Do you want to remove all the remaining configuration files?"
LangString SectionMainName 1033 "Program files (required)" LangString SectionMainName 1033 "Program files (required)"
@ -44,7 +45,8 @@ LangString MessageSectionShortcuts 2052 "开始菜单和快捷方式"
LangString MessageSectionCompress 2052 "压缩小熊猫 C++ 安装目录(需要 Windows 10 或更高版本)" LangString MessageSectionCompress 2052 "压缩小熊猫 C++ 安装目录(需要 Windows 10 或更高版本)"
LangString MessageSectionConfig 2052 "删除之前安装遗留的所有配置文件" LangString MessageSectionConfig 2052 "删除之前安装遗留的所有配置文件"
LangString MessageUninstallText 2052 "将要删除小熊猫C++, 是否继续?" LangString MessageUninstallText 2052 "将要删除小熊猫C++, 是否继续?"
LangString MessageUninstallExisting 2052 "本机上已经安装了旧版本小熊猫C++. $\n$\n点击'确定'以将其删除并继续,或者'取消'中止安装。" LangString MessageUninstallV2 2052 "本机上已经安装了旧版本小熊猫C++. $\n$\n点击'确定'以将其删除并继续,或者'取消'中止安装。"
LangString MessageUninstallingExisting 2052 "正在删除旧版本..."
LangString MessageCompressing 2052 "正在压缩小熊猫 C++ 安装目录..." LangString MessageCompressing 2052 "正在压缩小熊猫 C++ 安装目录..."
LangString MessageRemoveConfig 2052 "你想要删除所有的配置文件吗?" LangString MessageRemoveConfig 2052 "你想要删除所有的配置文件吗?"
LangString SectionMainName 2052 "程序文件 (必须)" LangString SectionMainName 2052 "程序文件 (必须)"

View File

@ -4,10 +4,14 @@ SetFont "Segoe UI" 11
Unicode True Unicode True
!define DISPLAY_NAME "Red Panda C++ ${APP_VERSION} (${ARCH})" !define DISPLAY_NAME "Red Panda C++ ${APP_VERSION} (${ARCH})"
!define REGISTRY_PROGRAM_ID "RedPanda-C++"
!define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGISTRY_PROGRAM_ID}"
!include "Integration.nsh" !include "Integration.nsh"
!include "LogicLib.nsh" !include "LogicLib.nsh"
!include "MUI2.nsh" !include "MUI2.nsh"
!include "WinVer.nsh" !include "WinVer.nsh"
!include "WordFunc.nsh"
!include "x64.nsh" !include "x64.nsh"
!include "lang.nsh" !include "lang.nsh"
@ -77,6 +81,13 @@ InstType "Safe";3
!insertmacro MUI_LANGUAGE "English" !insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese" !insertmacro MUI_LANGUAGE "SimpChinese"
####################################################################
# Silently uninstall previous version
Section "" SecUninstallPrevious
!insertmacro CheckPreviousInstaller
SectionEnd
#################################################################### ####################################################################
# Files, by option section # Files, by option section
@ -87,11 +98,13 @@ Section "$(SectionMainName)" SectionMain
; Allways create an uninstaller ; Allways create an uninstaller
WriteUninstaller "$INSTDIR\uninstall.exe" WriteUninstaller "$INSTDIR\uninstall.exe"
WriteRegStr ShCtx "Software\Microsoft\Windows\CurrentVersion\Uninstall\RedPanda-C++" "DisplayName" "Redpanda-C++" WriteRegStr ShCtx "${UNINSTKEY}" "DisplayName" "Redpanda-C++"
WriteRegStr ShCtx "Software\Microsoft\Windows\CurrentVersion\Uninstall\RedPanda-C++" "UninstallString" "$INSTDIR\uninstall.exe" WriteRegStr ShCtx "${UNINSTKEY}" "InstallLocation" "$INSTDIR"
WriteRegStr ShCtx "Software\Microsoft\Windows\CurrentVersion\Uninstall\RedPanda-C++" "DisplayVersion" "${APP_VERSION}" WriteRegStr ShCtx "${UNINSTKEY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegStr ShCtx "Software\Microsoft\Windows\CurrentVersion\Uninstall\RedPanda-C++" "DisplayIcon" "$INSTDIR\RedPandaIDE.exe" WriteRegStr ShCtx "${UNINSTKEY}" "QuietUninstallString" '"$INSTDIR\uninstall.exe" /S'
WriteRegStr ShCtx "Software\Microsoft\Windows\CurrentVersion\Uninstall\RedPanda-C++" "Publisher" "Roy Qu(royqh1979@gmail.com)" WriteRegStr ShCtx "${UNINSTKEY}" "DisplayVersion" "${APP_VERSION}"
WriteRegStr ShCtx "${UNINSTKEY}" "DisplayIcon" "$INSTDIR\RedPandaIDE.exe"
WriteRegStr ShCtx "${UNINSTKEY}" "Publisher" "Roy Qu(royqh1979@gmail.com)"
; Write required files ; Write required files
@ -300,18 +313,7 @@ FunctionEnd
Function myGuiInit Function myGuiInit
!insertmacro CheckOsArch !insertmacro CheckOsArch
!insertmacro CheckOsBuild !insertmacro CheckOsBuild
!insertmacro CheckV2Installer
; uninstall existing
SetRegView 32
Call UninstallExisting
SetRegView 64
Call UninstallExisting
!if "${ARCH}" == "x86"
SetRegView 32
!else
SetRegView 64
!endif
!insertmacro SectionAction_CheckMingw64 !insertmacro SectionAction_CheckMingw64
!insertmacro SectionAction_CheckCompress !insertmacro SectionAction_CheckCompress
@ -330,13 +332,30 @@ FunctionEnd
Var /GLOBAL uninstallString Var /GLOBAL uninstallString
Var /GLOBAL installLocation Var /GLOBAL installLocation
Var /GLOBAL oldVersion
Var /GLOBAL versionCompareResult
Function UninstallExisting Function UninstallExisting
ReadRegStr $uninstallString ShCtx "Software\Microsoft\Windows\CurrentVersion\Uninstall\RedPanda-C++" "UninstallString" ReadRegStr $uninstallString ShCtx "${UNINSTKEY}" "UninstallString"
${If} $uninstallString != "" ${If} $uninstallString != ""
ReadRegStr $installLocation ShCtx "${UNINSTKEY}" "InstallLocation"
DetailPrint "$(MessageUninstallingExisting)"
; uninstallString already quoted; NSIS requires installLocation unquoted
ExecWait '$uninstallString /S _?=$installLocation'
Delete "$uninstallString"
RMDir "$installLocation"
${EndIf}
FunctionEnd
Function UninstallV2
ReadRegStr $oldVersion HKLM "${UNINSTKEY}" "DisplayVersion"
${If} $oldVersion != ""
${VersionCompare} "3.0" "$oldVersion" $versionCompareResult
${If} "$versionCompareResult" == 1 ; 1st version is greater
ReadRegStr $uninstallString HKLM "${UNINSTKEY}" "UninstallString"
GetFullPathName $installLocation "$uninstallString\.." ; remove '\uninstall.exe' GetFullPathName $installLocation "$uninstallString\.." ; remove '\uninstall.exe'
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \ MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"$(MessageUninstallExisting)" \ "$(MessageUninstallV2)" \
/SD IDNO \ /SD IDNO \
IDOK uninst IDOK uninst
Abort Abort
@ -349,6 +368,7 @@ Function UninstallExisting
RMDir "$installLocation" RMDir "$installLocation"
BringToFront BringToFront
${EndIf} ${EndIf}
${EndIf}
FunctionEnd FunctionEnd
#################################################################### ####################################################################
@ -399,7 +419,7 @@ Section "Uninstall"
RMDir "$INSTDIR" RMDir "$INSTDIR"
; Remove registry keys ; Remove registry keys
DeleteRegKey ShCtx "Software\Microsoft\Windows\CurrentVersion\Uninstall\RedPanda-C++" DeleteRegKey ShCtx "${UNINSTKEY}"
DeleteRegKey ShCtx "Software\RedPanda-C++" DeleteRegKey ShCtx "Software\RedPanda-C++"
MessageBox MB_YESNO "$(MessageRemoveConfig)" /SD IDNO IDNO SkipRemoveConfig MessageBox MB_YESNO "$(MessageRemoveConfig)" /SD IDNO IDNO SkipRemoveConfig

View File

@ -45,6 +45,30 @@ Var /GLOBAL sectionDepTemp
${EndIf} ${EndIf}
!macroend !macroend
!macro CheckV2Installer
SetRegView 32
Call UninstallV2
SetRegView 64
Call UninstallV2
!if "${ARCH}" == "x86"
SetRegView 32
!else
SetRegView 64
!endif
!macroend
!macro CheckPreviousInstaller
SetRegView 32
Call UninstallExisting
SetRegView 64
Call UninstallExisting
!if "${ARCH}" == "x86"
SetRegView 32
!else
SetRegView 64
!endif
!macroend
!macro DisableSection section !macro DisableSection section
SectionGetFlags ${section} $sectionDepFlag SectionGetFlags ${section} $sectionDepFlag

View File

@ -1,2 +1,2 @@
APP_VERSION="2.27" APP_VERSION="3.0"
APP_VERSION_SUFFIX="rc1" APP_VERSION_SUFFIX="rc1"