Fixed CompareTo and some Profile Repository loading order

This commit is contained in:
Terry MacDonald 2021-09-04 20:58:08 +12:00
parent a112326e50
commit 708acd3c12
6 changed files with 107 additions and 40 deletions

View File

@ -261,31 +261,31 @@ namespace DisplayMagician {
{
if (forcedVideoLibrary.Value().Equals("NVIDIA"))
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.NVIDIA;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.NVIDIA);
Console.WriteLine($"Forcing NVIDIA Video Library as '--force-video-library NVIDIA' was provided on the commandline.");
logger.Info($"Forcing NVIDIA Video Library as '--force-video-library NVIDIA' was provided on the commandline.");
}
else if (forcedVideoLibrary.Value().Equals("AMD"))
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.AMD;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.AMD);
Console.WriteLine($"Forcing AMD Video Library as '--force-video-library AMD' was provided on the commandline.");
logger.Info($"Forcing AMD Video Library as '--force-video-library AMD' was provided on the commandline.");
}
else if (forcedVideoLibrary.Value().Equals("Windows"))
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.WINDOWS;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.WINDOWS);
Console.WriteLine($"Forcing Windows CCD Video Library as '--force-video-library Windows' was provided on the commandline.");
logger.Info($"Forcing Windows CCD Video Library as '--force-video-library Windows' was provided on the commandline.");
}
else
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.DETECT;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.DETECT);
logger.Info($"Leaving DisplayMagician to detect the best Video Library to use.");
}
}
else
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.DETECT;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.DETECT);
logger.Info($"Leaving DisplayMagician to detect the best Video Library to use.");
}
var argumentShortcut = runShortcutCmd.Argument("\"SHORTCUT_UUID\"", "(required) The UUID of the shortcut to run from those stored in the shortcut library.").IsRequired();
@ -328,31 +328,31 @@ namespace DisplayMagician {
{
if (forcedVideoLibrary.Value().Equals("NVIDIA"))
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.NVIDIA;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.NVIDIA);
Console.WriteLine($"Forcing NVIDIA Video Library as '--force-video-library NVIDIA' was provided on the commandline.");
logger.Info($"Forcing NVIDIA Video Library as '--force-video-library NVIDIA' was provided on the commandline.");
}
else if (forcedVideoLibrary.Value().Equals("AMD"))
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.AMD;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.AMD);
Console.WriteLine($"Forcing AMD Video Library as '--force-video-library AMD' was provided on the commandline.");
logger.Info($"Forcing AMD Video Library as '--force-video-library AMD' was provided on the commandline.");
}
else if (forcedVideoLibrary.Value().Equals("Windows"))
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.WINDOWS;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.WINDOWS);
Console.WriteLine($"Forcing Windows CCD Video Library as '--force-video-library Windows' was provided on the commandline.");
logger.Info($"Forcing Windows CCD Video Library as '--force-video-library Windows' was provided on the commandline.");
}
else
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.DETECT;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.DETECT);
logger.Info($"Leaving DisplayMagician to detect the best Video Library to use.");
}
}
else
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.DETECT;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.DETECT);
logger.Info($"Leaving DisplayMagician to detect the best Video Library to use.");
}
@ -403,31 +403,31 @@ namespace DisplayMagician {
{
if (forcedVideoLibrary.Value().Equals("NVIDIA"))
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.NVIDIA;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.NVIDIA);
Console.WriteLine($"Forcing NVIDIA Video Library as '--force-video-library NVIDIA' was provided on the commandline.");
logger.Info($"Forcing NVIDIA Video Library as '--force-video-library NVIDIA' was provided on the commandline.");
}
else if (forcedVideoLibrary.Value().Equals("AMD"))
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.AMD;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.AMD);
Console.WriteLine($"Forcing AMD Video Library as '--force-video-library AMD' was provided on the commandline.");
logger.Info($"Forcing AMD Video Library as '--force-video-library AMD' was provided on the commandline.");
}
else if (forcedVideoLibrary.Value().Equals("Windows"))
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.WINDOWS;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.WINDOWS);
Console.WriteLine($"Forcing Windows CCD Video Library as '--force-video-library Windows' was provided on the commandline.");
logger.Info($"Forcing Windows CCD Video Library as '--force-video-library Windows' was provided on the commandline.");
}
else
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.DETECT;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.DETECT);
logger.Info($"Leaving DisplayMagician to detect the best Video Library to use.");
}
}
else
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.DETECT;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.DETECT);
logger.Info($"Leaving DisplayMagician to detect the best Video Library to use.");
}
//description and help text of the command.
@ -465,25 +465,25 @@ namespace DisplayMagician {
{
if (forcedVideoLibrary.Value().Equals("NVIDIA"))
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.NVIDIA;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.NVIDIA);
Console.WriteLine($"Forcing NVIDIA Video Library as '--force-video-library NVIDIA' was provided on the commandline.");
logger.Info($"Forcing NVIDIA Video Library as '--force-video-library NVIDIA' was provided on the commandline.");
}
else if (forcedVideoLibrary.Value().Equals("AMD"))
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.AMD;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.AMD);
Console.WriteLine($"Forcing AMD Video Library as '--force-video-library AMD' was provided on the commandline.");
logger.Info($"Forcing AMD Video Library as '--force-video-library AMD' was provided on the commandline.");
}
else if (forcedVideoLibrary.Value().Equals("Windows"))
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.WINDOWS;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.WINDOWS);
Console.WriteLine($"Forcing Windows CCD Video Library as '--force-video-library Windows' was provided on the commandline.");
logger.Info($"Forcing Windows CCD Video Library as '--force-video-library Windows' was provided on the commandline.");
}
else
{
ProfileRepository.ForcedVideoMode = FORCED_VIDEO_MODE.DETECT;
ProfileRepository.InitialiseRepository(FORCED_VIDEO_MODE.DETECT);
logger.Info($"Leaving DisplayMagician to detect the best Video Library to use.");
}
}

