/// <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(), "Category: " + 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), "Downloads: " + string.Join(", ", DownloadFiles.Select(x => x.URL)), "-------------------------------------------------", "Description:\n" + Description }); }
/// <summary> /// Downloads the modded files archive and extracts all files to <see cref="DownloadDataDirectory"/> /// </summary> /// <param name="downloadFiles"></param> public void DownloadInstallFiles(DownloadFiles downloadFiles) { string archivePath = DownloadDataDirectory(downloadFiles); string archiveFilePath = ArchiveZipFile(downloadFiles); if (Directory.Exists(archivePath)) { UserFolders.DeleteDirectory(archivePath); } if (!Directory.Exists(archivePath)) { Directory.CreateDirectory(archivePath); } if (File.Exists(archiveFilePath)) { File.Delete(archiveFilePath); } Directory.CreateDirectory(archivePath); 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), archiveFilePath); } ZipFile.ExtractToDirectory(archiveFilePath, archivePath); }
/// <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 download url specified by the user if there are multiple types /// </summary> /// <returns>Download Archive URL</returns> public DownloadFiles GetDownloadFiles() { if (DownloadFiles.Count > 1) { var downloadNames = DownloadFiles.Select(x => x.Name).ToList(); var downloadName = DialogExtensions.ShowListInputDialog("Install Downloads", downloadNames); if (string.IsNullOrEmpty(downloadName)) { return(null); } return(DownloadFiles.First(x => x.Name.Equals(downloadName))); } else { return(DownloadFiles.First()); } }
/// <summary> /// Gets the downloaded mods archive file path. /// </summary> /// <returns>Mods Archive File Path</returns> public string ArchiveZipFile(DownloadFiles downloadFiles) => $@"{UserFolders.AppModsDataDirectory}{GameId}\{Author}\{StringExtensions.ReplaceInvalidChars(Name)} ({StringExtensions.ReplaceInvalidChars(downloadFiles.Name)}) (#{Id}).zip";