diff options
| author | Albin Sunnanbo <albin@sunnanbo.com> | 2008-03-13 14:24:00 +0000 |
|---|---|---|
| committer | albinsunnanbo <albinsunnanbo@users.sourceforge.net> | 2008-03-13 14:24:00 +0000 |
| commit | 69dc47d89f6605a2d9bb7e424766c38ffcbd3e93 (patch) | |
| tree | de9d256195b8df9b945c9f43272a61812cfc08e0 /src/io | |
| parent | BUG 168896, fix init.cpp.patch Native windows dialogs breaks some extensions ... (diff) | |
| download | inkscape-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/io')
| -rw-r--r-- | src/io/sys.cpp | 45 | ||||
| -rw-r--r-- | src/io/sys.h | 3 |
2 files changed, 48 insertions, 0 deletions
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); |
