From db77e29e26bb9f77fb1f619026d1e24b6811463f Mon Sep 17 00:00:00 2001 From: Miepee <38186597+Miepee@users.noreply.github.com> Date: Mon, 21 Jun 2021 16:40:21 +0200 Subject: [PATCH] Refactor Linux to use .local/share instead of CWD This is in order to be more XDG Base directory compliant and allow potential includes into package repos. --- .../AM2RLauncher.Gtk/AM2RLauncher.Gtk.csproj | 15 ++ AM2RLauncher/AM2RLauncher.Gtk/Program.cs | 13 +- .../Properties/Resources.Designer.cs | 85 +++++++++++ .../Properties/Resources.resx | 139 ++++++++++++++++++ .../AM2RLauncher.Wpf/AM2RLauncher.Wpf.csproj | 3 + .../log4net.config | 0 AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj | 6 - .../AM2RLauncher/CrossPlatformOperations.cs | 4 +- .../AM2RLauncher/MainForm/MainForm.Methods.cs | 2 + 9 files changed, 258 insertions(+), 9 deletions(-) create mode 100644 AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.Designer.cs create mode 100644 AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.resx rename AM2RLauncher/{AM2RLauncher => AM2RLauncher.Wpf}/log4net.config (100%) diff --git a/AM2RLauncher/AM2RLauncher.Gtk/AM2RLauncher.Gtk.csproj b/AM2RLauncher/AM2RLauncher.Gtk/AM2RLauncher.Gtk.csproj index 4ab8dc8..37f997e 100644 --- a/AM2RLauncher/AM2RLauncher.Gtk/AM2RLauncher.Gtk.csproj +++ b/AM2RLauncher/AM2RLauncher.Gtk/AM2RLauncher.Gtk.csproj @@ -13,5 +13,20 @@ + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + diff --git a/AM2RLauncher/AM2RLauncher.Gtk/Program.cs b/AM2RLauncher/AM2RLauncher.Gtk/Program.cs index 9062a81..58d03ac 100644 --- a/AM2RLauncher/AM2RLauncher.Gtk/Program.cs +++ b/AM2RLauncher/AM2RLauncher.Gtk/Program.cs @@ -22,8 +22,19 @@ namespace AM2RLauncher.Gtk [STAThread] public static void Main(string[] args) { + + string localAM2RPath = Environment.GetEnvironmentVariable("HOME") + "/.local/share/AM2RLauncher"; + + // Make sure first, ~/.local/share exists + if (!Directory.Exists(localAM2RPath)) + Directory.CreateDirectory(localAM2RPath); + + // Now, see if log4netConfig exists, if not write it again. + if (!File.Exists(localAM2RPath + "/log4net.config")) + File.WriteAllText(localAM2RPath + "/log4net.config", Properties.Resources.log4netContents); + // Configure logger - XmlConfigurator.Configure(new FileInfo(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "/log4net.config")); + XmlConfigurator.Configure(new FileInfo(localAM2RPath + "/log4net.config")); try { diff --git a/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.Designer.cs b/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.Designer.cs new file mode 100644 index 0000000..ce3bcff --- /dev/null +++ b/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.Designer.cs @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace AM2RLauncher.Gtk.Properties { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder 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 + // 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.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AM2RLauncher.Gtk.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die <log4net> + /// <root> + /// <level value="ALL" /> + /// <appender-ref ref="file" /> + /// </root> + /// <appender name="file" type="log4net.Appender.RollingFileAppender"> + /// <file value="${HOME}/.local/share/AM2RLauncher/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. + /// + internal static string log4netContents { + get { + return ResourceManager.GetString("log4netContents", resourceCulture); + } + } + } +} diff --git a/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.resx b/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.resx new file mode 100644 index 0000000..ce89876 --- /dev/null +++ b/AM2RLauncher/AM2RLauncher.Gtk/Properties/Resources.resx @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + <log4net> + <root> + <level value="ALL" /> + <appender-ref ref="file" /> + </root> + <appender name="file" type="log4net.Appender.RollingFileAppender"> + <file value="${HOME}/.local/share/AM2RLauncher/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 [%thread] %level %logger - %message%newline" /> + </layout> + </appender> +</log4net> + + \ No newline at end of file diff --git a/AM2RLauncher/AM2RLauncher.Wpf/AM2RLauncher.Wpf.csproj b/AM2RLauncher/AM2RLauncher.Wpf/AM2RLauncher.Wpf.csproj index c6b470a..e265ed5 100644 --- a/AM2RLauncher/AM2RLauncher.Wpf/AM2RLauncher.Wpf.csproj +++ b/AM2RLauncher/AM2RLauncher.Wpf/AM2RLauncher.Wpf.csproj @@ -45,6 +45,9 @@ Never + + Always + diff --git a/AM2RLauncher/AM2RLauncher/log4net.config b/AM2RLauncher/AM2RLauncher.Wpf/log4net.config similarity index 100% rename from AM2RLauncher/AM2RLauncher/log4net.config rename to AM2RLauncher/AM2RLauncher.Wpf/log4net.config diff --git a/AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj b/AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj index 3248b27..560f838 100644 --- a/AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj +++ b/AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj @@ -75,10 +75,4 @@ - - - Always - - - \ No newline at end of file diff --git a/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs b/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs index 426eaf7..100494d 100644 --- a/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs +++ b/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs @@ -22,9 +22,9 @@ namespace AM2RLauncher readonly private static Platform currentPlatform = Platform.Instance; /// - /// Current Path where the Launcher is located. + /// Current Path where the Launcher is located. For Linux this is redirected to ~/.local/share/AM2RLauncher, in order to be more compliant to the XDG Base Directory Specification. /// - static readonly public string CURRENTPATH = currentPlatform.IsWinForms ? Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) : Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); + static readonly public string CURRENTPATH = currentPlatform.IsWinForms ? Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) : Environment.GetEnvironmentVariable("HOME") + "/.local/share/AM2RLauncher"; /// /// Name of the Launcher executable. diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs index b24554c..3b980c7 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs @@ -303,6 +303,8 @@ namespace AM2RLauncher exe = "AM2R"; } + log.Info("Attempting to patch in " + profilePath); + if (Platform.IsWinForms) { // Patch game executable