/// <summary> /// Creates and writes the mod information to a text file at the specified path /// </summary> /// <param name="categoriesData"></param> /// <param name="directoryPath"></param> public void GenerateReadMeAtPath(CategoriesData categoriesData, string directoryPath) { if (!Directory.Exists(directoryPath)) { _ = Directory.CreateDirectory(directoryPath); } // Create contents and write them to readme file File.WriteAllLines(Path.Combine(directoryPath, "README.txt"), new string[] { "Mod Id: #" + Id.ToString(), "Title: " + categoriesData.GetCategoryById(GameId).Title, "Name: " + Name, "System Type: " + string.Join(", ", Firmwares), "Mod Type: " + Type, "Version: " + Version, "Region: " + string.Join(", ", GameRegions), "Created By: " + Author, "Submitted By: " + SubmittedBy, "Game Type: " + string.Join(", ", GameModes), "Installation File Paths: " + string.Join(", ", InstallPaths), "Archive Download URL: " + Url, "-------------------------------------------------", "Description:\n" + Description }); }
/// <summary> /// Get all of the mods matching the specified filters. /// </summary> /// <param name="consoleType"></param> /// <param name="categoryId"></param> /// <param name="name"></param> /// <param name="firmware"></param> /// <param name="modType"></param> /// <param name="region"></param> /// <param name="version"></param> /// <param name="author"></param> /// <param name="isCustomList"></param> /// <returns></returns> public List <ModItemData> GetModItems(CategoriesData categoriesData, string categoryId, string name, string firmware, string modType, string region, string version, string creator, bool favorites = false) { if (favorites) { return(Mods.Where(x => MainWindow.Settings.FavoriteIds.Exists(y => y.Platform == PlatformPrefix.PS3 && y.Ids.Contains(x.Id)) && x.GetCategoryType(categoriesData) == CategoryType.Game && (categoryId.IsNullOrEmpty() ? x.CategoryId.ContainsIgnoreCase(categoryId) : x.CategoryId.EqualsIgnoreCase(categoryId)) && x.Name.ContainsIgnoreCase(name) && x.FirmwareTypes.Exists(y => y.ContainsIgnoreCase(firmware)) && x.ModType.ContainsIgnoreCase(modType) && x.Region.ContainsIgnoreCase(region) && x.Versions.ToArray().AnyContainsIgnoreCase(version) && x.Creators.ToArray().AnyContainsIgnoreCase(creator)) .ToList()); } else { return(Mods.Where(x => x.GetCategoryType(categoriesData) == CategoryType.Game && (categoryId.IsNullOrEmpty() ? x.CategoryId.ContainsIgnoreCase(categoryId) : x.CategoryId.EqualsIgnoreCase(categoryId)) && x.Name.ContainsIgnoreCase(name) && x.FirmwareTypes.Exists(y => y.ContainsIgnoreCase(firmware)) && x.ModType.ContainsIgnoreCase(modType) && x.Region.ContainsIgnoreCase(region) && x.Versions.ToArray().AnyContainsIgnoreCase(version) && x.Creators.ToArray().AnyContainsIgnoreCase(creator)) .ToList()); } }
/// <summary> /// Get the total number of resources. /// </summary> /// <returns></returns> public int TotalResources(CategoriesData categoriesData) { return((from ModItem modItem in Mods where modItem.GetCategoryType(categoriesData) == CategoryType.Resource && modItem.GetCategoryType(categoriesData) != CategoryType.Homebrew && modItem.GetCategoryType(categoriesData) != CategoryType.Game && modItem.GetCategoryType(categoriesData) != CategoryType.Favorite select modItem).Count()); }
/// <summary> /// Get the category type. /// </summary> /// <param name="categoriesData"></param> /// <returns></returns> public CategoryType GetCategoryType(CategoriesData categoriesData) { foreach (CategoriesData.Category category in categoriesData.Categories) { if (category.Id.ToLower().Equals(GameId.ToLower())) { return(category.CategoryType); } } return(CategoryType.Game); }
/// <summary> /// Download mods archive to the specified local folder path /// </summary> /// <param name="categoriesData"></param> /// <param name="downloadFiles"></param> /// <param name="localPath">Path to downloads mods archive at folder</param> public void DownloadArchiveAtPath(CategoriesData categoriesData, DownloadFiles downloadFiles, string localPath) { string zipFileName = $"{StringExtensions.ReplaceInvalidChars(Name)} v{Version} for {GameId.ToUpper()}.zip"; string zipFilePath = Path.Combine(localPath, zipFileName); GenerateReadMeAtPath(categoriesData, DownloadDataDirectory(downloadFiles)); using WebClient webClient = new WebClient(); webClient.Headers.Add("Accept: application/zip"); webClient.Headers.Add("User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); webClient.DownloadFile(new Uri(downloadFiles.URL), zipFilePath); Archives.AddFilesToZip(zipFilePath, new string[] { Path.Combine(DownloadDataDirectory(downloadFiles), "README.txt") }); }
/// <summary> /// Get the total number of resources. /// </summary> /// <returns> </returns> public int TotalResources(CategoriesData categoriesData) { return(Mods.Count(x => x.GetCategoryType(categoriesData) == CategoryType.Resource)); }
/// <summary> /// Get the total number of homebrew applications. /// </summary> /// <returns> </returns> public int TotalHomebrew(CategoriesData categoriesData) { return(Mods.Count(x => x.GetCategoryType(categoriesData) == CategoryType.Homebrew)); }
/// <summary> /// Get the total number of game mods. /// </summary> /// <returns> </returns> public int TotalGameMods(CategoriesData categoriesData) { return(Mods.Count(x => x.GetCategoryType(categoriesData) == CategoryType.Game)); }