protected override async Task <int> Validate()
        {
            var baseResult = await base.Validate().ConfigureAwait(false);

            if (baseResult != StandardExitCodes.ErrorSuccess)
            {
                return(baseResult);
            }

            if (this.Verb.Name == null && this.Verb.ProcessorArchitecture == null && this.Verb.Publisher == null && this.Verb.Version == null && this.Verb.ResourceId == null)
            {
                await this.Console.WriteError("At least one property to change is required.").ConfigureAwait(false);

                return(StandardExitCodes.ErrorParameter);
            }

            if (this.Verb.Publisher != null)
            {
                var error = AppxValidatorFactory.ValidateSubject()(this.Verb.Publisher);
                if (error != null)
                {
                    if (this.Verb.Publisher.Contains('='))
                    {
                        await this.Console.WriteError("The format of the publisher is invalid. " + error).ConfigureAwait(false);
                    }
                    else
                    {
                        await this.Console.WriteError($"The format of the publisher is invalid. {error}\r\nDid you mean CN={this.Verb.Publisher}?").ConfigureAwait(false);
                    }

                    return(StandardExitCodes.ErrorFormat);
                }
            }

            if (this.Verb.Name != null)
            {
                var error = AppxValidatorFactory.ValidatePackageName()(this.Verb.Name);
                if (error != null)
                {
                    await this.Console.WriteError("The format of the package name is invalid. " + error).ConfigureAwait(false);

                    return(StandardExitCodes.ErrorFormat);
                }
            }

            if (this.Verb.ResourceId != null)
            {
                var error = AppxValidatorFactory.ValidateResourceId()(this.Verb.ResourceId);
                if (error != null)
                {
                    await this.Console.WriteError("The format of the resource ID is invalid. " + error).ConfigureAwait(false);

                    return(StandardExitCodes.ErrorFormat);
                }
            }

            return(StandardExitCodes.ErrorSuccess);
        }
