1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-16 17:08:25 +02:00

If an app settings file is empty, remove it

Since only non-default values are saved, it was quite likely settings
files were empty, especially since the clock saving was fixed. We now
remove a settings file on save if the contents are empty, so we have
to load fewer files on startup.
This commit is contained in:
Maarten ter Huurne 2014-08-18 12:47:50 +02:00
parent 23205dc7e6
commit 07eefb219f

View File

@ -39,6 +39,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <array> #include <array>
#include <cerrno>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <utility> #include <utility>
@ -329,31 +330,39 @@ bool LinkApp::targetExists()
bool LinkApp::save() { bool LinkApp::save() {
if (!edited) return false; if (!edited) return false;
DEBUG("Saving file: %s\n", file.c_str()); std::ostringstream out;
if (!isOpk()) {
if (!title.empty() ) out << "title=" << title << endl;
if (!description.empty() ) out << "description=" << description << endl;
if (!launchMsg.empty() ) out << "launchmsg=" << launchMsg << endl;
if (!icon.empty() ) out << "icon=" << icon << endl;
if (!exec.empty() ) out << "exec=" << exec << endl;
if (!params.empty() ) out << "params=" << params << endl;
if (!manual.empty() ) out << "manual=" << manual << endl;
if (consoleApp ) out << "consoleapp=true" << endl;
if (selectorfilter != "*") out << "selectorfilter=" << selectorfilter << endl;
}
if (iclock != 0 ) out << "clock=" << iclock << endl;
if (!selectordir.empty() ) out << "selectordir=" << selectordir << endl;
if (!selectorbrowser ) out << "selectorbrowser=false" << endl;
if (out.tellp() > 0) {
DEBUG("Saving app settings: %s\n", file.c_str());
ofstream f(file.c_str()); ofstream f(file.c_str());
if (f.is_open()) { if (f.is_open()) {
if (!isOpk()) { f << out.str();
if (!title.empty() ) f << "title=" << title << endl;
if (!description.empty() ) f << "description=" << description << endl;
if (!launchMsg.empty() ) f << "launchmsg=" << launchMsg << endl;
if (!icon.empty() ) f << "icon=" << icon << endl;
if (!exec.empty() ) f << "exec=" << exec << endl;
if (!params.empty() ) f << "params=" << params << endl;
if (!manual.empty() ) f << "manual=" << manual << endl;
if (consoleApp ) f << "consoleapp=true" << endl;
if (selectorfilter != "*") f << "selectorfilter=" << selectorfilter << endl;
}
if (iclock != 0 ) f << "clock=" << iclock << endl;
if (!selectordir.empty() ) f << "selectordir=" << selectordir << endl;
if (!selectorbrowser ) f << "selectorbrowser=false" << endl;
f.close(); f.close();
sync(); sync();
return true; return true;
} else } else {
ERROR("Error while opening the file '%s' for write.\n", file.c_str()); ERROR("Error while opening the file '%s' for write.\n", file.c_str());
return false; return false;
} }
} else {
DEBUG("Empty app settings: %s\n", file.c_str());
return unlink(file.c_str()) == 0 || errno == ENOENT;
}
}
void LinkApp::drawLaunch(Surface& s) { void LinkApp::drawLaunch(Surface& s) {
//Darkened background //Darkened background