From a55ad8f2b145d8b1e2abf8d3d8184d776685e435 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Dec 2022 19:21:54 +0000 Subject: [PATCH 01/13] Bump Newtonsoft.Json from 10.0.3 to 13.0.2 in /ForgeModBuilder Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 10.0.3 to 13.0.2. - [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases) - [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/10.0.3...13.0.2) --- updated-dependencies: - dependency-name: Newtonsoft.Json dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- ForgeModBuilder/packages.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ForgeModBuilder/packages.config b/ForgeModBuilder/packages.config index a25593c..9db1d0c 100644 --- a/ForgeModBuilder/packages.config +++ b/ForgeModBuilder/packages.config @@ -2,6 +2,6 @@ - + \ No newline at end of file From 3e7f74b3e703f2b7ace47bdbaca5d72b343e8660 Mon Sep 17 00:00:00 2001 From: "mend-bolt-for-github[bot]" <42819689+mend-bolt-for-github[bot]@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:45:15 +0000 Subject: [PATCH 02/13] Add .whitesource configuration file --- .whitesource | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .whitesource diff --git a/.whitesource b/.whitesource new file mode 100644 index 0000000..9c7ae90 --- /dev/null +++ b/.whitesource @@ -0,0 +1,14 @@ +{ + "scanSettings": { + "baseBranches": [] + }, + "checkRunSettings": { + "vulnerableCheckRunConclusionLevel": "failure", + "displayMode": "diff", + "useMendCheckNames": true + }, + "issueSettings": { + "minSeverityLevel": "LOW", + "issueType": "DEPENDENCY" + } +} \ No newline at end of file From f4b9a21ce4937c59364e51e65522a2ee9cd5d97a Mon Sep 17 00:00:00 2001 From: Adam Oswald Date: Wed, 20 Mar 2024 12:47:25 -0400 Subject: [PATCH 03/13] Update ForgeModBuilder.csproj --- ForgeModBuilder/ForgeModBuilder.csproj | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ForgeModBuilder/ForgeModBuilder.csproj b/ForgeModBuilder/ForgeModBuilder.csproj index ec5e4dd..5bc9a35 100644 --- a/ForgeModBuilder/ForgeModBuilder.csproj +++ b/ForgeModBuilder/ForgeModBuilder.csproj @@ -85,6 +85,12 @@ True + + ..\packages\WindowsAPICodePack-Core.1.1.1\lib\Microsoft.WindowsAPICodePack.dll + + + ..\packages\WindowsAPICodePack-Shell.1.1.1\lib\Microsoft.WindowsAPICodePack.Shell.dll + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll True @@ -217,4 +223,4 @@ --> - \ No newline at end of file + From 12d5653e56908574876a72a7537f979aafc99cb5 Mon Sep 17 00:00:00 2001 From: Adam Oswald Date: Wed, 20 Mar 2024 12:49:57 -0400 Subject: [PATCH 04/13] Update packages.config --- ForgeModBuilder/packages.config | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ForgeModBuilder/packages.config b/ForgeModBuilder/packages.config index a25593c..bcf9050 100644 --- a/ForgeModBuilder/packages.config +++ b/ForgeModBuilder/packages.config @@ -3,5 +3,7 @@ + + - \ No newline at end of file + From b565764b318893143e9f3f0c9eda153fb6ea2e3a Mon Sep 17 00:00:00 2001 From: Adam Oswald Date: Wed, 20 Mar 2024 12:50:23 -0400 Subject: [PATCH 05/13] Add files via upload --- ForgeModBuilder/NewProjectMenu.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ForgeModBuilder/NewProjectMenu.cs b/ForgeModBuilder/NewProjectMenu.cs index cfae1e3..88136fd 100644 --- a/ForgeModBuilder/NewProjectMenu.cs +++ b/ForgeModBuilder/NewProjectMenu.cs @@ -15,6 +15,7 @@ using Newtonsoft.Json; using System.Collections; using Newtonsoft.Json.Linq; +using Microsoft.WindowsAPICodePack.Dialogs; namespace ForgeModBuilder { @@ -418,10 +419,13 @@ public void DownloadSelectedVersion() string DownloadLink = downloadLinkNode.Attributes["href"].Value.Substring(48); //Remove the adfocus link as it breaks the download - find the direct download link Console.WriteLine("Found download link: " + DownloadLink); Program.INSTANCE.AddConsoleText("Found download link: " + DownloadLink); - FolderBrowserDialog fbd = new FolderBrowserDialog(); //Ask where they want to put the mod - if(fbd.ShowDialog() == DialogResult.OK) + CommonOpenFileDialog dialog = new CommonOpenFileDialog(); //Ask where they want to put the mod + + dialog.IsFolderPicker = true; + + if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { - if (System.IO.Directory.EnumerateFileSystemEntries(fbd.SelectedPath).Any()) //Make sure the folder is empty + if (System.IO.Directory.EnumerateFileSystemEntries(dialog.FileName).Any()) //Make sure the folder is empty { MessageBox.Show("The folder you selected has files in, please select another folder", "Invalid Folder", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -429,7 +433,7 @@ public void DownloadSelectedVersion() ProgressBarForm form = ProgressBarForm.ShowProgressBar("Downloading Project Src", "Downloading Src", new Font(Font.FontFamily, 16, FontStyle.Regular)); using (WebClient wc = new WebClient()) { - string[] Directory = fbd.SelectedPath.Split('\\'); + string[] Directory = dialog.FileName.Split('\\'); Directory[Directory.Length - 1] = ""; //Get the folder above the chosen folder wc.DownloadProgressChanged += (sender, e) => { @@ -448,12 +452,12 @@ public void DownloadSelectedVersion() File.Delete(string.Join("\\", Directory) + "temp.zip"); //Delete the zip file return; } - ZipFile.ExtractToDirectory(string.Join("\\", Directory) + "temp.zip", fbd.SelectedPath); //Extract the file - Console.WriteLine("Extracting file to " + fbd.SelectedPath); - Program.INSTANCE.AddConsoleText("Extracting file to " + fbd.SelectedPath); + ZipFile.ExtractToDirectory(string.Join("\\", Directory) + "temp.zip", dialog.FileName); //Extract the file + Console.WriteLine("Extracting file to " + dialog.FileName); + Program.INSTANCE.AddConsoleText("Extracting file to " + dialog.FileName); File.Delete(string.Join("\\", Directory) + "temp.zip"); //Delete the zip file - SetupBuildFile(fbd.SelectedPath); //Setup the build.gradle file - Program.INSTANCE.OpenProject(fbd.SelectedPath); //Open the project + SetupBuildFile(dialog.FileName); //Setup the build.gradle file + Program.INSTANCE.OpenProject(dialog.FileName); //Open the project if (MessageBox.Show("Would you like to setup now?", "Setup now?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Program.INSTANCE.SetupProject(""); //Setup the project From c484f4a23273bc84d3ff4af603bafd58e4071581 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 20 Mar 2024 16:50:38 +0000 Subject: [PATCH 06/13] Restyled by astyle --- ForgeModBuilder/NewProjectMenu.cs | 814 +++++++++++++++--------------- 1 file changed, 407 insertions(+), 407 deletions(-) diff --git a/ForgeModBuilder/NewProjectMenu.cs b/ForgeModBuilder/NewProjectMenu.cs index 88136fd..4d88c51 100644 --- a/ForgeModBuilder/NewProjectMenu.cs +++ b/ForgeModBuilder/NewProjectMenu.cs @@ -19,537 +19,537 @@ namespace ForgeModBuilder { - public partial class NewProjectMenu : Form +public partial class NewProjectMenu : Form +{ + //Show the form + public static DialogResult ShowNewProjectMenu() { - //Show the form - public static DialogResult ShowNewProjectMenu() - { - NewProjectMenu menu = new NewProjectMenu(); - return menu.ShowDialog(); - } + NewProjectMenu menu = new NewProjectMenu(); + return menu.ShowDialog(); + } - //The download URL for forge - public static string ForgeDownloadsURL = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/"; - // The url for all Minecraft versions - public static string MinecraftVersionURL = "https://launchermeta.mojang.com/mc/game/version_manifest.json"; + //The download URL for forge + public static string ForgeDownloadsURL = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/"; + // The url for all Minecraft versions + public static string MinecraftVersionURL = "https://launchermeta.mojang.com/mc/game/version_manifest.json"; - //Contains the latest minecraft version once synced - public static string LatestMinecraftVersion = ""; - //Stores all of the minecraft and forge versions once synced - public static Dictionary> Versions = new Dictionary>(); + //Contains the latest minecraft version once synced + public static string LatestMinecraftVersion = ""; + //Stores all of the minecraft and forge versions once synced + public static Dictionary> Versions = new Dictionary>(); - //The path to the versions.json file - private static string VersionsFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder/versions.json"; + //The path to the versions.json file + private static string VersionsFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder/versions.json"; - //Whether to sync - public static bool Sync = true; + //Whether to sync + public static bool Sync = true; - public NewProjectMenu() - { - InitializeComponent(); - LoadVersions(); - CancelButton = CancelSetupButton; - AcceptButton = CreateProjectButton; - } + public NewProjectMenu() + { + InitializeComponent(); + LoadVersions(); + CancelButton = CancelSetupButton; + AcceptButton = CreateProjectButton; + } - public static void SetupVersions() + public static void SetupVersions() + { + UpdateVersions(false, true); + if (Sync) { - UpdateVersions(false, true); - if (Sync) + if (Versions.Keys.Count == 0) { - if (Versions.Keys.Count == 0) + Console.WriteLine("Sycing versions!"); + Program.INSTANCE.AddConsoleText("Sycing versions!"); + SyncVersions(); + UpdateVersions(true, false); + } + else + { + HtmlWeb web = new HtmlWeb(); + HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL); + Dictionary checkVersions = new Dictionary(); + if(Program.INSTANCE.Options.ContainsKey("sync_versions")) { - Console.WriteLine("Sycing versions!"); - Program.INSTANCE.AddConsoleText("Sycing versions!"); - SyncVersions(); - UpdateVersions(true, false); + checkVersions = (Dictionary)Program.INSTANCE.Options["sync_versions"]; } - else - { - HtmlWeb web = new HtmlWeb(); - HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL); - Dictionary checkVersions = new Dictionary(); - if(Program.INSTANCE.Options.ContainsKey("sync_versions")) + foreach (string mcversion in Versions.Keys) { + if(checkVersions.Count != 0 && checkVersions.ContainsKey(mcversion)) { - checkVersions = (Dictionary)Program.INSTANCE.Options["sync_versions"]; - } - foreach (string mcversion in Versions.Keys) { - if(checkVersions.Count != 0 && checkVersions.ContainsKey(mcversion)) - { - if(!checkVersions[mcversion]) - { - continue; - } - } - document = web.Load(ForgeDownloadsURL + "index_" + mcversion + ".html"); - HtmlNode node = document.DocumentNode.SelectSingleNode("//td[@class='download-version']"); - string latestVersion = Regex.Replace(node.InnerHtml.Split('<')[0].Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty), @"\s+", "") + (node.InnerHtml.Contains("fa fa-star promo-recommended") ? "★" : ""); - if (Versions[mcversion].First() != latestVersion) - { - Console.WriteLine("Outdated list of forge versions for minecraft " + mcversion); - Program.INSTANCE.AddConsoleText("Outdated list of forge versions for minecraft " + mcversion); - SyncVersion(mcversion); - UpdateVersions(true, false); - } - else + if(!checkVersions[mcversion]) { - Console.WriteLine("No new forge versions found for minecraft " + mcversion); - Program.INSTANCE.AddConsoleText("No new forge versions found for minecraft " + mcversion); + continue; } } + document = web.Load(ForgeDownloadsURL + "index_" + mcversion + ".html"); + HtmlNode node = document.DocumentNode.SelectSingleNode("//td[@class='download-version']"); + string latestVersion = Regex.Replace(node.InnerHtml.Split('<')[0].Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty), @"\s+", "") + (node.InnerHtml.Contains("fa fa-star promo-recommended") ? "★" : ""); + if (Versions[mcversion].First() != latestVersion) + { + Console.WriteLine("Outdated list of forge versions for minecraft " + mcversion); + Program.INSTANCE.AddConsoleText("Outdated list of forge versions for minecraft " + mcversion); + SyncVersion(mcversion); + UpdateVersions(true, false); + } + else + { + Console.WriteLine("No new forge versions found for minecraft " + mcversion); + Program.INSTANCE.AddConsoleText("No new forge versions found for minecraft " + mcversion); + } } } - Sync = false; } + Sync = false; + } - public static void UpdateVersions(bool saveFile, bool readFromFile) + public static void UpdateVersions(bool saveFile, bool readFromFile) + { + if (saveFile) { - if (saveFile) + if(File.Exists(VersionsFilePath)) { - if(File.Exists(VersionsFilePath)) - { - JsonSerializer js = new JsonSerializer(); - js.NullValueHandling = NullValueHandling.Ignore; - using (StreamWriter sw = new StreamWriter(VersionsFilePath)) + JsonSerializer js = new JsonSerializer(); + js.NullValueHandling = NullValueHandling.Ignore; + using (StreamWriter sw = new StreamWriter(VersionsFilePath)) using (JsonWriter jw = new JsonTextWriter(sw)) { js.Serialize(jw, Versions); } - } - else + } + else + { + if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder")) { - if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder")) - { - Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder"); - } - File.Create(VersionsFilePath).Dispose(); - UpdateVersions(saveFile, readFromFile); + Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder"); } + File.Create(VersionsFilePath).Dispose(); + UpdateVersions(saveFile, readFromFile); } - if (readFromFile) + } + if (readFromFile) + { + if(File.Exists(VersionsFilePath)) { - if(File.Exists(VersionsFilePath)) - { - JsonSerializer js = new JsonSerializer(); - js.NullValueHandling = NullValueHandling.Ignore; - using (StreamReader sr = new StreamReader(VersionsFilePath)) + JsonSerializer js = new JsonSerializer(); + js.NullValueHandling = NullValueHandling.Ignore; + using (StreamReader sr = new StreamReader(VersionsFilePath)) using (JsonReader jr = new JsonTextReader(sr)) { Versions = js.Deserialize>>(jr); } - if(Versions == null) - { - Versions = new Dictionary>(); - } - if (Versions.Keys.Count > 0) + if(Versions == null) + { + Versions = new Dictionary>(); + } + if (Versions.Keys.Count > 0) + { + Version latest = new Version(Versions.Keys.First()); + LatestMinecraftVersion = Versions.Keys.First(); + Version current; + foreach (string version in Versions.Keys) { - Version latest = new Version(Versions.Keys.First()); - LatestMinecraftVersion = Versions.Keys.First(); - Version current; - foreach (string version in Versions.Keys) + current = new Version(version.Contains("_") ? version.Substring(0, version.IndexOf("_") - 1) : version); + if (latest.CompareTo(current) < 0) { - current = new Version(version.Contains("_") ? version.Substring(0, version.IndexOf("_") - 1) : version); - if (latest.CompareTo(current) < 0) - { - LatestMinecraftVersion = version; - latest = new Version(LatestMinecraftVersion); - } + LatestMinecraftVersion = version; + latest = new Version(LatestMinecraftVersion); } - Console.WriteLine("Latest version: " + LatestMinecraftVersion); } + Console.WriteLine("Latest version: " + LatestMinecraftVersion); } - else - { - if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder")) { - Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder"); - } - File.Create(VersionsFilePath).Dispose(); - UpdateVersions(saveFile, readFromFile); - } - } - Program.INSTANCE.SelectVersionsToCheckMenuItem.DropDownItems.Clear(); - Dictionary checkVersions = new Dictionary(); - if (Program.INSTANCE.Options.ContainsKey("sync_versions")) - { - checkVersions = (Dictionary)Program.INSTANCE.Options["sync_versions"]; } - foreach (string mcversion in Versions.Keys) + else { - ToolStripMenuItem menuItem = new ToolStripMenuItem(mcversion); - if (checkVersions.Count != 0 && checkVersions.ContainsKey(mcversion)) - { - menuItem.Checked = checkVersions[mcversion]; + if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder")) { + Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder"); } - menuItem.Click += (sender, args) => { - menuItem.Checked = !menuItem.Checked; - }; - Program.INSTANCE.SelectVersionsToCheckMenuItem.DropDownItems.Add(menuItem); + File.Create(VersionsFilePath).Dispose(); + UpdateVersions(saveFile, readFromFile); } } - - //Load the versions from the synced versions. Syncsing should have been done previously - public void LoadVersions() + Program.INSTANCE.SelectVersionsToCheckMenuItem.DropDownItems.Clear(); + Dictionary checkVersions = new Dictionary(); + if (Program.INSTANCE.Options.ContainsKey("sync_versions")) { - //Reset the holders of the versions - if(Versions.Count == 0) + checkVersions = (Dictionary)Program.INSTANCE.Options["sync_versions"]; + } + foreach (string mcversion in Versions.Keys) + { + ToolStripMenuItem menuItem = new ToolStripMenuItem(mcversion); + if (checkVersions.Count != 0 && checkVersions.ContainsKey(mcversion)) { - if (Sync) - { - SetupVersions(); - } else - { - return; - } + menuItem.Checked = checkVersions[mcversion]; } - MinecraftVersions.Items.Clear(); - ForgeVersions.Items.Clear(); - if(string.IsNullOrWhiteSpace(LatestMinecraftVersion)) + menuItem.Click += (sender, args) => { + menuItem.Checked = !menuItem.Checked; + }; + Program.INSTANCE.SelectVersionsToCheckMenuItem.DropDownItems.Add(menuItem); + } + } + + //Load the versions from the synced versions. Syncsing should have been done previously + public void LoadVersions() + { + //Reset the holders of the versions + if(Versions.Count == 0) + { + if (Sync) { - LatestMinecraftVersion = Versions.Keys.First(); - } - foreach(string mcversion in Versions.Keys) + SetupVersions(); + } else { - MinecraftVersions.Items.Add(mcversion); //Add each minecraft version + return; } - if (Versions.ContainsKey(LatestMinecraftVersion)) + } + MinecraftVersions.Items.Clear(); + ForgeVersions.Items.Clear(); + if(string.IsNullOrWhiteSpace(LatestMinecraftVersion)) + { + LatestMinecraftVersion = Versions.Keys.First(); + } + foreach(string mcversion in Versions.Keys) + { + MinecraftVersions.Items.Add(mcversion); //Add each minecraft version + } + if (Versions.ContainsKey(LatestMinecraftVersion)) + { + foreach (string forgeVersion in Versions[LatestMinecraftVersion]) { - foreach (string forgeVersion in Versions[LatestMinecraftVersion]) - { - ForgeVersions.Items.Add(forgeVersion); //Add each forge version - } + ForgeVersions.Items.Add(forgeVersion); //Add each forge version } - else + } + else + { + foreach (string forgeVersion in Versions[Versions.Keys.First()]) { - foreach (string forgeVersion in Versions[Versions.Keys.First()]) - { - ForgeVersions.Items.Add(forgeVersion); //Add each forge version - } + ForgeVersions.Items.Add(forgeVersion); //Add each forge version } - MinecraftVersions.SelectedIndex = 0; //Select the first minecraft version } + MinecraftVersions.SelectedIndex = 0; //Select the first minecraft version + } - //Load the versions from the forge web server - public static void SyncVersions() + //Load the versions from the forge web server + public static void SyncVersions() + { + Versions.Clear(); + LatestMinecraftVersion = ""; + try { - Versions.Clear(); - LatestMinecraftVersion = ""; - try + List MinecraftVersions = new List(); + //Create a nice looking progress bar to show how much has been got off the website + ProgressBarForm ProgressBar = ProgressBarForm.ShowProgressBar("Syncing Versions", "Syncing Versions", new Font(new FontFamily("Microsoft Sans Serif"), 16, FontStyle.Regular)); + // Get the minecraft versions + dynamic minecraftVersionsData = JObject.Parse(new WebClient().DownloadString(MinecraftVersionURL)); + // List minecraftVersions = new List(); // Store the versions which are releases. Some of these versions may not have a forge version + foreach (dynamic minecraftVersionData in minecraftVersionsData.versions) { - List MinecraftVersions = new List(); - //Create a nice looking progress bar to show how much has been got off the website - ProgressBarForm ProgressBar = ProgressBarForm.ShowProgressBar("Syncing Versions", "Syncing Versions", new Font(new FontFamily("Microsoft Sans Serif"), 16, FontStyle.Regular)); - // Get the minecraft versions - dynamic minecraftVersionsData = JObject.Parse(new WebClient().DownloadString(MinecraftVersionURL)); - // List minecraftVersions = new List(); // Store the versions which are releases. Some of these versions may not have a forge version - foreach (dynamic minecraftVersionData in minecraftVersionsData.versions) - { - if (minecraftVersionData.type == "release") - MinecraftVersions.Add((string)minecraftVersionData.id); - } - Console.WriteLine("Loaded minecraft versions from " + MinecraftVersionURL); - Program.INSTANCE.AddConsoleText("Loaded minecraft versions from " + MinecraftVersionURL); - LatestMinecraftVersion = MinecraftVersions[0]; + if (minecraftVersionData.type == "release") + MinecraftVersions.Add((string)minecraftVersionData.id); + } + Console.WriteLine("Loaded minecraft versions from " + MinecraftVersionURL); + Program.INSTANCE.AddConsoleText("Loaded minecraft versions from " + MinecraftVersionURL); + LatestMinecraftVersion = MinecraftVersions[0]; - //Create something which will access the website - HtmlWeb web = new HtmlWeb(); - // HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL); - HtmlAgilityPack.HtmlDocument document; - /* - LatestMinecraftVersion = document.DocumentNode.SelectSingleNode("//li[@class='elem-active']").InnerHtml; //Get the latest minecraft version - //MinecraftVersions.Add(LatestMinecraftVersion); - foreach (HtmlNode mcVersionNode in document.DocumentNode.SelectNodes("//li[@class='li-version-list']")) + //Create something which will access the website + HtmlWeb web = new HtmlWeb(); + // HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL); + HtmlAgilityPack.HtmlDocument document; + /* + LatestMinecraftVersion = document.DocumentNode.SelectSingleNode("//li[@class='elem-active']").InnerHtml; //Get the latest minecraft version + //MinecraftVersions.Add(LatestMinecraftVersion); + foreach (HtmlNode mcVersionNode in document.DocumentNode.SelectNodes("//li[@class='li-version-list']")) + { + foreach (HtmlNode subMcVersionNode in mcVersionNode.SelectNodes(".//li")) { - foreach (HtmlNode subMcVersionNode in mcVersionNode.SelectNodes(".//li")) + if (subMcVersionNode.HasChildNodes) { - if (subMcVersionNode.HasChildNodes) + foreach(HtmlNode node in subMcVersionNode.ChildNodes) { - foreach(HtmlNode node in subMcVersionNode.ChildNodes) + if(node.NodeType == HtmlNodeType.Element) { - if(node.NodeType == HtmlNodeType.Element) - { - MinecraftVersions.Add(node.InnerHtml); //Add each minecraft version - } + MinecraftVersions.Add(node.InnerHtml); //Add each minecraft version } } } } - */ - Version latestVersion = new Version(LatestMinecraftVersion); - Version mc; - foreach(string mcversion in MinecraftVersions.ToList()) - { - // mc = new Version(mcversion.Contains("_") ? mcversion.Substring(0, mcversion.IndexOf("_") - 1) : mcversion); - mc = new Version(mcversion); - if(latestVersion.CompareTo(mc) < 0) - { - MinecraftVersions.Insert(MinecraftVersions.IndexOf(mcversion), LatestMinecraftVersion); - MinecraftVersions.Remove(mcversion); - LatestMinecraftVersion = mcversion; - MinecraftVersions.Insert(0, mcversion); - } - } - if(latestVersion.CompareTo(new Version(LatestMinecraftVersion)) == 0) + } + */ + Version latestVersion = new Version(LatestMinecraftVersion); + Version mc; + foreach(string mcversion in MinecraftVersions.ToList()) + { + // mc = new Version(mcversion.Contains("_") ? mcversion.Substring(0, mcversion.IndexOf("_") - 1) : mcversion); + mc = new Version(mcversion); + if(latestVersion.CompareTo(mc) < 0) { - MinecraftVersions.Insert(0, LatestMinecraftVersion); + MinecraftVersions.Insert(MinecraftVersions.IndexOf(mcversion), LatestMinecraftVersion); + MinecraftVersions.Remove(mcversion); + LatestMinecraftVersion = mcversion; + MinecraftVersions.Insert(0, mcversion); } + } + if(latestVersion.CompareTo(new Version(LatestMinecraftVersion)) == 0) + { + MinecraftVersions.Insert(0, LatestMinecraftVersion); + } - foreach (string mcversion in MinecraftVersions) + foreach (string mcversion in MinecraftVersions) + { + Console.WriteLine(mcversion); + List forgeVersions = new List(); + try { - Console.WriteLine(mcversion); - List forgeVersions = new List(); - try + document = web.Load(ForgeDownloadsURL + "index_" + mcversion + ".html"); + foreach (HtmlNode forgeVersionNode in document.DocumentNode.SelectNodes("//td[@class='download-version']")) { - document = web.Load(ForgeDownloadsURL + "index_" + mcversion + ".html"); - foreach (HtmlNode forgeVersionNode in document.DocumentNode.SelectNodes("//td[@class='download-version']")) - { - //Load each forge version for every minecraft version - ProgressBar.ProgressBar.Value = (int)((document.DocumentNode.SelectNodes("//td[@class='download-version']").IndexOf(forgeVersionNode) + 1F) / document.DocumentNode.SelectNodes("//td[@class='download-version']").Count + (int)((MinecraftVersions.IndexOf(mcversion) + 1F) / MinecraftVersions.Count * 100)) - 1; - forgeVersions.Add(Regex.Replace(forgeVersionNode.InnerHtml.Split('<')[0].Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty), @"\s+", "") + (forgeVersionNode.InnerHtml.Contains("fa promo-recommended") ? "★" : "")); - } - Console.WriteLine(forgeVersions); - if (Versions.ContainsKey(mcversion)) - { - Versions.Remove(mcversion); - } - Versions.Add(mcversion, forgeVersions); - Console.WriteLine("Loaded forge versions from " + ForgeDownloadsURL + "index_" + mcversion + ".html"); - ForgeModBuilder.Program.INSTANCE.AddConsoleText("Loaded forge versions from " + ForgeDownloadsURL + "index_" + mcversion + ".html"); + //Load each forge version for every minecraft version + ProgressBar.ProgressBar.Value = (int)((document.DocumentNode.SelectNodes("//td[@class='download-version']").IndexOf(forgeVersionNode) + 1F) / document.DocumentNode.SelectNodes("//td[@class='download-version']").Count + (int)((MinecraftVersions.IndexOf(mcversion) + 1F) / MinecraftVersions.Count * 100)) - 1; + forgeVersions.Add(Regex.Replace(forgeVersionNode.InnerHtml.Split('<')[0].Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty), @"\s+", "") + (forgeVersionNode.InnerHtml.Contains("fa promo-recommended") ? "★" : "")); } - catch (NullReferenceException e) + Console.WriteLine(forgeVersions); + if (Versions.ContainsKey(mcversion)) { Versions.Remove(mcversion); - continue; } + Versions.Add(mcversion, forgeVersions); + Console.WriteLine("Loaded forge versions from " + ForgeDownloadsURL + "index_" + mcversion + ".html"); + ForgeModBuilder.Program.INSTANCE.AddConsoleText("Loaded forge versions from " + ForgeDownloadsURL + "index_" + mcversion + ".html"); + } + catch (NullReferenceException e) + { + Versions.Remove(mcversion); + continue; } - ProgressBar.Close(); //Close the progress bar - } - catch(Exception e) - { - Console.WriteLine("An error occurred:\n" + e.ToString()); - Program.INSTANCE.AddConsoleText("An error occurred:\n" + e.ToString()); } + ProgressBar.Close(); //Close the progress bar } + catch(Exception e) + { + Console.WriteLine("An error occurred:\n" + e.ToString()); + Program.INSTANCE.AddConsoleText("An error occurred:\n" + e.ToString()); + } + } - public static void SyncVersion(string mcversion) + public static void SyncVersion(string mcversion) + { + if(!Versions.ContainsKey(mcversion)) { - if(!Versions.ContainsKey(mcversion)) - { - Versions.Add(mcversion, new List()); - } - try - { - Versions[mcversion].Clear(); - HtmlWeb web = new HtmlWeb(); - HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL + "index_" + mcversion + ".html"); - foreach (HtmlNode forgeVersionNode in document.DocumentNode.SelectNodes("//td[@class='download-version']")) - { - string version = Regex.Replace(forgeVersionNode.InnerHtml.Split('<')[0].Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty), @"\s+", "") + (forgeVersionNode.InnerHtml.Contains("fa fa-star promo-recommended") ? "★" : ""); - if (Versions[mcversion].Contains(version)) - break; - Versions[mcversion].Add(version); - } - Console.WriteLine("Loaded forge versions from " + ForgeDownloadsURL + "index_" + mcversion + ".html"); - ForgeModBuilder.Program.INSTANCE.AddConsoleText("Loaded forge versions from " + ForgeDownloadsURL + "index_" + mcversion + ".html"); - } - catch (Exception e) + Versions.Add(mcversion, new List()); + } + try + { + Versions[mcversion].Clear(); + HtmlWeb web = new HtmlWeb(); + HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL + "index_" + mcversion + ".html"); + foreach (HtmlNode forgeVersionNode in document.DocumentNode.SelectNodes("//td[@class='download-version']")) { - Console.WriteLine("An error occurred:\n" + e.Message); - Program.INSTANCE.AddConsoleText("An error occurred:\n" + e.Message); + string version = Regex.Replace(forgeVersionNode.InnerHtml.Split('<')[0].Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty), @"\s+", "") + (forgeVersionNode.InnerHtml.Contains("fa fa-star promo-recommended") ? "★" : ""); + if (Versions[mcversion].Contains(version)) + break; + Versions[mcversion].Add(version); } + Console.WriteLine("Loaded forge versions from " + ForgeDownloadsURL + "index_" + mcversion + ".html"); + ForgeModBuilder.Program.INSTANCE.AddConsoleText("Loaded forge versions from " + ForgeDownloadsURL + "index_" + mcversion + ".html"); + } + catch (Exception e) + { + Console.WriteLine("An error occurred:\n" + e.Message); + Program.INSTANCE.AddConsoleText("An error occurred:\n" + e.Message); } + } - //Download the selected forge version and setup automatically - public void DownloadSelectedVersion() + //Download the selected forge version and setup automatically + public void DownloadSelectedVersion() + { + if(ForgeVersions.SelectedItem == null) //Make sure they selected a forge version { - if(ForgeVersions.SelectedItem == null) //Make sure they selected a forge version - { - MessageBox.Show("You need to select a forge version for the selected minecraft version to download", "Please choose a forge version", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if(ProjectName.Text == "Project Name") - { - MessageBox.Show("You need to set a name for your project", "Invalid Project Name", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if(ProjectVersion.Text == "Project Version") - { - MessageBox.Show("You need to set the initial version for your project", "Invalid Version", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if(ProjectGroupName.Text == "Project Group Name") - { - MessageBox.Show("You need to set a group name for your project", "Invalid Group Project Name", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if(JavaVersion.Text == "Java Version") - { - MessageBox.Show("You need to set a java version for your project", "Invalid Java Version", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - try + MessageBox.Show("You need to select a forge version for the selected minecraft version to download", "Please choose a forge version", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if(ProjectName.Text == "Project Name") + { + MessageBox.Show("You need to set a name for your project", "Invalid Project Name", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if(ProjectVersion.Text == "Project Version") + { + MessageBox.Show("You need to set the initial version for your project", "Invalid Version", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if(ProjectGroupName.Text == "Project Group Name") + { + MessageBox.Show("You need to set a group name for your project", "Invalid Group Project Name", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if(JavaVersion.Text == "Java Version") + { + MessageBox.Show("You need to set a java version for your project", "Invalid Java Version", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + HtmlWeb web = new HtmlWeb(); + HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL + "index_" + MinecraftVersions.SelectedItem + ".html"); //Find the download link from the slected version + foreach(HtmlNode downloadNode in document.DocumentNode.SelectNodes("//tr")) { - HtmlWeb web = new HtmlWeb(); - HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL + "index_" + MinecraftVersions.SelectedItem + ".html"); //Find the download link from the slected version - foreach(HtmlNode downloadNode in document.DocumentNode.SelectNodes("//tr")) + if(downloadNode.HasChildNodes && downloadNode.ChildNodes[1].InnerText.Contains(((string) ForgeVersions.SelectedItem).Split('★')[0])) //If it is the correct version { - if(downloadNode.HasChildNodes && downloadNode.ChildNodes[1].InnerText.Contains(((string) ForgeVersions.SelectedItem).Split('★')[0])) //If it is the correct version + HtmlNode downloadLinkNode = null; //Find the correct download link + try + { + downloadLinkNode = downloadNode.SelectSingleNode(".//i[contains(@class, 'classifier-mdk')]").ParentNode; + } + catch + { + + } + if(downloadLinkNode == null) { - HtmlNode downloadLinkNode = null; //Find the correct download link try { - downloadLinkNode = downloadNode.SelectSingleNode(".//i[contains(@class, 'classifier-mdk')]").ParentNode; + downloadLinkNode = downloadNode.SelectSingleNode(".//i[contains(@class, 'classifier-src')]").ParentNode; } catch { } - if(downloadLinkNode == null) + } + if(downloadLinkNode != null) + { + string DownloadLink = downloadLinkNode.Attributes["href"].Value.Substring(48); //Remove the adfocus link as it breaks the download - find the direct download link + Console.WriteLine("Found download link: " + DownloadLink); + Program.INSTANCE.AddConsoleText("Found download link: " + DownloadLink); + CommonOpenFileDialog dialog = new CommonOpenFileDialog(); //Ask where they want to put the mod + + dialog.IsFolderPicker = true; + + if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { - try - { - downloadLinkNode = downloadNode.SelectSingleNode(".//i[contains(@class, 'classifier-src')]").ParentNode; - } - catch + if (System.IO.Directory.EnumerateFileSystemEntries(dialog.FileName).Any()) //Make sure the folder is empty { - + MessageBox.Show("The folder you selected has files in, please select another folder", "Invalid Folder", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; } - } - if(downloadLinkNode != null) - { - string DownloadLink = downloadLinkNode.Attributes["href"].Value.Substring(48); //Remove the adfocus link as it breaks the download - find the direct download link - Console.WriteLine("Found download link: " + DownloadLink); - Program.INSTANCE.AddConsoleText("Found download link: " + DownloadLink); - CommonOpenFileDialog dialog = new CommonOpenFileDialog(); //Ask where they want to put the mod - - dialog.IsFolderPicker = true; - - if (dialog.ShowDialog() == CommonFileDialogResult.Ok) + ProgressBarForm form = ProgressBarForm.ShowProgressBar("Downloading Project Src", "Downloading Src", new Font(Font.FontFamily, 16, FontStyle.Regular)); + using (WebClient wc = new WebClient()) { - if (System.IO.Directory.EnumerateFileSystemEntries(dialog.FileName).Any()) //Make sure the folder is empty + string[] Directory = dialog.FileName.Split('\\'); + Directory[Directory.Length - 1] = ""; //Get the folder above the chosen folder + wc.DownloadProgressChanged += (sender, e) => { - MessageBox.Show("The folder you selected has files in, please select another folder", "Invalid Folder", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - ProgressBarForm form = ProgressBarForm.ShowProgressBar("Downloading Project Src", "Downloading Src", new Font(Font.FontFamily, 16, FontStyle.Regular)); - using (WebClient wc = new WebClient()) + form.ProgressBar.Value = e.ProgressPercentage; //Update progress bar based on how much has been downloaded + }; + wc.DownloadFileCompleted += (sender, e) => { - string[] Directory = dialog.FileName.Split('\\'); - Directory[Directory.Length - 1] = ""; //Get the folder above the chosen folder - wc.DownloadProgressChanged += (sender, e) => - { - form.ProgressBar.Value = e.ProgressPercentage; //Update progress bar based on how much has been downloaded - }; - wc.DownloadFileCompleted += (sender, e) => + form.Close(); + Close(); + Console.WriteLine("Downloaded file to " + string.Join("\\", Directory) + "temp.zip"); + Program.INSTANCE.AddConsoleText("Downloaded file to " + string.Join("\\", Directory) + "temp.zip"); + if (e.Error != null) { - form.Close(); - Close(); - Console.WriteLine("Downloaded file to " + string.Join("\\", Directory) + "temp.zip"); - Program.INSTANCE.AddConsoleText("Downloaded file to " + string.Join("\\", Directory) + "temp.zip"); - if (e.Error != null) - { - Console.WriteLine("An error occurred:\n" + e.Error); - Program.INSTANCE.AddConsoleText("An error occurred:\n" + e.Error); - File.Delete(string.Join("\\", Directory) + "temp.zip"); //Delete the zip file - return; - } - ZipFile.ExtractToDirectory(string.Join("\\", Directory) + "temp.zip", dialog.FileName); //Extract the file - Console.WriteLine("Extracting file to " + dialog.FileName); - Program.INSTANCE.AddConsoleText("Extracting file to " + dialog.FileName); + Console.WriteLine("An error occurred:\n" + e.Error); + Program.INSTANCE.AddConsoleText("An error occurred:\n" + e.Error); File.Delete(string.Join("\\", Directory) + "temp.zip"); //Delete the zip file - SetupBuildFile(dialog.FileName); //Setup the build.gradle file - Program.INSTANCE.OpenProject(dialog.FileName); //Open the project - if (MessageBox.Show("Would you like to setup now?", "Setup now?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - Program.INSTANCE.SetupProject(""); //Setup the project - } - }; - wc.DownloadFileAsync(new Uri(DownloadLink), string.Join("\\", Directory) + "temp.zip"); //Start the download - while (wc.IsBusy) { } - } - } - else - { - return; + return; + } + ZipFile.ExtractToDirectory(string.Join("\\", Directory) + "temp.zip", dialog.FileName); //Extract the file + Console.WriteLine("Extracting file to " + dialog.FileName); + Program.INSTANCE.AddConsoleText("Extracting file to " + dialog.FileName); + File.Delete(string.Join("\\", Directory) + "temp.zip"); //Delete the zip file + SetupBuildFile(dialog.FileName); //Setup the build.gradle file + Program.INSTANCE.OpenProject(dialog.FileName); //Open the project + if (MessageBox.Show("Would you like to setup now?", "Setup now?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + Program.INSTANCE.SetupProject(""); //Setup the project + } + }; + wc.DownloadFileAsync(new Uri(DownloadLink), string.Join("\\", Directory) + "temp.zip"); //Start the download + while (wc.IsBusy) { } } } + else + { + return; + } } } } - catch (Exception e) - { - Console.WriteLine("An error occurred:\n" + (string)e.Message); - Program.INSTANCE.AddConsoleText("An error occurred:\n" + (string)e.Message); - } } + catch (Exception e) + { + Console.WriteLine("An error occurred:\n" + (string)e.Message); + Program.INSTANCE.AddConsoleText("An error occurred:\n" + (string)e.Message); + } + } - //Setup all of the values in the build.gradle file - private void SetupBuildFile(string path) + //Setup all of the values in the build.gradle file + private void SetupBuildFile(string path) + { + Console.WriteLine("Setting up build file!"); + Program.INSTANCE.AddConsoleText("Setting up build file!"); + foreach (string file in Directory.GetFiles(path)) //Find the build.gradle file in the directory { - Console.WriteLine("Setting up build file!"); - Program.INSTANCE.AddConsoleText("Setting up build file!"); - foreach (string file in Directory.GetFiles(path)) //Find the build.gradle file in the directory + if (file.Contains("build.gradle")) { - if (file.Contains("build.gradle")) + string[] oldData = File.ReadAllLines(file); //Read all of the data in the file + string[] newData = new string[oldData.Length]; + bool firstVersion = true; + bool firstGroup = true; + int index = 0; + foreach(string line in oldData) { - string[] oldData = File.ReadAllLines(file); //Read all of the data in the file - string[] newData = new string[oldData.Length]; - bool firstVersion = true; - bool firstGroup = true; - int index = 0; - foreach(string line in oldData) + if (line.Contains("sourceCompatibility") && line.Contains("targetCompatibility")) { - if (line.Contains("sourceCompatibility") && line.Contains("targetCompatibility")) - { - newData[index] = Regex.Replace(line, "\'.*\'", "\'" + JavaVersion.Text + "\'"); //Set the java version - index++; - continue; - } - if (line.Contains("version") && firstVersion) - { - newData[index] = Regex.Replace(line, "\".*\"", "\"" + ProjectVersion.Text + "\""); //Set the project version - index++; - firstVersion = false; - continue; - } - if (line.Contains("archivesBaseName")) - { - newData[index] = Regex.Replace(line, "\".*\"", "\"" + ProjectName.Text + "\""); //Set the project name - index++; - continue; - } - if (line.Contains("group") && firstGroup) - { - newData[index] = Regex.Replace(line, "\".*\"", "\"" + ProjectGroupName.Text + "\""); //Set the project group name - index++; - firstGroup = false; - continue; - } - newData[index] = line; + newData[index] = Regex.Replace(line, "\'.*\'", "\'" + JavaVersion.Text + "\'"); //Set the java version + index++; + continue; + } + if (line.Contains("version") && firstVersion) + { + newData[index] = Regex.Replace(line, "\".*\"", "\"" + ProjectVersion.Text + "\""); //Set the project version index++; + firstVersion = false; + continue; } - StreamWriter w = new StreamWriter(file); - foreach (string line in newData) + if (line.Contains("archivesBaseName")) { - w.WriteLine(line); //Write the file + newData[index] = Regex.Replace(line, "\".*\"", "\"" + ProjectName.Text + "\""); //Set the project name + index++; + continue; } - w.Close(); + if (line.Contains("group") && firstGroup) + { + newData[index] = Regex.Replace(line, "\".*\"", "\"" + ProjectGroupName.Text + "\""); //Set the project group name + index++; + firstGroup = false; + continue; + } + newData[index] = line; + index++; + } + StreamWriter w = new StreamWriter(file); + foreach (string line in newData) + { + w.WriteLine(line); //Write the file } + w.Close(); } } + } - //Show the correct forge versions for the given minecraft version - private void MinecraftVersions_SelectedIndexChanged(object sender, EventArgs e) + //Show the correct forge versions for the given minecraft version + private void MinecraftVersions_SelectedIndexChanged(object sender, EventArgs e) + { + ForgeVersions.Items.Clear(); + foreach(string forgeVersion in Versions[MinecraftVersions.SelectedItem.ToString()]) { - ForgeVersions.Items.Clear(); - foreach(string forgeVersion in Versions[MinecraftVersions.SelectedItem.ToString()]) - { - ForgeVersions.Items.Add(forgeVersion); - } + ForgeVersions.Items.Add(forgeVersion); } + } - private void CreateProjectButton_Click(object sender, EventArgs e) - { - DownloadSelectedVersion(); - } + private void CreateProjectButton_Click(object sender, EventArgs e) + { + DownloadSelectedVersion(); } } +} From 5463564e31ff9657035aade883fd06db1749025f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 20 Mar 2024 16:50:49 +0000 Subject: [PATCH 07/13] Restyled by clang-format --- ForgeModBuilder/NewProjectMenu.cs | 1037 +++++++++++++++-------------- 1 file changed, 546 insertions(+), 491 deletions(-) diff --git a/ForgeModBuilder/NewProjectMenu.cs b/ForgeModBuilder/NewProjectMenu.cs index 4d88c51..e9fcf25 100644 --- a/ForgeModBuilder/NewProjectMenu.cs +++ b/ForgeModBuilder/NewProjectMenu.cs @@ -17,539 +17,594 @@ using Newtonsoft.Json.Linq; using Microsoft.WindowsAPICodePack.Dialogs; -namespace ForgeModBuilder -{ -public partial class NewProjectMenu : Form -{ - //Show the form - public static DialogResult ShowNewProjectMenu() - { - NewProjectMenu menu = new NewProjectMenu(); - return menu.ShowDialog(); - } +namespace ForgeModBuilder { +public partial class NewProjectMenu : Form { + // Show the form + public static DialogResult ShowNewProjectMenu() { + NewProjectMenu menu = new NewProjectMenu(); + return menu.ShowDialog(); + } - //The download URL for forge - public static string ForgeDownloadsURL = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/"; - // The url for all Minecraft versions - public static string MinecraftVersionURL = "https://launchermeta.mojang.com/mc/game/version_manifest.json"; + // The download URL for forge + public static string ForgeDownloadsURL = + "http://files.minecraftforge.net/maven/net/minecraftforge/forge/"; + // The url for all Minecraft versions + public static string MinecraftVersionURL = + "https://launchermeta.mojang.com/mc/game/version_manifest.json"; - //Contains the latest minecraft version once synced - public static string LatestMinecraftVersion = ""; - //Stores all of the minecraft and forge versions once synced - public static Dictionary> Versions = new Dictionary>(); + // Contains the latest minecraft version once synced + public static string LatestMinecraftVersion = ""; + // Stores all of the minecraft and forge versions once synced + public static Dictionary> Versions = + new Dictionary>(); - //The path to the versions.json file - private static string VersionsFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder/versions.json"; + // The path to the versions.json file + private static string VersionsFilePath = + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + + "/ForgeModBuilder/versions.json"; - //Whether to sync - public static bool Sync = true; + // Whether to sync + public static bool Sync = true; - public NewProjectMenu() - { - InitializeComponent(); - LoadVersions(); - CancelButton = CancelSetupButton; - AcceptButton = CreateProjectButton; - } - - public static void SetupVersions() - { - UpdateVersions(false, true); - if (Sync) - { - if (Versions.Keys.Count == 0) - { - Console.WriteLine("Sycing versions!"); - Program.INSTANCE.AddConsoleText("Sycing versions!"); - SyncVersions(); - UpdateVersions(true, false); - } - else - { - HtmlWeb web = new HtmlWeb(); - HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL); - Dictionary checkVersions = new Dictionary(); - if(Program.INSTANCE.Options.ContainsKey("sync_versions")) - { - checkVersions = (Dictionary)Program.INSTANCE.Options["sync_versions"]; - } - foreach (string mcversion in Versions.Keys) { - if(checkVersions.Count != 0 && checkVersions.ContainsKey(mcversion)) - { - if(!checkVersions[mcversion]) - { - continue; - } - } - document = web.Load(ForgeDownloadsURL + "index_" + mcversion + ".html"); - HtmlNode node = document.DocumentNode.SelectSingleNode("//td[@class='download-version']"); - string latestVersion = Regex.Replace(node.InnerHtml.Split('<')[0].Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty), @"\s+", "") + (node.InnerHtml.Contains("fa fa-star promo-recommended") ? "★" : ""); - if (Versions[mcversion].First() != latestVersion) - { - Console.WriteLine("Outdated list of forge versions for minecraft " + mcversion); - Program.INSTANCE.AddConsoleText("Outdated list of forge versions for minecraft " + mcversion); - SyncVersion(mcversion); - UpdateVersions(true, false); - } - else - { - Console.WriteLine("No new forge versions found for minecraft " + mcversion); - Program.INSTANCE.AddConsoleText("No new forge versions found for minecraft " + mcversion); - } - } - } - } - Sync = false; - } + public NewProjectMenu() { + InitializeComponent(); + LoadVersions(); + CancelButton = CancelSetupButton; + AcceptButton = CreateProjectButton; + } - public static void UpdateVersions(bool saveFile, bool readFromFile) - { - if (saveFile) - { - if(File.Exists(VersionsFilePath)) - { - JsonSerializer js = new JsonSerializer(); - js.NullValueHandling = NullValueHandling.Ignore; - using (StreamWriter sw = new StreamWriter(VersionsFilePath)) - using (JsonWriter jw = new JsonTextWriter(sw)) - { - js.Serialize(jw, Versions); - } - } - else - { - if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder")) - { - Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder"); - } - File.Create(VersionsFilePath).Dispose(); - UpdateVersions(saveFile, readFromFile); - } - } - if (readFromFile) - { - if(File.Exists(VersionsFilePath)) - { - JsonSerializer js = new JsonSerializer(); - js.NullValueHandling = NullValueHandling.Ignore; - using (StreamReader sr = new StreamReader(VersionsFilePath)) - using (JsonReader jr = new JsonTextReader(sr)) - { - Versions = js.Deserialize>>(jr); - } - if(Versions == null) - { - Versions = new Dictionary>(); - } - if (Versions.Keys.Count > 0) - { - Version latest = new Version(Versions.Keys.First()); - LatestMinecraftVersion = Versions.Keys.First(); - Version current; - foreach (string version in Versions.Keys) - { - current = new Version(version.Contains("_") ? version.Substring(0, version.IndexOf("_") - 1) : version); - if (latest.CompareTo(current) < 0) - { - LatestMinecraftVersion = version; - latest = new Version(LatestMinecraftVersion); - } - } - Console.WriteLine("Latest version: " + LatestMinecraftVersion); - } - } - else - { - if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder")) { - Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder"); - } - File.Create(VersionsFilePath).Dispose(); - UpdateVersions(saveFile, readFromFile); - } - } - Program.INSTANCE.SelectVersionsToCheckMenuItem.DropDownItems.Clear(); + public static void SetupVersions() { + UpdateVersions(false, true); + if (Sync) { + if (Versions.Keys.Count == 0) { + Console.WriteLine("Sycing versions!"); + Program.INSTANCE.AddConsoleText("Sycing versions!"); + SyncVersions(); + UpdateVersions(true, false); + } else { + HtmlWeb web = new HtmlWeb(); + HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL); Dictionary checkVersions = new Dictionary(); - if (Program.INSTANCE.Options.ContainsKey("sync_versions")) - { - checkVersions = (Dictionary)Program.INSTANCE.Options["sync_versions"]; + if (Program.INSTANCE.Options.ContainsKey("sync_versions")) { + checkVersions = (Dictionary) + Program.INSTANCE.Options["sync_versions"]; } - foreach (string mcversion in Versions.Keys) - { - ToolStripMenuItem menuItem = new ToolStripMenuItem(mcversion); - if (checkVersions.Count != 0 && checkVersions.ContainsKey(mcversion)) - { - menuItem.Checked = checkVersions[mcversion]; + foreach (string mcversion in Versions.Keys) { + if (checkVersions.Count != 0 && + checkVersions.ContainsKey(mcversion)) { + if (!checkVersions[mcversion]) { + continue; } - menuItem.Click += (sender, args) => { - menuItem.Checked = !menuItem.Checked; - }; - Program.INSTANCE.SelectVersionsToCheckMenuItem.DropDownItems.Add(menuItem); + } + document = + web.Load(ForgeDownloadsURL + "index_" + mcversion + ".html"); + HtmlNode node = document.DocumentNode.SelectSingleNode( + "//td[@class='download-version']"); + string latestVersion = + Regex.Replace(node.InnerHtml.Split('<') [0] + .Replace(" ", string.Empty) + .Replace(Environment.NewLine, string.Empty), + @"\s+", "") + + (node.InnerHtml.Contains("fa fa-star promo-recommended") ? "★" + : ""); + if (Versions[mcversion].First() != latestVersion) { + Console.WriteLine("Outdated list of forge versions for minecraft " + + mcversion); + Program.INSTANCE.AddConsoleText( + "Outdated list of forge versions for minecraft " + mcversion); + SyncVersion(mcversion); + UpdateVersions(true, false); + } else { + Console.WriteLine("No new forge versions found for minecraft " + + mcversion); + Program.INSTANCE.AddConsoleText( + "No new forge versions found for minecraft " + mcversion); + } } + } } + Sync = false; + } - //Load the versions from the synced versions. Syncsing should have been done previously - public void LoadVersions() - { - //Reset the holders of the versions - if(Versions.Count == 0) - { - if (Sync) - { - SetupVersions(); - } else - { - return; - } + public static void UpdateVersions(bool saveFile, bool readFromFile) { + if (saveFile) { + if (File.Exists(VersionsFilePath)) { + JsonSerializer js = new JsonSerializer(); + js.NullValueHandling = NullValueHandling.Ignore; + using (StreamWriter sw = new StreamWriter(VersionsFilePath)) using ( + JsonWriter jw = new JsonTextWriter(sw)) { + js.Serialize(jw, Versions); } - MinecraftVersions.Items.Clear(); - ForgeVersions.Items.Clear(); - if(string.IsNullOrWhiteSpace(LatestMinecraftVersion)) - { - LatestMinecraftVersion = Versions.Keys.First(); + } else { + if (!Directory.Exists(Environment.GetFolderPath( + Environment.SpecialFolder.ApplicationData) + + "/ForgeModBuilder")) { + Directory.CreateDirectory( + Environment.GetFolderPath( + Environment.SpecialFolder.ApplicationData) + + "/ForgeModBuilder"); } - foreach(string mcversion in Versions.Keys) - { - MinecraftVersions.Items.Add(mcversion); //Add each minecraft version + File.Create(VersionsFilePath).Dispose(); + UpdateVersions(saveFile, readFromFile); + } + } + if (readFromFile) { + if (File.Exists(VersionsFilePath)) { + JsonSerializer js = new JsonSerializer(); + js.NullValueHandling = NullValueHandling.Ignore; + using (StreamReader sr = new StreamReader(VersionsFilePath)) using ( + JsonReader jr = new JsonTextReader(sr)) { + Versions = js.Deserialize>>(jr); } - if (Versions.ContainsKey(LatestMinecraftVersion)) - { - foreach (string forgeVersion in Versions[LatestMinecraftVersion]) - { - ForgeVersions.Items.Add(forgeVersion); //Add each forge version - } + if (Versions == null) { + Versions = new Dictionary>(); } - else - { - foreach (string forgeVersion in Versions[Versions.Keys.First()]) - { - ForgeVersions.Items.Add(forgeVersion); //Add each forge version + if (Versions.Keys.Count > 0) { + Version latest = new Version(Versions.Keys.First()); + LatestMinecraftVersion = Versions.Keys.First(); + Version current; + foreach (string version in Versions.Keys) { + current = + new Version(version.Contains("_") + ? version.Substring(0, version.IndexOf("_") - 1) + : version); + if (latest.CompareTo(current) < 0) { + LatestMinecraftVersion = version; + latest = new Version(LatestMinecraftVersion); } + } + Console.WriteLine("Latest version: " + LatestMinecraftVersion); + } + } else { + if (!Directory.Exists(Environment.GetFolderPath( + Environment.SpecialFolder.ApplicationData) + + "/ForgeModBuilder")) { + Directory.CreateDirectory( + Environment.GetFolderPath( + Environment.SpecialFolder.ApplicationData) + + "/ForgeModBuilder"); } - MinecraftVersions.SelectedIndex = 0; //Select the first minecraft version + File.Create(VersionsFilePath).Dispose(); + UpdateVersions(saveFile, readFromFile); + } + } + Program.INSTANCE.SelectVersionsToCheckMenuItem.DropDownItems.Clear(); + Dictionary checkVersions = new Dictionary(); + if (Program.INSTANCE.Options.ContainsKey("sync_versions")) { + checkVersions = + (Dictionary)Program.INSTANCE.Options["sync_versions"]; } + foreach (string mcversion in Versions.Keys) { + ToolStripMenuItem menuItem = new ToolStripMenuItem(mcversion); + if (checkVersions.Count != 0 && checkVersions.ContainsKey(mcversion)) { + menuItem.Checked = checkVersions[mcversion]; + } + menuItem.Click += + (sender, args) => { menuItem.Checked = !menuItem.Checked; }; + Program.INSTANCE.SelectVersionsToCheckMenuItem.DropDownItems.Add( + menuItem); + } + } - //Load the versions from the forge web server - public static void SyncVersions() - { - Versions.Clear(); - LatestMinecraftVersion = ""; - try - { - List MinecraftVersions = new List(); - //Create a nice looking progress bar to show how much has been got off the website - ProgressBarForm ProgressBar = ProgressBarForm.ShowProgressBar("Syncing Versions", "Syncing Versions", new Font(new FontFamily("Microsoft Sans Serif"), 16, FontStyle.Regular)); - // Get the minecraft versions - dynamic minecraftVersionsData = JObject.Parse(new WebClient().DownloadString(MinecraftVersionURL)); - // List minecraftVersions = new List(); // Store the versions which are releases. Some of these versions may not have a forge version - foreach (dynamic minecraftVersionData in minecraftVersionsData.versions) - { - if (minecraftVersionData.type == "release") - MinecraftVersions.Add((string)minecraftVersionData.id); - } - Console.WriteLine("Loaded minecraft versions from " + MinecraftVersionURL); - Program.INSTANCE.AddConsoleText("Loaded minecraft versions from " + MinecraftVersionURL); - LatestMinecraftVersion = MinecraftVersions[0]; + // Load the versions from the synced versions. Syncsing should have been done + // previously + public void LoadVersions() { + // Reset the holders of the versions + if (Versions.Count == 0) { + if (Sync) { + SetupVersions(); + } else { + return; + } + } + MinecraftVersions.Items.Clear(); + ForgeVersions.Items.Clear(); + if (string.IsNullOrWhiteSpace(LatestMinecraftVersion)) { + LatestMinecraftVersion = Versions.Keys.First(); + } + foreach (string mcversion in Versions.Keys) { + MinecraftVersions.Items.Add(mcversion); // Add each minecraft version + } + if (Versions.ContainsKey(LatestMinecraftVersion)) { + foreach (string forgeVersion in Versions[LatestMinecraftVersion]) { + ForgeVersions.Items.Add(forgeVersion); // Add each forge version + } + } else { + foreach (string forgeVersion in Versions[Versions.Keys.First()]) { + ForgeVersions.Items.Add(forgeVersion); // Add each forge version + } + } + MinecraftVersions.SelectedIndex = 0; // Select the first minecraft version + } - //Create something which will access the website - HtmlWeb web = new HtmlWeb(); - // HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL); - HtmlAgilityPack.HtmlDocument document; - /* - LatestMinecraftVersion = document.DocumentNode.SelectSingleNode("//li[@class='elem-active']").InnerHtml; //Get the latest minecraft version - //MinecraftVersions.Add(LatestMinecraftVersion); - foreach (HtmlNode mcVersionNode in document.DocumentNode.SelectNodes("//li[@class='li-version-list']")) - { - foreach (HtmlNode subMcVersionNode in mcVersionNode.SelectNodes(".//li")) - { - if (subMcVersionNode.HasChildNodes) - { - foreach(HtmlNode node in subMcVersionNode.ChildNodes) - { - if(node.NodeType == HtmlNodeType.Element) - { - MinecraftVersions.Add(node.InnerHtml); //Add each minecraft version - } - } - } - } - } - */ - Version latestVersion = new Version(LatestMinecraftVersion); - Version mc; - foreach(string mcversion in MinecraftVersions.ToList()) - { - // mc = new Version(mcversion.Contains("_") ? mcversion.Substring(0, mcversion.IndexOf("_") - 1) : mcversion); - mc = new Version(mcversion); - if(latestVersion.CompareTo(mc) < 0) - { - MinecraftVersions.Insert(MinecraftVersions.IndexOf(mcversion), LatestMinecraftVersion); - MinecraftVersions.Remove(mcversion); - LatestMinecraftVersion = mcversion; - MinecraftVersions.Insert(0, mcversion); - } - } - if(latestVersion.CompareTo(new Version(LatestMinecraftVersion)) == 0) - { - MinecraftVersions.Insert(0, LatestMinecraftVersion); - } + // Load the versions from the forge web server + public static void SyncVersions() { + Versions.Clear(); + LatestMinecraftVersion = ""; + try { + List MinecraftVersions = new List(); + // Create a nice looking progress bar to show how much has been got off + // the website + ProgressBarForm ProgressBar = ProgressBarForm.ShowProgressBar( + "Syncing Versions", "Syncing Versions", + new Font(new FontFamily("Microsoft Sans Serif"), 16, + FontStyle.Regular)); + // Get the minecraft versions + dynamic minecraftVersionsData = + JObject.Parse(new WebClient().DownloadString(MinecraftVersionURL)); + // List minecraftVersions = new List(); // Store the + // versions which are releases. Some of these versions may not have a + // forge version + foreach (dynamic minecraftVersionData in minecraftVersionsData.versions) { + if (minecraftVersionData.type == "release") + MinecraftVersions.Add((string)minecraftVersionData.id); + } + Console.WriteLine("Loaded minecraft versions from " + + MinecraftVersionURL); + Program.INSTANCE.AddConsoleText("Loaded minecraft versions from " + + MinecraftVersionURL); + LatestMinecraftVersion = MinecraftVersions[0]; - foreach (string mcversion in MinecraftVersions) - { - Console.WriteLine(mcversion); - List forgeVersions = new List(); - try - { - document = web.Load(ForgeDownloadsURL + "index_" + mcversion + ".html"); - foreach (HtmlNode forgeVersionNode in document.DocumentNode.SelectNodes("//td[@class='download-version']")) - { - //Load each forge version for every minecraft version - ProgressBar.ProgressBar.Value = (int)((document.DocumentNode.SelectNodes("//td[@class='download-version']").IndexOf(forgeVersionNode) + 1F) / document.DocumentNode.SelectNodes("//td[@class='download-version']").Count + (int)((MinecraftVersions.IndexOf(mcversion) + 1F) / MinecraftVersions.Count * 100)) - 1; - forgeVersions.Add(Regex.Replace(forgeVersionNode.InnerHtml.Split('<')[0].Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty), @"\s+", "") + (forgeVersionNode.InnerHtml.Contains("fa promo-recommended") ? "★" : "")); - } - Console.WriteLine(forgeVersions); - if (Versions.ContainsKey(mcversion)) - { - Versions.Remove(mcversion); - } - Versions.Add(mcversion, forgeVersions); - Console.WriteLine("Loaded forge versions from " + ForgeDownloadsURL + "index_" + mcversion + ".html"); - ForgeModBuilder.Program.INSTANCE.AddConsoleText("Loaded forge versions from " + ForgeDownloadsURL + "index_" + mcversion + ".html"); - } - catch (NullReferenceException e) - { - Versions.Remove(mcversion); - continue; - } - } - ProgressBar.Close(); //Close the progress bar + // Create something which will access the website + HtmlWeb web = new HtmlWeb(); + // HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL); + HtmlAgilityPack.HtmlDocument document; + /* + LatestMinecraftVersion = + document.DocumentNode.SelectSingleNode("//li[@class='elem-active']").InnerHtml; + //Get the latest minecraft version + //MinecraftVersions.Add(LatestMinecraftVersion); + foreach (HtmlNode mcVersionNode in + document.DocumentNode.SelectNodes("//li[@class='li-version-list']")) + { + foreach (HtmlNode subMcVersionNode in + mcVersionNode.SelectNodes(".//li")) + { + if (subMcVersionNode.HasChildNodes) + { + foreach(HtmlNode node in subMcVersionNode.ChildNodes) + { + if(node.NodeType == HtmlNodeType.Element) + { + MinecraftVersions.Add(node.InnerHtml); //Add each + minecraft version + } + } + } + } + } + */ + Version latestVersion = new Version(LatestMinecraftVersion); + Version mc; + foreach (string mcversion in MinecraftVersions.ToList()) { + // mc = new Version(mcversion.Contains("_") ? mcversion.Substring(0, + // mcversion.IndexOf("_") - 1) : mcversion); + mc = new Version(mcversion); + if (latestVersion.CompareTo(mc) < 0) { + MinecraftVersions.Insert(MinecraftVersions.IndexOf(mcversion), + LatestMinecraftVersion); + MinecraftVersions.Remove(mcversion); + LatestMinecraftVersion = mcversion; + MinecraftVersions.Insert(0, mcversion); } - catch(Exception e) - { - Console.WriteLine("An error occurred:\n" + e.ToString()); - Program.INSTANCE.AddConsoleText("An error occurred:\n" + e.ToString()); + } + if (latestVersion.CompareTo(new Version(LatestMinecraftVersion)) == 0) { + MinecraftVersions.Insert(0, LatestMinecraftVersion); + } + + foreach (string mcversion in MinecraftVersions) { + Console.WriteLine(mcversion); + List forgeVersions = new List(); + try { + document = + web.Load(ForgeDownloadsURL + "index_" + mcversion + ".html"); + foreach (HtmlNode forgeVersionNode in document.DocumentNode + .SelectNodes("//td[@class='download-version']")) { + // Load each forge version for every minecraft version + ProgressBar.ProgressBar.Value = + (int)((document.DocumentNode + .SelectNodes("//td[@class='download-version']") + .IndexOf(forgeVersionNode) + + 1F) / + document.DocumentNode + .SelectNodes("//td[@class='download-version']") + .Count + + (int)((MinecraftVersions.IndexOf(mcversion) + 1F) / + MinecraftVersions.Count * 100)) - + 1; + forgeVersions.Add( + Regex.Replace(forgeVersionNode.InnerHtml.Split('<') [0] + .Replace(" ", string.Empty) + .Replace(Environment.NewLine, string.Empty), + @"\s+", "") + + (forgeVersionNode.InnerHtml.Contains("fa promo-recommended") + ? "★" + : "")); + } + Console.WriteLine(forgeVersions); + if (Versions.ContainsKey(mcversion)) { + Versions.Remove(mcversion); + } + Versions.Add(mcversion, forgeVersions); + Console.WriteLine("Loaded forge versions from " + ForgeDownloadsURL + + "index_" + mcversion + ".html"); + ForgeModBuilder.Program.INSTANCE.AddConsoleText( + "Loaded forge versions from " + ForgeDownloadsURL + "index_" + + mcversion + ".html"); + } catch (NullReferenceException e) { + Versions.Remove(mcversion); + continue; } + } + ProgressBar.Close(); // Close the progress bar + } catch (Exception e) { + Console.WriteLine("An error occurred:\n" + e.ToString()); + Program.INSTANCE.AddConsoleText("An error occurred:\n" + e.ToString()); } + } - public static void SyncVersion(string mcversion) - { - if(!Versions.ContainsKey(mcversion)) - { - Versions.Add(mcversion, new List()); - } - try - { - Versions[mcversion].Clear(); - HtmlWeb web = new HtmlWeb(); - HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL + "index_" + mcversion + ".html"); - foreach (HtmlNode forgeVersionNode in document.DocumentNode.SelectNodes("//td[@class='download-version']")) - { - string version = Regex.Replace(forgeVersionNode.InnerHtml.Split('<')[0].Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty), @"\s+", "") + (forgeVersionNode.InnerHtml.Contains("fa fa-star promo-recommended") ? "★" : ""); - if (Versions[mcversion].Contains(version)) - break; - Versions[mcversion].Add(version); - } - Console.WriteLine("Loaded forge versions from " + ForgeDownloadsURL + "index_" + mcversion + ".html"); - ForgeModBuilder.Program.INSTANCE.AddConsoleText("Loaded forge versions from " + ForgeDownloadsURL + "index_" + mcversion + ".html"); - } - catch (Exception e) - { - Console.WriteLine("An error occurred:\n" + e.Message); - Program.INSTANCE.AddConsoleText("An error occurred:\n" + e.Message); - } + public static void SyncVersion(string mcversion) { + if (!Versions.ContainsKey(mcversion)) { + Versions.Add(mcversion, new List()); + } + try { + Versions[mcversion].Clear(); + HtmlWeb web = new HtmlWeb(); + HtmlAgilityPack.HtmlDocument document = + web.Load(ForgeDownloadsURL + "index_" + mcversion + ".html"); + foreach (HtmlNode forgeVersionNode in document.DocumentNode.SelectNodes( + "//td[@class='download-version']")) { + string version = + Regex.Replace(forgeVersionNode.InnerHtml.Split('<') [0] + .Replace(" ", string.Empty) + .Replace(Environment.NewLine, string.Empty), + @"\s+", "") + + (forgeVersionNode.InnerHtml.Contains("fa fa-star promo-recommended") + ? "★" + : ""); + if (Versions[mcversion].Contains(version)) + break; + Versions[mcversion].Add(version); + } + Console.WriteLine("Loaded forge versions from " + ForgeDownloadsURL + + "index_" + mcversion + ".html"); + ForgeModBuilder.Program.INSTANCE.AddConsoleText( + "Loaded forge versions from " + ForgeDownloadsURL + "index_" + + mcversion + ".html"); + } catch (Exception e) { + Console.WriteLine("An error occurred:\n" + e.Message); + Program.INSTANCE.AddConsoleText("An error occurred:\n" + e.Message); } + } - //Download the selected forge version and setup automatically - public void DownloadSelectedVersion() + // Download the selected forge version and setup automatically + public void DownloadSelectedVersion() { + if (ForgeVersions.SelectedItem == + null) // Make sure they selected a forge version { - if(ForgeVersions.SelectedItem == null) //Make sure they selected a forge version - { - MessageBox.Show("You need to select a forge version for the selected minecraft version to download", "Please choose a forge version", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if(ProjectName.Text == "Project Name") - { - MessageBox.Show("You need to set a name for your project", "Invalid Project Name", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if(ProjectVersion.Text == "Project Version") - { - MessageBox.Show("You need to set the initial version for your project", "Invalid Version", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if(ProjectGroupName.Text == "Project Group Name") - { - MessageBox.Show("You need to set a group name for your project", "Invalid Group Project Name", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if(JavaVersion.Text == "Java Version") - { - MessageBox.Show("You need to set a java version for your project", "Invalid Java Version", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - try + MessageBox.Show( + "You need to select a forge version for the selected minecraft version to download", + "Please choose a forge version", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (ProjectName.Text == "Project Name") { + MessageBox.Show("You need to set a name for your project", + "Invalid Project Name", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (ProjectVersion.Text == "Project Version") { + MessageBox.Show("You need to set the initial version for your project", + "Invalid Version", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (ProjectGroupName.Text == "Project Group Name") { + MessageBox.Show("You need to set a group name for your project", + "Invalid Group Project Name", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (JavaVersion.Text == "Java Version") { + MessageBox.Show("You need to set a java version for your project", + "Invalid Java Version", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + try { + HtmlWeb web = new HtmlWeb(); + HtmlAgilityPack.HtmlDocument document = web.Load( + ForgeDownloadsURL + "index_" + MinecraftVersions.SelectedItem + + ".html"); // Find the download link from the slected version + foreach (HtmlNode downloadNode in document.DocumentNode.SelectNodes( + "//tr")) { + if (downloadNode.HasChildNodes && + downloadNode.ChildNodes[1].InnerText.Contains( + ((string)ForgeVersions.SelectedItem) + .Split('★')[0])) // If it is the correct version { - HtmlWeb web = new HtmlWeb(); - HtmlAgilityPack.HtmlDocument document = web.Load(ForgeDownloadsURL + "index_" + MinecraftVersions.SelectedItem + ".html"); //Find the download link from the slected version - foreach(HtmlNode downloadNode in document.DocumentNode.SelectNodes("//tr")) - { - if(downloadNode.HasChildNodes && downloadNode.ChildNodes[1].InnerText.Contains(((string) ForgeVersions.SelectedItem).Split('★')[0])) //If it is the correct version - { - HtmlNode downloadLinkNode = null; //Find the correct download link - try - { - downloadLinkNode = downloadNode.SelectSingleNode(".//i[contains(@class, 'classifier-mdk')]").ParentNode; - } - catch - { - - } - if(downloadLinkNode == null) - { - try - { - downloadLinkNode = downloadNode.SelectSingleNode(".//i[contains(@class, 'classifier-src')]").ParentNode; - } - catch - { - - } - } - if(downloadLinkNode != null) - { - string DownloadLink = downloadLinkNode.Attributes["href"].Value.Substring(48); //Remove the adfocus link as it breaks the download - find the direct download link - Console.WriteLine("Found download link: " + DownloadLink); - Program.INSTANCE.AddConsoleText("Found download link: " + DownloadLink); - CommonOpenFileDialog dialog = new CommonOpenFileDialog(); //Ask where they want to put the mod + HtmlNode downloadLinkNode = null; // Find the correct download link + try { + downloadLinkNode = + downloadNode + .SelectSingleNode( + ".//i[contains(@class, 'classifier-mdk')]") + .ParentNode; + } catch { + } + if (downloadLinkNode == null) { + try { + downloadLinkNode = + downloadNode + .SelectSingleNode( + ".//i[contains(@class, 'classifier-src')]") + .ParentNode; + } catch { + } + } + if (downloadLinkNode != null) { + string DownloadLink = + downloadLinkNode.Attributes["href"].Value.Substring( + 48); // Remove the adfocus link as it breaks the download - + // find the direct download link + Console.WriteLine("Found download link: " + DownloadLink); + Program.INSTANCE.AddConsoleText("Found download link: " + + DownloadLink); + CommonOpenFileDialog dialog = + new CommonOpenFileDialog(); // Ask where they want to put the + // mod - dialog.IsFolderPicker = true; + dialog.IsFolderPicker = true; - if (dialog.ShowDialog() == CommonFileDialogResult.Ok) - { - if (System.IO.Directory.EnumerateFileSystemEntries(dialog.FileName).Any()) //Make sure the folder is empty - { - MessageBox.Show("The folder you selected has files in, please select another folder", "Invalid Folder", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - ProgressBarForm form = ProgressBarForm.ShowProgressBar("Downloading Project Src", "Downloading Src", new Font(Font.FontFamily, 16, FontStyle.Regular)); - using (WebClient wc = new WebClient()) - { - string[] Directory = dialog.FileName.Split('\\'); - Directory[Directory.Length - 1] = ""; //Get the folder above the chosen folder - wc.DownloadProgressChanged += (sender, e) => - { - form.ProgressBar.Value = e.ProgressPercentage; //Update progress bar based on how much has been downloaded - }; - wc.DownloadFileCompleted += (sender, e) => - { - form.Close(); - Close(); - Console.WriteLine("Downloaded file to " + string.Join("\\", Directory) + "temp.zip"); - Program.INSTANCE.AddConsoleText("Downloaded file to " + string.Join("\\", Directory) + "temp.zip"); - if (e.Error != null) - { - Console.WriteLine("An error occurred:\n" + e.Error); - Program.INSTANCE.AddConsoleText("An error occurred:\n" + e.Error); - File.Delete(string.Join("\\", Directory) + "temp.zip"); //Delete the zip file - return; - } - ZipFile.ExtractToDirectory(string.Join("\\", Directory) + "temp.zip", dialog.FileName); //Extract the file - Console.WriteLine("Extracting file to " + dialog.FileName); - Program.INSTANCE.AddConsoleText("Extracting file to " + dialog.FileName); - File.Delete(string.Join("\\", Directory) + "temp.zip"); //Delete the zip file - SetupBuildFile(dialog.FileName); //Setup the build.gradle file - Program.INSTANCE.OpenProject(dialog.FileName); //Open the project - if (MessageBox.Show("Would you like to setup now?", "Setup now?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - Program.INSTANCE.SetupProject(""); //Setup the project - } - }; - wc.DownloadFileAsync(new Uri(DownloadLink), string.Join("\\", Directory) + "temp.zip"); //Start the download - while (wc.IsBusy) { } - } - } - else - { - return; - } - } + if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { + if (System.IO.Directory + .EnumerateFileSystemEntries(dialog.FileName) + .Any()) // Make sure the folder is empty + { + MessageBox.Show( + "The folder you selected has files in, please select another folder", + "Invalid Folder", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + ProgressBarForm form = ProgressBarForm.ShowProgressBar( + "Downloading Project Src", "Downloading Src", + new Font(Font.FontFamily, 16, FontStyle.Regular)); + using (WebClient wc = new WebClient()) { + string[] Directory = dialog.FileName.Split('\\'); + Directory[Directory.Length - 1] = + ""; // Get the folder above the chosen folder + wc.DownloadProgressChanged += (sender, e) => { + form.ProgressBar.Value = + e.ProgressPercentage; // Update progress bar based on how + // much has been downloaded + }; + wc.DownloadFileCompleted += (sender, e) => { + form.Close(); + Close(); + Console.WriteLine("Downloaded file to " + + string.Join("\\", Directory) + "temp.zip"); + Program.INSTANCE.AddConsoleText("Downloaded file to " + + string.Join("\\", Directory) + + "temp.zip"); + if (e.Error != null) { + Console.WriteLine("An error occurred:\n" + e.Error); + Program.INSTANCE.AddConsoleText("An error occurred:\n" + + e.Error); + File.Delete(string.Join("\\", Directory) + + "temp.zip"); // Delete the zip file + return; + } + ZipFile.ExtractToDirectory( + string.Join("\\", Directory) + "temp.zip", + dialog.FileName); // Extract the file + Console.WriteLine("Extracting file to " + dialog.FileName); + Program.INSTANCE.AddConsoleText("Extracting file to " + + dialog.FileName); + File.Delete(string.Join("\\", Directory) + + "temp.zip"); // Delete the zip file + SetupBuildFile(dialog.FileName); // Setup the build.gradle + // file + Program.INSTANCE.OpenProject( + dialog.FileName); // Open the project + if (MessageBox.Show("Would you like to setup now?", + "Setup now?", MessageBoxButtons.YesNo, + MessageBoxIcon.Question) == + DialogResult.Yes) { + Program.INSTANCE.SetupProject(""); // Setup the project + } + }; + wc.DownloadFileAsync(new Uri(DownloadLink), + string.Join("\\", Directory) + + "temp.zip"); // Start the download + while (wc.IsBusy) { } + } + } else { + return; } + } } - catch (Exception e) - { - Console.WriteLine("An error occurred:\n" + (string)e.Message); - Program.INSTANCE.AddConsoleText("An error occurred:\n" + (string)e.Message); - } + } + } catch (Exception e) { + Console.WriteLine("An error occurred:\n" + (string)e.Message); + Program.INSTANCE.AddConsoleText("An error occurred:\n" + + (string)e.Message); } + } - //Setup all of the values in the build.gradle file - private void SetupBuildFile(string path) + // Setup all of the values in the build.gradle file + private void SetupBuildFile(string path) { + Console.WriteLine("Setting up build file!"); + Program.INSTANCE.AddConsoleText("Setting up build file!"); + foreach (string file in Directory.GetFiles( + path)) // Find the build.gradle file in the directory { - Console.WriteLine("Setting up build file!"); - Program.INSTANCE.AddConsoleText("Setting up build file!"); - foreach (string file in Directory.GetFiles(path)) //Find the build.gradle file in the directory - { - if (file.Contains("build.gradle")) - { - string[] oldData = File.ReadAllLines(file); //Read all of the data in the file - string[] newData = new string[oldData.Length]; - bool firstVersion = true; - bool firstGroup = true; - int index = 0; - foreach(string line in oldData) - { - if (line.Contains("sourceCompatibility") && line.Contains("targetCompatibility")) - { - newData[index] = Regex.Replace(line, "\'.*\'", "\'" + JavaVersion.Text + "\'"); //Set the java version - index++; - continue; - } - if (line.Contains("version") && firstVersion) - { - newData[index] = Regex.Replace(line, "\".*\"", "\"" + ProjectVersion.Text + "\""); //Set the project version - index++; - firstVersion = false; - continue; - } - if (line.Contains("archivesBaseName")) - { - newData[index] = Regex.Replace(line, "\".*\"", "\"" + ProjectName.Text + "\""); //Set the project name - index++; - continue; - } - if (line.Contains("group") && firstGroup) - { - newData[index] = Regex.Replace(line, "\".*\"", "\"" + ProjectGroupName.Text + "\""); //Set the project group name - index++; - firstGroup = false; - continue; - } - newData[index] = line; - index++; - } - StreamWriter w = new StreamWriter(file); - foreach (string line in newData) - { - w.WriteLine(line); //Write the file - } - w.Close(); - } + if (file.Contains("build.gradle")) { + string[] oldData = + File.ReadAllLines(file); // Read all of the data in the file + string[] newData = new string[oldData.Length]; + bool firstVersion = true; + bool firstGroup = true; + int index = 0; + foreach (string line in oldData) { + if (line.Contains("sourceCompatibility") && + line.Contains("targetCompatibility")) { + newData[index] = Regex.Replace(line, "\'.*\'", + "\'" + JavaVersion.Text + + "\'"); // Set the java version + index++; + continue; + } + if (line.Contains("version") && firstVersion) { + newData[index] = Regex.Replace(line, "\".*\"", + "\"" + ProjectVersion.Text + + "\""); // Set the project version + index++; + firstVersion = false; + continue; + } + if (line.Contains("archivesBaseName")) { + newData[index] = Regex.Replace(line, "\".*\"", + "\"" + ProjectName.Text + + "\""); // Set the project name + index++; + continue; + } + if (line.Contains("group") && firstGroup) { + newData[index] = + Regex.Replace(line, "\".*\"", + "\"" + ProjectGroupName.Text + + "\""); // Set the project group name + index++; + firstGroup = false; + continue; + } + newData[index] = line; + index++; } - } - - //Show the correct forge versions for the given minecraft version - private void MinecraftVersions_SelectedIndexChanged(object sender, EventArgs e) - { - ForgeVersions.Items.Clear(); - foreach(string forgeVersion in Versions[MinecraftVersions.SelectedItem.ToString()]) - { - ForgeVersions.Items.Add(forgeVersion); + StreamWriter w = new StreamWriter(file); + foreach (string line in newData) { + w.WriteLine(line); // Write the file } + w.Close(); + } } + } - private void CreateProjectButton_Click(object sender, EventArgs e) - { - DownloadSelectedVersion(); + // Show the correct forge versions for the given minecraft version + private void MinecraftVersions_SelectedIndexChanged(object sender, + EventArgs e) { + ForgeVersions.Items.Clear(); + foreach (string forgeVersion in + Versions[MinecraftVersions.SelectedItem.ToString()]) { + ForgeVersions.Items.Add(forgeVersion); } + } + + private void CreateProjectButton_Click(object sender, EventArgs e) { + DownloadSelectedVersion(); + } } } From 96ad61400376340f4e64a0331744d1fe8cf76e60 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 20 Mar 2024 16:50:50 +0000 Subject: [PATCH 08/13] Restyled by whitespace --- ForgeModBuilder/ForgeModBuilder.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ForgeModBuilder/ForgeModBuilder.csproj b/ForgeModBuilder/ForgeModBuilder.csproj index 5bc9a35..02e2479 100644 --- a/ForgeModBuilder/ForgeModBuilder.csproj +++ b/ForgeModBuilder/ForgeModBuilder.csproj @@ -216,7 +216,7 @@ - - + \ No newline at end of file diff --git a/ForgeModBuilder/packages.config b/ForgeModBuilder/packages.config index bcf9050..24ae187 100644 --- a/ForgeModBuilder/packages.config +++ b/ForgeModBuilder/packages.config @@ -2,8 +2,8 @@ - + - + \ No newline at end of file From 915a7991c5761e042ba11a38a78b301d27329a71 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 20 Mar 2024 16:59:45 +0000 Subject: [PATCH 12/13] Restyled by whitespace --- ForgeModBuilder/packages.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ForgeModBuilder/packages.config b/ForgeModBuilder/packages.config index b3ee25a..f76da3b 100644 --- a/ForgeModBuilder/packages.config +++ b/ForgeModBuilder/packages.config @@ -6,4 +6,4 @@ - \ No newline at end of file + From b0b88e822bac5930bd0b804d14d4c3081592f5f0 Mon Sep 17 00:00:00 2001 From: Adam Oswald Date: Wed, 20 Mar 2024 13:13:35 -0400 Subject: [PATCH 13/13] Delete .whitesource --- .whitesource | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 .whitesource diff --git a/.whitesource b/.whitesource deleted file mode 100644 index 9c7ae90..0000000 --- a/.whitesource +++ /dev/null @@ -1,14 +0,0 @@ -{ - "scanSettings": { - "baseBranches": [] - }, - "checkRunSettings": { - "vulnerableCheckRunConclusionLevel": "failure", - "displayMode": "diff", - "useMendCheckNames": true - }, - "issueSettings": { - "minSeverityLevel": "LOW", - "issueType": "DEPENDENCY" - } -} \ No newline at end of file