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");
private string _uuid;
private string _uuid = "";
private Version _version;
private bool _isActive = false;
private bool _isPossible = false;
@ -94,7 +94,7 @@ namespace HeliosPlus.Shared
}
#endregion
static ProfileItem()
public ProfileItem()
{
try
{
@ -116,12 +116,12 @@ namespace HeliosPlus.Shared
get
{
if (String.IsNullOrWhiteSpace(_uuid))
_uuid = Guid.NewGuid().ToString("B");
_uuid = Guid.NewGuid().ToString("B");
return _uuid;
}
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);
if (match.Success)
_uuid = value;
@ -165,6 +165,7 @@ namespace HeliosPlus.Shared
public ProfileViewport[] Viewports { get; set; } = new ProfileViewport[0];
[JsonIgnore]
public ProfileIcon ProfileIcon
{
get
@ -241,7 +242,7 @@ namespace HeliosPlus.Shared
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";
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))
return false;
if (overwriteId)
if (overwriteId == true)
profile.UUID = UUID;
// Copy all our profile data over to the other profile
profile.Name = Name;
profile.UUID = UUID;
profile.Name = Name;
profile.Viewports = Viewports;
profile.ProfileIcon = ProfileIcon;
profile.SavedProfileIconCacheFilename = SavedProfileIconCacheFilename;
@ -279,7 +278,7 @@ namespace HeliosPlus.Shared
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)
{

View File

@ -29,7 +29,7 @@ namespace HeliosPlus.Shared
{
#region Class Variables
// 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);
// Other constants that are useful
public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus");
@ -98,6 +98,9 @@ namespace HeliosPlus.Shared
{
get
{
if (_allProfiles == null)
// Load the Profiles from storage if they need to be
LoadProfiles();
return _allProfiles.Count;
}
}
@ -112,18 +115,27 @@ namespace HeliosPlus.Shared
// 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
if (!ContainsProfile(Profile))
{
// Add the Profile to the list of Profiles
_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
if (ContainsProfile(Profile))
{
@ -261,7 +273,7 @@ namespace HeliosPlus.Shared
if (String.IsNullOrWhiteSpace(ProfileNameOrId))
return false;
if (ProfileItem.IsValidId(ProfileNameOrId))
if (ProfileItem.IsValidUUID(ProfileNameOrId))
foreach (ProfileItem testProfile in _allProfiles)
{
if (testProfile.UUID.Equals(ProfileNameOrId))
@ -283,7 +295,7 @@ namespace HeliosPlus.Shared
if (String.IsNullOrWhiteSpace(ProfileNameOrId))
return null;
if (ProfileItem.IsValidId(ProfileNameOrId))
if (ProfileItem.IsValidUUID(ProfileNameOrId))
foreach (ProfileItem testProfile in _allProfiles)
{
if (testProfile.UUID.Equals(ProfileNameOrId))
@ -316,11 +328,11 @@ namespace HeliosPlus.Shared
// rename the old Profile Icon to the new name
string newSavedProfileIconCacheFilename = Path.Combine(_profileStorageJsonPath, String.Concat(@"profile-", GetValidFilename(profile.Name).ToLower(CultureInfo.InvariantCulture), @".ico"));
File.Move(profile.SavedProfileIconCacheFilename, newSavedProfileIconCacheFilename);
//string newSavedProfileIconCacheFilename = Path.Combine(_profileStorageJsonPath, String.Concat(@"profile-", profile.UUID, @".ico"));
//File.Move(profile.SavedProfileIconCacheFilename, newSavedProfileIconCacheFilename);
// Then update the profile too
profile.SavedProfileIconCacheFilename = newSavedProfileIconCacheFilename;
//profile.SavedProfileIconCacheFilename = newSavedProfileIconCacheFilename;
// Save the Profiles JSON as it's different now
SaveProfiles();
@ -335,7 +347,8 @@ namespace HeliosPlus.Shared
public static void UpdateActiveProfile()
{
_currentProfile = new ProfileItem
ProfileItem activeProfile = new ProfileItem
{
Name = "Current Display Profile",
Viewports = PathInfo.GetActivePaths().Select(info => new ProfileViewport(info)).ToArray(),
@ -343,6 +356,17 @@ namespace HeliosPlus.Shared
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))
{
List<ProfileItem> profiles = new List<ProfileItem>();
//List<ProfileItem> profiles = new List<ProfileItem>();
try
{
_allProfiles = JsonConvert.DeserializeObject<List<ProfileItem>>(json, new JsonSerializerSettings
@ -388,7 +412,8 @@ namespace HeliosPlus.Shared
MissingMemberHandling = MissingMemberHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Include,
TypeNameHandling = TypeNameHandling.Auto
TypeNameHandling = TypeNameHandling.Auto,
ObjectCreationHandling = ObjectCreationHandling.Replace
});
}
catch (Exception ex)
@ -406,12 +431,12 @@ namespace HeliosPlus.Shared
_currentProfile = myCurrentProfile;
// 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
loadedProfile.ProfileIcon = new ProfileIcon(loadedProfile);
loadedProfile.ProfileBitmap = loadedProfile.ProfileIcon.ToBitmap(128, 128);
/* loadedProfile.ProfileIcon = new ProfileIcon(loadedProfile);
loadedProfile.ProfileBitmap = loadedProfile.ProfileIcon.ToBitmap(256, 256);
*/
if (ProfileRepository.IsActiveProfile(loadedProfile))
_currentProfile = loadedProfile;
@ -482,7 +507,7 @@ namespace HeliosPlus.Shared
{
// 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;
try

View File

@ -18,6 +18,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NvAPIWrapper.Native.Display.Structures;
using System.Text.RegularExpressions;
namespace HeliosPlus
{
@ -41,9 +42,10 @@ namespace HeliosPlus
private MultiIcon _shortcutIcon, _originalIcon = null;
private Bitmap _shortcutBitmap, _originalBitmap = null;
private ProfileItem _profileToUse = null;
private string _originalIconPath = "";
private uint _id = 0;
private string _profileName = "";
private string _originalIconPath = "", _savedShortcutIconCacheFilename = "", _uuid = "";
private string _name = "";
//private uint _id = 0;
private string _profileUuid = "";
private bool _isPossible = false;
public ShortcutItem()
@ -57,26 +59,57 @@ namespace HeliosPlus
public static Version Version = new Version(1, 0);
public uint Id
public string UUID
{
get
{
if (_id == 0)
_id = ShortcutRepository.GetNextAvailableShortcutId();
return _id;
if (String.IsNullOrWhiteSpace(_uuid))
_uuid = Guid.NewGuid().ToString("B");
return _uuid;
}
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]
public ProfileItem ProfileToUse {
get
{
if (_profileToUse == null && !String.IsNullOrWhiteSpace(_profileUuid))
foreach (ProfileItem profileToTest in ProfileRepository.AllProfiles)
{
if (profileToTest.UUID.Equals(_profileUuid))
{
_profileToUse = profileToTest;
break;
}
}
return _profileToUse;
}
set
@ -84,27 +117,32 @@ namespace HeliosPlus
if (value is ProfileItem)
{
_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
if (_originalBitmap is Bitmap)
_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
{
return _profileName;
if (_profileUuid == null && _profileToUse is ProfileItem)
_profileUuid = _profileToUse.UUID;
return _profileUuid;
}
set
{
_profileName = value;
_profileUuid = value;
// We try to find and set the ProfileTouse
foreach (ProfileItem profileToTest in ProfileRepository.AllProfiles)
{
if (profileToTest.Name.Equals(_profileName))
if (profileToTest.UUID.Equals(_profileUuid))
_profileToUse = profileToTest;
}
}
@ -161,8 +199,7 @@ namespace HeliosPlus
}
}
//[JsonConverter(typeof(CustomBitmapConverter))]
[JsonIgnore]
[JsonConverter(typeof(CustomBitmapConverter))]
public Bitmap OriginalBitmap
{
get
@ -184,8 +221,7 @@ namespace HeliosPlus
}
}
//[JsonConverter(typeof(CustomBitmapConverter))]
[JsonIgnore]
[JsonConverter(typeof(CustomBitmapConverter))]
public Bitmap ShortcutBitmap
{
get
@ -214,7 +250,6 @@ namespace HeliosPlus
public string SavedShortcutIconCacheFilename { get; set; }
[JsonIgnore]
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))
return false;
if (overwriteId)
shortcut.Id = Id;
if (overwriteUUID)
shortcut.UUID = UUID;
// Copy all the shortcut data over to the other Shortcut
shortcut.Name = Name;
shortcut.ProfileToUse = ProfileToUse;
shortcut.ProfileName = ProfileName;
shortcut.ProfileUUID = ProfileUUID;
shortcut.Permanence = Permanence;
shortcut.Category = Category;
shortcut.DifferentExecutableToMonitor = DifferentExecutableToMonitor;
@ -570,6 +605,29 @@ namespace HeliosPlus
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

View File

@ -8,6 +8,7 @@ using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -18,7 +19,7 @@ namespace HeliosPlus
{
#region Class Variables
// 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);
// Other constants that are useful
private static string _shortcutStorageJsonPath = Path.Combine(Program.AppDataPath, $"Shortcuts");
@ -35,14 +36,15 @@ namespace HeliosPlus
public ShortcutRepository()
{
// Load the Shortcuts from storage
if (LoadShortcuts() && ShortcutCount > 0)
LoadShortcuts();
/* if (LoadShortcuts() && ShortcutCount > 0)
{
// Work out the starting NextShortcutId value
long max = _allShortcuts.Max<ShortcutItem>(item => item.Id);
_lastShortcutId = Convert.ToUInt32(max);
} else
_lastShortcutId = 0;
}
*/ }
public ShortcutRepository(ShortcutItem shortcut) : this()
{
@ -58,7 +60,8 @@ namespace HeliosPlus
{
if (_allShortcuts == null)
// Load the Shortcuts from storage
if (LoadShortcuts() && ShortcutCount > 0)
LoadShortcuts();
/* if (LoadShortcuts() && ShortcutCount > 0)
{
// Work out the starting NextShortcutId value
long max = _allShortcuts.Max<ShortcutItem>(item => item.Id);
@ -66,7 +69,7 @@ namespace HeliosPlus
}
else
_lastShortcutId = 0;
*/
return _allShortcuts;
}
}
@ -93,7 +96,7 @@ namespace HeliosPlus
if (ContainsShortcut(shortcut))
{
// We update the existing Shortcut with the data over
ShortcutItem shortcutToUpdate = GetShortcut(shortcut.Id);
ShortcutItem shortcutToUpdate = GetShortcut(shortcut.UUID);
shortcut.CopyTo(shortcutToUpdate);
}
else
@ -124,7 +127,7 @@ namespace HeliosPlus
return false;
// 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)
{
try
@ -138,7 +141,7 @@ namespace HeliosPlus
}
// 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)
{
@ -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;
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
List<ShortcutItem> shortcutsToRemove = _allShortcuts.FindAll(item => item.Name.Equals(shortcutName));
foreach (ShortcutItem shortcutToRemove in shortcutsToRemove)
{
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)
{
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)
{
@ -227,37 +208,38 @@ namespace HeliosPlus
foreach (ShortcutItem testShortcut in _allShortcuts)
{
if (testShortcut.Id.Equals(shortcut.Id))
if (testShortcut.UUID.Equals(shortcut.UUID))
return true;
}
return false;
}
public static bool ContainsShortcut(string shortcutName)
public static bool ContainsShortcut(string shortcutNameOrUuid)
{
if (String.IsNullOrWhiteSpace(shortcutName))
if (String.IsNullOrWhiteSpace(shortcutNameOrUuid))
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))
return true;
foreach (ShortcutItem testShortcut in _allShortcuts)
{
if (testShortcut.UUID.Equals(shortcutNameOrUuid))
return true;
}
}
return false;
}
public static bool ContainsShortcut(uint shortcutId)
{
if (shortcutId == 0)
return true;
foreach (ShortcutItem testShortcut in _allShortcuts)
else
{
if (testShortcut.Id.Equals(shortcutId))
return true;
foreach (ShortcutItem testShortcut in _allShortcuts)
{
if (testShortcut.Name.Equals(shortcutNameOrUuid))
return true;
}
}
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;
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))
return testShortcut;
foreach (ShortcutItem testShortcut in _allShortcuts)
{
if (testShortcut.UUID.Equals(shortcutNameOrUuid))
return testShortcut;
}
}
else
{
foreach (ShortcutItem testShortcut in _allShortcuts)
{
if (testShortcut.Name.Equals(shortcutNameOrUuid))
return testShortcut;
}
}
return null;
}
public static ShortcutItem GetShortcut(uint shortcutId)
public static bool RenameShortcutProfile(ProfileItem newProfile)
{
if (shortcutId == 0)
return null;
if (!(newProfile is ProfileItem))
return false;
foreach (ShortcutItem testShortcut in _allShortcuts)
foreach (ShortcutItem testShortcut in ShortcutRepository.AllShortcuts)
{
if (testShortcut.Id.Equals(shortcutId))
return testShortcut;
if (testShortcut.ProfileUUID.Equals(newProfile.UUID) && testShortcut.AutoName)
{
testShortcut.ProfileToUse = newProfile;
testShortcut.AutoSuggestShortcutName();
}
}
return null;
SaveShortcuts();
return true;
}
public static uint GetNextAvailableShortcutId()
{
return ++_lastShortcutId;
}
/* public static uint GetNextAvailableShortcutId()
{
return ++_lastShortcutId;
}*/
@ -332,7 +337,7 @@ namespace HeliosPlus
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.
updatedShortcut.ProfileToUse = profile;
@ -397,7 +402,7 @@ namespace HeliosPlus
if (shortcut.Category == ShortcutCategory.Application)
{
// 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
@ -409,13 +414,13 @@ namespace HeliosPlus
if (shortcut.GameLibrary == SupportedGameLibrary.Steam)
{
// 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)
{
// 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
{
// 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;

View File

@ -14,17 +14,19 @@ namespace HeliosPlus.UIForms
internal partial class DisplayProfileForm : Form
{
private ProfileItem _selectedProfile;
private List<ProfileItem> _savedProfiles = new List<ProfileItem>();
//private List<ProfileItem> _savedProfiles = new List<ProfileItem>();
private string _saveOrRenameMode = "save";
private static bool _inDialog = false;
//private static bool _inDialog = false;
private static ProfileItem _profileToLoad = null;
private ProfileAdaptor _profileAdaptor;
private ProfileRepository _profileRepository;
public DisplayProfileForm()
{
InitializeComponent();
this.AcceptButton = this.btn_save_or_rename;
_profileAdaptor = new ProfileAdaptor();
_profileRepository = new ProfileRepository();
}
public DisplayProfileForm(ProfileItem profileToLoad) : this()
@ -105,7 +107,7 @@ namespace HeliosPlus.UIForms
ilv_saved_profiles.Items[ilvItemToSelect].Selected = true;
// select the
foreach (ProfileItem newSelectedProfile in _savedProfiles)
foreach (ProfileItem newSelectedProfile in ProfileRepository.AllProfiles)
{
if (newSelectedProfile.Name.Equals(ilv_saved_profiles.Items[ilvItemToSelect].Text))
{
@ -126,63 +128,57 @@ namespace HeliosPlus.UIForms
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
ilv_saved_profiles.SuspendLayout();
if (_savedProfiles.Count > 0)
ImageListViewItem newItem = null;
bool foundCurrentProfileInLoadedProfiles = false;
foreach (ProfileItem loadedProfile in ProfileRepository.AllProfiles)
{
ImageListViewItem newItem = null;
bool foundCurrentProfileInLoadedProfiles = false;
foreach (ProfileItem loadedProfile in _savedProfiles)
bool thisLoadedProfileIsAlreadyHere = (from item in ilv_saved_profiles.Items where item.Text == loadedProfile.Name select item.Text).Any();
if (!thisLoadedProfileIsAlreadyHere)
{
bool thisLoadedProfileIsAlreadyHere = (from item in ilv_saved_profiles.Items where item.Text == loadedProfile.Name select item.Text).Any();
if (!thisLoadedProfileIsAlreadyHere)
{
//loadedProfile.SaveProfileImageToCache();
//newItem = new ImageListViewItem(loadedProfile.SavedProfileCacheFilename, loadedProfile.Name);
//newItem = new ImageListViewItem(loadedProfile, loadedProfile.Name);
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;
}
//loadedProfile.SaveProfileImageToCache();
//newItem = new ImageListViewItem(loadedProfile.SavedProfileCacheFilename, loadedProfile.Name);
//newItem = new ImageListViewItem(loadedProfile, loadedProfile.Name);
newItem = new ImageListViewItem(loadedProfile, loadedProfile.Name);
//ilv_saved_profiles.Items.Add(newItem);
ilv_saved_profiles.Items.Add(newItem, _profileAdaptor);
}
// If we get to the end of the loaded profiles and haven't
// found a matching profile, then we need to show the current
// Profile
if (!foundCurrentProfileInLoadedProfiles)
ChangeSelectedProfile(ProfileRepository.CurrentProfile);
// 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);
if (ProfileRepository.CurrentProfile.Equals(loadedProfile))
{
// We have already saved the selected profile!
// so we need to show the selected profile
ChangeSelectedProfile(loadedProfile);
foundCurrentProfileInLoadedProfiles = true;
}
}
else
{
// 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
// If we get to the end of the loaded profiles and haven't
// found a matching profile, then we need to show the current
// Profile
if (!foundCurrentProfileInLoadedProfiles)
ChangeSelectedProfile(ProfileRepository.CurrentProfile);
}
// Restart updating the saved_profiles listview
ilv_saved_profiles.ResumeLayout();
// 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
// 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)
{
// Load all the profiles to prepare things
_savedProfiles = ProfileRepository.AllProfiles;
//_savedProfiles = ProfileRepository.AllProfiles;
// Update the Current Profile
ProfileRepository.UpdateCurrentProfile();
// Refresh the Profile UI
@ -223,9 +219,35 @@ namespace HeliosPlus.UIForms
// And update the save/rename textbox
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";
btn_save_or_rename.Text = "Rename To";
@ -253,7 +275,7 @@ namespace HeliosPlus.UIForms
lbl_profile_shown_subtitle.Text = "";
btn_apply.Visible = true;
}
}
}*/
// Refresh the image list view
RefreshImageListView(profile);
@ -353,10 +375,14 @@ namespace HeliosPlus.UIForms
}
// Lets rename the selectedProfile to the new name
ProfileRepository.RenameProfile(_selectedProfile, txt_profile_save_name.Text);
// Lets update the rest of the profile screen too
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);
@ -368,7 +394,7 @@ namespace HeliosPlus.UIForms
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)
{

View File

@ -21,14 +21,15 @@ namespace HeliosPlus.UIForms
List<SteamGame> _allSteamGames;
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 ShortcutItem _shortcutToEdit = null;
private bool _isNewShortcut = false;
private bool _isUnsaved = false;
private bool _saveNameAutomatic = true;
private uint _gameId = 0;
private uint _id = 0;
private string _uuid = "";
public ShortcutForm()
{
@ -37,6 +38,8 @@ namespace HeliosPlus.UIForms
// Set the profileAdaptor we need to load images from Profiles
// into the Profiles ImageListView
_profileAdaptor = new ProfileAdaptor();
// Then load the ProfilesRepository
_profileRepository = new ProfileRepository();
// 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
@ -367,6 +370,8 @@ namespace HeliosPlus.UIForms
}
// Fill the Shortcut object with the bits we care about saving
// Save the autonaming setting
_shortcutToEdit.AutoName = cb_autosuggest.Checked;
// Update the Executable args
_shortcutToEdit.ExecutableArguments = txt_args_executable.Text;
@ -603,17 +608,28 @@ namespace HeliosPlus.UIForms
{
// Load all the profiles to prepare things
_loadedProfiles = ProfileRepository.AllProfiles;
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!
// so we need to show the selected profile
ChangeSelectedProfile(loadedProfile);
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
// found a matching profile, then we need to show the first
// Profile
if (!foundCurrentProfileInLoadedProfiles && _loadedProfiles.Count > 0)
ChangeSelectedProfile(_loadedProfiles[0]);
if (!foundCurrentProfileInLoadedProfiles && ProfileRepository.ProfileCount > 0)
ChangeSelectedProfile(ProfileRepository.AllProfiles[0]);
// Start finding the games and loading the Games ListView
@ -678,7 +694,7 @@ namespace HeliosPlus.UIForms
// Now start populating the other fields
_id = _shortcutToEdit.Id;
_uuid = _shortcutToEdit.UUID;
// Set if we launch App/Game/NoGame
switch (_shortcutToEdit.Category)
{
@ -704,6 +720,8 @@ namespace HeliosPlus.UIForms
cb_args_game.Checked = true;
}
cb_autosuggest.Checked = _shortcutToEdit.AutoName;
//select the loaded Game item if it is there
foreach (ListViewItem gameItem in lv_games.Items)
{
@ -821,7 +839,7 @@ namespace HeliosPlus.UIForms
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)
{
@ -873,7 +891,7 @@ namespace HeliosPlus.UIForms
{
if (_loadedProfiles.Count > 0)
if (ProfileRepository.ProfileCount > 0)
{
// Temporarily stop updating the saved_profiles listview
@ -881,7 +899,7 @@ namespace HeliosPlus.UIForms
ImageListViewItem newItem = null;
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();
if (!thisLoadedProfileIsAlreadyHere)
@ -904,8 +922,8 @@ namespace HeliosPlus.UIForms
// Check if we were loading a profile to edit
// If so, select that instead of all that other stuff above!
if (_shortcutToEdit != null)
ChangeSelectedProfile(_shortcutToEdit.ProfileToUse);
//if (_shortcutToEdit != null)
// ChangeSelectedProfile(_shortcutToEdit.ProfileToUse);*/
// Restart updating the saved_profiles listview
ilv_saved_profiles.ResumeLayout();

View File

@ -23,13 +23,16 @@ namespace HeliosPlus.UIForms
private ShortcutAdaptor _shortcutAdaptor;
private ImageListViewItem _selectedShortcutILVItem = null;
private ShortcutItem _selectedShortcut = null;
private ShortcutRepository _shortcutRepository = new ShortcutRepository();
private ShortcutRepository _shortcutRepository;
private ProfileRepository _profileRepository;
public ShortcutLibraryForm()
{
InitializeComponent();
_shortcutAdaptor = new ShortcutAdaptor();
}
_shortcutRepository = new ShortcutRepository();
_profileRepository = new ProfileRepository();
}
private void btn_new_Click(object sender, EventArgs e)
{
@ -49,8 +52,6 @@ namespace HeliosPlus.UIForms
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
RefreshShortcutLibraryUI();
}