Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <inheritdoc />
        public override bool Equals(object obj)
        {
            PackageGroup other = obj as PackageGroup;

            if (other != null)
            {
                return(this.GroupName.Equals(other.GroupName) &&
                       this.Packages.Equals(other.Packages));
            }

            return(false);
        }