Removed braces from UUID in filenames

Simplified UUID logic by removing braces from the
filenames and within the storage JSON files.
This commit is contained in:
Terry MacDonald
2020-08-19 10:16:04 +12:00
parent b95e7bbd39
commit 32ad405904
6 changed files with 63 additions and 21 deletions

View File

@ -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)
{

View File

@ -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<Display> 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

View File

@ -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<Display> _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

View File

@ -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");
@ -170,6 +172,21 @@ namespace HeliosPlus {
}
// 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))
{

View File

@ -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;

View File

@ -27,14 +27,32 @@ namespace HeliosPlus
private static List<ShortcutItem> _allShortcuts = new List<ShortcutItem>();
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;