Get Steam account name and install path
From NSIS Wiki
Jump to navigationJump to search
Author: Afrow UK (talk, contrib) |
Description
This gets the account name for Valve's Steam (Half-Life 1, 2 etc) It also returns Steam's install path (e.g. C:\Valve\Steam)
Usage
Call GetSteamAccountName Pop $R0 ; account name e.g. afrow uk Pop $R1 ; steam path e.g. C:\Valve\Steam
If Steam is not installed, then empty strings are returned.
If Steam is installed but no accounts are found, then the account name returned is "[ACCOUNT_NAME]".
Example
Perhaps you want your $INSTDIR to be the full path to the SourceMods folder (for HL2), in which case you'd do it like so:
LangString SteamNotInstalled ${LANG_ENGLISH} "Valve's Steam is not installed!$\r$\nSetup will now exit." Function .onInit Call GetSteamAccountName Pop $R0 ; CaDDy- Pop $R1 ; E\Games\Steaaam # Check if Steam is installed StrCmp $R0 "" 0 +3 MessageBox MB_OK|MB_ICONSTOP $(SteamNotInstalled) Abort # It is installed so set INSTDIR StrCpy $INSTDIR "$R1\SteamApps\$R0\SourceMods\MyMod" FunctionEnd
The Function
Function GetSteamAccountName Push $R0 Push $R1 Push $R2 Push $R3 ReadRegStr $R0 HKCU "Software\Valve\Steam" "SteamExe" StrCmp $R0 "" noSteam StrCpy $R1 0 IntOp $R1 $R1 - 1 StrCpy $R2 $R0 1 $R1 StrCmp $R2 "" noAccount StrCmp $R2 "/" 0 -3 StrCpy $R0 $R0 $R1 StrCpy $R1 0 IntOp $R1 $R1 + 1 StrCpy $R2 $R0 1 -$R1 StrCmp $R2 "" +8 StrCmp $R2 "/" 0 -3 StrCpy $R2 $R0 -$R1 IntOp $R1 $R1 - 1 StrCpy $R3 $R0 "" -$R1 StrCpy $R0 "$R2\$R3" IntOp $R1 $R1 + 1 Goto -9 FindFirst $R1 $R2 "$R0\steamapps\*.*" loopFile: StrCmp $R2 "SourceMods" nextFile #added this for the newest steam (common/media is other content (like trailers and 3rd party games) StrCmp $R2 "common" nextFile StrCmp $R2 "media" nextFile StrCmp $R2 "." nextFile StrCmp $R2 ".." nextFile IfFileExists "$R0\steamapps\$R2\*.*" done nextFile: ClearErrors FindNext $R1 $R2 IfErrors 0 loopFile FindClose $R1 noAccount: StrCpy $R2 "[ACCOUNT_NAME]" done: StrCpy $R1 $R0 StrCpy $R0 $R2 Goto +3 noSteam: StrCpy $R1 "" StrCpy $R0 "" Pop $R3 Pop $R2 Exch $R1 Exch Exch $R0 FunctionEnd
Written for new NSIS user in this forum topic (modified afterwards for Source mod developers).
Edit (amckern) The VDC has a more complete script found at http://developer.valvesoftware.com/wiki/Source_Mod_Installers
-Stu