Fixed ChangeProfile command line

ChangeProfile command wasn't working, but
now that you can use the Desktop Background
context menu to change profiles I needed to
fix this so that the menu runs this command.
This commit is contained in:
Terry MacDonald 2020-11-22 21:27:29 +13:00
parent 63df55fa79
commit c52950c9b5
3 changed files with 23 additions and 15 deletions

View File

@ -30,6 +30,7 @@ namespace HeliosPlus.Shared
private static List<WindowsDisplayAPI.UnAttachedDisplay> _unavailableDisplays; private static List<WindowsDisplayAPI.UnAttachedDisplay> _unavailableDisplays;
internal static string AppDataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus"); internal static string AppDataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus");
private static string uuidV4Regex = @"(?im)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$";
private string _uuid = ""; private string _uuid = "";
private Version _version; private Version _version;
@ -125,7 +126,6 @@ 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}";
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;
@ -272,7 +272,6 @@ namespace HeliosPlus.Shared
public static bool IsValidUUID(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); Match match = Regex.Match(testId, uuidV4Regex, RegexOptions.IgnoreCase);
if (match.Success) if (match.Success)
return true; return true;

View File

@ -103,20 +103,29 @@ namespace HeliosPlus {
}); });
}); });
// This is the ApplyProfile command // This is the ChangeProfile command
app.Command(HeliosStartupAction.ChangeProfile.ToString(), (runShortcutCmd) => app.Command(HeliosStartupAction.ChangeProfile.ToString(), (runProfileCmd) =>
{ {
var argumentShortcut = runShortcutCmd.Argument("\"SHORTCUT_UUID\"", "(required) The UUID of the shortcut to run from those stored in the shortcut library.").IsRequired(); var argumentProfile = runProfileCmd.Argument("\"Profile_UUID\"", "(required) The UUID of the profile to run from those stored in the profile file.").IsRequired();
argumentShortcut.Validators.Add(new ShortcutMustExistValidator()); argumentProfile.Validators.Add(new ProfileMustExistValidator());
//description and help text of the command. //description and help text of the command.
runShortcutCmd.Description = "Use this command to run favourite game or application with a display profile of your choosing."; runProfileCmd.Description = "Use this command to change to a display profile of your choosing.";
runShortcutCmd.OnExecute(() => runProfileCmd.OnExecute(() =>
{ {
// try
RunShortcut(argumentShortcut.Value); {
return 0; // Lookup the profile
ProfileItem profileToUse = ProfileRepository.AllProfiles.Where(p => p.UUID.Equals(argumentProfile.Value)).First();
ApplyProfile(profileToUse);
return 0;
}
catch (Exception)
{
return 1;
}
}); });
}); });

View File

@ -14,13 +14,13 @@ using System.ServiceModel.Dispatcher;
namespace HeliosPlus namespace HeliosPlus
{ {
class ProfileMustExistValidator : IOptionValidator class ProfileMustExistValidator : IArgumentValidator
{ {
public ValidationResult GetValidationResult(CommandOption optionProfile, ValidationContext context) public ValidationResult GetValidationResult(CommandArgument argumentProfileName, ValidationContext context)
{ {
// This validator only runs if there is a value // This validator only runs if there is a value
if (!optionProfile.HasValue()) return ValidationResult.Success; if (argumentProfileName.Value == "") return ValidationResult.Success;
var profileName = (string) optionProfile.Value(); var profileName = (string)argumentProfileName.Value;
// Try to find the Profile Name // Try to find the Profile Name
if (!ProfileRepository.ContainsProfile(profileName)) if (!ProfileRepository.ContainsProfile(profileName))