mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Changed profile matching logic
Relaxed the profile matching logic to use my looser displayidentifier logic as it is more likely that connections to a display is changed rather thant the display paths, resolution or anything like that. Will use this as an experiment to see if it works or not. Also fixed the shortcut renaming errors by searching for the UUID, not the shortcut name which is the pretty much the way I should have done it in the first place!
This commit is contained in:
parent
45f5bb814c
commit
11cd923e46
@ -441,20 +441,26 @@ namespace DisplayMagician
|
|||||||
logger.Debug($"ShortcutRepository/LoadShortcuts: Connecting Shortcut profile names to the real profile objects");
|
logger.Debug($"ShortcutRepository/LoadShortcuts: Connecting Shortcut profile names to the real profile objects");
|
||||||
foreach (ShortcutItem updatedShortcut in _allShortcuts)
|
foreach (ShortcutItem updatedShortcut in _allShortcuts)
|
||||||
{
|
{
|
||||||
|
bool foundProfile = false;
|
||||||
foreach (ProfileItem profile in ProfileRepository.AllProfiles)
|
foreach (ProfileItem profile in ProfileRepository.AllProfiles)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (profile.Equals(updatedShortcut.ProfileToUse))
|
if (profile.UUID.Equals(updatedShortcut.ProfileUUID))
|
||||||
{
|
{
|
||||||
// And assign the matching Profile if we find it.
|
// And assign the matching Profile if we find it.
|
||||||
updatedShortcut.ProfileToUse = profile;
|
updatedShortcut.ProfileToUse = profile;
|
||||||
|
foundProfile = true;
|
||||||
|
logger.Debug($"ShortcutRepository/LoadShortcuts: Found the profile with UUID {updatedShortcut.ProfileUUID} and linked it to a profile!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We should only get here if there isn't a profile to match to.
|
if (!foundProfile)
|
||||||
logger.Debug($"ShortcutRepository/LoadShortcuts: Couldn't find the profile with UUID {updatedShortcut.ProfileUUID} so couldn't link it to a profile! We can't use this shortcut.");
|
{
|
||||||
updatedShortcut.ProfileToUse = null;
|
// We should only get here if there isn't a profile to match to.
|
||||||
|
logger.Debug($"ShortcutRepository/LoadShortcuts: Couldn't find the profile with UUID {updatedShortcut.ProfileUUID} so couldn't link it to a profile! We can't use this shortcut.");
|
||||||
|
updatedShortcut.ProfileToUse = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the shortcuts alphabetically
|
// Sort the shortcuts alphabetically
|
||||||
|
@ -96,7 +96,7 @@ namespace DisplayMagician.UIForms
|
|||||||
{
|
{
|
||||||
Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize));
|
Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize));
|
||||||
|
|
||||||
ShortcutItem shortcutToRender = ShortcutRepository.GetShortcut(item.Text);
|
ShortcutItem shortcutToRender = ShortcutRepository.GetShortcut(item.EquipmentModel);
|
||||||
if (shortcutToRender.IsValid == ShortcutValidity.Error)
|
if (shortcutToRender.IsValid == ShortcutValidity.Error)
|
||||||
{
|
{
|
||||||
// The shortcut is permanently invalid (game removed or profile deleted)
|
// The shortcut is permanently invalid (game removed or profile deleted)
|
||||||
|
@ -77,7 +77,7 @@ namespace DisplayMagician.UIForms
|
|||||||
ShortcutItem shortcut = (ShortcutItem) key;
|
ShortcutItem shortcut = (ShortcutItem) key;
|
||||||
//return shortcut.Name;
|
//return shortcut.Name;
|
||||||
|
|
||||||
return shortcut.Name;
|
return shortcut.UUID;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -181,7 +181,7 @@ namespace DisplayMagician.UIForms
|
|||||||
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Dimensions, string.Empty, mySize));
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Dimensions, string.Empty, mySize));
|
||||||
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Resolution, string.Empty, mySizeF));
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Resolution, string.Empty, mySizeF));
|
||||||
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ImageDescription, string.Empty, name ?? ""));
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ImageDescription, string.Empty, name ?? ""));
|
||||||
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.EquipmentModel, string.Empty, ""));
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.EquipmentModel, string.Empty, shortcut.UUID));
|
||||||
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateTaken, string.Empty, now));
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateTaken, string.Empty, now));
|
||||||
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Artist, string.Empty, ""));
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Artist, string.Empty, ""));
|
||||||
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Copyright, string.Empty, ""));
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Copyright, string.Empty, ""));
|
||||||
|
@ -100,6 +100,11 @@ namespace DisplayMagician.UIForms
|
|||||||
return (from item in ShortcutRepository.AllShortcuts where item.Name == shortcutName select item).First();
|
return (from item in ShortcutRepository.AllShortcuts where item.Name == shortcutName select item).First();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ShortcutItem GetShortcutFromUUID(string shortcutUUID)
|
||||||
|
{
|
||||||
|
return (from item in ShortcutRepository.AllShortcuts where item.UUID == shortcutUUID select item).First();
|
||||||
|
}
|
||||||
|
|
||||||
private void btn_save_Click(object sender, EventArgs e)
|
private void btn_save_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
//DialogResult = DialogResult.None;
|
//DialogResult = DialogResult.None;
|
||||||
@ -252,8 +257,8 @@ namespace DisplayMagician.UIForms
|
|||||||
private void btn_edit_Click(object sender, EventArgs e)
|
private void btn_edit_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
int currentIlvIndex = ilv_saved_shortcuts.SelectedItems[0].Index;
|
int currentIlvIndex = ilv_saved_shortcuts.SelectedItems[0].Index;
|
||||||
string shortcutName = ilv_saved_shortcuts.Items[currentIlvIndex].Text;
|
string shortcutUUID = ilv_saved_shortcuts.Items[currentIlvIndex].EquipmentModel;
|
||||||
_selectedShortcut = GetShortcutFromName(shortcutName);
|
_selectedShortcut = GetShortcutFromUUID(shortcutUUID);
|
||||||
|
|
||||||
if (_selectedShortcut == null)
|
if (_selectedShortcut == null)
|
||||||
return;
|
return;
|
||||||
@ -262,9 +267,10 @@ namespace DisplayMagician.UIForms
|
|||||||
|
|
||||||
// We need to stop ImageListView redrawing things before we're ready
|
// We need to stop ImageListView redrawing things before we're ready
|
||||||
// This stops an exception when ILV is just too keen!
|
// This stops an exception when ILV is just too keen!
|
||||||
ilv_saved_shortcuts.SuspendLayout();
|
|
||||||
|
|
||||||
var shortcutForm = new ShortcutForm(_selectedShortcut);
|
var shortcutForm = new ShortcutForm(_selectedShortcut);
|
||||||
|
//ilv_saved_shortcuts.SuspendLayout();
|
||||||
shortcutForm.ShowDialog(this);
|
shortcutForm.ShowDialog(this);
|
||||||
if (shortcutForm.DialogResult == DialogResult.OK)
|
if (shortcutForm.DialogResult == DialogResult.OK)
|
||||||
{
|
{
|
||||||
|
@ -331,7 +331,8 @@ namespace DisplayMagicianShared
|
|||||||
// 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))
|
//if (Paths.SequenceEqual(other.Paths))
|
||||||
|
if (ProfileDisplayIdentifiers.SequenceEqual(other.ProfileDisplayIdentifiers))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
@ -339,7 +340,7 @@ namespace DisplayMagicianShared
|
|||||||
|
|
||||||
// If Equals() returns true for this object compared to another
|
// If Equals() returns true for this object compared to another
|
||||||
// then GetHashCode() must return the same value for these objects.
|
// then GetHashCode() must return the same value for these objects.
|
||||||
public override int GetHashCode()
|
/*public override int GetHashCode()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Get hash code for the Viewports field if it is not null.
|
// Get hash code for the Viewports field if it is not null.
|
||||||
@ -348,6 +349,16 @@ namespace DisplayMagicianShared
|
|||||||
//Calculate the hash code for the product.
|
//Calculate the hash code for the product.
|
||||||
return hashPaths;
|
return hashPaths;
|
||||||
|
|
||||||
|
}*/
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
|
||||||
|
// Get hash code for the ProfileDisplayIdentifiers field if it is not null.
|
||||||
|
int hashPaths = ProfileDisplayIdentifiers == null ? 0 : ProfileDisplayIdentifiers.GetHashCode();
|
||||||
|
|
||||||
|
//Calculate the hash code for the product.
|
||||||
|
return hashPaths;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -462,7 +473,7 @@ namespace DisplayMagicianShared
|
|||||||
class ProfileComparer : IEqualityComparer<ProfileItem>
|
class ProfileComparer : IEqualityComparer<ProfileItem>
|
||||||
{
|
{
|
||||||
// Products are equal if their names and product numbers are equal.
|
// Products are equal if their names and product numbers are equal.
|
||||||
public bool Equals(ProfileItem x, ProfileItem y)
|
/*public bool Equals(ProfileItem x, ProfileItem y)
|
||||||
{
|
{
|
||||||
|
|
||||||
//Check whether the compared objects reference the same data.
|
//Check whether the compared objects reference the same data.
|
||||||
@ -480,11 +491,31 @@ namespace DisplayMagicianShared
|
|||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public bool Equals(ProfileItem x, ProfileItem y)
|
||||||
|
{
|
||||||
|
|
||||||
|
//Check whether the compared objects reference the same data.
|
||||||
|
if (Object.ReferenceEquals(x, y)) return true;
|
||||||
|
|
||||||
|
//Check whether any of the compared objects is null.
|
||||||
|
if (x is null || y is null)
|
||||||
|
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
|
||||||
|
if (x.ProfileDisplayIdentifiers.SequenceEqual(y.ProfileDisplayIdentifiers))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If Equals() returns true for a pair of objects
|
// If Equals() returns true for a pair of objects
|
||||||
// then GetHashCode() must return the same value for these objects.
|
// then GetHashCode() must return the same value for these objects.
|
||||||
public int GetHashCode(ProfileItem profile)
|
/*public int GetHashCode(ProfileItem profile)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Check whether the object is null
|
// Check whether the object is null
|
||||||
@ -496,7 +527,20 @@ namespace DisplayMagicianShared
|
|||||||
//Calculate the hash code for the product.
|
//Calculate the hash code for the product.
|
||||||
return hashPaths;
|
return hashPaths;
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
// Modified the GetHashCode to compare the displayidentifier
|
||||||
|
public int GetHashCode(ProfileItem profile)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Check whether the object is null
|
||||||
|
if (profile is null) return 0;
|
||||||
|
|
||||||
|
// Get hash code for the ProfileDisplayIdentifiers field if it is not null.
|
||||||
|
int hashPaths = profile.ProfileDisplayIdentifiers == null ? 0 : profile.ProfileDisplayIdentifiers.GetHashCode();
|
||||||
|
|
||||||
|
//Calculate the hash code for the product.
|
||||||
|
return hashPaths;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -47,10 +47,10 @@ namespace DisplayMagicianShared
|
|||||||
SharedLogger.logger.Debug($"ProfileRepository/ProfileRepository: Initialising the NvAPIWrapper.NVIDIA library.");
|
SharedLogger.logger.Debug($"ProfileRepository/ProfileRepository: Initialising the NvAPIWrapper.NVIDIA library.");
|
||||||
NvAPIWrapper.NVIDIA.Initialize();
|
NvAPIWrapper.NVIDIA.Initialize();
|
||||||
|
|
||||||
SharedLogger.logger.Debug($"ProfileRepository/ProfileRepository: Creating the Profiles storage folder {AppProfileStoragePath}.");
|
|
||||||
// Create the Profile Storage Path if it doesn't exist so that it's avilable for all the program
|
// Create the Profile Storage Path if it doesn't exist so that it's avilable for all the program
|
||||||
if (!Directory.Exists(AppProfileStoragePath))
|
if (!Directory.Exists(AppProfileStoragePath))
|
||||||
{
|
{
|
||||||
|
SharedLogger.logger.Debug($"ProfileRepository/ProfileRepository: Creating the Profiles storage folder {AppProfileStoragePath}.");
|
||||||
Directory.CreateDirectory(AppProfileStoragePath);
|
Directory.CreateDirectory(AppProfileStoragePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -495,7 +495,7 @@ namespace DisplayMagicianShared
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void UpdateActiveProfile()
|
/*public static void UpdateActiveProfile()
|
||||||
{
|
{
|
||||||
|
|
||||||
SharedLogger.logger.Debug($"ProfileRepository/UpdateActiveProfile: Updating the profile currently active (in use now).");
|
SharedLogger.logger.Debug($"ProfileRepository/UpdateActiveProfile: Updating the profile currently active (in use now).");
|
||||||
@ -526,9 +526,42 @@ namespace DisplayMagicianShared
|
|||||||
|
|
||||||
//IsPossibleRefresh();
|
//IsPossibleRefresh();
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
public static void UpdateActiveProfile()
|
||||||
|
{
|
||||||
|
|
||||||
|
SharedLogger.logger.Debug($"ProfileRepository/UpdateActiveProfile: Updating the profile currently active (in use now).");
|
||||||
|
|
||||||
|
ProfileItem activeProfile = new ProfileItem
|
||||||
|
{
|
||||||
|
Name = "Current Display Profile",
|
||||||
|
Paths = PathInfo.GetActivePaths().Select(info => new DisplayMagicianShared.Topology.Path(info)).ToArray()
|
||||||
|
};
|
||||||
|
|
||||||
|
activeProfile.ProfileIcon = new ProfileIcon(activeProfile);
|
||||||
|
activeProfile.ProfileBitmap = activeProfile.ProfileIcon.ToBitmap(256, 256);
|
||||||
|
|
||||||
|
if (_profilesLoaded && _allProfiles.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (ProfileItem loadedProfile in ProfileRepository.AllProfiles)
|
||||||
|
{
|
||||||
|
if (activeProfile.Equals(loadedProfile))
|
||||||
|
{
|
||||||
|
_currentProfile = loadedProfile;
|
||||||
|
SharedLogger.logger.Debug($"ProfileRepository/UpdateActiveProfile: The profile {loadedProfile.Name} is currently active (in use now).");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SharedLogger.logger.Debug($"ProfileRepository/UpdateActiveProfile: The current profile is a new profile that doesn't already exist in the Profile Repository.");
|
||||||
|
_currentProfile = activeProfile;
|
||||||
|
|
||||||
|
//IsPossibleRefresh();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static ProfileItem GetActiveProfile()
|
public static ProfileItem GetActiveProfile()
|
||||||
{
|
{
|
||||||
if (!(_currentProfile is ProfileItem))
|
if (!(_currentProfile is ProfileItem))
|
||||||
@ -549,7 +582,8 @@ namespace DisplayMagicianShared
|
|||||||
|
|
||||||
SharedLogger.logger.Debug($"ProfileRepository/IsActiveProfile: Checking whether the profile {profile.Name} is the currently active profile.");
|
SharedLogger.logger.Debug($"ProfileRepository/IsActiveProfile: Checking whether the profile {profile.Name} is the currently active profile.");
|
||||||
|
|
||||||
if (profile.Paths.SequenceEqual(_currentProfile.Paths))
|
//if (profile.Paths.SequenceEqual(_currentProfile.Paths))
|
||||||
|
if (profile.Equals(_currentProfile))
|
||||||
{
|
{
|
||||||
SharedLogger.logger.Debug($"ProfileRepository/IsActiveProfile: The profile {profile.Name} is the currently active profile.");
|
SharedLogger.logger.Debug($"ProfileRepository/IsActiveProfile: The profile {profile.Name} is the currently active profile.");
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user