diff --git a/GCMM/Configuration.cs b/GCMM/Configuration.cs new file mode 100644 index 0000000..962ae15 --- /dev/null +++ b/GCMM/Configuration.cs @@ -0,0 +1,23 @@ +using System.IO; +using Newtonsoft.Json; + +namespace GCMM +{ + public class Configuration + { + public string GamePath { get; set; } + public AutoPatchingState AutoPatch { get; set; } = AutoPatchingState.Unspecified; + + public static Configuration Load() + { + if (File.Exists("configuration.json")) + return JsonConvert.DeserializeObject(File.ReadAllText("configuration.json")); + return new Configuration(); + } + + public void Save() + { + File.WriteAllText("configuration.json", JsonConvert.SerializeObject(this)); + } + } +} \ No newline at end of file diff --git a/GCMM/CustomMessageBox.cs b/GCMM/CustomMessageBox.cs index 1662e0c..aedb083 100644 --- a/GCMM/CustomMessageBox.cs +++ b/GCMM/CustomMessageBox.cs @@ -1,15 +1,4 @@ -using GCMM.Properties; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using System.Windows.Forms; +using System.Windows.Forms; namespace GCMM { diff --git a/GCMM/GCMM.csproj b/GCMM/GCMM.csproj index 212bdbd..9bf00d3 100644 --- a/GCMM/GCMM.csproj +++ b/GCMM/GCMM.csproj @@ -38,18 +38,6 @@ Form - - True - True - Settings.settings - - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - \ No newline at end of file diff --git a/GCMM/MainForm.cs b/GCMM/MainForm.cs index ff092d8..f5edf1a 100644 --- a/GCMM/MainForm.cs +++ b/GCMM/MainForm.cs @@ -1,16 +1,10 @@ -using GCMM.Properties; -using Newtonsoft.Json.Linq; -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.IO; -using System.IO.Compression; using System.Linq; -using System.Net; -using System.Reflection; -using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; @@ -22,7 +16,10 @@ namespace GCMM { InitializeComponent(); resources = new ComponentResourceManager(typeof(MainForm)); + Configuration = Configuration.Load(); } + + public Configuration Configuration { get; } private readonly ComponentResourceManager resources; private readonly Dictionary mods = new Dictionary(); @@ -58,40 +55,34 @@ You may also want to verify the game's files in the launcher. public async Task LoadEverything(bool evenMods) { - if (Settings.Default.NeedsUpdate) - { - Settings.Default.Upgrade(); - Settings.Default.NeedsUpdate = false; - Settings.Default.Save(); - } modlist.Items.Clear(); mods.Clear(); //This method may get called twice when ran from the command line UpdateButton(installbtn, false); modinfobox.Text = defaultInfo; - if (string.IsNullOrWhiteSpace(Settings.Default.GamePath) || GetExe() == null) + if (string.IsNullOrWhiteSpace(Configuration.GamePath) || GetExe() == null) { - Settings.Default.GamePath = GetGameFolder(); - if (string.IsNullOrWhiteSpace(Settings.Default.GamePath)) + Configuration.GamePath = GetGameFolder(); + if (string.IsNullOrWhiteSpace(Configuration.GamePath)) { DialogUtils.ShowWarning(resources.GetString("Game_not_found"), ""); - Settings.Default.GamePath = SelectGameFolder(); + Configuration.GamePath = SelectGameFolder(); } else - DialogUtils.ShowInfo(string.Format(resources.GetString("Found_game_at"), Settings.Default.GamePath), ""); - Settings.Default.Save(); + DialogUtils.ShowInfo(string.Format(resources.GetString("Found_game_at"), Configuration.GamePath), ""); + Configuration.Save(); } - if (Settings.Default.AutoLaunch == AutoPatchingState.Unspecified) - { - Settings.Default.AutoLaunch = AutoPatchingState.Disabled; - if (DialogUtils.ShowYesNoQuestion(resources.GetString("Change_launch_settings_question"), - resources.GetString("Change_launch_settings_title"))) - EnableDisableAutoPatchingWithDialog(true); - } - if(string.IsNullOrWhiteSpace(Settings.Default.GamePath)) + if(string.IsNullOrWhiteSpace(Configuration.GamePath)) { status.Text = resources.GetString("Status_Game_not_found"); return; } + if (Configuration.AutoPatch == AutoPatchingState.Unspecified) + { + Configuration.AutoPatch = AutoPatchingState.Disabled; + if (DialogUtils.ShowYesNoQuestion(resources.GetString("Change_launch_settings_question"), + resources.GetString("Change_launch_settings_title"))) + EnableDisableAutoPatchingWithDialog(true); + } DeleteEmptyPluginsDir(out bool pexists, out bool dexists); if (!pexists && dexists) unpatched.Checked = true; //It will call the event but that won't do anything diff --git a/GCMM/MainModInstaller.cs b/GCMM/MainModInstaller.cs index 6128c1b..cd18cdd 100644 --- a/GCMM/MainModInstaller.cs +++ b/GCMM/MainModInstaller.cs @@ -1,11 +1,9 @@ -using GCMM.Properties; -using Newtonsoft.Json; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; -using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -57,7 +55,7 @@ namespace GCMM if (!modFound) if (MessageBox.Show("The mod was not found in the downloaded archive. It likely means it's using a different name for the dll file. The mod manager will not be able to track this mod if you continue. Do you want to continue?", "Mod not found in archive", MessageBoxButtons.YesNo) == DialogResult.No) return; - ExtractMod(archive, pluginOnly ? plugins.FullName : Settings.Default.GamePath, mod); + ExtractMod(archive, pluginOnly ? plugins.FullName : Configuration.GamePath, mod); } File.Delete(tmppath); } diff --git a/GCMM/MainModList.cs b/GCMM/MainModList.cs index 6cea0cc..ab1799f 100644 --- a/GCMM/MainModList.cs +++ b/GCMM/MainModList.cs @@ -1,5 +1,4 @@ -using GCMM.Properties; -using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Diagnostics; @@ -8,7 +7,6 @@ using System.IO; using System.Linq; using System.Net; using System.Reflection; -using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; diff --git a/GCMM/MainPatcher.cs b/GCMM/MainPatcher.cs index 44e3cfb..e0a00eb 100644 --- a/GCMM/MainPatcher.cs +++ b/GCMM/MainPatcher.cs @@ -1,16 +1,11 @@ -using GCMM.Properties; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; +using System; using System.Diagnostics; using System.IO.Compression; using System.IO; using System.Linq; using System.Net; -using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -using System.Reflection; namespace GCMM { @@ -117,7 +112,7 @@ namespace GCMM await client.DownloadFileTaskAsync(url, "IPA.zip"); using (var fs = new FileStream("IPA.zip", FileMode.Open)) using (var za = new ZipArchive(fs)) - za.ExtractToDirectory(Settings.Default.GamePath, true); //Overwrite files that were left from a previous install of the patcher + za.ExtractToDirectory(Configuration.GamePath, true); //Overwrite files that were left from a previous install of the patcher File.Delete("IPA.zip"); } } @@ -139,7 +134,7 @@ namespace GCMM UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true, - WorkingDirectory = Settings.Default.GamePath, + WorkingDirectory = Configuration.GamePath, CreateNoWindow = true }; var process = Process.Start(psi); diff --git a/GCMM/MainUtils.cs b/GCMM/MainUtils.cs index 18bc29d..8e02a7b 100644 --- a/GCMM/MainUtils.cs +++ b/GCMM/MainUtils.cs @@ -1,14 +1,9 @@ -using GCMM.Properties; -using Microsoft.Win32; -using System; -using System.Collections.Generic; +using System; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Net; -using System.Text; -using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; @@ -63,7 +58,7 @@ namespace GCMM { DialogUtils.ShowInfo(resources.GetString("Change_launch_settings_done"), resources.GetString("Change_launch_settings_title")); - Settings.Default.AutoLaunch = enable ? AutoPatchingState.Enabled : AutoPatchingState.Disabled; + Configuration.AutoPatch = enable ? AutoPatchingState.Enabled : AutoPatchingState.Disabled; } else DialogUtils.ShowError(resources.GetString("Change_launch_settings_error"), @@ -155,8 +150,6 @@ namespace GCMM public WebClient GetClient() { var client = new WebClient(); - if (!Settings.Default.UseProxy) - client.Proxy = null; client.Headers.Clear(); client.Headers[HttpRequestHeader.Accept] = "application/json"; client.BaseAddress = "https://git.exmods.org"; @@ -198,7 +191,7 @@ namespace GCMM /// public string GamePath(string path, string gamepath = null) { - return ((gamepath ?? Settings.Default.GamePath) + path).Replace('\\', Path.DirectorySeparatorChar); + return ((gamepath ?? Configuration.GamePath) + path).Replace('\\', Path.DirectorySeparatorChar); } public string GetExe(string path = null) diff --git a/GCMM/Properties/Settings.Designer.cs b/GCMM/Properties/Settings.Designer.cs deleted file mode 100644 index eb611aa..0000000 --- a/GCMM/Properties/Settings.Designer.cs +++ /dev/null @@ -1,98 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace GCMM.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string GamePath { - get { - return ((string)(this["GamePath"])); - } - set { - this["GamePath"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string WinePath { - get { - return ((string)(this["WinePath"])); - } - set { - this["WinePath"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("False")] - public bool UseProxy { - get { - return ((bool)(this["UseProxy"])); - } - set { - this["UseProxy"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("True")] - public bool NeedsUpdate { - get { - return ((bool)(this["NeedsUpdate"])); - } - set { - this["NeedsUpdate"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("0")] - public int SteamUserID { - get { - return ((int)(this["SteamUserID"])); - } - set { - this["SteamUserID"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("0")] - public AutoPatchingState AutoLaunch { - get { - return ((AutoPatchingState)(this["AutoLaunch"])); - } - set { - this["AutoLaunch"] = value; - } - } - } -} diff --git a/GCMM/Properties/Settings.settings b/GCMM/Properties/Settings.settings deleted file mode 100644 index b88984e..0000000 --- a/GCMM/Properties/Settings.settings +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - False - - - True - - - 0 - - - 0 - - - - diff --git a/GCMM/SettingsForm.Designer.cs b/GCMM/SettingsForm.Designer.cs index 77f6065..c11354f 100644 --- a/GCMM/SettingsForm.Designer.cs +++ b/GCMM/SettingsForm.Designer.cs @@ -23,8 +23,8 @@ #region Windows Form Designer generated code /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. /// private void InitializeComponent() { @@ -34,14 +34,13 @@ this.browsebtn = new System.Windows.Forms.Button(); this.savebtn = new System.Windows.Forms.Button(); this.cancelbtn = new System.Windows.Forms.Button(); - this.useProxy = new System.Windows.Forms.CheckBox(); this.autopatching = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (238))); this.label1.Location = new System.Drawing.Point(12, 15); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(116, 20); @@ -70,7 +69,7 @@ // this.savebtn.DialogResult = System.Windows.Forms.DialogResult.OK; this.savebtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green; - this.savebtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(40)))), ((int)(((byte)(0))))); + this.savebtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int) (((byte) (0)))), ((int) (((byte) (40)))), ((int) (((byte) (0))))); this.savebtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.savebtn.Location = new System.Drawing.Point(270, 113); this.savebtn.Name = "savebtn"; @@ -84,7 +83,7 @@ // this.cancelbtn.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.cancelbtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green; - this.cancelbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(40)))), ((int)(((byte)(0))))); + this.cancelbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int) (((byte) (0)))), ((int) (((byte) (40)))), ((int) (((byte) (0))))); this.cancelbtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.cancelbtn.Location = new System.Drawing.Point(352, 113); this.cancelbtn.Name = "cancelbtn"; @@ -94,20 +93,10 @@ this.cancelbtn.UseVisualStyleBackColor = true; this.cancelbtn.Click += new System.EventHandler(this.cancelbtn_Click); // - // useProxy - // - this.useProxy.AutoSize = true; - this.useProxy.Location = new System.Drawing.Point(12, 49); - this.useProxy.Name = "useProxy"; - this.useProxy.Size = new System.Drawing.Size(147, 17); - this.useProxy.TabIndex = 5; - this.useProxy.Text = "Use system proxy settings"; - this.useProxy.UseVisualStyleBackColor = true; - // // autopatching // this.autopatching.AutoSize = true; - this.autopatching.Location = new System.Drawing.Point(12, 72); + this.autopatching.Location = new System.Drawing.Point(12, 56); this.autopatching.Name = "autopatching"; this.autopatching.Size = new System.Drawing.Size(194, 17); this.autopatching.TabIndex = 6; @@ -123,7 +112,6 @@ this.CancelButton = this.cancelbtn; this.ClientSize = new System.Drawing.Size(439, 148); this.Controls.Add(this.autopatching); - this.Controls.Add(this.useProxy); this.Controls.Add(this.cancelbtn); this.Controls.Add(this.savebtn); this.Controls.Add(this.browsebtn); @@ -131,7 +119,7 @@ this.Controls.Add(this.label1); this.ForeColor = System.Drawing.Color.Lime; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "SettingsForm"; @@ -142,7 +130,6 @@ this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.PerformLayout(); - } #endregion @@ -152,7 +139,6 @@ private System.Windows.Forms.Button browsebtn; private System.Windows.Forms.Button savebtn; private System.Windows.Forms.Button cancelbtn; - private System.Windows.Forms.CheckBox useProxy; private System.Windows.Forms.CheckBox autopatching; } } diff --git a/GCMM/SettingsForm.cs b/GCMM/SettingsForm.cs index ac3a5e9..a044e62 100644 --- a/GCMM/SettingsForm.cs +++ b/GCMM/SettingsForm.cs @@ -1,14 +1,4 @@ -using GCMM.Properties; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; +using System; using System.Windows.Forms; namespace GCMM @@ -24,10 +14,9 @@ namespace GCMM private void Form1_Load(object sender, EventArgs e) { - gamelocation.Text = Settings.Default.GamePath; - useProxy.Checked = Settings.Default.UseProxy; - mainForm = Owner as MainForm; - autopatchingEnabled = Settings.Default.AutoLaunch == AutoPatchingState.Enabled; + mainForm = (MainForm) Owner; + gamelocation.Text = mainForm.Configuration.GamePath; + autopatchingEnabled = mainForm.Configuration.AutoPatch == AutoPatchingState.Enabled; autopatching.Checked = autopatchingEnabled; } @@ -38,11 +27,10 @@ namespace GCMM private void savebtn_Click(object sender, EventArgs e) { - Settings.Default.GamePath = gamelocation.Text; - Settings.Default.UseProxy = useProxy.Checked; + mainForm.Configuration.GamePath = gamelocation.Text; if (autopatching.Checked != autopatchingEnabled) mainForm.EnableDisableAutoPatchingWithDialog(autopatching.Checked); - Settings.Default.Save(); + mainForm.Configuration.Save(); Close(); }