From e461e1b4ab87233281034e42e00e79859d37177f Mon Sep 17 00:00:00 2001 From: Kittenji <41535779+ChrisFeline@users.noreply.github.com> Date: Sun, 29 Dec 2024 04:29:56 -0500 Subject: [PATCH 1/5] Another Try Catch --- Program.cs | 66 +++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/Program.cs b/Program.cs index 0126851..7a32bb2 100644 --- a/Program.cs +++ b/Program.cs @@ -49,52 +49,52 @@ internal static bool ContainsArg(string arg) { [STAThread] static void Main(string[] args) { - Logger.Log("Initializing logging."); - try { + Logger.Log("Initializing logging."); + Directory.SetCurrentDirectory(ProgramDirectory); Logger.Log("Program Directory: " + ProgramDirectory); - } catch (Exception e) { - Logger.Error("Failed to set Program Directory to: " + ProgramDirectory); - Logger.Error(e.ToString()); - } - Arguments = args; - CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; - CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; - Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; + Arguments = args; + CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; + CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; + Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - if (CheckMutex()) { - // Don't run program if it's already running, instead we focus the already existing window - NativeMethods.PostMessage((IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.WM_FOCUSINST, IntPtr.Zero, IntPtr.Zero); - return; - } + if (CheckMutex()) { + // Don't run program if it's already running, instead we focus the already existing window + NativeMethods.PostMessage((IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.WM_FOCUSINST, IntPtr.Zero, IntPtr.Zero); + return; + } - if (!Directory.Exists(DataLocation)) Directory.CreateDirectory(DataLocation); + if (!Directory.Exists(DataLocation)) Directory.CreateDirectory(DataLocation); - LANG.Initialize(); - Updater.CheckPostUpdate(args); + LANG.Initialize(); + Updater.CheckPostUpdate(args); - Logger.Log("Initializing application rendering."); - ApplicationConfiguration.Initialize(); - Application.SetCompatibleTextRenderingDefault(true); + Logger.Log("Initializing application rendering."); + ApplicationConfiguration.Initialize(); + Application.SetCompatibleTextRenderingDefault(true); - Logger.Log("Initializing font."); - InitializeFont(); + Logger.Log("Initializing font."); + InitializeFont(); - MainWindow.Started = false; + MainWindow.Started = false; - if (!StartCheckForUpdate()) { - Application.ApplicationExit += OnApplicationExit; + if (!StartCheckForUpdate()) { + Application.ApplicationExit += OnApplicationExit; - Logger.Log("Running 'MainWindow'"); - Application.Run(new MainWindow()); - } + Logger.Log("Running 'MainWindow'"); + Application.Run(new MainWindow()); + } - // Check when all forms close - Logger.Log("All windows are closed..."); - GitHubUpdate.Start(); + // Check when all forms close + Logger.Log("All windows are closed..."); + GitHubUpdate.Start(); + } catch (Exception e) { + // What the heck happened? + File.WriteAllText(Path.Combine(DataLocation, "output.error"), e.ToString()); + } } private static void OnApplicationExit(object? sender, EventArgs e) { From 8c1af41e3b1819da6fce70c4139718797c7819b7 Mon Sep 17 00:00:00 2001 From: Kittenji <41535779+ChrisFeline@users.noreply.github.com> Date: Sun, 29 Dec 2024 04:30:17 -0500 Subject: [PATCH 2/5] Fix 'Copy On Join' --- Models/SaveData.cs | 20 ++++++++++++++++++++ Utils/LogParser/ToNLogContext.cs | 2 +- Windows/MainWindow.cs | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Models/SaveData.cs b/Models/SaveData.cs index 6a19271..bbbed8e 100644 --- a/Models/SaveData.cs +++ b/Models/SaveData.cs @@ -136,6 +136,26 @@ public void SetParsedPos(string name, long pos, bool save) if (save) SetDirty(); } + public Entry? FindRecentEntry() { + if (Collection.Count == 0) return null; + + History? latest = null; + foreach (History h in Collection) { + if (!h.IsCustom && (latest == null || h.UniversalTime > latest.UniversalTime)) + latest = h; + } + + if (latest == null || latest.Database.Count == 0) return null; + + Entry? recent = null; + foreach (Entry e in latest.Database) { + if (recent == null || e.Timestamp > latest.Timestamp) + recent = e; + } + + return recent; + } + public static void OpenDataLocation() { MainWindow.OpenExternalLink(Path.GetDirectoryName(Destination) ?? string.Empty); diff --git a/Utils/LogParser/ToNLogContext.cs b/Utils/LogParser/ToNLogContext.cs index 3fec745..d557080 100644 --- a/Utils/LogParser/ToNLogContext.cs +++ b/Utils/LogParser/ToNLogContext.cs @@ -53,7 +53,7 @@ public override void Enter(string instanceID, bool isHomeWorld) { DSRichPresence.SetInstanceID(instanceID, isHomeWorld); if (isHomeWorld && Settings.Get.AutoCopy && Settings.Get.CopyOnJoin && MainWindow.Started) { - MainWindow.Instance?.CopyRecent(true); + MainWindow.CopyRecentData(); NotificationManager.PlayCopy(); } } diff --git a/Windows/MainWindow.cs b/Windows/MainWindow.cs index 98018b8..725c7d3 100644 --- a/Windows/MainWindow.cs +++ b/Windows/MainWindow.cs @@ -1060,6 +1060,7 @@ internal void CopyRecent(bool force) { RecentData.Fresh = false; } + internal static void CopyRecentData() => SaveData.FindRecentEntry()?.CopyToClipboard(); #endregion } From 09d735bfee55da156e5e7db40bff1392b8e2e6ad Mon Sep 17 00:00:00 2001 From: Kittenji <41535779+ChrisFeline@users.noreply.github.com> Date: Sun, 29 Dec 2024 04:48:22 -0500 Subject: [PATCH 3/5] Fix Auto Copy Again --- Models/SaveData.cs | 2 +- Utils/LogParser/ToNLogContext.cs | 4 +--- Windows/MainWindow.cs | 25 +++++++++++++------------ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Models/SaveData.cs b/Models/SaveData.cs index bbbed8e..3be8c02 100644 --- a/Models/SaveData.cs +++ b/Models/SaveData.cs @@ -149,7 +149,7 @@ public void SetParsedPos(string name, long pos, bool save) Entry? recent = null; foreach (Entry e in latest.Database) { - if (recent == null || e.Timestamp > latest.Timestamp) + if (recent == null || e.Timestamp > recent.Timestamp) recent = e; } diff --git a/Utils/LogParser/ToNLogContext.cs b/Utils/LogParser/ToNLogContext.cs index d557080..4a3a7d5 100644 --- a/Utils/LogParser/ToNLogContext.cs +++ b/Utils/LogParser/ToNLogContext.cs @@ -52,10 +52,8 @@ public override void Enter(string instanceID, bool isHomeWorld) { WebSocketAPI.SendValue("INSTANCE", instanceID); DSRichPresence.SetInstanceID(instanceID, isHomeWorld); - if (isHomeWorld && Settings.Get.AutoCopy && Settings.Get.CopyOnJoin && MainWindow.Started) { + if (isHomeWorld && Settings.Get.AutoCopy && Settings.Get.CopyOnJoin && MainWindow.Started) MainWindow.CopyRecentData(); - NotificationManager.PlayCopy(); - } } } diff --git a/Windows/MainWindow.cs b/Windows/MainWindow.cs index 725c7d3..97dcf45 100644 --- a/Windows/MainWindow.cs +++ b/Windows/MainWindow.cs @@ -95,8 +95,8 @@ private void mainWindow_Shown(object sender, EventArgs e) { Started = true; SetTitle(null); - if (Settings.Get.CopyOnOpen) - CopyRecent(true); + if (Settings.Get.AutoCopy && Settings.Get.CopyOnOpen) + CopyRecentData(); LilOSC.Initialize(); WebSocketAPI.Initialize(); @@ -643,7 +643,7 @@ private void LogWatcher_OnLine(object? sender, OnLineArgs e) { } private void LogWatcher_OnTick(object? sender, EventArgs e) { - if ((Settings.Get.CopyOnSave && Started)) + if (Settings.Get.CopyOnSave && Started) CopyRecent(false); Export(); @@ -955,14 +955,6 @@ private void FirstImport() { if (temp == null || temp.UniversalTime < h.UniversalTime) temp = h; } - - if (Settings.Get.AutoCopy && Settings.Get.CopyOnOpen) { - Entry? first = temp?.Database.FirstOrDefault(); - if (first != null) { - SetRecent(first); - NotificationManager.PlayCopy(); - } - } } private void AddCustomEntry(Entry entry, History? collection) { @@ -1058,9 +1050,18 @@ internal void CopyRecent(bool force) { RecentData.CopyToClipboard(); RecentData.Fresh = false; + + NotificationManager.PlayCopy(); } - internal static void CopyRecentData() => SaveData.FindRecentEntry()?.CopyToClipboard(); + internal static void CopyRecentData() { + Entry? entry = SaveData.FindRecentEntry(); + + if (entry != null) { + entry.CopyToClipboard(); + NotificationManager.PlayCopy(); + } + } #endregion } From 6f0ac8fafa0a7bc4ade7951633bd3e094bb96fa9 Mon Sep 17 00:00:00 2001 From: Kittenji <41535779+ChrisFeline@users.noreply.github.com> Date: Sun, 29 Dec 2024 04:54:52 -0500 Subject: [PATCH 4/5] Remove Copy Audio from saves --- Windows/MainWindow.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Windows/MainWindow.cs b/Windows/MainWindow.cs index 97dcf45..9f0d5d8 100644 --- a/Windows/MainWindow.cs +++ b/Windows/MainWindow.cs @@ -1050,8 +1050,6 @@ internal void CopyRecent(bool force) { RecentData.CopyToClipboard(); RecentData.Fresh = false; - - NotificationManager.PlayCopy(); } internal static void CopyRecentData() { From 881831340beb0202fb00d5bc4293bcbfe2eb0a72 Mon Sep 17 00:00:00 2001 From: Kittenji <41535779+ChrisFeline@users.noreply.github.com> Date: Mon, 30 Dec 2024 04:41:48 -0500 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dd4b5a..ab3267b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,4 @@ # Latest Changelog -- Fixed terror names on Webhook embed not showing the correct variant name. -- Fixed new line handling on custom Chatbox messages with JS tags. -- Fixed Auto Copy on Open copying while this feature was disabled. -- Removed YoBro, for real this time. \ No newline at end of file +- Fixed 'Auto Copy on Join' feature not working properly. +- Removed YoBro, he's part of a tree now. \ No newline at end of file