Jump to content
rcmaehl

Steam Library UDF

Recommended Posts

rcmaehl

Hi all, I've recently needed to be able to catalog Programs on my system and Steam is a pain to do. So here's the UDF I've made.

FAQ

Q1: Isn't this game related?
A1: It's borderline, yes, so much so I cleared it with M23 before posting

Q2: Can you add X function that does X with the Steam API?
A2: No

Q3: Can you add X function that does X with games?
A3: No

Q4: Can you add X function that doesn't meet the above criteria?
A4: No, just to be safe anyway

Q5: Why doesn't this get me the .exe!?
A5: See Q3

 

UDF

#include-once
#include <File.au3>
#include <StringConstants.au3>

; #FUNCTION# ====================================================================================================================
; Name ..........: _GetSteamLibraries
; Description ...: Obtains a list of Steam Libraries
; Syntax ........: _GetSteamLibraries([$sPath = "None"])
; Parameters ....: $sPath               - [optional] Steam Install Directory. Default will grab from Registry
; Return values .: Success - Returns an array of Steam library locations
;                  Failure - Returns 0 and sets @error:
;                  |1 - Steam Install Location Error, sets @extended: (1, Unable to read Registry; 2, Path Invalid)
;                  |2 - Steam Library File Error, sets @extended: (1, File does not exist; 2, File could not be read)
; Author ........: rcmaehl (Robert Maehl)
; Modified ......: 03/20/19
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GetSteamLibraries($hPath = "None")

    Local $aLibraries[1]
    Local $hLibraryFile

    $aLibraries[0] = 0

    If $hPath = "None" Then
        Local $hSteamDir = RegRead("HKEY_CURRENT_USER\Software\Valve\Steam", "SteamPath")
        If @error Then
            SetError(1,0,0)
        Else
            $hSteamDir = StringReplace($hSteamDir, "/", "\")
        EndIf
    Else
        If FileExists($hPath) Then
            Local $hSteamDir = $hPath
        Else
            SetError(1,1,0)
        EndIf
    EndIf

    If FileExists($hSteamDir & "\steamapps\libraryfolders.vdf") Then
        $hLibraryFile = FileOpen($hSteamDir & "\steamapps\libraryfolders.vdf")
        If @error Then SetError(2,0,0)
    Else
        SetError(2,1,0)
    EndIf

    Local $iLines = _FileCountLines($hSteamDir & "\steamapps\libraryfolders.vdf")

    For $iLine = 1 to $iLines Step 1
        $sLine = FileReadLine($hLibraryFile, $iLine)
        If @error = -1 Then ExitLoop
        $sLine = StringStripWS($sLine, $STR_STRIPLEADING)
        $sLine = StringRegExpReplace($sLine, '"\s*"', "?")
        $sLine = StringReplace($sLine, '"', "")
        $sLine = StringReplace($sLine, "\\", "\")
        $aLine = StringSplit($sLine, '?')

        If $aLine[0] = 2 And StringIsInt($aLine[1]) Then
            ReDim $aLibraries[$aLine[1] + 1]
            $aLibraries[0] = UBound($aLibraries) - 1
            $aLibraries[$aLine[1]] = $aLine[2]
        EndIf
    Next

    FileClose($hLibraryFile)

    Return $aLibraries

EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _SteamGetGamesFromLibrary
; Description ...: Obtains a list of Games from a specified Steam Library
; Syntax ........: _SteamGetGamesFromLibrary($sLibrary)
; Parameters ....: $sLibrary            - Path to a valid Steam Library
; Return values .: Success - Returns an array of Steam games
;                  Failure - Returns 0 and sets @error:
;                  |1 - Steam Library Empty
; Author ........: rcmaehl (Robert Maehl)
; Modified ......: 03/09/19
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _SteamGetGamesFromLibrary($sLibrary)

    Local $aGames[1][2]

    $aGames[0][0] = "0"

    Local $hSearch = FileFindFirstFile($sLibrary & "\steamapps\appmanifest_*.acf")

    If $hSearch = -1 Then SetError(1,0,0)

    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then Return $aGames

        ReDim $aGames[UBound($aGames) + 1][2]

        $hManifestFile = FileOpen($sLibrary & "\steamapps\" & $sFile)
        If $hManifestFile = -1 Then ContinueLoop

        Local $iLines = _FileCountLines($sLibrary & "\steamapps\" & $sFile)

        For $iLine = 1 to $iLines Step 1
            $sLine = FileReadLine($hManifestFile, $iLine)
            If @error = -1 Then ExitLoop
            $sLine = StringStripWS($sLine, $STR_STRIPLEADING)
            $sLine = StringRegExpReplace($sLine, '"\s*"', "?")
            $sLine = StringReplace($sLine, '"', "")
            $aLine = StringSplit($sLine, '?')

            If $aLine[0] = 2 And $aLine[1] = "appid" Then
                $aGames[UBound($aGames) - 1][0] = $aLine[2]
            EndIf

            If $aLine[0] = 2 And $aLine[1] = "name" Then
                $aGames[UBound($aGames) - 1][1] = $aLine[2]
            EndIf
        Next

        $aGames[0][0] = UBound($aGames) - 1

        FileClose($hManifestFile)

    WEnd

EndFunc


; #FUNCTION# ====================================================================================================================
; Name ..........: _SteamGetGamesDetailsFromLibrary
; Description ...: Obtains a list of Details from a specified Steam Library
; Syntax ........: _SteamGetGamesDetailsFromLibrary($sLibrary, $sDetails)
; Parameters ....: $sLibrary            - Path to a valid Steam Library
;                  $sDetails            - a Opt("GUIDataSeparatorChar") seperated list of details to get
; Return values .: Success - Returns an array of Steam game details
;                  Failure - Returns 0 and sets @error:
;                  |1 - Steam Library Empty
; Author ........: rcmaehl (Robert Maehl)
; Modified ......: 03/09/19
; Modified ......:
; Remarks .......: Steam manifests do not include the location of the executable
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _SteamGetGamesDetailsFromLibrary($sLibrary, $sDetails)

    Local $aGames[1][2]

    $aDetails = StringSplit($sDetails, Opt("GUIDataSeparatorChar"), $STR_NOCOUNT)

    $aGames[0][0] = "0"

    Local $hSearch = FileFindFirstFile($sLibrary & "\steamapps\appmanifest_*.acf")

    ReDim $aGames[0][UBound($aDetails)]

    If $hSearch = -1 Then SetError(1,0,0)

    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then Return $aGames

        ReDim $aGames[UBound($aGames) + 1][UBound($aDetails)]

        $hManifestFile = FileOpen($sLibrary & "\steamapps\" & $sFile)
        If $hManifestFile = -1 Then ContinueLoop

        Local $iLines = _FileCountLines($sLibrary & "\steamapps\" & $sFile)

        For $iLine = 1 to $iLines Step 1
            $sLine = FileReadLine($hManifestFile, $iLine)
            If @error = -1 Then ExitLoop
            $sLine = StringStripWS($sLine, $STR_STRIPLEADING)
            $sLine = StringRegExpReplace($sLine, '"\s*"', "?")
            $sLine = StringReplace($sLine, '"', "")
            $aLine = StringSplit($sLine, '?')

            For $iDetail = 0 To UBound($aDetails) - 1

                If $aLine[0] = 2 And $aLine[1] = $aDetails[$iDetail] Then
                    $aGames[UBound($aGames) - 1][$iDetail] = $aLine[2]
                EndIf

            Next

        Next

        $aGames[0][0] = UBound($aGames) - 1

        FileClose($hManifestFile)

    WEnd

EndFunc


CHANGELOG

3/20/2018

    _GetSteamLibraries                Fixed:   No Longer Crashes if Steam is not installed
    _SteamGetGamesFromLibrary         Updated: Obtains AppID instead of install folder now

 

Edited by rcmaehl
Updated
  • Like 1

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Share this post


Link to post
Share on other sites
rcmaehl

Latest Update:

.
    _GetSteamLibraries                Fixed:   No Longer Crashes if Steam is not installed
    _SteamGetGamesFromLibrary         Updated: Obtains AppID instead of install folder now


I'm not sure why you would run this script without Steam being installed.... but it's fixed....


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • shokwave8
      By shokwave8
      Good evening,
      My problem: i tried to build a launcher for an Arma3 Server (onlinegame). Till now i made the launcher ask for the location of the arma3.exe for saving that and running this .exe. The following problem is, that i have no clue how to autoconnect to an IP:Port. I found some codes online and tryed to do the same but i failed. 
      Found these codes for C++ 
      Process.Start("steam://connect/DEINE_SERVER_IP:SERVER_PORT) Process.Start("steam://rungameid/107410// -skipintro -mod=@HierDeinAddonName-connect=HierDieServerIP -port=HierDerPort") Things i've tried:
      Run("steam://rungameid/107410") ;this doesn't start the game Run("S:\Steam\steamapps\common\Arma 3\arma3.exe") ;this starts the game without connecting ;is there a way of running the first one with AutoIT? I hope i could define the problem good enough for understanding. 
       
      Thanks a lot for  reading.  
       
       
      EDIT: I just figured out that 
      steam://rungameid/107410 is an URL and not a directory... I'm very sorry its to late for me  Still i would be glad if someone could help me with the autoconnection to a server. 
×