Archive: Path is being corrupted with Installer


Path is being corrupted with Installer
I've researched this for hours and I'm at a dead end. Basically what's happening is I specify a path for a desktop shortcut to point to "C:\Program Files\Steam\Steam.exe"

Now I've put message boxes to output and verify these directories are correct as they install (At least in the msgbox). However the shortcut doesn't work. I looked at the target of the newly created shortcut and somehow the path gets turned into "C:\program filessteamsteam.exe" The final two slashes get removed and the words are joined together (except the space between program and files).

This seems like a bug. Am I doing something wrong in code? I've added it below:

-------------------------------------------------------
!define PRODUCT_NAME "Dissonance"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "Guildhall At SMU"
!define PRODUCT_WEB_SITE "http://guildhall.smu.edu"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define FULL_NAME "${PRODUCT_NAME} v${PRODUCT_VERSION}"
!define UNINSTALL_NAME "${FULL_NAME} Uninstall"

; Needed to find where the local files are to put in the installer
!define LOCALDIR "C:\Program Files\Steam\steamapps\SourceMods\Dissonance"
!define LOCAL_ICONDIR "C:\Program Files\Steam\steam\Games"
!define APPID 220

SetCompressor lzma

; MUI 1.67 compatible ------
!include "MUI.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

; Welcome page
!insertmacro MUI_PAGE_WELCOME
; Directory page
!insertmacro MUI_PAGE_COMPONENTS
; Components
!insertmacro MUI_PAGE_DIRECTORY

; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"

; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

; MUI end ------

Name "${FULL_NAME}"
OutFile "${FULL_NAME} Setup.exe"
;InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"

ShowInstDetails show
ShowUnInstDetails show

Section "Dissonance Game"
SetOutPath "$INSTDIR"
SetOverwrite try
File /r "${LOCALDIR}"
SectionEnd

Var ICONDIR
Var STEAMEXE
Var STEAMPATH

Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Website.lnk" "$INSTDIR\${PRODUCT_NAME}\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${UNINSTALL_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}\${UNINSTALL_NAME}.exe"

SetOutPath "$ICONDIR"
File "${LOCAL_ICONDIR}\${PRODUCT_NAME}.ico"
SectionEnd

Section "Desktop Shortcut" SHORTCUT
SetOutPath "$DESKTOP"
MessageBox MB_OK "Steam Exe: $STEAMEXE"
MessageBox MB_OK "Icon Dir: $ICONDIR"
CreateShortcut "${FULL_NAME}.lnk" $STEAMEXE
SectionEnd

Section -Post
WriteUninstaller "$INSTDIR\${PRODUCT_NAME}\${UNINSTALL_NAME}.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\${PRODUCT_NAME}\${UNINSTALL_NAME}.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd

Function .onInit
; Try to find the mod path from the registry
ReadRegStr $R0 HKCU "SOFTWARE\Valve\Steam" "SourceModInstallPath"
IfErrors ModPathError ModPathOk
ModPathError:
MessageBox MB_YESNO|MB_ICONEXCLAMATION "HELP SCREEN: Can't automatically find the 'SourceMods' folder address. $\r$\rIT'S OK TO CONTINUE... it just means you will have to find it manually... $\r$\r" IDYES done
Abort
ModPathOk:
StrCpy $INSTDIR "$R0"
MessageBox MB_OK "Install Dir $INSTDIR"

; Try to find the steam root path from the registry
ReadRegStr $R1 HKCU "SOFTWARE\Valve\Steam" "SteamPath"
IfErrors SteamPathError SteamPathOk
SteamPathError:
MessageBox MB_YESNO|MB_ICONEXCLAMATION "HELP SCREEN: Can't automatically find the root folder for steam. $\r$\rIT'S OK TO CONTINUE... it just means you will have to find it manually... $\r$\r" IDYES done
Abort
SteamPathOk:
StrCpy $STEAMPATH "$R1"
MessageBox MB_OK "SteamPath: $STEAMPATH"
StrCpy $ICONDIR "$STEAMPATH\steam\games"
MessageBox MB_OK "Icon Dir: $ICONDIR"
SectionSetFlags ${SHORTCUT} 0

; Try and find the steam.exe from the registry
ReadRegStr $R2 HKCU "SOFTWARE\Valve\Steam" "SteamExe"
IfErrors SteamExeError SteamExeOk
SteamExeError:
MessageBox MB_YESNO|MB_ICONEXCLAMATION "HELP SCREEN: Can't automatically find 'steam.exe'. $\r$\rIT'S OK TO CONTINUE... it just means you will have to find it manually... $\r$\r" IDYES done
Abort
SteamExeOk:
StrCpy $STEAMEXE "$R2"
MessageBox MB_OK "Steam Exe: $STEAMEXE"
Done:
FunctionEnd

Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
FunctionEnd

Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
Abort
FunctionEnd

Section Uninstall
MessageBox MB_OK "Install Dir: $INSTDIR"
RmDir /r "$INSTDIR\${PRODUCT_NAME}\*.*"

Delete "$DESKTOP\${FULL_NAME}.lnk"
Delete "$ICONDIR\${PRODUCT_NAME}.ico"
Delete "$SMPROGRAMS\${PRODUCT_NAME}\${UNINSTALL_NAME}.lnk"
Delete "$SMPROGRAMS\${PRODUCT_NAME}\Website.lnk"

RMDir "$SMPROGRAMS\${PRODUCT_NAME}"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
SetAutoClose true
SectionEnd


What does $INSTDIR get set to in your .onINIT function? Does it have a trailing backslash?


I think I fixed it. The registry variables that get referenced by STEAM_EXE path and STEAM_PATH path were stored as "C:/program files/steam/steam.exe" and "C:/program files/steam" respectively. Changing them to backslashes in the registry seemed to fix the problem.