コード例 #1
0
        /// <summary>
        /// Purges the mod directory asynchronous.
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> PurgeModDirectoryAsync(string folder)
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(false);
            }
            var fullPath = Path.Combine(game.UserDirectory, Shared.Constants.ModDirectory, folder);
            var exists   = await ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
            {
                RootDirectory = fullPath
            });

            if (!exists)
            {
                fullPath = Path.Combine(GetModDirectoryRootPath(game), folder);
            }
            var result = await ModWriter.PurgeModDirectoryAsync(new ModWriterParameters()
            {
                RootDirectory = fullPath
            }, true);

            var mods = GetInstalledModsInternal(game, false);

            if (mods.Any(p => !string.IsNullOrWhiteSpace(p.FullPath) && p.FullPath.Contains(fullPath)))
            {
                var mod = mods.Where(p => p.FullPath.Contains(fullPath));
                if (mod.Any())
                {
                    await DeleteDescriptorsInternalAsync(mod);
                }
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// export hash report as an asynchronous operation.
        /// </summary>
        /// <param name="mods">The mods.</param>
        /// <param name="path">The path.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> ExportHashReportAsync(IEnumerable <IMod> mods, string path)
        {
            if (!string.IsNullOrWhiteSpace(path) && mods?.Count() > 0)
            {
                var modExport    = mods.ToList();
                var collection   = GetAllModCollectionsInternal().FirstOrDefault(p => p.IsSelected);
                var patchModName = GenerateCollectionPatchName(collection.Name);
                var allMods      = GetInstalledModsInternal(GameService.GetSelected(), false);
                var patchMod     = allMods.FirstOrDefault(p => p.Name.Equals(patchModName));
                if (patchMod == null)
                {
                    var game = GameService.GetSelected();
                    if (await ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
                    {
                        RootDirectory = GetPatchModDirectory(game, patchModName)
                    }))
                    {
                        patchMod = GeneratePatchModDescriptor(allMods, game, patchModName);
                    }
                }
                if (patchMod != null && collection.PatchModEnabled)
                {
                    if (patchMod.Files == null || !patchMod.Files.Any())
                    {
                        await PopulateModFilesInternalAsync(new List <IMod>() { patchMod });
                    }
                    modExport.Add(patchMod);
                }
                var reports = await ParseReportAsync(modExport);

                return(await exportService.ExportAsync(reports, path));
            }
            return(false);
        }
コード例 #3
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));
        }
コード例 #4
0
        /// <summary>
        /// Mods the directory exists asynchronous.
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual Task <bool> ModDirectoryExistsAsync(string folder)
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(Task.FromResult(false));
            }
            return(ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
            {
                RootDirectory = game.UserDirectory,
                Path = Path.Combine(Shared.Constants.ModDirectory, folder)
            }));
        }
コード例 #5
0
        /// <summary>
        /// Customs the mod directory empty asynchronous.
        /// </summary>
        /// <param name="gameType">Type of the game.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> CustomModDirectoryEmptyAsync(string gameType)
        {
            var game = GameService.Get().FirstOrDefault(p => p.Type.Equals(gameType));

            if (game == null)
            {
                return(true);
            }
            if (string.IsNullOrWhiteSpace(game.CustomModDirectory))
            {
                return(true);
            }
            var path   = GetModDirectoryRootPath(game);
            var result = await ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
            {
                RootDirectory = path
            });

            return(!result);
        }
コード例 #6
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));
        }
コード例 #7
0
        /// <summary>
        /// Imports the hash report asynchronous.
        /// </summary>
        /// <param name="mods">The mods.</param>
        /// <param name="hashReports">The hash reports.</param>
        /// <returns>Task&lt;IEnumerable&lt;IModHashReport&gt;&gt;.</returns>
        public virtual async Task <IEnumerable <IHashReport> > ImportHashReportAsync(IEnumerable <IMod> mods, IReadOnlyCollection <IHashReport> hashReports)
        {
            var importedReports = exportService.GetCollectionReports(hashReports);

            if (importedReports == null || !importedReports.Any())
            {
                return(null);
            }
            var modExport    = mods.ToList();
            var collection   = GetAllModCollectionsInternal().FirstOrDefault(p => p.IsSelected);
            var patchModName = GenerateCollectionPatchName(collection.Name);
            var allMods      = GetInstalledModsInternal(GameService.GetSelected(), false);
            var patchMod     = allMods.FirstOrDefault(p => p.Name.Equals(patchModName));

            if (patchMod == null)
            {
                var game = GameService.GetSelected();
                if (await ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
                {
                    RootDirectory = GetPatchModDirectory(game, patchModName)
                }))
                {
                    patchMod = GeneratePatchModDescriptor(allMods, game, patchModName);
                }
            }
            if (patchMod != null)
            {
                if (patchMod.Files == null || !patchMod.Files.Any())
                {
                    await PopulateModFilesInternalAsync(new List <IMod>() { patchMod });
                }
                modExport.Add(patchMod);
            }
            var currentReports = await ParseReportAsync(modExport);

            return(exportService.CompareReports(currentReports.ToList(), importedReports.ToList()));
        }
コード例 #8
0
        /// <summary>
        /// Mods the directory exists asynchronous.
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public virtual async Task <bool> ModDirectoryExistsAsync(string folder)
        {
            var game = GameService.GetSelected();

            if (game == null)
            {
                return(false);
            }
            var result = await ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
            {
                RootDirectory = game.UserDirectory,
                Path          = Path.Combine(Shared.Constants.ModDirectory, folder)
            });

            if (!result && !string.IsNullOrEmpty(game.CustomModDirectory))
            {
                result = await ModWriter.ModDirectoryExistsAsync(new ModWriterParameters()
                {
                    RootDirectory = GetModDirectoryRootPath(game),
                    Path          = folder
                });
            }
            return(result);
        }