示例#1
0
        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));
        }
示例#2
0
        private Stream OpenReadStream(string filename)
        {
            var pathInfo = MtpPath.GetPathInfo(filename);

            if (pathInfo.IsMtpPath)
            {
                return(GetDevice(pathInfo).OpenRead(pathInfo.RelativePathOnDevice));
            }

            return(_streamHelper.OpenRead(filename));
        }
示例#3
0
        /// <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)));
        }
示例#5
0
        /// <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);
 }