Beispiel #2
0
        public PackageSelectorViewModel(IInteractionService interactionService, PackageSelectorDisplayMode displayMode)
        {
            this.displayMode      = displayMode;
            this.Publisher        = new ValidatedChangeableProperty <string>("Publisher name", AppxValidatorFactory.ValidateSubject());
            this.DisplayPublisher = new ValidatedChangeableProperty <string>("Publisher display name", ValidatorFactory.ValidateNotEmptyField());
            this.Name             = new ValidatedChangeableProperty <string>("Package name", AppxValidatorFactory.ValidatePackageName());
            this.DisplayName      = new ValidatedChangeableProperty <string>("Package display name", ValidatorFactory.ValidateNotEmptyField());
            this.Version          = new ValidatedChangeableProperty <string>("Version", AppxValidatorFactory.ValidateVersion());
            this.Architecture     = new ChangeableProperty <AppxPackageArchitecture>(AppxPackageArchitecture.Neutral);
            this.PackageType      = new ChangeableProperty <PackageType>();

            this.Publisher.DisplayName        = "Publisher name";
            this.DisplayPublisher.DisplayName = "Publisher display name";
            this.Name.DisplayName             = "Package name";
            this.DisplayName.DisplayName      = "Package display name";
            this.Version.DisplayName          = "Package version";
            this.InputPath = new ChangeableFileProperty("Package path", interactionService, ChangeableFileProperty.ValidatePath);

            this.PackageType.ValueChanged += this.PackageTypeOnValueChanged;
            this.showPackageTypeSelector   = displayMode.HasFlag(PackageSelectorDisplayMode.ShowTypeSelector);

            this.displayMode = displayMode;
            this.SetInputFilter();

            this.InputPath.ValueChanged += this.InputPathOnValueChanged;

            if (displayMode.HasFlag(PackageSelectorDisplayMode.ShowActualName))
            {
                this.ShowActualNames = true;
                this.AddChildren(this.Name, this.Publisher);
            }

            if (displayMode.HasFlag(PackageSelectorDisplayMode.ShowDisplayName))
            {
                this.ShowDisplayNames = true;
                this.AddChildren(this.DisplayName, this.DisplayPublisher);
            }

            this.allowChangingSourcePackage = displayMode.HasFlag(PackageSelectorDisplayMode.AllowChanging);
            this.AllowBrowsing = displayMode.HasFlag(PackageSelectorDisplayMode.AllowBrowsing);

            if (displayMode.HasFlag(PackageSelectorDisplayMode.RequireFullIdentity))
            {
                this.RequireFullIdentity = true;
                this.RequireArchitecture = true;
                this.RequireVersion      = true;
                this.AddChildren(this.Version, this.Architecture);
            }
            else if (displayMode.HasFlag(PackageSelectorDisplayMode.RequireArchitecture))
            {
                this.RequireFullIdentity = true;
                this.RequireArchitecture = true;
                this.AddChildren(this.Architecture);
            }
            else if (displayMode.HasFlag(PackageSelectorDisplayMode.RequireVersion))
            {
                this.RequireFullIdentity = true;
                this.RequireVersion      = true;
                this.AddChildren(this.Version);
            }

            this.AddChildren(this.PackageType);
        }
        public override Task Execute(SetPackageIdentity command, CancellationToken cancellationToken = default)
        {
            var(_, rootNamespace) = this.EnsureNamespace(Namespaces.Root);
            var identityFullName = rootNamespace + "Identity";


            // ReSharper disable once PossibleNullReferenceException
            var identity = this.Manifest.Root.Element(identityFullName);

            if (identity == null)
            {
                identity = new XElement(rootNamespace + "Identity");
                // ReSharper disable once PossibleNullReferenceException
                this.Manifest.Root.Add(identity);
            }

            if (command.Publisher != null)
            {
                var validationError = AppxValidatorFactory.ValidateSubject()(command.Publisher);
                if (validationError != null)
                {
                    throw new ArgumentException(validationError, nameof(command));
                }

                var attr = identity.Attribute("Publisher");
                if (attr == null)
                {
                    Logger.Info($"Setting attribute 'Publisher' to '{command.Publisher}'...");
                    attr = new XAttribute("Publisher", command.Publisher);
                    identity.Add(attr);
                    this.ValueChanged?.Invoke(this, new CommandValueChanged("Publisher", command.Publisher));
                }
                else
                {
                    Logger.Info($"Changing attribute 'Publisher' from '{attr.Value}' to '{command.Publisher}'...");
                    this.ValueChanged?.Invoke(this, new CommandValueChanged("Publisher", attr.Value, command.Publisher));
                    attr.Value = command.Publisher;
                }
            }

            if (command.Name != null)
            {
                var validationError = AppxValidatorFactory.ValidatePackageName()(command.Name);
                if (validationError != null)
                {
                    throw new ArgumentException(validationError, nameof(command));
                }

                var attr = identity.Attribute("Name");
                if (attr == null)
                {
                    Logger.Info($"Setting attribute 'Name' to '{command.Name}'...");
                    this.ValueChanged?.Invoke(this, new CommandValueChanged("Name", command.Name));
                    attr = new XAttribute("Name", command.Name);
                    identity.Add(attr);
                }
                else
                {
                    Logger.Info($"Changing attribute 'Name' from '{attr.Value}' to '{command.Name}'...");
                    this.ValueChanged?.Invoke(this, new CommandValueChanged("Name", attr.Value, command.Name));
                    attr.Value = command.Name;
                }
            }

            if (command.Version != null)
            {
                var attr = identity.Attribute("Version");
                if (attr == null)
                {
                    var newVersion      = VersionStringOperations.ResolveMaskedVersion(command.Version);
                    var validationError = AppxValidatorFactory.ValidateVersion()(newVersion);
                    if (validationError != null)
                    {
                        throw new ArgumentException(validationError, nameof(command));
                    }

                    Logger.Info($"Setting attribute 'Version' to '{newVersion}'...");
                    attr = new XAttribute("Version", newVersion);
                    identity.Add(attr);
                }
                else
                {
                    var newVersion = VersionStringOperations.ResolveMaskedVersion(command.Version, attr.Value);

                    var validationError = AppxValidatorFactory.ValidateVersion()(newVersion);
                    if (validationError != null)
                    {
                        throw new ArgumentException(validationError, nameof(command));
                    }

                    Logger.Info($"Changing attribute 'Version' from '{attr.Value}' to '{newVersion}'...");
                    this.ValueChanged?.Invoke(this, new CommandValueChanged("Version", attr.Value, newVersion));
                    attr.Value = newVersion;
                }
            }

            if (command.ProcessorArchitecture != null)
            {
                var attr = identity.Attribute("ProcessorArchitecture");
                if (attr == null)
                {
                    Logger.Info($"Setting attribute 'ProcessorArchitecture' to '{command.ProcessorArchitecture}'...");
                    this.ValueChanged?.Invoke(this, new CommandValueChanged("ProcessorArchitecture", command.ProcessorArchitecture));
                    attr = new XAttribute("ProcessorArchitecture", command.ProcessorArchitecture);
                    identity.Add(attr);
                }
                else
                {
                    Logger.Info($"Changing attribute 'ProcessorArchitecture' from '{attr.Value}' to '{command.ProcessorArchitecture}'...");
                    this.ValueChanged?.Invoke(this, new CommandValueChanged("ProcessorArchitecture", attr.Value, command.ProcessorArchitecture));
                    attr.Value = command.ProcessorArchitecture;
                }
            }

            if (command.ResourceId != null)
            {
                var validationError = AppxValidatorFactory.ValidateResourceId()(command.ResourceId);
                if (validationError != null)
                {
                    throw new ArgumentException(validationError, nameof(command));
                }

                var attr = identity.Attribute("ResourceId");
                if (attr == null)
                {
                    Logger.Info($"Setting attribute 'ResourceId' to '{command.ResourceId}'...");
                    this.ValueChanged?.Invoke(this, new CommandValueChanged("ResourceId", command.ResourceId));
                    attr = new XAttribute("ResourceId", command.ResourceId);
                    identity.Add(attr);
                }
                else
                {
                    Logger.Info($"Changing attribute 'ResourceId' from '{attr.Value}' to '{command.ResourceId}'...");
                    this.ValueChanged?.Invoke(this, new CommandValueChanged("ResourceId", attr.Value, command.ResourceId));
                    attr.Value = command.ResourceId;
                }
            }

            return(Task.CompletedTask);
        }
        private void InitializeTabParentPackage()
        {
            this.SourcePath = new ChangeableFileProperty("Parent package path", this.interactionService, ChangeableFileProperty.ValidatePathAndPresence)
            {
                // ReSharper disable once StringLiteralTypo
                Filter      = new DialogFilterBuilder("*" + FileConstants.MsixExtension, "*" + FileConstants.AppxExtension, FileConstants.AppxManifestFile).BuildFilter(),
                IsValidated = true
            };

            this.PackageSourceMode = new ChangeableProperty <PackageSourceMode>();
            this.ParentName        = new ValidatedChangeableProperty <string>("Parent package name", false, AppxValidatorFactory.ValidatePackageName());
            this.ParentPublisher   = new ValidatedChangeableProperty <string>("Parent publisher", false, AppxValidatorFactory.ValidateSubject());

            this.TabParentPackage = new ChangeableContainer(
                this.PackageSourceMode,
                this.ParentName,
                this.ParentPublisher,
                this.SourcePath);

            this.SourcePath.ValueChanged        += SourcePathOnValueChanged;
            this.PackageSourceMode.ValueChanged += this.PackageSourceModeChanged;
        }
        private void InitializeTabProperties()
        {
            this.DisplayName          = new ValidatedChangeableProperty <string>("Displayed name", ValidatorFactory.ValidateNotEmptyField());
            this.PublisherDisplayName = new ValidatedChangeableProperty <string>("Displayed publisher name", ValidatorFactory.ValidateNotEmptyField());
            this.Name          = new ValidatedChangeableProperty <string>("Package name", AppxValidatorFactory.ValidatePackageName());
            this.PublisherName = new ValidatedChangeableProperty <string>("Publisher name", AppxValidatorFactory.ValidateSubject());
            this.Version       = new ValidatedChangeableProperty <string>("Version", "1.0.0.0", AppxValidatorFactory.ValidateVersion());

            this.TabProperties = new ChangeableContainer(
                this.DisplayName,
                this.PublisherDisplayName,
                this.Name,
                this.PublisherName,
                this.Version);

            this.TabProperties.Commit();

            this.DisplayName.ValueChanged          += DisplayNameOnValueChanged;
            this.PublisherDisplayName.ValueChanged += PublisherDisplayNameOnValueChanged;
        }
