예제 #1
0
        /// <summary>
        /// Exports the mods asynchronous.
        /// </summary>
        /// <param name="enabledMods">The mods.</param>
        /// <param name="regularMods">The regular mods.</param>
        /// <param name="modCollection">The mod collection.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> ExportModsAsync(IReadOnlyCollection <IMod> enabledMods, IReadOnlyCollection <IMod> regularMods, IModCollection modCollection)
        {
            var game = GameService.GetSelected();

            if (game == null || enabledMods == null || regularMods == null || modCollection == null)
            {
                return(false);
            }
            var allMods        = GetInstalledModsInternal(game, false);
            var mod            = GeneratePatchModDescriptor(allMods, game, GenerateCollectionPatchName(modCollection.Name));
            var applyModParams = new ModWriterParameters()
            {
                OtherMods     = regularMods.Where(p => !enabledMods.Any(m => m.DescriptorFile.Equals(p.DescriptorFile))).ToList(),
                EnabledMods   = enabledMods,
                RootDirectory = game.UserDirectory
            };

            if (await ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
            {
                RootDirectory = mod.FullPath
            }))
            {
                if (modCollection.PatchModEnabled && enabledMods.Any())
                {
                    if (await ModWriter.WriteDescriptorAsync(new ModWriterParameters()
                    {
                        Mod = mod,
                        RootDirectory = game.UserDirectory,
                        Path = mod.DescriptorFile,
                        LockDescriptor = CheckIfModShouldBeLocked(game, mod)
                    }, IsPatchModInternal(mod)))
                    {
                        applyModParams.TopPriorityMods = new List <IMod>()
                        {
                            mod
                        };
                        Cache.Invalidate(new CacheInvalidateParameters()
                        {
                            Region = ModsCacheRegion, Prefix = game.Type, Keys = new List <string> {
                                GetModsCacheKey(true), GetModsCacheKey(false)
                            }
                        });
                    }
                }
            }
            else
            {
                // Remove left over descriptor
                if (allMods.Any(p => p.Name.Equals(mod.Name)))
                {
                    await DeleteDescriptorsInternalAsync(new List <IMod>() { mod });
                }
            }
            return(await ModWriter.ApplyModsAsync(applyModParams));
        }
예제 #2
0
        /// <summary>
        /// Exports the mods asynchronous.
        /// </summary>
        /// <param name="enabledMods">The mods.</param>
        /// <param name="regularMods">The regular mods.</param>
        /// <param name="collectionName">Name of the collection.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> ExportModsAsync(IReadOnlyCollection <IMod> enabledMods, IReadOnlyCollection <IMod> regularMods, string collectionName)
        {
            var game = GameService.GetSelected();

            if (game == null || enabledMods == null || regularMods == null)
            {
                return(false);
            }
            var allMods        = GetInstalledModsInternal(game, false);
            var mod            = GeneratePatchModDescriptor(allMods, game, GenerateCollectionPatchName(collectionName));
            var applyModParams = new ModWriterParameters()
            {
                OtherMods     = regularMods.Where(p => !enabledMods.Any(m => m.DescriptorFile.Equals(p.DescriptorFile))).ToList(),
                EnabledMods   = enabledMods,
                RootDirectory = game.UserDirectory
            };

            if (await ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
            {
                RootDirectory = game.UserDirectory,
                Path = mod.FileName
            }))
            {
                if (await ModWriter.WriteDescriptorAsync(new ModWriterParameters()
                {
                    Mod = mod,
                    RootDirectory = game.UserDirectory,
                    Path = mod.DescriptorFile
                }, IsPatchModInternal(mod)))
                {
                    applyModParams.TopPriorityMods = new List <IMod>()
                    {
                        mod
                    };
                    Cache.Invalidate(ModsCachePrefix, ConstructModsCacheKey(game, true), ConstructModsCacheKey(game, false));
                }
            }
            return(await ModWriter.ApplyModsAsync(applyModParams));
        }