Fixed some UI status messages

This commit is contained in:
Terry MacDonald 2021-10-02 16:22:36 +13:00
parent 02ce747d3c
commit 8bd3d07fa4
8 changed files with 109 additions and 58 deletions

View File

@ -58,8 +58,7 @@ namespace DisplayMagician {
DesktopNotificationManagerCompat.RegisterAumidAndComServer<DesktopNotificationActivator>(ShellUtils.AUMID);
DesktopNotificationManagerCompat.RegisterActivator<DesktopNotificationActivator>();
// Prepare NLog for logging
// Prepare NLog for internal logging - Comment out when not required
//NLog.Common.InternalLogger.LogLevel = NLog.LogLevel.Debug;
//NLog.Common.InternalLogger.LogToConsole = true;
//NLog.Common.InternalLogger.LogFile = "C:\\Users\\terry\\AppData\\Local\\DisplayMagician\\Logs\\nlog-internal.txt";
@ -83,7 +82,25 @@ namespace DisplayMagician {
Console.WriteLine($"Program/StartUpNormally exception: Cannot create the Application Log Folder {AppLogPath} - {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
}
}
// NOTE: This had to be moved up from the later state
// Copy the old Settings file to the new v2 name
bool upgradedSettingsFile = false;
string oldSettingsFile = Path.Combine(AppDataPath, "Settings_1.0.json");
string newSettingsFile = Path.Combine(AppDataPath, "Settings_2.0.json");
try
{
if (File.Exists(oldSettingsFile) && !File.Exists(newSettingsFile))
{
File.Copy(oldSettingsFile, newSettingsFile, true);
upgradedSettingsFile = true;
}
}
catch (Exception ex)
{
logger.Error(ex, $"Program/Main: Exception upgrading v1 settings file {oldSettingsFile} to v2 settings file {ProgramSettings.programSettingsStorageJsonFileName}.");
}
// Load the program settings
AppProgramSettings = ProgramSettings.LoadSettings();
@ -209,9 +226,46 @@ namespace DisplayMagician {
//Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
Application.SetCompatibleTextRenderingDefault(false);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Check if it's an upgrade from DisplayMagician v1 to v2
// and if it is then copy the old configs to the new filenames and
// explain to the user what they need to do.
// e.g. DisplayProfiles_1.0.json exists, but DisplayProfiles_2.0.json doesn't
if (File.Exists(Path.Combine(AppProfilePath, "DisplayProfiles_1.0.json")) && !File.Exists(Path.Combine(AppProfilePath, "DisplayProfiles_2.0.json")))
{
logger.Info($"Program/Main: This is an upgrade from DisplayMagician v1 to DisplayMagician v2, so performing some upgrade steps.");
// Note whether we copied the old Settings file to the new v2 name earlier (before the logging was enabled)
if (upgradedSettingsFile)
{
logger.Info($"Program/Main: Upgraded v1 settings file {oldSettingsFile} to v2 settings file {newSettingsFile} earlier in loading process (before logging service was available).");
}
// Copy the old Game Shortcuts file to the new v2 name
string oldShortcutsFile = Path.Combine(AppShortcutPath, "Shortcuts_1.0.json");
string newShortcutsFile = Path.Combine(AppShortcutPath, "Shortcuts_2.0.json");
try
{
if (File.Exists(oldShortcutsFile) && !File.Exists(newShortcutsFile))
{
logger.Info($"Program/Main: Upgrading v1 shortcut file {oldShortcutsFile} to v2 shortcut file {newShortcutsFile }.");
File.Copy(oldShortcutsFile, newShortcutsFile);
}
}
catch(Exception ex)
{
logger.Error(ex, $"Program/Main: Exception upgrading v1 shortcut file {oldShortcutsFile} to v2 shortcut file {ShortcutRepository.ShortcutStorageFileName}.");
}
// Warn the user about the fact we need a new DisplayProfiles_2.0.json
StartMessageForm myMessageWindow = new StartMessageForm();
myMessageWindow.MessageMode = "rtf";
myMessageWindow.URL = "https://displaymagician.littlebitbig.com/messages/DisplayMagician1to2.rtf";
myMessageWindow.HeadingText = "DisplayMagician v2.0.0 Upgrade Warning";
myMessageWindow.ButtonText = "&Close";
myMessageWindow.ShowDialog();
}
logger.Debug($"Setting up commandline processing configuration");
var app = new CommandLineApplication
@ -615,7 +669,7 @@ namespace DisplayMagician {
try
{
// Save a copy of the DisplayMagician Icon, and all the game library ones in preparation for future use
// Save a copy of the DisplayMagician Icon
if (!File.Exists(AppDisplayMagicianIconFilename))
{
Icon heliosIcon = (Icon)Properties.Resources.DisplayMagician;
@ -635,19 +689,7 @@ namespace DisplayMagician {
// Check for updates
CheckForUpdates();
// Check if it's an upgrade from DisplayMagician v1 to v2
// and if it is then explain what the user needs to do.
// e.g. DisplayProfiles_1.0.json exists, but DisplayProfiles_2.0.json doesn't
if (File.Exists(Path.Combine(AppProfilePath, "DisplayProfiles_1.0.json")) && !File.Exists(Path.Combine(AppProfilePath, "DisplayProfiles_2.0.json")))
{
StartMessageForm myMessageWindow = new StartMessageForm();
myMessageWindow.URL = "https://displaymagician.littlebitbig.com/messages/DisplayMagician1to2.rtf";
myMessageWindow.HeadingText = "DisplayMagician v2.0.0 Upgrade Warning";
myMessageWindow.ButtonText = "&Close";
myMessageWindow.Show();
}
// Show any messages we need to show
// Show any messages we need to show
ShowMessages();
// Run the program with normal startup

View File

@ -15,7 +15,7 @@ namespace DisplayMagician
// Common items to the class
private static bool _programSettingsLoaded = false;
// Other constants that are useful
private static string _programSettingsStorageJsonFileName = Path.Combine(Program.AppDataPath, $"Settings_{FileVersion.ToString(2)}.json");
public static string programSettingsStorageJsonFileName = Path.Combine(Program.AppDataPath, $"Settings_2.0.json");
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
#endregion
@ -215,12 +215,6 @@ namespace DisplayMagician
}
}
public static Version FileVersion
{
get => new Version(1, 0, 0);
}
#endregion
#region Class Methods
@ -232,15 +226,15 @@ namespace DisplayMagician
// This means we have to only use console.write in this function....
ProgramSettings programSettings = null;
if (File.Exists(_programSettingsStorageJsonFileName))
if (File.Exists(programSettingsStorageJsonFileName))
{
string json = "";
try {
json = File.ReadAllText(_programSettingsStorageJsonFileName, Encoding.Unicode);
json = File.ReadAllText(programSettingsStorageJsonFileName, Encoding.Unicode);
}
catch (Exception ex)
{
Console.WriteLine($"ProgramSettings/LoadSettings: Tried to read the JSON file {_programSettingsStorageJsonFileName} to memory from disk but File.ReadAllText threw an exception. {ex}");
Console.WriteLine($"ProgramSettings/LoadSettings: Tried to read the JSON file {programSettingsStorageJsonFileName} to memory from disk but File.ReadAllText threw an exception. {ex}");
}
if (!string.IsNullOrWhiteSpace(json))
@ -257,13 +251,13 @@ namespace DisplayMagician
}
catch (Exception ex)
{
Console.WriteLine($"ProgramSettings/LoadSettings: Tried to parse the JSON file {_programSettingsStorageJsonFileName} but the JsonConvert threw an exception. {ex}");
Console.WriteLine($"ProgramSettings/LoadSettings: Tried to parse the JSON file {programSettingsStorageJsonFileName} but the JsonConvert threw an exception. {ex}");
}
}
}
else
{
Console.WriteLine($"ProgramSettings/LoadSettings: No ProgramSettings file found. Creating new one at {_programSettingsStorageJsonFileName}");
Console.WriteLine($"ProgramSettings/LoadSettings: No ProgramSettings file found. Creating new one at {programSettingsStorageJsonFileName}");
programSettings = new ProgramSettings();
programSettings.SaveSettings();
}
@ -279,7 +273,7 @@ namespace DisplayMagician
public bool SaveSettings()
{
logger.Debug($"ProgramSettings/SaveSettings: Attempting to save the program settings to the {_programSettingsStorageJsonFileName}.");
logger.Debug($"ProgramSettings/SaveSettings: Attempting to save the program settings to the {programSettingsStorageJsonFileName}.");
try
{
@ -294,13 +288,13 @@ namespace DisplayMagician
if (!string.IsNullOrWhiteSpace(json))
{
File.WriteAllText(_programSettingsStorageJsonFileName, json, Encoding.Unicode);
File.WriteAllText(programSettingsStorageJsonFileName, json, Encoding.Unicode);
return true;
}
}
catch (Exception ex)
{
logger.Error(ex, $"ProgramSettings/SaveSettings: Exception attempting to save the program settings to {_programSettingsStorageJsonFileName}.");
logger.Error(ex, $"ProgramSettings/SaveSettings: Exception attempting to save the program settings to {programSettingsStorageJsonFileName}.");
}
return false;

View File

@ -26,8 +26,8 @@ using System.Resources;
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
// Version information
[assembly: AssemblyVersion("2.0.1.23")]
[assembly: AssemblyFileVersion("2.0.1.23")]
[assembly: AssemblyVersion("2.0.0.45")]
[assembly: AssemblyFileVersion("2.0.0.45")]
[assembly: NeutralResourcesLanguageAttribute( "en" )]
[assembly: CLSCompliant(true)]

View File

@ -34,7 +34,7 @@ namespace DisplayMagician
private static bool _cancelWait = false;
// Other constants that are useful
private static string AppShortcutStoragePath = Path.Combine(Program.AppDataPath, $"Shortcuts");
private static string _shortcutStorageJsonFileName = Path.Combine(AppShortcutStoragePath, $"Shortcuts_{Version.ToString(2)}.json");
private static string _shortcutStorageJsonFileName = Path.Combine(AppShortcutStoragePath, $"Shortcuts_2.0.json");
private static string uuidV4Regex = @"(?im)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$";
private static CoreAudioController _audioController = null;
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
@ -93,9 +93,9 @@ namespace DisplayMagician
}
}
public static Version Version
public static string ShortcutStorageFileName
{
get => new Version(1, 0, 0);
get => _shortcutStorageJsonFileName;
}
public static bool CancelWait {

View File

@ -397,36 +397,39 @@ namespace DisplayMagician.UIForms
else if (_selectedShortcut.Category.Equals(ShortcutCategory.Game))
message = $"Running the {_selectedShortcut.GameName} game and waiting until you close it.";
// Create a Mask Control that will cover the ShortcutLibrary Window to lock
lbl_mask.Text = message;
lbl_mask.Location = new Point(0, 0);
lbl_mask.Size = this.Size;
lbl_mask.BackColor = Color.FromArgb(100, Color.Black);
lbl_mask.BringToFront();
lbl_mask.Visible = true;
ilv_saved_shortcuts.SuspendLayout();
ilv_saved_shortcuts.Refresh();
if (!Program.AppProgramSettings.MinimiseOnStart)
{
// Create a Mask Control that will cover the ShortcutLibrary Window to lock
lbl_mask.Text = message;
lbl_mask.Location = new Point(0, 0);
lbl_mask.Size = this.Size;
lbl_mask.BackColor = Color.FromArgb(100, Color.Black);
lbl_mask.BringToFront();
lbl_mask.Visible = true;
ilv_saved_shortcuts.SuspendLayout();
ilv_saved_shortcuts.Refresh();
// Get the MainForm so we can access the NotifyIcon on it.
MainForm mainForm = (MainForm)this.Owner;
// Run the shortcut
ShortcutRepository.RunShortcut(_selectedShortcut, mainForm.notifyIcon);
ilv_saved_shortcuts.ResumeLayout();
// REmove the Masked Control to allow the user to start using DisplayMagician again.
lbl_mask.Visible = false;
lbl_mask.SendToBack();
}
else
{
// Run the shortcut
ShortcutRepository.RunShortcut(_selectedShortcut, Program.AppMainForm.notifyIcon);
}
ilv_saved_shortcuts.ResumeLayout();
// REmove the Masked Control to allow the user to start using DisplayMagician again.
lbl_mask.Visible = false;
lbl_mask.SendToBack();
}
private void ilv_saved_shortcuts_ItemHover(object sender, ItemHoverEventArgs e)

View File

@ -69,6 +69,7 @@ namespace DisplayMagician.UIForms
catch (Exception ex)
{
logger.Error(ex, $"StartMessageForm/StartMessageForm_Load: Filename supplied (\"{Filename}\") is not within the Application startup path (\"{Application.StartupPath}\")");
this.Close();
return;
}
@ -90,16 +91,21 @@ namespace DisplayMagician.UIForms
else
{
logger.Error($"StartMessageForm/StartMessageForm_Load: Message from file {Filename} is in an unsupported MessageMode: {MessageMode}");
this.Close();
return;
}
}
else
{
logger.Error($"StartMessageForm/StartMessageForm_Load: Couldn't find the Filename supplied (\"{Filename}\") and load it into the RichTextBox message object");
this.Close();
return;
}
}
catch (Exception ex)
{
logger.Error(ex, $"StartMessageForm/StartMessageForm_Load: Exception while trying to load the Filename supplied (\"{Filename}\") into the RichTextBox message object");
this.Close();
return;
}
}
@ -151,6 +157,8 @@ namespace DisplayMagician.UIForms
else
{
logger.Error($"StartMessageForm/StartMessageForm_Load: Message from URL {URL} is in an unsupported MessageMode: {MessageMode}");
this.Close();
return;
}
}
}

