Skip to content

Commit

Permalink
Make true/false checks case-insensitive
Browse files Browse the repository at this point in the history
Some applications ignore letter case of the spec and use True for true.
  • Loading branch information
Code7R committed Oct 2, 2024
1 parent 0a2f4dc commit 2597cc4
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/fdomenu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -464,29 +464,25 @@ DesktopFile::DesktopFile(string filePath, const string &langWanted) {
auto take_loc_best = [&](size_t start, string &out, string &outLoc) {
auto peq = line.find('=', start);
if (peq == string::npos)
return; // no value assigned at all?

return; // w00t, no value assigned at all?
// calc value start and end
auto v = line.find_first_not_of(SPACECHARS, peq + 1);
if (v == string::npos)
v = peq + 1;
auto e = line.find_last_not_of(SPACECHARS, v);
e = (e == string::npos) ? e + 1 : string::npos;
// identify language filter before value assignment
auto l = line.find('[', start);

// neutral version
// i18n neutral version
if (l >= peq || l == string::npos) {
out = line.substr(v, e - v);
return;
}

// translated version but not looked for localized
// translation found but not looking for localized version here?
if (langWanted.size() < 2)
return;

// get localized
l++;

// exact match always overrides, the short is considered optional
// the exact match always overrides, the short is considered optional
if (0 == line.compare(l, langWanted.size(), langWanted))
outLoc = line.substr(v, e - v);
else if (outLoc.empty() && 0 == line.compare(l, 2, langWanted, 0, 2))
Expand All @@ -512,29 +508,26 @@ DesktopFile::DesktopFile(string filePath, const string &langWanted) {
int kl = -1;
#define DFCHECK(x) (kl = sizeof(x) - 1, strncmp(line.c_str(), x, kl) == 0)
#define DFVALUE get_value(kl)
#define DFTRUE(x) (0 == strcasecmp("true", x.c_str()))
if (DFCHECK("Terminal"))
Terminal = DFVALUE.compare("true") == 0;
// else if (DFCHECK("TryExec"))
// TryExec = DFVALUE;
Terminal = DFTRUE(DFVALUE);
else if (DFCHECK("Type")) {
auto v = DFVALUE;
if (v == "Application")
IsApp = true;
else if (v == "Directory")
IsApp = false;
} else if (DFCHECK("NoDisplay"))
NoDisplay = DFVALUE.compare("true") == 0;
NoDisplay = DFTRUE(DFVALUE);
else if (DFCHECK("Name"))
take_loc_best(kl, Name, NameLoc);
else if (DFCHECK("OnlyShowIn"))
NoDisplay = true;
else if (DFCHECK("Icon"))
Icon = DFVALUE;
else if (DFCHECK("GenericName")) {
if (generic_name)
take_loc_best(kl, GenericName, GenericNameLoc);
continue;
} else if (DFCHECK("Categories"))
else if (DFCHECK("GenericName") && generic_name)
take_loc_best(kl, GenericName, GenericNameLoc);
else if (DFCHECK("Categories"))
Categories = DFVALUE;
else if (DFCHECK("Exec"))
Exec = DFVALUE;
Expand Down

0 comments on commit 2597cc4

Please sign in to comment.