49 std::vector<const SteamLaunchEntry*> windowsEntries;
52 if (entry.supportsWindows() && !entry.executable.empty())
54 windowsEntries.push_back(&entry);
58 if (windowsEntries.empty())
62 for (
const auto* entry : windowsEntries)
64 if (entry->isDefault())
69 return *windowsEntries.front();
74 std::vector<const SteamLaunchEntry*> linuxEntries;
77 if (entry.supportsLinux() && !entry.executable.empty())
79 linuxEntries.push_back(&entry);
83 if (linuxEntries.empty())
86 for (
const auto* entry : linuxEntries)
88 if (entry->isDefault())
92 return *linuxEntries.front();
101 std::ifstream file(path, std::ios::binary | std::ios::ate);
104 Logger::error(
"[AppInfo] Failed to open: {}", path.string());
108 auto fileSize = file.tellg();
111 Logger::error(
"[AppInfo] File too small: {} bytes",
static_cast<size_t>(fileSize));
116 constexpr std::streamoff kMaxFileSize = 512LL * 1024 * 1024;
117 if (fileSize > kMaxFileSize)
119 Logger::error(
"[AppInfo] File exceeds maximum allowed size ({} bytes): {}",
120 static_cast<size_t>(fileSize), path.string());
125 data_.resize(
static_cast<size_t>(fileSize));
126 file.read(
reinterpret_cast<char*
>(data_.data()), fileSize);
130 std::memcpy(&version_, data_.data(), 4);
131 if (version_ == MAGIC_V27 || version_ == MAGIC_V28)
137 Logger::warn(
"[AppInfo] Detected legacy appinfo.vdf format 0x{:08X}. "
138 "Update your Steam client to restore metadata parsing; "
139 "falling back to ACF manifests.",
143 if (version_ != MAGIC_V29)
146 "[AppInfo] Unknown format version: 0x{:08X} (expected 0x{:08X}, 0x{:08X}, or 0x{:08X})",
147 version_, MAGIC_V27, MAGIC_V28, MAGIC_V29);
152 uint64_t stOffset = 0;
153 std::memcpy(&stOffset, data_.data() + 8, 8);
155 if (stOffset >= data_.size())
157 Logger::error(
"[AppInfo] String table offset out of bounds: {}", stOffset);
161 if (!loadStringTable(
static_cast<size_t>(stOffset)))
167 if (!indexAppRecords())
173 Logger::info(
"[AppInfo] Loaded {} apps, {} strings from {}", appOffsets_.size(),
174 stringTable_.size(), path.filename().string());
178bool SteamAppInfoParser::loadStringTable(
size_t offset)
180 if (offset + 4 > data_.size())
184 std::memcpy(&count, data_.data() + offset, 4);
187 stringTable_.clear();
189 constexpr uint32_t kMaxStringCount = 1'000'000;
190 stringTable_.reserve(std::min(count, kMaxStringCount));
192 for (uint32_t i = 0; i < count && offset < data_.size(); ++i)
195 const char* start =
reinterpret_cast<const char*
>(data_.data() + offset);
196 size_t maxLen = data_.size() - offset;
197 size_t len = strnlen(start, maxLen);
199 stringTable_.emplace_back(start, len);
208bool SteamAppInfoParser::indexAppRecords()
215 while (offset + 8 <= data_.size())
218 std::memcpy(&appId, data_.data() + offset, 4);
224 uint32_t recordSize = 0;
225 std::memcpy(&recordSize, data_.data() + offset, 4);
229 if (recordSize > data_.size() - offset)
231 Logger::warn(
"[AppInfo] Truncated record for app {}", appId);
235 appOffsets_[appId] = {offset, recordSize};
236 offset += recordSize;
248 auto it = appOffsets_.find(appId);
249 if (it == appOffsets_.end())
252 auto [offset, size] = it->second;
253 return parseAppRecord(offset, size);
258 return appOffsets_.find(appId) != appOffsets_.end();
261SteamAppVdfInfo SteamAppInfoParser::parseAppRecord(
size_t offset,
size_t size)
const
266 size_t vdfStart = offset + APP_RECORD_HEADER_SIZE;
267 size_t vdfEnd = offset + size;
269 if (vdfStart >= vdfEnd || vdfEnd > data_.size())
272 auto vdfData = parseVdfBinary(vdfStart, vdfEnd);
275 if (
auto* appinfo = getNestedMap(vdfData,
"appinfo"))
277 if (
auto* common = getNestedMap(*appinfo,
"common"))
279 info.
name = getNestedString(*common,
"name");
280 info.
type = getNestedString(*common,
"type");
284 if (
auto* config = getNestedMap(*appinfo,
"config"))
286 if (
auto* launch = getNestedMap(*config,
"launch"))
288 for (
const auto& [key, val] : *launch)
290 if (val.type != VdfValue::MAP)
296 idx = std::stoi(key);
303 info.
launchEntries.push_back(parseLaunchEntry(val.mapVal, idx));
308 [](
const auto& a,
const auto& b) { return a.index < b.index; });
314 if (
auto* appinfo = getNestedMap(vdfData,
"appinfo"))
316 auto it = appinfo->find(
"appid");
317 if (it != appinfo->end())
319 info.
appId = it->second.asInt();
326SteamLaunchEntry SteamAppInfoParser::parseLaunchEntry(
const VdfMap& data,
int index)
const
328 SteamLaunchEntry entry;
330 entry.
executable = getNestedString(data,
"executable");
331 entry.
arguments = getNestedString(data,
"arguments");
332 entry.
description = getNestedString(data,
"description");
333 entry.
type = getNestedString(data,
"type");
336 if (
auto* config = getNestedMap(data,
"config"))
338 entry.
oslist = getNestedString(*config,
"oslist");
339 entry.
osarch = getNestedString(*config,
"osarch");
349SteamAppInfoParser::VdfMap SteamAppInfoParser::parseVdfBinary(
size_t offset,
size_t endOffset)
const
351 return parseVdfBinaryRecursive(offset, endOffset, 0);
354SteamAppInfoParser::VdfMap
355SteamAppInfoParser::parseVdfBinaryRecursive(
size_t& offset,
size_t endOffset,
int depth)
const
362 while (offset < endOffset)
364 uint8_t typeTag = data_[offset];
367 if (typeTag ==
static_cast<uint8_t
>(VdfType::End))
371 if (offset + 4 > endOffset)
374 uint32_t keyIndex = 0;
375 std::memcpy(&keyIndex, data_.data() + offset, 4);
378 std::string key = getStringByIndex(keyIndex);
382 switch (
static_cast<VdfType
>(typeTag))
384 case VdfType::Nested:
386 value.type = VdfValue::MAP;
387 value.mapVal = parseVdfBinaryRecursive(offset, endOffset, depth + 1);
390 case VdfType::String:
392 value.type = VdfValue::STRING;
393 const char* start =
reinterpret_cast<const char*
>(data_.data() + offset);
394 size_t maxLen = endOffset - offset;
395 size_t len = strnlen(start, maxLen);
396 value.strVal.assign(start, len);
397 offset += len + (len < maxLen ? 1 : 0);
402 case VdfType::Pointer:
404 value.type = VdfValue::INT32;
405 if (offset + 4 > endOffset)
407 std::memcpy(&value.intVal, data_.data() + offset, 4);
411 case VdfType::Float32:
413 value.type = VdfValue::INT32;
414 if (offset + 4 > endOffset)
417 std::memcpy(&value.intVal, data_.data() + offset, 4);
422 case VdfType::Int64Unsigned:
424 value.type = VdfValue::INT64;
425 if (offset + 8 > endOffset)
427 std::memcpy(&value.int64Val, data_.data() + offset, 8);
433 Logger::debug(
"[AppInfo] Unknown VDF type 0x{:02X} at offset {}", typeTag, offset - 5);
437 result[key] = std::move(value);
447std::string SteamAppInfoParser::getStringByIndex(uint32_t index)
const
449 if (index < stringTable_.size())
450 return stringTable_[index];
451 return std::to_string(index);
454const SteamAppInfoParser::VdfMap* SteamAppInfoParser::getNestedMap(
const VdfMap& root,
455 const std::string& key)
const
457 auto it = root.find(key);
458 if (it != root.end())
459 return it->second.asMap();
463std::string SteamAppInfoParser::getNestedString(
const VdfMap& map,
const std::string& key)
const
465 auto it = map.find(key);
466 if (it != map.end() && it->second.type == VdfValue::STRING)
467 return it->second.strVal;
471uint32_t SteamAppInfoParser::getNestedInt(
const VdfMap& map,
const std::string& key)
const
473 auto it = map.find(key);
474 if (it != map.end() && it->second.type == VdfValue::INT32)
475 return it->second.intVal;
static void info(const std::string &message, Args &&... args)
Log info message (general information).
static void debug(const std::string &message, Args &&... args)
Log debug message (verbose development info).
static void error(const std::string &message, Args &&... args)
Log error message (recoverable failure).
static void warn(const std::string &message, Args &&... args)
Log warning message (non-critical issue).
std::optional< SteamAppVdfInfo > getAppInfo(uint32_t appId) const
Get parsed app info for a specific app ID.
bool load(const std::filesystem::path &path)
Load and index an appinfo.vdf file.
bool hasApp(uint32_t appId) const
Check if a specific app ID exists in the cache.
Parsed metadata for a single Steam app from appinfo.vdf.
std::string name
App name from common section.
std::optional< SteamLaunchEntry > getProtonLaunchEntry() const
Get the best launch entry for running under Proton.
std::vector< SteamLaunchEntry > launchEntries
All launch configurations.
std::string type
App type: "Game", "Tool", "DLC", "Demo", etc.
std::optional< SteamLaunchEntry > getNativeLaunchEntry() const
Get the best launch entry for native Linux execution.
A single launch configuration from appinfo.vdf.
int index
Launch entry index (0, 1, 2, ...).
std::string description
User-facing description (e.g., "DirectX 12 mode").
std::string osarch
Architecture: "32", "64", or empty.
std::string executable
Executable path relative to install dir (e.g., "game.exe").
std::string type
Launch type: "default", "none", "option1", "option2", etc.
std::string arguments
Default launch arguments.
std::string oslist
Comma-separated OS list: "windows", "linux", "macos".