View File

@ -12,7 +12,7 @@ using System.Drawing.Imaging;
namespace DisplayMagicianShared.AMD
{
public class AMDProfileItem : ProfileItem, IComparable
public class AMDProfileItem : ProfileItem
{
private static List<AMDProfileItem> _allSavedProfiles = new List<AMDProfileItem>();
private ProfileIcon _profileIcon;
@ -363,13 +363,13 @@ namespace DisplayMagicianShared.AMD
return _screens;
}
public override int CompareTo(object obj)
/*public override int CompareTo(object obj)
{
if (!(obj is AMDProfileItem)) throw new ArgumentException("Object to CompareTo is not a AMDProfileItem"); ;
AMDProfileItem otherProfile = (AMDProfileItem)obj;
return this.Name.CompareTo(otherProfile.Name);
}
}*/
// The public override for the Object.Equals
public override bool Equals(object obj)

View File

@ -14,7 +14,7 @@ using DisplayMagicianShared.Windows;
namespace DisplayMagicianShared.NVIDIA
{
public class NVIDIAProfileItem : ProfileItem, IComparable
public class NVIDIAProfileItem : ProfileItem
{
private static List<NVIDIAProfileItem> _allSavedProfiles = new List<NVIDIAProfileItem>();
private ProfileIcon _profileIcon;
@ -393,7 +393,7 @@ namespace DisplayMagicianShared.NVIDIA
}
else if (_nvidiaDisplayConfig.MosaicConfig.MosaicGridTopos[i].DisplayCount == 1)
{
// This is a single screen
// This is a single screen with an adjoining mosaic screen
// Set some basics about the screen
uint displayId = _nvidiaDisplayConfig.MosaicConfig.MosaicGridTopos[i].Displays[0].DisplayId;
string windowsDisplayName = _nvidiaDisplayConfig.DisplayNames[displayId];
@ -547,14 +547,7 @@ namespace DisplayMagicianShared.NVIDIA
return _screens;
}
public override int CompareTo(object obj)
{
if (!(obj is NVIDIAProfileItem)) throw new ArgumentException("Object to CompareTo is not a NVIDIAProfileItem"); ;
NVIDIAProfileItem otherProfile = (NVIDIAProfileItem)obj;
return this.Name.CompareTo(otherProfile.Name);
}
// The public override for the Object.Equals
public override bool Equals(object obj)

View File

@ -52,7 +52,7 @@ namespace DisplayMagicianShared
public int Row;
}
public class ProfileItem : IComparable
public class ProfileItem : IComparable<ProfileItem>
{
private static List<ProfileItem> _allSavedProfiles = new List<ProfileItem>();
private ProfileIcon _profileIcon;
@ -504,14 +504,74 @@ namespace DisplayMagicianShared
return new List<ScreenPosition>();
}
public virtual int CompareTo(object obj)
/*public virtual int CompareTo(object obj)
{
if (!(obj is ProfileItem)) throw new ArgumentException("Object to CompareTo is not a Shortcut"); ;
ProfileItem otherProfile = (ProfileItem)obj;
return this.Name.CompareTo(otherProfile.Name);
}*/
public int CompareTo(ProfileItem other)
{
int result = CompareToValues(other);
// If comparison based solely on values
// returns zero, indicating that two instances
// are equal in those fields they have in common,
// only then we break the tie by comparing
// data types of the two instances.
if (result == 0)
result = CompareTypes(other);
return result;
}
protected virtual int CompareToValues(ProfileItem other)
{
if (object.ReferenceEquals(other, null))
return 1; // All instances are greater than null
// Base class simply compares Mark properties
return Name.CompareTo(other.Name);
}
protected int CompareTypes(ProfileItem other)
{
// Base type is considered less than derived type
// when two instances have the same values of
// base fields.
// Instances of two distinct derived types are
// ordered by comparing full names of their
// types when base fields are equal.
// This is consistent comparison rule for all
// instances of the two derived types.
int result = 0;
Type thisType = this.GetType();
Type otherType = other.GetType();
if (otherType.IsSubclassOf(thisType))
result = -1; // other is subclass of this class
else if (thisType.IsSubclassOf(otherType))
result = 1; // this is subclass of other class
else if (thisType != otherType)
result = thisType.FullName.CompareTo(otherType.FullName);
// cut the tie with a test that returns
// the same value for all objects
return result;
}
// The public override for the Object.Equals
public override bool Equals(object obj)
{
@ -524,7 +584,7 @@ namespace DisplayMagicianShared
{
return !object.ReferenceEquals(obj, null) &&
obj is ProfileItem &&
((ProfileItem)obj).ProfileDisplayIdentifiers == this.ProfileDisplayIdentifiers;
((ProfileItem)obj).ProfileDisplayIdentifiers.SequenceEqual(this.ProfileDisplayIdentifiers);
}
// If Equals() returns true for this object compared to another

View File

@ -102,8 +102,6 @@ namespace DisplayMagicianShared
{
SharedLogger.logger.Warn(ex, $"ProfileRepository/ProfileRepository: Exception creating the Profiles storage folder.");
}
// Load the Profiles from storage
LoadProfiles();
}
#endregion
@ -221,6 +219,22 @@ namespace DisplayMagicianShared
#endregion
#region Class Methods
public static bool InitialiseRepository(FORCED_VIDEO_MODE forcedVideoMode = FORCED_VIDEO_MODE.DETECT)
{
if (!SetVideoCardMode(forcedVideoMode))
{
return false;
}
if (!LoadProfiles())
{
return false;
}
return true;
}
public static bool AddProfile(ProfileItem profile)
{
if (!(profile is ProfileItem))

View File

@ -11,7 +11,7 @@ using System.Drawing.Imaging;
namespace DisplayMagicianShared.Windows
{
public class WinProfileItem : ProfileItem, IComparable
public class WinProfileItem : ProfileItem
{
private static List<WinProfileItem> _allSavedProfiles = new List<WinProfileItem>();
private ProfileIcon _profileIcon;
@ -318,13 +318,13 @@ namespace DisplayMagicianShared.Windows
return _screens;
}
public override int CompareTo(object obj)
/*public override int CompareTo(object obj)
{
if (!(obj is WinProfileItem)) throw new ArgumentException("Object to CompareTo is not a WinProfileItem"); ;
WinProfileItem otherProfile = (WinProfileItem)obj;
return this.Name.CompareTo(otherProfile.Name);
}
}*/
// The public override for the Object.Equals
public override bool Equals(object obj)