Set all the JSON.net default values

We now properly set the default JSON values for everything except Display Profiles, which should avoid crashes to desktop if we miss setting a value from it's default in the future. This should help with application robustness.
This commit is contained in:
Terry MacDonald 2022-07-08 09:59:29 +12:00
parent d719cecad2
commit cb51ea9245
7 changed files with 86 additions and 15 deletions

View File

@ -468,7 +468,7 @@ namespace DisplayMagician {
if (File.Exists(oldv22ShortcutsFile)) if (File.Exists(oldv22ShortcutsFile))
{ {
logger.Info($"Program/Main: Upgrading v2.2 shortcut file {oldv2ShortcutsFile} to latest shortcut file {targetShortcutsFile}."); logger.Info($"Program/Main: Upgrading v2.2 shortcut file {oldv2ShortcutsFile} to latest shortcut file {targetShortcutsFile}.");
File.Copy(oldv2ShortcutsFile, targetShortcutsFile); File.Copy(oldv22ShortcutsFile, targetShortcutsFile);
} }
else if (File.Exists(oldv2ShortcutsFile)) else if (File.Exists(oldv2ShortcutsFile))
{ {
@ -481,6 +481,11 @@ namespace DisplayMagician {
File.Copy(oldv1ShortcutsFile, targetShortcutsFile); File.Copy(oldv1ShortcutsFile, targetShortcutsFile);
} }
// Load the Shortcuts so that they get populated with default values as part of the upgrade
ShortcutRepository.LoadShortcuts();
// Now save the shortcuts so the new default values get written to disk
ShortcutRepository.SaveShortcuts();
} }
else else
{ {

View File

@ -2,6 +2,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
@ -41,6 +42,7 @@ namespace DisplayMagician
#endregion #endregion
#region Class Properties #region Class Properties
[DefaultValue(0)]
public string DisplayMagicianVersion public string DisplayMagicianVersion
{ {
get get
@ -56,6 +58,8 @@ namespace DisplayMagician
_displayMagicianVersion = value; _displayMagicianVersion = value;
} }
} }
[DefaultValue(false)]
public bool StartOnBootUp public bool StartOnBootUp
{ {
get get
@ -68,6 +72,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(true)]
public bool ShowSplashScreen public bool ShowSplashScreen
{ {
get get
@ -80,6 +85,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(true)]
public bool ShowMinimiseMessageInActionCenter public bool ShowMinimiseMessageInActionCenter
{ {
get get
@ -92,6 +98,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(true)]
public bool ShowStatusMessageInActionCenter public bool ShowStatusMessageInActionCenter
{ {
get get
@ -104,6 +111,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(false)]
public bool UpgradeToPreReleases public bool UpgradeToPreReleases
{ {
get get
@ -116,6 +124,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(true)]
public bool UpgradeEnabled public bool UpgradeEnabled
{ {
get get
@ -128,6 +137,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(false)]
public bool MinimiseOnStart { public bool MinimiseOnStart {
get get
{ {
@ -139,6 +149,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(true)]
public bool InstalledDesktopContextMenu public bool InstalledDesktopContextMenu
{ {
get get
@ -151,6 +162,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(0)]
public int LastMessageIdRead public int LastMessageIdRead
{ {
get get
@ -163,6 +175,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(default(List<int>))]
public List<int> MessagesToMonitor public List<int> MessagesToMonitor
{ {
get get
@ -175,6 +188,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("Trace")]
public string LogLevel public string LogLevel
{ {
get get
@ -212,6 +226,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(Keys.None)]
public Keys HotkeyMainWindow public Keys HotkeyMainWindow
{ {
get get
@ -224,6 +239,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(Keys.None)]
public Keys HotkeyDisplayProfileWindow public Keys HotkeyDisplayProfileWindow
{ {
get get
@ -236,6 +252,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(Keys.None)]
public Keys HotkeyShortcutLibraryWindow public Keys HotkeyShortcutLibraryWindow
{ {
get get

View File

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

View File

@ -16,6 +16,7 @@ using IWshRuntimeLibrary;
using AudioSwitcher.AudioApi.CoreAudio; using AudioSwitcher.AudioApi.CoreAudio;
using AudioSwitcher.AudioApi; using AudioSwitcher.AudioApi;
using TsudaKageyu; using TsudaKageyu;
using System.ComponentModel;
namespace DisplayMagician namespace DisplayMagician
{ {
@ -195,10 +196,7 @@ namespace DisplayMagician
// If Autoname is on, and then lets autoname it! // If Autoname is on, and then lets autoname it!
// That populates all the right things // That populates all the right things
AutoSuggestShortcutName(); AutoSuggestShortcutName();
} }
//RefreshValidity();
} }
public static Version Version public static Version Version
@ -206,7 +204,7 @@ namespace DisplayMagician
get => new Version(1, 0); get => new Version(1, 0);
} }
[DefaultValue("")]
public string UUID public string UUID
{ {
get get
@ -222,6 +220,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string Name public string Name
{ {
get get
@ -234,6 +233,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(true)]
public bool AutoName public bool AutoName
{ {
get get
@ -269,6 +269,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string ProfileUUID { public string ProfileUUID {
get get
{ {
@ -287,6 +288,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(ShortcutPermanence.Temporary)]
public ShortcutPermanence DisplayPermanence public ShortcutPermanence DisplayPermanence
{ {
get get
@ -300,6 +302,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(ShortcutPermanence.Temporary)]
public ShortcutPermanence AudioPermanence public ShortcutPermanence AudioPermanence
{ {
get get
@ -313,6 +316,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(ShortcutPermanence.Temporary)]
public ShortcutPermanence CapturePermanence public ShortcutPermanence CapturePermanence
{ {
get get
@ -326,6 +330,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(ShortcutCategory.Game)]
public ShortcutCategory Category public ShortcutCategory Category
{ {
get get
@ -339,6 +344,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(ProcessPriority.Normal)]
public ProcessPriority ProcessPriority public ProcessPriority ProcessPriority
{ {
get get
@ -352,6 +358,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string DifferentExecutableToMonitor public string DifferentExecutableToMonitor
{ {
get get
@ -365,6 +372,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string ExecutableNameAndPath public string ExecutableNameAndPath
{ {
get get
@ -384,6 +392,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string ExecutableArguments public string ExecutableArguments
{ {
get get
@ -397,6 +406,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(false)]
public bool ExecutableArgumentsRequired public bool ExecutableArgumentsRequired
{ {
get get
@ -410,6 +420,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(false)]
public bool RunExeAsAdministrator public bool RunExeAsAdministrator
{ {
get get
@ -423,6 +434,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(true)]
public bool ProcessNameToMonitorUsesExecutable public bool ProcessNameToMonitorUsesExecutable
{ {
get get
@ -436,6 +448,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string GameAppId public string GameAppId
{ {
get get
@ -449,6 +462,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string GameName public string GameName
{ {
get get
@ -462,6 +476,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(SupportedGameLibraryType.Unknown)]
public SupportedGameLibraryType GameLibrary public SupportedGameLibraryType GameLibrary
{ {
get get
@ -476,6 +491,7 @@ namespace DisplayMagician
} }
#pragma warning disable CS3003 // Type is not CLS-compliant #pragma warning disable CS3003 // Type is not CLS-compliant
[DefaultValue(Keys.None)]
public Keys Hotkey public Keys Hotkey
#pragma warning restore CS3003 // Type is not CLS-compliant #pragma warning restore CS3003 // Type is not CLS-compliant
{ {
@ -489,6 +505,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(20)]
public int StartTimeout public int StartTimeout
{ {
get get
@ -502,6 +519,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string GameArguments public string GameArguments
{ {
get get
@ -528,6 +546,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string DifferentGameExeToMonitor public string DifferentGameExeToMonitor
{ {
get get
@ -554,7 +573,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string AudioDevice public string AudioDevice
{ {
get get
@ -568,6 +587,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(false)]
public bool ChangeAudioDevice public bool ChangeAudioDevice
{ {
get get
@ -581,7 +601,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(true)]
public bool UseAsCommsAudioDevice public bool UseAsCommsAudioDevice
{ {
get get
@ -593,8 +613,9 @@ namespace DisplayMagician
{ {
_useAsCommsAudioDevice = value; _useAsCommsAudioDevice = value;
} }
} }
[DefaultValue(50)]
public decimal AudioVolume public decimal AudioVolume
{ {
get get
@ -608,6 +629,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(false)]
public bool SetAudioVolume public bool SetAudioVolume
{ {
get get
@ -621,6 +643,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string CaptureDevice public string CaptureDevice
{ {
get get
@ -634,6 +657,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(false)]
public bool ChangeCaptureDevice public bool ChangeCaptureDevice
{ {
get get
@ -647,6 +671,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(true)]
public bool UseAsCommsCaptureDevice public bool UseAsCommsCaptureDevice
{ {
get get
@ -660,6 +685,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(50)]
public decimal CaptureVolume public decimal CaptureVolume
{ {
get get
@ -673,6 +699,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(false)]
public bool SetCaptureVolume public bool SetCaptureVolume
{ {
get get
@ -686,6 +713,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(default(List<StartProgram>))]
public List<StartProgram> StartPrograms public List<StartProgram> StartPrograms
{ {
get get
@ -699,6 +727,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(default(List<StopProgram>))]
public List<StopProgram> StopPrograms public List<StopProgram> StopPrograms
{ {
get get
@ -712,7 +741,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string OriginalIconPath { public string OriginalIconPath {
get get
{ {
@ -728,6 +757,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(default(Bitmap))]
[JsonConverter(typeof(CustomBitmapConverter))] [JsonConverter(typeof(CustomBitmapConverter))]
public Bitmap OriginalLargeBitmap public Bitmap OriginalLargeBitmap
{ {
@ -747,6 +777,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(default(Bitmap))]
[JsonConverter(typeof(CustomBitmapConverter))] [JsonConverter(typeof(CustomBitmapConverter))]
public Bitmap ShortcutBitmap public Bitmap ShortcutBitmap
{ {
@ -761,6 +792,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public string SavedShortcutIconCacheFilename public string SavedShortcutIconCacheFilename
{ {
get get
@ -800,6 +832,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue("")]
public ShortcutBitmap SelectedImage public ShortcutBitmap SelectedImage
{ {
get get
@ -814,6 +847,7 @@ namespace DisplayMagician
} }
} }
[DefaultValue(default(List<ShortcutBitmap>))]
public List<ShortcutBitmap> AvailableImages public List<ShortcutBitmap> AvailableImages
{ {
get get

View File

@ -406,7 +406,7 @@ namespace DisplayMagician
} }
} }
private static bool LoadShortcuts() public static bool LoadShortcuts()
{ {
logger.Debug($"ShortcutRepository/LoadShortcuts: Loading shortcuts from {_shortcutStorageJsonFileName} into the Shortcut Repository"); logger.Debug($"ShortcutRepository/LoadShortcuts: Loading shortcuts from {_shortcutStorageJsonFileName} into the Shortcut Repository");

View File

@ -14,6 +14,7 @@ using DisplayMagicianShared.AMD;
using DisplayMagicianShared.NVIDIA; using DisplayMagicianShared.NVIDIA;
using DisplayMagicianShared.Windows; using DisplayMagicianShared.Windows;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.ComponentModel;
namespace DisplayMagicianShared namespace DisplayMagicianShared
{ {
@ -155,6 +156,8 @@ namespace DisplayMagicianShared
#region Instance Properties #region Instance Properties
[DefaultValue("")]
public string UUID public string UUID
{ {
get get
@ -199,8 +202,11 @@ namespace DisplayMagicianShared
} }
} }
[DefaultValue(VIDEO_MODE.WINDOWS)]
public virtual VIDEO_MODE VideoMode { get; set; } = VIDEO_MODE.WINDOWS; public virtual VIDEO_MODE VideoMode { get; set; } = VIDEO_MODE.WINDOWS;
[DefaultValue(Keys.None)]
public Keys Hotkey { public Keys Hotkey {
get get
{ {
@ -212,9 +218,11 @@ namespace DisplayMagicianShared
} }
} }
[DefaultValue("")]
public virtual string Name { get; set; } public virtual string Name { get; set; }
[JsonRequired] [JsonRequired]
public NVIDIA_DISPLAY_CONFIG NVIDIADisplayConfig public NVIDIA_DISPLAY_CONFIG NVIDIADisplayConfig
{ {
get get
@ -291,13 +299,16 @@ namespace DisplayMagicianShared
} }
} }
[DefaultValue("")]
public string SavedProfileIconCacheFilename { get; set; } public string SavedProfileIconCacheFilename { get; set; }
[DefaultValue(Wallpaper.Mode.DoNothing)]
public Wallpaper.Mode WallpaperMode { get; set; } public Wallpaper.Mode WallpaperMode { get; set; }
[DefaultValue(Wallpaper.Style.Fill)]
public Wallpaper.Style WallpaperStyle { get; set; } public Wallpaper.Style WallpaperStyle { get; set; }
[DefaultValue("")]
public string WallpaperBitmapFilename{ public string WallpaperBitmapFilename{
get get
{ {
@ -309,6 +320,7 @@ namespace DisplayMagicianShared
} }
} }
[DefaultValue(default(List<string>))]
public virtual List<string> ProfileDisplayIdentifiers public virtual List<string> ProfileDisplayIdentifiers
{ {
get get
@ -326,6 +338,7 @@ namespace DisplayMagicianShared
} }
} }
[DefaultValue(default(Bitmap))]
[JsonConverter(typeof(CustomBitmapConverter))] [JsonConverter(typeof(CustomBitmapConverter))]
public virtual Bitmap ProfileBitmap public virtual Bitmap ProfileBitmap
{ {
@ -346,6 +359,7 @@ namespace DisplayMagicianShared
} }
[DefaultValue(default(Bitmap))]
[JsonConverter(typeof(CustomBitmapConverter))] [JsonConverter(typeof(CustomBitmapConverter))]
public virtual Bitmap ProfileTightestBitmap public virtual Bitmap ProfileTightestBitmap
{ {

View File

@ -15,6 +15,7 @@ using Newtonsoft.Json.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.ComponentModel;
namespace DisplayMagicianShared namespace DisplayMagicianShared
{ {