Get Steam account name and install path: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Better description for function return values.)
m (Forgot about adding an extra line...)
Line 15: Line 15:


If Steam is not installed, then empty strings are returned.
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]".
If Steam is installed but no accounts are found, then the account name returned is "[ACCOUNT_NAME]".



Revision as of 09:47, 2 October 2005

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]".

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
  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).

-Stu