mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-25 20:49:44 +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:
parent
23205dc7e6
commit
07eefb219f
@ -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,30 +330,38 @@ 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;
|
||||||
|
|
||||||
ofstream f(file.c_str());
|
if (out.tellp() > 0) {
|
||||||
if (f.is_open()) {
|
DEBUG("Saving app settings: %s\n", file.c_str());
|
||||||
if (!isOpk()) {
|
ofstream f(file.c_str());
|
||||||
if (!title.empty() ) f << "title=" << title << endl;
|
if (f.is_open()) {
|
||||||
if (!description.empty() ) f << "description=" << description << endl;
|
f << out.str();
|
||||||
if (!launchMsg.empty() ) f << "launchmsg=" << launchMsg << endl;
|
f.close();
|
||||||
if (!icon.empty() ) f << "icon=" << icon << endl;
|
sync();
|
||||||
if (!exec.empty() ) f << "exec=" << exec << endl;
|
return true;
|
||||||
if (!params.empty() ) f << "params=" << params << endl;
|
} else {
|
||||||
if (!manual.empty() ) f << "manual=" << manual << endl;
|
ERROR("Error while opening the file '%s' for write.\n", file.c_str());
|
||||||
if (consoleApp ) f << "consoleapp=true" << endl;
|
return false;
|
||||||
if (selectorfilter != "*") f << "selectorfilter=" << selectorfilter << endl;
|
|
||||||
}
|
}
|
||||||
if (iclock != 0 ) f << "clock=" << iclock << endl;
|
} else {
|
||||||
if (!selectordir.empty() ) f << "selectordir=" << selectordir << endl;
|
DEBUG("Empty app settings: %s\n", file.c_str());
|
||||||
if (!selectorbrowser ) f << "selectorbrowser=false" << endl;
|
return unlink(file.c_str()) == 0 || errno == ENOENT;
|
||||||
f.close();
|
}
|
||||||
sync();
|
|
||||||
return true;
|
|
||||||
} else
|
|
||||||
ERROR("Error while opening the file '%s' for write.\n", file.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinkApp::drawLaunch(Surface& s) {
|
void LinkApp::drawLaunch(Surface& s) {
|
||||||
|
Loading…
Reference in New Issue
Block a user