From b3f936c194643cab92df01468371240dfbc14d71 Mon Sep 17 00:00:00 2001
From: xRushG <145561288+xRushG@users.noreply.github.com>
Date: Thu, 23 May 2024 21:29:35 +0200
Subject: [PATCH 1/2] - Added my missed comment for outlined
LocalSettingsManager - Fixed a bug that occurred when trying to open the log
file on the Notification settings page. - Removed unnecessary file
association when user tries to open the log file on the Notification page.
The "choose file" dialog handles the extension as it is fixed on .log -
Implemented fallback to open file explorer to the specified file location if
mRem fails to open the log file.
---
mRemoteNG/App/ProgramRoot.cs | 6 ++
.../Forms/OptionsPages/NotificationsPage.cs | 77 ++++++++++++++++++-
2 files changed, 81 insertions(+), 2 deletions(-)
diff --git a/mRemoteNG/App/ProgramRoot.cs b/mRemoteNG/App/ProgramRoot.cs
index c5891894..29023244 100644
--- a/mRemoteNG/App/ProgramRoot.cs
+++ b/mRemoteNG/App/ProgramRoot.cs
@@ -21,6 +21,12 @@ namespace mRemoteNG.App
[STAThread]
public static void Main(string[] args)
{
+ /*
+ * Temporarily disable LocalSettingsManager initialization at startup
+ * due to unfinished implementation causing build errors.
+ * Uncomment if needed in your local repo.
+ */
+ /*
/*var settingsManager = new LocalSettingsManager();
// Check if the database exists
diff --git a/mRemoteNG/UI/Forms/OptionsPages/NotificationsPage.cs b/mRemoteNG/UI/Forms/OptionsPages/NotificationsPage.cs
index 159dee05..7a40c08d 100644
--- a/mRemoteNG/UI/Forms/OptionsPages/NotificationsPage.cs
+++ b/mRemoteNG/UI/Forms/OptionsPages/NotificationsPage.cs
@@ -155,8 +155,15 @@ namespace mRemoteNG.UI.Forms.OptionsPages
private void buttonOpenLogFile_Click(object sender, System.EventArgs e)
{
- if (Path.GetExtension(textBoxLogPath.Text) == ".log")
- Process.Start(textBoxLogPath.Text);
+ string logFile = textBoxLogPath.Text;
+ bool doesExist = File.Exists(logFile);
+
+ if (doesExist && OpenLogAssociated(logFile))
+ return;
+ else if (doesExist && OpenLogNotepad(logFile))
+ return;
+
+ OpenLogLocation(logFile);
}
private void chkLogToCurrentDir_CheckedChanged(object sender, System.EventArgs e)
@@ -165,5 +172,71 @@ namespace mRemoteNG.UI.Forms.OptionsPages
buttonRestoreDefaultLogPath.Enabled = !chkLogToCurrentDir.Checked;
textBoxLogPath.Text = Logger.DefaultLogPath;
}
+
+ #region Privat Methods to Open Logfile
+
+ ///
+ /// Attempts to open a file using the default application associated with its file type.
+ ///
+ /// The path of the file to be opened.
+ /// True if the operation was successful; otherwise, false.
+ private static bool OpenLogAssociated(string path)
+ {
+ try
+ {
+ // Open the file using the default application associated with its file type based on the user's preference
+ Process.Start(path);
+ return true;
+ }
+ catch
+ {
+ // If necessary, the error can be logged here.
+ return false;
+ }
+ }
+
+ ///
+ /// Attempts to open a file in Notepad, the default text editor on Windows systems.
+ ///
+ /// The path of the file to be opened in Notepad.
+ /// True if the operation was successful; otherwise, false.
+ private static bool OpenLogNotepad(string path)
+ {
+ try
+ {
+ // Open it in "Notepad" (Windows default editor).
+ // Usually available on all Windows systems
+ Process.Start("notepad.exe", path);
+ return true;
+ }
+ catch
+ {
+ // If necessary, the error can be logged here.
+ return false;
+ }
+ }
+
+ ///
+ /// Attempts to open the location of a specified file in Windows Explorer.
+ ///
+ /// The path of the file whose location needs to be opened.
+ /// True if the operation was successful; otherwise, false.
+ private static bool OpenLogLocation(string path)
+ {
+ try
+ {
+ /// when all fails open filelocation to logfile...
+ // Open Windows Explorer to the directory containing the file
+ Process.Start("explorer.exe", $"/select,\"{path}\"");
+ return true;
+ }
+ catch
+ {
+ // If necessary, the error can be logged here.
+ return false;
+ }
+ }
+
+ #endregion
}
}
\ No newline at end of file
From 99d9e709216e8689b2f69cd2ccc96620567c5f07 Mon Sep 17 00:00:00 2001
From: xRushG <145561288+xRushG@users.noreply.github.com>
Date: Wed, 29 May 2024 15:20:56 +0200
Subject: [PATCH 2/2] Fix #2592: Prevent GeneralAppInfo.ApplicationVersion from
being set in Unit Tests. Not needed for tests.
---
mRemoteNGTests/App/UpdaterTests.cs | 32 ++++++++----------------------
1 file changed, 8 insertions(+), 24 deletions(-)
diff --git a/mRemoteNGTests/App/UpdaterTests.cs b/mRemoteNGTests/App/UpdaterTests.cs
index c4c01c7a..80ee0914 100644
--- a/mRemoteNGTests/App/UpdaterTests.cs
+++ b/mRemoteNGTests/App/UpdaterTests.cs
@@ -9,75 +9,59 @@ namespace mRemoteNGTests.App;
[TestFixture]
public class UpdaterTests
{
+ private readonly Version TestApplicationVersion = new("1.0.0.0");
+
[Test]
public void UpdateStableChannel()
{
- GeneralAppInfo.ApplicationVersion = "1.0.0.0";
var CurrentUpdateInfo = UpdateInfo.FromString(Resources.update);
Assert.That(CurrentUpdateInfo.CheckIfValid(), Is.True);
- Version v;
- Version.TryParse(GeneralAppInfo.ApplicationVersion, out v);
- var IsNewer = CurrentUpdateInfo.Version > v;
+ bool IsNewer = CurrentUpdateInfo.Version > TestApplicationVersion;
Assert.That(IsNewer, Is.True);
}
[Test]
public void UpdateBetaChannel()
{
- GeneralAppInfo.ApplicationVersion = "1.0.0.0";
var CurrentUpdateInfo = UpdateInfo.FromString(Resources.beta_update);
Assert.That(CurrentUpdateInfo.CheckIfValid(), Is.True);
- Version v;
- Version.TryParse(GeneralAppInfo.ApplicationVersion, out v);
- var IsNewer = CurrentUpdateInfo.Version > v;
+ bool IsNewer = CurrentUpdateInfo.Version > TestApplicationVersion;
Assert.That(IsNewer, Is.True);
}
[Test]
public void UpdateDevChannel()
{
- GeneralAppInfo.ApplicationVersion = "1.0.0.0";
var CurrentUpdateInfo = UpdateInfo.FromString(Resources.dev_update);
Assert.That(CurrentUpdateInfo.CheckIfValid(), Is.True);
- Version v;
- Version.TryParse(GeneralAppInfo.ApplicationVersion, out v);
- var IsNewer = CurrentUpdateInfo.Version > v;
+ bool IsNewer = CurrentUpdateInfo.Version > TestApplicationVersion;
Assert.That(IsNewer, Is.True);
}
[Test]
public void UpdateStablePortableChannel()
{
- GeneralAppInfo.ApplicationVersion = "1.0.0.0";
var CurrentUpdateInfo = UpdateInfo.FromString(Resources.update_portable);
Assert.That(CurrentUpdateInfo.CheckIfValid(), Is.True);
- Version v;
- Version.TryParse(GeneralAppInfo.ApplicationVersion, out v);
- var IsNewer = CurrentUpdateInfo.Version > v;
+ bool IsNewer = CurrentUpdateInfo.Version > TestApplicationVersion;
Assert.That(IsNewer, Is.True);
}
[Test]
public void UpdateBetaPortableChannel()
{
- GeneralAppInfo.ApplicationVersion = "1.0.0.0";
var CurrentUpdateInfo = UpdateInfo.FromString(Resources.beta_update_portable);
Assert.That(CurrentUpdateInfo.CheckIfValid(), Is.True);
- Version v;
- Version.TryParse(GeneralAppInfo.ApplicationVersion, out v);
- var IsNewer = CurrentUpdateInfo.Version > v;
+ bool IsNewer = CurrentUpdateInfo.Version > TestApplicationVersion;
Assert.That(IsNewer, Is.True);
}
[Test]
public void UpdateDevPortableChannel()
{
- GeneralAppInfo.ApplicationVersion = "1.0.0.0";
var CurrentUpdateInfo = UpdateInfo.FromString(Resources.dev_update_portable);
Assert.That(CurrentUpdateInfo.CheckIfValid(), Is.True);
- Version v;
- Version.TryParse(GeneralAppInfo.ApplicationVersion, out v);
- var IsNewer = CurrentUpdateInfo.Version > v;
+ bool IsNewer = CurrentUpdateInfo.Version > TestApplicationVersion;
Assert.That(IsNewer, Is.True);
}
}
\ No newline at end of file