Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for creating and updating portable manifests #290

Merged
merged 9 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions src/WingetCreateCLI/Commands/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,17 @@ private static void PromptInstallerProperties<T>(T manifest, PropertyInfo proper

bool prompted = false;

// If we know the installertype is EXE, prompt the user for installer switches (silent and silentwithprogress)
// If the installerType is EXE, prompt the user for whether the package is a portable
if (installer.InstallerType == InstallerType.Exe)
{
Console.WriteLine();
Logger.DebugLocalized(nameof(Resources.AdditionalMetadataNeeded_Message), installer.InstallerUrl);
prompted = true;
PromptInstallerSwitchesForExe(manifest);
if (!PromptForPortableExe(installer))
{
// If we know the installertype is EXE, prompt the user for installer switches (silent and silentwithprogress)
Logger.DebugLocalized(nameof(Resources.AdditionalMetadataNeeded_Message), installer.InstallerUrl);
prompted = true;
PromptInstallerSwitchesForExe(installer);
}
}

foreach (var requiredProperty in requiredInstallerProperties)
Expand All @@ -326,7 +330,7 @@ private static void PromptInstallerProperties<T>(T manifest, PropertyInfo proper
}
}

private static void PromptInstallerSwitchesForExe<T>(T manifest)
private static void PromptInstallerSwitchesForExe<T>(T manifestInstaller)
{
InstallerSwitches installerSwitches = new InstallerSwitches();

Expand All @@ -335,7 +339,35 @@ private static void PromptInstallerSwitchesForExe<T>(T manifest)

if (!string.IsNullOrEmpty(installerSwitches.Silent) || !string.IsNullOrEmpty(installerSwitches.SilentWithProgress))
{
manifest.GetType().GetProperty(nameof(InstallerSwitches)).SetValue(manifest, installerSwitches);
manifestInstaller.GetType().GetProperty(nameof(InstallerSwitches)).SetValue(manifestInstaller, installerSwitches);
}
}

/// <summary>
/// Prompts the user to confirm whether the package is a portable.
/// If true, then prompts for related portable metadata.
/// </summary>
/// <typeparam name="T">Manifest installer.</typeparam>
/// <param name="manifestInstaller">Manifest installer object model.</param>
/// <returns>Boolean value indicating whether the package is a portable.</returns>
private static bool PromptForPortableExe<T>(T manifestInstaller)
{
if (Prompt.Confirm(Resources.ConfirmPortablePackage_Message))
{
manifestInstaller.GetType().GetProperty(nameof(Installer.InstallerType)).SetValue(manifestInstaller, InstallerType.Portable);
string portableCommandAlias = Prompt.Input<string>(Resources.PortableCommandAlias_Message);

if (!string.IsNullOrEmpty(portableCommandAlias))
{
List<string> portableCommands = new List<string> { portableCommandAlias };
manifestInstaller.GetType().GetProperty(nameof(Installer.Commands)).SetValue(manifestInstaller, portableCommands);
}

return true;
}
else
{
return false;
}
}

Expand Down
18 changes: 18 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.

15 changes: 11 additions & 4 deletions src/WingetCreateCLI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
</data>
<data name="GitHubFailedAuthorization_Message" xml:space="preserve">
<value>GitHub authorization failed: {0} - {1}</value>
<comment>{0} - will be replaced with error code
<comment>{0} - will be replaced with error code
{1} - will be replaced with error description</comment>
</data>
<data name="GitHubLoginFail_Error" xml:space="preserve">
Expand Down Expand Up @@ -679,14 +679,14 @@
<data name="MultipleMatchedInstaller_Error" xml:space="preserve">
<value>Multiple matches found for {0} {1} installer detected from the url: {2}</value>
<comment>{0} - will be replaced with installer architecture

{1} - will be replaced with the installer type

{2} - will be replaced with the installer</comment>
</data>
<data name="UnmatchedInstaller_Error" xml:space="preserve">
<value>No matches found for {0} {1} installer detected from url: {2}</value>
<comment>{0} - will be replaced with installer architecture
<comment>{0} - will be replaced with installer architecture

