implement data folder for log.config, use code cleaner

pull/30/head
Miepee 5 years ago
parent 664e39f18b
commit 0446689e77

@ -1,7 +1,7 @@
using Eto.Forms; using Eto.Forms;
using log4net; using log4net;
using System;
using log4net.Config; using log4net.Config;
using System;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
@ -22,19 +22,18 @@ namespace AM2RLauncher.Gtk
[STAThread] [STAThread]
public static void Main(string[] args) public static void Main(string[] args)
{ {
string launcherDataPath = GenerateCurrentPath();
string localAM2RPath = Environment.GetEnvironmentVariable("HOME") + "/.local/share/AM2RLauncher"; // Make sure first, ~/.local/share/AM2RLauncher exists
if (!Directory.Exists(launcherDataPath))
// Make sure first, ~/.local/share exists Directory.CreateDirectory(launcherDataPath);
if (!Directory.Exists(localAM2RPath))
Directory.CreateDirectory(localAM2RPath);
// Now, see if log4netConfig exists, if not write it again. // Now, see if log4netConfig exists, if not write it again.
if (!File.Exists(localAM2RPath + "/log4net.config")) if (!File.Exists(launcherDataPath + "/log4net.config"))
File.WriteAllText(localAM2RPath + "/log4net.config", Properties.Resources.log4netContents); File.WriteAllText(launcherDataPath + "/log4net.config", Properties.Resources.log4netContents.Replace("${DATADIR}", launcherDataPath));
// Configure logger // Configure logger
XmlConfigurator.Configure(new FileInfo(localAM2RPath + "/log4net.config")); XmlConfigurator.Configure(new FileInfo(launcherDataPath + "/log4net.config"));
try try
{ {
@ -43,7 +42,7 @@ namespace AM2RLauncher.Gtk
GTKLauncher.UnhandledException += GTKLauncher_UnhandledException; GTKLauncher.UnhandledException += GTKLauncher_UnhandledException;
GTKLauncher.Run(new MainForm()); 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()); 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()); 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()); 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); 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);
}
} }
} }

