Fix "shortcut.vdf"s with more than 10 entries.

pull/169/head
Peter Repukat 2 years ago
parent 49a4ea79e3
commit 78a2a490ff

@ -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();
}
}

@ -282,7 +282,7 @@ class Parser {
static inline std::ofstream ofile;
template <typename typ, typename size>
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<char> 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);

Loading…
Cancel
Save