summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlbin Sunnanbo <albin@sunnanbo.com>2008-03-13 14:24:00 +0000
committeralbinsunnanbo <albinsunnanbo@users.sourceforge.net>2008-03-13 14:24:00 +0000
commit69dc47d89f6605a2d9bb7e424766c38ffcbd3e93 (patch)
treede9d256195b8df9b945c9f43272a61812cfc08e0 /src
parentBUG 168896, fix init.cpp.patch Native windows dialogs breaks some extensions ... (diff)
downloadinkscape-69dc47d89f6605a2d9bb7e424766c38ffcbd3e93.tar.gz
inkscape-69dc47d89f6605a2d9bb7e424766c38ffcbd3e93.zip
BUG 168896, fix BUG_168896_refactor_tempfile.patch problems with Vista tempfiles breaks some extensions (including Save as XAML)
(bzr r5082)
Diffstat (limited to 'src')
-rw-r--r--src/extension/implementation/script.cpp8
-rw-r--r--src/extension/implementation/xslt.cpp2
-rw-r--r--src/io/sys.cpp45
-rw-r--r--src/io/sys.h3
-rw-r--r--src/ui/dialog/ocaldialogs.cpp3
-rw-r--r--src/ui/dialog/print.cpp3
6 files changed, 57 insertions, 7 deletions
diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp
index 381b02b08..da60c8821 100644
--- a/src/extension/implementation/script.cpp
+++ b/src/extension/implementation/script.cpp
@@ -472,7 +472,7 @@ ScriptDocCache::ScriptDocCache (Inkscape::UI::View::View * view) :
_tempfd(0)
{
try {
- _tempfd = Glib::file_open_tmp(_filename, "ink_ext_XXXXXX.svg");
+ _tempfd = Inkscape::IO::file_open_tmp(_filename, "ink_ext_XXXXXX.svg");
} catch (...) {
/// \todo Popup dialog here
return;
@@ -593,7 +593,7 @@ Script::open(Inkscape::Extension::Input *module,
std::string tempfilename_out;
int tempfd_out = 0;
try {
- tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX");
+ tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX");
} catch (...) {
/// \todo Popup dialog here
return NULL;
@@ -667,7 +667,7 @@ Script::save(Inkscape::Extension::Output *module,
std::string tempfilename_in;
int tempfd_in = 0;
try {
- tempfd_in = Glib::file_open_tmp(tempfilename_in, "ink_ext_XXXXXX");
+ tempfd_in = Inkscape::IO::file_open_tmp(tempfilename_in, "ink_ext_XXXXXX");
} catch (...) {
/// \todo Popup dialog here
return;
@@ -764,7 +764,7 @@ Script::effect(Inkscape::Extension::Effect *module,
std::string tempfilename_out;
int tempfd_out = 0;
try {
- tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX.svg");
+ tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX.svg");
} catch (...) {
/// \todo Popup dialog here
return;
diff --git a/src/extension/implementation/xslt.cpp b/src/extension/implementation/xslt.cpp
index fb7d6a6f9..8b0ba97a8 100644
--- a/src/extension/implementation/xslt.cpp
+++ b/src/extension/implementation/xslt.cpp
@@ -195,7 +195,7 @@ XSLT::save(Inkscape::Extension::Output */*module*/, SPDocument *doc, gchar const
std::string tempfilename_out;
int tempfd_out = 0;
try {
- tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX");
+ tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX");
} catch (...) {
/// \todo Popup dialog here
return;
diff --git a/src/io/sys.cpp b/src/io/sys.cpp
index a1e693a24..b184988fd 100644
--- a/src/io/sys.cpp
+++ b/src/io/sys.cpp
@@ -166,6 +166,51 @@ int Inkscape::IO::mkdir_utf8name( char const *utf8name )
return retval;
}
+/*
+ * Wrapper around Glib::file_open_tmp()
+ * Returns a handle to the temp file
+ * name_used contains the actual name used
+ *
+ * Returns:
+ * A file handle (as from open()) to the file opened for reading and writing.
+ * The file is opened in binary mode on platforms where there is a difference.
+ * The file handle should be closed with close().
+ *
+ * Note:
+ * On Windows Vista Glib::file_open_tmp fails with the current version of glibmm
+ * A special case is implemented for WIN32. This can be removed if the issue is fixed
+ * in future versions of glibmm
+ * */
+int Inkscape::IO::file_open_tmp(std::string& name_used, const std::string& prefix)
+{
+#ifndef WIN32
+ return Glib::file_open_tmp(name_used, prefix);
+#else
+ /* Special case for WIN32 due to a bug in glibmm
+ * (only needed for Windows Vista, but since there is only one windows build all builds get the workaround)
+ * The workaround can be removed if the bug is fixed in glibmm
+ *
+ * The code is mostly identical to the implementation in glibmm
+ * http://svn.gnome.org/svn/glibmm/branches/glibmm-2-12/glib/src/fileutils.ccg
+ * */
+
+ std::string basename_template (prefix);
+ basename_template += "XXXXXX"; // this sillyness shouldn't be in the interface
+
+ GError* error = 0;
+ gchar *buf_name_used;
+
+ gint fileno = g_file_open_tmp(basename_template.c_str(), &buf_name_used, &error);
+
+ if(error)
+ Glib::Error::throw_exception(error);
+
+ name_used = g_strdup(buf_name_used);
+ g_free(buf_name_used);
+ return fileno;
+#endif
+}
+
bool Inkscape::IO::file_test( char const *utf8name, GFileTest test )
{
bool exists = false;
diff --git a/src/io/sys.h b/src/io/sys.h
index fd39c630b..b31602d91 100644
--- a/src/io/sys.h
+++ b/src/io/sys.h
@@ -18,6 +18,7 @@
#include <glib/gtypes.h>
#include <glib/gdir.h>
#include <glib/gfileutils.h>
+#include <string>
/*#####################
## U T I L I T Y
@@ -32,6 +33,8 @@ FILE *fopen_utf8name( char const *utf8name, char const *mode );
int mkdir_utf8name( char const *utf8name );
+int file_open_tmp( std::string& name_used, const std::string& prefix );
+
bool file_test( char const *utf8name, GFileTest test );
GDir *dir_open(gchar const *utf8name, guint flags, GError **error);
diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp
index e9ef63443..19b739061 100644
--- a/src/ui/dialog/ocaldialogs.cpp
+++ b/src/ui/dialog/ocaldialogs.cpp
@@ -24,6 +24,7 @@
#include "interface.h"
#include "gc-core.h"
#include <dialogs/dialog-events.h>
+#include "io/sys.h"
namespace Inkscape
{
@@ -285,7 +286,7 @@ void FileListViewText::on_cursor_changed()
// create file path
const std::string tmptemplate = "ocal-";
std::string tmpname;
- int fd = Glib::file_open_tmp(tmpname, tmptemplate);
+ int fd = Inkscape::IO::file_open_tmp(tmpname, tmptemplate);
if (fd<0) {
g_warning("Error creating temp file");
return;
diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp
index 3deb4204a..52ff07ee6 100644
--- a/src/ui/dialog/print.cpp
+++ b/src/ui/dialog/print.cpp
@@ -26,6 +26,7 @@
#include "unit-constants.h"
#include "helper/png-write.h"
#include "svg/svg-color.h"
+#include "io/sys.h"
static void
@@ -46,7 +47,7 @@ draw_page (GtkPrintOperation */*operation*/,
std::string tmp_base = "inkscape-print-png-XXXXXX";
int tmp_fd;
- if ( (tmp_fd = Glib::file_open_tmp (tmp_png, tmp_base)) >= 0) {
+ if ( (tmp_fd = Inkscape::IO::file_open_tmp (tmp_png, tmp_base)) >= 0) {
close(tmp_fd);
guint32 bgcolor = 0x00000000;