Get Steam account name and install path: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Forgot about adding an extra line...) |
m (Reverted edits by 74.36.164.221 to last version by 68.186.162.227) |
||
(13 intermediate revisions by 10 users not shown) | |||
Line 17: | Line 17: | ||
If Steam is installed but no accounts are found, then the account name returned is "[ACCOUNT_NAME]". | 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: | |||
<highlight-nsis> | |||
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 | |||
</highlight-nsis> | |||
== The Function == | == The Function == | ||
Line 52: | Line 76: | ||
loopFile: | loopFile: | ||
StrCmp $R2 "SourceMods" nextFile | 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 | ||
StrCmp $R2 ".." nextFile | StrCmp $R2 ".." nextFile | ||
Line 84: | Line 111: | ||
Written for [[User:new NSIS user|new NSIS user]] in [http://forums.winamp.com/showthread.php?postid=1703925 this forum topic] (modified afterwards for Source mod developers). | Written for [[User:new NSIS user|new NSIS user]] in [http://forums.winamp.com/showthread.php?postid=1703925 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 | -Stu | ||
[[Category:Other Products Handling Functions]] | [[Category:Other Products Handling Functions]] |
Latest revision as of 05:14, 22 July 2008
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