Shortcut names now update if profile name changed

If a shortcut has Autoname turned on, and if the user
changes the name of the profile, then the shortcut will
be renamed to keep pace with the new profile name.
If autoname is NOT turned on, then the shortcut name
will be kept as is, and the user will need to make any
changes. Please note that HeliosPlus will not make
any changes to any desktop shortcuts saved to the PC.
It will only change the name of the shortcut in the
shortcut library within the App.
This commit is contained in:
terrymacdonald
2020-06-15 21:57:46 +12:00
parent 23e1dbd244
commit 5b396032ff
7 changed files with 348 additions and 216 deletions

View File

@ -29,7 +29,7 @@ namespace HeliosPlus.Shared
internal static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus"); internal static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus");
private string _uuid; private string _uuid = "";
private Version _version; private Version _version;
private bool _isActive = false; private bool _isActive = false;
private bool _isPossible = false; private bool _isPossible = false;
@ -94,7 +94,7 @@ namespace HeliosPlus.Shared
} }
#endregion #endregion
static ProfileItem() public ProfileItem()
{ {
try try
{ {
@ -121,7 +121,7 @@ namespace HeliosPlus.Shared
} }
set set
{ {
string uuidV4Regex = @"/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i"; string uuidV4Regex = @"\{[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\}";
Match match = Regex.Match(value, uuidV4Regex, RegexOptions.IgnoreCase); Match match = Regex.Match(value, uuidV4Regex, RegexOptions.IgnoreCase);
if (match.Success) if (match.Success)
_uuid = value; _uuid = value;
@ -165,6 +165,7 @@ namespace HeliosPlus.Shared
public ProfileViewport[] Viewports { get; set; } = new ProfileViewport[0]; public ProfileViewport[] Viewports { get; set; } = new ProfileViewport[0];
[JsonIgnore]
public ProfileIcon ProfileIcon public ProfileIcon ProfileIcon
{ {
get get
@ -241,7 +242,7 @@ namespace HeliosPlus.Shared
return true; return true;
} }
public static bool IsValidId(string testId) public static bool IsValidUUID(string testId)
{ {
string uuidV4Regex = @"/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i"; string uuidV4Regex = @"/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i";
Match match = Regex.Match(testId, uuidV4Regex, RegexOptions.IgnoreCase); Match match = Regex.Match(testId, uuidV4Regex, RegexOptions.IgnoreCase);
@ -252,18 +253,16 @@ namespace HeliosPlus.Shared
} }
public bool CopyTo(ProfileItem profile, bool overwriteId = false) public bool CopyTo(ProfileItem profile, bool overwriteId = true)
{ {
if (!(profile is ProfileItem)) if (!(profile is ProfileItem))
return false; return false;
if (overwriteId) if (overwriteId == true)
profile.UUID = UUID; profile.UUID = UUID;
// Copy all our profile data over to the other profile // Copy all our profile data over to the other profile
profile.Name = Name; profile.Name = Name;
profile.UUID = UUID;
profile.Name = Name;
profile.Viewports = Viewports; profile.Viewports = Viewports;
profile.ProfileIcon = ProfileIcon; profile.ProfileIcon = ProfileIcon;
profile.SavedProfileIconCacheFilename = SavedProfileIconCacheFilename; profile.SavedProfileIconCacheFilename = SavedProfileIconCacheFilename;
@ -279,7 +278,7 @@ namespace HeliosPlus.Shared
return this.Equals(obj as ProfileItem); return this.Equals(obj as ProfileItem);
} }
// Profiles are equal if their contents (except name) are equal // Profiles are equal if their Viewports are equal
public bool Equals(ProfileItem other) public bool Equals(ProfileItem other)
{ {

View File

@ -29,7 +29,7 @@ namespace HeliosPlus.Shared
{ {
#region Class Variables #region Class Variables
// Common items to the class // Common items to the class
private static List<ProfileItem> _allProfiles = new List<ProfileItem>(); private static List<ProfileItem> _allProfiles = null;
public static Version Version = new Version(1, 0, 0); public static Version Version = new Version(1, 0, 0);
// Other constants that are useful // Other constants that are useful
public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus"); public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus");
@ -98,6 +98,9 @@ namespace HeliosPlus.Shared
{ {
get get
{ {
if (_allProfiles == null)
// Load the Profiles from storage if they need to be
LoadProfiles();
return _allProfiles.Count; return _allProfiles.Count;
} }
} }
@ -112,18 +115,27 @@ namespace HeliosPlus.Shared
// Doublecheck if it already exists // Doublecheck if it already exists
// Because then we just update the one that already exists // Because then we just update the one that already exists
if (ContainsProfile(Profile)) if (!ContainsProfile(Profile))
{
// We update the existing Profile with the data over
ProfileItem ProfileToUpdate = GetProfile(Profile.UUID);
Profile.CopyTo(ProfileToUpdate);
}
else
{ {
// Add the Profile to the list of Profiles // Add the Profile to the list of Profiles
_allProfiles.Add(Profile); _allProfiles.Add(Profile);
} }
/* // Doublecheck if it already exists
// Because then we just update the one that already exists
if (ContainsProfile(Profile))
{
// We update the existing Profile with the data over
ProfileItem ProfileToUpdate = GetProfile(Profile.UUID);
Profile.CopyTo(ProfileToUpdate);
}
else
{
// Add the Profile to the list of Profiles
_allProfiles.Add(Profile);
}
*/
//Doublecheck it's been added //Doublecheck it's been added
if (ContainsProfile(Profile)) if (ContainsProfile(Profile))
{ {
@ -261,7 +273,7 @@ namespace HeliosPlus.Shared
if (String.IsNullOrWhiteSpace(ProfileNameOrId)) if (String.IsNullOrWhiteSpace(ProfileNameOrId))
return false; return false;
if (ProfileItem.IsValidId(ProfileNameOrId)) if (ProfileItem.IsValidUUID(ProfileNameOrId))
foreach (ProfileItem testProfile in _allProfiles) foreach (ProfileItem testProfile in _allProfiles)
{ {
if (testProfile.UUID.Equals(ProfileNameOrId)) if (testProfile.UUID.Equals(ProfileNameOrId))
@ -283,7 +295,7 @@ namespace HeliosPlus.Shared
if (String.IsNullOrWhiteSpace(ProfileNameOrId)) if (String.IsNullOrWhiteSpace(ProfileNameOrId))
return null; return null;
if (ProfileItem.IsValidId(ProfileNameOrId)) if (ProfileItem.IsValidUUID(ProfileNameOrId))
foreach (ProfileItem testProfile in _allProfiles) foreach (ProfileItem testProfile in _allProfiles)
{ {
if (testProfile.UUID.Equals(ProfileNameOrId)) if (testProfile.UUID.Equals(ProfileNameOrId))
@ -316,11 +328,11 @@ namespace HeliosPlus.Shared
// rename the old Profile Icon to the new name // rename the old Profile Icon to the new name
string newSavedProfileIconCacheFilename = Path.Combine(_profileStorageJsonPath, String.Concat(@"profile-", GetValidFilename(profile.Name).ToLower(CultureInfo.InvariantCulture), @".ico")); //string newSavedProfileIconCacheFilename = Path.Combine(_profileStorageJsonPath, String.Concat(@"profile-", profile.UUID, @".ico"));
File.Move(profile.SavedProfileIconCacheFilename, newSavedProfileIconCacheFilename); //File.Move(profile.SavedProfileIconCacheFilename, newSavedProfileIconCacheFilename);
// Then update the profile too // Then update the profile too
profile.SavedProfileIconCacheFilename = newSavedProfileIconCacheFilename; //profile.SavedProfileIconCacheFilename = newSavedProfileIconCacheFilename;
// Save the Profiles JSON as it's different now // Save the Profiles JSON as it's different now
SaveProfiles(); SaveProfiles();
@ -335,7 +347,8 @@ namespace HeliosPlus.Shared
public static void UpdateActiveProfile() public static void UpdateActiveProfile()
{ {
_currentProfile = new ProfileItem
ProfileItem activeProfile = new ProfileItem
{ {
Name = "Current Display Profile", Name = "Current Display Profile",
Viewports = PathInfo.GetActivePaths().Select(info => new ProfileViewport(info)).ToArray(), Viewports = PathInfo.GetActivePaths().Select(info => new ProfileViewport(info)).ToArray(),
@ -343,6 +356,17 @@ namespace HeliosPlus.Shared
ProfileBitmap = _currentProfile.ProfileIcon.ToBitmap(256, 256) ProfileBitmap = _currentProfile.ProfileIcon.ToBitmap(256, 256)
}; };
foreach (ProfileItem loadedProfile in ProfileRepository.AllProfiles)
{
if (activeProfile.Equals(loadedProfile))
{
_currentProfile = loadedProfile;
return;
}
}
_currentProfile = activeProfile;
} }
@ -380,7 +404,7 @@ namespace HeliosPlus.Shared
if (!string.IsNullOrWhiteSpace(json)) if (!string.IsNullOrWhiteSpace(json))
{ {
List<ProfileItem> profiles = new List<ProfileItem>(); //List<ProfileItem> profiles = new List<ProfileItem>();
try try
{ {
_allProfiles = JsonConvert.DeserializeObject<List<ProfileItem>>(json, new JsonSerializerSettings _allProfiles = JsonConvert.DeserializeObject<List<ProfileItem>>(json, new JsonSerializerSettings
@ -388,7 +412,8 @@ namespace HeliosPlus.Shared
MissingMemberHandling = MissingMemberHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Include, DefaultValueHandling = DefaultValueHandling.Include,
TypeNameHandling = TypeNameHandling.Auto TypeNameHandling = TypeNameHandling.Auto,
ObjectCreationHandling = ObjectCreationHandling.Replace
}); });
} }
catch (Exception ex) catch (Exception ex)
@ -406,12 +431,12 @@ namespace HeliosPlus.Shared
_currentProfile = myCurrentProfile; _currentProfile = myCurrentProfile;
// Lookup all the Profile Names in the Saved Profiles // Lookup all the Profile Names in the Saved Profiles
foreach (ProfileItem loadedProfile in profiles) foreach (ProfileItem loadedProfile in _allProfiles)
{ {
// Save a profile Icon to the profile // Save a profile Icon to the profile
loadedProfile.ProfileIcon = new ProfileIcon(loadedProfile); /* loadedProfile.ProfileIcon = new ProfileIcon(loadedProfile);
loadedProfile.ProfileBitmap = loadedProfile.ProfileIcon.ToBitmap(128, 128); loadedProfile.ProfileBitmap = loadedProfile.ProfileIcon.ToBitmap(256, 256);
*/
if (ProfileRepository.IsActiveProfile(loadedProfile)) if (ProfileRepository.IsActiveProfile(loadedProfile))
_currentProfile = loadedProfile; _currentProfile = loadedProfile;
@ -482,7 +507,7 @@ namespace HeliosPlus.Shared
{ {
// Work out the name of the Profile we'll save. // Work out the name of the Profile we'll save.
profile.SavedProfileIconCacheFilename = Path.Combine(_profileStorageJsonPath, String.Concat(@"profile-", GetValidFilename(profile.Name).ToLower(CultureInfo.InvariantCulture), @".ico")); profile.SavedProfileIconCacheFilename = Path.Combine(_profileStorageJsonPath, String.Concat(@"profile-", profile.UUID, @".ico"));
MultiIcon ProfileIcon; MultiIcon ProfileIcon;
try try

View File

@ -18,6 +18,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using NvAPIWrapper.Native.Display.Structures; using NvAPIWrapper.Native.Display.Structures;
using System.Text.RegularExpressions;
namespace HeliosPlus namespace HeliosPlus
{ {
@ -41,9 +42,10 @@ namespace HeliosPlus
private MultiIcon _shortcutIcon, _originalIcon = null; private MultiIcon _shortcutIcon, _originalIcon = null;
private Bitmap _shortcutBitmap, _originalBitmap = null; private Bitmap _shortcutBitmap, _originalBitmap = null;
private ProfileItem _profileToUse = null; private ProfileItem _profileToUse = null;
private string _originalIconPath = ""; private string _originalIconPath = "", _savedShortcutIconCacheFilename = "", _uuid = "";
private uint _id = 0; private string _name = "";
private string _profileName = ""; //private uint _id = 0;
private string _profileUuid = "";
private bool _isPossible = false; private bool _isPossible = false;
public ShortcutItem() public ShortcutItem()
@ -57,26 +59,57 @@ namespace HeliosPlus
public static Version Version = new Version(1, 0); public static Version Version = new Version(1, 0);
public uint Id public string UUID
{ {
get get
{ {
if (_id == 0) if (String.IsNullOrWhiteSpace(_uuid))
_id = ShortcutRepository.GetNextAvailableShortcutId(); _uuid = Guid.NewGuid().ToString("B");
return _id; return _uuid;
} }
set set
{ {
_id = value; string uuidV4Regex = @"\{[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\}";
Match match = Regex.Match(value, uuidV4Regex, RegexOptions.IgnoreCase);
if (match.Success)
_uuid = value;
} }
} }
public string Name { get; set; } = ""; public string Name
{
get
{
if (AutoName && _profileToUse is ProfileItem)
{
// If Autoname is on, and then lets autoname it!
AutoSuggestShortcutName();
}
return _name;
}
set
{
_name = value;
}
}
public bool AutoName { get; set; } = true;
[JsonIgnore] [JsonIgnore]
public ProfileItem ProfileToUse { public ProfileItem ProfileToUse {
get get
{ {
if (_profileToUse == null && !String.IsNullOrWhiteSpace(_profileUuid))
foreach (ProfileItem profileToTest in ProfileRepository.AllProfiles)
{
if (profileToTest.UUID.Equals(_profileUuid))
{
_profileToUse = profileToTest;
break;
}
}
return _profileToUse; return _profileToUse;
} }
set set
@ -84,27 +117,32 @@ namespace HeliosPlus
if (value is ProfileItem) if (value is ProfileItem)
{ {
_profileToUse = value; _profileToUse = value;
_profileName = _profileToUse.Name; _profileUuid = _profileToUse.UUID;
// And if we have the _originalBitmap we can also save the Bitmap overlay, but only if the ProfileToUse is set // And if we have the _originalBitmap we can also save the Bitmap overlay, but only if the ProfileToUse is set
if (_originalBitmap is Bitmap) if (_originalBitmap is Bitmap)
_shortcutBitmap = ToBitmapOverlay(_originalBitmap, ProfileToUse.ProfileTightestBitmap,256,256); _shortcutBitmap = ToBitmapOverlay(_originalBitmap, ProfileToUse.ProfileTightestBitmap,256,256);
// And we rename the shortcut if the AutoName is on
if (AutoName)
AutoSuggestShortcutName();
} }
} }
} }
public string ProfileName { public string ProfileUUID {
get get
{ {
return _profileName; if (_profileUuid == null && _profileToUse is ProfileItem)
_profileUuid = _profileToUse.UUID;
return _profileUuid;
} }
set set
{ {
_profileName = value; _profileUuid = value;
// We try to find and set the ProfileTouse // We try to find and set the ProfileTouse
foreach (ProfileItem profileToTest in ProfileRepository.AllProfiles) foreach (ProfileItem profileToTest in ProfileRepository.AllProfiles)
{ {
if (profileToTest.Name.Equals(_profileName)) if (profileToTest.UUID.Equals(_profileUuid))
_profileToUse = profileToTest; _profileToUse = profileToTest;
} }
} }
@ -161,8 +199,7 @@ namespace HeliosPlus
} }
} }
//[JsonConverter(typeof(CustomBitmapConverter))] [JsonConverter(typeof(CustomBitmapConverter))]
[JsonIgnore]
public Bitmap OriginalBitmap public Bitmap OriginalBitmap
{ {
get get
@ -184,8 +221,7 @@ namespace HeliosPlus
} }
} }
//[JsonConverter(typeof(CustomBitmapConverter))] [JsonConverter(typeof(CustomBitmapConverter))]
[JsonIgnore]
public Bitmap ShortcutBitmap public Bitmap ShortcutBitmap
{ {
get get
@ -214,7 +250,6 @@ namespace HeliosPlus
public string SavedShortcutIconCacheFilename { get; set; } public string SavedShortcutIconCacheFilename { get; set; }
[JsonIgnore] [JsonIgnore]
public bool IsPossible public bool IsPossible
{ {
@ -228,18 +263,18 @@ namespace HeliosPlus
} }
} }
public bool CopyTo (ShortcutItem shortcut, bool overwriteId = false) public bool CopyTo (ShortcutItem shortcut, bool overwriteUUID = false)
{ {
if (!(shortcut is ShortcutItem)) if (!(shortcut is ShortcutItem))
return false; return false;
if (overwriteId) if (overwriteUUID)
shortcut.Id = Id; shortcut.UUID = UUID;
// Copy all the shortcut data over to the other Shortcut // Copy all the shortcut data over to the other Shortcut
shortcut.Name = Name; shortcut.Name = Name;
shortcut.ProfileToUse = ProfileToUse; shortcut.ProfileToUse = ProfileToUse;
shortcut.ProfileName = ProfileName; shortcut.ProfileUUID = ProfileUUID;
shortcut.Permanence = Permanence; shortcut.Permanence = Permanence;
shortcut.Category = Category; shortcut.Category = Category;
shortcut.DifferentExecutableToMonitor = DifferentExecutableToMonitor; shortcut.DifferentExecutableToMonitor = DifferentExecutableToMonitor;
@ -570,6 +605,29 @@ namespace HeliosPlus
return shortcutFileName != null && File.Exists(shortcutFileName); return shortcutFileName != null && File.Exists(shortcutFileName);
} }
public void AutoSuggestShortcutName()
{
if (AutoName && _profileToUse is ProfileItem)
{
if (Category.Equals(ShortcutCategory.NoGame))
{
if (Permanence.Equals(ShortcutPermanence.Permanent))
_name = $"{_profileToUse.Name}";
else if (Permanence.Equals(ShortcutPermanence.Temporary))
_name = $"{_profileToUse.Name} (Temporary)";
}
else if (Category.Equals(ShortcutCategory.Game) && GameName.Length > 0)
{
_name = $"{GameName} ({_profileToUse.Name})";
}
else if (Category.Equals(ShortcutCategory.Application) && ExecutableNameAndPath.Length > 0)
{
string baseName = Path.GetFileNameWithoutExtension(ExecutableNameAndPath);
_name = $"{baseName} ({_profileToUse.Name})";
}
}
}
} }
#region JsonConverterBitmap #region JsonConverterBitmap

View File

@ -8,6 +8,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@ -18,7 +19,7 @@ namespace HeliosPlus
{ {
#region Class Variables #region Class Variables
// Common items to the class // Common items to the class
private static List<ShortcutItem> _allShortcuts = new List<ShortcutItem>(); private static List<ShortcutItem> _allShortcuts = null;
public static Version Version = new Version(1, 0, 0); public static Version Version = new Version(1, 0, 0);
// Other constants that are useful // Other constants that are useful
private static string _shortcutStorageJsonPath = Path.Combine(Program.AppDataPath, $"Shortcuts"); private static string _shortcutStorageJsonPath = Path.Combine(Program.AppDataPath, $"Shortcuts");
@ -35,14 +36,15 @@ namespace HeliosPlus
public ShortcutRepository() public ShortcutRepository()
{ {
// Load the Shortcuts from storage // Load the Shortcuts from storage
if (LoadShortcuts() && ShortcutCount > 0) LoadShortcuts();
/* if (LoadShortcuts() && ShortcutCount > 0)
{ {
// Work out the starting NextShortcutId value // Work out the starting NextShortcutId value
long max = _allShortcuts.Max<ShortcutItem>(item => item.Id); long max = _allShortcuts.Max<ShortcutItem>(item => item.Id);
_lastShortcutId = Convert.ToUInt32(max); _lastShortcutId = Convert.ToUInt32(max);
} else } else
_lastShortcutId = 0; _lastShortcutId = 0;
} */ }
public ShortcutRepository(ShortcutItem shortcut) : this() public ShortcutRepository(ShortcutItem shortcut) : this()
{ {
@ -58,7 +60,8 @@ namespace HeliosPlus
{ {
if (_allShortcuts == null) if (_allShortcuts == null)
// Load the Shortcuts from storage // Load the Shortcuts from storage
if (LoadShortcuts() && ShortcutCount > 0) LoadShortcuts();
/* if (LoadShortcuts() && ShortcutCount > 0)
{ {
// Work out the starting NextShortcutId value // Work out the starting NextShortcutId value
long max = _allShortcuts.Max<ShortcutItem>(item => item.Id); long max = _allShortcuts.Max<ShortcutItem>(item => item.Id);
@ -66,7 +69,7 @@ namespace HeliosPlus
} }
else else
_lastShortcutId = 0; _lastShortcutId = 0;
*/
return _allShortcuts; return _allShortcuts;
} }
} }
@ -93,7 +96,7 @@ namespace HeliosPlus
if (ContainsShortcut(shortcut)) if (ContainsShortcut(shortcut))
{ {
// We update the existing Shortcut with the data over // We update the existing Shortcut with the data over
ShortcutItem shortcutToUpdate = GetShortcut(shortcut.Id); ShortcutItem shortcutToUpdate = GetShortcut(shortcut.UUID);
shortcut.CopyTo(shortcutToUpdate); shortcut.CopyTo(shortcutToUpdate);
} }
else else
@ -124,7 +127,7 @@ namespace HeliosPlus
return false; return false;
// Remove the Shortcut Icons from the Cache // Remove the Shortcut Icons from the Cache
List<ShortcutItem> shortcutsToRemove = _allShortcuts.FindAll(item => item.Id.Equals(shortcut.Id)); List<ShortcutItem> shortcutsToRemove = _allShortcuts.FindAll(item => item.UUID.Equals(shortcut.UUID));
foreach (ShortcutItem shortcutToRemove in shortcutsToRemove) foreach (ShortcutItem shortcutToRemove in shortcutsToRemove)
{ {
try try
@ -138,7 +141,7 @@ namespace HeliosPlus
} }
// Remove the shortcut from the list. // Remove the shortcut from the list.
int numRemoved = _allShortcuts.RemoveAll(item => item.Id.Equals(shortcut.Id)); int numRemoved = _allShortcuts.RemoveAll(item => item.UUID.Equals(shortcut.UUID));
if (numRemoved == 1) if (numRemoved == 1)
{ {
@ -152,13 +155,27 @@ namespace HeliosPlus
} }
public static bool RemoveShortcut(string shortcutName) public static bool RemoveShortcut(string shortcutNameOrUuid)
{ {
if (String.IsNullOrWhiteSpace(shortcutName)) if (String.IsNullOrWhiteSpace(shortcutNameOrUuid))
return false; return false;
List<ShortcutItem> shortcutsToRemove;
int numRemoved;
string uuidV4Regex = @"/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i";
Match match = Regex.Match(shortcutNameOrUuid, uuidV4Regex, RegexOptions.IgnoreCase);
if (match.Success)
{
shortcutsToRemove = _allShortcuts.FindAll(item => item.UUID.Equals(shortcutNameOrUuid));
numRemoved = _allShortcuts.RemoveAll(item => item.UUID.Equals(shortcutNameOrUuid));
}
else
{
shortcutsToRemove = _allShortcuts.FindAll(item => item.Name.Equals(shortcutNameOrUuid));
numRemoved = _allShortcuts.RemoveAll(item => item.Name.Equals(shortcutNameOrUuid));
}
// Remove the Shortcut Icons from the Cache // Remove the Shortcut Icons from the Cache
List<ShortcutItem> shortcutsToRemove = _allShortcuts.FindAll(item => item.Name.Equals(shortcutName));
foreach (ShortcutItem shortcutToRemove in shortcutsToRemove) foreach (ShortcutItem shortcutToRemove in shortcutsToRemove)
{ {
try try
@ -171,9 +188,6 @@ namespace HeliosPlus
} }
} }
// Remove the shortcut from the list.
int numRemoved = _allShortcuts.RemoveAll(item => item.Name.Equals(shortcutName));
if (numRemoved == 1) if (numRemoved == 1)
{ {
SaveShortcuts(); SaveShortcuts();
@ -186,39 +200,6 @@ namespace HeliosPlus
} }
public static bool RemoveShortcut(uint shortcutId)
{
if (shortcutId == 0)
return false;
// Remove the Shortcut Icons from the Cache
List<ShortcutItem> shortcutsToRemove = _allShortcuts.FindAll(item => item.Id.Equals(shortcutId));
foreach (ShortcutItem shortcutToRemove in shortcutsToRemove)
{
try
{
File.Delete(shortcutToRemove.SavedShortcutIconCacheFilename);
}
catch
{
// TODO check and report
}
}
// Remove the shortcut from the list.
int numRemoved = _allShortcuts.RemoveAll(item => item.Id.Equals(shortcutId));
if (numRemoved == 1)
{
SaveShortcuts();
return true;
}
else if (numRemoved == 0)
return false;
else
throw new ShortcutRepositoryException();
}
public static bool ContainsShortcut(ShortcutItem shortcut) public static bool ContainsShortcut(ShortcutItem shortcut)
{ {
@ -227,37 +208,38 @@ namespace HeliosPlus
foreach (ShortcutItem testShortcut in _allShortcuts) foreach (ShortcutItem testShortcut in _allShortcuts)
{ {
if (testShortcut.Id.Equals(shortcut.Id)) if (testShortcut.UUID.Equals(shortcut.UUID))
return true; return true;
} }
return false; return false;
} }
public static bool ContainsShortcut(string shortcutName) public static bool ContainsShortcut(string shortcutNameOrUuid)
{ {
if (String.IsNullOrWhiteSpace(shortcutName)) if (String.IsNullOrWhiteSpace(shortcutNameOrUuid))
return false; return false;
foreach (ShortcutItem testShortcut in _allShortcuts)
string uuidV4Regex = @"/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i";
Match match = Regex.Match(shortcutNameOrUuid, uuidV4Regex, RegexOptions.IgnoreCase);
if (match.Success)
{ {
if (testShortcut.Name.Equals(shortcutName)) foreach (ShortcutItem testShortcut in _allShortcuts)
return true; {
if (testShortcut.UUID.Equals(shortcutNameOrUuid))
return true;
}
} }
else
return false;
}
public static bool ContainsShortcut(uint shortcutId)
{
if (shortcutId == 0)
return true;
foreach (ShortcutItem testShortcut in _allShortcuts)
{ {
if (testShortcut.Id.Equals(shortcutId)) foreach (ShortcutItem testShortcut in _allShortcuts)
return true; {
if (testShortcut.Name.Equals(shortcutNameOrUuid))
return true;
}
} }
return false; return false;
@ -265,38 +247,61 @@ namespace HeliosPlus
} }
public static ShortcutItem GetShortcut(string shortcutName) public static ShortcutItem GetShortcut(string shortcutNameOrUuid)
{ {
if (String.IsNullOrWhiteSpace(shortcutName)) if (String.IsNullOrWhiteSpace(shortcutNameOrUuid))
return null; return null;
foreach (ShortcutItem testShortcut in _allShortcuts) string uuidV4Regex = @"/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i";
Match match = Regex.Match(shortcutNameOrUuid, uuidV4Regex, RegexOptions.IgnoreCase);
if (match.Success)
{ {
if (testShortcut.Name.Equals(shortcutName)) foreach (ShortcutItem testShortcut in _allShortcuts)
return testShortcut; {
if (testShortcut.UUID.Equals(shortcutNameOrUuid))
return testShortcut;
}
}
else
{
foreach (ShortcutItem testShortcut in _allShortcuts)
{
if (testShortcut.Name.Equals(shortcutNameOrUuid))
return testShortcut;
}
} }
return null; return null;
} }
public static ShortcutItem GetShortcut(uint shortcutId) public static bool RenameShortcutProfile(ProfileItem newProfile)
{ {
if (shortcutId == 0) if (!(newProfile is ProfileItem))
return null; return false;
foreach (ShortcutItem testShortcut in _allShortcuts) foreach (ShortcutItem testShortcut in ShortcutRepository.AllShortcuts)
{ {
if (testShortcut.Id.Equals(shortcutId)) if (testShortcut.ProfileUUID.Equals(newProfile.UUID) && testShortcut.AutoName)
return testShortcut; {
testShortcut.ProfileToUse = newProfile;
testShortcut.AutoSuggestShortcutName();
}
} }
return null; SaveShortcuts();
return true;
} }
public static uint GetNextAvailableShortcutId() /* public static uint GetNextAvailableShortcutId()
{ {
return ++_lastShortcutId; return ++_lastShortcutId;
} }*/
@ -332,7 +337,7 @@ namespace HeliosPlus
foreach (ProfileItem profile in ProfileRepository.AllProfiles) foreach (ProfileItem profile in ProfileRepository.AllProfiles)
{ {
if (profile.Name.Equals(updatedShortcut.ProfileName)) if (profile.Equals(updatedShortcut.ProfileToUse))
{ {
// And assign the matching Profile if we find it. // And assign the matching Profile if we find it.
updatedShortcut.ProfileToUse = profile; updatedShortcut.ProfileToUse = profile;
@ -397,7 +402,7 @@ namespace HeliosPlus
if (shortcut.Category == ShortcutCategory.Application) if (shortcut.Category == ShortcutCategory.Application)
{ {
// Work out the name of the shortcut we'll save. // Work out the name of the shortcut we'll save.
shortcut.SavedShortcutIconCacheFilename = Path.Combine(_shortcutStorageJsonPath, String.Concat(@"executable-", Program.GetValidFilename(shortcut.Name).ToLower(CultureInfo.InvariantCulture), "-", Path.GetFileNameWithoutExtension(shortcut.ExecutableNameAndPath), @".ico")); shortcut.SavedShortcutIconCacheFilename = Path.Combine(_shortcutStorageJsonPath, String.Concat(@"executable-", shortcut.ProfileToUse.UUID, "-", Path.GetFileNameWithoutExtension(shortcut.ExecutableNameAndPath), @".ico"));
} }
// Only add the rest of the options if the temporary switch radio button is set // Only add the rest of the options if the temporary switch radio button is set
@ -409,13 +414,13 @@ namespace HeliosPlus
if (shortcut.GameLibrary == SupportedGameLibrary.Steam) if (shortcut.GameLibrary == SupportedGameLibrary.Steam)
{ {
// Work out the name of the shortcut we'll save. // Work out the name of the shortcut we'll save.
shortcut.SavedShortcutIconCacheFilename = Path.Combine(_shortcutStorageJsonPath, String.Concat(@"steam-", Program.GetValidFilename(shortcut.Name).ToLower(CultureInfo.InvariantCulture), "-", shortcut.GameAppId.ToString(), @".ico")); shortcut.SavedShortcutIconCacheFilename = Path.Combine(_shortcutStorageJsonPath, String.Concat(@"steam-", shortcut.ProfileToUse.UUID, "-", shortcut.GameAppId.ToString(), @".ico"));
} }
else if (shortcut.GameLibrary == SupportedGameLibrary.Uplay) else if (shortcut.GameLibrary == SupportedGameLibrary.Uplay)
{ {
// Work out the name of the shortcut we'll save. // Work out the name of the shortcut we'll save.
shortcut.SavedShortcutIconCacheFilename = Path.Combine(_shortcutStorageJsonPath, String.Concat(@"uplay-", Program.GetValidFilename(shortcut.Name).ToLower(CultureInfo.InvariantCulture), "-", shortcut.GameAppId.ToString(), @".ico")); shortcut.SavedShortcutIconCacheFilename = Path.Combine(_shortcutStorageJsonPath, String.Concat(@"uplay-", shortcut.ProfileToUse.UUID, "-", shortcut.GameAppId.ToString(), @".ico"));
} }
} }
@ -425,7 +430,7 @@ namespace HeliosPlus
else else
{ {
// Work out the name of the shortcut we'll save. // Work out the name of the shortcut we'll save.
shortcut.SavedShortcutIconCacheFilename = Path.Combine(_shortcutStorageJsonPath, String.Concat(@"permanent-", Program.GetValidFilename(shortcut.Name).ToLower(CultureInfo.InvariantCulture), @".ico")); shortcut.SavedShortcutIconCacheFilename = Path.Combine(_shortcutStorageJsonPath, String.Concat(@"permanent-", shortcut.ProfileToUse.UUID, @".ico"));
} }
MultiIcon shortcutIcon; MultiIcon shortcutIcon;

View File

@ -14,17 +14,19 @@ namespace HeliosPlus.UIForms
internal partial class DisplayProfileForm : Form internal partial class DisplayProfileForm : Form
{ {
private ProfileItem _selectedProfile; private ProfileItem _selectedProfile;
private List<ProfileItem> _savedProfiles = new List<ProfileItem>(); //private List<ProfileItem> _savedProfiles = new List<ProfileItem>();
private string _saveOrRenameMode = "save"; private string _saveOrRenameMode = "save";
private static bool _inDialog = false; //private static bool _inDialog = false;
private static ProfileItem _profileToLoad = null; private static ProfileItem _profileToLoad = null;
private ProfileAdaptor _profileAdaptor; private ProfileAdaptor _profileAdaptor;
private ProfileRepository _profileRepository;
public DisplayProfileForm() public DisplayProfileForm()
{ {
InitializeComponent(); InitializeComponent();
this.AcceptButton = this.btn_save_or_rename; this.AcceptButton = this.btn_save_or_rename;
_profileAdaptor = new ProfileAdaptor(); _profileAdaptor = new ProfileAdaptor();
_profileRepository = new ProfileRepository();
} }
public DisplayProfileForm(ProfileItem profileToLoad) : this() public DisplayProfileForm(ProfileItem profileToLoad) : this()
@ -105,7 +107,7 @@ namespace HeliosPlus.UIForms
ilv_saved_profiles.Items[ilvItemToSelect].Selected = true; ilv_saved_profiles.Items[ilvItemToSelect].Selected = true;
// select the // select the
foreach (ProfileItem newSelectedProfile in _savedProfiles) foreach (ProfileItem newSelectedProfile in ProfileRepository.AllProfiles)
{ {
if (newSelectedProfile.Name.Equals(ilv_saved_profiles.Items[ilvItemToSelect].Text)) if (newSelectedProfile.Name.Equals(ilv_saved_profiles.Items[ilvItemToSelect].Text))
{ {
@ -126,63 +128,57 @@ namespace HeliosPlus.UIForms
private void RefreshDisplayProfileUI() private void RefreshDisplayProfileUI()
{ {
if (!_inDialog) // Temporarily stop updating the saved_profiles listview
ilv_saved_profiles.SuspendLayout();
if (ProfileRepository.ProfileCount > 0)
{ {
// Temporarily stop updating the saved_profiles listview ImageListViewItem newItem = null;
ilv_saved_profiles.SuspendLayout(); bool foundCurrentProfileInLoadedProfiles = false;
foreach (ProfileItem loadedProfile in ProfileRepository.AllProfiles)
if (_savedProfiles.Count > 0)
{ {
ImageListViewItem newItem = null; bool thisLoadedProfileIsAlreadyHere = (from item in ilv_saved_profiles.Items where item.Text == loadedProfile.Name select item.Text).Any();
bool foundCurrentProfileInLoadedProfiles = false; if (!thisLoadedProfileIsAlreadyHere)
foreach (ProfileItem loadedProfile in _savedProfiles)
{ {
bool thisLoadedProfileIsAlreadyHere = (from item in ilv_saved_profiles.Items where item.Text == loadedProfile.Name select item.Text).Any(); //loadedProfile.SaveProfileImageToCache();
if (!thisLoadedProfileIsAlreadyHere) //newItem = new ImageListViewItem(loadedProfile.SavedProfileCacheFilename, loadedProfile.Name);
{ //newItem = new ImageListViewItem(loadedProfile, loadedProfile.Name);
//loadedProfile.SaveProfileImageToCache(); newItem = new ImageListViewItem(loadedProfile, loadedProfile.Name);
//newItem = new ImageListViewItem(loadedProfile.SavedProfileCacheFilename, loadedProfile.Name); //ilv_saved_profiles.Items.Add(newItem);
//newItem = new ImageListViewItem(loadedProfile, loadedProfile.Name); ilv_saved_profiles.Items.Add(newItem, _profileAdaptor);
newItem = new ImageListViewItem(loadedProfile, loadedProfile.Name);
//ilv_saved_profiles.Items.Add(newItem);
ilv_saved_profiles.Items.Add(newItem, _profileAdaptor);
}
if (ProfileRepository.CurrentProfile.Equals(loadedProfile))
{
// We have already saved the selected profile!
// so we need to show the selected profile
ChangeSelectedProfile(loadedProfile);
foundCurrentProfileInLoadedProfiles = true;
}
} }
// If we get to the end of the loaded profiles and haven't if (ProfileRepository.CurrentProfile.Equals(loadedProfile))
// found a matching profile, then we need to show the current {
// Profile // We have already saved the selected profile!
if (!foundCurrentProfileInLoadedProfiles) // so we need to show the selected profile
ChangeSelectedProfile(ProfileRepository.CurrentProfile); ChangeSelectedProfile(loadedProfile);
foundCurrentProfileInLoadedProfiles = true;
// Check if we were loading a profile to edit }
// If so, select that instead of all that other stuff above!
if (_profileToLoad != null)
ChangeSelectedProfile(_profileToLoad);
} }
else
{ // If we get to the end of the loaded profiles and haven't
// If there are no profiles at all then we are starting from scratch! // found a matching profile, then we need to show the current
// Show the profile in the DV window // Profile
// Use the current profile name in the label and the save name if (!foundCurrentProfileInLoadedProfiles)
ChangeSelectedProfile(ProfileRepository.CurrentProfile); ChangeSelectedProfile(ProfileRepository.CurrentProfile);
}
// Restart updating the saved_profiles listview // Check if we were loading a profile to edit
ilv_saved_profiles.ResumeLayout(); // If so, select that instead of all that other stuff above!
if (_profileToLoad != null)
ChangeSelectedProfile(_profileToLoad);
} }
else else
// Otherwise turn off the dialog mode we were just in {
_inDialog = false; // If there are no profiles at all then we are starting from scratch!
// Show the profile in the DV window
// Use the current profile name in the label and the save name
ChangeSelectedProfile(ProfileRepository.CurrentProfile);
}
// Restart updating the saved_profiles listview
ilv_saved_profiles.ResumeLayout();
} }
@ -203,7 +199,7 @@ namespace HeliosPlus.UIForms
private void DisplayProfileForm_Load(object sender, EventArgs e) private void DisplayProfileForm_Load(object sender, EventArgs e)
{ {
// Load all the profiles to prepare things // Load all the profiles to prepare things
_savedProfiles = ProfileRepository.AllProfiles; //_savedProfiles = ProfileRepository.AllProfiles;
// Update the Current Profile // Update the Current Profile
ProfileRepository.UpdateCurrentProfile(); ProfileRepository.UpdateCurrentProfile();
// Refresh the Profile UI // Refresh the Profile UI
@ -223,9 +219,35 @@ namespace HeliosPlus.UIForms
// And update the save/rename textbox // And update the save/rename textbox
txt_profile_save_name.Text = _selectedProfile.Name; txt_profile_save_name.Text = _selectedProfile.Name;
if (_selectedProfile.Equals(ProfileRepository.CurrentProfile)) if (ProfileRepository.AllProfiles.Contains(_selectedProfile))
{ {
if (_savedProfiles.Contains(_selectedProfile)) // we already have the profile stored
_saveOrRenameMode = "rename";
btn_save_or_rename.Text = "Rename To";
if (!_selectedProfile.IsPossible)
{
lbl_profile_shown_subtitle.Text = "(Display Profile is not valid so cannot be used)";
btn_apply.Visible = false;
}
else
{
lbl_profile_shown_subtitle.Text = "";
btn_apply.Visible = true;
}
}
else
{
// we don't have the profile stored yet
_saveOrRenameMode = "save";
btn_save_or_rename.Text = "Save As";
lbl_profile_shown_subtitle.Text = "(Current Display Profile in use - UNSAVED)";
btn_apply.Visible = false;
}
/*if (ProfileRepository.CurrentProfile.Equals(_selectedProfile))
{
if (ProfileRepository.AllProfiles.Contains(_selectedProfile))
{ {
_saveOrRenameMode = "rename"; _saveOrRenameMode = "rename";
btn_save_or_rename.Text = "Rename To"; btn_save_or_rename.Text = "Rename To";
@ -253,7 +275,7 @@ namespace HeliosPlus.UIForms
lbl_profile_shown_subtitle.Text = ""; lbl_profile_shown_subtitle.Text = "";
btn_apply.Visible = true; btn_apply.Visible = true;
} }
} }*/
// Refresh the image list view // Refresh the image list view
RefreshImageListView(profile); RefreshImageListView(profile);
@ -357,6 +379,10 @@ namespace HeliosPlus.UIForms
// Lets update the rest of the profile screen too // Lets update the rest of the profile screen too
lbl_profile_shown.Text = txt_profile_save_name.Text; lbl_profile_shown.Text = txt_profile_save_name.Text;
// And we also need to go through the Shortcuts in the library and rename them!
ShortcutRepository.RenameShortcutProfile(_selectedProfile);
} }
ChangeSelectedProfile(_selectedProfile); ChangeSelectedProfile(_selectedProfile);
@ -368,7 +394,7 @@ namespace HeliosPlus.UIForms
private void ilv_saved_profiles_ItemClick(object sender, ItemClickEventArgs e) private void ilv_saved_profiles_ItemClick(object sender, ItemClickEventArgs e)
{ {
foreach (ProfileItem savedProfile in _savedProfiles) foreach (ProfileItem savedProfile in ProfileRepository.AllProfiles)
{ {
if (savedProfile.Name == e.Item.Text) if (savedProfile.Name == e.Item.Text)
{ {

View File

@ -21,14 +21,15 @@ namespace HeliosPlus.UIForms
List<SteamGame> _allSteamGames; List<SteamGame> _allSteamGames;
private ProfileAdaptor _profileAdaptor; private ProfileAdaptor _profileAdaptor;
private List<ProfileItem> _loadedProfiles = new List<ProfileItem>(); //private List<ProfileItem> _loadedProfiles = new List<ProfileItem>();
private ProfileRepository _profileRepository;
private ProfileItem _profileToUse= null; private ProfileItem _profileToUse= null;
private ShortcutItem _shortcutToEdit = null; private ShortcutItem _shortcutToEdit = null;
private bool _isNewShortcut = false; private bool _isNewShortcut = false;
private bool _isUnsaved = false; private bool _isUnsaved = false;
private bool _saveNameAutomatic = true; private bool _saveNameAutomatic = true;
private uint _gameId = 0; private uint _gameId = 0;
private uint _id = 0; private string _uuid = "";
public ShortcutForm() public ShortcutForm()
{ {
@ -37,6 +38,8 @@ namespace HeliosPlus.UIForms
// Set the profileAdaptor we need to load images from Profiles // Set the profileAdaptor we need to load images from Profiles
// into the Profiles ImageListView // into the Profiles ImageListView
_profileAdaptor = new ProfileAdaptor(); _profileAdaptor = new ProfileAdaptor();
// Then load the ProfilesRepository
_profileRepository = new ProfileRepository();
// Create a new SHortcut if we are creating a new one // Create a new SHortcut if we are creating a new one
// And set up the page (otherwise this is all set when we load an // And set up the page (otherwise this is all set when we load an
@ -367,6 +370,8 @@ namespace HeliosPlus.UIForms
} }
// Fill the Shortcut object with the bits we care about saving // Fill the Shortcut object with the bits we care about saving
// Save the autonaming setting
_shortcutToEdit.AutoName = cb_autosuggest.Checked;
// Update the Executable args // Update the Executable args
_shortcutToEdit.ExecutableArguments = txt_args_executable.Text; _shortcutToEdit.ExecutableArguments = txt_args_executable.Text;
@ -603,17 +608,28 @@ namespace HeliosPlus.UIForms
{ {
// Load all the profiles to prepare things // Load all the profiles to prepare things
_loadedProfiles = ProfileRepository.AllProfiles;
bool foundCurrentProfileInLoadedProfiles = false; bool foundCurrentProfileInLoadedProfiles = false;
foreach (ProfileItem loadedProfile in _loadedProfiles) foreach (ProfileItem loadedProfile in ProfileRepository.AllProfiles)
{ {
if (ProfileRepository.CurrentProfile.Equals(loadedProfile)) if (ProfileRepository.IsActiveProfile(loadedProfile))
{ {
// We have already saved the selected profile! // We have already saved the selected profile!
// so we need to show the selected profile // so we need to show the selected profile
ChangeSelectedProfile(loadedProfile); ChangeSelectedProfile(loadedProfile);
foundCurrentProfileInLoadedProfiles = true; foundCurrentProfileInLoadedProfiles = true;
// If the profile is the same, but the user has renamed the profile
// since the shortcut was last created, then we need to tell the user
if (!loadedProfile.Name.Equals(ProfileRepository.CurrentProfile.Name))
{
MessageBox.Show(
@"The Display Profile used by this Shortcut still exists, but it's changed it's name. We've updated the shortcut's name to reflect this change.",
@"Display Profile name changed",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
} }
} }
@ -621,8 +637,8 @@ namespace HeliosPlus.UIForms
// If we get to the end of the loaded profiles and haven't // If we get to the end of the loaded profiles and haven't
// found a matching profile, then we need to show the first // found a matching profile, then we need to show the first
// Profile // Profile
if (!foundCurrentProfileInLoadedProfiles && _loadedProfiles.Count > 0) if (!foundCurrentProfileInLoadedProfiles && ProfileRepository.ProfileCount > 0)
ChangeSelectedProfile(_loadedProfiles[0]); ChangeSelectedProfile(ProfileRepository.AllProfiles[0]);
// Start finding the games and loading the Games ListView // Start finding the games and loading the Games ListView
@ -678,7 +694,7 @@ namespace HeliosPlus.UIForms
// Now start populating the other fields // Now start populating the other fields
_id = _shortcutToEdit.Id; _uuid = _shortcutToEdit.UUID;
// Set if we launch App/Game/NoGame // Set if we launch App/Game/NoGame
switch (_shortcutToEdit.Category) switch (_shortcutToEdit.Category)
{ {
@ -704,6 +720,8 @@ namespace HeliosPlus.UIForms
cb_args_game.Checked = true; cb_args_game.Checked = true;
} }
cb_autosuggest.Checked = _shortcutToEdit.AutoName;
//select the loaded Game item if it is there //select the loaded Game item if it is there
foreach (ListViewItem gameItem in lv_games.Items) foreach (ListViewItem gameItem in lv_games.Items)
{ {
@ -821,7 +839,7 @@ namespace HeliosPlus.UIForms
private void ilv_saved_profiles_ItemClick(object sender, ItemClickEventArgs e) private void ilv_saved_profiles_ItemClick(object sender, ItemClickEventArgs e)
{ {
foreach (ProfileItem loadedProfile in _loadedProfiles) foreach (ProfileItem loadedProfile in ProfileRepository.AllProfiles)
{ {
if (loadedProfile.Name == e.Item.Text) if (loadedProfile.Name == e.Item.Text)
{ {
@ -873,7 +891,7 @@ namespace HeliosPlus.UIForms
{ {
if (_loadedProfiles.Count > 0) if (ProfileRepository.ProfileCount > 0)
{ {
// Temporarily stop updating the saved_profiles listview // Temporarily stop updating the saved_profiles listview
@ -881,7 +899,7 @@ namespace HeliosPlus.UIForms
ImageListViewItem newItem = null; ImageListViewItem newItem = null;
bool foundCurrentProfileInLoadedProfiles = false; bool foundCurrentProfileInLoadedProfiles = false;
foreach (ProfileItem loadedProfile in _loadedProfiles) foreach (ProfileItem loadedProfile in ProfileRepository.AllProfiles)
{ {
bool thisLoadedProfileIsAlreadyHere = (from item in ilv_saved_profiles.Items where item.Text == loadedProfile.Name select item.Text).Any(); bool thisLoadedProfileIsAlreadyHere = (from item in ilv_saved_profiles.Items where item.Text == loadedProfile.Name select item.Text).Any();
if (!thisLoadedProfileIsAlreadyHere) if (!thisLoadedProfileIsAlreadyHere)
@ -904,8 +922,8 @@ namespace HeliosPlus.UIForms
// Check if we were loading a profile to edit // Check if we were loading a profile to edit
// If so, select that instead of all that other stuff above! // If so, select that instead of all that other stuff above!
if (_shortcutToEdit != null) //if (_shortcutToEdit != null)
ChangeSelectedProfile(_shortcutToEdit.ProfileToUse); // ChangeSelectedProfile(_shortcutToEdit.ProfileToUse);*/
// Restart updating the saved_profiles listview // Restart updating the saved_profiles listview
ilv_saved_profiles.ResumeLayout(); ilv_saved_profiles.ResumeLayout();

View File

@ -23,13 +23,16 @@ namespace HeliosPlus.UIForms
private ShortcutAdaptor _shortcutAdaptor; private ShortcutAdaptor _shortcutAdaptor;
private ImageListViewItem _selectedShortcutILVItem = null; private ImageListViewItem _selectedShortcutILVItem = null;
private ShortcutItem _selectedShortcut = null; private ShortcutItem _selectedShortcut = null;
private ShortcutRepository _shortcutRepository = new ShortcutRepository(); private ShortcutRepository _shortcutRepository;
private ProfileRepository _profileRepository;
public ShortcutLibraryForm() public ShortcutLibraryForm()
{ {
InitializeComponent(); InitializeComponent();
_shortcutAdaptor = new ShortcutAdaptor(); _shortcutAdaptor = new ShortcutAdaptor();
} _shortcutRepository = new ShortcutRepository();
_profileRepository = new ProfileRepository();
}
private void btn_new_Click(object sender, EventArgs e) private void btn_new_Click(object sender, EventArgs e)
{ {
@ -49,8 +52,6 @@ namespace HeliosPlus.UIForms
private void ShortcutLibraryForm_Load(object sender, EventArgs e) private void ShortcutLibraryForm_Load(object sender, EventArgs e)
{ {
// Load all the shortcuts we have saved earlier
List<ShortcutItem> _savedShortcuts = ShortcutRepository.AllShortcuts;
// Refresh the Shortcut Library UI // Refresh the Shortcut Library UI
RefreshShortcutLibraryUI(); RefreshShortcutLibraryUI();
} }