49
49
#include "application/editor.h"
50
50
#include "desktop.h"
51
51
#include "desktop-handles.h"
52
#include "dialogs/input.h"
52
#include "device-manager.h"
53
53
#include "document.h"
54
54
#include "event-context.h"
55
55
#include "extension/db.h"
56
56
#include "extension/init.h"
57
57
#include "extension/output.h"
58
58
#include "extension/system.h"
59
#include "helper/sp-marshal.h"
59
//#include "helper/sp-marshal.h"
60
60
#include "inkscape-private.h"
61
61
#include "io/sys.h"
62
62
#include "message-stack.h"
604
606
Inkscape::XML::Node *repr;
605
607
repr = sp_document_repr_root (doc);
606
608
if (doc->isModifiedSinceSave()) {
607
const gchar *docname, *d0, *d;
608
gchar n[64], c[1024];
609
const gchar *docname;
611
611
/* originally, the document name was retrieved from
612
612
* the sodipod:docname attribute */
613
613
docname = doc->name;
615
/* fixme: Quick hack to remove emergency file suffix */
616
d0 = strrchr ((char*)docname, '.');
615
/* Removes an emergency save suffix if present: /(.*)\.[0-9_]*\.[0-9_]*\.[~\.]*$/\1/ */
616
const char* d0 = strrchr ((char*)docname, '.');
617
617
if (d0 && (d0 > docname)) {
618
d0 = strrchr ((char*)(d0 - 1), '.');
619
if (d0 && (d0 > docname)) {
621
while (isdigit (*d) || (*d == '.') || (*d == '_')) d += 1;
623
memcpy (n, docname, MIN (d0 - docname - 1, 64));
619
unsigned int dots = 0;
620
while ((isdigit (*d) || *d=='_' || *d=='.') && d>docname && dots<2) {
624
if (*d=='.' && d>docname && dots==2) {
626
size_t len = MIN (d - docname, 63);
627
memcpy (n, docname, len);
631
633
if (!docname || !*docname) docname = "emergency";
632
// try saving to the profile location
635
// Emergency filename
633
637
g_snprintf (c, 1024, "%.256s.%s.%d.svg", docname, sptstr, count);
634
gchar * location = homedir_path(c);
635
Inkscape::IO::dump_fopen_call(location, "E");
636
file = Inkscape::IO::fopen_utf8name(location, "w");
637
g_snprintf (c, 1024, "%s", location); // we want the complete path to be stored in c (for reporting purposes)
640
// try saving to /tmp
641
g_snprintf (c, 1024, "/tmp/inkscape-%.256s.%s.%d.svg", docname, sptstr, count);
642
Inkscape::IO::dump_fopen_call(c, "G");
643
file = Inkscape::IO::fopen_utf8name(c, "w");
646
// try saving to the current directory
647
gchar *curdir = g_get_current_dir();
648
g_snprintf (c, 1024, "inkscape-%.256s.%s.%d.svg", docname, sptstr, count);
649
Inkscape::IO::dump_fopen_call(c, "F");
650
file = Inkscape::IO::fopen_utf8name(c, "w");
651
// store the complete path in c so that it can be reported later
652
gchar * location = g_build_filename(curdir, c, NULL);
653
g_snprintf (c, 1024, "%s", location);
640
const char* locations[] = {
648
for(size_t i=0; i<sizeof(locations)/sizeof(*locations); i++) {
649
if (!locations[i]) continue; // It seems to be okay, but just in case
650
gchar * filename = g_build_filename(locations[i], c, NULL);
651
Inkscape::IO::dump_fopen_call(filename, "E");
652
file = Inkscape::IO::fopen_utf8name(filename, "w");
654
g_snprintf (c, 1024, "%s", filename); // we want the complete path to be stored in c (for reporting purposes)
657
661
sp_repr_save_stream (repr->document(), file, SP_SVG_NS_URI);
658
662
savednames = g_slist_prepend (savednames, g_strdup (c));