private Boolean CopyItemFromDevice(String savePath, String fromPath, String item) { Boolean continueCopy = true; Boolean dontCopyMusic = true; Boolean dontCopyPhotos = true; String itemPath = fromPath + "/" + item; if (dontCopyMusic && ( fromPath.Equals("//private/var/root/Media/iTunes_Control") || fromPath.Equals("//var/root/Media/iTunes_Control"))) { return(true); } if (dontCopyPhotos && fromPath.Equals("//private/var/root/Media/DCIM")) { return(true); } if (!item.Equals(".") && !item.Equals("..")) { if (myPhone.IsDirectory(itemPath)) { String newPath = savePath + "\\" + item; Directory.CreateDirectory(newPath); String[] items = myPhone.GetFiles(itemPath); for (Int32 i = 0; i < items.Length; i++) { continueCopy = CopyItemFromDevice(newPath, itemPath, items[i]); if (!continueCopy) { break; } } } else { String sourcePath = fromPath + "/" + item; String destPath = savePath + "\\" + item.Replace("*", "^").Replace(":", "!"); iPhone.FileTypes fileType = myPhone.FileType(sourcePath); if (fileType == iPhone.FileTypes.Folder || fileType == iPhone.FileTypes.File) { labelStatus.Text = "Copying: " + sourcePath; if (item.Contains(".plist")) { DecodePListStream(sourcePath, destPath); } Byte[] fileBuffer = new Byte[1024]; Int32 length; Int32 bytesSoFar = 0; toolStripProgressBar1.Visible = true; toolStripProgressBar1.Minimum = 0; using (Stream inStream = iPhoneFile.OpenRead(myPhone, sourcePath)) { toolStripProgressBar1.Maximum = (Int32)inStream.Length; using (Stream outStream = File.OpenWrite(destPath)) { try { while ((length = inStream.Read(fileBuffer, 0, fileBuffer.Length)) > 0 && !cancelCopy) { bytesSoFar += length; toolStripProgressBar1.Value = bytesSoFar; Application.DoEvents(); if (cancelCopy) { if (MessageBox.Show("Cancel Copying?", "iPhoneList Message", MessageBoxButtons.YesNo) == DialogResult.No) { cancelCopy = false; } } if (!cancelCopy) { outStream.Write(fileBuffer, 0, length); } } } catch (IOException err) { DialogResult retVal = MessageBox.Show("iPhone stopped responding on file: " + sourcePath + ".\n Attempt to Continue?", err.Message, MessageBoxButtons.YesNo); if (retVal == DialogResult.No) { continueCopy = false; } } } } toolStripProgressBar1.Visible = false; } else { labelStatus.Text = "Skipping non-File: " + sourcePath; } Application.DoEvents(); } } return(continueCopy); }
public ItemProperty FindItem(String fullPath) { /*Have to account for these: * FileName, * Extension, * FullPath, * FileType, * HeaderBytes, * HeaderString, * ExtHeadBytes, // Extension First, then Header * ExtHeadString */ /* I need to lay out the approach here... * When we read a folder, we get back a list of all the folder entries, * including the current / parent folder pointers. * * I could break them up into FindFile / Folder / Device, but * I may use the same criteria to locate them * What's interesting with this particular approach is that the FIND * function doesn't specify what to look for. We literally scan the rules * and stop with the first MATCH. * * Now since we store the FileType of each ItemProperty entry, we need to * perform the first match on that attribute of the passed file. * So FileType is the first piece of information we need. */ // Set variables to store whether we've already gathered a particular piece of info String fileName = null; Boolean _fileName = false; String extension = null; Boolean _extension = false; ItemProperty returnItem = null; iPhone.FileTypes fileType = phone.FileType(fullPath); foreach (ItemProperty item in items) { if (fileType == item.Type) { switch (item.Identifier) { case TypeIdentifier.FileType: returnItem = item; break; case TypeIdentifier.FullPath: if (item.FileInfoText.Equals(fullPath.ToLower())) { returnItem = item; } break; case TypeIdentifier.FileName: if (!_fileName) { fileName = fullPath.Substring(fullPath.LastIndexOf("/") + 1).ToLower(); _fileName = true; } if (item.FileInfoText.Equals(fileName)) { returnItem = item; } break; case TypeIdentifier.Extension: if (!_extension) { extension = TextString.GetFileExtension(fullPath); _extension = true; } if (extension == item.FileInfoText) { returnItem = item; } break; case TypeIdentifier.ExtHeadString: case TypeIdentifier.ExtHeadBytes: if (!_extension) { extension = TextString.GetFileExtension(fullPath); _extension = true; } if (extension == item.FileInfoText) { Byte[] buffer = GetHeaderBytes(fullPath, item.ByteOffset, item.Header.Length); if (buffer == item.Header) { returnItem = item; } } break; case TypeIdentifier.HeaderBytes: case TypeIdentifier.HeaderString: Byte[] fileBuffer = GetHeaderBytes(fullPath, item.ByteOffset, item.Header.Length); if (fileBuffer == item.Header) { returnItem = item; } break; } } if (returnItem != null) { break; } } return(returnItem); }