Browse Source

Switch to custom configuration and remove unneeded configs

tags/v1.5.0
NorbiPeti 3 years ago
parent
commit
a27f3449be
12 changed files with 63 additions and 237 deletions
  1. +23
    -0
      GCMM/Configuration.cs
  2. +1
    -12
      GCMM/CustomMessageBox.cs
  3. +0
    -12
      GCMM/GCMM.csproj
  4. +17
    -26
      GCMM/MainForm.cs
  5. +2
    -4
      GCMM/MainModInstaller.cs
  6. +1
    -3
      GCMM/MainModList.cs
  7. +3
    -8
      GCMM/MainPatcher.cs
  8. +3
    -10
      GCMM/MainUtils.cs
  9. +0
    -98
      GCMM/Properties/Settings.Designer.cs
  10. +0
    -25
      GCMM/Properties/Settings.settings
  11. +7
    -21
      GCMM/SettingsForm.Designer.cs
  12. +6
    -18
      GCMM/SettingsForm.cs

+ 23
- 0
GCMM/Configuration.cs View File

@@ -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<Configuration>(File.ReadAllText("configuration.json"));
return new Configuration();
}

public void Save()
{
File.WriteAllText("configuration.json", JsonConvert.SerializeObject(this));
}
}
}

+ 1
- 12
GCMM/CustomMessageBox.cs View File

@@ -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
{


+ 0
- 12
GCMM/GCMM.csproj View File

@@ -38,18 +38,6 @@
<Compile Update="SettingsForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>

</Project>

+ 17
- 26
GCMM/MainForm.cs View File

@@ -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<string, ModInfo> mods = new Dictionary<string, ModInfo>();
@@ -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)
if(string.IsNullOrWhiteSpace(Configuration.GamePath))
{
Settings.Default.AutoLaunch = AutoPatchingState.Disabled;
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);
}
if(string.IsNullOrWhiteSpace(Settings.Default.GamePath))
{
status.Text = resources.GetString("Status_Game_not_found");
return;
}
DeleteEmptyPluginsDir(out bool pexists, out bool dexists);
if (!pexists && dexists)
unpatched.Checked = true; //It will call the event but that won't do anything


+ 2
- 4
GCMM/MainModInstaller.cs View File

@@ -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);
}


+ 1
- 3
GCMM/MainModList.cs View File

@@ -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;


+ 3
- 8
GCMM/MainPatcher.cs View File

@@ -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);


+ 3
- 10
GCMM/MainUtils.cs View File

@@ -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
/// <returns></returns>
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)


+ 0
- 98
GCMM/Properties/Settings.Designer.cs View File

@@ -1,98 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------

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;
}
}
}
}

+ 0
- 25
GCMM/Properties/Settings.settings View File

@@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="GCMM.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="GamePath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="WinePath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="UseProxy" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="NeedsUpdate" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="SteamUserID" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="AutoLaunch" Type="GCMM.AutoPatchingState" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>


+ 7
- 21
GCMM/SettingsForm.Designer.cs View File

@@ -23,8 +23,8 @@
#region Windows Form Designer generated code

/// <summary>
/// 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.
/// </summary>
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;
}
}


+ 6
- 18
GCMM/SettingsForm.cs View File

@@ -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();
}



Loading…
Cancel
Save