From 78a2a490ffafb73572d2265297e295e4afcd60b0 Mon Sep 17 00:00:00 2001 From: Peter Repukat Date: Sun, 3 Apr 2022 12:53:26 +0200 Subject: [PATCH] Fix "shortcut.vdf"s with more than 10 entries. --- GlosSIConfig/UIModel.cpp | 7 ++++++- GlosSIConfig/VDFParser.h | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/GlosSIConfig/UIModel.cpp b/GlosSIConfig/UIModel.cpp index bf4b6ed..3bfdf91 100644 --- a/GlosSIConfig/UIModel.cpp +++ b/GlosSIConfig/UIModel.cpp @@ -410,5 +410,10 @@ std::wstring UIModel::getSteamUserId() const void UIModel::parseShortcutVDF() { const std::filesystem::path config_path = std::wstring(getSteamPath()) + user_data_path_.toStdWString() + getSteamUserId() + shortcutsfile_.toStdWString(); - shortcuts_vdf_ = VDFParser::Parser::parseShortcuts(config_path); + try { + shortcuts_vdf_ = VDFParser::Parser::parseShortcuts(config_path); + } + catch (const std::exception& e) { + qDebug() << "Error parsing VDF: " << e.what(); + } } diff --git a/GlosSIConfig/VDFParser.h b/GlosSIConfig/VDFParser.h index 5dc8d23..a2d38d4 100644 --- a/GlosSIConfig/VDFParser.h +++ b/GlosSIConfig/VDFParser.h @@ -282,7 +282,7 @@ class Parser { static inline std::ofstream ofile; template - static inline auto readVDFBuffer(typ& buff, size sz) + static inline auto readVDFBuffer(typ* buff, size sz) { if (ifile.eof()) { @@ -335,28 +335,45 @@ class Parser { if (vdffile.first_byte != firsty) { // TODO: invalid ifile.close(); - return vdffile; + throw std::exception("First byte is invalid in vdf"); } auto headername = readVDFString(); if (vdffile.identifier != headername) { // TODO: invalid ifile.close(); - return vdffile; + throw std::exception("VDF header is invalid"); } - char buff[3]; while (true) { + std::vector buff; if (ifile.eof()) { break; } - readVDFBuffer(buff, 3); // 2 bytes idx, 0x00 delmiter + char b = '\x0'; + readVDFBuffer(&b, 1); // skip 0 byte + if (b != '\x0') + buff.push_back(b); + do { + if (ifile.eof()) { + break; + } + readVDFBuffer(&b, 1); // 1-2 bytes idx, 0x00 delmiter + if (b != '\x0') + buff.push_back(b); + } while (b != '\x0'); if (buff[0] == 0x08 && buff[1] == 0x08) { break; } Shortcut shortcut; - shortcut.idx.data[0] = buff[0]; - shortcut.idx.data[1] = buff[1]; + if (buff.size() == 2) { + shortcut.idx.data[0] = buff[0]; + shortcut.idx.data[1] = buff[1]; + } + else { + shortcut.idx.data[0] = '\x0'; + shortcut.idx.data[1] = buff[0]; + } while (true) // TODO; { if (ifile.eof()) { @@ -371,7 +388,7 @@ class Parser { else { // WTF?! // TODO: - throw std::exception("WTF"); + throw std::exception("VDF: WTF"); } } auto key = readVDFString(); @@ -482,7 +499,11 @@ class Parser { ofile.write(vdffile.identifier.data(), vdffile.identifier.length()); ofile.write("\x00", 1); for (auto& shortcut : vdffile.shortcuts) { - ofile.write(shortcut.idx.data, 2); + if (shortcut.idx.data[0] == '\x0') { + ofile.write(&shortcut.idx.data[1], 1); + } else { + ofile.write(shortcut.idx.data, 2); + } ofile.write("\x00", 1); // ofile.write((char*)&shortcut.appId.type_id, 1);