From 32ad405904b5251f7ff3ced9b8f67d8614c491e2 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Wed, 19 Aug 2020 10:16:04 +1200 Subject: [PATCH] Removed braces from UUID in filenames Simplified UUID logic by removing braces from the filenames and within the storage JSON files. --- HeliosPlus.Reporting/Program.cs | 2 +- HeliosPlus.Shared/ProfileItem.cs | 7 ++--- HeliosPlus.Shared/ProfileRepository.cs | 18 ++++++++----- HeliosPlus/Program.cs | 17 ++++++++++++ HeliosPlus/ShortcutItem.cs | 4 +-- HeliosPlus/ShortcutRepository.cs | 36 +++++++++++++++++++------- 6 files changed, 63 insertions(+), 21 deletions(-) diff --git a/HeliosPlus.Reporting/Program.cs b/HeliosPlus.Reporting/Program.cs index fbdf7c0..1cf9cf2 100644 --- a/HeliosPlus.Reporting/Program.cs +++ b/HeliosPlus.Reporting/Program.cs @@ -208,7 +208,7 @@ namespace HeliosPlus.Reporting try { - Dump(ProfileItem.LoadAllProfiles(), "HeliosPlus.Shared.Profile.GetAllProfiles()", null, 99); + Dump(ProfileRepository.AllProfiles, "HeliosPlus.Shared.ProfileRepository.AllProfiles", null, 99); } catch (Exception e) { diff --git a/HeliosPlus.Shared/ProfileItem.cs b/HeliosPlus.Shared/ProfileItem.cs index da65bc6..6b76777 100644 --- a/HeliosPlus.Shared/ProfileItem.cs +++ b/HeliosPlus.Shared/ProfileItem.cs @@ -117,12 +117,12 @@ namespace HeliosPlus.Shared get { if (String.IsNullOrWhiteSpace(_uuid)) - _uuid = Guid.NewGuid().ToString("B"); + _uuid = Guid.NewGuid().ToString("D"); 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}\}"; + 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; @@ -137,8 +137,9 @@ namespace HeliosPlus.Shared IEnumerable currentDisplays = WindowsDisplayAPI.Display.GetDisplays(); foreach (Display availableDisplay in currentDisplays) { + Console.WriteLine($"DsiplayName: {availableDisplay.DisplayName}"); if (availableDisplay.IsAvailable) - Console.WriteLine(""); + Console.WriteLine($""); } // Find the list of TargetDisplays we currently have from the currentprofile diff --git a/HeliosPlus.Shared/ProfileRepository.cs b/HeliosPlus.Shared/ProfileRepository.cs index c1c28c3..3242643 100644 --- a/HeliosPlus.Shared/ProfileRepository.cs +++ b/HeliosPlus.Shared/ProfileRepository.cs @@ -39,8 +39,8 @@ namespace HeliosPlus.Shared public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus"); public static string AppIconPath = Path.Combine(AppDataPath, $"Icons"); public static string AppHeliosPlusIconFilename = Path.Combine(AppIconPath, @"HeliosPlus.ico"); - private static string _profileStorageJsonPath = Path.Combine(AppDataPath, $"Profiles"); - private static string _profileStorageJsonFileName = Path.Combine(_profileStorageJsonPath, $"DisplayProfiles_{Version.ToString(2)}.json"); + private static string AppProfileStoragePath = Path.Combine(AppDataPath, $"Profiles"); + private static string _profileStorageJsonFileName = Path.Combine(AppProfileStoragePath, $"DisplayProfiles_{Version.ToString(2)}.json"); private static uint _lastProfileId; private static ProfileItem _currentProfile; private static List _availableDisplays; @@ -56,6 +56,12 @@ namespace HeliosPlus.Shared try { NvAPIWrapper.NVIDIA.Initialize(); + + // Create the Profile Storage Path if it doesn't exist so that it's avilable for all the program + if (!Directory.Exists(AppProfileStoragePath)) + { + Directory.CreateDirectory(AppProfileStoragePath); + } } catch (Exception ex) { @@ -480,16 +486,16 @@ namespace HeliosPlus.Shared public static bool SaveProfiles() { - if (!Directory.Exists(_profileStorageJsonPath)) + if (!Directory.Exists(AppProfileStoragePath)) { try { - Directory.CreateDirectory(_profileStorageJsonPath); + Directory.CreateDirectory(AppProfileStoragePath); } catch (Exception ex) { Console.WriteLine($"ProfileRepository/SaveProfiles exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); - Console.WriteLine($"Unable to create Profile folder {_profileStorageJsonPath}: " + ex.Message); + Console.WriteLine($"Unable to create Profile folder {AppProfileStoragePath}: " + ex.Message); } } @@ -524,7 +530,7 @@ namespace HeliosPlus.Shared { // Work out the name of the Profile we'll save. - profile.SavedProfileIconCacheFilename = Path.Combine(_profileStorageJsonPath, String.Concat(@"profile-", profile.UUID, @".ico")); + profile.SavedProfileIconCacheFilename = Path.Combine(AppProfileStoragePath, String.Concat(@"profile-", profile.UUID, @".ico")); MultiIcon ProfileIcon; try diff --git a/HeliosPlus/Program.cs b/HeliosPlus/Program.cs index b881fb3..fa0268f 100644 --- a/HeliosPlus/Program.cs +++ b/HeliosPlus/Program.cs @@ -40,6 +40,8 @@ namespace HeliosPlus { internal static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus"); public static string AppIconPath = Path.Combine(Program.AppDataPath, $"Icons"); + public static string AppProfilePath = Path.Combine(Program.AppDataPath, $"Profiles"); + public static string AppShortcutPath = Path.Combine(Program.AppDataPath, $"Shortcuts"); public static string AppHeliosPlusIconFilename = Path.Combine(AppIconPath, @"HeliosPlus.ico"); public static string AppOriginIconFilename = Path.Combine(AppIconPath, @"Origin.ico"); public static string AppSteamIconFilename = Path.Combine(AppIconPath, @"Steam.ico"); @@ -169,6 +171,21 @@ namespace HeliosPlus { throw new Exception(Language.Can_not_open_a_named_pipe_for_Inter_process_communication); } + + // Create the Shortcut Icon Cache if it doesn't exist so that it's avilable for all the program + if (!Directory.Exists(AppIconPath)) + { + try + { + Directory.CreateDirectory(AppIconPath); + } + catch (Exception ex) + { + Console.WriteLine($"Program/StartUpNormally exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); + // TODO + } + } + // Create the Shortcut Icon Cache if it doesn't exist so that it's avilable for all the program if (!Directory.Exists(AppIconPath)) diff --git a/HeliosPlus/ShortcutItem.cs b/HeliosPlus/ShortcutItem.cs index 4979c9e..fdc70b4 100644 --- a/HeliosPlus/ShortcutItem.cs +++ b/HeliosPlus/ShortcutItem.cs @@ -74,12 +74,12 @@ namespace HeliosPlus get { if (String.IsNullOrWhiteSpace(_uuid)) - _uuid = Guid.NewGuid().ToString("B"); + _uuid = Guid.NewGuid().ToString("D"); 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}\}"; + 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; diff --git a/HeliosPlus/ShortcutRepository.cs b/HeliosPlus/ShortcutRepository.cs index 80d4401..d02813e 100644 --- a/HeliosPlus/ShortcutRepository.cs +++ b/HeliosPlus/ShortcutRepository.cs @@ -27,14 +27,32 @@ namespace HeliosPlus private static List _allShortcuts = new List(); private static bool _shortcutsLoaded = false; // Other constants that are useful - private static string _shortcutStorageJsonPath = Path.Combine(Program.AppDataPath, $"Shortcuts"); - private static string _shortcutStorageJsonFileName = Path.Combine(_shortcutStorageJsonPath, $"Shortcuts_{Version.ToString(2)}.json"); + private static string AppShortcutStoragePath = Path.Combine(Program.AppDataPath, $"Shortcuts"); + private static string _shortcutStorageJsonFileName = Path.Combine(AppShortcutStoragePath, $"Shortcuts_{Version.ToString(2)}.json"); private static string uuidV4Regex = @"(?im)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$"; #endregion #region Class Constructors static ShortcutRepository() { + + try + { + NvAPIWrapper.NVIDIA.Initialize(); + + // Create the Profile Storage Path if it doesn't exist so that it's avilable for all the program + if (!Directory.Exists(AppShortcutStoragePath)) + { + Directory.CreateDirectory(AppShortcutStoragePath); + } + } + catch (Exception ex) + { + Console.WriteLine($"ShortcutItem/Instansiation exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); + // ignored + } + + // Load the Shortcuts from storage LoadShortcuts(); } @@ -340,17 +358,17 @@ namespace HeliosPlus private static bool SaveShortcuts() { - if (!Directory.Exists(_shortcutStorageJsonPath)) + if (!Directory.Exists(AppShortcutStoragePath)) { try { - Directory.CreateDirectory(_shortcutStorageJsonPath); + Directory.CreateDirectory(AppShortcutStoragePath); } catch (Exception ex) { Console.WriteLine($"ShortcutRepository/SaveShortcuts exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); - Console.WriteLine($"Unable to create Shortcut folder {_shortcutStorageJsonPath}: " + ex.Message); + Console.WriteLine($"Unable to create Shortcut folder {AppShortcutStoragePath}: " + ex.Message); } } @@ -392,7 +410,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-", shortcut.ProfileToUse.UUID, "-", Path.GetFileNameWithoutExtension(shortcut.ExecutableNameAndPath), @".ico")); + shortcut.SavedShortcutIconCacheFilename = Path.Combine(AppShortcutStoragePath, 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 @@ -404,13 +422,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-", shortcut.ProfileToUse.UUID, "-", shortcut.GameAppId.ToString(), @".ico")); + shortcut.SavedShortcutIconCacheFilename = Path.Combine(AppShortcutStoragePath, 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-", shortcut.ProfileToUse.UUID, "-", shortcut.GameAppId.ToString(), @".ico")); + shortcut.SavedShortcutIconCacheFilename = Path.Combine(AppShortcutStoragePath, String.Concat(@"uplay-", shortcut.ProfileToUse.UUID, "-", shortcut.GameAppId.ToString(), @".ico")); } } @@ -420,7 +438,7 @@ namespace HeliosPlus else { // Work out the name of the shortcut we'll save. - shortcut.SavedShortcutIconCacheFilename = Path.Combine(_shortcutStorageJsonPath, String.Concat(@"permanent-", shortcut.ProfileToUse.UUID, @".ico")); + shortcut.SavedShortcutIconCacheFilename = Path.Combine(AppShortcutStoragePath, String.Concat(@"permanent-", shortcut.ProfileToUse.UUID, @".ico")); } MultiIcon shortcutIcon;