ENH: Add NSIS options page for path selection, fix adding and removing from path, add welcome page and license page
This commit is contained in:
parent
16d126675d
commit
619ebce6cf
|
@ -239,6 +239,7 @@ IF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
|
||||||
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "CMake is a build tool")
|
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "CMake is a build tool")
|
||||||
SET(CPACK_PACKAGE_VENDOR "Kitware")
|
SET(CPACK_PACKAGE_VENDOR "Kitware")
|
||||||
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt")
|
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt")
|
||||||
|
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt")
|
||||||
SET(CPACK_PACKAGE_VERSION_MAJOR "${CMake_VERSION_MAJOR}")
|
SET(CPACK_PACKAGE_VERSION_MAJOR "${CMake_VERSION_MAJOR}")
|
||||||
SET(CPACK_PACKAGE_VERSION_MINOR "${CMake_VERSION_MINOR}")
|
SET(CPACK_PACKAGE_VERSION_MINOR "${CMake_VERSION_MINOR}")
|
||||||
SET(CPACK_PACKAGE_VERSION_PATCH "${CMake_VERSION_PATCH}")
|
SET(CPACK_PACKAGE_VERSION_PATCH "${CMake_VERSION_PATCH}")
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
[Settings]
|
||||||
|
NumFields=3
|
||||||
|
|
||||||
|
[Field 1]
|
||||||
|
Type=label
|
||||||
|
Text=By default @CPACK_PACKAGE_INSTALL_DIRECTORY@ does not add its directory to the system PATH.
|
||||||
|
Left=0
|
||||||
|
Right=-1
|
||||||
|
Top=0
|
||||||
|
Bottom=20
|
||||||
|
|
||||||
|
[Field 2]
|
||||||
|
Type=checkbox
|
||||||
|
Text=Check this option to add the path to the system PATH
|
||||||
|
Left=0
|
||||||
|
Right=-1
|
||||||
|
Top=30
|
||||||
|
Bottom=40
|
||||||
|
State=0
|
||||||
|
|
||||||
|
[Field 3]
|
||||||
|
Type=checkbox
|
||||||
|
Text=If administrator, add to the PATH for all users.
|
||||||
|
Left=0
|
||||||
|
Right=-1
|
||||||
|
Top=40
|
||||||
|
Bottom=50
|
||||||
|
State=1
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
Var MUI_TEMP
|
Var MUI_TEMP
|
||||||
Var STARTMENU_FOLDER
|
Var STARTMENU_FOLDER
|
||||||
Var SV_ALLUSERS
|
Var SV_ALLUSERS
|
||||||
|
Var START_MENU
|
||||||
|
Var ADD_TO_PATH
|
||||||
|
Var ADD_TO_PATH_ALL_USERS
|
||||||
|
|
||||||
;--------------------------------
|
;--------------------------------
|
||||||
;Include Modern UI
|
;Include Modern UI
|
||||||
|
@ -60,6 +63,8 @@ Function .onInit
|
||||||
done:
|
done:
|
||||||
StrCmp $SV_ALLUSERS "AllUsers" 0 +2
|
StrCmp $SV_ALLUSERS "AllUsers" 0 +2
|
||||||
StrCpy $INSTDIR "$PROGRAMFILES\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
|
StrCpy $INSTDIR "$PROGRAMFILES\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
|
||||||
|
|
||||||
|
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini"
|
||||||
FunctionEnd
|
FunctionEnd
|
||||||
|
|
||||||
;--------------------------------
|
;--------------------------------
|
||||||
|
@ -95,12 +100,7 @@ FunctionEnd
|
||||||
;====================================================
|
;====================================================
|
||||||
!macro select_NT_profile UN
|
!macro select_NT_profile UN
|
||||||
Function ${UN}select_NT_profile
|
Function ${UN}select_NT_profile
|
||||||
MessageBox MB_YESNO|MB_ICONQUESTION "Change the environment for all users? $\n\
|
StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single
|
||||||
$\n\
|
|
||||||
Saying no here will change the envrironment for the current user only. $\n\
|
|
||||||
$\n\
|
|
||||||
(Administrator permissions required for all users)" \
|
|
||||||
IDNO environment_single
|
|
||||||
DetailPrint "Selected environment for all users"
|
DetailPrint "Selected environment for all users"
|
||||||
Push "all"
|
Push "all"
|
||||||
Return
|
Return
|
||||||
|
@ -124,7 +124,7 @@ Function AddToPath
|
||||||
Exch $0
|
Exch $0
|
||||||
Push $1
|
Push $1
|
||||||
Push $2
|
Push $2
|
||||||
|
|
||||||
Call IsNT
|
Call IsNT
|
||||||
Pop $1
|
Pop $1
|
||||||
StrCmp $1 1 AddToPath_NT
|
StrCmp $1 1 AddToPath_NT
|
||||||
|
@ -153,9 +153,13 @@ $\r$\n\
|
||||||
read_path_NT_current:
|
read_path_NT_current:
|
||||||
ReadRegStr $1 ${NT_current_env} "PATH"
|
ReadRegStr $1 ${NT_current_env} "PATH"
|
||||||
read_path_NT_resume:
|
read_path_NT_resume:
|
||||||
StrCmp $1 "" AddToPath_NTdoIt
|
StrCmp $1 "" AddToPath_NoCurrentPath
|
||||||
StrCpy $2 "$0;$1"
|
StrCpy $2 "$0;$1"
|
||||||
Goto AddToPath_NTdoIt
|
Goto AddToPath_NTdoIt
|
||||||
|
AddToPath_NoCurrentPath:
|
||||||
|
DetailPrint "No current path, so just use $0"
|
||||||
|
StrCpy $2 $0
|
||||||
|
Goto AddToPath_NTdoIt
|
||||||
AddToPath_NTdoIt:
|
AddToPath_NTdoIt:
|
||||||
StrCmp $4 "current" write_path_NT_current
|
StrCmp $4 "current" write_path_NT_current
|
||||||
ClearErrors
|
ClearErrors
|
||||||
|
@ -176,7 +180,8 @@ Should I try for the current user?" \
|
||||||
Goto write_path_NT_failed
|
Goto write_path_NT_failed
|
||||||
write_path_NT_resume:
|
write_path_NT_resume:
|
||||||
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
|
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
|
||||||
DetailPrint "added path for user ($4), $0"
|
DetailPrint "Added path for user ($4), $0"
|
||||||
|
DetailPrint "New path is: $2"
|
||||||
write_path_NT_failed:
|
write_path_NT_failed:
|
||||||
|
|
||||||
Pop $4
|
Pop $4
|
||||||
|
@ -243,18 +248,32 @@ $\r$\n\
|
||||||
ReadRegStr $1 ${NT_current_env} "PATH"
|
ReadRegStr $1 ${NT_current_env} "PATH"
|
||||||
un_read_path_NT_resume:
|
un_read_path_NT_resume:
|
||||||
|
|
||||||
|
StrCpy $8 $0
|
||||||
Push $1
|
Push $1
|
||||||
Push $0
|
Push $0
|
||||||
Call un.StrStr ; Find $0 in $1
|
Call un.StrStr ; Find $0 in $1
|
||||||
Pop $0 ; pos of our dir
|
Pop $0 ; pos of our dir
|
||||||
IntCmp $0 -1 unRemoveFromPath_done
|
IntCmp $0 -1 unRemoveFromPath_done
|
||||||
; else, it is in path
|
; else, it is in path
|
||||||
StrCpy $3 $1 $0 ; $3 now has the part of the path before our dir
|
StrLen $5 $1 ; Get the length of the original path
|
||||||
IntOp $2 $2 + $0 ; $2 now contains the pos after our dir in the path (';')
|
StrLen $6 $0 ; get the length of path without the first path
|
||||||
IntOp $2 $2 + 1 ; $2 now containts the pos after our dir and the semicolon.
|
IntOp $5 $5 - $6
|
||||||
StrLen $0 $1
|
IntOp $5 $5 - 1
|
||||||
StrCpy $1 $1 $0 $2
|
IntCmp $5 -1 unRemoveFromPath_nothingBefore
|
||||||
StrCpy $3 "$3$1"
|
StrCpy $3 $1 $5 ; $3 now has the part of the path before our dir
|
||||||
|
Goto unRemoveFromPath_AfterBefore
|
||||||
|
unRemoveFromPath_nothingBefore:
|
||||||
|
StrCpy $3 ""
|
||||||
|
unRemoveFromPath_AfterBefore:
|
||||||
|
StrCpy $7 $0 "" $2 ; $3 now has the part of the path after our dir
|
||||||
|
StrCpy $3 "$3$7"
|
||||||
|
|
||||||
|
; $3 now holds path, but there may be some stray semicolon at
|
||||||
|
; beginning. Let's remove it
|
||||||
|
StrCpy $7 $3 1
|
||||||
|
StrCmp $7 ";" 0 unRemoveFromPath_NoTrailingSemiColon
|
||||||
|
StrCpy $3 $3 "" 1
|
||||||
|
unRemoveFromPath_NoTrailingSemiColon:
|
||||||
|
|
||||||
StrCmp $4 "current" un_write_path_NT_current
|
StrCmp $4 "current" un_write_path_NT_current
|
||||||
WriteRegExpandStr ${NT_all_env} "PATH" $3
|
WriteRegExpandStr ${NT_all_env} "PATH" $3
|
||||||
|
@ -263,6 +282,8 @@ $\r$\n\
|
||||||
WriteRegExpandStr ${NT_current_env} "PATH" $3
|
WriteRegExpandStr ${NT_current_env} "PATH" $3
|
||||||
un_write_path_NT_resume:
|
un_write_path_NT_resume:
|
||||||
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
|
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
|
||||||
|
DetailPrint "Removed $8 from the path"
|
||||||
|
DetailPrint "New path is: $3"
|
||||||
unRemoveFromPath_done:
|
unRemoveFromPath_done:
|
||||||
Pop $4
|
Pop $4
|
||||||
Pop $3
|
Pop $3
|
||||||
|
@ -364,7 +385,10 @@ FunctionEnd
|
||||||
|
|
||||||
;--------------------------------
|
;--------------------------------
|
||||||
;Pages
|
;Pages
|
||||||
|
!insertmacro MUI_PAGE_WELCOME
|
||||||
|
|
||||||
|
!insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@"
|
||||||
|
Page custom InstallOptionsPage
|
||||||
!insertmacro MUI_PAGE_DIRECTORY
|
!insertmacro MUI_PAGE_DIRECTORY
|
||||||
|
|
||||||
;Start Menu Folder Page Configuration
|
;Start Menu Folder Page Configuration
|
||||||
|
@ -383,13 +407,29 @@ FunctionEnd
|
||||||
|
|
||||||
!insertmacro MUI_LANGUAGE "English"
|
!insertmacro MUI_LANGUAGE "English"
|
||||||
|
|
||||||
|
;--------------------------------
|
||||||
|
;Reserve Files
|
||||||
|
|
||||||
|
;These files should be inserted before other files in the data block
|
||||||
|
;Keep these lines before any File command
|
||||||
|
;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA)
|
||||||
|
|
||||||
|
ReserveFile "NSIS.InstallOptions.ini"
|
||||||
|
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
|
||||||
|
|
||||||
|
|
||||||
;--------------------------------
|
;--------------------------------
|
||||||
;Installer Sections
|
;Installer Sections
|
||||||
|
|
||||||
Section "Add to path"
|
Section "Add to path"
|
||||||
Push $INSTDIR\bin
|
Push $INSTDIR\bin
|
||||||
StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 +2
|
;Read a value from an InstallOptions INI file
|
||||||
|
!insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH "NSIS.InstallOptions.ini" "Field 2" "State"
|
||||||
|
!insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_ALL_USERS "NSIS.InstallOptions.ini" "Field 3" "State"
|
||||||
|
;StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 +2
|
||||||
|
StrCmp $ADD_TO_PATH "1" 0 doNotAddToPath
|
||||||
Call AddToPath
|
Call AddToPath
|
||||||
|
doNotAddToPath:
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
Section "Installer Section" InstSection
|
Section "Installer Section" InstSection
|
||||||
|
@ -416,12 +456,26 @@ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PAC
|
||||||
@CPACK_NSIS_CREATE_ICONS@
|
@CPACK_NSIS_CREATE_ICONS@
|
||||||
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
|
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
|
||||||
|
|
||||||
|
; Write special uninstall registry entries
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" \
|
||||||
|
"StartMenu" "$STARTMENU_FOLDER"
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" \
|
||||||
|
"AddToPath" "$ADD_TO_PATH"
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" \
|
||||||
|
"AddToPathAllUsers" "$ADD_TO_PATH_ALL_USERS"
|
||||||
|
|
||||||
@CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
|
@CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
|
||||||
|
|
||||||
!insertmacro MUI_STARTMENU_WRITE_END
|
!insertmacro MUI_STARTMENU_WRITE_END
|
||||||
|
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
|
;--------------------------------
|
||||||
|
; Create custom pages
|
||||||
|
Function InstallOptionsPage
|
||||||
|
!insertmacro MUI_HEADER_TEXT "Install Options" "Chose options for installing @CPACK_PACKAGE_INSTALL_DIRECTORY@"
|
||||||
|
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "NSIS.InstallOptions.ini"
|
||||||
|
FunctionEnd
|
||||||
|
|
||||||
;--------------------------------
|
;--------------------------------
|
||||||
; determine admin versus local install
|
; determine admin versus local install
|
||||||
|
@ -452,6 +506,14 @@ FunctionEnd
|
||||||
;Uninstaller Section
|
;Uninstaller Section
|
||||||
|
|
||||||
Section "Uninstall"
|
Section "Uninstall"
|
||||||
|
ReadRegStr $START_MENU HKLM \
|
||||||
|
"Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" "StartMenu"
|
||||||
|
;MessageBox MB_OK "Start menu is in: $START_MENU"
|
||||||
|
ReadRegStr $ADD_TO_PATH HKLM \
|
||||||
|
"Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" "AddToPath"
|
||||||
|
ReadRegStr $ADD_TO_PATH_ALL_USERS HKLM \
|
||||||
|
"Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@" "AddToPathAllUsers"
|
||||||
|
;MessageBox MB_OK "Add to path: $ADD_TO_PATH all users: $ADD_TO_PATH_ALL_USERS"
|
||||||
|
|
||||||
@CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@
|
@CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@
|
||||||
|
|
||||||
|
@ -485,14 +547,34 @@ Section "Uninstall"
|
||||||
|
|
||||||
IfErrors startMenuDeleteLoopDone
|
IfErrors startMenuDeleteLoopDone
|
||||||
|
|
||||||
StrCmp $MUI_TEMP $SMPROGRAMS startMenuDeleteLoopDone startMenuDeleteLoop
|
StrCmp "$MUI_TEMP" "$SMPROGRAMS" startMenuDeleteLoopDone startMenuDeleteLoop
|
||||||
startMenuDeleteLoopDone:
|
startMenuDeleteLoopDone:
|
||||||
|
|
||||||
|
; If the user changed the shortcut, then untinstall may not work. This should
|
||||||
|
; try to fix it.
|
||||||
|
StrCpy $MUI_TEMP "$START_MENU"
|
||||||
|
Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
|
||||||
|
@CPACK_NSIS_DELETE_ICONS@
|
||||||
|
|
||||||
|
;Delete empty start menu parent diretories
|
||||||
|
StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
|
||||||
|
|
||||||
|
secondStartMenuDeleteLoop:
|
||||||
|
ClearErrors
|
||||||
|
RMDir $MUI_TEMP
|
||||||
|
GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
|
||||||
|
|
||||||
|
IfErrors secondStartMenuDeleteLoopDone
|
||||||
|
|
||||||
|
StrCmp "$MUI_TEMP" "$SMPROGRAMS" secondStartMenuDeleteLoopDone secondStartMenuDeleteLoop
|
||||||
|
secondStartMenuDeleteLoopDone:
|
||||||
|
|
||||||
DeleteRegKey /ifempty SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
|
DeleteRegKey /ifempty SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
|
||||||
|
|
||||||
Push $INSTDIR\bin
|
Push $INSTDIR\bin
|
||||||
StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 +2
|
StrCmp $ADD_TO_PATH "1" 0 doNotRemoveFromPath
|
||||||
Call un.RemoveFromPath
|
Call un.RemoveFromPath
|
||||||
|
doNotRemoveFromPath:
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,19 @@ int cmCPackNSISGenerator::CompressFiles(const char* outFileName,
|
||||||
<< std::endl);
|
<< std::endl);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
std::string nsisInInstallOptions
|
||||||
|
= this->FindTemplate("NSIS.InstallOptions.ini.in");
|
||||||
|
if ( nsisInInstallOptions.size() == 0 )
|
||||||
|
{
|
||||||
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||||
|
"CPack error: Could not find NSIS installer options file."
|
||||||
|
<< std::endl);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
std::string nsisFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
std::string nsisFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
||||||
std::string tmpFile = nsisFileName;
|
std::string tmpFile = nsisFileName;
|
||||||
tmpFile += "/NSISOutput.log";
|
tmpFile += "/NSISOutput.log";
|
||||||
|
std::string nsisInstallOptions = nsisFileName + "/NSIS.InstallOptions.ini";
|
||||||
nsisFileName += "/project.nsi";
|
nsisFileName += "/project.nsi";
|
||||||
cmOStringStream str;
|
cmOStringStream str;
|
||||||
std::vector<std::string>::const_iterator it;
|
std::vector<std::string>::const_iterator it;
|
||||||
|
@ -90,6 +100,7 @@ int cmCPackNSISGenerator::CompressFiles(const char* outFileName,
|
||||||
|
|
||||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << nsisInFileName
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << nsisInFileName
|
||||||
<< " to " << nsisFileName << std::endl);
|
<< " to " << nsisFileName << std::endl);
|
||||||
|
this->ConfigureFile(nsisInInstallOptions.c_str(), nsisInstallOptions.c_str());
|
||||||
this->ConfigureFile(nsisInFileName.c_str(), nsisFileName.c_str());
|
this->ConfigureFile(nsisInFileName.c_str(), nsisFileName.c_str());
|
||||||
std::string nsisCmd = "\"";
|
std::string nsisCmd = "\"";
|
||||||
nsisCmd += this->GetOption("CPACK_INSTALLER_PROGRAM");
|
nsisCmd += this->GetOption("CPACK_INSTALLER_PROGRAM");
|
||||||
|
|
Loading…
Reference in New Issue