@ -19,7 +19,7 @@ namespace AM2RLauncher.Gtk.Properties {
// -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. // -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 // 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. // 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.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources { internal class Resources {
@ -67,14 +67,14 @@ namespace AM2RLauncher.Gtk.Properties {
/// <appender-ref ref="file" /> /// <appender-ref ref="file" />
/// </root> /// </root>
/// <appender name="file" type="log4net.Appender.RollingFileAppender"> /// <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" /> /// <appendToFile value="true" />
/// <rollingStyle value="Once" /> /// <rollingStyle value="Once" />
/// <maxSizeRollBackups value="7" /> /// <maxSizeRollBackups value="7" />
/// <maximumFileSize value="3MB" /> /// <maximumFileSize value="3MB" />
/// <staticLogFileName value="true" /> /// <staticLogFileName value="true" />
/// <layout type="log4net.Layout.PatternLayout"> /// <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.
/// </summary> /// </summary>
internal static string log4netContents { internal static string log4netContents {
get { get {

@ -124,7 +124,7 @@
&lt;appender-ref ref="file" /&gt; &lt;appender-ref ref="file" /&gt;
&lt;/root&gt; &lt;/root&gt;
&lt;appender name="file" type="log4net.Appender.RollingFileAppender"&gt; &lt;appender name="file" type="log4net.Appender.RollingFileAppender"&gt;
&lt;file value="${HOME}/.local/share/AM2RLauncher/Logs/AM2RLauncher.log" /&gt; &lt;file value="${DATADIR}/Logs/AM2RLauncher.log" /&gt;
&lt;appendToFile value="true" /&gt; &lt;appendToFile value="true" /&gt;
&lt;rollingStyle value="Once" /&gt; &lt;rollingStyle value="Once" /&gt;
&lt;maxSizeRollBackups value="7" /&gt; &lt;maxSizeRollBackups value="7" /&gt;

@ -1,14 +1,14 @@
using Eto.Forms; using Eto.Forms;
using System;
using log4net; using log4net;
using log4net.Config; using log4net.Config;
using System;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
namespace AM2RLauncher.Wpf namespace AM2RLauncher.Wpf
{ {
/// <summary> /// <summary>
/// The main class for the GTK project. /// The main class for the WinForms project.
/// </summary> /// </summary>
class MainClass class MainClass
{ {
@ -17,13 +17,13 @@ namespace AM2RLauncher.Wpf
/// </summary> /// </summary>
private static readonly ILog log = LogManager.GetLogger(typeof(MainForm)); private static readonly ILog log = LogManager.GetLogger(typeof(MainForm));
/// <summary> /// <summary>
/// The main method for the GTK project. /// The main method for the WinForms project.
/// </summary> /// </summary>
[STAThread] [STAThread]
public static void Main(string[] args) public static void Main(string[] args)
{ {
// Configure logger // 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 catch in case it ever crashes before actually getting to the Eto application
try try
@ -33,7 +33,7 @@ namespace AM2RLauncher.Wpf
WinLauncher.UnhandledException += WinLauncher_UnhandledException; WinLauncher.UnhandledException += WinLauncher_UnhandledException;
WinLauncher.Run(new MainForm()); 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()); 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", 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) 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()); 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);
} }
} }
} }

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 17
VisualStudioVersion = 16.0.31005.135 VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AM2RLauncher", "AM2RLauncher\AM2RLauncher.csproj", "{9B67055C-5AEF-4F83-AFE0-38E600183C9F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AM2RLauncher", "AM2RLauncher\AM2RLauncher.csproj", "{9B67055C-5AEF-4F83-AFE0-38E600183C9F}"
EndProject EndProject

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<ApplicationIcon>icon64.ico</ApplicationIcon> <ApplicationIcon>Resources\LauncherIcon.ico</ApplicationIcon>
<Authors>Lojemiru, Miepee</Authors> <Authors>Lojemiru, Miepee</Authors>
<Company>AM2R-Community-Developers</Company> <Company>AM2R-Community-Developers</Company>
<Description>This is a Launcher for AM2R and its Community Updates.</Description> <Description>This is a Launcher for AM2R and its Community Updates.</Description>
@ -19,6 +19,10 @@
<DebugSymbols>false</DebugSymbols> <DebugSymbols>false</DebugSymbols>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Content Include="Resources\LauncherIcon.ico" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Eto.Forms" Version="2.5.11" /> <PackageReference Include="Eto.Forms" Version="2.5.11" />
<PackageReference Include="LibGit2Sharp" Version="0.26.2" /> <PackageReference Include="LibGit2Sharp" Version="0.26.2" />
@ -75,4 +79,10 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="../../LICENSE">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

@ -1,21 +1,19 @@
using Eto; using Eto;
using Eto.Forms; using log4net;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration; using System.Configuration;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Text;
using System.Reflection; using System.Reflection;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using log4net;
namespace AM2RLauncher namespace AM2RLauncher
{ {
/// <summary> /// <summary>
/// Class that does Operations that work cross-platform. /// Class that does Operations that work cross-platform.
/// </summary> /// </summary>
class CrossPlatformOperations public class CrossPlatformOperations
{ {
/// <summary> /// <summary>
/// The logger for <see cref="MainForm"/>, used to write any caught exceptions. /// The logger for <see cref="MainForm"/>, used to write any caught exceptions.
@ -25,17 +23,27 @@ namespace AM2RLauncher
/// <summary> /// <summary>
/// Gets the current platform. /// Gets the current platform.
/// </summary> /// </summary>
readonly private static Platform currentPlatform = Platform.Instance; private static readonly Platform currentPlatform = Platform.Instance;
/// <summary> /// <summary>
/// Current Path where the Launcher is located. For more info, check <see cref="GenerateCurrentPath"/>. /// Current Path where the Launcher is located. For more info, check <see cref="GenerateCurrentPath"/>.
/// </summary> /// </summary>
static readonly public string CURRENTPATH = GenerateCurrentPath(); public static readonly string CURRENTPATH = GenerateCurrentPath();
/// <summary> /// <summary>
/// Name of the Launcher executable. /// Name of the Launcher executable.
/// </summary> /// </summary>
static readonly public string LAUNCHERNAME = AppDomain.CurrentDomain.FriendlyName; public static readonly string LAUNCHERNAME = AppDomain.CurrentDomain.FriendlyName;
/// <summary>
/// Path to the Home Folder on *Nix-based systems.
/// </summary>
public static readonly string NIXHOME = Environment.GetEnvironmentVariable("HOME");
/// <summary>
/// Path to the Config folder on *Nix-based systems.
/// </summary>
public static readonly string NIXXDGCONFIG = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");
/// <summary> /// <summary>
/// Generates the mirror list, depending on the current Platform. /// Generates the mirror list, depending on the current Platform.
@ -82,9 +90,8 @@ namespace AM2RLauncher
if (currentPlatform.IsGtk) if (currentPlatform.IsGtk)
{ {
// Config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config) // Config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config)
string homePath = Environment.GetEnvironmentVariable("HOME"); string homePath = NIXHOME;
string xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); string launcherConfigPath = (String.IsNullOrWhiteSpace(NIXXDGCONFIG) ? (homePath + "/.config") : NIXXDGCONFIG) + "/AM2RLauncher";
string launcherConfigPath = (String.IsNullOrWhiteSpace(xdgConfigHome) ? (homePath + "/.config") : xdgConfigHome) + "/AM2RLauncher";
string launcherConfigFilePath = launcherConfigPath + "/config.xml"; string launcherConfigFilePath = launcherConfigPath + "/config.xml";
XML.LauncherConfigXML launcherConfig = new XML.LauncherConfigXML(); XML.LauncherConfigXML launcherConfig = new XML.LauncherConfigXML();
@ -130,9 +137,8 @@ namespace AM2RLauncher
else if (currentPlatform.IsGtk) else if (currentPlatform.IsGtk)
{ {
// Config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config) // Config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config)
string homePath = Environment.GetEnvironmentVariable("HOME"); string homePath = NIXHOME;
string xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); string launcherConfigPath = (String.IsNullOrWhiteSpace(NIXXDGCONFIG) ? (homePath + "/.config") : NIXXDGCONFIG) + "/AM2RLauncher";
string launcherConfigPath = (String.IsNullOrWhiteSpace(xdgConfigHome) ? (homePath + "/.config") : xdgConfigHome) + "/AM2RLauncher";
string launcherConfigFilePath = launcherConfigPath + "/config.xml"; string launcherConfigFilePath = launcherConfigPath + "/config.xml";
XML.LauncherConfigXML launcherConfig = new XML.LauncherConfigXML(); XML.LauncherConfigXML launcherConfig = new XML.LauncherConfigXML();
@ -170,7 +176,7 @@ namespace AM2RLauncher
MatchCollection oldMatch = settingRegex.Matches(oldConfigText); MatchCollection oldMatch = settingRegex.Matches(oldConfigText);
MatchCollection newMatch = settingRegex.Matches(newConfigText); 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); newConfigText = newConfigText.Replace(newMatch[i].Value, oldMatch[i].Value);
File.WriteAllText(newConfigPath, newConfigText); File.WriteAllText(newConfigPath, newConfigText);
@ -179,9 +185,8 @@ namespace AM2RLauncher
else if (currentPlatform.IsGtk) else if (currentPlatform.IsGtk)
{ {
// Config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config) // Config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config)
string homePath = Environment.GetEnvironmentVariable("HOME"); string homePath = NIXHOME;
string xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); string launcherConfigPath = (String.IsNullOrWhiteSpace(NIXXDGCONFIG) ? (homePath + "/.config") : NIXXDGCONFIG) + "/AM2RLauncher";
string launcherConfigPath = (String.IsNullOrWhiteSpace(xdgConfigHome) ? (homePath + "/.config") : xdgConfigHome) + "/AM2RLauncher";
string launcherConfigFilePath = launcherConfigPath + "/config.xml"; string launcherConfigFilePath = launcherConfigPath + "/config.xml";
XML.LauncherConfigXML launcherConfig = new XML.LauncherConfigXML(); 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... // 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 // And on Nix systems, we want to replace ~ with its corresponding env var
string realPath = currentPlatform.IsWinForms ? Environment.ExpandEnvironmentVariables(path).Replace("/", "\\") string realPath = currentPlatform.IsWinForms ? Environment.ExpandEnvironmentVariables(path).Replace("/", "\\")
: path.Replace("~", Environment.GetEnvironmentVariable("HOME")); : path.Replace("~", NIXHOME);
if (!Directory.Exists(realPath)) if (!Directory.Exists(realPath))
{ {
log.Info(realPath + " did not exist and was created"); 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... // 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 // And on nix systems, we want to replace ~ with its corresponding env var
string realPath = currentPlatform.IsWinForms ? Environment.ExpandEnvironmentVariables(path).Replace("/", "\\") string realPath = currentPlatform.IsWinForms ? Environment.ExpandEnvironmentVariables(path).Replace("/", "\\")
: path.Replace("~", Environment.GetEnvironmentVariable("HOME")); : path.Replace("~", NIXHOME);
if (!File.Exists(realPath)) if (!File.Exists(realPath))
{ {
log.Error(realPath + "did not exist, operation to open its folder was cancelled!"); log.Error(realPath + "did not exist, operation to open its folder was cancelled!");
@ -273,16 +278,16 @@ namespace AM2RLauncher
arguments = "-version"; arguments = "-version";
} }
ProcessStartInfo javaStart = new ProcessStartInfo(); ProcessStartInfo javaStart = new ProcessStartInfo
javaStart.FileName = process; {
javaStart.Arguments = arguments; FileName = process,
javaStart.UseShellExecute = false; Arguments = arguments,
javaStart.CreateNoWindow = true; 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 // This is primarily for linux, but could be happening on windows as well
try try
@ -297,7 +302,6 @@ namespace AM2RLauncher
} }
return java.ExitCode == 0; return java.ExitCode == 0;
} }
/// <summary> /// <summary>
@ -309,16 +313,16 @@ namespace AM2RLauncher
string process = "xdelta3"; string process = "xdelta3";
string arguments = "-V"; string arguments = "-V";
ProcessStartInfo xdeltaStart = new ProcessStartInfo(); ProcessStartInfo xdeltaStart = new ProcessStartInfo
xdeltaStart.FileName = process; {
xdeltaStart.Arguments = arguments; FileName = process,
xdeltaStart.UseShellExecute = false; Arguments = arguments,
xdeltaStart.CreateNoWindow = true; UseShellExecute = false,
CreateNoWindow = true
};
Process xdelta = new Process();
xdelta.StartInfo = xdeltaStart; Process xdelta = new Process { StartInfo = xdeltaStart };
try try
{ {
@ -347,7 +351,7 @@ namespace AM2RLauncher
if (original == output) if (original == output)
output = 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 + "/", "") + "\""; + "\" \"" + output.Replace(CURRENTPATH + "/", "") + "\"";
if (currentPlatform.IsWinForms) if (currentPlatform.IsWinForms)
@ -438,7 +442,7 @@ namespace AM2RLauncher
if (string.IsNullOrWhiteSpace(xdgDataHome)) if (string.IsNullOrWhiteSpace(xdgDataHome))
{ {
log.Info("Using default Linux CurrentPath."); log.Info("Using default Linux CurrentPath.");
xdgDataHome = Environment.GetEnvironmentVariable("HOME") + "/.local/share"; xdgDataHome = NIXHOME + "/.local/share";
} }
// Add AM2RLauncher to the end of the dataPath // Add AM2RLauncher to the end of the dataPath

@ -1,16 +1,11 @@
using Eto; using AM2RLauncher.Helpers;
using Eto;
using Eto.Forms; using Eto.Forms;
using log4net;
using System; using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Linq;
using System.Net; using System.Net;
using System.Reflection;
using System.Text;
using log4net;
using AM2RLauncher.Helpers;
namespace AM2RLauncher namespace AM2RLauncher
{ {
@ -45,8 +40,6 @@ namespace AM2RLauncher
{ {
log.Info("Running update check..."); log.Info("Running update check...");
string version = VERSION.Replace(".", "");
// Update section // Update section
// Clean old files that have been left // Clean old files that have been left
@ -158,7 +151,7 @@ namespace AM2RLauncher
log.Info("File successfully downloaded."); log.Info("File successfully downloaded.");
} }
} }
catch(UnauthorizedAccessException) catch (UnauthorizedAccessException)
{ {
log.Error("UnauthorizedAccessException caught! Displaying MessageBox."); log.Error("UnauthorizedAccessException caught! Displaying MessageBox.");
MessageBox.Show(Language.Text.UnauthorizedAccessMessage); MessageBox.Show(Language.Text.UnauthorizedAccessMessage);
@ -189,7 +182,7 @@ namespace AM2RLauncher
} }
// Do the same for each subdir // 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()) foreach (FileInfo file in dir.GetFiles())
{ {

@ -1,5 +1,5 @@
using Eto.Forms; using Eto.Drawing;
using Eto.Drawing; using Eto.Forms;
using Pablo.Controls; using Pablo.Controls;
namespace AM2RLauncher namespace AM2RLauncher

@ -1,6 +1,6 @@
using System; using Eto.Drawing;
using Eto.Forms; using Eto.Forms;
using Eto.Drawing; using System;
namespace Pablo.Controls namespace Pablo.Controls
{ {

@ -1,10 +1,8 @@
using log4net; using log4net;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text;
namespace AM2RLauncher.Helpers namespace AM2RLauncher.Helpers
{ {

@ -1,7 +1,5 @@
using System; using Eto.Drawing;
using System.Collections.Generic; using System;
using System.Text;
using Eto.Drawing;
namespace Pablo.Controls namespace Pablo.Controls
{ {

@ -1,26 +1,18 @@
using Eto; using AM2RLauncher.Helpers;
using Eto.Drawing; using AM2RLauncher.XML;
using Eto;
using Eto.Forms; 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;
using LibGit2Sharp.Handlers;
using System;
using System.ComponentModel;
using System.IO; using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using LibGit2Sharp.Handlers;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.ComponentModel; using System.Threading.Tasks;
using System.Net;
using System.IO.Compression;
using AM2RLauncher.XML;
using AM2RLauncher.Helpers;
namespace AM2RLauncher namespace AM2RLauncher
{ {
@ -225,7 +217,7 @@ namespace AM2RLauncher
} }
successful = false; 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); 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); 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]); InstallProfile(profileList[profileIndex.Value]);
} }
catch(Exception ex) catch (Exception ex)
{ {
log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace); 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); MessageBox.Show(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Language.Text.ErrorWindowTitle, MessageBoxType.Error);
@ -578,7 +570,7 @@ namespace AM2RLauncher
log.Error("Mod is for " + profile.OperatingSystem + " while current OS is " + Platform + ". Cancelling mod import."); 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); Language.Text.ErrorWindowTitle, MessageBoxType.Error);
HelperMethods.DeleteDirectory(modsDir + "/" + extractedName); HelperMethods.DeleteDirectory(modsDir + "/" + extractedName);
return; return;
@ -824,7 +816,7 @@ namespace AM2RLauncher
log.Info("Current mirror has been set to " + currentMirror + "."); 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!!! // Don't overwrite the git config while we download!!!
if (updateState == UpdateState.Downloading) return; if (updateState == UpdateState.Downloading) return;

@ -1,21 +1,16 @@
using System; using AM2RLauncher.Helpers;
using System.Collections.Generic; using AM2RLauncher.XML;
using System.Text; using Eto;
using Eto.Drawing;
using Eto.Forms; using Eto.Forms;
using System.Threading;
using LibGit2Sharp; using LibGit2Sharp;
using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using Eto;
using System.Diagnostics;
using System.Linq; 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.Text.RegularExpressions;
using System.Threading;
namespace AM2RLauncher namespace AM2RLauncher
{ {
@ -403,7 +398,7 @@ namespace AM2RLauncher
// Clean files // Clean files
Directory.Delete(profilePath + "/AM2R.AppDir", true); Directory.Delete(profilePath + "/AM2R.AppDir", true);
Directory.Delete(assetsPath, true); Directory.Delete(assetsPath, true);
File.Delete(profilePath + "/" +exe); File.Delete(profilePath + "/" + exe);
if (File.Exists(profilePath + "/AM2R.AppImage")) File.Delete(profilePath + "/AM2R.AppImage"); if (File.Exists(profilePath + "/AM2R.AppImage")) File.Delete(profilePath + "/AM2R.AppImage");
File.Move(profilePath + "/" + "AM2R-x86_64.AppImage", profilePath + "/AM2R.AppImage"); File.Move(profilePath + "/" + "AM2R-x86_64.AppImage", profilePath + "/AM2R.AppImage");
} }
@ -500,7 +495,7 @@ namespace AM2RLauncher
{ {
FileName = proc, FileName = proc,
// For an explanation on the .replace look in CreateXdeltaPatch method // 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, WorkingDirectory = tempDir,
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = true CreateNoWindow = true
@ -646,7 +641,7 @@ namespace AM2RLauncher
// These are used on both windows and linux for game logging // These are used on both windows and linux for game logging
string savePath = Platform.IsWinForms ? profile.SaveLocation.Replace("%localappdata%", Environment.GetEnvironmentVariable("LOCALAPPDATA")) 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"); DirectoryInfo logDir = new DirectoryInfo(savePath + "/logs");
string date = string.Join("-", DateTime.Now.ToString().Split(Path.GetInvalidFileNameChars(), StringSplitOptions.RemoveEmptyEntries)); string date = string.Join("-", DateTime.Now.ToString().Split(Path.GetInvalidFileNameChars(), StringSplitOptions.RemoveEmptyEntries));
@ -704,7 +699,7 @@ namespace AM2RLauncher
{ {
string envVars = customEnvVarTextBox.Text; 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 // Env var variable
string variable = envVars.Substring(0, envVars.IndexOf('=')); 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[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) if (envVars.IndexOf(' ') >= 0)
valueSubstringLength = envVars.IndexOf(' ')+1; valueSubstringLength = envVars.IndexOf(' ') + 1;
else else
valueSubstringLength = envVars.Length; 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 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) if (envVars.IndexOf(' ', secondQuoteIndex) >= 0)
valueSubstringLength = envVars.IndexOf(' ', secondQuoteIndex)+1; valueSubstringLength = envVars.IndexOf(' ', secondQuoteIndex) + 1;
else else
valueSubstringLength = envVars.Length; valueSubstringLength = envVars.Length;
} }
@ -746,7 +741,7 @@ namespace AM2RLauncher
log.Info("CWD of Profile is " + startInfo.WorkingDirectory); log.Info("CWD of Profile is " + startInfo.WorkingDirectory);
log.Info("Launching game with following variables: "); 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 + "\""); log.Info("Key: \"" + item.Key + "\" Value: \"" + item.Value + "\"");
} }
@ -1048,9 +1043,9 @@ namespace AM2RLauncher
case UpdateState.Download: playButton.Enabled = true; playButton.ToolTip = Language.Text.PlayButtonDownloadToolTip; break; 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.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.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.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; case UpdateState.Playing: playButton.Enabled = false; playButton.ToolTip = Language.Text.PlayButtonPlayingToolTip; break;
} }
playButton.Text = GetPlayButtonText(); playButton.Text = GetPlayButtonText();

@ -1,17 +1,16 @@
using Eto.Drawing; using AM2RLauncher.XML;
using Eto.Drawing;
using Eto.Forms; using Eto.Forms;
using log4net;
using Pablo.Controls;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using Pablo.Controls; using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
using System.Globalization;
using AM2RLauncher.XML;
using log4net;
using log4net.Config;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading;
namespace AM2RLauncher namespace AM2RLauncher
{ {
@ -143,7 +142,7 @@ namespace AM2RLauncher
var results = lineRegex.Matches(osRelease).Cast<Match>(); var results = lineRegex.Matches(osRelease).Cast<Match>();
var version = results.FirstOrDefault(x => x.Value.Contains("VERSION")); var version = results.FirstOrDefault(x => x.Value.Contains("VERSION"));
log.Info("Current Distro: " + results.FirstOrDefault(x => x.Value.Contains("NAME")).Value.Substring(5).Replace("\"", "") + 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. // Set the Current Directory to the path the Launcher is located. Fixes some relative path issues.

@ -1,6 +1,5 @@
using Eto; using Eto;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace AM2RLauncher namespace AM2RLauncher

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 101 KiB

@ -1,10 +1,6 @@
using System; using System;
using System.Reflection;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.Linq; using System.Linq;
using System.ComponentModel; using System.Xml.Serialization;
namespace AM2RLauncher.XML namespace AM2RLauncher.XML
{ {

@ -1,8 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization; using System.Xml.Serialization;
namespace AM2RLauncher.XML namespace AM2RLauncher.XML

@ -1,9 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Web;
using System.Text; using System.Text;
namespace AM2RLauncher.XML namespace AM2RLauncher.XML

Loading…
Cancel
Save