/// <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));
        }
Example #2
0
        /// <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 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)));
        }
Example #5
0
        /// <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);
                    }
                }
            }
        }
        ///<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 IsMtpPathShouldReturnTrue()
 {
     Assert.That(MtpPath.IsMtpPath(_pathToTest), Is.True);
 }
Example #8
0
 public void IsMtpPathShouldReturnFalse()
 {
     Assert.That(MtpPath.IsMtpPath(_pathToTest), Is.False);
 }