コード例 #1
0
        /// <summary>
        /// Opens an iPhoneFile stream on the specified path
        /// </summary>
        /// <param name="phone">A valid iPhone object</param>
        /// <param name="path">The file to open</param>
        /// <param name="openmode">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file</param>
        /// <returns></returns>
        public static iPhoneFile Open(iPhone phone, string path, FileAccess openmode)
        {
            OpenMode mode;
            int      ret;
            long     handle;
            string   full_path;

            mode = OpenMode.None;
            switch (openmode)
            {
            case FileAccess.Read: mode = OpenMode.Read; break;

            case FileAccess.Write: mode = OpenMode.Write; break;

            case FileAccess.ReadWrite: throw new NotImplementedException("Read+Write not (yet) implemented");
            }

            full_path = phone.FullPath(phone.GetCurrentDirectory(), path);
            ret       = MobileDevice.AFCFileRefOpen(phone.AFCHandle, full_path, (int)mode, 0, out handle);
            if (ret != 0)
            {
                throw new IOException("AFCFileRefOpen failed with error " + ret.ToString());
            }
            fileName = path;
            return(new iPhoneFile(phone, handle, mode));
        }