summaryrefslogtreecommitdiffstats
path: root/src/preferences.cpp
diff options
context:
space:
mode:
authorMarc Jeanmougin <marc@jeanmougin.fr>2019-10-09 23:14:00 +0000
committerMarc Jeanmougin <marc@jeanmougin.fr>2019-10-09 23:14:00 +0000
commit83a3b443c3bc726126b9d9eea8233992a7fb7079 (patch)
tree82d093a9f54da81c44e4d8cf6bf167964a4bdbf9 /src/preferences.cpp
parentFix memory leaks in color wheel (diff)
downloadinkscape-83a3b443c3bc726126b9d9eea8233992a7fb7079.tar.gz
inkscape-83a3b443c3bc726126b9d9eea8233992a7fb7079.zip
Backup prefs instead of deleting
Fixes https://gitlab.com/inkscape/inbox/issues/850
Diffstat (limited to 'src/preferences.cpp')
-rw-r--r--src/preferences.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/preferences.cpp b/src/preferences.cpp
index 018ba7b01..8bcdcecc1 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -12,6 +12,7 @@
*/
#include <cstring>
+#include <ctime>
#include <sstream>
#include <utility>
#include <glibmm/fileutils.h>
@@ -271,11 +272,22 @@ void Preferences::save()
*/
void Preferences::reset()
{
+ time_t sptime = time (nullptr);
+ struct tm *sptm = localtime (&sptime);
+ gchar sptstr[256];
+ strftime (sptstr, 256, "%Y_%m_%d_%H_%M_%S", sptm);
+
+ char *new_name = g_strdup_printf("%s_%s", _prefs_filename.c_str(), sptstr);
+
+
if (g_file_test(_prefs_filename.c_str(), G_FILE_TEST_EXISTS)) {
- int retcode = g_unlink (_prefs_filename.c_str());
- if (retcode == 0) g_warning("%s", _("Preferences file was deleted."));
- else g_warning("%s", _("There was an error trying to delete the preferences file."));
+ //int retcode = g_unlink (_prefs_filename.c_str());
+ int retcode = g_rename (_prefs_filename.c_str(), new_name );
+ if (retcode == 0) g_warning("%s %s.", _("Preferences file was backed up to"), new_name);
+ else g_warning("%s", _("There was an error trying to reset the preferences file."));
}
+
+ g_free(new_name);
_observer_map.clear();
Inkscape::GC::release(_prefs_doc);
_prefs_doc = nullptr;