Fixed Profile matching again

This time adjusted profile matching
so that it will work no matter what order
the displayidentifiers or paths are stored
in. Should be a bit slower but a lot more
reliable.
This commit is contained in:
Terry MacDonald 2021-03-26 23:55:35 +13:00
parent 1b6cc7967d
commit 846001548e
3 changed files with 83 additions and 19 deletions

View File

@ -328,14 +328,35 @@ namespace DisplayMagicianShared
return false; return false;
// Check if the profile identifiers are not the same, then return false // Check if the profile identifiers are not the same, then return false
if (!ProfileDisplayIdentifiers.SequenceEqual(other.ProfileDisplayIdentifiers)) int foundDICount = 0;
foreach (string profileDI in ProfileDisplayIdentifiers)
{
foreach (string otherDI in other.ProfileDisplayIdentifiers)
{
if (profileDI.Equals(otherDI))
foundDICount++;
}
}
if (foundDICount != ProfileDisplayIdentifiers.Count)
return false; return false;
// Check whether the profiles' properties are equal // Check whether the profiles' properties are equal
// We need to exclude the name as the name is solely for saving to disk // We need to exclude the name as the name is solely for saving to disk
// and displaying to the user. // and displaying to the user.
// Two profiles are equal only when they have the same viewport data // Two profiles are equal only when they have the same viewport data
if (Paths.SequenceEqual(other.Paths)) // The data may be in different orders each run, so we need to compare them one by one
int foundPathsCount = 0;
foreach (Topology.Path profilePath in Paths)
{
foreach (Topology.Path otherPath in other.Paths)
{
if (profilePath.Equals(otherPath))
foundPathsCount++;
}
}
if (foundPathsCount == Paths.Length)
return true; return true;
else else
return false; return false;
@ -357,10 +378,13 @@ namespace DisplayMagicianShared
{ {
// Get hash code for the ProfileDisplayIdentifiers field if it is not null. // Get hash code for the ProfileDisplayIdentifiers field if it is not null.
int hashPaths = ProfileDisplayIdentifiers == null ? 0 : ProfileDisplayIdentifiers.GetHashCode(); int hashIds = ProfileDisplayIdentifiers == null ? 0 : ProfileDisplayIdentifiers.GetHashCode();
//Calculate the hash code for the product. // Get Paths too
return hashPaths; int hashPaths = Paths == null ? 0 : Paths.GetHashCode();
// Calculate the hash code for the product.
return (hashIds, hashPaths).GetHashCode();
} }
@ -506,11 +530,35 @@ namespace DisplayMagicianShared
if (x is null || y is null) if (x is null || y is null)
return false; 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 (profileDI.Equals(otherDI))
foundDICount++;
}
}
if (foundDICount != x.ProfileDisplayIdentifiers.Count)
return false;
// Check whether the profiles' properties are equal // Check whether the profiles' properties are equal
// We need to exclude the name as the name is solely for saving to disk // We need to exclude the name as the name is solely for saving to disk
// and displaying to the user. // and displaying to the user.
// Two profiles are equal only when they have the same viewport data // Two profiles are equal only when they have the same viewport data
if (x.ProfileDisplayIdentifiers.SequenceEqual(y.ProfileDisplayIdentifiers)) int foundPathsCount = 0;
foreach (Topology.Path profilePath in x.Paths)
{
foreach (Topology.Path otherPath in y.Paths)
{
if (profilePath.Equals(otherPath))
foundPathsCount++;
}
}
if (foundPathsCount == x.Paths.Length)
return true; return true;
else else
return false; return false;
@ -539,10 +587,13 @@ namespace DisplayMagicianShared
if (profile is null) return 0; if (profile is null) return 0;
// Get hash code for the ProfileDisplayIdentifiers field if it is not null. // Get hash code for the ProfileDisplayIdentifiers field if it is not null.
int hashPaths = profile.ProfileDisplayIdentifiers == null ? 0 : profile.ProfileDisplayIdentifiers.GetHashCode(); int hashIds = profile.ProfileDisplayIdentifiers == null ? 0 : profile.ProfileDisplayIdentifiers.GetHashCode();
// Get hash code for the Paths
int hashPaths = profile.Paths == null ? 0 : profile.Paths.GetHashCode();
//Calculate the hash code for the product. //Calculate the hash code for the product.
return hashPaths; return (hashIds,hashPaths).GetHashCode();
} }
} }

View File

@ -537,7 +537,8 @@ namespace DisplayMagicianShared
ProfileItem activeProfile = new ProfileItem ProfileItem activeProfile = new ProfileItem
{ {
Name = "Current Display Profile", Name = "Current Display Profile",
Paths = PathInfo.GetActivePaths().Select(info => new DisplayMagicianShared.Topology.Path(info)).ToArray() Paths = PathInfo.GetActivePaths().Select(info => new DisplayMagicianShared.Topology.Path(info)).ToArray(),
ProfileDisplayIdentifiers = ProfileRepository.GenerateProfileDisplayIdentifiers()
}; };
activeProfile.ProfileIcon = new ProfileIcon(activeProfile); activeProfile.ProfileIcon = new ProfileIcon(activeProfile);
@ -911,6 +912,9 @@ namespace DisplayMagicianShared
} }
// Sort the display identifiers
displayIdentifiers.Sort();
return displayIdentifiers; return displayIdentifiers;
} }
@ -1116,6 +1120,9 @@ namespace DisplayMagicianShared
} }
// Sort the display identifiers
displayIdentifiers.Sort();
return displayIdentifiers; return displayIdentifiers;
} }

View File

@ -82,12 +82,18 @@ namespace DisplayMagicianShared.Topology
Resolution.Equals(other.Resolution) && Resolution.Equals(other.Resolution) &&
SourceId == other.SourceId) SourceId == other.SourceId)
{ {
// If the above all match, then we need to check the DisplayTargets /*// If the above all match, then we need to check the DisplayTargets
if (other.TargetDisplays.SequenceEqual(TargetDisplays)) if (other.TargetDisplays.SequenceEqual(TargetDisplays))
return true; return true;
else else
return false;*/
foreach (PathTarget myTargetDisplay in TargetDisplays)
{
if (!other.TargetDisplays.Contains(myTargetDisplay))
return false; return false;
} }
return true;
}
else else
return false; return false;
} }
@ -139,16 +145,16 @@ namespace DisplayMagicianShared.Topology
{ {
// If the above all match, then we need to check the DisplayTargets // If the above all match, then we need to check the DisplayTargets
// If they aren't equal then we need to return false; // If they aren't equal then we need to return false;
if (!x.TargetDisplays.SequenceEqual(y.TargetDisplays)) /*if (!x.TargetDisplays.SequenceEqual(y.TargetDisplays))
return false; return false;
else else
return true; return true;*/
/* foreach (ProfileViewportTargetDisplay xTargetDisplay in x.TargetDisplays) foreach (PathTarget xTargetDisplay in x.TargetDisplays)
{ {
if (!y.TargetDisplays.Contains(xTargetDisplay)) if (!y.TargetDisplays.Contains(xTargetDisplay))
return false; return false;
}*/ }
//return true; return true;
} }
else else
return false; return false;