Recent

Author Topic: Linux, Reading .vdf and .acf File from steam  (Read 449 times)

TheLastCayen

  • Jr. Member
  • **
  • Posts: 77
Linux, Reading .vdf and .acf File from steam
« on: September 26, 2020, 05:54:42 am »
Hi,

I am using :
 - Linux Mint Xfce 20
 - fpc-laz_3.2.0-1_amd64
 - lazarus-project_2.0.10-0_amd64
 - Steam client package version: 1599174997

File content: ~/.steam/steam/steamapps/libraryfolders.vdf

Code: Pascal  [Select][+][-]
  1. "LibraryFolders"
  2. {
  3.         "TimeNextStatsReport"           "1601180103"
  4.         "ContentStatsID"                "6125312595497005168"
  5.         "1"             "/media/local/IntelSSD/SteamLibrary"
  6.         "2"             "/media/local/WeakOS/game_lib_test"
  7. }
  8.  

I am looking for the proper way to read this file. The information I am looking for are the librarys folder path. So the value of
"1"
"2"
...

I wonder if there is a way like I will use to open an INI and read the elements or if I am better to open the file as plain text and use a
Code: Pascal  [Select][+][-]
  1.   I:=1;
  2.   while not EOF
  3.  

check for pos('"''+inttostr(I)+'"',string), find the next '"', read each char until the last '"', then finally inc(I) before the end of my loop...

I also have to read few .acf files that look like similar formating. This file seems to contain fixed values.

example: /media/local/IntelSSD/SteamLibrary/steamapps/appmanifest_380840.acf

Code: Pascal  [Select][+][-]
  1. "AppState"
  2. {
  3.         "appid"         "380840"
  4.         "Universe"              "1"
  5.         "name"          "Teeworlds"
  6.         "StateFlags"            "4"
  7.         "installdir"            "Teeworlds"
  8.         "LastUpdated"           "1601091118"
  9.         "UpdateResult"          "0"
  10.         "SizeOnDisk"            "13686336"
  11.         "buildid"               "4917151"
  12.         "LastOwner"             "76561198016630600"
  13.         "BytesToDownload"               "1463744"
  14.         "BytesDownloaded"               "1463744"
  15.         "AutoUpdateBehavior"            "0"
  16.         "AllowOtherDownloadsWhileRunning"               "0"
  17.         "ScheduledAutoUpdate"           "0"
  18.         "InstalledDepots"
  19.         {
  20.                 "380841"
  21.                 {
  22.                         "manifest"              "8063356514560605065"
  23.                         "size"          "9536238"
  24.                 }
  25.                 "380842"
  26.                 {
  27.                         "manifest"              "6745528655538745962"
  28.                         "size"          "4150098"
  29.                 }
  30.         }
  31.         "UserConfig"
  32.         {
  33.                 "language"              "english"
  34.                 "platform_override_dest"                "linux"
  35.                 "platform_override_source"              "windows"
  36.         }
  37. }
  38.  

In that file, I am looking for the value of :
  "appid"
  "name"
  "platform_override_dest"
  "platform_override_source"


Thank you



+ Attachments and other options
shortcuts: hit alt+s to submit/post or alt+p to preview

 

jamie

  • Hero Member
  • *****
  • Posts: 3782
Re: Linux, Reading .vdf and .acf File from steam
« Reply #1 on: September 27, 2020, 05:15:34 pm »
I guess no one person here as responded to your request

You need to make a little parser, one that first looks for your heading, then abides by the { … Opening brace, gather the quoted information ….

etc
The only true wisdom is knowing you know nothing

TheLastCayen

  • Jr. Member
  • **
  • Posts: 77
Re: Linux, Reading .vdf and .acf File from steam
« Reply #2 on: September 30, 2020, 03:48:02 am »
Thank you for your reply Jamie,

Sorry for the late post, I got a bit busy. What do you mean per parser? can you refer to any documentation? I only find how to make my prog language when I look on google for a parser.

Thank you

MarkMLl

  • Hero Member
  • *****
  • Posts: 1446
Re: Linux, Reading .vdf and .acf File from steam
« Reply #3 on: September 30, 2020, 10:03:25 am »
I'd suggest that the first thing to do is to look for any information at all on what the authors describe those files as. In general .ini files are deprecated because they aren't very good at defining structured data.

They probably wouldn't parse as JSON since there isn't a colon between the key and value, or as YAML on account of the quotes around both key and value, and it's clearly not XML. Even if you could find something which was superficially similar, there'd be a risk that Valve had done something unexpected with e.g. quoting/escaping. Various people describe it as "JSON-like" and there are relevant projects on e.g. Github, but the ultimate reference is obviously https://developer.valvesoftware.com/wiki/KeyValues

Apropos parsers, Google and/or Wp for "top down" and "recursive descent". The general idea is that you dascard whitespace/padding except where it's significant to the format (i.e. if EOL is significant you convert each to a token as you're reading the files, and you collapse repeated whitespace to single spaces), then you read (and process/store) a token and then use information on what you've just read to guide your choice as to what's expected next. So your

Code: [Select]
    "LibraryFolders"
    {
            "TimeNextStatsReport"           "1601180103"
            "ContentStatsID"                "6125312595497005168"
            "1"             "/media/local/IntelSSD/SteamLibrary"
            "2"             "/media/local/WeakOS/game_lib_test"
    }

is processed as

* Expect a quoted string... OK, got it.
* Expect a a block in braces... go do it... end.

Your block in braces is processed as

* Expect literal { otherwise error
* Expect quoted identifier or number
* If identifier, process it and expect a quoted string
* If number, process it and expect a quoted string
* repeat until }

HTH.

MarkMLl

« Last Edit: September 30, 2020, 05:48:12 pm by MarkMLl »
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

TheLastCayen

  • Jr. Member
  • **
  • Posts: 77
Re: Linux, Reading .vdf and .acf File from steam
« Reply #4 on: October 04, 2020, 05:22:17 pm »
Thank for the info MarkMLI,

I will work around what you recommended.

MarkMLl

  • Hero Member
  • *****
  • Posts: 1446
Re: Linux, Reading .vdf and .acf File from steam
« Reply #5 on: October 04, 2020, 07:15:15 pm »
The important point is that a parser doesn't swallow the next separator/terminator, so you typically parse from a buffer where you can put it back once you've encountered it.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

 

TinyPortal © 2005-2018