diff --git a/TODO.md b/TODO.md index 52bb8f0..380e899 100644 --- a/TODO.md +++ b/TODO.md @@ -4,3 +4,5 @@ - [ ] Choose switch-mod download server - [ ] Full support for custom mod root path locations - [ ] Linux port ??? +- [X] Allow user to select games to download +- [X] Delete zip files after extraction diff --git a/source/YuzuModDownloader/ModDownloader.cs b/source/YuzuModDownloader/ModDownloader.cs index a3f98fe..659d068 100644 --- a/source/YuzuModDownloader/ModDownloader.cs +++ b/source/YuzuModDownloader/ModDownloader.cs @@ -51,14 +51,22 @@ public async Task DownloadPrerequisitesAsync() wc.DownloadFileCompleted += (s, e) => { UpdateProgress(0, "Unpacking prerequisites ..."); - using (var archive = ZipFile.OpenRead(sevenZLocation)) + var archive = ZipFile.OpenRead(sevenZLocation); + var entriesCount = archive.Entries.Count(); + var stepSize = 100 / entriesCount; + var i = 0; + using (archive) { foreach (var entry in archive.Entries) { entry.ExtractToFile(Path.Combine($"{prerequisitesLocation}", entry.FullName), true); + UpdateProgress(stepSize * i, entry.Name); + i++; } } + File.Delete(sevenZLocation); UpdateProgress(100, "Done"); + }; wc.DownloadProgressChanged += (s, e) => UpdateProgress(e.ProgressPercentage, "Downloading Prerequisites ..."); await wc.DownloadFileTaskAsync("https://my.cloudme.com/v1/ws2/:amakvana/:7z/7z.zip", sevenZLocation); @@ -97,6 +105,7 @@ public async Task DownloadTitleModsAsync(string titleName, string titleId, strin var web = new HtmlWeb(); var htmlDoc = web.Load(modWebsiteUrl); var nodes = htmlDoc.DocumentNode.SelectNodes(@"//h3[contains(., """ + titleName + "\")]/following::table[1]//td//a"); + // if true, delete existing mods if (deleteExistingMods) @@ -141,6 +150,7 @@ public async Task DownloadTitleModsAsync(string titleName, string titleId, strin }; using (var p = Process.Start(psi)) { + File.Delete($@"{UserDirPath}\load\{titleId}\{fileName}"); UpdateProgress(100, "Done"); } }; diff --git a/source/YuzuModDownloader/YuzuModDownloader.csproj b/source/YuzuModDownloader/YuzuModDownloader.csproj index 1dcc1ac..076a0bf 100644 --- a/source/YuzuModDownloader/YuzuModDownloader.csproj +++ b/source/YuzuModDownloader/YuzuModDownloader.csproj @@ -1,138 +1,147 @@ - - - - - Debug - AnyCPU - {AA84FF1C-778F-42B6-872A-2114014D7B73} - WinExe - YuzuModDownloader - YuzuModDownloader - v4.7.2 - 512 - true - true - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - icon.ico - - - - ..\packages\HtmlAgilityPack.1.11.30\lib\Net45\HtmlAgilityPack.dll - - - - - ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll - True - True - - - - - - - - - - - - - - - - Form - - - frmAbout.cs - - - Form - - - frmMain.cs - - - - - - frmAbout.cs - - - frmMain.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - True - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - - - - - - - - False - Microsoft .NET Framework 4.7.2 %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 - false - - - + + + + + Debug + AnyCPU + {AA84FF1C-778F-42B6-872A-2114014D7B73} + WinExe + YuzuModDownloader + YuzuModDownloader + v4.7.2 + 512 + true + true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + icon.ico + + + + ..\packages\HtmlAgilityPack.1.11.30\lib\Net45\HtmlAgilityPack.dll + + + + + ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + True + True + + + + + + + + + + + + + + + + Form + + + frmAbout.cs + + + Form + + + frmMain.cs + + + Form + + + frmSelect.cs + + + + + + frmAbout.cs + + + frmMain.cs + + + frmSelect.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + \ No newline at end of file diff --git a/source/YuzuModDownloader/frmMain.cs b/source/YuzuModDownloader/frmMain.cs index f79f539..102a396 100644 --- a/source/YuzuModDownloader/frmMain.cs +++ b/source/YuzuModDownloader/frmMain.cs @@ -38,17 +38,30 @@ private async void btnDownload_Click(object sender, EventArgs e) modDownloader.UpdateProgress += ModDownloader_UpdateProgress; await modDownloader.DownloadPrerequisitesAsync(); await modDownloader.DownloadGameTitleIdDatabaseAsync(gameTitleIDsXml); - var gameTitleNameIDs = modDownloader.ReadGameTitleIdDatabase(gameTitleIDsXml); + var gameTitleNameIDs = modDownloader.ReadGameTitleIdDatabase(gameTitleIDsXml); + System.Collections.Generic.List selectedTitles; + + using (var f = new frmSelect(gameTitleNameIDs)) + { + f.ShowDialog(); + selectedTitles = f.getSelectedTitles(); + } // download mods for each game int totalGames = 0; - foreach (var g in gameTitleNameIDs) + foreach(var titleName in selectedTitles) + { + string titleId = gameTitleNameIDs[titleName]; + await modDownloader.DownloadTitleModsAsync(titleName, titleId, "https://github.com/yuzu-emu/yuzu/wiki/Switch-Mods", chkClearModDataLocation.Checked); + totalGames++; + } + /*foreach (var g in gameTitleNameIDs) { string titleName = g.Key; string titleId = g.Value; await modDownloader.DownloadTitleModsAsync(titleName, titleId, "https://github.com/yuzu-emu/yuzu/wiki/Switch-Mods", chkClearModDataLocation.Checked); totalGames++; - } + }*/ // enable form controls MessageBox.Show($"Done! Mods downloaded for {totalGames} games.{Environment.NewLine}{Environment.NewLine}" + @@ -76,7 +89,7 @@ private void YuzuWebsiteToolStripMenuItem_Click(object sender, EventArgs e) } private void AboutToolStripMenuItem_Click(object sender, EventArgs e) - { + { using (var f = new frmAbout()) { f.ShowDialog(); diff --git a/source/YuzuModDownloader/frmSelect.Designer.cs b/source/YuzuModDownloader/frmSelect.Designer.cs new file mode 100644 index 0000000..1db2312 --- /dev/null +++ b/source/YuzuModDownloader/frmSelect.Designer.cs @@ -0,0 +1,87 @@ +namespace YuzuModDownloader +{ + partial class frmSelect + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.button1 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.treeView1 = new System.Windows.Forms.TreeView(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(457, 365); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 1; + this.button1.Text = "OK"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 31); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(146, 13); + this.label1.TabIndex = 2; + this.label1.Text = "Select the Titles to Download"; + this.label1.Click += new System.EventHandler(this.label1_Click); + // + // treeView1 + // + this.treeView1.Location = new System.Drawing.Point(15, 67); + this.treeView1.Name = "treeView1"; + this.treeView1.Size = new System.Drawing.Size(529, 278); + this.treeView1.TabIndex = 5; + this.treeView1.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterCheck); + // + // frmSelect + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(556, 400); + this.Controls.Add(this.treeView1); + this.Controls.Add(this.label1); + this.Controls.Add(this.button1); + this.Name = "frmSelect"; + this.Text = "Titles Selector"; + this.Load += new System.EventHandler(this.frmSelect_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label1; + + private System.Collections.Generic.Dictionary titles; + private System.Windows.Forms.TreeView treeView1; + } +} \ No newline at end of file diff --git a/source/YuzuModDownloader/frmSelect.cs b/source/YuzuModDownloader/frmSelect.cs new file mode 100644 index 0000000..05e9512 --- /dev/null +++ b/source/YuzuModDownloader/frmSelect.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace YuzuModDownloader +{ + public partial class frmSelect : Form + { + private List selectedTitles = new List { }; + public frmSelect() + { + InitializeComponent(); + } + public frmSelect(Dictionary titles) + { + init_titles(titles); + InitializeComponent(); + } + + private void frmSelect_Load(object sender, EventArgs e) + { + treeView1.CheckBoxes = true; + + TreeNode mainNode = treeView1.Nodes.Add("Available Games"); + + // Add nodes to treeView1. + + foreach (var title in this.titles.Keys) + { + TreeNode gameNode = mainNode.Nodes.Add(title); + // Not Yet Implemented + /*foreach (var mod in this.title_mods[titles]) + { + gameNode.Nodes.Add(mod); + }*/ + + } + + } + + private void label1_Click(object sender, EventArgs e) + { + + } + + private void init_titles(Dictionary titles) + { + this.titles = titles; + } + + public List getSelectedTitles() + { + return selectedTitles; + } + + private void treeView1_AfterCheck(object sender, TreeViewEventArgs e) + { + if (e.Action != TreeViewAction.ByKeyboard && e.Action != TreeViewAction.ByMouse) + return; + TreeNode mainNode = treeView1.Nodes[0]; + if (e.Node == mainNode) + { + foreach (TreeNode node in mainNode.Nodes) + { + node.Checked = mainNode.Checked; + } + } + else + { + int sum = 0; + foreach (TreeNode node in mainNode.Nodes) + { + sum += node.Checked ? 1 : 0; + } + + if (sum == 0) + { + mainNode.Checked = false; + } + else if (sum == mainNode.Nodes.Count) + { + mainNode.Checked = true; + } + else + { + mainNode.Checked = false; + } + } + + } + + private void button1_Click(object sender, EventArgs e) + { + foreach(TreeNode node in treeView1.Nodes[0].Nodes) // [0] -> All Games + { + if (!node.Checked) + continue; + selectedTitles.Add(node.Text); + } + this.Close(); + } + } +} diff --git a/source/YuzuModDownloader/frmSelect.resx b/source/YuzuModDownloader/frmSelect.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/source/YuzuModDownloader/frmSelect.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file