{1} - will be replaced with the installer type
{2} - will be replaced with the installer</comment>
Expand Down Expand Up @@ -915,6 +915,13 @@
<value>List of winget arguments the installer does not support</value>
<comment>"winget" is the proper name of the tool</comment>
</data>
<data name="ConfirmPortablePackage_Message" xml:space="preserve">
<value>Is this a portable package?</value>
</data>
<data name="PortableCommandAlias_Message" xml:space="preserve">
<value>What is the command alias of the portable package |e.g. nuget|</value>
<comment>`command alias` refers to the name of the exe file that will be used when running the application from the command line.</comment>
</data>
<data name="SyncForkWithUpstream_Message" xml:space="preserve">
<value>Unable to create a reference to the forked repository. This can be caused when the forked repository is behind by too many commits. Sync your fork and try again.</value>
</data>
Expand Down
12 changes: 8 additions & 4 deletions src/WingetCreateCore/Common/PackageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace Microsoft.WingetCreateCore
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
Expand Down Expand Up @@ -615,14 +615,18 @@ private static CompatibilitySet GetCompatibilitySet(InstallerType type)
case InstallerType.Inno:
case InstallerType.Nullsoft:
case InstallerType.Exe:
case InstallerType.Burn:
case InstallerType.Burn:
// Portable is included as a compatible installer type since
// they are detected as 'exe' installers. This is to ensure
// updating a portable manifest is supported.
case InstallerType.Portable:
return CompatibilitySet.Exe;
case InstallerType.Wix:
case InstallerType.Msi:
return CompatibilitySet.Msi;
case InstallerType.Msix:
case InstallerType.Appx:
return CompatibilitySet.Msix;
return CompatibilitySet.Msix;
default:
return CompatibilitySet.None;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public void Setup()
/// <returns>A <see cref="Task"/> representing the asynchronous test.</returns>
[TestCase(TestConstants.TestExePackageIdentifier, TestConstants.TestExeManifest, TestConstants.TestExeInstaller)]
[TestCase(TestConstants.TestMsiPackageIdentifier, TestConstants.TestMsiManifest, TestConstants.TestMsiInstaller)]
[TestCase(TestConstants.TestMultifileMsixPackageIdentifier, TestConstants.TestMultifileMsixManifestDir, TestConstants.TestMsixInstaller)]
[TestCase(TestConstants.TestMultifileMsixPackageIdentifier, TestConstants.TestMultifileMsixManifestDir, TestConstants.TestMsixInstaller)]
[TestCase(TestConstants.TestPortablePackageIdentifier, TestConstants.TestPortableManifest, TestConstants.TestExeInstaller)]
public async Task SubmitAndUpdateInstaller(string packageId, string manifestName, string installerName)
{
await this.RunSubmitAndUpdateFlow(packageId, TestUtils.GetTestFile(manifestName), installerName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PackageIdentifier: TestPublisher.Portable
PackageVersion: 0.1.2
PackageName: Test portable app
Publisher: Test publisher
License: MIT
ShortDescription: A manifest used for testing a portable package.
Installers:
- Architecture: x64
InstallerType: portable
InstallerUrl: https://fakedomain.com/WingetCreateTestExeInstaller.exe
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
Commands:
- portableCommand
PackageLocale: en-US
ManifestType: singleton
ManifestVersion: 1.2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
PackageIdentifier: WingetCreateE2E.PortableTest
PackageName: PortableTest
PackageVersion: 1.2.3.4
Publisher: WingetCreateE2E
Author: Microsoft
License: MIT
LicenseUrl: https://github.com/microsoft/winget-create
MinimumOSVersion: 10.0.0.0
ShortDescription: Testing WingetCreate with a portable exe
PackageLocale: en-US
Tags:
- Windows Package Manager
- winget create
- package manager
- utility
- tool
- test
InstallerType: portable
Installers:
- Architecture: x64
InstallerUrl: https://fakedomain.com/WingetCreateTestExeInstaller.exe
InstallerSha256: A7803233EEDB6A4B59B3024CCF9292A6FFFB94507DC998AA67C5B745D197A5DC
Commands:
- portableCommand
ManifestType: singleton
ManifestVersion: 1.2.0
10 changes: 10 additions & 0 deletions src/WingetCreateTests/WingetCreateTests/TestConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public static class TestConstants
/// </summary>
public const string TestMultifileMsixPackageIdentifier = "Multifile.MsixTest";

/// <summary>
/// PackageIdentifier for test portable.
/// </summary>
public const string TestPortablePackageIdentifier = "WingetCreateE2E.PortableTest";

/// <summary>
/// File name of the test exe manifest.
/// </summary>
Expand All @@ -63,6 +68,11 @@ public static class TestConstants
/// </summary>
public const string TestMsiManifest = "WingetCreateE2E.MsiTest.yaml";

/// <summary>
/// File name of the test portable manifest.
/// </summary>
public const string TestPortableManifest = "WingetCreateE2E.PortableTest.yaml";

/// <summary>
/// Path of the directory with the multifile msix test manifests.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.WingetCreateUnitTests
using Microsoft.WingetCreateCore;
using Microsoft.WingetCreateCore.Models.Singleton;
using NUnit.Framework;

/// <summary>
/// Unit tests for verifying unicode text and directionality.
/// </summary>
Expand Down Expand Up @@ -76,11 +76,9 @@ public void VerfiyNewLineSupport()

// we know when written that \r\n and \x85 characters are replaced with \n.
var writtenFixed = string.Join('\n', written.Description.Split(new string[] { "\n", "\r\n", "\x85" }, StringSplitOptions.None));

Assert.AreEqual(writtenFixed, read.Description, $"String {read.Description} had the wrong number of newlines :(.");
File.Delete(testManifestFilePath);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,25 @@ public async Task UpdateResetsVersionSpecificFields()
Assert.IsNull(updatedDefaultLocaleManifest.ReleaseNotesUrl, "ReleaseNotesUrl should be null.");
}

/// <summary>
/// Ensures that updating a portable package preserves the portable installerType.
/// </summary>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
[Test]
public async Task UpdatePortable()
{
TestUtils.InitializeMockDownloads(TestConstants.TestExeInstaller);
(UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData("TestPublisher.Portable", null, this.tempPath, null);
var updatedManifests = await RunUpdateCommand(command, initialManifestContent);
Assert.IsNotNull(updatedManifests, "Command should have succeeded");

InstallerManifest updatedInstallerManifest = updatedManifests.InstallerManifest;
var updatedInstaller = updatedInstallerManifest.Installers.First();

Assert.IsTrue(updatedInstaller.InstallerType == InstallerType.Portable, "InstallerType should be portable");
Assert.IsTrue(updatedInstaller.Commands[0] == "portableCommand", "Command value should be preserved.");
}

private static (UpdateCommand UpdateCommand, List<string> InitialManifestContent) GetUpdateCommandAndManifestData(string id, string version, string outputDir, IEnumerable<string> installerUrls)
{
var updateCommand = new UpdateCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<None Update="Resources\Multifile.MsixTest\Multifile.MsixTest.locale.en-US.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\TestPublisher.Portable.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\TestPublisher.FullSingleton1_2.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -78,6 +81,9 @@
<None Update="Resources\Multifile.MsixTest\Multifile.MsixTest.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\WingetCreateE2E.PortableTest.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\WingetCreateTestExeInstaller.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down