예제 #1
0
        public static string GetFolder(MacDomains domain, uint folderType)
        {
            FSRef reference;
            int no = FSFindFolder(domain, folderType, false, out reference);

            if (no != 0) throw new Exception(string.Format("domain: {0} type: {1} return: {2}", domain, folderType, no));

            if (no != 0) return null;

            IntPtr url = IntPtr.Zero;
            IntPtr str = IntPtr.Zero;
            try
            {
                url = CFURLCreateFromFSRef(IntPtr.Zero, ref reference);
                str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);

                CFRange range = new CFRange();
                range.location = (IntPtr)0;
                range.length = (IntPtr)CFStringGetLength(str);

                char[] strdata = new char[(int)range.length];
                CFStringGetCharacters(str, range, strdata);
                return new String(strdata);
            }
            finally
            {
                if (url != IntPtr.Zero) CoreFoundation.Release(url);
                if (str != IntPtr.Zero) CoreFoundation.Release(str);
            }
        }
예제 #2
0
        public static string GetFolder(MacDomains domain, uint folderType)
        {
            FSRef reference;
            int   no = FSFindFolder(domain, folderType, false, out reference);

            if (no != 0)
            {
                throw new Exception(string.Format("domain: {0} type: {1} return: {2}", domain, folderType, no));
            }

            if (no != 0)
            {
                return(null);
            }

            IntPtr url = IntPtr.Zero;
            IntPtr str = IntPtr.Zero;

            try
            {
                url = CFURLCreateFromFSRef(IntPtr.Zero, ref reference);
                str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);

                CFRange range = new CFRange();
                range.location = (IntPtr)0;
                range.length   = (IntPtr)CFStringGetLength(str);

                char[] strdata = new char[(int)range.length];
                CFStringGetCharacters(str, range, strdata);
                return(new String(strdata));
            }
            finally
            {
                if (url != IntPtr.Zero)
                {
                    CoreFoundation.Release(url);
                }
                if (str != IntPtr.Zero)
                {
                    CoreFoundation.Release(str);
                }
            }
        }
예제 #3
0
 private extern static short FSFindFolder(MacDomains vRefNum, uint folderType, bool createFolder, out FSRef foundRef);
예제 #4
0
 private static extern short FSFindFolder(MacDomains vRefNum, uint folderType, bool createFolder, out FSRef foundRef);