[gexiv2/wip/59: 2/2] win32: Handle non-unicode exiv2 case




commit f72dc06ecfedabb6bbd75dc538fd342b59325b26
Author: Jens Georg <mail jensge org>
Date:   Sat Nov 14 17:39:04 2020 +0100

    win32: Handle non-unicode exiv2 case
    
    If exiv2 is not compiled with windows unicode support, we need to
    convert the path to the locale from utf8.
    
    It can happen that this doesn't work (e.g. converting a russian filename
    on a german locale)
    
    Addresses #59

 gexiv2/gexiv2-metadata.cpp | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
---
diff --git a/gexiv2/gexiv2-metadata.cpp b/gexiv2/gexiv2-metadata.cpp
index 0b21d64..3c6c28f 100644
--- a/gexiv2/gexiv2-metadata.cpp
+++ b/gexiv2/gexiv2-metadata.cpp
@@ -23,6 +23,10 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
+#ifdef G_OS_WIN32
+#include <glib/gwin32.h>
+#endif
+
 #include <exiv2/exiv2.hpp>
 
 #if EXIV2_TEST_VERSION(0,27,99)
@@ -392,8 +396,22 @@ gboolean gexiv2_metadata_open_path (GExiv2Metadata *self, const gchar *path, GEr
         }
         file.append(wfile);
         g_free(wfile);
+#else
+#ifdef G_OS_WIN32
+        char* local_path = g_win32_locale_filename_from_utf8(path);
+        if (local_path == nullptr) {
+            char *msg = g_strdup_printf("Failed to convert \"%s\" to locale \"%s\"", path, 
g_win32_getlocale());
+            g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, msg);
+
+            g_free(msg);
+
+            return FALSE;
+        }
+        file = local_path;
+        g_free(local_path);
 #else
         file = path;
+#endif
 #endif
         self->priv->image = Exiv2::ImageFactory::open (file);
         


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]