From 3f53c1ee2f9b0460308544d1f81e730bba23a573 Mon Sep 17 00:00:00 2001 From: Miepee <38186597+Miepee@users.noreply.github.com> Date: Fri, 7 Jan 2022 08:59:45 +0100 Subject: [PATCH] Fix logging if using custom datapath on windows --- .../AM2RLauncher.Wpf/AM2RLauncher.Wpf.csproj | 15 ++ AM2RLauncher/AM2RLauncher.Wpf/Program.cs | 12 +- .../Properties/Resources.Designer.cs | 85 +++++++++++ .../Properties/Resources.resx | 139 ++++++++++++++++++ 4 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 AM2RLauncher/AM2RLauncher.Wpf/Properties/Resources.Designer.cs create mode 100644 AM2RLauncher/AM2RLauncher.Wpf/Properties/Resources.resx diff --git a/AM2RLauncher/AM2RLauncher.Wpf/AM2RLauncher.Wpf.csproj b/AM2RLauncher/AM2RLauncher.Wpf/AM2RLauncher.Wpf.csproj index d553da1..9621af8 100644 --- a/AM2RLauncher/AM2RLauncher.Wpf/AM2RLauncher.Wpf.csproj +++ b/AM2RLauncher/AM2RLauncher.Wpf/AM2RLauncher.Wpf.csproj @@ -41,6 +41,21 @@ + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + Never diff --git a/AM2RLauncher/AM2RLauncher.Wpf/Program.cs b/AM2RLauncher/AM2RLauncher.Wpf/Program.cs index 75799e1..d4bf4b3 100644 --- a/AM2RLauncher/AM2RLauncher.Wpf/Program.cs +++ b/AM2RLauncher/AM2RLauncher.Wpf/Program.cs @@ -22,8 +22,18 @@ namespace AM2RLauncher.Wpf [STAThread] public static void Main(string[] args) { + string launcherDataPath = GenerateCurrentPath(); + + // Make sure first, that the path exists + if (!Directory.Exists(launcherDataPath)) + Directory.CreateDirectory(launcherDataPath); + + // Now, see if log4netConfig exists, if not write it again. + if (!File.Exists(launcherDataPath + "/log4net.config")) + File.WriteAllText(launcherDataPath + "/log4net.config", Properties.Resources.log4netContents.Replace("${DATADIR}", launcherDataPath)); + // Configure logger - XmlConfigurator.Configure(new FileInfo(GenerateCurrentPath() + "/log4net.config")); + XmlConfigurator.Configure(new FileInfo(launcherDataPath + "/log4net.config")); // Try catch in case it ever crashes before actually getting to the Eto application try diff --git a/AM2RLauncher/AM2RLauncher.Wpf/Properties/Resources.Designer.cs b/AM2RLauncher/AM2RLauncher.Wpf/Properties/Resources.Designer.cs new file mode 100644 index 0000000..ce32519 --- /dev/null +++ b/AM2RLauncher/AM2RLauncher.Wpf/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.Wpf.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.Wpf.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="${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 [%thread] %level %logg [Rest der Zeichenfolge wurde abgeschnitten]"; ähnelt. + /// + internal static string log4netContents { + get { + return ResourceManager.GetString("log4netContents", resourceCulture); + } + } + } +} diff --git a/AM2RLauncher/AM2RLauncher.Wpf/Properties/Resources.resx b/AM2RLauncher/AM2RLauncher.Wpf/Properties/Resources.resx new file mode 100644 index 0000000..a2cff8e --- /dev/null +++ b/AM2RLauncher/AM2RLauncher.Wpf/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="${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 [%thread] %level %logger - %message%newline" /> + </layout> + </appender> +</log4net> + + \ No newline at end of file