1; 2; Common var and function definition for ot windows installer. 3; 4 5SetCompressor /SOLID lzma 6 7RequestExecutionLevel user 8 9; Prefix where openturns is installed on Linux. 10!ifndef OPENTURNS_PREFIX 11 !error "OPENTURNS_PREFIX must be defined" 12!endif 13 14!ifndef ARCH 15 !error "ARCH must be defined" 16!endif 17 18!include "WordFunc.nsh" ; for ${WordAdd}, ${WordReplace} 19!include "FileFunc.nsh" ; for ${DirState} , ${GetParent}, ${ConfigWrite}, ${GetFileAttributes} 20!include "TextFunc.nsh" ; for ${ConfigRead} 21!include "LogicLib.nsh" ; for ${If} 22 23; Script generated by the HM NIS Edit Script Wizard. 24; HM NIS Edit Wizard helper defines 25!ifndef PRODUCT_VERSION 26 !error "PRODUCT_VERSION must be defined" 27!endif 28!define PRODUCT_WEB_SITE "http://www.openturns.org" 29!define PRODUCT_DIR_REGKEY "Software\OpenTURNS" 30!define PRODUCT_INST_ROOT_KEY "HKLM" 31 32 33!macro CHECK_REG_VIEW 34 ${If} "${ARCH}" == "x86_64" 35 SetRegView 64 36 ${EndIf} 37!macroend 38 39 40!macro PRINT MSG 41 SetDetailsPrint both 42 DetailPrint "${MSG}" 43 SetDetailsPrint none 44!macroend 45 46 47Var UserInstall 48 49; Check that current user has administrator privileges 50; if ok : set UserInstall to 0, if not : set UserInstall to 1 51!macro CHECK_USER_INSTALL WARN_MSG 52 StrCpy $UserInstall "0" 53 54 ; avoid check if /userlevel option is present on command line 55 ${GetParameters} $R1 56 ClearErrors 57 ${GetOptions} $R1 '/userlevel=' $R0 58 IfErrors 0 set_level 59 60 ClearErrors 61 WriteRegStr ${PRODUCT_INST_ROOT_KEY} ${PRODUCT_DIR_REGKEY} "Test" "${PRODUCT_VERSION}" 62 IfErrors user_install admin_install 63 user_install: 64 StrCpy $UserInstall "1" 65 MessageBox MB_OK|MB_ICONINFORMATION "You are not running Windows from an administrator account.$\r$\rTo enable admin rights on Windows Vista and above: right click on the installer, choose 'Run as administrator'.$\r$\r${WARN_MSG}" /SD IDOK 66 admin_install: 67 DeleteRegValue ${PRODUCT_INST_ROOT_KEY} ${PRODUCT_DIR_REGKEY} "Test" 68 Goto end_set_level 69 70 set_level: 71 StrCpy $UserInstall $R0 72 end_set_level: 73!macroend 74 75 76!macro CHECK_USER_INSTALL_FILE FILE_NAME 77 ; Get previous installation mode 78 IfFileExists "${FILE_NAME}" user_mode 0 79 StrCpy $UserInstall "0" 80 Goto end_user_mode 81 user_mode: 82 StrCpy $UserInstall "1" 83 end_user_mode: 84 85 ${If} "$UserInstall" == "0" 86 !insertmacro CHECK_USER_INSTALL "Uninstall from a non-administrator could not work cause you installed ${PRODUCT_NAME} from an admin account." 87 ${EndIf} 88!macroend 89 90 91!macro CREATE_USER_INSTALL_FILE FILE_NAME 92 ; create a file for uninstaller 93 FileOpen $0 "${FILE_NAME}" w 94 IfErrors userfile_fail 95 FileWrite $0 "${PRODUCT_NAME} was installed in user mode." 96 FileClose $0 97 userfile_fail: 98!macroend 99 100 101; Set whether OpenTURNS shortcuts will be in every user menu or only in current user menu. 102; CHECK_USER_INSTALL must have been called first 103!macro SET_MENU_CONTEXT 104 ${If} "$UserInstall" == "0" 105 SetShellVarContext all 106 ${Else} 107 SetShellVarContext current 108 ${EndIf} 109!macroend 110 111 112 113Var OT_INSTALL_PATH 114 115!define Python_default_INSTALL_PATH "C:\Python${PYBASEVER_NODOT}" 116!define Default_OT_INSTALL_PATH "${Python_default_INSTALL_PATH}\Lib\site-packages\openturns" 117 118 119; get openturns version from the file VERSION.TXT 120; need $R5 set to VERSION.txt path 121; return in $R1 openturns version found 122Function GetOpenTURNSFileVersion 123 ClearErrors 124 FileOpen $0 $R5 r 125 IfErrors done 126 FileRead $0 $1 127 ${WordFind} $1 " " "+2" $R1 128 FileClose $0 129 done: 130FunctionEnd 131 132 133; return in $R0 openturns path found. 134; return in $R1 openturns version found. 135Function CheckOpenTURNS 136 StrCpy $R0 "" 137 StrCpy $R1 "" 138 ClearErrors 139 140 ; search the prog in registry 141 ReadRegStr $R0 HKLM "${PRODUCT_DIR_REGKEY}" "InstallPath" 142 ${If} "$R0" == "" 143 !insertmacro PRINT "OpenTURNS not found in registry." 144 ${Else} 145 ; Check that the directory fetched in the registry is existing. 146 IfFileExists "$R0\*.*" 0 openturns_reg_not_found 147 !insertmacro PRINT "=> OpenTURNS found here: $R0." 148 ReadRegStr $R1 HKLM "${PRODUCT_DIR_REGKEY}" "Current Version" 149 ; version not found in registry rty with the version file 150 ${If} $R1 == "" 151 StrCpy $R5 "$R0\VERSION.TXT" 152 Call GetOpenTURNSFileVersion 153 ${EndIf} 154 Goto end_openturns_reg_not_found 155 openturns_reg_not_found: 156 !insertmacro PRINT "OpenTURNS not found in $R0." 157 StrCpy $R0 "" 158 end_openturns_reg_not_found: 159 ${EndIf} 160 161 ; Search the prog in default directory 162 ${If} $R0 == "" 163 IfFileExists "${Default_OT_INSTALL_PATH}\*.*" 0 openturns_not_found 164 !insertmacro PRINT "OpenTURNS found in ${Default_OT_INSTALL_PATH}." 165 StrCpy $R0 "${Default_OT_INSTALL_PATH}" 166 StrCpy $R5 "$R0\VERSION.TXT" 167 Call GetOpenTURNSFileVersion 168 openturns_not_found: 169 ${EndIf} 170 171FunctionEnd 172 173 174