Exemple #1
0
        public static XboxFileInfo CopyTo(this FileInfo fileInfo, XboxPath xboxPath, XboxConsole console, IProgress <XboxFileTransferMetric> metrics)
        {
            if (fileInfo == null)
            {
                throw new ArgumentNullException("fileInfo");
            }

            if (xboxPath == null)
            {
                throw new ArgumentNullException("xboxPath");
            }

            if (console == null)
            {
                throw new ArgumentNullException("console");
            }

            if (!fileInfo.Exists)
            {
                throw new FileNotFoundException("Cannot copy a file that does not exist", fileInfo.FullName);
            }

            console.Adapter.SendFile(console.SystemIpAddressAndSessionKeyCombined, fileInfo.FullName, xboxPath, metrics);

            return(new XboxFileInfo(xboxPath, console));
        }
        /// <summary>
        /// Determines whether a file or directory exists on an Xbox.
        /// </summary>
        /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param>
        /// <param name="path">The file or directory to look for.</param>
        /// <param name="additionalExistsPredicate">The optional additional logic to determine existence based on XboxFileSystemInfoDefinition.</param>
        /// <param name="consoleAdapter">The Xbox console to search on.</param>
        /// <returns>A value indicating whether the file or directory exists on the console or not.</returns>
        internal static bool ExistsImpl(string systemIpAddress, XboxPath path, Func <XboxFileSystemInfoDefinition, bool> additionalExistsPredicate, XboxConsoleAdapterBase consoleAdapter)
        {
            XboxFileSystemInfoDefinition definition;

            try
            {
                definition = consoleAdapter.GetFileSystemInfoDefinition(systemIpAddress, path);
            }
            catch (FileNotFoundException)
            {
                return(false);
            }
            catch (UnauthorizedAccessException)
            {
                // Following the same approach as in .NET, returning false without throwing an exception in case of insufficient permissions:
                // http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx
                return(false);
            }

            if (additionalExistsPredicate != null)
            {
                return(additionalExistsPredicate(definition));
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Copies a directory from a PC to an Xbox.
        /// </summary>
        /// <param name="directoryInfo">The directory info object pointing to the PC directory to copy.</param>
        /// <param name="xboxPath">The path on the Xbox to copy the directory contents to.</param>
        /// <param name="console">The Xbox console to copy the contents to.</param>
        /// <param name="metrics">The progress handler that the calling app uses to receive progress updates about metrics. This may be null.</param>
        /// <returns>An XboxDirectoryInfo object pointing to the newly copied directory.</returns>
        public static XboxDirectoryInfo CopyTo(this DirectoryInfo directoryInfo, XboxPath xboxPath, XboxConsole console, IProgress <XboxFileTransferMetric> metrics)
        {
            if (directoryInfo == null)
            {
                throw new ArgumentNullException("directoryInfo");
            }

            if (xboxPath == null)
            {
                throw new ArgumentNullException("xboxPath");
            }

            if (console == null)
            {
                throw new ArgumentNullException("console");
            }

            if (!XboxDirectory.Exists(xboxPath, console))
            {
                XboxDirectory.Create(xboxPath, console);
            }

            var directorySize = directoryInfo.EnumerateFiles("*", SearchOption.AllDirectories).Sum(x => x.Length);

            return(directoryInfo.CopyToRecursive(xboxPath, console, directorySize, metrics));
        }
        /// <summary>
        /// Investigates whether a directory exists on an Xbox.
        /// </summary>
        /// <param name="directory">The directory to look for.</param>
        /// <param name="console">The Xbox Console to look on.</param>
        /// <returns>A value indicating whether the directory exists on the console or not.</returns>
        public static bool Exists(XboxPath directory, XboxConsole console)
        {
            if (console == null)
            {
                throw new ArgumentNullException("console");
            }

            return(XboxDirectoryInfo.ExistsImpl(console.SystemIpAddressAndSessionKeyCombined, directory, console.Adapter));
        }
        /// <summary>
        /// Deletes the directory and, if argument recursive is true, all of its contents.
        /// </summary>
        /// <param name="recursive">Value indicating whether or not to try delete contents.</param>
        /// <exception cref="System.IO.IOException">Thrown if this object represents the root of the drive.</exception>
        public void Delete(bool recursive)
        {
            if (XboxPath.IsRoot(this.FullName))
            {
                throw new IOException("Cannot delete the drive root");
            }

            if (this.Exists)
            {
                this.Console.Adapter.DeleteDirectory(this.Console.SystemIpAddressAndSessionKeyCombined, this.XboxPath, recursive);
            }

            this.Refresh();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="XboxFileSystemInfo"/> class.
        /// </summary>
        /// <param name="xboxPath">The Xbox path to the file system object.</param>
        /// <param name="console">The console on which the file system object resides.</param>
        /// <exception cref="System.ArgumentException">Thrown if given an invalid path.</exception>
        protected XboxFileSystemInfo(XboxPath xboxPath, XboxConsole console)
            : base(console)
        {
            if (xboxPath == null)
            {
                throw new ArgumentNullException("xboxPath");
            }

            if (!xboxPath.IsValid)
            {
                throw new ArgumentException("Invalid Xbox path.", "xboxPath");
            }

            this.XboxPath = xboxPath;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="XboxFileSystemInfo"/> class.
        /// </summary>
        /// <param name="path">The path to the file system object.</param>
        /// <param name="operatingSystem">The operating system on which the file system object resides.</param>
        /// <param name="console">The console on which the file system object resides.</param>
        /// <exception cref="System.ArgumentException">Thrown if given an invalid path.</exception>
        protected XboxFileSystemInfo(string path, XboxOperatingSystem operatingSystem, XboxConsole console)
            : base(console)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            if (!XboxPath.IsValidPath(path))
            {
                throw new ArgumentException("Invalid path.", "path");
            }

            this.XboxPath = new XboxPath(path, operatingSystem);
        }
        /// <summary>
        /// Copies a directory from an Xbox console to a PC.
        /// </summary>
        /// <param name="sourceDirectory">The directory to copy from.</param>
        /// <param name="destinationDirectory">The directory to copy to. </param>
        /// <param name="console">The Xbox to copy from.</param>
        /// <param name="metrics">The progress handler that the calling app uses to receive progress updates about metrics. This may be null.</param>
        /// <exception cref="Microsoft.Internal.GamesTest.Xbox.XboxConsoleFeatureNotSupportedException">Thrown if the source directory is not a path with an Xbox origin.</exception>
        public static void Copy(XboxPath sourceDirectory, string destinationDirectory, XboxConsole console, IProgress <XboxFileTransferMetric> metrics)
        {
            if (sourceDirectory == null)
            {
                throw new ArgumentNullException("sourceDirectory");
            }

            if (XboxPath.HasXboxOrigin(sourceDirectory.FullName))
            {
                new XboxDirectoryInfo(sourceDirectory, console).Copy(destinationDirectory, metrics);
            }
            else
            {
                throw new XboxConsoleFeatureNotSupportedException("No Xbox path specified.  This method cannot be used for PC to PC transfers.");
            }
        }
        /// <summary>
        /// Copies a file from an Xbox console to a PC.
        /// </summary>
        /// <param name="sourceFile">The file to copy from.</param>
        /// <param name="destinationFile">The file to copy to. </param>
        /// <param name="console">The Xbox to copy from.</param>
        /// <param name="metrics">The progress handler that the calling app uses to receive progress updates about metrics. This may be null.</param>
        /// <exception cref="Microsoft.Internal.GamesTest.Xbox.XboxConsoleFeatureNotSupportedException">Thrown if the source file is not a path with an Xbox origin.</exception>
        public static void Copy(XboxPath sourceFile, string destinationFile, XboxConsole console, IProgress <XboxFileTransferMetric> metrics)
        {
            if (sourceFile == null)
            {
                throw new ArgumentNullException("sourceFile");
            }

            if (XboxPath.HasXboxOrigin(sourceFile.FullName))
            {
                new XboxFileInfo(sourceFile, console).Copy(destinationFile, metrics);
            }
            else
            {
                throw new XboxConsoleFeatureNotSupportedException("The source XboxPath object does not contain a valid Xbox file path.");
            }
        }
        /// <summary>
        /// Copies this directory to the specified local path.
        /// </summary>
        /// <param name="localPath">The path on the local machine to copy to.</param>
        /// <param name="recursive">Recursively copies all subdirectories if set to <c>true</c>.</param>
        /// <param name="metrics">The progress handler that the calling app uses to receive progress updates about metrics. This may be null.</param>
        /// <exception cref="System.IO.DirectoryNotFoundException">Thrown if the source directory does not exist at the path specified.</exception>
        /// <exception cref="Microsoft.Internal.GamesTest.Xbox.XboxConsoleFeatureNotSupportedException">Thrown if the localPath does not have an Xbox origin.</exception>
        public void Copy(string localPath, bool recursive, IProgress <XboxFileTransferMetric> metrics)
        {
            if (!this.Exists)
            {
                throw new DirectoryNotFoundException("Source directory does not exist at the path specified.");
            }

            if (XboxPath.HasXboxOrigin(localPath))
            {
                throw new XboxConsoleFeatureNotSupportedException("Not able to copy from Xbox to Xbox.");
            }

            if (!Directory.Exists(localPath))
            {
                Directory.CreateDirectory(localPath);
            }

            this.Console.Adapter.ReceiveDirectory(this.Console.SystemIpAddressAndSessionKeyCombined, this.XboxPath, localPath, recursive, metrics);
        }
Exemple #11
0
        /// <summary>
        /// Combines two XboxPath objects.
        /// </summary>
        /// <param name="path1">The first path.</param>
        /// <param name="path2">The second path.</param>
        /// <returns> An XboxPath containing the combined paths. If path2 contains an absolute path, this method returns path2.</returns>
        public static XboxPath Combine(XboxPath path1, XboxPath path2)
        {
            if (path1 == null)
            {
                throw new ArgumentNullException("path1");
            }

            if (path2 == null)
            {
                throw new ArgumentNullException("path2");
            }

            if (path1.OperatingSystem != path2.OperatingSystem)
            {
                throw new ArgumentException("Both paths must target the same operating system.");
            }

            string resultPath = XboxPath.Combine(path1.FullName, path2.FullName);

            return(new XboxPath(resultPath, path1.OperatingSystem));
        }
 /// <summary>
 /// Determines whether a directory exists on an Xbox.
 /// </summary>
 /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param>
 /// <param name="path">The directory to look for.</param>
 /// <param name="consoleAdapter">The Xbox console to search on.</param>
 /// <returns>A value indicating whether the directory exists on the console or not.</returns>
 internal static bool ExistsImpl(string systemIpAddress, XboxPath path, XboxConsoleAdapterBase consoleAdapter)
 {
     return(XboxFileSystemInfo.ExistsImpl(systemIpAddress, path, xboxFileSystemInfoDefinition => xboxFileSystemInfoDefinition.IsDirectory, consoleAdapter));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="XboxDirectoryInfo"/> class.
 /// </summary>
 /// <param name="xboxPath">The Xbox path to the directory.</param>
 /// <param name="console">The console on which the directory resides.</param>
 public XboxDirectoryInfo(XboxPath xboxPath, XboxConsole console)
     : base(xboxPath, console)
 {
 }
Exemple #14
0
 /// <summary>
 /// Copies a file from an Xbox console to a PC.
 /// </summary>
 /// <param name="sourceFile">The file to copy from.</param>
 /// <param name="destinationFile">The file to copy to. </param>
 /// <param name="console">The Xbox to copy from.</param>
 /// <exception cref="Microsoft.Internal.GamesTest.Xbox.XboxConsoleFeatureNotSupportedException">Thrown if the source file is not a path with an Xbox origin.</exception>
 public static void Copy(XboxPath sourceFile, string destinationFile, XboxConsole console)
 {
     Copy(sourceFile, destinationFile, console, null);
 }
Exemple #15
0
 /// <summary>
 /// Moves a file from an Xbox console to a PC.
 /// </summary>
 /// <param name="sourceFile">The file to move from.</param>
 /// <param name="destinationFile">The file to move to.</param>
 /// <param name="console">The console to move the file from.</param>
 public static void Move(XboxPath sourceFile, string destinationFile, XboxConsole console)
 {
     Copy(sourceFile, destinationFile, console);
     new XboxFileInfo(sourceFile, console).Delete();
 }
Exemple #16
0
 /// <summary>
 /// Deletes a file from an Xbox.
 /// </summary>
 /// <param name="file">The file to delete from the Xbox.</param>
 /// <param name="console">The Xbox that contains the file to delete.</param>
 public static void Delete(XboxPath file, XboxConsole console)
 {
     new XboxFileInfo(file, console).Delete();
 }
 /// <summary>
 /// Creates a directory on an Xbox.
 /// </summary>
 /// <param name="directory">The directory to create.</param>
 /// <param name="console">The Xbox console to create the directory on.</param>
 public static void Create(XboxPath directory, XboxConsole console)
 {
     new XboxDirectoryInfo(directory, console).Create();
 }
 /// <summary>
 /// Moves a directory from an Xbox console to a PC.
 /// </summary>
 /// <param name="sourceDirectory">The directory to move.</param>
 /// <param name="destinationDirectory">The directory to move to.</param>
 /// <param name="console">The console to move the directory from.</param>
 public static void Move(XboxPath sourceDirectory, string destinationDirectory, XboxConsole console)
 {
     Copy(sourceDirectory, destinationDirectory, console);
     new XboxDirectoryInfo(sourceDirectory, console).Delete(true);
 }
 /// <summary>
 /// Copies a directory from an Xbox console to a PC.
 /// </summary>
 /// <param name="sourceDirectory">The directory to copy from.</param>
 /// <param name="destinationDirectory">The directory to copy to. </param>
 /// <param name="console">The Xbox to copy from.</param>
 /// <exception cref="Microsoft.Internal.GamesTest.Xbox.XboxConsoleFeatureNotSupportedException">Thrown if the source directory is not a path with an Xbox origin.</exception>
 public static void Copy(XboxPath sourceDirectory, string destinationDirectory, XboxConsole console)
 {
     Copy(sourceDirectory, destinationDirectory, console, null);
 }
Exemple #20
0
 public static XboxFileInfo CopyTo(this FileInfo fileInfo, XboxPath xboxPath, XboxConsole console)
 {
     return(CopyTo(fileInfo, xboxPath, console, null));
 }
 /// <summary>
 /// Deletes a directory from an Xbox.
 /// </summary>
 /// <param name="directory">The directory to delete on the Xbox.</param>
 /// <param name="recursive">Whether or not to delete the contents inside the directory.</param>
 /// <param name="console">The Xbox that contains the directory.</param>
 public static void Delete(XboxPath directory, bool recursive, XboxConsole console)
 {
     new XboxDirectoryInfo(directory, console).Delete(recursive);
 }
Exemple #22
0
        private static XboxDirectoryInfo CopyToRecursive(this DirectoryInfo directoryInfo, XboxPath xboxPath, XboxConsole console, long totalSizeOfFolder, IProgress <XboxFileTransferMetric> metrics)
        {
            double totalTransferred = 0;
            double tempTransferred  = 0;

            IProgress <XboxFileTransferMetric> newMetrics = null;

            if (metrics != null)
            {
                newMetrics = new Progress <XboxFileTransferMetric>((x) =>
                {
                    tempTransferred = x.TotalBytesTransferred;

                    metrics.Report(new XboxFileTransferMetric(x.SourceFilePath, x.TargetFilePath, x.FileSizeInBytes, x.FileBytesTransferred, totalSizeOfFolder, totalTransferred + tempTransferred));
                });
            }

            var directories = directoryInfo.GetDirectories();

            foreach (var directory in directories)
            {
                directory.CopyToRecursive(new XboxPath(Path.Combine(xboxPath.FullName, directory.Name), xboxPath.OperatingSystem), console, totalSizeOfFolder, newMetrics);

                totalTransferred += tempTransferred;
                tempTransferred   = 0;
            }

            var files = directoryInfo.GetFiles();

            foreach (var file in files)
            {
                XboxFile.Copy(file.FullName, new XboxPath(Path.Combine(xboxPath.FullName, file.Name), xboxPath.OperatingSystem), console, newMetrics);
                totalTransferred += tempTransferred;
                tempTransferred   = 0;
            }

            return(new XboxDirectoryInfo(xboxPath, console));
        }
Exemple #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XboxFileInfo"/> class.
 /// </summary>
 /// <param name="xboxPath">The Xbox path to the file on the Xbox.</param>
 /// <param name="console">The console on which the directory resides.</param>
 public XboxFileInfo(XboxPath xboxPath, XboxConsole console)
     : base(xboxPath, console)
 {
 }
Exemple #24
0
 /// <summary>
 /// Copies a directory from a PC to an Xbox.
 /// </summary>
 /// <param name="directoryInfo">The directory info object pointing to the PC directory to copy.</param>
 /// <param name="xboxPath">The path on the Xbox to copy the directory contents to.</param>
 /// <param name="console">The Xbox console to copy the contents to.</param>
 /// <returns>An XboxDirectoryInfo object pointing to the newly copied directory.</returns>
 public static XboxDirectoryInfo CopyTo(this DirectoryInfo directoryInfo, XboxPath xboxPath, XboxConsole console)
 {
     return(CopyTo(directoryInfo, xboxPath, console, null));
 }