[banshee] [SafeUri] Fix g_filename_to_uri usage on Windows



commit 99efc88ee2b973da3e711e8ddc0a30ac90e01057
Author: Fernando Casanova <fcasanova fluendo com>
Date:   Fri Mar 5 15:43:48 2010 -0800

    [SafeUri] Fix g_filename_to_uri usage on Windows
    
    On Windows it converts first from the system encoding, so to work around
    that we directly call the _utf8 method (bgo#611694)
    
    Signed-off-by: Gabriel Burt <gabriel burt gmail com>

 src/Core/Banshee.Core/Banshee.Base/SafeUri.cs |   18 ++++++++++++++++++
 src/Core/Banshee.Core/Banshee.Core.csproj     |    1 +
 2 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/src/Core/Banshee.Core/Banshee.Base/SafeUri.cs b/src/Core/Banshee.Core/Banshee.Base/SafeUri.cs
index 4ab9bd1..171d1d7 100644
--- a/src/Core/Banshee.Core/Banshee.Base/SafeUri.cs
+++ b/src/Core/Banshee.Core/Banshee.Base/SafeUri.cs
@@ -74,7 +74,12 @@ namespace Banshee.Base
         {
             // TODO: replace with managed conversion to avoid marshalling
             IntPtr path_ptr = GLib.Marshaller.StringToPtrGStrdup (localPath);
+
+#if WIN32
+            IntPtr uri_ptr = g_filename_to_uri_utf8 (path_ptr, IntPtr.Zero, IntPtr.Zero);
+#else
             IntPtr uri_ptr = g_filename_to_uri (path_ptr, IntPtr.Zero, IntPtr.Zero);
+#endif
             GLib.Marshaller.Free (path_ptr);
 
             if (uri_ptr == IntPtr.Zero) {
@@ -91,7 +96,12 @@ namespace Banshee.Base
         {
             // TODO: replace with managed conversion to avoid marshalling
             IntPtr uri_ptr = GLib.Marshaller.StringToPtrGStrdup (uri);
+#if WIN32
+            IntPtr path_ptr = g_filename_from_uri_utf8 (uri_ptr, IntPtr.Zero, IntPtr.Zero);
+#else
             IntPtr path_ptr = g_filename_from_uri (uri_ptr, IntPtr.Zero, IntPtr.Zero);
+#endif
+
             GLib.Marshaller.Free (uri_ptr);
 
             if (path_ptr == IntPtr.Zero) {
@@ -176,10 +186,18 @@ namespace Banshee.Base
             get { return Scheme == System.Uri.UriSchemeFile; }
         }
 
+#if WIN32
+        [DllImport ("libglib-2.0-0.dll")]
+        private static extern IntPtr g_filename_to_uri_utf8 (IntPtr filename, IntPtr hostname, IntPtr error);
+
+        [DllImport ("libglib-2.0-0.dll")]
+        private static extern IntPtr g_filename_from_uri_utf8 (IntPtr uri, IntPtr hostname, IntPtr error);
+#else
         [DllImport ("libglib-2.0-0.dll")]
         private static extern IntPtr g_filename_to_uri (IntPtr filename, IntPtr hostname, IntPtr error);
 
         [DllImport ("libglib-2.0-0.dll")]
         private static extern IntPtr g_filename_from_uri (IntPtr uri, IntPtr hostname, IntPtr error);
+#endif
     }
 }
diff --git a/src/Core/Banshee.Core/Banshee.Core.csproj b/src/Core/Banshee.Core/Banshee.Core.csproj
index 1e79c23..b0c1a25 100644
--- a/src/Core/Banshee.Core/Banshee.Core.csproj
+++ b/src/Core/Banshee.Core/Banshee.Core.csproj
@@ -33,6 +33,7 @@
     <WarningLevel>4</WarningLevel>
     <Optimize>false</Optimize>
     <OutputPath>..\..\..\bin</OutputPath>
+    <DefineConstants>WIN32</DefineConstants>
   </PropertyGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\Libraries\Hyena\Hyena.csproj">



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