Skip to content

Commit

Permalink
Auto replace if vanity urls are used (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdanish-kh authored Sep 13, 2023
1 parent a71c11d commit 769665c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/WingetCreateCLI/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -638,6 +652,27 @@ private static void DisplayManifestsAsMenuSelection(Manifests manifests)
}
}

private static bool AreInstallerUrlsVanityUrls(Manifests baseManifest, Manifests newManifest)
{
List<Installer> 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);
Expand Down
9 changes: 9 additions & 0 deletions src/WingetCreateCLI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/WingetCreateCLI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1118,4 +1118,7 @@
<data name="UseOverrides_ErrorMessage" xml:space="preserve">
<value>Try using the architecture and/or scope overrides to uniquely match new URLs to existing installer nodes in the manifest.</value>
</data>
<data name="AutoReplacingPreviousVersion_Message" xml:space="preserve">
<value>Vanity URL detected. The submission will automatically replace the previous version.</value>
</data>
</root>

0 comments on commit 769665c

Please sign in to comment.