diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs index da0377a2..a9961457 100644 --- a/src/WingetCreateCLI/Commands/UpdateCommand.cs +++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs @@ -239,6 +239,20 @@ await this.UpdateManifestsInteractively(initialManifests) : return false; } + if (!this.Replace) + { + // Updated manifests will always be in multi-manifest format so no need to check for singleton manifest. + string updatedVersion = updatedManifests.VersionManifest.PackageVersion; + string originalVersion = originalManifests.VersionManifest != null ? originalManifests.VersionManifest.PackageVersion : originalManifests.SingletonManifest.PackageVersion; + + if (WinGetUtil.CompareVersions(updatedVersion, originalVersion) != 0 && AreInstallerUrlsVanityUrls(originalManifests, updatedManifests)) + { + Logger.InfoLocalized(nameof(Resources.AutoReplacingPreviousVersion_Message)); + Console.WriteLine(); + this.Replace = true; + } + } + return await this.LoadGitHubClient(true) ? (commandEvent.IsSuccessful = await this.GitHubSubmitManifests( updatedManifests, @@ -638,6 +652,27 @@ private static void DisplayManifestsAsMenuSelection(Manifests manifests) } } + private static bool AreInstallerUrlsVanityUrls(Manifests baseManifest, Manifests newManifest) + { + List newInstallers = newManifest.InstallerManifest.Installers; + + // All installer URLs in the new manifest must have a matching installer URL in the base manifest. + foreach (Installer installer in newInstallers) + { + if (baseManifest.InstallerManifest != null && !baseManifest.InstallerManifest.Installers.Any(i => i.InstallerUrl == installer.InstallerUrl)) + { + return false; + } + + if (baseManifest.SingletonManifest != null && !baseManifest.SingletonManifest.Installers.Any(i => i.InstallerUrl == installer.InstallerUrl)) + { + return false; + } + } + + return true; + } + private string ObtainMatchingRelativeFilePath(string oldRelativeFilePath, string directory, string archiveName) { string fileName = Path.GetFileName(oldRelativeFilePath); diff --git a/src/WingetCreateCLI/Properties/Resources.Designer.cs b/src/WingetCreateCLI/Properties/Resources.Designer.cs index 4e7edc46..f64b9da0 100644 --- a/src/WingetCreateCLI/Properties/Resources.Designer.cs +++ b/src/WingetCreateCLI/Properties/Resources.Designer.cs @@ -222,6 +222,15 @@ public static string Author_KeywordDescription { } } + /// + /// Looks up a localized string similar to Vanity URL detected. The submission will automatically replace the previous version.. + /// + public static string AutoReplacingPreviousVersion_Message { + get { + return ResourceManager.GetString("AutoReplacingPreviousVersion_Message", resourceCulture); + } + } + /// /// Looks up a localized string similar to BACK. /// diff --git a/src/WingetCreateCLI/Properties/Resources.resx b/src/WingetCreateCLI/Properties/Resources.resx index b923f1fc..0631b7fe 100644 --- a/src/WingetCreateCLI/Properties/Resources.resx +++ b/src/WingetCreateCLI/Properties/Resources.resx @@ -1118,4 +1118,7 @@ Try using the architecture and/or scope overrides to uniquely match new URLs to existing installer nodes in the manifest. + + Vanity URL detected. The submission will automatically replace the previous version. + \ No newline at end of file