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;
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 Version _version;
@ -125,7 +126,6 @@ namespace HeliosPlus.Shared
}
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);
if (match.Success)
_uuid = value;
@ -272,7 +272,6 @@ namespace HeliosPlus.Shared
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);
if (match.Success)
return true;

View File

@ -103,20 +103,29 @@ namespace HeliosPlus {
});
});
// This is the ApplyProfile command
app.Command(HeliosStartupAction.ChangeProfile.ToString(), (runShortcutCmd) =>
// This is the ChangeProfile command
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();
argumentShortcut.Validators.Add(new ShortcutMustExistValidator());
var argumentProfile = runProfileCmd.Argument("\"Profile_UUID\"", "(required) The UUID of the profile to run from those stored in the profile file.").IsRequired();
argumentProfile.Validators.Add(new ProfileMustExistValidator());
//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(() =>
{
//
RunShortcut(argumentShortcut.Value);
return 0;
try
{
// 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
{
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
if (!optionProfile.HasValue()) return ValidationResult.Success;
var profileName = (string) optionProfile.Value();
if (argumentProfileName.Value == "") return ValidationResult.Success;
var profileName = (string)argumentProfileName.Value;
// Try to find the Profile Name
if (!ProfileRepository.ContainsProfile(profileName))