/// <summary> /// export hash report as an asynchronous operation. /// </summary> /// <param name="mods">The mods.</param> /// <param name="path">The path.</param> /// <returns>Task<System.Boolean>.</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); }
/// <summary> /// delete descriptors internal as an asynchronous operation. /// </summary> /// <param name="mods">The mods.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> protected virtual async Task <bool> DeleteDescriptorsInternalAsync(IEnumerable <IMod> mods) { var game = GameService.GetSelected(); if (game != null && mods?.Count() > 0) { var tasks = new List <Task>(); foreach (var item in mods) { var task = ModWriter.DeleteDescriptorAsync(new ModWriterParameters() { Mod = item, RootDirectory = game.UserDirectory }); tasks.Add(task); } await Task.WhenAll(tasks); Cache.Invalidate(new CacheInvalidateParameters() { Region = ModsCacheRegion, Prefix = game.Type, Keys = new List <string> { GetModsCacheKey(true), GetModsCacheKey(false) } }); return(true); } return(false); }
/// <summary> /// lock descriptors as an asynchronous operation. /// </summary> /// <param name="mods">The mods.</param> /// <param name="isLocked">if set to <c>true</c> [is locked].</param> /// <returns>Task<System.Boolean>.</returns> public virtual async Task <bool> LockDescriptorsAsync(IEnumerable <IMod> mods, bool isLocked) { var game = GameService.GetSelected(); if (game != null && mods?.Count() > 0) { var tasks = new List <Task>(); foreach (var item in mods) { // Cannot lock\unlock mandatory local zipped mods if (!CheckIfModShouldBeLocked(game, item)) { var task = ModWriter.SetDescriptorLockAsync(new ModWriterParameters() { Mod = item, RootDirectory = game.UserDirectory }, isLocked); item.IsLocked = isLocked; tasks.Add(task); } } await Task.WhenAll(tasks); return(true); } return(false); }
/// <summary> /// Purges the mod directory asynchronous. /// </summary> /// <param name="folder">The folder.</param> /// <returns>Task<System.Boolean>.</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 result = await ModWriter.PurgeModDirectoryAsync(new ModWriterParameters() { RootDirectory = game.UserDirectory, Path = Path.Combine(Shared.Constants.ModDirectory, folder) }, 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); }
/// <summary> /// install mods as an asynchronous operation. /// </summary> /// <returns>Task<System.Boolean>.</returns> public virtual async Task <bool> InstallModsAsync() { var game = GameService.GetSelected(); if (game == null) { return(false); } var mods = GetInstalledModsInternal(game, false); var descriptors = new List <IMod>(); var userDirectoryMods = GetAllModDescriptors(Path.Combine(game.UserDirectory, Shared.Constants.ModDirectory), ModSource.Local); if (userDirectoryMods?.Count() > 0) { descriptors.AddRange(userDirectoryMods); } var workshopDirectoryMods = GetAllModDescriptors(game.WorkshopDirectory, ModSource.Steam); if (workshopDirectoryMods?.Count() > 0) { descriptors.AddRange(workshopDirectoryMods); } var diffs = descriptors.Where(p => !mods.Any(m => m.DescriptorFile.Equals(p.DescriptorFile, StringComparison.OrdinalIgnoreCase))).ToList(); if (diffs.Count > 0) { await ModWriter.CreateModDirectoryAsync(new ModWriterParameters() { RootDirectory = game.UserDirectory, Path = Shared.Constants.ModDirectory }); var tasks = new List <Task>(); foreach (var diff in diffs) { if (IsPatchModInternal(diff)) { continue; } tasks.Add(ModWriter.WriteDescriptorAsync(new ModWriterParameters() { Mod = diff, RootDirectory = game.UserDirectory, Path = diff.DescriptorFile }, IsPatchModInternal(diff))); } if (tasks.Count > 0) { await Task.WhenAll(tasks); Cache.Invalidate(ModsCachePrefix, ConstructModsCacheKey(game, true), ConstructModsCacheKey(game, false)); } return(true); } return(false); }
/// <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<System.Boolean>.</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)); }
protected override bool Execute() { Log("Creating .mod File"); SendMessage("Writing Mod File"); ModWriter.CreateModFile(m_options.Data.MyDocsDir.FullName, m_options.Mod); Log("Finished"); return(true); }
/// <summary> /// Mods the directory exists asynchronous. /// </summary> /// <param name="folder">The folder.</param> /// <returns>Task<System.Boolean>.</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) })); }
/// <summary> /// Gets the patch mod directory. /// </summary> /// <param name="game">The game.</param> /// <param name="patchOrMergeName">Name of the patch or merge.</param> /// <returns>System.String.</returns> protected virtual string GetPatchModDirectory(IGame game, string patchOrMergeName) { var path = Path.Combine(game.UserDirectory, Shared.Constants.ModDirectory, patchOrMergeName); path = path.StandardizeDirectorySeparator(); var parameters = new ModWriterParameters() { Path = path }; if (!ModWriter.ModDirectoryExists(parameters) && !string.IsNullOrWhiteSpace(game.CustomModDirectory)) { path = Path.Combine(game.CustomModDirectory, patchOrMergeName).StandardizeDirectorySeparator(); } return(path); }
/// <summary> /// Customs the mod directory empty asynchronous. /// </summary> /// <param name="gameType">Type of the game.</param> /// <returns>Task<System.Boolean>.</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); }
/// <summary> /// lock descriptors as an asynchronous operation. /// </summary> /// <param name="mods">The mods.</param> /// <param name="isLocked">if set to <c>true</c> [is locked].</param> /// <returns>Task<System.Boolean>.</returns> public virtual async Task <bool> LockDescriptorsAsync(IEnumerable <IMod> mods, bool isLocked) { var game = GameService.GetSelected(); if (game != null && mods?.Count() > 0) { var tasks = new List <Task>(); foreach (var item in mods) { var task = ModWriter.SetDescriptorLockAsync(new ModWriterParameters() { Mod = item, RootDirectory = game.UserDirectory }, isLocked); tasks.Add(task); } await Task.WhenAll(tasks); return(true); } return(false); }
/// <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<System.Boolean>.</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)); }
/// <summary> /// Imports the hash report asynchronous. /// </summary> /// <param name="mods">The mods.</param> /// <param name="hashReports">The hash reports.</param> /// <returns>Task<IEnumerable<IModHashReport>>.</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())); }
/// <summary> /// Mods the directory exists asynchronous. /// </summary> /// <param name="folder">The folder.</param> /// <returns>Task<System.Boolean>.</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); }
/// <summary> /// install mods as an asynchronous operation. /// </summary> /// <param name="statusToRetain">The status to retain.</param> /// <returns>Task<System.Boolean>.</returns> public virtual async Task <bool> InstallModsAsync(IEnumerable <IMod> statusToRetain) { var game = GameService.GetSelected(); if (game == null) { return(false); } var mods = GetInstalledModsInternal(game, false); var descriptors = new List <IMod>(); var userDirectoryMods = GetAllModDescriptors(Path.Combine(game.UserDirectory, Shared.Constants.ModDirectory), ModSource.Local); if (userDirectoryMods?.Count() > 0) { descriptors.AddRange(userDirectoryMods); } var workshopDirectoryMods = GetAllModDescriptors(game.WorkshopDirectory, ModSource.Steam); if (workshopDirectoryMods?.Count() > 0) { descriptors.AddRange(workshopDirectoryMods); } var diffs = descriptors.Where(p => !mods.Any(m => m.DescriptorFile.Equals(p.DescriptorFile, StringComparison.OrdinalIgnoreCase))).ToList(); if (diffs.Count > 0) { await ModWriter.CreateModDirectoryAsync(new ModWriterParameters() { RootDirectory = game.UserDirectory, Path = Shared.Constants.ModDirectory }); var tasks = new List <Task>(); foreach (var diff in diffs.GroupBy(p => p.DescriptorFile)) { var localDiff = diff.FirstOrDefault(); if (IsPatchModInternal(localDiff)) { continue; } tasks.Add(Task.Run(async() => { bool shouldLock = CheckIfModShouldBeLocked(game, localDiff); if (statusToRetain != null && !shouldLock) { var mod = statusToRetain.FirstOrDefault(p => p.DescriptorFile.Equals(localDiff.DescriptorFile, StringComparison.OrdinalIgnoreCase)); if (mod != null) { shouldLock = mod.IsLocked; } } await ModWriter.WriteDescriptorAsync(new ModWriterParameters() { Mod = localDiff, RootDirectory = game.UserDirectory, Path = localDiff.DescriptorFile, LockDescriptor = shouldLock }, IsPatchModInternal(localDiff));; })); } if (tasks.Count > 0) { await Task.WhenAll(tasks); Cache.Invalidate(ModsCachePrefix, ConstructModsCacheKey(game, true), ConstructModsCacheKey(game, false)); } return(true); } return(false); }
/// <summary> /// install mods as an asynchronous operation. /// </summary> /// <param name="statusToRetain">The status to retain.</param> /// <returns>Task<System.Boolean>.</returns> public virtual async Task <IReadOnlyCollection <IModInstallationResult> > InstallModsAsync(IEnumerable <IMod> statusToRetain) { var game = GameService.GetSelected(); if (game == null) { return(null); } var mods = GetInstalledModsInternal(game, false); var descriptors = new List <IModInstallationResult>(); var userDirectoryMods = GetAllModDescriptors(Path.Combine(game.UserDirectory, Shared.Constants.ModDirectory), ModSource.Local); if (userDirectoryMods?.Count() > 0) { descriptors.AddRange(userDirectoryMods); } if (!string.IsNullOrWhiteSpace(game.CustomModDirectory)) { var customMods = GetAllModDescriptors(GetModDirectoryRootPath(game), ModSource.Local); if (customMods != null && customMods.Any()) { descriptors.AddRange(customMods); } } var workshopDirectoryMods = game.WorkshopDirectory.SelectMany(p => GetAllModDescriptors(p, ModSource.Steam)); if (workshopDirectoryMods.Any()) { descriptors.AddRange(workshopDirectoryMods); } var diffs = descriptors.Where(p => p.Mod != null && !mods.Any(m => m.DescriptorFile.Equals(p.Mod.DescriptorFile, StringComparison.OrdinalIgnoreCase))).ToList(); if (diffs.Count > 0) { var result = new List <IModInstallationResult>(); await ModWriter.CreateModDirectoryAsync(new ModWriterParameters() { RootDirectory = game.UserDirectory, Path = Shared.Constants.ModDirectory }); var tasks = new List <Task>(); foreach (var diff in diffs.GroupBy(p => p.Mod.DescriptorFile)) { var installResult = diff.FirstOrDefault(); var localDiff = diff.FirstOrDefault().Mod; if (IsPatchModInternal(localDiff)) { continue; } tasks.Add(Task.Run(async() => { bool shouldLock = CheckIfModShouldBeLocked(game, localDiff); if (statusToRetain != null && !shouldLock) { var mod = statusToRetain.FirstOrDefault(p => p.DescriptorFile.Equals(localDiff.DescriptorFile, StringComparison.OrdinalIgnoreCase)); if (mod != null) { shouldLock = mod.IsLocked; } } await ModWriter.WriteDescriptorAsync(new ModWriterParameters() { Mod = localDiff, RootDirectory = game.UserDirectory, Path = localDiff.DescriptorFile, LockDescriptor = shouldLock }, IsPatchModInternal(localDiff));; })); installResult.Installed = true; result.Add(installResult); } if (tasks.Count > 0) { await Task.WhenAll(tasks); Cache.Invalidate(new CacheInvalidateParameters() { Region = ModsCacheRegion, Prefix = game.Type, Keys = new List <string> { GetModsCacheKey(true), GetModsCacheKey(false) } }); } if (descriptors.Any(p => p.Invalid)) { result.AddRange(descriptors.Where(p => p.Invalid)); } return(result); } if (descriptors.Any(p => p.Invalid)) { return(descriptors.Where(p => p.Invalid).ToList()); } return(null); }