/// <summary> /// rename / move a file /// </summary> /// <param name="sourceFileName">source pathname</param> /// <param name="destinationFileName">destination pathname</param> /// <param name="allowOverwrite">set to true to overwrite an existing destination file</param> public void FileRename(string sourceFileName, string destinationFileName, bool allowOverwrite) { if (MtpPath.IsMtpPath(sourceFileName) || MtpPath.IsMtpPath(destinationFileName)) { throw new NotImplementedException(); } _fileUtilities.FileRename(sourceFileName, destinationFileName, allowOverwrite); }
/// <summary> /// create an abstract directory object /// </summary> /// <param name="path">full path to the directory</param> /// <returns>an abstrcat object</returns> public IDirectoryInfo GetDirectoryInfo(string path) { if (MtpPath.IsMtpPath(path)) { return(new MtpDirectoryInfoProvider(_deviceManager).GetDirectoryInfo(path)); } return(new SystemDirectoryInfoProvider().GetDirectoryInfo(path)); }
/// <summary> /// create an abstract drive info object /// </summary> /// <param name="path">name of the drive/path</param> /// <returns>an abstrcat object</returns> public IDriveInfo GetDriveInfoForPath(string path) { if (MtpPath.IsMtpPath(path)) { return(new MtpDriveInfoProvider(_deviceManager).GetDriveInfoForPath(path)); } return(new SystemDriveInfoProvider().GetDriveInfoForPath(path)); }
private Stream OpenReadStream(string filename) { var pathInfo = MtpPath.GetPathInfo(filename); if (pathInfo.IsMtpPath) { return(GetDevice(pathInfo).OpenRead(pathInfo.RelativePathOnDevice)); } return(_streamHelper.OpenRead(filename)); }
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)); }
/// <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> /// 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); }
/// <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> /// copy a file - the containing folder will be created if it does not exist /// </summary> /// <param name="sourceFileName">source pathname</param> /// <param name="destinationFileName">destination pathname</param> /// <param name="allowOverwrite">set to true to overwrite an existing file</param> public void FileCopy(string sourceFileName, string destinationFileName, bool allowOverwrite) { if (!MtpPath.IsMtpPath(sourceFileName) && !MtpPath.IsMtpPath(destinationFileName)) { _fileUtilities.FileCopy(sourceFileName, destinationFileName, allowOverwrite); } else { var sourceFileInfo = _fileInfoProvider.GetFileInfo(sourceFileName); using (var sourceStream = OpenReadStream(sourceFileName)) { using (var destinationStream = OpenWriteStream(destinationFileName, sourceFileInfo.Length, allowOverwrite)) { _streamHelper.Copy(sourceStream, destinationStream); } } } }
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); }
public void MakeFullPathShouldReturnOriginalPath() { Assert.That(MtpPath.MakeFullPath(_pathToTest), Is.EqualTo(@"mtp:\my device\path")); }
public void StripMtpPrefixShouldRemoveMtpPrefix() { Assert.That(MtpPath.StripMtpPrefix(_pathToTest), Is.EqualTo(@"my device\path")); }
public void IsMtpPathShouldReturnTrue() { Assert.That(MtpPath.IsMtpPath(_pathToTest), Is.True); }
public void MakeFullPathShouldAddMtpPrefix() { Assert.That(MtpPath.MakeFullPath(_pathToTest), Is.EqualTo(@"MTP:\abc\def\ghi")); }
public void StripMtpPrefixShouldReturnOriginalPath() { Assert.That(MtpPath.StripMtpPrefix(_pathToTest), Is.EqualTo(_pathToTest)); }
///<summary> /// Returns the absolute path for the supplied path, using the current directory and volume if path is not already an absolute path. ///</summary> ///<param name="path">The file or directory for which to obtain absolute path information</param> ///<returns>A string containing the fully qualified location of path, such as "C:\MyFile.txt".</returns> public string GetFullPath(string path) { //If the path is an MTP path it is by definition already an absolute path return(MtpPath.IsMtpPath(path) ? path : Path.GetFullPath(path)); }
public void IsMtpPathShouldReturnFalse() { Assert.That(MtpPath.IsMtpPath(_pathToTest), Is.False); }