private Stream OpenWriteStream(string filename, long length, bool allowOverwrite) { var pathInfo = MtpPath.GetPathInfo(filename); if (pathInfo.IsMtpPath) { return(GetDevice(pathInfo).OpenWrite(pathInfo.RelativePathOnDevice, length, allowOverwrite)); } return(_streamHelper.OpenWrite(filename, allowOverwrite)); }
private Stream OpenReadStream(string filename) { var pathInfo = MtpPath.GetPathInfo(filename); if (pathInfo.IsMtpPath) { return(GetDevice(pathInfo).OpenRead(pathInfo.RelativePathOnDevice)); } return(_streamHelper.OpenRead(filename)); }
/// <summary> /// delete a file /// </summary> /// <param name="path">pathname of the file to delete</param> public void FileDelete(string path) { var pathInfo = MtpPath.GetPathInfo(path); if (!pathInfo.IsMtpPath) { _fileUtilities.FileDelete(path); return; } var device = GetDevice(pathInfo); device.Delete(pathInfo.RelativePathOnDevice); }
/// <summary> /// create an abstract file info object /// </summary> /// <param name="path">full path to the file</param> /// <returns>the file info</returns> public IFileInfo GetFileInfo(string path) { if (MtpPath.IsMtpPath(path)) { var pathInfo = MtpPath.GetPathInfo(path); var device = _deviceManager.GetDevice(pathInfo.DeviceName); if (device == null) { throw new FileNotFoundException(String.Format("Device [{0}] not found", pathInfo.DeviceName)); } return(new FileInfo(device, pathInfo.RelativePathOnDevice)); } return(new SystemFileInfo(new System.IO.FileInfo(path))); }
/// <summary> /// check if a file exists /// </summary> /// <param name="path">pathname to check</param> /// <returns>true if the file exists</returns> public bool FileExists(string path) { var pathInfo = MtpPath.GetPathInfo(path); if (!pathInfo.IsMtpPath) { return(_fileUtilities.FileExists(path)); } var device = _deviceManager.GetDevice(pathInfo.DeviceName); if (device == null) { return(false); } return(device.GetObjectFromPath(pathInfo.RelativePathOnDevice) != null); }
public void GetMtpPathInfoShouldCorrectlySetPath() { Assert.That(MtpPath.GetPathInfo(_pathToTest).RelativePathOnDevice, Is.EqualTo("path")); }
public void GetMtpPathInfoShouldCorrectlySetDeviceName() { Assert.That(MtpPath.GetPathInfo(_pathToTest).DeviceName, Is.EqualTo("my device")); }
public void GetMtpPathInfoShouldSetIsMtpPathToTrue() { Assert.That(MtpPath.GetPathInfo(_pathToTest).IsMtpPath, Is.True); }