/// <summary> /// Determines whether the given path refers to an existing file or directory on the phone. /// </summary> /// <param name="path">The path to test.</param> /// <returns><c>true</c> if path refers to an existing file or directory, otherwise <c>false</c>.</returns> unsafe public bool Exists(string path) { void *data = null; int ret = MobileDevice.AFCFileInfoOpen(hAFC, path, ref data); if (ret == 0) { MobileDevice.AFCKeyValueClose(data); } return(ret == 0); }
unsafe private bool ConnectToPhone() { if (MobileDevice.AMDeviceConnect(iDeviceHandle) == 1) { //int connid; throw new Exception("Phone in recovery mode, support not yet implemented"); //connid = MobileDevice.AMDeviceGetConnectionID(ref iDeviceHandle); //MobileDevice.AMRestoreModeDeviceCreate(0, connid, 0); //return false; } if (MobileDevice.AMDeviceIsPaired(iDeviceHandle) == 0) { return(false); } int chk = MobileDevice.AMDeviceValidatePairing(iDeviceHandle); if (chk != 0) { return(false); } if (MobileDevice.AMDeviceStartSession(iDeviceHandle) == 1) { return(false); } if (MobileDevice.AMDeviceStartService(iDeviceHandle, new CFString("com.apple.afc2"), ref hService, null) != 0) { if (MobileDevice.AMDeviceStartService(iDeviceHandle, new CFString("com.apple.afc"), ref hService, null) != 0) { return(false); } } else { wasAFC2 = true; } if (MobileDevice.AFCConnectionOpen(hService, 0, ref hAFC) != 0) { return(false); } connected = true; return(true); }
/// <summary> /// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. /// </summary> /// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param> /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param> /// <param name="count">The number of bytes to be written to the current stream.</param> unsafe public override void Write(byte[] buffer, int offset, int count) { if (!CanWrite) { throw new NotImplementedException("Stream open for reading only"); } byte[] temp; if (offset == 0) { temp = buffer; } else { temp = new byte[count]; Buffer.BlockCopy(buffer, offset, temp, 0, count); } int ret = MobileDevice.AFCFileRefWrite(phone.AFCHandle, handle, temp, (uint)count); }
/// <summary> /// Initializes a new iDevice object. /// </summary> unsafe private void doConstruction() { dnc = new DeviceNotificationCallback(NotifyCallback); drn1 = new DeviceRestoreNotificationCallback(DfuConnectCallback); drn2 = new DeviceRestoreNotificationCallback(RecoveryConnectCallback); drn3 = new DeviceRestoreNotificationCallback(DfuDisconnectCallback); drn4 = new DeviceRestoreNotificationCallback(RecoveryDisconnectCallback); void *notification; int ret = MobileDevice.AMDeviceNotificationSubscribe(dnc, 0, 0, 0, out notification); if (ret != 0) { throw new Exception("AMDeviceNotificationSubscribe failed with error " + ret); } ret = MobileDevice.AMRestoreRegisterForDeviceNotifications(drn1, drn2, drn3, drn4, 0, null); if (ret != 0) { throw new Exception("AMRestoreRegisterForDeviceNotifications failed with error " + ret); } current_directory = "/"; }
/// <summary> /// Returns the FileInfo dictionary /// </summary> /// <param name="path">The file or directory for which to retrieve information.</param> unsafe public Dictionary <string, string> GetFileInfo(string path) { Dictionary <string, string> ans = new Dictionary <string, string>(); void *data = null; int ret = MobileDevice.AFCFileInfoOpen(hAFC, path, ref data); if (ret == 0 && data != null) { void *pname, pvalue; while (MobileDevice.AFCKeyValueRead(data, out pname, out pvalue) == 0 && pname != null && pvalue != null) { string name = Marshal.PtrToStringAnsi(new IntPtr(pname)); string value = Marshal.PtrToStringAnsi(new IntPtr(pvalue)); ans.Add(name, value); } MobileDevice.AFCKeyValueClose(data); } return(ans); }
/// <summary> /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device. /// </summary> unsafe public override void Flush() { MobileDevice.AFCFlushData(phone.AFCHandle, handle); }
/// <summary> /// Sets the length of this stream to the given value. /// </summary> /// <param name="value">The new length of the stream.</param> unsafe public override void SetLength(long value) { int ret; ret = MobileDevice.AFCFileRefSetFileSize(phone.AFCHandle, handle, (uint)value); }
/// <summary> /// Moves a file or a directory and its contents to a new location or renames a file or directory if the old and new parent path matches. /// </summary> /// <param name="sourceName">The path of the file or directory to move or rename.</param> /// <param name="destName">The path to the new location for <c>sourceName</c>.</param> /// <remarks>Files cannot be moved across filesystem boundaries.</remarks> unsafe public bool Rename(string sourceName, string destName) { return(MobileDevice.AFCRenamePath(hAFC, FullPath(CurrentDirectory, sourceName), FullPath(CurrentDirectory, destName)) == 0); }
/// <summary> /// Creates the directory specified in path /// </summary> /// <param name="path">The directory path to create</param> /// <returns>true if directory was created</returns> unsafe public bool CreateDirectory(string path) { return(!(MobileDevice.AFCDirectoryCreate(hAFC, FullPath(CurrentDirectory, path)) != 0)); }
/// <summary> /// Deactivates the iDevice /// </summary> /// <returns></returns> unsafe public int Deactivate() { return(MobileDevice.AMDeviceDeactivate(iDeviceHandle)); }
/// <summary> /// Activates the device with a WildCard ticket /// </summary> /// <param name="wildcard_ticket"></param> /// <returns></returns> unsafe public int Activate(IntPtr wildcard_ticket) { return(MobileDevice.AMDeviceActivate(iDeviceHandle, wildcard_ticket)); }
unsafe public IntPtr CopyDictionary(string cfstring) { return(MobileDevice.AMDeviceCopyValue_IntPtr(iDeviceHandle, 0, new CFString(cfstring))); }
/// <summary> /// Any type of CoreFoundation object from the iDevice would be returned as a string /// </summary> /// <param name="cfstring"></param> /// <returns></returns> unsafe public string CopyValue(string cfstring) { return(MobileDevice.AMDeviceCopyValue(iDeviceHandle, cfstring)); }