Skip to content

Commit

Permalink
Fix Shitty shortcuts.vdf parser tag writing
Browse files Browse the repository at this point in the history
  • Loading branch information
Alia5 committed Sep 5, 2022
1 parent f532fb7 commit f631321
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions GlosSIConfig/VDFParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static constexpr const char k_Devkit[] = {"Devkit"};
static constexpr const char k_DevkitGameID[] = {"DevkitGameID"};
static constexpr const char k_DevkitOverrideAppID[] = {"DevkitOverrideAppID"};
static constexpr const char k_LastPlayTime[] = {"LastPlayTime"};
static constexpr const char k_FlatpakAppID[] = {"FlatpakAppID"};
static constexpr const char k_tags[] = {"tags"};

enum VDFTypeId {
Expand All @@ -77,7 +78,7 @@ enum VDFTypeId {
Number,
};

template <const char* const keyname, typename type, const uint8_t const _type_id>
template <const char* const keyname, typename type, const uint8_t _type_id>
struct VDFKeyPair {
VDFKeyPair() {}
explicit VDFKeyPair(type _value) : value(_value) {}
Expand Down Expand Up @@ -145,10 +146,12 @@ struct ShortcutTag {
ShortcutTag(){};
ShortcutTag(const ShortcutTag& other)
{
idx = other.idx;
value = other.value;
};
ShortcutTag(ShortcutTag&& other)
{
idx = std::move(other.idx);
value = std::move(other.value);
};
VDFIdx idx;
Expand All @@ -157,11 +160,13 @@ struct ShortcutTag {

ShortcutTag& operator=(const ShortcutTag& other)
{
idx = other.idx;
value = other.value;
return *this;
}
ShortcutTag& operator=(ShortcutTag&& other)
{
idx = std::move(other.idx);
value = std::move(other.value);
return *this;
}
Expand All @@ -184,6 +189,7 @@ struct Shortcut {
VDFKeyPair<k_DevkitGameID, std::string, VDFTypeId::String> DevkitGameID{""};
VDFKeyPair<k_DevkitOverrideAppID, uint32_t, VDFTypeId::Number> DevkitOverrideAppID{0}; //
VDFKeyPair<k_LastPlayTime, uint32_t, VDFTypeId::Number> LastPlayTime{0}; //
VDFKeyPair<k_FlatpakAppID, std::string, VDFTypeId::String> FlatpakAppID{""}; //
VDFKeyPair<k_tags, std::vector<ShortcutTag>, VDFTypeId::StringList> tags{};
Shortcut& operator=(const Shortcut& other)
{
Expand All @@ -204,6 +210,7 @@ struct Shortcut {
DevkitGameID = other.DevkitGameID;
DevkitOverrideAppID = other.DevkitOverrideAppID;
LastPlayTime = other.LastPlayTime;
FlatpakAppID = other.FlatpakAppID;
tags = other.tags;
return *this;
}
Expand Down Expand Up @@ -343,7 +350,7 @@ class Parser {
if (ifile.eof()) {
break;
}
auto tid = static_cast<VDFTypeId>(readVDFValue<uint8_t>());
const auto tid = static_cast<VDFTypeId>(readVDFValue<uint8_t>());
if (tid == 0x08) {
auto nextbyte = readVDFValue<uint8_t>();
if (nextbyte == 0x08) {
Expand Down Expand Up @@ -419,6 +426,10 @@ class Parser {
shortcut.LastPlayTime.value = readVDFValue<uint32_t>();
continue;
}
if (key == shortcut.FlatpakAppID.key) {
shortcut.FlatpakAppID.value = readVDFString();
continue;
}
if (key == shortcut.tags.key) {
ShortcutTag tag;
while (true) {
Expand All @@ -427,16 +438,16 @@ class Parser {
}
char tbuff[2];
readVDFBuffer(tbuff, 2); // 2 bytes POSSIBLE end marker
ifile.seekg(-2, std::ios_base::cur);
ifile.seekg(-1, std::ios_base::cur); // go one back, skip typeId
if (tbuff[0] == 0x08 && tbuff[1] == 0x08) {
ifile.seekg(-1, std::ios_base::cur); // another back
break;
}
tag.idx.data = readVDFString();
if (tag.idx.data == "\x08\x08") {
ifile.seekg(-2, std::ios_base::cur);
break;
}
ifile.seekg(1, std::ios_base::cur);
tag.value = readVDFString();
shortcut.tags.value.push_back(tag);
}
Expand Down Expand Up @@ -557,6 +568,12 @@ class Parser {
ofile.write(shortcut.LastPlayTime.key, 13);
ofile.write((char*)&shortcut.LastPlayTime.value, 4);

//
ofile.write((char*)&shortcut.FlatpakAppID.type_id, 1);
ofile.write(shortcut.FlatpakAppID.key, 13);
ofile.write(shortcut.FlatpakAppID.value.data(), shortcut.FlatpakAppID.value.length());
ofile.write("\x00", 1);

//
ofile.write((char*)&shortcut.tags.type_id, 1);
ofile.write(shortcut.tags.key, 5);
Expand Down

0 comments on commit f631321

Please sign in to comment.