public static string UriToFilename(string uri)
{
// TODO: replace with managed conversion to avoid marshalling
IntPtr uri_ptr = GLib.Marshaller.StringToPtrGStrdup (uri);
IntPtr path_ptr = PlatformDetection.IsWindows
? g_filename_from_uri_utf8 (uri_ptr, IntPtr.Zero, IntPtr.Zero)
: g_filename_from_uri (uri_ptr, IntPtr.Zero, IntPtr.Zero);
GLib.Marshaller.Free (uri_ptr);
if (path_ptr == IntPtr.Zero) {
throw new ApplicationException ("URI could not be converted to local file location");
}
string path = GLib.Marshaller.Utf8PtrToString (path_ptr);
GLib.Marshaller.Free (path_ptr);
return path;
}