Skip to content

Commit 91f95ec

Browse files
committed
Add confirm on exit option.
1 parent b9f6507 commit 91f95ec

File tree

5 files changed

+3270
-3160
lines changed

5 files changed

+3270
-3160
lines changed

Remote Server/Remote Server.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
<PropertyGroup>
2929
<!-- Set version numbers -->
3030
<ProductMajor>6</ProductMajor>
31-
<ProductMinor>7</ProductMinor>
32-
<ProductPatch>1</ProductPatch>
31+
<ProductMinor>8</ProductMinor>
32+
<ProductPatch>0</ProductPatch>
3333

3434
<!-- Set the pre-release string without a leading minus e.g. rc.1 -->
35-
<ProductPreRelease></ProductPreRelease>
35+
<ProductPreRelease>rc.2</ProductPreRelease>
3636

3737
<!--Create a dynamic revision number based on time of build
3838

Remote Server/ServerForm.cs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public partial class ServerForm : Form
161161
internal const string MINIMISE_ON_START_PROFILENAME = "Minimise On Start"; public const bool MINIMISE_ON_START_DEFAULT = false;
162162
internal const string CHECK_FOR_UPDATES = "Check For Updates"; public const bool CHECK_FOR_UPDATES_DEFAULT = true;
163163
internal const string CHECK_FOR_PRE_RELEASE = "Check For Pre-release Updates"; public const bool CHECK_FOR_PRE_RELEASE_DEFAULT = true;
164+
internal const string SUPPRESS_CONFIRMATION_ON_WINDOWS_CLOSE = "Suppress Confirmation On Windows Close"; public const bool SUPPRESS_CONFIRMATION_ON_WINDOWS_CLOSE_DEFAULT = false;
164165

165166
// Minimise behaviour strings
166167
internal const string MINIMISE_TO_SYSTEM_TRAY_KEY = "Minimise to system tray";
@@ -282,6 +283,7 @@ public partial class ServerForm : Form
282283
internal static bool StartMinimised;
283284
internal static bool CheckForUpdates;
284285
internal static bool CheckForPreReleaseUpdates;
286+
internal static bool SuppressConfirmationOnWindowsClose;
285287

286288
#endregion
287289

@@ -1654,6 +1656,7 @@ public static void ReadProfile()
16541656
StartMinimised = driverProfile.GetValue<bool>(MINIMISE_ON_START_PROFILENAME, string.Empty, MINIMISE_ON_START_DEFAULT);
16551657
CheckForUpdates = driverProfile.GetValue<bool>(CHECK_FOR_UPDATES, string.Empty, CHECK_FOR_UPDATES_DEFAULT);
16561658
CheckForPreReleaseUpdates = driverProfile.GetValue<bool>(CHECK_FOR_PRE_RELEASE, string.Empty, CHECK_FOR_PRE_RELEASE_DEFAULT);
1659+
SuppressConfirmationOnWindowsClose = driverProfile.GetValue<bool>(SUPPRESS_CONFIRMATION_ON_WINDOWS_CLOSE, string.Empty, SUPPRESS_CONFIRMATION_ON_WINDOWS_CLOSE_DEFAULT);
16571660

16581661
// Set the next log roll-over time using the persisted roll-over time value
16591662
SetNextRolloverTime();
@@ -1775,6 +1778,7 @@ public static void WriteProfile()
17751778
driverProfile.SetValueInvariant<bool>(MINIMISE_ON_START_PROFILENAME, string.Empty, StartMinimised);
17761779
driverProfile.SetValueInvariant<bool>(CHECK_FOR_UPDATES, string.Empty, CheckForUpdates);
17771780
driverProfile.SetValueInvariant<bool>(CHECK_FOR_PRE_RELEASE, string.Empty, CheckForPreReleaseUpdates);
1781+
driverProfile.SetValueInvariant<bool>(SUPPRESS_CONFIRMATION_ON_WINDOWS_CLOSE, string.Empty, SuppressConfirmationOnWindowsClose);
17781782

17791783
// Update the next roll-over time in case the time has changed
17801784
//TL.LogMessage("WriteProfile", $"NextRolloverTime Before: {NextRolloverTime}");
@@ -1973,21 +1977,29 @@ private void ChkLogRequestsAndResponses_CheckedChanged(object sender, EventArgs
19731977
/// <param name="e"></param>
19741978
private void ServerForm_FormClosing(object sender, FormClosingEventArgs e)
19751979
{
1976-
// Check whether the server is configured to ask for shutdown confirmation
1980+
LogMessage(0, 0, 0, "ServerForm_FormClosing", $"Confirm exit: {ConfirmExit}, Suppress on Windows shutdown: {SuppressConfirmationOnWindowsClose}, Shutdown reason: {e.CloseReason}");
1981+
// Check whether the Remote server is configured to ask for shutdown confirmation
19771982
if (ConfirmExit) // Confirmation is required
1978-
{
1979-
// Ask the user whether they want to close the remote server
1980-
DialogResult result = MessageBox.Show("Are you sure you want to close the Remote Server?", "ASCOM Remote Server", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
1981-
1982-
// An OK result means the user wants to shut down the Remote Server so allow the form to close, otherwise cancel the close.
1983-
if (result != DialogResult.OK)
1984-
e.Cancel = true;
1985-
}
1986-
else // No confirmation is required so go ahead and let the application shut down.
1987-
{
1988-
// No action required
1989-
}
1983+
{
1984+
// Check whether the system is shutting down and whether or not we are suppressing the close dialogue on Windows shutdown
1985+
if (e.CloseReason == CloseReason.WindowsShutDown & SuppressConfirmationOnWindowsClose) // Windows is shutting down and we are suppressing the close dialogue
1986+
{
1987+
// No action required
1988+
}
1989+
else // A close down confirmation dialogue is required.
1990+
{
1991+
// Ask the user whether they want to close the remote server
1992+
DialogResult result = MessageBox.Show("Are you sure you want to close the Remote Server?", "ASCOM Remote Server", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
19901993

1994+
// An OK result means the user wants to shut down the Remote Server so allow the form to close, otherwise cancel the close.
1995+
if (result != DialogResult.OK)
1996+
e.Cancel = true;
1997+
}
1998+
}
1999+
else // No confirmation is required so go ahead and let the application shut down.
2000+
{
2001+
// No action required
2002+
}
19912003
}
19922004

19932005
/// <summary>

0 commit comments

Comments
 (0)