Example #1
0
        /// <summary>
        /// Opens an iDeviceFile stream on the specified path
        /// </summary>
        /// <param name="phone">A valid iDevice 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>
        unsafe public static iDeviceFile Open(iDevice 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.CurrentDirectory, path);
            ret       = MobileDevice.AFCFileRefOpen(phone.AFCHandle, full_path, (int)mode, 0, out handle);
            if (ret != 0)
            {
                phone.ReConnect();
                throw new IOException("AFCFileRefOpen failed with error " + ret.ToString());
            }

            return(new iDeviceFile(phone, handle, mode));
        }