Beispiel #6
0
 protected AppInstallerBasePackageViewModel(AppInstallerBaseEntry baseEntry)
 {
     this.Name      = new ValidatedChangeableProperty <string>("Package name", baseEntry.Name, AppxValidatorFactory.ValidatePackageName());
     this.Publisher = new ValidatedChangeableProperty <string>("Package publisher", baseEntry.Publisher, AppxValidatorFactory.ValidateSubject());
     this.Version   = new ValidatedChangeableProperty <string>("Package version", baseEntry.Version, AppxValidatorFactory.ValidateVersion());
     this.Uri       = new ValidatedChangeableProperty <string>("Package URI", baseEntry.Uri, ValidatorFactory.ValidateUri(true));
     this.AddChildren(this.Name, this.Publisher, this.Version, this.Uri);
 }
Beispiel #7
0
        public NewSelfSignedViewModel(
            ISelfElevationProxyProvider <ISigningManager> signingManagerFactory,
            IInteractionService interactionService,
            IConfigurationService configurationService) : base("New self signed certificate", interactionService)
        {
            this.signingManagerFactory = signingManagerFactory;

            this.OutputPath            = new ChangeableFolderProperty("Output path", interactionService, configurationService.GetCurrentConfiguration().Signing?.DefaultOutFolder);
            this.PublisherName         = new ValidatedChangeableProperty <string>("Publisher name", "CN=", AppxValidatorFactory.ValidateSubject());
            this.PublisherFriendlyName = new ValidatedChangeableProperty <string>("Publisher display name", ValidatePublisherFriendlyName);
            this.Password   = new ValidatedChangeableProperty <string>("Password", ValidatePassword);
            this.ValidUntil = new ValidatedChangeableProperty <DateTime>("Valid until", DateTime.Now.Add(TimeSpan.FromDays(365)), ValidateDateTime);
            this.AddChildren(this.PublisherFriendlyName, this.PublisherName, this.ValidUntil, this.Password, this.OutputPath);

            this.PublisherName.ValueChanged         += this.PublisherNameOnValueChanged;
            this.PublisherFriendlyName.ValueChanged += this.PublisherFriendlyNameOnValueChanged;

            this.RegisterForCommandLineGeneration(this.PublisherFriendlyName, this.PublisherName, this.ValidUntil, this.Password, this.OutputPath);
        }