/// <summary> /// Extracts a file from a specific package in the package group. If the file does not exist in /// the package referenced in <paramref name="fileReference"/>, this method returned will return null. /// </summary> /// <returns>The unversioned file or null.</returns> /// <param name="fileReference">File reference.</param> public byte[] ExtractUnversionedReference(ItemReference fileReference) { PackageInteractionHandler package = GetPackageByName(fileReference.PackageName); if (package != null) { return(package.ExtractReference(fileReference)); } return(null); }
/// <summary> /// Gets the file info for the specified reference in its specific package. If the file does not exist in /// the package referenced in <paramref name="fileReference"/>, this method returned will return null. /// </summary> /// <returns>The reference info.</returns> /// <param name="fileReference">Reference reference.</param> public MPQFileInfo GetVersionedReferenceInfo(FileReference fileReference) { if (fileReference == null) { throw new ArgumentNullException(nameof(fileReference)); } PackageInteractionHandler package = GetPackageByName(fileReference.PackageName); return(package.GetReferenceInfo(fileReference)); }
/// <summary> /// Gets the file info for the specified reference in its specific package. If the file does not exist in /// the package referenced in <paramref name="itemReference"/>, this method returned will return null. /// </summary> /// <returns>The reference info.</returns> /// <param name="itemReference">Item reference.</param> public MPQFileInfo GetUnversionedReferenceInfo(ItemReference itemReference) { PackageInteractionHandler package = GetPackageByName(itemReference.PackageName); if (package != null) { return(package.GetReferenceInfo(itemReference)); } return(null); }
/// <summary> /// Gets the file info for the specified reference in its specific package. If the file does not exist in /// the package referenced in <paramref name="fileReference"/>, this method returned will return null. /// </summary> /// <returns>The reference info.</returns> /// <param name="fileReference">Reference reference.</param> public MPQFileInfo GetVersionedReferenceInfo(FileReference fileReference) { PackageInteractionHandler package = GetPackageByName(fileReference.PackageName); if (package != null) { return(package.GetReferenceInfo(fileReference)); } return(null); }
/// <summary> /// Creates a new package group, and asynchronously loads all of the packages in the provided directory. /// </summary> /// <param name="alias">The alias of the package group that's being loaded.</param> /// <param name="groupName">The name of the group that is to be created.</param> /// <param name="packageDirectory">The directory where the packages to load are.</param> /// <param name="ct">A <see cref="CancellationToken"/> which can be used to cancel the operation.</param> /// <param name="progress">The progress reporting object.</param> /// <returns>A loaded package group.</returns> public static async Task <PackageGroup> LoadAsync ( string alias, string groupName, string packageDirectory, CancellationToken ct, IProgress <GameLoadingProgress>?progress = null ) { var group = new PackageGroup(groupName); // Grab all packages in the game directory var packagePaths = Directory.EnumerateFiles(packageDirectory, "*.*", SearchOption.AllDirectories) .Where(s => s.EndsWith(".mpq") || s.EndsWith(".MPQ")) .OrderBy(a => a) .ToList(); // Internal counters for progress reporting double completedSteps = 0; double totalSteps = packagePaths.Count; foreach (var packagePath in packagePaths) { ct.ThrowIfCancellationRequested(); try { progress?.Report(new GameLoadingProgress { CompletionPercentage = completedSteps / totalSteps, State = GameLoadingState.LoadingPackages, Alias = alias }); var handler = await PackageInteractionHandler.LoadAsync(packagePath); group.AddPackage(handler); ++completedSteps; } catch (FileLoadException fex) { Log.Warn($"FileLoadException for package \"{packagePath}\": {fex.Message}\n" + $"Please report this on GitHub or via email."); } catch (NotImplementedException nex) { Log.Warn($"NotImplementedException for package \"{packagePath}\": {nex.Message}\n" + $"There's a good chance your game version isn't supported yet."); } } return(group); }
/// <summary> /// Asynchronously loads a package at the given path. /// </summary> /// <param name="packagePath">The path on disk where the package is.</param> /// <returns>A loaded PackageInteractionHandler.</returns> public static Task <PackageInteractionHandler> LoadAsync(string packagePath) { return(Task.Run ( () => { PackageInteractionHandler handler = new PackageInteractionHandler(); handler.Load(packagePath); return handler; } )); }
/// <summary> /// Adds a package to the package group. /// </summary> /// <param name="package">The package to add.</param> /// <exception cref="ArgumentNullException">Thrown if the package is null.</exception> public void AddPackage(PackageInteractionHandler package) { if (package == null) { throw new ArgumentNullException(nameof(package)); } if (this.Packages.Contains(package)) { return; } this.Packages.Add(package); }
/// <summary> /// Extracts a file from a specific package in the package group. If the file does not exist in /// the package referenced in <paramref name="fileReference"/>, this method returned will return null. /// </summary> /// <returns>The unversioned file or null.</returns> /// <param name="fileReference">Reference reference.</param> public byte[] ExtractVersionedReference(FileReference fileReference) { if (fileReference == null) { throw new ArgumentNullException(nameof(fileReference)); } if (fileReference.IsVirtual) { return(ExtractReference(fileReference)); } PackageInteractionHandler package = GetPackageByName(fileReference.PackageName); return(package?.ExtractReference(fileReference)); }