From b37cc03a32fc5246437d9c2c0ca32b4996587a69 Mon Sep 17 00:00:00 2001 From: Muhammad Danish Date: Tue, 12 Sep 2023 21:29:27 +0500 Subject: [PATCH 1/2] Auto replace if vanity urls are used --- src/WingetCreateCLI/Commands/UpdateCommand.cs | 34 +++++++++++++++++++ .../Properties/Resources.Designer.cs | 9 +++++ src/WingetCreateCLI/Properties/Resources.resx | 3 ++ 3 files changed, 46 insertions(+) diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs index da0377a2..d03a48b0 100644 --- a/src/WingetCreateCLI/Commands/UpdateCommand.cs +++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs @@ -239,6 +239,19 @@ await this.UpdateManifestsInteractively(initialManifests) : return false; } + if (!this.Replace) + { + 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 +651,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 match 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 From 76c7e053c6fc446d48224dedb5f9af12e870b338 Mon Sep 17 00:00:00 2001 From: Muhammad Danish Date: Wed, 13 Sep 2023 20:33:02 +0500 Subject: [PATCH 2/2] comments --- src/WingetCreateCLI/Commands/UpdateCommand.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs index d03a48b0..a9961457 100644 --- a/src/WingetCreateCLI/Commands/UpdateCommand.cs +++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs @@ -241,6 +241,7 @@ await this.UpdateManifestsInteractively(initialManifests) : 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; @@ -655,7 +656,7 @@ private static bool AreInstallerUrlsVanityUrls(Manifests baseManifest, Manifests { List newInstallers = newManifest.InstallerManifest.Installers; - // All installer URLs in the new manifest must match the base manifest. + // 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))