View File

@ -133,7 +133,7 @@
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />-->
<!-- Preapre custom actions to register and unregisterthe ShellExtension DLL -->
<CustomAction Id="InstallShell" FileKey="ServerRegistrationManager.exe" ExeCommand='install "[APPLICATIONROOTDIRECTORY]\DisplayMagicianShellExtension.dll" -codebase' Execute="deferred" Return="check" Impersonate="no" />
<CustomAction Id="InstallShell" FileKey="ServerRegistrationManager.exe" ExeCommand='install "[APPLICATIONROOTDIRECTORY]\DisplayMagicianShellExtension.dll -os64" -codebase' Execute="deferred" Return="check" Impersonate="no" />
<CustomAction Id="UninstallShell" FileKey="ServerRegistrationManager.exe" ExeCommand='uninstall "[APPLICATIONROOTDIRECTORY]\DisplayMagicianShellExtension.dll"' Execute="deferred" Return="check" Impersonate="no" />
<!-- Plumb the registering and unregistering of the ShellExtension DLL into the instllation sequence -->

View File

@ -47,7 +47,6 @@ namespace DisplayMagicianShared
private static List<ProfileItem> _allProfiles = new List<ProfileItem>();
public static Dictionary<string, bool> _profileWarningLookup = new Dictionary<string, bool>();
private static bool _profilesLoaded = false;
public static Version _version = new Version(2, 0, 0);
private static ProfileItem _currentProfile;
private static List<string> _connectedDisplayIdentifiers = new List<string>();
private static bool notifiedEDIDErrorToUser = false;
@ -63,7 +62,7 @@ namespace DisplayMagicianShared
public static string AppIconPath = System.IO.Path.Combine(AppDataPath, $"Icons");
public static string AppDisplayMagicianIconFilename = System.IO.Path.Combine(AppIconPath, @"DisplayMagician.ico");
private static readonly string AppProfileStoragePath = System.IO.Path.Combine(AppDataPath, $"Profiles");
private static readonly string _profileStorageJsonFileName = System.IO.Path.Combine(AppProfileStoragePath, $"DisplayProfiles_{_version.ToString(2)}.json");
private static readonly string _profileStorageJsonFileName = System.IO.Path.Combine(AppProfileStoragePath, $"DisplayProfiles_2.0.json");
@ -162,6 +161,11 @@ namespace DisplayMagicianShared
}
}
public static string ProfileStorageFileName
{
get => _profileStorageJsonFileName;
}
public static VIDEO_MODE CurrentVideoMode
{
get