diff options
| author | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-12-23 07:38:22 +0000 |
|---|---|---|
| committer | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-12-23 07:38:22 +0000 |
| commit | e802b6dfe8ef0105389b69e17e7faa2e4c92d756 (patch) | |
| tree | 7556cf902a0f943cb4bbc3b47b89fb13797ad4e1 | |
| parent | 40ec6f0854c2210e670199f701636d9d78ffa6c0 (diff) | |
Some more Windows fixes, both in CMake and in the code itself. (I don't like the const casting for the latter, but it's only until we get rid of use of strchr)
Added CPack setup to automate generation of source package for *nix and NSIS installer for Windows.
Some other minor CMake fixes.
Converted docs/README and docs/WIN32.txt from Unix linefeeds to DOS linefeeds so they show up right in Notepad under Windows.
Added small fix for Visual Studio 2008, CMake doesn't detect the Express version correctly and it must be explicitly defined.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1861 5417fbe8-f217-4b02-8779-1006273d7864
| -rw-r--r-- | CMakeLists.txt | 174 | ||||
| -rw-r--r-- | Config.bat | 4 | ||||
| -rw-r--r-- | NSIS.template.in | 825 | ||||
| -rw-r--r-- | data/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | docs/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | docs/README | 750 | ||||
| -rw-r--r-- | docs/WIN32.txt | 418 | ||||
| -rw-r--r-- | include/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | install.js | 24 | ||||
| -rw-r--r-- | lang/CMakeLists.txt | 55 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | src/base64.c | 2 | ||||
| -rw-r--r-- | src/bin/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | src/channels.c | 6 | ||||
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/messages.c | 2 | ||||
| -rw-r--r-- | src/modules/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/process.c | 12 | ||||
| -rw-r--r-- | src/protocol/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/tools/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | src/tools/db-convert.c | 2 | ||||
| -rw-r--r-- | src/users.c | 4 |
22 files changed, 1685 insertions, 655 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b44cd193c..ff26b5cc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,20 @@ # This usage of CMake requires at least version 2.4 (checks are made to determine what to use when certain versions lack functions) cmake_minimum_required(VERSION 2.4 FATAL_ERROR) +if(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) # Detect is we are using CMake 2.6 or better, these versions include functions that require less work than CMake 2.4 does if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) set(CMAKE26_OR_BETTER TRUE) + set(CMAKE244_OR_BETTER TRUE) + set(CMAKE242_OR_BETTER TRUE) else(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) set(CMAKE26_OR_BETTER FALSE) # Also detect if we are using CMake 2.4.4 or better, the CheckCXXCompilerFlag module is non-existant in earlier versions if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} GREATER 2.4.3) set(CMAKE244_OR_BETTER TRUE) + set(CMAKE242_OR_BETTER TRUE) else(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} GREATER 2.4.3) set(CMAKE244_OR_BETTER FALSE) # ALSO detect if we are using CMake 2.4.2 or better, the APPEND sub-command of list() is non-existant in earlier versions @@ -62,7 +68,7 @@ if(MSVC) string(REPLACE "/GX " "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) string(REPLACE "/W3 " "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Set the compile flags to have warnings on the max setting (but disable a few annoying ones), exception handling turned on, the proper defines, and the include directories - set(CXXFLAGS "${CXXFLAGS} /W4 /wd4251 /wd4706 /wd4800 /EHs /D_WIN32 /DMSVCPP /I\"${Anope_SOURCE_DIR}/include\" /I\"${Anope_BINARY_DIR}/include\" /I\"${Anope_BINARY_DIR}/lang\"") + set(CXXFLAGS "${CXXFLAGS} /W4 /wd4251 /wd4706 /wd4800 /wd4996 /EHs /D_WIN32 /DMSVCPP /D_CRT_SECURE_NO_WARNINGS /I\"${Anope_SOURCE_DIR}/include\" /I\"${Anope_BINARY_DIR}/include\" /I\"${Anope_BINARY_DIR}/lang\"") # Set the module-specific compile flags to include a define for module compiling set(MODULE_CXXFLAGS "${CXXFLAGS} /DMODULE_COMPILE") # Otherwise, we're not using Visual Studio @@ -275,37 +281,39 @@ if(PERL AND USE_RUN_CC_PL) set(CMAKE_CXX_CREATE_SHARED_MODULE "${PERL} ${Anope_SOURCE_DIR}/run-cc.pl ${CMAKE_CXX_CREATE_SHARED_MODULE}") endif(PERL AND USE_RUN_CC_PL) -# If a INSTDIR wasn't passed in to CMake, set the default to the services directory under the user's home directory -if(NOT INSTDIR) - set(INSTDIR "$ENV{HOME}/services") -endif(NOT INSTDIR) - -# Set Anope's data install location to be the data directory under the install directory -set(DATADIR "${INSTDIR}/data") - -# Only process Anope's version on Windows, it's needed for win32.rc as well as version branding at link time +# If a INSTDIR was passed in to CMake, use it as the install prefix, otherwise set the default install prefix to the services directory under the user's home directory +if(INSTDIR) + set(CMAKE_INSTALL_PREFIX "${INSTDIR}") +else(INSTDIR) + set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/services") +endif(INSTDIR) + +# Version number processing +# Find all lines in version.log that start with VERSION_ +read_from_file(${Anope_SOURCE_DIR}/version.log "^VERSION_" VERSIONS) +# Iterate through the strings found +foreach(VERSION_STR ${VERSIONS}) + # Get the length of the string + string(LENGTH ${VERSION_STR} VERSION_LEN) + # Subtract 16 from the string's length (8 for VERSION_, 5 more for the type, 2 for the space and leading quote, 1 for the trailing quote) + math(EXPR VERSION_NUM_LEN "${VERSION_LEN} - 16") + # Extract the type from the string + string(SUBSTRING ${VERSION_STR} 8 5 VERSION_TYPE) + # Extract the actual value from the string + string(SUBSTRING ${VERSION_STR} 15 ${VERSION_NUM_LEN} VERSION) + # Set the version type to the value extract from above + set(VERSION_${VERSION_TYPE} ${VERSION}) +endforeach(VERSION_STR ${VERSIONS}) + +# Set the version variables based on what was found above +set(VERSION_COMMA "${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_BUILD}") +set(VERSION_DOTTED_NOBUILD "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") +set(VERSION_DOTTED "${VERSION_DOTTED_NOBUILD}.${VERSION_BUILD}") +set(VERSION_FULL "${VERSION_DOTTED}${VERSION_EXTRA}") +set(VERSION_FULL_NOBUILD "${VERSION_DOTTED_NOBUILD}${VERSION_EXTRA}") + +# Only do the following for Windows if(WIN32) - # Find all lines in version.log that start with VERSION_ - read_from_file(${Anope_SOURCE_DIR}/version.log "^VERSION_" VERSIONS) - # Iterate through the strings found - foreach(VERSION_STR ${VERSIONS}) - # Get the length of the string - string(LENGTH ${VERSION_STR} VERSION_LEN) - # Subtract 16 from the string's length (8 for VERSION_, 5 more for the type, 2 for the space and leading quote, 1 for the trailing quote) - math(EXPR VERSION_NUM_LEN "${VERSION_LEN} - 16") - # Extract the type from the string - string(SUBSTRING ${VERSION_STR} 8 5 VERSION_TYPE) - # Extract the actual value from the string - string(SUBSTRING ${VERSION_STR} 15 ${VERSION_NUM_LEN} VERSION) - # Set the version type to the value extract from above - set(VERSION_${VERSION_TYPE} ${VERSION}) - endforeach(VERSION_STR ${VERSIONS}) - - # Set the version variables based on what was found above - set(VERSION_COMMA "${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_BUILD}") - set(VERSION_DOTTED "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_BUILD}") - set(VERSION_FULL "${VERSION_DOTTED}${VERSION_EXTRA}") - # Generate the win32.rc file using the above variables configure_file(${Anope_SOURCE_DIR}/src/win32.rc.cmake ${Anope_BINARY_DIR}/src/win32.rc) endif(WIN32) @@ -463,20 +471,110 @@ macro(calculate_depends SRC) endif(HEADERS) endmacro(calculate_depends) +# A macro to update the environment variable CPACK_IGNORED_FILES which contains a list of files for CPack to ignore +macro(add_to_cpack_ignored_files ITEM) + # Temporary copy of the orignal item + set(REAL_ITEM "${ITEM}") + # If we have 2+ arguments, assume that the second one was something like TRUE (doesn't matter really) and convert periods so they will be \\. for CPack + if(${ARGC} GREATER 1) + string(REPLACE "." "\\\\." REAL_ITEM ${REAL_ITEM}) + endif(${ARGC} GREATER 1) + # If the environment variable is already defined, just tack the item to the end + if(DEFINED ENV{CPACK_IGNORED_FILES}) + set(ENV{CPACK_IGNORED_FILES} "$ENV{CPACK_IGNORED_FILES};${REAL_ITEM}") + # Otherwise set the environment variable to the item + else(DEFINED ENV{CPACK_IGNORED_FILES}) + set(ENV{CPACK_IGNORED_FILES} "${REAL_ITEM}") + endif(DEFINED ENV{CPACK_IGNORED_FILES}) +endmacro(add_to_cpack_ignored_files) + +# Add the initial files to ignore which will be ignored regardless of if you are building in-source or out-of-source +add_to_cpack_ignored_files(".git\;config.cache\;.svn\;CMakeFiles" TRUE) +# If the two directories are the same, we are building in-source, thus we need to ignore more files from the build +if(${Anope_SOURCE_DIR} STREQUAL ${Anope_BINARY_DIR}) + # This variable is used in the sub-directories to determine if we are building in-source + set(IN_SOURCE TRUE) + # Add the files that need their periods converted + add_to_cpack_ignored_files("Makefile\;cmake_install.cmake\;sysconf.h$\;CMakeCache.txt\;install_manifest.txt" TRUE) + # Add the files we don't want the periods converted for + add_to_cpack_ignored_files(".\\\\\\\\.so$;CPack.;anope-${VERSION_FULL_NOBUILD}-source\\\\\\\\..") + # If using Visual Studio, add these files as well + if(MSVC) + add_to_cpack_ignored_files(".vcproj$\;.sln$\;.ncb$\;.suo$\;.dir$\;.ilk$\;.exp$\;.pdb$\;.lib$\;/debug$;/release$;/relwithdebinfo$;/minsizerel$" TRUE) + endif(MSVC) +# Otherwise, the two directories are different and we are building out-of-source +else(${Anope_SOURCE_DIR} STREQUAL ${Anope_BINARY_DIR}) + set(IN_SOURCE FALSE) +endif(${Anope_SOURCE_DIR} STREQUAL ${Anope_BINARY_DIR}) + # Go into the following directories and run their CMakeLists.txt as well add_subdirectory(data) +add_subdirectory(docs) add_subdirectory(lang) add_subdirectory(src) add_subdirectory(include) +# Get the filename of the Anope binary, to use later +get_target_property(SERVICES_BINARY ${PROGRAM_NAME} LOCATION) +get_filename_component(SERVICES_BINARY ${SERVICES_BINARY} NAME) + # At install time, create the following additional directories -install(CODE "file(MAKE_DIRECTORY \"${DATADIR}/backups\")") -install(CODE "file(MAKE_DIRECTORY \"${DATADIR}/logs\")") -install(CODE "file(MAKE_DIRECTORY \"${DATADIR}/modules/runtime\")") +install(CODE "file(MAKE_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/data/backups\")") +install(CODE "file(MAKE_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/data/logs\")") +install(CODE "file(MAKE_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/data/modules/runtime\")") # On non-Windows platforms, if RUNGROUP is set, change the permissions of the below directories, as well as the group of the data directory if(NOT WIN32 AND RUNGROUP) - install(CODE "execute_process(COMMAND ${CHMOD} 2775 \"${DATADIR}/backups\")") - install(CODE "execute_process(COMMAND ${CHMOD} 2775 \"${DATADIR}/logs\")") - install(CODE "execute_process(COMMAND ${CHMOD} 2775 \"${DATADIR}/modules/runtime\")") - install(CODE "execute_process(COMMAND ${CHGRP} -R ${RUNGROUP} \"${DATADIR}\")") + install(CODE "execute_process(COMMAND ${CHMOD} 2775 \"\${CMAKE_INSTALL_PREFIX}/data/backups\")") + install(CODE "execute_process(COMMAND ${CHMOD} 2775 \"\${CMAKE_INSTALL_PREFIX}/data/logs\")") + install(CODE "execute_process(COMMAND ${CHMOD} 2775 \"\${CMAKE_INSTALL_PREFIX}/data/modules/runtime\")") + install(CODE "execute_process(COMMAND ${CHGRP} -R ${RUNGROUP} \"\${CMAKE_INSTALL_PREFIX}\")") endif(NOT WIN32 AND RUNGROUP) +# On Windows platforms, install extra files +if(WIN32) + install(FILES ${Anope_SOURCE_DIR}/anope.bat + ${Anope_SOURCE_DIR}/Changes + ${Anope_SOURCE_DIR}/Changes.conf + ${Anope_SOURCE_DIR}/Changes.lang + DESTINATION . + ) +endif(WIN32) + +# Only process the CPack section if we have CPack +if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") + # Override the module include path to include our directory, as we are using our own version of the NSIS template + set(CMAKE_MODULE_PATH ${Anope_SOURCE_DIR}) + # Various options for CPack + set(CPACK_PACKAGE_NAME "Anope IRC Services") + set(CPACK_PACKAGE_VENDOR "Anope Team") + set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) + set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}) + set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}${VERSION_EXTRA}") + set(CPACK_PACKAGE_FILE_NAME "anope-${VERSION_FULL_NOBUILD}") + set(CPACK_RESOURCE_FILE_LICENSE "${Anope_SOURCE_DIR}/docs/COPYING") + # The following doesn't actually do anything. :( + #set(CPACK_RESOURCE_FILE_README "${Anope_SOURCE_DIR}/docs/README") + # The following is primarily for NSIS + if(WIN32) + set(CPACK_GENERATOR "NSIS") + set(CPACK_PACKAGE_INSTALL_DIRECTORY "Anope") + set(CPACK_PACKAGE_EXECUTABLES "") + set(CPACK_NSIS_MENU_LINKS + "${SERVICES_BINARY}" "Anope IRC Services" + "anope.bat\\\" \\\"-debug -nofork" "Anope IRC Services (Debug and Window Logging)" + "anope.bat\\\" \\\"-nofork" "Anope IRC Services (Window Logging)" + "anope.bat\\\" \\\"-nothird" "Anope IRC Services (No Third Party Modules)" + "http://www.anope.org" "Anope Web Site" + ) + # The following doesn't work, but a bug report has been filed about it + #set(CPACK_CREATE_DESKTOP_LINK_${SERVICES_BINARY} TRUE) + set(CPACK_NSIS_MUI_ICON "${Anope_SOURCE_DIR}/src\\\\anope-icon.ico") + set(CPACK_NSIS_MUI_UNIICON "${Anope_SOURCE_DIR}/src\\\\anope-icon.ico") + set(CPACK_NSIS_INSTALLED_ICON_NAME "${SERVICES_BINARY}") + set(CPACK_NSIS_URL_INFO_ABOUT "http://www.anope.org") + set(CPACK_NSIS_COMPRESSOR "/SOLID lzma") + endif(WIN32) + set(CPACK_SOURCE_PACKAGE_FILE_NAME "anope-${VERSION_FULL_NOBUILD}-source") + set(CPACK_SOURCE_IGNORE_FILES "$ENV{CPACK_IGNORED_FILES}") + set(CPACK_MONOLITHIC_INSTALL TRUE) + include(CPack) +endif(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") diff --git a/Config.bat b/Config.bat index 96501a98c..7205c91ef 100644 --- a/Config.bat +++ b/Config.bat @@ -1,3 +1,3 @@ @echo off
-cscript /nologo install.js
-
+cscript /nologo %~dp0\install.js
+pause
diff --git a/NSIS.template.in b/NSIS.template.in new file mode 100644 index 000000000..a9c91a2b7 --- /dev/null +++ b/NSIS.template.in @@ -0,0 +1,825 @@ +; CPack install script designed for a nmake build + +;-------------------------------- +; You must define these values + + !define VERSION "@CPACK_PACKAGE_VERSION@" + !define INST_DIR "@CPACK_TEMPORARY_DIRECTORY@" + +;-------------------------------- +;Variables + + Var MUI_TEMP + Var STARTMENU_FOLDER + Var SV_ALLUSERS + Var START_MENU + Var DO_NOT_ADD_TO_PATH + Var ADD_TO_PATH_ALL_USERS + Var ADD_TO_PATH_CURRENT_USER + Var INSTALL_DESKTOP + +;-------------------------------- +;Include Modern UI + + !include "MUI2.nsh" + + ;Default installation folder + InstallDir "$PROGRAMFILES\@CPACK_PACKAGE_INSTALL_DIRECTORY@" + +;-------------------------------- +;General + + ;Name and file + Name "@CPACK_PACKAGE_NAME@ @CPACK_PACKAGE_VERSION@" + OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@" + + ;Set compression + SetCompressor @CPACK_NSIS_COMPRESSOR@ + +@CPACK_NSIS_DEFINES@ + + !include Sections.nsh + +;--- Component support macros: --- +; The code for the add/remove functionality is from: +; http://nsis.sourceforge.net/Add/Remove_Functionality +; It has been modified slightly and extended to provide +; inter-component dependencies. +Var AR_SecFlags +Var AR_RegFlags +@CPACK_NSIS_SECTION_SELECTED_VARS@ + +; Loads the "selected" flag for the section named SecName into the +; variable VarName. +!macro LoadSectionSelectedIntoVar SecName VarName + SectionGetFlags ${${SecName}} $${VarName} + IntOp $${VarName} $${VarName} & ${SF_SELECTED} ;Turn off all other bits +!macroend + +; Loads the value of a variable... can we get around this? +!macro LoadVar VarName + IntOp $R0 0 + $${VarName} +!macroend + +; Sets the value of a variable +!macro StoreVar VarName IntValue + IntOp $${VarName} 0 + ${IntValue} +!macroend + +!macro InitSection SecName + ; This macro reads component installed flag from the registry and + ;changes checked state of the section on the components page. + ;Input: section index constant name specified in Section command. + + ClearErrors + ;Reading component status from registry + ReadRegDWORD $AR_RegFlags HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@\Components\${SecName}" "Installed" + IfErrors "default_${SecName}" + ;Status will stay default if registry value not found + ;(component was never installed) + IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits + SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading default section flags + IntOp $AR_SecFlags $AR_SecFlags & 0xFFFE ;Turn lowest (enabled) bit off + IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags ;Change lowest bit + + ; Note whether this component was installed before + !insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags + IntOp $R0 $AR_RegFlags & $AR_RegFlags + + ;Writing modified flags + SectionSetFlags ${${SecName}} $AR_SecFlags + + "default_${SecName}:" + !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected +!macroend + +!macro FinishSection SecName + ; This macro reads section flag set by user and removes the section + ;if it is not selected. + ;Then it writes component installed flag to registry + ;Input: section index constant name specified in Section command. + + SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading section flags + ;Checking lowest bit: + IntOp $AR_SecFlags $AR_SecFlags & ${SF_SELECTED} + IntCmp $AR_SecFlags 1 "leave_${SecName}" + ;Section is not selected: + ;Calling Section uninstall macro and writing zero installed flag + !insertmacro "Remove_${${SecName}}" + WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@\Components\${SecName}" \ + "Installed" 0 + Goto "exit_${SecName}" + + "leave_${SecName}:" + ;Section is selected: + WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@\Components\${SecName}" \ + "Installed" 1 + + "exit_${SecName}:" +!macroend + +!macro RemoveSection SecName + ; This macro is used to call section's Remove_... macro + ;from the uninstaller. + ;Input: section index constant name specified in Section command. + + !insertmacro "Remove_${${SecName}}" +!macroend + +; Determine whether the selection of SecName changed +!macro MaybeSelectionChanged SecName + !insertmacro LoadVar ${SecName}_selected + SectionGetFlags ${${SecName}} $R1 + IntOp $R1 $R1 & ${SF_SELECTED} ;Turn off all other bits + + ; See if the status has changed: + IntCmp $R0 $R1 "${SecName}_unchanged" + !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected + + IntCmp $R1 ${SF_SELECTED} "${SecName}_was_selected" + !insertmacro "Deselect_required_by_${SecName}" + goto "${SecName}_unchanged" + + "${SecName}_was_selected:" + !insertmacro "Select_${SecName}_depends" + + "${SecName}_unchanged:" +!macroend +;--- End of Add/Remove macros --- + +;-------------------------------- +;Interface Settings + + !define MUI_ABORTWARNING + +;---------------------------------------- +; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02" +;---------------------------------------- +!verbose 3 +!include "WinMessages.NSH" +!verbose 4 + +;==================================================== +; get_NT_environment +; Returns: the selected environment +; Output : head of the stack +;==================================================== +!macro select_NT_profile UN +Function ${UN}select_NT_profile + StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single + DetailPrint "Selected environment for all users" + Push "all" + Return + environment_single: + DetailPrint "Selected environment for current user only." + Push "current" + Return +FunctionEnd +!macroend +!insertmacro select_NT_profile "" +!insertmacro select_NT_profile "un." +;---------------------------------------------------- +!define NT_current_env 'HKCU "Environment"' +!define NT_all_env 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' + +!ifndef WriteEnvStr_RegKey + !ifdef ALL_USERS + !define WriteEnvStr_RegKey \ + 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' + !else + !define WriteEnvStr_RegKey 'HKCU "Environment"' + !endif +!endif + +; AddToPath - Adds the given dir to the search path. +; Input - head of the stack +; Note - Win9x systems requires reboot + +Function AddToPath + Exch $0 + Push $1 + Push $2 + Push $3 + + # don't add if the path doesn't exist + IfFileExists "$0\*.*" "" AddToPath_done + + ReadEnvStr $1 PATH + Push "$1;" + Push "$0;" + Call StrStr + Pop $2 + StrCmp $2 "" "" AddToPath_done + Push "$1;" + Push "$0\;" + Call StrStr + Pop $2 + StrCmp $2 "" "" AddToPath_done + GetFullPathName /SHORT $3 $0 + Push "$1;" + Push "$3;" + Call StrStr + Pop $2 + StrCmp $2 "" "" AddToPath_done + Push "$1;" + Push "$3\;" + Call StrStr + Pop $2 + StrCmp $2 "" "" AddToPath_done + + Call IsNT + Pop $1 + StrCmp $1 1 AddToPath_NT + ; Not on NT + StrCpy $1 $WINDIR 2 + FileOpen $1 "$1\autoexec.bat" a + FileSeek $1 -1 END + FileReadByte $1 $2 + IntCmp $2 26 0 +2 +2 # DOS EOF + FileSeek $1 -1 END # write over EOF + FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n" + FileClose $1 + SetRebootFlag true + Goto AddToPath_done + + AddToPath_NT: + ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH" + StrCmp $1 "" AddToPath_NTdoIt + Push $1 + Call Trim + Pop $1 + StrCpy $0 "$1;$0" + AddToPath_NTdoIt: + WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $0 + SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 + + AddToPath_done: + Pop $3 + Pop $2 + Pop $1 + Pop $0 +FunctionEnd + + +; RemoveFromPath - Remove a given dir from the path +; Input: head of the stack + +Function un.RemoveFromPath + Exch $0 + Push $1 + Push $2 + Push $3 + Push $4 + Push $5 + Push $6 + + IntFmt $6 "%c" 26 # DOS EOF + + Call un.IsNT + Pop $1 + StrCmp $1 1 unRemoveFromPath_NT + ; Not on NT + StrCpy $1 $WINDIR 2 + FileOpen $1 "$1\autoexec.bat" r + GetTempFileName $4 + FileOpen $2 $4 w + GetFullPathName /SHORT $0 $0 + StrCpy $0 "SET PATH=%PATH%;$0" + Goto unRemoveFromPath_dosLoop + + unRemoveFromPath_dosLoop: + FileRead $1 $3 + StrCpy $5 $3 1 -1 # read last char + StrCmp $5 $6 0 +2 # if DOS EOF + StrCpy $3 $3 -1 # remove DOS EOF so we can compare + StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine + StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine + StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine + StrCmp $3 "" unRemoveFromPath_dosLoopEnd + FileWrite $2 $3 + Goto unRemoveFromPath_dosLoop + unRemoveFromPath_dosLoopRemoveLine: + SetRebootFlag true + Goto unRemoveFromPath_dosLoop + + unRemoveFromPath_dosLoopEnd: + FileClose $2 + FileClose $1 + StrCpy $1 $WINDIR 2 + Delete "$1\autoexec.bat" + CopyFiles /SILENT $4 "$1\autoexec.bat" + Delete $4 + Goto unRemoveFromPath_done + + unRemoveFromPath_NT: + ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH" + StrCpy $5 $1 1 -1 # copy last char + StrCmp $5 ";" +2 # if last char != ; + StrCpy $1 "$1;" # append ; + Push $1 + Push "$0;" + Call un.StrStr ; Find `$0;` in $1 + Pop $2 ; pos of our dir + StrCmp $2 "" unRemoveFromPath_done + ; else, it is in path + # $0 - path to add + # $1 - path var + StrLen $3 "$0;" + StrLen $4 $2 + StrCpy $5 $1 -$4 # $5 is now the part before the path to remove + StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove + StrCpy $3 $5$6 + + StrCpy $5 $3 1 -1 # copy last char + StrCmp $5 ";" 0 +2 # if last char == ; + StrCpy $3 $3 -1 # remove last char + + WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $3 + SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 + + unRemoveFromPath_done: + Pop $6 + Pop $5 + Pop $4 + Pop $3 + Pop $2 + Pop $1 + Pop $0 +FunctionEnd + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Uninstall sutff +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +########################################### +# Utility Functions # +########################################### + +;==================================================== +; IsNT - Returns 1 if the current system is NT, 0 +; otherwise. +; Output: head of the stack +;==================================================== +; IsNT +; no input +; output, top of the stack = 1 if NT or 0 if not +; +; Usage: +; Call IsNT +; Pop $R0 +; ($R0 at this point is 1 or 0) + +!macro IsNT un +Function ${un}IsNT + Push $0 + ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion + StrCmp $0 "" 0 IsNT_yes + ; we are not NT. + Pop $0 + Push 0 + Return + + IsNT_yes: + ; NT!!! + Pop $0 + Push 1 +FunctionEnd +!macroend +!insertmacro IsNT "" +!insertmacro IsNT "un." + +; StrStr +; input, top of stack = string to search for +; top of stack-1 = string to search in +; output, top of stack (replaces with the portion of the string remaining) +; modifies no other variables. +; +; Usage: +; Push "this is a long ass string" +; Push "ass" +; Call StrStr +; Pop $R0 +; ($R0 at this point is "ass string") + +!macro StrStr un +Function ${un}StrStr +Exch $R1 ; st=haystack,old$R1, $R1=needle + Exch ; st=old$R1,haystack + Exch $R2 ; st=old$R1,old$R2, $R2=haystack + Push $R3 + Push $R4 + Push $R5 + StrLen $R3 $R1 + StrCpy $R4 0 + ; $R1=needle + ; $R2=haystack + ; $R3=len(needle) + ; $R4=cnt + ; $R5=tmp + loop: + StrCpy $R5 $R2 $R3 $R4 + StrCmp $R5 $R1 done + StrCmp $R5 "" done + IntOp $R4 $R4 + 1 + Goto loop +done: + StrCpy $R1 $R2 "" $R4 + Pop $R5 + Pop $R4 + Pop $R3 + Pop $R2 + Exch $R1 +FunctionEnd +!macroend +!insertmacro StrStr "" +!insertmacro StrStr "un." + +Function Trim ; Added by Pelaca + Exch $R1 + Push $R2 +Loop: + StrCpy $R2 "$R1" 1 -1 + StrCmp "$R2" " " RTrim + StrCmp "$R2" "$\n" RTrim + StrCmp "$R2" "$\r" RTrim + StrCmp "$R2" ";" RTrim + GoTo Done +RTrim: + StrCpy $R1 "$R1" -1 + Goto Loop +Done: + Pop $R2 + Exch $R1 +FunctionEnd + +Function ConditionalAddToRegisty + Pop $0 + Pop $1 + StrCmp "$0" "" ConditionalAddToRegisty_EmptyString + WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@" \ + "$1" "$0" + ;MessageBox MB_OK "Set Registry: '$1' to '$0'" + DetailPrint "Set install registry entry: '$1' to '$0'" + ConditionalAddToRegisty_EmptyString: +FunctionEnd + +;-------------------------------- + +!ifdef CPACK_USES_DOWNLOAD +Function DownloadFile + IfFileExists $INSTDIR\* +2 + CreateDirectory $INSTDIR + Pop $0 + + ; Skip if already downloaded + IfFileExists $INSTDIR\$0 0 +2 + Return + + StrCpy $1 "@CPACK_DOWNLOAD_SITE@" + + try_again: + NSISdl::download "$1/$0" "$INSTDIR\$0" + + Pop $1 + StrCmp $1 "success" success + StrCmp $1 "Cancelled" cancel + MessageBox MB_OK "Download failed: $1" + cancel: + Return + success: +FunctionEnd +!endif + +;-------------------------------- +; Installation types +@CPACK_NSIS_INSTALLATION_TYPES@ + +;-------------------------------- +; Component sections +@CPACK_NSIS_COMPONENT_SECTIONS@ + +;-------------------------------- +; Define some macro setting for the gui +@CPACK_NSIS_INSTALLER_MUI_ICON_CODE@ +@CPACK_NSIS_INSTALLER_ICON_CODE@ +@CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC@ + +;-------------------------------- +;Pages + !define MUI_LANGDLL_REGISTRY_ROOT "SHCTX" + !define MUI_LANGDLL_REGISTRY_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@" + !define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language" + + !insertmacro MUI_PAGE_WELCOME + + !insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@" + !insertmacro MUI_PAGE_DIRECTORY + + ;Start Menu Folder Page Configuration + !define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX" + !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" + !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder" + !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER + + @CPACK_NSIS_PAGE_COMPONENTS@ + + !insertmacro MUI_PAGE_INSTFILES + + !define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\docs\README.txt" + !insertmacro MUI_PAGE_FINISH + + !insertmacro MUI_UNPAGE_CONFIRM + !insertmacro MUI_UNPAGE_INSTFILES + +;-------------------------------- +;Languages + + !insertmacro MUI_LANGUAGE "Dutch" + !insertmacro MUI_LANGUAGE "English" + !insertmacro MUI_LANGUAGE "French" + !insertmacro MUI_LANGUAGE "German" + !insertmacro MUI_LANGUAGE "Italian" + !insertmacro MUI_LANGUAGE "Portuguese" + !insertmacro MUI_LANGUAGE "Spanish" + +;-------------------------------- +;Installer Sections + +Section "-Core installation" + ;Use the entire tree produced by the INSTALL target. Keep the + ;list of directories here in sync with the RMDir commands below. + SetOutPath "$INSTDIR" + @CPACK_NSIS_FULL_INSTALL@ + + ;Store installation folder + WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR + + ;Create uninstaller + WriteUninstaller "$INSTDIR\Uninstall.exe" + Push "DisplayName" + Push "@CPACK_NSIS_DISPLAY_NAME@" + Call ConditionalAddToRegisty + Push "DisplayVersion" + Push "@CPACK_PACKAGE_VERSION@" + Call ConditionalAddToRegisty + Push "Publisher" + Push "@CPACK_PACKAGE_VENDOR@" + Call ConditionalAddToRegisty + Push "UninstallString" + Push "$INSTDIR\Uninstall.exe" + Call ConditionalAddToRegisty + Push "NoRepair" + Push "1" + Call ConditionalAddToRegisty + + !ifdef CPACK_NSIS_ADD_REMOVE + ;Create add/remove functionality + Push "ModifyPath" + Push "$INSTDIR\AddRemove.exe" + Call ConditionalAddToRegisty + !else + Push "NoModify" + Push "1" + Call ConditionalAddToRegisty + !endif + + ; Optional registration + Push "DisplayIcon" + Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@" + Call ConditionalAddToRegisty + Push "HelpLink" + Push "@CPACK_NSIS_HELP_LINK@" + Call ConditionalAddToRegisty + Push "URLInfoAbout" + Push "@CPACK_NSIS_URL_INFO_ABOUT@" + Call ConditionalAddToRegisty + Push "Contact" + Push "@CPACK_NSIS_CONTACT@" + Call ConditionalAddToRegisty + !insertmacro MUI_STARTMENU_WRITE_BEGIN Application + + ;Create shortcuts + CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER" +@CPACK_NSIS_CREATE_ICONS@ +@CPACK_NSIS_CREATE_ICONS_EXTRA@ + CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe" + + ; Write special uninstall registry entries + Push "StartMenu" + Push "$STARTMENU_FOLDER" + Call ConditionalAddToRegisty + Push "DoNotAddToPath" + Push "$DO_NOT_ADD_TO_PATH" + Call ConditionalAddToRegisty + Push "AddToPathAllUsers" + Push "$ADD_TO_PATH_ALL_USERS" + Call ConditionalAddToRegisty + Push "AddToPathCurrentUser" + Push "$ADD_TO_PATH_CURRENT_USER" + Call ConditionalAddToRegisty + Push "InstallToDesktop" + Push "$INSTALL_DESKTOP" + Call ConditionalAddToRegisty + +@CPACK_NSIS_EXTRA_INSTALL_COMMANDS@ + + !insertmacro MUI_STARTMENU_WRITE_END + +SectionEnd + +;-------------------------------- +; determine admin versus local install +Function un.onInit + + ClearErrors + UserInfo::GetName + IfErrors noLM + Pop $0 + UserInfo::GetAccountType + Pop $1 + StrCmp $1 "Admin" 0 +3 + SetShellVarContext all + |
