74 if (documents.empty()) {
82 std::string autosave_dir = prefs->
getString(
"/options/autosave/path");
83 if (autosave_dir.empty()) {
84 autosave_dir = Glib::build_filename(Glib::get_user_cache_dir(),
"inkscape");
87 Glib::RefPtr<Gio::File> dir_file = Gio::File::create_for_path(autosave_dir);
88 if (!dir_file->query_exists()) {
89 if (!dir_file->make_directory_with_parents()) {
90 std::cerr <<
"InkscapeApplication::document_autosave: Failed to create autosave directory: " << autosave_dir << std::endl;
100 std::time_t time = std::time(
nullptr);
101 std::tm tm = *std::localtime(&time);
102 std::stringstream datetime;
103 datetime << std::put_time(&tm,
"%Y_%m_%d_%H_%M_%S");
106 int autosave_max = prefs->
getInt(
"/options/autosave/max", 10);
107 for (
auto document : documents) {
111 if (document->isModifiedSinceAutoSave()) {
112 std::string base_name =
"automatic-save-" + std::to_string(uid);
119 Glib::Dir directory(autosave_dir);
120 std::vector<std::string> file_names(directory.begin(), directory.end());
123 std::sort(file_names.begin(), file_names.end(), std::greater<std::string>());
128 if (
file_name.compare(0, base_name.size(), base_name) == 0) {
130 if (count >= autosave_max) {
132 std::string path = Glib::build_filename(autosave_dir,
file_name);
133 if (unlink(path.c_str()) == -1) {
134 std::cerr <<
"InkscapeApplication::document_autosave: Failed to unlink file: "
135 << path <<
": " << strerror(errno) << std::endl;
143 std::string filename = base_name +
"-" + datetime.str() +
"-" + std::to_string(pid) +
"-" + std::to_string(docnum) +
".svg";
144 std::string path = Glib::build_filename(autosave_dir, filename.c_str());
149 gchar *errortext =
nullptr;
155 errortext = g_strdup(_(
"Autosave failed! Could not find inkscape extension to save document."));
158 errortext = g_strdup_printf(_(
"Autosave failed! File %s could not be saved."), safeUri.c_str());
163 errortext = g_strdup_printf(_(
"Autosave failed! File %s could not be saved."), safeUri.c_str());
167 g_warning(
"%s", errortext);
170 document->setModifiedSinceAutoSaveFalse();
void sp_repr_save_stream(Document *doc, FILE *fp, gchar const *default_ns, bool compress, gchar const *const old_href_abs_base, gchar const *const new_href_abs_base)