From 0446689e774196c7d2139761d6f511493d997916 Mon Sep 17 00:00:00 2001
From: Miepee <38186597+Miepee@users.noreply.github.com>
Date: Tue, 28 Dec 2021 16:54:26 +0100
Subject: [PATCH] implement data folder for log.config, use code cleaner
---
AM2RLauncher/AM2RLauncher.Gtk/Program.cs | 59 ++-
.../Properties/Resources.Designer.cs | 6 +-
.../Properties/Resources.resx | 2 +-
AM2RLauncher/AM2RLauncher.Wpf/Program.cs | 33 +-
AM2RLauncher/AM2RLauncher.sln | 4 +-
AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj | 12 +-
.../AM2RLauncher/CrossPlatformOperations.cs | 86 ++--
AM2RLauncher/AM2RLauncher/LauncherUpdater.cs | 27 +-
.../AM2RLauncher/MainForm/ColorButton.cs | 106 ++---
.../AM2RLauncher/MainForm/CustomButton.cs | 366 +++++++++---------
.../AM2RLauncher/MainForm/HelperMethods.cs | 2 -
.../AM2RLauncher/MainForm/ImageButton.cs | 186 +++++----
.../AM2RLauncher/MainForm/MainForm.Events.cs | 58 ++-
.../AM2RLauncher/MainForm/MainForm.Methods.cs | 53 ++-
.../AM2RLauncher/MainForm/MainForm.UI.cs | 17 +-
AM2RLauncher/AM2RLauncher/MainForm/Splash.cs | 5 +-
.../LauncherIcon.ico} | Bin
.../AM2RLauncher/XML/LauncherConfigXML.cs | 8 +-
AM2RLauncher/AM2RLauncher/XML/ProfileXML.cs | 6 +-
AM2RLauncher/AM2RLauncher/XML/Serializer.cs | 4 -
20 files changed, 538 insertions(+), 502 deletions(-)
rename AM2RLauncher/AM2RLauncher/{icon64.ico => Resources/LauncherIcon.ico} (100%)
diff --git a/AM2RLauncher/AM2RLauncher.Gtk/Program.cs b/AM2RLauncher/AM2RLauncher.Gtk/Program.cs
index 58d03ac..2d36bb3 100644
--- a/AM2RLauncher/AM2RLauncher.Gtk/Program.cs
+++ b/AM2RLauncher/AM2RLauncher.Gtk/Program.cs
@@ -1,7 +1,7 @@
using Eto.Forms;
using log4net;
-using System;
using log4net.Config;
+using System;
using System.IO;
using System.Reflection;
@@ -22,19 +22,18 @@ namespace AM2RLauncher.Gtk
[STAThread]
public static void Main(string[] args)
{
+ string launcherDataPath = GenerateCurrentPath();
- string localAM2RPath = Environment.GetEnvironmentVariable("HOME") + "/.local/share/AM2RLauncher";
-
- // Make sure first, ~/.local/share exists
- if (!Directory.Exists(localAM2RPath))
- Directory.CreateDirectory(localAM2RPath);
+ // Make sure first, ~/.local/share/AM2RLauncher exists
+ if (!Directory.Exists(launcherDataPath))
+ Directory.CreateDirectory(launcherDataPath);
// Now, see if log4netConfig exists, if not write it again.
- if (!File.Exists(localAM2RPath + "/log4net.config"))
- File.WriteAllText(localAM2RPath + "/log4net.config", Properties.Resources.log4netContents);
+ if (!File.Exists(launcherDataPath + "/log4net.config"))
+ File.WriteAllText(launcherDataPath + "/log4net.config", Properties.Resources.log4netContents.Replace("${DATADIR}", launcherDataPath));
// Configure logger
- XmlConfigurator.Configure(new FileInfo(localAM2RPath + "/log4net.config"));
+ XmlConfigurator.Configure(new FileInfo(launcherDataPath + "/log4net.config"));
try
{
@@ -43,7 +42,7 @@ namespace AM2RLauncher.Gtk
GTKLauncher.UnhandledException += GTKLauncher_UnhandledException;
GTKLauncher.Run(new MainForm());
}
- catch(Exception e)
+ catch (Exception e)
{
log.Error("An unhandled exception has occurred: \n*****Stack Trace*****\n\n" + e.StackTrace.ToString());
Console.WriteLine(Language.Text.UnhandledException + "\n" + e.Message + "\n*****Stack Trace*****\n\n" + e.StackTrace.ToString());
@@ -58,5 +57,45 @@ namespace AM2RLauncher.Gtk
log.Error("An unhandled exception has occurred: \n*****Stack Trace*****\n\n" + e.ExceptionObject.ToString());
MessageBox.Show(Language.Text.UnhandledException + "\n*****Stack Trace*****\n\n" + e.ExceptionObject.ToString(), "GTK", MessageBoxType.Error);
}
+
+ // This is a duplicate of CrossPlatformOperations.GenerateCurrentPath, because trying to invoke that would cause a crash due to currentPlatform not being initialized.
+ private static string GenerateCurrentPath()
+ {
+ string NIXHOME = Environment.GetEnvironmentVariable("HOME");
+ // First, we check if the user has a custom AM2RLAUNCHERDATA env var
+ string am2rLauncherDataEnvVar = Environment.GetEnvironmentVariable("AM2RLAUNCHERDATA");
+ if (!String.IsNullOrWhiteSpace(am2rLauncherDataEnvVar))
+ {
+ try
+ {
+ // This will create the directories recursively if they don't exist
+ Directory.CreateDirectory(am2rLauncherDataEnvVar);
+
+ // Our env var is now set and directories exist
+ return am2rLauncherDataEnvVar;
+ }
+ catch { }
+ }
+
+ // First check if XDG_DATA_HOME is set, if not we'll use ~/.local/share
+ string xdgDataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
+ if (string.IsNullOrWhiteSpace(xdgDataHome))
+ xdgDataHome = NIXHOME + "/.local/share";
+
+ // Add AM2RLauncher to the end of the dataPath
+ xdgDataHome += "/AM2RLauncher";
+
+ try
+ {
+ // This will create the directories recursively if they don't exist
+ Directory.CreateDirectory(xdgDataHome);
+
+ // Our env var is now set and directories exist
+ return xdgDataHome;
+ }
+ catch { }
+
+ return Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
+ }
}
}
diff --git a/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.Designer.cs b/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.Designer.cs
index ce3bcff..1b88f02 100644
--- a/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.Designer.cs
+++ b/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.Designer.cs
@@ -19,7 +19,7 @@ namespace AM2RLauncher.Gtk.Properties {
// -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
// Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
// mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
@@ -67,14 +67,14 @@ namespace AM2RLauncher.Gtk.Properties {
/// <appender-ref ref="file" />
/// </root>
/// <appender name="file" type="log4net.Appender.RollingFileAppender">
- /// <file value="${HOME}/.local/share/AM2RLauncher/Logs/AM2RLauncher.log" />
+ /// <file value="${DATADIR}/Logs/AM2RLauncher.log" />
/// <appendToFile value="true" />
/// <rollingStyle value="Once" />
/// <maxSizeRollBackups value="7" />
/// <maximumFileSize value="3MB" />
/// <staticLogFileName value="true" />
/// <layout type="log4net.Layout.PatternLayout">
- /// <conversionPattern value="%date [Rest der Zeichenfolge wurde abgeschnitten]"; ähnelt.
+ /// <conversionPattern value="%date [%thread] %level %logg [Rest der Zeichenfolge wurde abgeschnitten]"; ähnelt.
///
internal static string log4netContents {
get {
diff --git a/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.resx b/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.resx
index ce89876..a2cff8e 100644
--- a/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.resx
+++ b/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.resx
@@ -124,7 +124,7 @@
<appender-ref ref="file" />
</root>
<appender name="file" type="log4net.Appender.RollingFileAppender">
- <file value="${HOME}/.local/share/AM2RLauncher/Logs/AM2RLauncher.log" />
+ <file value="${DATADIR}/Logs/AM2RLauncher.log" />
<appendToFile value="true" />
<rollingStyle value="Once" />
<maxSizeRollBackups value="7" />
diff --git a/AM2RLauncher/AM2RLauncher.Wpf/Program.cs b/AM2RLauncher/AM2RLauncher.Wpf/Program.cs
index 0f81983..75799e1 100644
--- a/AM2RLauncher/AM2RLauncher.Wpf/Program.cs
+++ b/AM2RLauncher/AM2RLauncher.Wpf/Program.cs
@@ -1,14 +1,14 @@
using Eto.Forms;
-using System;
using log4net;
using log4net.Config;
+using System;
using System.IO;
using System.Reflection;
namespace AM2RLauncher.Wpf
{
///
- /// The main class for the GTK project.
+ /// The main class for the WinForms project.
///
class MainClass
{
@@ -17,13 +17,13 @@ namespace AM2RLauncher.Wpf
///
private static readonly ILog log = LogManager.GetLogger(typeof(MainForm));
///
- /// The main method for the GTK project.
+ /// The main method for the WinForms project.
///
[STAThread]
public static void Main(string[] args)
{
// Configure logger
- XmlConfigurator.Configure(new FileInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/log4net.config"));
+ XmlConfigurator.Configure(new FileInfo(GenerateCurrentPath() + "/log4net.config"));
// Try catch in case it ever crashes before actually getting to the Eto application
try
@@ -33,7 +33,7 @@ namespace AM2RLauncher.Wpf
WinLauncher.UnhandledException += WinLauncher_UnhandledException;
WinLauncher.Run(new MainForm());
}
- catch(Exception e)
+ catch (Exception e)
{
log.Error("An unhandled exception has occurred: \n*****Stack Trace*****\n\n" + e.StackTrace.ToString());
System.Windows.Forms.MessageBox.Show(Language.Text.UnhandledException + "\n" + e.Message + "\n*****Stack Trace*****\n\n" + e.StackTrace.ToString(), "Microsoft .NET Framework",
@@ -47,7 +47,28 @@ namespace AM2RLauncher.Wpf
private static void WinLauncher_UnhandledException(object sender, Eto.UnhandledExceptionEventArgs e)
{
log.Error("An unhandled exception has occurred: \n*****Stack Trace*****\n\n" + e.ExceptionObject.ToString());
- MessageBox.Show(Language.Text.UnhandledException + "\n*****Stack Trace*****\n\n" +e.ExceptionObject.ToString(), "Microsoft .NET Framework", MessageBoxType.Error);
+ MessageBox.Show(Language.Text.UnhandledException + "\n*****Stack Trace*****\n\n" + e.ExceptionObject.ToString(), "Microsoft .NET Framework", MessageBoxType.Error);
+ }
+
+ // This is a duplicate of CrossPlatformOperations.GenerateCurrentPath, because trying to invoke that would cause a crash due to currentPlatform not being initialized.
+ private static string GenerateCurrentPath()
+ {
+ // First, we check if the user has a custom AM2RLAUNCHERDATA env var
+ string am2rLauncherDataEnvVar = Environment.GetEnvironmentVariable("AM2RLAUNCHERDATA");
+ if (!String.IsNullOrWhiteSpace(am2rLauncherDataEnvVar))
+ {
+ try
+ {
+ // This will create the directories recursively if they don't exist
+ Directory.CreateDirectory(am2rLauncherDataEnvVar);
+
+ // Our env var is now set and directories exist
+ return am2rLauncherDataEnvVar;
+ }
+ catch { }
+ }
+ // Windows has the path where the exe is located as default
+ return Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
}
}
}
diff --git a/AM2RLauncher/AM2RLauncher.sln b/AM2RLauncher/AM2RLauncher.sln
index f238fbe..836a33c 100644
--- a/AM2RLauncher/AM2RLauncher.sln
+++ b/AM2RLauncher/AM2RLauncher.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.31005.135
+# Visual Studio Version 17
+VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AM2RLauncher", "AM2RLauncher\AM2RLauncher.csproj", "{9B67055C-5AEF-4F83-AFE0-38E600183C9F}"
EndProject
diff --git a/AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj b/AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj
index 1b5f15e..7565b4a 100644
--- a/AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj
+++ b/AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj
@@ -2,7 +2,7 @@
netstandard2.0
- icon64.ico
+ Resources\LauncherIcon.ico
Lojemiru, Miepee
AM2R-Community-Developers
This is a Launcher for AM2R and its Community Updates.
@@ -19,6 +19,10 @@
false
+
+
+
+
@@ -75,4 +79,10 @@
+
+
+ PreserveNewest
+
+
+
\ No newline at end of file
diff --git a/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs b/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs
index e6fa7c1..35e5a1b 100644
--- a/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs
+++ b/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs
@@ -1,21 +1,19 @@
using Eto;
-using Eto.Forms;
+using log4net;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
-using System.Text;
using System.Reflection;
using System.Text.RegularExpressions;
-using log4net;
namespace AM2RLauncher
{
///
/// Class that does Operations that work cross-platform.
///
- class CrossPlatformOperations
+ public class CrossPlatformOperations
{
///
/// The logger for , used to write any caught exceptions.
@@ -25,17 +23,27 @@ namespace AM2RLauncher
///
/// Gets the current platform.
///
- readonly private static Platform currentPlatform = Platform.Instance;
+ private static readonly Platform currentPlatform = Platform.Instance;
///
/// Current Path where the Launcher is located. For more info, check .
///
- static readonly public string CURRENTPATH = GenerateCurrentPath();
+ public static readonly string CURRENTPATH = GenerateCurrentPath();
///
/// Name of the Launcher executable.
///
- static readonly public string LAUNCHERNAME = AppDomain.CurrentDomain.FriendlyName;
+ public static readonly string LAUNCHERNAME = AppDomain.CurrentDomain.FriendlyName;
+
+ ///
+ /// Path to the Home Folder on *Nix-based systems.
+ ///
+ public static readonly string NIXHOME = Environment.GetEnvironmentVariable("HOME");
+
+ ///
+ /// Path to the Config folder on *Nix-based systems.
+ ///
+ public static readonly string NIXXDGCONFIG = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");
///
/// Generates the mirror list, depending on the current Platform.
@@ -82,9 +90,8 @@ namespace AM2RLauncher
if (currentPlatform.IsGtk)
{
// Config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config)
- string homePath = Environment.GetEnvironmentVariable("HOME");
- string xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");
- string launcherConfigPath = (String.IsNullOrWhiteSpace(xdgConfigHome) ? (homePath + "/.config") : xdgConfigHome) + "/AM2RLauncher";
+ string homePath = NIXHOME;
+ string launcherConfigPath = (String.IsNullOrWhiteSpace(NIXXDGCONFIG) ? (homePath + "/.config") : NIXXDGCONFIG) + "/AM2RLauncher";
string launcherConfigFilePath = launcherConfigPath + "/config.xml";
XML.LauncherConfigXML launcherConfig = new XML.LauncherConfigXML();
@@ -121,7 +128,7 @@ namespace AM2RLauncher
if (appConfig == null)
throw new NullReferenceException("Could not find the Config file! Please make sure it exists!");
ConnectionStringsSection connectionStringsSection = (ConnectionStringsSection)appConfig.GetSection("connectionStrings");
- if (connectionStringsSection == null || connectionStringsSection.ConnectionStrings[property]?.ConnectionString == null)
+ if (connectionStringsSection == null || connectionStringsSection.ConnectionStrings[property]?.ConnectionString == null)
throw new ArgumentException("The property " + property + " could not be found.");
connectionStringsSection.ConnectionStrings[property].ConnectionString = value.ToString();
appConfig.Save();
@@ -130,9 +137,8 @@ namespace AM2RLauncher
else if (currentPlatform.IsGtk)
{
// Config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config)
- string homePath = Environment.GetEnvironmentVariable("HOME");
- string xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");
- string launcherConfigPath = (String.IsNullOrWhiteSpace(xdgConfigHome) ? (homePath + "/.config") : xdgConfigHome) + "/AM2RLauncher";
+ string homePath = NIXHOME;
+ string launcherConfigPath = (String.IsNullOrWhiteSpace(NIXXDGCONFIG) ? (homePath + "/.config") : NIXXDGCONFIG) + "/AM2RLauncher";
string launcherConfigFilePath = launcherConfigPath + "/config.xml";
XML.LauncherConfigXML launcherConfig = new XML.LauncherConfigXML();
@@ -152,7 +158,7 @@ namespace AM2RLauncher
File.WriteAllText(launcherConfigFilePath, XML.Serializer.Serialize(launcherConfig));
}
}
-
+
///
/// When a Launcher update occurs that introduces new config properties, this method ensures that the old user config is copied over as much as possible.
///
@@ -170,7 +176,7 @@ namespace AM2RLauncher
MatchCollection oldMatch = settingRegex.Matches(oldConfigText);
MatchCollection newMatch = settingRegex.Matches(newConfigText);
- for(int i = 0; i < oldMatch.Count; i++)
+ for (int i = 0; i < oldMatch.Count; i++)
newConfigText = newConfigText.Replace(newMatch[i].Value, oldMatch[i].Value);
File.WriteAllText(newConfigPath, newConfigText);
@@ -179,9 +185,8 @@ namespace AM2RLauncher
else if (currentPlatform.IsGtk)
{
// Config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config)
- string homePath = Environment.GetEnvironmentVariable("HOME");
- string xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");
- string launcherConfigPath = (String.IsNullOrWhiteSpace(xdgConfigHome) ? (homePath + "/.config") : xdgConfigHome) + "/AM2RLauncher";
+ string homePath = NIXHOME;
+ string launcherConfigPath = (String.IsNullOrWhiteSpace(NIXXDGCONFIG) ? (homePath + "/.config") : NIXXDGCONFIG) + "/AM2RLauncher";
string launcherConfigFilePath = launcherConfigPath + "/config.xml";
XML.LauncherConfigXML launcherConfig = new XML.LauncherConfigXML();
@@ -212,7 +217,7 @@ namespace AM2RLauncher
// We have to replace forward slashes with backslashes here on windows because explorer.exe is picky...
// And on Nix systems, we want to replace ~ with its corresponding env var
string realPath = currentPlatform.IsWinForms ? Environment.ExpandEnvironmentVariables(path).Replace("/", "\\")
- : path.Replace("~", Environment.GetEnvironmentVariable("HOME"));
+ : path.Replace("~", NIXHOME);
if (!Directory.Exists(realPath))
{
log.Info(realPath + " did not exist and was created");
@@ -238,7 +243,7 @@ namespace AM2RLauncher
// We have to replace forward slashes with backslashes here on windows because explorer.exe is picky...
// And on nix systems, we want to replace ~ with its corresponding env var
string realPath = currentPlatform.IsWinForms ? Environment.ExpandEnvironmentVariables(path).Replace("/", "\\")
- : path.Replace("~", Environment.GetEnvironmentVariable("HOME"));
+ : path.Replace("~", NIXHOME);
if (!File.Exists(realPath))
{
log.Error(realPath + "did not exist, operation to open its folder was cancelled!");
@@ -273,16 +278,16 @@ namespace AM2RLauncher
arguments = "-version";
}
- ProcessStartInfo javaStart = new ProcessStartInfo();
- javaStart.FileName = process;
- javaStart.Arguments = arguments;
- javaStart.UseShellExecute = false;
- javaStart.CreateNoWindow = true;
-
+ ProcessStartInfo javaStart = new ProcessStartInfo
+ {
+ FileName = process,
+ Arguments = arguments,
+ UseShellExecute = false,
+ CreateNoWindow = true
+ };
- Process java = new Process();
- java.StartInfo = javaStart;
+ Process java = new Process { StartInfo = javaStart };
// This is primarily for linux, but could be happening on windows as well
try
@@ -297,7 +302,6 @@ namespace AM2RLauncher
}
return java.ExitCode == 0;
-
}
///
@@ -307,18 +311,18 @@ namespace AM2RLauncher
public static bool CheckIfXdeltaIsInstalled()
{
string process = "xdelta3";
- string arguments = "-V";
-
- ProcessStartInfo xdeltaStart = new ProcessStartInfo();
- xdeltaStart.FileName = process;
- xdeltaStart.Arguments = arguments;
- xdeltaStart.UseShellExecute = false;
- xdeltaStart.CreateNoWindow = true;
+ string arguments = "-V";
+ ProcessStartInfo xdeltaStart = new ProcessStartInfo
+ {
+ FileName = process,
+ Arguments = arguments,
+ UseShellExecute = false,
+ CreateNoWindow = true
+ };
- Process xdelta = new Process();
- xdelta.StartInfo = xdeltaStart;
+ Process xdelta = new Process { StartInfo = xdeltaStart };
try
{
@@ -347,7 +351,7 @@ namespace AM2RLauncher
if (original == output)
output = output += "_";
- string arguments = "-f -d -s \"" + original.Replace(CURRENTPATH + "/","") + "\" \"" + patch.Replace(CURRENTPATH + "/", "")
+ string arguments = "-f -d -s \"" + original.Replace(CURRENTPATH + "/", "") + "\" \"" + patch.Replace(CURRENTPATH + "/", "")
+ "\" \"" + output.Replace(CURRENTPATH + "/", "") + "\"";
if (currentPlatform.IsWinForms)
@@ -438,7 +442,7 @@ namespace AM2RLauncher
if (string.IsNullOrWhiteSpace(xdgDataHome))
{
log.Info("Using default Linux CurrentPath.");
- xdgDataHome = Environment.GetEnvironmentVariable("HOME") + "/.local/share";
+ xdgDataHome = NIXHOME + "/.local/share";
}
// Add AM2RLauncher to the end of the dataPath
diff --git a/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs b/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs
index 789f5dd..b927332 100644
--- a/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs
+++ b/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs
@@ -1,16 +1,11 @@
-using Eto;
+using AM2RLauncher.Helpers;
+using Eto;
using Eto.Forms;
+using log4net;
using System;
-using System.Collections.Generic;
-using System.Configuration;
using System.IO;
using System.IO.Compression;
-using System.Linq;
using System.Net;
-using System.Reflection;
-using System.Text;
-using log4net;
-using AM2RLauncher.Helpers;
namespace AM2RLauncher
{
@@ -45,8 +40,6 @@ namespace AM2RLauncher
{
log.Info("Running update check...");
- string version = VERSION.Replace(".", "");
-
// Update section
// Clean old files that have been left
@@ -104,7 +97,7 @@ namespace AM2RLauncher
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://github.com/AM2R-Community-Developers/AM2RLauncher/releases/latest");
HttpWebResponse response = null;
try
- {
+ {
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException)
@@ -144,7 +137,7 @@ namespace AM2RLauncher
Directory.CreateDirectory(tmpUpdatePath);
try
- {
+ {
using (var client = new WebClient())
{
string platformSuffix = "";
@@ -152,13 +145,13 @@ namespace AM2RLauncher
else if (currentPlatform.IsGtk) platformSuffix = "_lin";
log.Info("Downloading https://github.com/AM2R-Community-Developers/AM2RLauncher/releases/latest/download/AM2RLauncher_" + onlineVersion + platformSuffix + ".zip to " + zipPath + ".");
-
+
client.DownloadFile("https://github.com/AM2R-Community-Developers/AM2RLauncher/releases/latest/download/AM2RLauncher_" + onlineVersion + platformSuffix + ".zip", zipPath);
log.Info("File successfully downloaded.");
}
}
- catch(UnauthorizedAccessException)
+ catch (UnauthorizedAccessException)
{
log.Error("UnauthorizedAccessException caught! Displaying MessageBox.");
MessageBox.Show(Language.Text.UnauthorizedAccessMessage);
@@ -174,7 +167,7 @@ namespace AM2RLauncher
foreach (var file in new DirectoryInfo(tmpUpdatePath).GetFiles())
{
- log.Info("Moving " + file.FullName + " to " + CrossPlatformOperations.CURRENTPATH + "/" + file.Name);
+ log.Info("Moving " + file.FullName + " to " + CrossPlatformOperations.CURRENTPATH + "/" + file.Name);
File.Copy(file.FullName, updatePath + "/" + file.Name, true);
}
// For windows, the actual application is in "AM2RLauncher.dll". Which means, we need to update the lib folder as well.
@@ -189,7 +182,7 @@ namespace AM2RLauncher
}
// Do the same for each subdir
- foreach(DirectoryInfo dir in new DirectoryInfo(CrossPlatformOperations.CURRENTPATH + "/lib").GetDirectories())
+ foreach (DirectoryInfo dir in new DirectoryInfo(CrossPlatformOperations.CURRENTPATH + "/lib").GetDirectories())
{
foreach (FileInfo file in dir.GetFiles())
{
@@ -201,7 +194,7 @@ namespace AM2RLauncher
if (Directory.Exists(tmpUpdatePath + "lib"))
HelperMethods.DirectoryCopy(tmpUpdatePath + "lib", CrossPlatformOperations.CURRENTPATH + "/lib", true);
}
-
+
Directory.Delete(tmpUpdatePath, true);
CrossPlatformOperations.CopyOldConfigToNewConfig();
diff --git a/AM2RLauncher/AM2RLauncher/MainForm/ColorButton.cs b/AM2RLauncher/AM2RLauncher/MainForm/ColorButton.cs
index c15e37c..6d03f59 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/ColorButton.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/ColorButton.cs
@@ -1,74 +1,74 @@
-using Eto.Forms;
-using Eto.Drawing;
+using Eto.Drawing;
+using Eto.Forms;
using Pablo.Controls;
namespace AM2RLauncher
{
- ///
- /// Extension of that allows for advanced color settings.
- ///
- class ColorButton : CustomButton
- {
- /// The to draw the background with when is true.
- public Color BackgroundColorHover { get; set; }
+ ///
+ /// Extension of that allows for advanced color settings.
+ ///
+ class ColorButton : CustomButton
+ {
+ /// The to draw the background with when is true.
+ public Color BackgroundColorHover { get; set; }
- /// The to use for text drawing.
- public Font Font { get; set; }
+ /// The to use for text drawing.
+ public Font Font { get; set; }
- /// The with which to draw the frame.
- public Color FrameColor { get; set; }
+ /// The with which to draw the frame.
+ public Color FrameColor { get; set; }
- /// The with which to draw the frame when it is disabled.
- public Color FrameColorDisabled { get; set; }
+ /// The with which to draw the frame when it is disabled.
+ public Color FrameColorDisabled { get; set; }
- /// The text to be drawn.
- public string Text { get; set; }
+ /// The text to be drawn.
+ public string Text { get; set; }
- /// The with which to draw the .
- public Color TextColor { get; set; }
+ /// The with which to draw the .
+ public Color TextColor { get; set; }
- /// The with which to draw the when it is disabled.
- public Color TextColorDisabled { get; set; }
+ /// The with which to draw the when it is disabled.
+ public Color TextColorDisabled { get; set; }
- ///
- /// Creates a with a default set of attributes.
- ///
- public ColorButton()
+ ///
+ /// Creates a with a default set of attributes.
+ ///
+ public ColorButton()
{
- BackgroundColorHover = Colors.White;
- Font = new Font(SystemFont.Default, 12);
- FrameColor = Colors.White;
- FrameColorDisabled = Colors.Gray;
- Text = "";
- TextColor = Colors.Black;
- TextColorDisabled = Colors.Gray;
- }
+ BackgroundColorHover = Colors.White;
+ Font = new Font(SystemFont.Default, 12);
+ FrameColor = Colors.White;
+ FrameColorDisabled = Colors.Gray;
+ Text = "";
+ TextColor = Colors.Black;
+ TextColorDisabled = Colors.Gray;
+ }
- ///
- /// Event raised to draw this control.
- ///
- ///
- protected override void OnPaint(PaintEventArgs pe)
+ ///
+ /// Event raised to draw this control.
+ ///
+ ///
+ protected override void OnPaint(PaintEventArgs pe)
{
- // Define draw bounds
- Rectangle drawBounds = new Rectangle(2, 2, Width - 5, Height - 5);
+ // Define draw bounds
+ Rectangle drawBounds = new Rectangle(2, 2, Width - 5, Height - 5);
- // Draw background
- pe.Graphics.FillRectangle(Hover ? BackgroundColorHover : BackgroundColor, drawBounds);
+ // Draw background
+ pe.Graphics.FillRectangle(Hover ? BackgroundColorHover : BackgroundColor, drawBounds);
- // Draw frame
- Pen framePen = new Pen(Enabled ? FrameColor : FrameColorDisabled, 1);
- pe.Graphics.DrawRectangle(framePen, drawBounds);
+ // Draw frame
+ Pen framePen = new Pen(Enabled ? FrameColor : FrameColorDisabled, 1);
+ pe.Graphics.DrawRectangle(framePen, drawBounds);
- SolidBrush brush = new SolidBrush(Enabled ? TextColor : TextColorDisabled);
+ SolidBrush brush = new SolidBrush(Enabled ? TextColor : TextColorDisabled);
- // Get text measurements
- SizeF stringSize = pe.Graphics.MeasureString(Font, Text);
- int textWidth = (int)stringSize.Width;
- int textHeight = (int)stringSize.Height;
+ // Get text measurements
+ SizeF stringSize = pe.Graphics.MeasureString(Font, Text);
+ int textWidth = (int)stringSize.Width;
+ int textHeight = (int)stringSize.Height;
- // Draw text
- pe.Graphics.DrawText(Font, brush, new PointF(Width / 2 - textWidth / 2, Height / 2 - textHeight / 2), Text);
- }
+ // Draw text
+ pe.Graphics.DrawText(Font, brush, new PointF(Width / 2 - textWidth / 2, Height / 2 - textHeight / 2), Text);
+ }
}
}
diff --git a/AM2RLauncher/AM2RLauncher/MainForm/CustomButton.cs b/AM2RLauncher/AM2RLauncher/MainForm/CustomButton.cs
index 86ea74f..6bf6e1a 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/CustomButton.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/CustomButton.cs
@@ -1,191 +1,191 @@
-using System;
+using Eto.Drawing;
using Eto.Forms;
-using Eto.Drawing;
+using System;
namespace Pablo.Controls
{
- ///
- /// A custom button implementation for advanced drawing and events.
- /// Originally written by cwensley (https://gist.github.com/cwensley/95000998e37acd93e830),
- /// modified by Lojemiru and Miepee for use in the AM2RLauncher.
- ///
- public class CustomButton : Drawable
- {
- /// Whether or not this is being pressed.
- bool pressed;
-
- /// Whether or not the mouse is hovering over this .
- bool hover;
-
- ///
- bool mouseDown;
-
- /// Gets or sets the disabled color of this control.
- public static Color DisabledColor = Color.FromGrayscale(0.4f, 0.3f);
-
- /// Gets or sets the color of this control.
- public static Color EnabledColor = Colors.Black;
-
- /// Gets or sets whether or not this control is enabled.
- public override bool Enabled
- {
- get { return base.Enabled; }
- set
- {
- if (base.Enabled != value)
- {
- base.Enabled = value;
- if (Loaded)
- Invalidate();
- }
- }
- }
-
- /// Gets or sets .
- public bool Pressed
- {
- get { return pressed; }
- set
- {
- if (pressed != value)
- {
- pressed = value;
- mouseDown = false;
- if (Loaded)
- Invalidate();
- }
- }
- }
-
- /// Gets .
- public bool Hover
+ ///
+ /// A custom button implementation for advanced drawing and events.
+ /// Originally written by cwensley (https://gist.github.com/cwensley/95000998e37acd93e830),
+ /// modified by Lojemiru and Miepee for use in the AM2RLauncher.
+ ///
+ public class CustomButton : Drawable
+ {
+ /// Whether or not this is being pressed.
+ bool pressed;
+
+ /// Whether or not the mouse is hovering over this .
+ bool hover;
+
+ ///
+ bool mouseDown;
+
+ /// Gets or sets the disabled color of this control.
+ public static Color DisabledColor = Color.FromGrayscale(0.4f, 0.3f);
+
+ /// Gets or sets the color of this control.
+ public static Color EnabledColor = Colors.Black;
+
+ /// Gets or sets whether or not this control is enabled.
+ public override bool Enabled
{
- get { return hover; }
+ get { return base.Enabled; }
+ set
+ {
+ if (base.Enabled != value)
+ {
+ base.Enabled = value;
+ if (Loaded)
+ Invalidate();
+ }
+ }
}
- /// Gets either the or dependent on .
- public Color DrawColor
- {
- get { return Enabled ? EnabledColor : DisabledColor; }
- }
-
- /// Gets or sets whether or not this control should act as a toggle.
- public bool Toggle { get; set; }
-
- /// Gets or sets whether or not this control is persistent.
- public bool Persistent { get; set; }
-
- public event EventHandler Click;
-
- ///
- /// Event raised when this control is clicked.
- ///
- ///
- protected virtual void OnClick(EventArgs e)
- {
- if (Click != null)
- Click(this, e);
- }
-
- /// Default constructor. Sets to true.
- public CustomButton() { Enabled = true; }
-
- /// Event raised when this control is resized.
- ///
- protected override void OnSizeChanged(EventArgs e)
- {
- base.OnSizeChanged(e);
- if (Loaded)
- Invalidate();
- }
-
- ///
- /// Event raised when the mouse is pressed down over this control's bounding box.
- ///
- ///
- protected override void OnMouseDown(MouseEventArgs e)
- {
- base.OnMouseDown(e);
- if (Enabled)
- {
- mouseDown = true;
- Invalidate();
- }
- }
-
- ///
- /// Event raised when the mouse enters this control's bounding box.
- ///
- ///
- protected override void OnMouseEnter(MouseEventArgs e)
- {
- Cursor = new Cursor(CursorType.Pointer);
- base.OnMouseEnter(e);
- hover = true;
- Invalidate();
- }
-
- ///
- /// Event raised when the mouse leaves this control's bounding box.
- ///
- ///
- protected override void OnMouseLeave(MouseEventArgs e)
- {
- Cursor = new Cursor(CursorType.Default);
- base.OnMouseLeave(e);
- hover = false;
- Invalidate();
- }
-
- ///
- /// Event raised when the mouse is released over this control's bounding box.
- ///
- ///
- protected override void OnMouseUp(MouseEventArgs e)
- {
- base.OnMouseUp(e);
- var rect = new Rectangle(this.Size);
- if (mouseDown && rect.Contains((Point)e.Location))
- {
- if (Toggle)
- pressed = !pressed;
- else if (Persistent)
- pressed = true;
- else
- pressed = false;
- mouseDown = false;
-
- this.Invalidate();
- if (Enabled)
- OnClick(EventArgs.Empty);
- }
- else
- {
- mouseDown = false;
- this.Invalidate();
- }
- }
-
- ///
- /// Event raised to draw this control.
- ///
- ///
- protected override void OnPaint(PaintEventArgs pe)
- {
- var rect = new Rectangle(this.Size);
- var col = Color.FromGrayscale(hover && Enabled ? 0.95f : 0.8f);
- if (Enabled && (pressed || mouseDown))
- {
- pe.Graphics.FillRectangle(col, rect);
- pe.Graphics.DrawInsetRectangle(Colors.Gray, Colors.White, rect);
- }
- else if (hover && Enabled)
- {
- pe.Graphics.FillRectangle(col, rect);
- pe.Graphics.DrawInsetRectangle(Colors.White, Colors.Gray, rect);
- }
-
- base.OnPaint(pe);
- }
- }
+ /// Gets or sets .
+ public bool Pressed
+ {
+ get { return pressed; }
+ set
+ {
+ if (pressed != value)
+ {
+ pressed = value;
+ mouseDown = false;
+ if (Loaded)
+ Invalidate();
+ }
+ }
+ }
+
+ /// Gets .
+ public bool Hover
+ {
+ get { return hover; }
+ }
+
+ /// Gets either the or dependent on .
+ public Color DrawColor
+ {
+ get { return Enabled ? EnabledColor : DisabledColor; }
+ }
+
+ /// Gets or sets whether or not this control should act as a toggle.
+ public bool Toggle { get; set; }
+
+ /// Gets or sets whether or not this control is persistent.
+ public bool Persistent { get; set; }
+
+ public event EventHandler Click;
+
+ ///
+ /// Event raised when this control is clicked.
+ ///
+ ///
+ protected virtual void OnClick(EventArgs e)
+ {
+ if (Click != null)
+ Click(this, e);
+ }
+
+ /// Default constructor. Sets to true.
+ public CustomButton() { Enabled = true; }
+
+ /// Event raised when this control is resized.
+ ///
+ protected override void OnSizeChanged(EventArgs e)
+ {
+ base.OnSizeChanged(e);
+ if (Loaded)
+ Invalidate();
+ }
+
+ ///
+ /// Event raised when the mouse is pressed down over this control's bounding box.
+ ///
+ ///
+ protected override void OnMouseDown(MouseEventArgs e)
+ {
+ base.OnMouseDown(e);
+ if (Enabled)
+ {
+ mouseDown = true;
+ Invalidate();
+ }
+ }
+
+ ///
+ /// Event raised when the mouse enters this control's bounding box.
+ ///
+ ///
+ protected override void OnMouseEnter(MouseEventArgs e)
+ {
+ Cursor = new Cursor(CursorType.Pointer);
+ base.OnMouseEnter(e);
+ hover = true;
+ Invalidate();
+ }
+
+ ///
+ /// Event raised when the mouse leaves this control's bounding box.
+ ///
+ ///
+ protected override void OnMouseLeave(MouseEventArgs e)
+ {
+ Cursor = new Cursor(CursorType.Default);
+ base.OnMouseLeave(e);
+ hover = false;
+ Invalidate();
+ }
+
+ ///
+ /// Event raised when the mouse is released over this control's bounding box.
+ ///
+ ///
+ protected override void OnMouseUp(MouseEventArgs e)
+ {
+ base.OnMouseUp(e);
+ var rect = new Rectangle(this.Size);
+ if (mouseDown && rect.Contains((Point)e.Location))
+ {
+ if (Toggle)
+ pressed = !pressed;
+ else if (Persistent)
+ pressed = true;
+ else
+ pressed = false;
+ mouseDown = false;
+
+ this.Invalidate();
+ if (Enabled)
+ OnClick(EventArgs.Empty);
+ }
+ else
+ {
+ mouseDown = false;
+ this.Invalidate();
+ }
+ }
+
+ ///
+ /// Event raised to draw this control.
+ ///
+ ///
+ protected override void OnPaint(PaintEventArgs pe)
+ {
+ var rect = new Rectangle(this.Size);
+ var col = Color.FromGrayscale(hover && Enabled ? 0.95f : 0.8f);
+ if (Enabled && (pressed || mouseDown))
+ {
+ pe.Graphics.FillRectangle(col, rect);
+ pe.Graphics.DrawInsetRectangle(Colors.Gray, Colors.White, rect);
+ }
+ else if (hover && Enabled)
+ {
+ pe.Graphics.FillRectangle(col, rect);
+ pe.Graphics.DrawInsetRectangle(Colors.White, Colors.Gray, rect);
+ }
+
+ base.OnPaint(pe);
+ }
+ }
}
diff --git a/AM2RLauncher/AM2RLauncher/MainForm/HelperMethods.cs b/AM2RLauncher/AM2RLauncher/MainForm/HelperMethods.cs
index 9587174..e44d054 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/HelperMethods.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/HelperMethods.cs
@@ -1,10 +1,8 @@
using log4net;
using System;
-using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Security.Cryptography;
-using System.Text;
namespace AM2RLauncher.Helpers
{
diff --git a/AM2RLauncher/AM2RLauncher/MainForm/ImageButton.cs b/AM2RLauncher/AM2RLauncher/MainForm/ImageButton.cs
index 6f25c00..92ce2cc 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/ImageButton.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/ImageButton.cs
@@ -1,107 +1,105 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Eto.Drawing;
+using Eto.Drawing;
+using System;
namespace Pablo.Controls
{
- ///
- /// Extension of that allows image assignment and drawing.
- /// Originally written by cwensley (https://gist.github.com/cwensley/95000998e37acd93e830),
- /// modified by Lojemiru and Miepee for use in the AM2RLauncher.
- ///
- public class ImageButton : CustomButton
- {
- ///
- /// Whether or not this control's size has been set.
- ///
- bool sizeSet;
+ ///
+ /// Extension of that allows image assignment and drawing.
+ /// Originally written by cwensley (https://gist.github.com/cwensley/95000998e37acd93e830),
+ /// modified by Lojemiru and Miepee for use in the AM2RLauncher.
+ ///
+ public class ImageButton : CustomButton
+ {
+ ///
+ /// Whether or not this control's size has been set.
+ ///
+ bool sizeSet;
- ///
- /// Gets or sets the to draw during .
- ///
- public Image Image { get; set; }
+ ///
+ /// Gets or sets the to draw during .
+ ///
+ public Image Image { get; set; }
- ///
- /// Gets or sets the to draw during if this control is disabled.
- ///
- public Image DisabledImage { get; set; }
+ ///
+ /// Gets or sets the to draw during if this control is disabled.
+ ///
+ public Image DisabledImage { get; set; }
- ///
- /// Gets or sets the of this control.
- ///
- public override Size Size
- {
- get { return base.Size; }
- set { base.Size = value; sizeSet = true; }
- }
+ ///
+ /// Gets or sets the of this control.
+ ///
+ public override Size Size
+ {
+ get { return base.Size; }
+ set { base.Size = value; sizeSet = true; }
+ }
- ///
- /// Default contructor, assigns no special attributes.
- ///
- public ImageButton() { }
+ ///
+ /// Default contructor, assigns no special attributes.
+ ///
+ public ImageButton() { }
- ///
- /// Event raised when this control is loading.
- ///
- ///
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- if (Image != null)
- {
- if (!sizeSet)
- this.Size = Image.Size + 4;
- }
- }
+ ///
+ /// Event raised when this control is loading.
+ ///
+ ///
+ protected override void OnLoad(EventArgs e)
+ {
+ base.OnLoad(e);
+ if (Image != null)
+ {
+ if (!sizeSet)
+ this.Size = Image.Size + 4;
+ }
+ }
- ///
- /// Event raised when this control has finished loading.
- ///
- ///
- protected override void OnLoadComplete(EventArgs e)
- {
- base.OnLoadComplete(e);
+ ///
+ /// Event raised when this control has finished loading.
+ ///
+ ///
+ protected override void OnLoadComplete(EventArgs e)
+ {
+ base.OnLoadComplete(e);
- if (DisabledImage == null)
- {
- var image = Image;
- if (image != null)
- {
- var disabledImage = new Bitmap(image.Size.Width, image.Size.Height, PixelFormat.Format32bppRgba);
- using (var graphics = new Graphics(disabledImage))
- {
- graphics.DrawImage(image, 0, 0);
- }
- using (var bd = disabledImage.Lock())
- {
- unsafe
- {
- var data = (int*)bd.Data;
- for (int i = 0; i < bd.ScanWidth * disabledImage.Size.Height; i++)
- {
- var col = Color.FromArgb(bd.TranslateDataToArgb(*data));
- var gray = (col.R + col.G + col.B) / 3;
- *data = bd.TranslateArgbToData(Color.FromGrayscale(gray, 0.8f).ToArgb());
- }
- }
- }
- }
- }
- }
+ if (DisabledImage == null)
+ {
+ var image = Image;
+ if (image != null)
+ {
+ var disabledImage = new Bitmap(image.Size.Width, image.Size.Height, PixelFormat.Format32bppRgba);
+ using (var graphics = new Graphics(disabledImage))
+ {
+ graphics.DrawImage(image, 0, 0);
+ }
+ using (var bd = disabledImage.Lock())
+ {
+ unsafe
+ {
+ var data = (int*)bd.Data;
+ for (int i = 0; i < bd.ScanWidth * disabledImage.Size.Height; i++)
+ {
+ var col = Color.FromArgb(bd.TranslateDataToArgb(*data));
+ var gray = (col.R + col.G + col.B) / 3;
+ *data = bd.TranslateArgbToData(Color.FromGrayscale(gray, 0.8f).ToArgb());
+ }
+ }
+ }
+ }
+ }
+ }
- ///
- /// Event raised to draw this control.
- ///
- ///
- protected override void OnPaint(Eto.Forms.PaintEventArgs pe)
- {
- var image = this.Enabled ? Image : DisabledImage;
- var size = image.Size.FitTo(this.Size - 2);
- var xoffset = (this.Size.Width - size.Width) / 2;
- var yoffset = (this.Size.Height - size.Height) / 2;
- pe.Graphics.DrawImage(image, xoffset, yoffset, size.Width, size.Height);
- }
- }
+ ///
+ /// Event raised to draw this control.
+ ///
+ ///
+ protected override void OnPaint(Eto.Forms.PaintEventArgs pe)
+ {
+ var image = this.Enabled ? Image : DisabledImage;
+ var size = image.Size.FitTo(this.Size - 2);
+ var xoffset = (this.Size.Width - size.Width) / 2;
+ var yoffset = (this.Size.Height - size.Height) / 2;
+ pe.Graphics.DrawImage(image, xoffset, yoffset, size.Width, size.Height);
+ }
+ }
}
diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs
index 642abc6..25ce549 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs
@@ -1,26 +1,18 @@
-using Eto;
-using Eto.Drawing;
+using AM2RLauncher.Helpers;
+using AM2RLauncher.XML;
+using Eto;
using Eto.Forms;
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Pablo.Controls;
-using System.Diagnostics;
-using System.Globalization;
-using System.Linq;
-using System.Threading.Tasks;
using LibGit2Sharp;
+using LibGit2Sharp.Handlers;
+using System;
+using System.ComponentModel;
using System.IO;
+using System.IO.Compression;
+using System.Linq;
using System.Runtime.InteropServices;
-using LibGit2Sharp.Handlers;
using System.Text.RegularExpressions;
using System.Threading;
-using System.ComponentModel;
-using System.Net;
-using System.IO.Compression;
-
-using AM2RLauncher.XML;
-using AM2RLauncher.Helpers;
+using System.Threading.Tasks;
namespace AM2RLauncher
{
@@ -140,7 +132,7 @@ namespace AM2RLauncher
log.Info("Cancelling archival! User-defined archive in Mods already exists.");
}
-
+
}
else // If our desired rename already exists, it's probably a user archive... so we just delete the folder and move on with installation of the new version.
{
@@ -152,7 +144,7 @@ namespace AM2RLauncher
LoadProfiles();
-
+
}
}
@@ -225,7 +217,7 @@ namespace AM2RLauncher
}
successful = false;
}
- catch(Exception ex) // This is if somehow any other exception might get thrown as well.
+ catch (Exception ex) // This is if somehow any other exception might get thrown as well.
{
log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace);
MessageBox.Show(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Language.Text.ErrorWindowTitle, MessageBoxType.Error);
@@ -352,7 +344,7 @@ namespace AM2RLauncher
{
InstallProfile(profileList[profileIndex.Value]);
}
- catch(Exception ex)
+ catch (Exception ex)
{
log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace);
MessageBox.Show(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Language.Text.ErrorWindowTitle, MessageBoxType.Error);
@@ -430,7 +422,7 @@ namespace AM2RLauncher
progressLabel.Text = Language.Text.ProgressbarProgress + " " + transferProgress.ReceivedObjects + " (" + (int)transferProgress.ReceivedBytes / 1000000 + "MB) / " + transferProgress.TotalObjects + " objects";
currentGitObject = transferProgress.ReceivedObjects;
progressBar.Value = transferProgress.ReceivedObjects;
-
+
}
}));
@@ -578,7 +570,7 @@ namespace AM2RLauncher
log.Error("Mod is for " + profile.OperatingSystem + " while current OS is " + Platform + ". Cancelling mod import.");
- MessageBox.Show(Language.Text.ModIsForWrongOS.Replace("$NAME",profile.Name).Replace("$OS",profile.OperatingSystem).Replace("$CURRENTOS",currentOS),
+ MessageBox.Show(Language.Text.ModIsForWrongOS.Replace("$NAME", profile.Name).Replace("$OS", profile.OperatingSystem).Replace("$CURRENTOS", currentOS),
Language.Text.ErrorWindowTitle, MessageBoxType.Error);
HelperMethods.DeleteDirectory(modsDir + "/" + extractedName);
return;
@@ -596,7 +588,7 @@ namespace AM2RLauncher
addedProfile = profile;
log.Info(profile.Name + " successfully installed.");
MessageBox.Show(Language.Text.ModSuccessfullyInstalledMessage.Replace("$NAME", profile.Name), Language.Text.SuccessWindowTitle);
-
+
}
else
{
@@ -747,7 +739,7 @@ namespace AM2RLauncher
}
/// Gets called when user selects a different item from and changes accordingly.
- private void ProfileDropDownSelectedIndexChanged(object sender, EventArgs e)
+ private void ProfileDropDownSelectedIndexChanged(object sender, EventArgs e)
{
profileIndex = profileDropDown.SelectedIndex;
log.Info("profileDropDown.SelectedIndex has been changed to " + profileIndex + ".");
@@ -799,12 +791,12 @@ namespace AM2RLauncher
mirrorDropDown.Enabled = !enabled;
// Not sure why the dropdown menu needs this hack, but the textBox does not.
if (Platform.IsWinForms)
- mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive;
- mirrorLabel.TextColor = !enabled ? colGreen : colInactive;
+ mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive;
+ mirrorLabel.TextColor = !enabled ? colGreen : colInactive;
// Create warning dialog when enabling
if (enabled)
- {
+ {
MessageBox.Show(Language.Text.WarningWindowText, Language.Text.WarningWindowTitle, MessageBoxType.Warning);
currentMirror = customMirrorTextBox.Text;
}
@@ -824,7 +816,7 @@ namespace AM2RLauncher
log.Info("Current mirror has been set to " + currentMirror + ".");
- CrossPlatformOperations.WriteToConfig("MirrorIndex",mirrorDropDown.SelectedIndex);
+ CrossPlatformOperations.WriteToConfig("MirrorIndex", mirrorDropDown.SelectedIndex);
// Don't overwrite the git config while we download!!!
if (updateState == UpdateState.Downloading) return;
@@ -901,7 +893,7 @@ namespace AM2RLauncher
ProfileXML profile = profileList[settingsProfileDropDown.SelectedIndex];
log.Info("User is attempting to delete profile " + profile.Name + ".");
- DialogResult result = MessageBox.Show(Language.Text.DeleteModWarning.Replace("$NAME", profile.Name), Language.Text.WarningWindowTitle,
+ DialogResult result = MessageBox.Show(Language.Text.DeleteModWarning.Replace("$NAME", profile.Name), Language.Text.WarningWindowTitle,
MessageBoxButtons.OKCancel, MessageBoxType.Warning, MessageBoxDefaultButton.Cancel);
if (result == DialogResult.Ok)
@@ -992,7 +984,7 @@ namespace AM2RLauncher
// Rename directory to take the old one's place
string originalFolder = modsDir + "/" + extractedName.Replace("_new", "");
Directory.Move(modsDir + "/" + extractedName, originalFolder);
-
+
}
else // Cancel the operation!
{
@@ -1051,9 +1043,9 @@ namespace AM2RLauncher
{
e.Cancel = true;
}
- else
+ else
isGitProcessGettingCancelled = true;
- // We don't need to delete any folders here, the cancelled gitClone will do that automatically for us :)
+ // We don't need to delete any folders here, the cancelled gitClone will do that automatically for us :)
}
else if (updateState == UpdateState.Installing)
diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs
index 248dc82..080e126 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs
@@ -1,21 +1,16 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
+using AM2RLauncher.Helpers;
+using AM2RLauncher.XML;
+using Eto;
+using Eto.Drawing;
using Eto.Forms;
-using System.Threading;
using LibGit2Sharp;
+using System;
+using System.Diagnostics;
using System.IO;
using System.IO.Compression;
-using Eto;
-using System.Diagnostics;
using System.Linq;
-using Eto.Drawing;
-using System.Xml.Serialization;
-using AM2RLauncher.XML;
-using System.Net.NetworkInformation;
-using System.Net;
-using AM2RLauncher.Helpers;
using System.Text.RegularExpressions;
+using System.Threading;
namespace AM2RLauncher
{
@@ -269,12 +264,12 @@ namespace AM2RLauncher
// Failsafe for Profiles directory
if (!Directory.Exists(profilesHomePath))
Directory.CreateDirectory(profilesHomePath);
-
+
// This failsafe should NEVER get triggered, but Miepee's broken this too much for me to trust it otherwise.
if (Directory.Exists(profilePath))
Directory.Delete(profilePath, true);
-
+
// Create profile directory
Directory.CreateDirectory(profilePath);
@@ -326,7 +321,7 @@ namespace AM2RLauncher
if (profile.UsesYYC)
{
CrossPlatformOperations.ApplyXdeltaPatch(profilePath + "/data.win", dataPath + "/AM2R.xdelta", profilePath + "/" + exe);
-
+
// Delete 1.1's data.win, we don't need it anymore!
File.Delete(profilePath + "/data.win");
}
@@ -341,7 +336,7 @@ namespace AM2RLauncher
CrossPlatformOperations.ApplyXdeltaPatch(profilePath + "/data.win", dataPath + "/game.xdelta", profilePath + "/" + datawin);
CrossPlatformOperations.ApplyXdeltaPatch(profilePath + "/AM2R.exe", dataPath + "/AM2R.xdelta", profilePath + "/" + exe);
// Just in case the resulting file isn't chmoddded...
- Process.Start("chmod", "+x \"" + profilePath + "/" + exe + "\"").WaitForExit();
+ Process.Start("chmod", "+x \"" + profilePath + "/" + exe + "\"").WaitForExit();
// These are not needed by linux at all, so we delete them
File.Delete(profilePath + "/data.win");
@@ -363,7 +358,7 @@ namespace AM2RLauncher
// HQ music
if (!profile.UsesCustomMusic && (bool)hqMusicPCCheck.Checked)
HelperMethods.DirectoryCopy(CrossPlatformOperations.CURRENTPATH + "/PatchData/data/HDR_HQ_in-game_music", profilePath);
-
+
// Linux post-process
if (Platform.IsGtk)
@@ -403,7 +398,7 @@ namespace AM2RLauncher
// Clean files
Directory.Delete(profilePath + "/AM2R.AppDir", true);
Directory.Delete(assetsPath, true);
- File.Delete(profilePath + "/" +exe);
+ File.Delete(profilePath + "/" + exe);
if (File.Exists(profilePath + "/AM2R.AppImage")) File.Delete(profilePath + "/AM2R.AppImage");
File.Move(profilePath + "/" + "AM2R-x86_64.AppImage", profilePath + "/AM2R.AppImage");
}
@@ -450,7 +445,7 @@ namespace AM2RLauncher
// Check if xdelta is installed on linux, by searching all folders in PATH
if (Platform.IsGtk && !CrossPlatformOperations.CheckIfXdeltaIsInstalled())
- {
+ {
// Message box show needs to be done on main thread
Application.Instance.Invoke(new Action(() =>
{
@@ -500,7 +495,7 @@ namespace AM2RLauncher
{
FileName = proc,
// For an explanation on the .replace look in CreateXdeltaPatch method
- Arguments = args + "\"" + apktoolPath.Replace(CrossPlatformOperations.CURRENTPATH + "/","../") + "\" d \"" + dataPath.Replace(CrossPlatformOperations.CURRENTPATH + "/", "../") + "/android/AM2RWrapper.apk\"",
+ Arguments = args + "\"" + apktoolPath.Replace(CrossPlatformOperations.CURRENTPATH + "/", "../") + "\" d \"" + dataPath.Replace(CrossPlatformOperations.CURRENTPATH + "/", "../") + "/android/AM2RWrapper.apk\"",
WorkingDirectory = tempDir,
UseShellExecute = false,
CreateNoWindow = true
@@ -646,7 +641,7 @@ namespace AM2RLauncher
// These are used on both windows and linux for game logging
string savePath = Platform.IsWinForms ? profile.SaveLocation.Replace("%localappdata%", Environment.GetEnvironmentVariable("LOCALAPPDATA"))
- : profile.SaveLocation.Replace("~", Environment.GetEnvironmentVariable("HOME"));
+ : profile.SaveLocation.Replace("~", CrossPlatformOperations.NIXHOME);
DirectoryInfo logDir = new DirectoryInfo(savePath + "/logs");
string date = string.Join("-", DateTime.Now.ToString().Split(Path.GetInvalidFileNameChars(), StringSplitOptions.RemoveEmptyEntries));
@@ -704,7 +699,7 @@ namespace AM2RLauncher
{
string envVars = customEnvVarTextBox.Text;
- for(int i = 0; i < customEnvVarTextBox.Text.Count(f => f == '='); i++)
+ for (int i = 0; i < customEnvVarTextBox.Text.Count(f => f == '='); i++)
{
// Env var variable
string variable = envVars.Substring(0, envVars.IndexOf('='));
@@ -715,15 +710,15 @@ namespace AM2RLauncher
if (envVars[0] != '"') // If value is not embedded in "", check if there are spaces left. If yes, get the index of the space, if not that was the last
{
if (envVars.IndexOf(' ') >= 0)
- valueSubstringLength = envVars.IndexOf(' ')+1;
+ valueSubstringLength = envVars.IndexOf(' ') + 1;
else
valueSubstringLength = envVars.Length;
}
else // If value is embedded in "", check if there are spaces after the "". if yes, get index of that, if not that was the last
{
- int secondQuoteIndex = envVars.IndexOf('"', envVars.IndexOf('"')+1);
+ int secondQuoteIndex = envVars.IndexOf('"', envVars.IndexOf('"') + 1);
if (envVars.IndexOf(' ', secondQuoteIndex) >= 0)
- valueSubstringLength = envVars.IndexOf(' ', secondQuoteIndex)+1;
+ valueSubstringLength = envVars.IndexOf(' ', secondQuoteIndex) + 1;
else
valueSubstringLength = envVars.Length;
}
@@ -746,7 +741,7 @@ namespace AM2RLauncher
log.Info("CWD of Profile is " + startInfo.WorkingDirectory);
log.Info("Launching game with following variables: ");
- foreach(System.Collections.DictionaryEntry item in startInfo.EnvironmentVariables)
+ foreach (System.Collections.DictionaryEntry item in startInfo.EnvironmentVariables)
{
log.Info("Key: \"" + item.Key + "\" Value: \"" + item.Value + "\"");
}
@@ -907,7 +902,7 @@ namespace AM2RLauncher
}
else // Otherwise, disable.
{
- apkButton.Enabled = false;
+ apkButton.Enabled = false;
apkButton.ToolTip = Language.Text.ApkButtonDisabledToolTip;
}
}
@@ -1048,9 +1043,9 @@ namespace AM2RLauncher
case UpdateState.Download: playButton.Enabled = true; playButton.ToolTip = Language.Text.PlayButtonDownloadToolTip; break;
case UpdateState.Downloading: playButton.Enabled = true; playButton.ToolTip = ""; break; // ; playButton.ToolTip = Language.Text.PlayButtonDownladingToolTip; break;
case UpdateState.Select11: playButton.Enabled = true; playButton.ToolTip = Language.Text.PlayButtonSelect11ToolTip; break;
- case UpdateState.Install: playButton.Enabled = true; playButton.ToolTip = Language.Text.PlayButtonInstallToolTip.Replace("$NAME", profileName) ; break;
+ case UpdateState.Install: playButton.Enabled = true; playButton.ToolTip = Language.Text.PlayButtonInstallToolTip.Replace("$NAME", profileName); break;
case UpdateState.Installing: playButton.Enabled = false; playButton.ToolTip = Language.Text.PlayButtonInstallingToolTip; break;
- case UpdateState.Play: playButton.Enabled = true; playButton.ToolTip = Language.Text.PlayButtonPlayToolTip.Replace("$NAME", profileName) ; break;
+ case UpdateState.Play: playButton.Enabled = true; playButton.ToolTip = Language.Text.PlayButtonPlayToolTip.Replace("$NAME", profileName); break;
case UpdateState.Playing: playButton.Enabled = false; playButton.ToolTip = Language.Text.PlayButtonPlayingToolTip; break;
}
playButton.Text = GetPlayButtonText();
diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs
index 0838351..30e4221 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs
@@ -1,17 +1,16 @@
-using Eto.Drawing;
+using AM2RLauncher.XML;
+using Eto.Drawing;
using Eto.Forms;
+using log4net;
+using Pablo.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
-using Pablo.Controls;
+using System.Globalization;
using System.IO;
using System.Linq;
-using System.Threading;
-using System.Globalization;
-using AM2RLauncher.XML;
-using log4net;
-using log4net.Config;
using System.Text.RegularExpressions;
+using System.Threading;
namespace AM2RLauncher
{
@@ -143,7 +142,7 @@ namespace AM2RLauncher
var results = lineRegex.Matches(osRelease).Cast();
var version = results.FirstOrDefault(x => x.Value.Contains("VERSION"));
log.Info("Current Distro: " + results.FirstOrDefault(x => x.Value.Contains("NAME")).Value.Substring(5).Replace("\"", "") +
- (version == null ? "" : " " + version.Value.Substring(8).Replace("\"","")));
+ (version == null ? "" : " " + version.Value.Substring(8).Replace("\"", "")));
}
// Set the Current Directory to the path the Launcher is located. Fixes some relative path issues.
@@ -626,7 +625,7 @@ namespace AM2RLauncher
mirrorDropDown.Items.AddRange(mirrorDescriptionList); // As above, find a way to get this inside the dropDown definition
mirrorIndex = (int.Parse(CrossPlatformOperations.ReadFromConfig("MirrorIndex")) < mirrorDropDown.Items.Count) ? int.Parse(CrossPlatformOperations.ReadFromConfig("MirrorIndex")) : 0;
- mirrorDropDown.SelectedIndex = mirrorIndex;
+ mirrorDropDown.SelectedIndex = mirrorIndex;
currentMirror = mirrorList[mirrorDropDown.SelectedIndex];
diff --git a/AM2RLauncher/AM2RLauncher/MainForm/Splash.cs b/AM2RLauncher/AM2RLauncher/MainForm/Splash.cs
index 43c4b2f..c670e4c 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/Splash.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/Splash.cs
@@ -1,6 +1,5 @@
using Eto;
using System;
-using System.Collections.Generic;
using System.Linq;
namespace AM2RLauncher
@@ -81,9 +80,9 @@ namespace AM2RLauncher
string[] combinedSplash;
Random rng = new Random();
- if (Platform.Instance.IsGtk)
+ if (Platform.Instance.IsGtk)
combinedSplash = generalSplash.Concat(linuxSplash).ToArray();
- else
+ else
combinedSplash = generalSplash;
string splashString = combinedSplash[rng.Next(0, combinedSplash.Length)];
diff --git a/AM2RLauncher/AM2RLauncher/icon64.ico b/AM2RLauncher/AM2RLauncher/Resources/LauncherIcon.ico
similarity index 100%
rename from AM2RLauncher/AM2RLauncher/icon64.ico
rename to AM2RLauncher/AM2RLauncher/Resources/LauncherIcon.ico
diff --git a/AM2RLauncher/AM2RLauncher/XML/LauncherConfigXML.cs b/AM2RLauncher/AM2RLauncher/XML/LauncherConfigXML.cs
index 54dbd5b..3e6309c 100644
--- a/AM2RLauncher/AM2RLauncher/XML/LauncherConfigXML.cs
+++ b/AM2RLauncher/AM2RLauncher/XML/LauncherConfigXML.cs
@@ -1,10 +1,6 @@
using System;
-using System.Reflection;
-using System.Collections.Generic;
-using System.Text;
-using System.Xml.Serialization;
using System.Linq;
-using System.ComponentModel;
+using System.Xml.Serialization;
namespace AM2RLauncher.XML
{
@@ -87,7 +83,7 @@ namespace AM2RLauncher.XML
public object this[string property]
{
get
- {
+ {
// This is gonna throw an exception, if the property can't be found. because of null.GetValue(this)
return typeof(LauncherConfigXML).GetProperties().Where(p => p.CanRead && p.Name == property).First().GetValue(this).ToString();
}
diff --git a/AM2RLauncher/AM2RLauncher/XML/ProfileXML.cs b/AM2RLauncher/AM2RLauncher/XML/ProfileXML.cs
index 02c7a91..3af457e 100644
--- a/AM2RLauncher/AM2RLauncher/XML/ProfileXML.cs
+++ b/AM2RLauncher/AM2RLauncher/XML/ProfileXML.cs
@@ -1,12 +1,8 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using System.Xml.Serialization;
namespace AM2RLauncher.XML
-{
+{
///
/// Class that handles how the mod settings are saved as XML.
///
diff --git a/AM2RLauncher/AM2RLauncher/XML/Serializer.cs b/AM2RLauncher/AM2RLauncher/XML/Serializer.cs
index c4a5ee5..869995b 100644
--- a/AM2RLauncher/AM2RLauncher/XML/Serializer.cs
+++ b/AM2RLauncher/AM2RLauncher/XML/Serializer.cs
@@ -1,9 +1,5 @@
using System;
-using System.Collections.Generic;
using System.IO;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Web;
using System.Text;
namespace AM2RLauncher.XML