public static string FSRefToString(ref FSRef fsref) { IntPtr url = IntPtr.Zero; IntPtr str = IntPtr.Zero; try { url = CFURLCreateFromFSRef(IntPtr.Zero, ref fsref); if (url == IntPtr.Zero) { return(null); } str = CFURLCopyFileSystemPath(url, CFUrlPathStyle.Posix); if (str == IntPtr.Zero) { return(null); } return(FetchString(str)); } finally { if (url != IntPtr.Zero) { Release(url); } if (str != IntPtr.Zero) { Release(str); } } }
public static string FSRefToPath(ref FSRef fsRef) { //FIXME: is this big enough? const int MAX_LENGTH = 4096; IntPtr buf = IntPtr.Zero; string ret; try { buf = Marshal.AllocHGlobal(MAX_LENGTH); CheckReturn(FSRefMakePath(ref fsRef, buf, (uint)MAX_LENGTH)); //FIXME: on Mono, auto is UTF-8, which is correct but I'd prefer to be more explicit ret = Marshal.PtrToStringAuto(buf, MAX_LENGTH); } finally { if (buf != IntPtr.Zero) { Marshal.FreeHGlobal(buf); } } return(ret); }
static extern int FSRefMakePath(ref FSRef fsRef, IntPtr buffer, uint bufferSize);
extern static IntPtr CFURLCreateFromFSRef(IntPtr allocator, ref FSRef fsref);