mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Separated profile equals from possible
This change was to separate 'Equals' (which checks for exactly the same) with 'Possible' (which checks that the connected displays are available to use. Should make the profile comparison a lot more accurate.
This commit is contained in:
parent
846001548e
commit
e913640751
@ -123,7 +123,6 @@
|
||||
this.ShowInTaskbar = false;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "DisplayMagician - Please Wait";
|
||||
this.TopMost = true;
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ApplyingProfileForm_FormClosing);
|
||||
this.Load += new System.EventHandler(this.ApplyingProfileForm_Reposition);
|
||||
this.Shown += new System.EventHandler(this.ApplyingProfileForm_Shown);
|
||||
|
@ -327,15 +327,35 @@ namespace DisplayMagicianShared
|
||||
if (this.GetType() != other.GetType())
|
||||
return false;
|
||||
|
||||
if (Paths.Length != other.Paths.Length)
|
||||
return false;
|
||||
|
||||
// Check if the profile identifiers are not the same, then return false
|
||||
int foundDICount = 0;
|
||||
foreach (string profileDI in ProfileDisplayIdentifiers)
|
||||
{
|
||||
foreach (string otherDI in other.ProfileDisplayIdentifiers)
|
||||
|
||||
if (other.ProfileDisplayIdentifiers.Contains(profileDI))
|
||||
{
|
||||
if (profileDI.Equals(otherDI))
|
||||
foundDICount++;
|
||||
foundDICount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (foundDICount != other.ProfileDisplayIdentifiers.Count)
|
||||
return false;
|
||||
|
||||
foundDICount = 0;
|
||||
foreach (string profileDI in other.ProfileDisplayIdentifiers)
|
||||
{
|
||||
|
||||
if (ProfileDisplayIdentifiers.Contains(profileDI))
|
||||
{
|
||||
foundDICount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (foundDICount != ProfileDisplayIdentifiers.Count)
|
||||
@ -346,17 +366,29 @@ namespace DisplayMagicianShared
|
||||
// and displaying to the user.
|
||||
// Two profiles are equal only when they have the same viewport data
|
||||
// The data may be in different orders each run, so we need to compare them one by one
|
||||
int foundPathsCount = 0;
|
||||
|
||||
int foundPathsCount = 0;
|
||||
int foundOtherPathsCount = 0;
|
||||
foreach (Topology.Path profilePath in Paths)
|
||||
{
|
||||
foreach (Topology.Path otherPath in other.Paths)
|
||||
if (other.Paths.Contains(profilePath))
|
||||
{
|
||||
if (profilePath.Equals(otherPath))
|
||||
foundPathsCount++;
|
||||
}
|
||||
foundPathsCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
foreach (Topology.Path otherPath in other.Paths)
|
||||
{
|
||||
if (Paths.Contains(otherPath))
|
||||
{
|
||||
foundOtherPathsCount++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundPathsCount == Paths.Length)
|
||||
|
||||
if (foundPathsCount == foundOtherPathsCount)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
@ -483,8 +515,10 @@ namespace DisplayMagicianShared
|
||||
}
|
||||
if (validDisplayCount == ProfileDisplayIdentifiers.Count)
|
||||
{
|
||||
|
||||
SharedLogger.logger.Debug($"ProfileRepository/IsPossibleRefresh: The profile {Name} is possible!");
|
||||
_isPossible = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -530,35 +564,63 @@ namespace DisplayMagicianShared
|
||||
if (x is null || y is null)
|
||||
return false;
|
||||
|
||||
if (x.Paths.Length != y.Paths.Length)
|
||||
return false;
|
||||
|
||||
// Check if the profile identifiers are not the same, then return false
|
||||
int foundDICount = 0;
|
||||
foreach (string profileDI in x.ProfileDisplayIdentifiers)
|
||||
{
|
||||
foreach (string otherDI in y.ProfileDisplayIdentifiers)
|
||||
if (y.ProfileDisplayIdentifiers.Contains(profileDI))
|
||||
{
|
||||
if (profileDI.Equals(otherDI))
|
||||
foundDICount++;
|
||||
foundDICount++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (foundDICount != x.ProfileDisplayIdentifiers.Count)
|
||||
return false;
|
||||
|
||||
foundDICount = 0;
|
||||
foreach (string profileDI in y.ProfileDisplayIdentifiers)
|
||||
{
|
||||
if (x.ProfileDisplayIdentifiers.Contains(profileDI))
|
||||
{
|
||||
foundDICount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
if (foundDICount != y.ProfileDisplayIdentifiers.Count)
|
||||
return false;
|
||||
|
||||
|
||||
// Check whether the profiles' properties are equal
|
||||
// We need to exclude the name as the name is solely for saving to disk
|
||||
// and displaying to the user.
|
||||
// Two profiles are equal only when they have the same viewport data
|
||||
int foundPathsCount = 0;
|
||||
int foundOtherPathsCount = 0;
|
||||
foreach (Topology.Path profilePath in x.Paths)
|
||||
{
|
||||
foreach (Topology.Path otherPath in y.Paths)
|
||||
if (y.Paths.Contains(profilePath))
|
||||
{
|
||||
if (profilePath.Equals(otherPath))
|
||||
foundPathsCount++;
|
||||
foundPathsCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
foreach (Topology.Path otherPath in y.Paths)
|
||||
{
|
||||
if (x.Paths.Contains(otherPath))
|
||||
{
|
||||
foundOtherPathsCount++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundPathsCount == x.Paths.Length)
|
||||
|
||||
if (foundPathsCount == foundOtherPathsCount)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
@ -406,7 +406,8 @@ namespace DisplayMagicianShared
|
||||
|
||||
foreach (ProfileItem testProfile in _allProfiles)
|
||||
{
|
||||
if (testProfile.Paths.SequenceEqual(_currentProfile.Paths))
|
||||
// TODO - change for Equals
|
||||
if (testProfile.Equals(_currentProfile))
|
||||
{
|
||||
SharedLogger.logger.Debug($"ProfileRepository/ContainsCurrentProfile: Our profile repository does contain the display profile currently in use");
|
||||
return true;
|
||||
@ -538,7 +539,7 @@ namespace DisplayMagicianShared
|
||||
{
|
||||
Name = "Current Display Profile",
|
||||
Paths = PathInfo.GetActivePaths().Select(info => new DisplayMagicianShared.Topology.Path(info)).ToArray(),
|
||||
ProfileDisplayIdentifiers = ProfileRepository.GenerateProfileDisplayIdentifiers()
|
||||
//ProfileDisplayIdentifiers = ProfileRepository.GenerateProfileDisplayIdentifiers()
|
||||
};
|
||||
|
||||
activeProfile.ProfileIcon = new ProfileIcon(activeProfile);
|
||||
|
@ -77,6 +77,12 @@ namespace DisplayMagicianShared.Topology
|
||||
|
||||
// Check whether the Profile Viewport properties are equal
|
||||
// Two profiles are equal only when they have the same viewport data exactly
|
||||
/*if (PixelFormat == other.PixelFormat &&
|
||||
Position.Equals(other.Position) &&
|
||||
Resolution.Equals(other.Resolution) &&
|
||||
SourceId == other.SourceId)*/
|
||||
// Note: Removed the source ID as it changes on boot sometimes!
|
||||
// It can change and the profiles can still be the same
|
||||
if (PixelFormat == other.PixelFormat &&
|
||||
Position.Equals(other.Position) &&
|
||||
Resolution.Equals(other.Resolution) &&
|
||||
@ -92,6 +98,11 @@ namespace DisplayMagicianShared.Topology
|
||||
if (!other.TargetDisplays.Contains(myTargetDisplay))
|
||||
return false;
|
||||
}
|
||||
/*foreach (PathTarget theirTargetDisplay in other.TargetDisplays)
|
||||
{
|
||||
if (!TargetDisplays.Contains(theirTargetDisplay))
|
||||
return false;
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -120,10 +131,52 @@ namespace DisplayMagicianShared.Topology
|
||||
//Calculate the hash code for the product.
|
||||
return hashPixelFormat ^ hashPosition ^ hashResolution ^ hashSourceId ^ hashTargetDisplays;
|
||||
}
|
||||
|
||||
public bool IsPossible(Path other)
|
||||
{
|
||||
|
||||
// If parameter is null, return false.
|
||||
if (Object.ReferenceEquals(other, null))
|
||||
return false;
|
||||
|
||||
// Optimization for a common success case.
|
||||
if (Object.ReferenceEquals(this, other))
|
||||
return true;
|
||||
|
||||
// If run-time types are not exactly the same, return false.
|
||||
if (this.GetType() != other.GetType())
|
||||
return false;
|
||||
|
||||
// Check whether the Profile Viewport properties are equal
|
||||
// Two profiles are equal only when they have the same viewport data exactly
|
||||
/*if (PixelFormat == other.PixelFormat &&
|
||||
Position.Equals(other.Position) &&
|
||||
Resolution.Equals(other.Resolution) &&
|
||||
SourceId == other.SourceId)*/
|
||||
// Note: Removed the source ID as it changes on boot sometimes!
|
||||
// It can change and the profiles can still be the same
|
||||
if (PixelFormat == other.PixelFormat &&
|
||||
Position.Equals(other.Position) &&
|
||||
Resolution.Equals(other.Resolution))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ContainsSurround()
|
||||
{
|
||||
foreach (PathTarget pathTarget in TargetDisplays)
|
||||
{
|
||||
if (pathTarget.SurroundTopology == null)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Custom comparer for the ProfileViewport class
|
||||
class PathComparer : IEqualityComparer<Path>
|
||||
|
||||
// Custom comparer for the ProfileViewport class
|
||||
class PathComparer : IEqualityComparer<Path>
|
||||
{
|
||||
// Products are equal if their names and product numbers are equal.
|
||||
public bool Equals(Path x, Path y)
|
||||
@ -138,6 +191,12 @@ namespace DisplayMagicianShared.Topology
|
||||
|
||||
// Check whether the Profile Viewport properties are equal
|
||||
// Two profiles are equal only when they have the same viewport data exactly
|
||||
/*if (x.PixelFormat == y.PixelFormat &&
|
||||
x.Position.Equals(y.Position) &&
|
||||
x.Resolution.Equals(y.Resolution) &&
|
||||
x.SourceId == y.SourceId)*/
|
||||
// Note: Removed the source ID as it changes on boot sometimes!
|
||||
// It can change and the profiles can still be the same
|
||||
if (x.PixelFormat == y.PixelFormat &&
|
||||
x.Position.Equals(y.Position) &&
|
||||
x.Resolution.Equals(y.Resolution) &&
|
||||
@ -154,6 +213,11 @@ namespace DisplayMagicianShared.Topology
|
||||
if (!y.TargetDisplays.Contains(xTargetDisplay))
|
||||
return false;
|
||||
}
|
||||
/*foreach (PathTarget yTargetDisplay in y.TargetDisplays)
|
||||
{
|
||||
if (!x.TargetDisplays.Contains(yTargetDisplay))
|
||||
return false;
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user