public void TestXboxPathCombineXboxPathObjects() { this.RunDataDrivenTest( this.PathStringsForCombine.Select( pathStrings => new TestInputData <Tuple <XboxPath, XboxPath>, XboxPath>(new Tuple <XboxPath, XboxPath>(new XboxPath(pathStrings.Item1.Item1, XboxOperatingSystem.System), new XboxPath(pathStrings.Item1.Item2, XboxOperatingSystem.System)), new XboxPath(pathStrings.Item2, XboxOperatingSystem.System), pathStrings.ExpectedException)), (input) => XboxPath.Combine(input.Item1, input.Item2), (expected, actual) => expected.FullName == actual.FullName && expected.OperatingSystem == actual.OperatingSystem); }
/// <summary> /// Remove the given directory from the Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="directoryToDelete">The Xbox directory to remove.</param> /// <param name="recursive">True to recursivly delete the directory, its content and all of its sub-directories.</param> protected override void DeleteDirectoryImpl(string systemIpAddress, XboxPath directoryToDelete, bool recursive) { if (directoryToDelete == null) { throw new ArgumentNullException("directoryToDelete"); } this.XboxXdk.RemoveDirectory(systemIpAddress, directoryToDelete.FullName, directoryToDelete.OperatingSystem, recursive); }
/// <summary> /// Deletes a file from an Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxFilePath">The complete path to the file to be deleted.</param> protected override void DeleteFileImpl(string systemIpAddress, XboxPath xboxFilePath) { if (xboxFilePath == null) { throw new ArgumentNullException("xboxFilePath"); } this.XboxXdk.DeleteFiles(systemIpAddress, xboxFilePath.FullName, xboxFilePath.OperatingSystem, 0); }
/// <summary> /// Creates a directory on an Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxDirectoryPath">The complete path to the directory to be created.</param> protected override void CreateDirectoryImpl(string systemIpAddress, XboxPath xboxDirectoryPath) { if (xboxDirectoryPath == null) { throw new ArgumentNullException("xboxDirectoryPath"); } this.XboxXdk.CreateDirectory(systemIpAddress, xboxDirectoryPath.FullName, xboxDirectoryPath.OperatingSystem); }
public void TestConstructorInitializesProperties() { const string FakeFilePath = "ContentNotImportant"; const XboxOperatingSystem OperatingSystem = XboxOperatingSystem.System; XboxPath path = new XboxPath(FakeFilePath, OperatingSystem); Assert.AreEqual(FakeFilePath, path.FullName, "The constructor for the XboxPath class did not initialize the FilePath property correctly."); Assert.AreEqual(OperatingSystem, path.OperatingSystem, "The constructor for the XboxPath class did not initialize the OperatingSystem property correctly."); }
/// <summary> /// Registers a package located on the TitleScratch drive. /// </summary> /// <param name="scratchPath">Relative path to the package on the TitleScratch drive, omitting the root specification.</param> /// <returns>An XboxPackage object that allows you to manipulate the package.</returns> public XboxPackage RegisterPackage(XboxPath scratchPath) { this.ThrowIfDisposed(); if (scratchPath == null) { throw new ArgumentNullException("scratchPath"); } return(new XboxPackage(this.Adapter.RegisterPackage(this.SystemIpAddressAndSessionKeyCombined, scratchPath.FullName), this)); }
/// <summary> /// Gets the size of a folder on the console. /// </summary> /// <param name="systemIpAddress">The ip of the console.</param> /// <param name="sourceDirectory">The directory to the size.</param> /// <returns>The size in bytes of the folder.</returns> private ulong GetDirectorySizeRecursive(string systemIpAddress, XboxPath sourceDirectory) { var folder = this.GetDirectoryContents(systemIpAddress, sourceDirectory); var sum = unchecked ((ulong)folder.Sum(f => unchecked ((long)f.FileSize))); foreach (var dir in folder.Where(f => f.IsDirectory)) { sum += this.GetDirectorySizeRecursive(systemIpAddress, dir.Path); } return(sum); }
/// <summary> /// Copies a file from an Xbox to a PC. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="sourceFile">The source file to be copied.</param> /// <param name="destinationFilePath">The destination of the file on the PC.</param> /// <param name="metrics">The progress handler that the calling app uses to receive progress updates about metrics. This may be null.</param> protected override void ReceiveFileImpl(string systemIpAddress, XboxPath sourceFile, string destinationFilePath, IProgress <XboxFileTransferMetric> metrics) { if (sourceFile == null) { throw new ArgumentNullException("sourceFile"); } if (string.IsNullOrWhiteSpace(destinationFilePath)) { throw new ArgumentNullException("destinationFilePath"); } this.XboxXdk.CopyFiles(systemIpAddress, sourceFile.FullName, destinationFilePath, sourceFile.OperatingSystem, 0, metrics); }
/// <summary> /// Remove the given directory from the Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="directoryToDelete">The Xbox directory to remove.</param> /// <param name="recurisve">True to recursivly delete the directory, its content and all of its sub-directories.</param> public void DeleteDirectory(string systemIpAddress, XboxPath directoryToDelete, bool recurisve) { this.ThrowIfDisposed(); this.ThrowIfInvalidSystemIpAddress(systemIpAddress); if (directoryToDelete == null) { throw new ArgumentNullException("directoryToDelete"); } this.PerformXdkAction( systemIpAddress, () => this.DeleteDirectoryImpl(systemIpAddress, directoryToDelete, recurisve), string.Format(CultureInfo.InvariantCulture, "Failed to remove directory '{0}'", directoryToDelete.FullName)); }
/// <summary> /// Creates a directory on an Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxDirectoryPath">The complete path to the directory to be created.</param> public void CreateDirectory(string systemIpAddress, XboxPath xboxDirectoryPath) { this.ThrowIfDisposed(); this.ThrowIfInvalidSystemIpAddress(systemIpAddress); if (xboxDirectoryPath == null) { throw new ArgumentNullException("xboxDirectoryPath"); } this.PerformXdkAction( systemIpAddress, () => this.CreateDirectoryImpl(systemIpAddress, xboxDirectoryPath), string.Format(CultureInfo.InvariantCulture, "Failed to create directory '{0}'", xboxDirectoryPath.FullName)); }
/// <summary> /// Deletes a file from an Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxFilePath">The complete path to the file to be deleted.</param> public void DeleteFile(string systemIpAddress, XboxPath xboxFilePath) { this.ThrowIfDisposed(); this.ThrowIfInvalidSystemIpAddress(systemIpAddress); if (xboxFilePath == null) { throw new ArgumentNullException("xboxFilePath"); } this.PerformXdkAction( systemIpAddress, () => this.DeleteFileImpl(systemIpAddress, xboxFilePath), string.Format(CultureInfo.InvariantCulture, "Failed to delete file '{0}'", xboxFilePath.FullName)); }
/// <summary> /// Retrieves an XboxFileSystemInfoDefintion object for the specified file system object. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxFilePath">The file system object for a which an XboxFileSystemInfoDefinition object shall be retrieved.</param> /// <returns> /// An XboxFileSystemInfoDefinition object describing the file specified in the <paramref name="xboxFilePath" /> parameter. /// </returns> protected override XboxFileSystemInfoDefinition GetFileSystemInfoDefinitionImpl(string systemIpAddress, XboxPath xboxFilePath) { if (xboxFilePath == null) { throw new ArgumentNullException("xboxFilePath"); } bool isRoot = XboxPath.IsRoot(xboxFilePath.FullName); string cleanedFilePath = null; // For disk roots we need cleanedFilePath to keep the trailing separator char to make a valid searchPattern for XboxXdk.FindFiles. if (!isRoot && (xboxFilePath.FullName.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase) || xboxFilePath.FullName.EndsWith(Path.AltDirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase))) { cleanedFilePath = xboxFilePath.FullName.Substring(0, xboxFilePath.FullName.Length - 1); } else { cleanedFilePath = xboxFilePath.FullName; } // If the "xboxFilePath" parameter represents a directory and we just pass the string // straight to the "FindFiles" method, then it will return only the content of the directory. // By appending a "*" onto the end we can retrieve the directory itself. However, if the path ends with a trailing slash // then the search pattern won't work as expected, which is why the trailing slash is removed above. Additionally, if "xboxFilePath" // represents a file then this process works as well. string searchPattern = string.Format(CultureInfo.InvariantCulture, "{0}*", cleanedFilePath); var matchingFiles = this.XboxXdk.FindFiles(systemIpAddress, searchPattern, xboxFilePath.OperatingSystem, 0); if (isRoot) { // For disk roots we create a definition object as long as XboxXdk.FindFiles above didn't throw an exception (that means the disk root was traversed successfully) return(new XboxFileSystemInfoDefinition(0, FileAttributes.Directory, xboxFilePath.FullName, xboxFilePath.OperatingSystem, 0, 0, 0)); } else { XboxFileSystemInfoDefinition returnValue = matchingFiles.FirstOrDefault(f => f.Path.FullName.Equals(cleanedFilePath, StringComparison.OrdinalIgnoreCase)); if (returnValue == default(XboxFileSystemInfoDefinition)) { throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, "Unable to locate file on the Xbox's {0} operating system.", xboxFilePath.OperatingSystem), xboxFilePath.FullName); } else { return(returnValue); } } }
/// <summary> /// Recursively copies a directory from an Xbox to a PC. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxDirectory">The xbox directory to be copied.</param> /// <param name="destinationDirectory">The destination directory on the PC.</param> /// <param name="totalSizeOfFolder">The total size of the initial directory.</param> /// <param name="metrics">The progress handler that the calling app uses to receive progress updates about metrics. This may be null.</param> protected void ReceiveDirectoryRecursive(string systemIpAddress, XboxPath xboxDirectory, string destinationDirectory, ulong totalSizeOfFolder, IProgress <XboxFileTransferMetric> metrics) { if (!Directory.Exists(destinationDirectory)) { Directory.CreateDirectory(destinationDirectory); } try { 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 contents = this.GetDirectoryContents(systemIpAddress, xboxDirectory); if (contents.Any(f => !f.IsDirectory)) { this.XboxXdk.CopyFiles(systemIpAddress, xboxDirectory.FullName, destinationDirectory, xboxDirectory.OperatingSystem, 0, newMetrics); totalTransferred += tempTransferred; tempTransferred = 0; } foreach (XboxFileSystemInfoDefinition subdirectory in contents.Where(f => f.IsDirectory)) { string directoryName = Path.Combine(destinationDirectory, Path.GetFileName(subdirectory.Path.FullName)); this.ReceiveDirectoryRecursive(systemIpAddress, subdirectory.Path, directoryName, totalSizeOfFolder, newMetrics); totalTransferred += tempTransferred; tempTransferred = 0; } } catch (FileNotFoundException) { } }
/// <summary> /// Copies a directory from a PC to an Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="sourceDirectory">The path to the directory on the PC to be copied.</param> /// <param name="destinationDirectory">The destination directory on the Xbox.</param> /// <param name="recursive">True to recursive copy all files in the given directory and all of its subdirectories.</param> /// <param name="metrics">The progress handler that the calling app uses to receive progress updates about metrics. This may be null.</param> public void SendDirectory(string systemIpAddress, string sourceDirectory, XboxPath destinationDirectory, bool recursive, IProgress <XboxFileTransferMetric> metrics) { this.ThrowIfDisposed(); this.ThrowIfInvalidSystemIpAddress(systemIpAddress); if (string.IsNullOrWhiteSpace(sourceDirectory)) { throw new ArgumentNullException("sourceDirectory"); } if (destinationDirectory == null) { throw new ArgumentNullException("destinationDirectory"); } this.PerformXdkAction( systemIpAddress, () => this.SendDirectoryImpl(systemIpAddress, sourceDirectory, destinationDirectory, recursive, metrics), string.Format(CultureInfo.InvariantCulture, "Failed to copy directory. Source: '{0}' Destination: '{1}' Operating System: '{2}'", sourceDirectory, destinationDirectory.FullName, destinationDirectory.OperatingSystem.ToString())); }
/// <summary> /// Copies a file from an Xbox to a PC. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="sourceFile">The source file to be copied.</param> /// <param name="destinationFilePath">The destination of the file on the PC.</param> /// <param name="metrics">The progress handler that the calling app uses to receive progress updates about metrics. This may be null.</param> public void ReceiveFile(string systemIpAddress, XboxPath sourceFile, string destinationFilePath, IProgress <XboxFileTransferMetric> metrics) { this.ThrowIfDisposed(); this.ThrowIfInvalidSystemIpAddress(systemIpAddress); if (sourceFile == null) { throw new ArgumentNullException("sourceFile"); } if (string.IsNullOrWhiteSpace(destinationFilePath)) { throw new ArgumentNullException("destinationFilePath"); } this.PerformXdkAction( systemIpAddress, () => this.ReceiveFileImpl(systemIpAddress, sourceFile, destinationFilePath, metrics), string.Format(CultureInfo.InvariantCulture, "Failed to copy file. Source: '{0}' Operating System: '{1}' Destination: '{2}'", sourceFile.FullName, sourceFile.OperatingSystem.ToString(), destinationFilePath)); }
/// <summary> /// Copies a directory from the Xbox to a PC. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="sourceDirectory">The Xbox diretory to copy.</param> /// <param name="destinationDirectory">The path to the destination directory on the PC.</param> /// <param name="recursive">True to recurisve delete the content in the given directory and all of its subdirectories.</param> /// <param name="metrics">The progress handler that the calling app uses to receive progress updates about metrics. This may be null.</param> protected override void ReceiveDirectoryImpl(string systemIpAddress, XboxPath sourceDirectory, string destinationDirectory, bool recursive, IProgress <XboxFileTransferMetric> metrics) { if (sourceDirectory == null) { throw new ArgumentNullException("sourceDirectory"); } if (string.IsNullOrWhiteSpace(destinationDirectory)) { throw new ArgumentNullException("destinationDirectory"); } if (recursive) { ulong totalBytes = 0; if (metrics != null) { totalBytes = this.GetDirectorySizeRecursive(systemIpAddress, sourceDirectory); } // The January XDK will not copy empty directories, so we have to do it ourselves. this.ReceiveDirectoryRecursive(systemIpAddress, sourceDirectory, destinationDirectory, totalBytes, metrics); } else { try { var contents = this.GetDirectoryContents(systemIpAddress, sourceDirectory); if (contents.Any(f => !f.IsDirectory)) { this.XboxXdk.CopyFiles(systemIpAddress, sourceDirectory.FullName, destinationDirectory, sourceDirectory.OperatingSystem, 0, metrics); } } catch (FileNotFoundException) { // If the directory exists, but is empty then the XDK will throw a FileNotFoundException. } } }
/// <summary> /// Creates a directory on an Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxDirectoryPath">The complete path to the directory to be created.</param> protected virtual void CreateDirectoryImpl(string systemIpAddress, XboxPath xboxDirectoryPath) { throw new XboxConsoleFeatureNotSupportedException(NotSupportedMessage); }
/// <summary> /// Retrieves an XboxFileSystemInfoDefintion object for the specified file system object. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxFilePath">The file system object for a which an XboxFileSystemInfoDefinition object shall be retrieved.</param> /// <returns>An XboxFileSystemInfoDefinition object describing the file specified in the <paramref name="xboxFilePath"/> parameter.</returns> protected virtual XboxFileSystemInfoDefinition GetFileSystemInfoDefinitionImpl(string systemIpAddress, XboxPath xboxFilePath) { throw new XboxConsoleFeatureNotSupportedException(NotSupportedMessage); }
/// <summary> /// Retrieves the contents of a directory on an Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxDirectory">The complete path to the directory.</param> /// <param name="searchPattern">Search pattern for files in the directory.</param> /// <param name="recursionLevels">Number of levels of directory structure to recurse through while getting contents.</param> /// <returns>The contents of a directory on an Xbox.</returns> protected virtual IEnumerable <XboxFileSystemInfoDefinition> GetDirectoryContentsImpl(string systemIpAddress, XboxPath xboxDirectory, string searchPattern, int recursionLevels) { throw new XboxConsoleFeatureNotSupportedException(NotSupportedMessage); }
/// <summary> /// Copies a directory from the Xbox to a PC. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="sourceDirectory">The Xbox diretory to copy.</param> /// <param name="destinationDirectory">The path to the destination directory on the PC.</param> /// <param name="recursive">True to copy the directory and all of its sub-directories.</param> /// <param name="metrics">The progress handler that the calling app uses to receive progress updates about metrics. This may be null.</param> protected virtual void ReceiveDirectoryImpl(string systemIpAddress, XboxPath sourceDirectory, string destinationDirectory, bool recursive, IProgress <XboxFileTransferMetric> metrics) { throw new XboxConsoleFeatureNotSupportedException(NotSupportedMessage); }
/// <summary> /// Remove the given directory from the Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="directoryToDelete">The Xbox directory to remove.</param> /// <param name="recurisve">True to recursivly delete the directory, its content and all of its sub-directories.</param> protected virtual void DeleteDirectoryImpl(string systemIpAddress, XboxPath directoryToDelete, bool recurisve) { throw new XboxConsoleFeatureNotSupportedException(NotSupportedMessage); }
/// <summary> /// Copies a file from an Xbox to a PC. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="sourceFile">The source file to be copied.</param> /// <param name="destinationFilePath">The destination of the file on the PC.</param> /// <param name="metrics">The progress handler that the calling app uses to receive progress updates about metrics. This may be null.</param> protected virtual void ReceiveFileImpl(string systemIpAddress, XboxPath sourceFile, string destinationFilePath, IProgress <XboxFileTransferMetric> metrics) { throw new XboxConsoleFeatureNotSupportedException(NotSupportedMessage); }
/// <summary> /// Deletes a file from an Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxFilePath">The complete path to the file to be deleted.</param> protected virtual void DeleteFileImpl(string systemIpAddress, XboxPath xboxFilePath) { throw new XboxConsoleFeatureNotSupportedException(NotSupportedMessage); }
/// <summary> /// Retrieves an XboxFileSystemInfoDefintion object for the specified file system object. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxFilePath">The file system object for a which an XboxFileSystemInfoDefinition object shall be retrieved.</param> /// <returns>An XboxFileSystemInfoDefinition object describing the file specified in the <paramref name="xboxFilePath"/> parameter.</returns> public XboxFileSystemInfoDefinition GetFileSystemInfoDefinition(string systemIpAddress, XboxPath xboxFilePath) { this.ThrowIfDisposed(); this.ThrowIfInvalidSystemIpAddress(systemIpAddress); if (xboxFilePath == null) { throw new ArgumentNullException("xboxFilePath"); } return(this.PerformXdkFunc( systemIpAddress, () => this.GetFileSystemInfoDefinitionImpl(systemIpAddress, xboxFilePath), string.Format(CultureInfo.InvariantCulture, "Failed to retrieve XboxFileSystemInfoDefinition for '{0}'", xboxFilePath))); }
public void TestXboxPathGetDirectoryName() { this.RunDataDrivenTest( this.PathsForGetDirectoryName, path => XboxPath.GetDirectoryName(path)); }
/// <summary> /// Retrieves the contents of a directory on an Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxDirectory">The complete path to the directory.</param> /// <param name="searchPattern">Search pattern for files in the directory.</param> /// <param name="recursive">True if search should check recursively through child folders.</param> /// <returns>The contents of a directory on an Xbox.</returns> public IEnumerable <XboxFileSystemInfoDefinition> GetDirectoryContents(string systemIpAddress, XboxPath xboxDirectory, string searchPattern, bool recursive) { this.ThrowIfDisposed(); this.ThrowIfInvalidSystemIpAddress(systemIpAddress); if (xboxDirectory == null) { throw new ArgumentNullException("xboxDirectory"); } int recursionLevel = recursive ? int.MaxValue : 0; return(this.PerformXdkFunc( systemIpAddress, () => this.GetDirectoryContentsImpl(systemIpAddress, xboxDirectory, searchPattern, recursionLevel), string.Format(CultureInfo.InvariantCulture, "Failed to retrieve contents of directory '{0}'", xboxDirectory.FullName))); }
/// <summary> /// Retrieves the contents of a directory on an Xbox. /// </summary> /// <param name="systemIpAddress">The "System Ip" address of the Xbox kit.</param> /// <param name="xboxDirectory">The complete path to the directory.</param> /// <returns>The contents of a directory on an Xbox.</returns> public IEnumerable <XboxFileSystemInfoDefinition> GetDirectoryContents(string systemIpAddress, XboxPath xboxDirectory) { return(this.GetDirectoryContents(systemIpAddress, xboxDirectory, "*", false)); }
public void TestXboxPathCombineStrings() { this.RunDataDrivenTest( this.PathStringsForCombine, (input) => XboxPath.Combine(input.Item1, input.Item2)); }
public void TestConstructorThrowsArgumentNullException() { #pragma warning disable 168 var notUsed = new XboxPath(null, XboxOperatingSystem.System); #pragma warning restore 168 }
public void TestXboxPathHasXboxOriginNullArgument() { XboxPath.HasXboxOrigin(null); }