mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
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:
parent
63df55fa79
commit
c52950c9b5
@ -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;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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))
|
||||||
|
Loading…
Reference in New Issue
Block a user