From b4d8c969230e2ec8079dbb870523eacbf0925938 Mon Sep 17 00:00:00 2001 From: Ruben Guerrero Date: Wed, 10 Jan 2024 09:23:10 -0800 Subject: [PATCH] Update WinGetUtilInterop project (#4045) This PR fulfills my lifelong dream of updating the `WinGetUtilInterop` to include most of the APIs from `WinGetUtil`. Internally we have a project with all this code, so I just copy them here with some minor changes. Because of that, some of them are not included. The idea would be that any new APIs added into WinGetUtil should have their corresponding C# interop implementation in the same PR. APIs included: - WinGetLoggingInit - WinGetLoggingTerm - WinGetSQLiteIndexCreate - WinGetSQLiteIndexOpen - WinGetSQLiteIndexClose - WinGetSQLiteIndexAddManifest - WinGetSQLiteIndexUpdateManifest - WinGetSQLiteIndexRemoveManifest - WinGetSQLiteIndexPrepareForPackaging - WinGetSQLiteIndexCheckConsistency - WinGetCreateManifest - WinGetCloseManifest - WinGetValidateManifestV3 - WinGetDownload - WinGetCompareVersions - WinGetBeginInstallerMetadataCollection - WinGetCompleteInstallerMetadataCollection Missing ones: - WinGetValidateManifest - WinGetValidateManifestV2 - WinGetValidateManifestDependencies - WinGetMergeInstallerMetadata In that project we just have SQLite tests, so I port them too. I also added the same stylecops convention so you will see some header changes. --- azure-pipelines.yml | 13 +- src/AppInstallerCLI.sln | 31 +- src/WinGetSourceCreator/WinGetLocalSource.cs | 4 +- .../APIUnitTests/SQLiteIndexUnitTests.cs | 337 ++++++++++++ .../Common/DisplayTestMethodNameAttribute.cs | 6 +- .../ManifestEqualityUnitTests.cs | 6 +- .../ManifestUnitTest/V1ManifestReadTest.cs | 8 +- .../TestCollateral/PackageTest.yaml | 18 + .../TestCollateral/PackageTestNewName.yaml | 18 + .../TestCollateral/PackageTestNewVersion.yaml | 18 + .../WinGetUtilInterop.UnitTests.csproj | 22 + src/WinGetUtilInterop/Api/WinGetFactory.cs | 208 ++++++++ .../Api/WinGetInstallerMetadata.cs | 96 ++++ src/WinGetUtilInterop/Api/WinGetLogging.cs | 68 +++ src/WinGetUtilInterop/Api/WinGetManifest.cs | 110 ++++ .../WinGetSQLiteIndex.cs} | 478 ++++++++---------- src/WinGetUtilInterop/Api/WinGetUtilities.cs | 63 +++ src/WinGetUtilInterop/Common/Constants.cs | 19 + .../Common/CreateManifestResult.cs | 69 +++ src/WinGetUtilInterop/Common/Enums.cs | 197 ++++++++ .../Common/ManifestValidationResult.cs | 42 ++ .../Exceptions/WinGetDownloadException.cs | 51 ++ .../WinGetInstallerMetadataException.cs | 51 ++ .../Exceptions/WinGetLoggingException.cs | 51 ++ .../Exceptions/WinGetManifestException.cs | 51 ++ .../Exceptions/WinGetSQLiteIndexException.cs | 51 ++ .../Exceptions/WinGetUtilIndexException.cs | 48 -- .../Helpers/WinGetUtilWrapperManifest.cs | 77 --- .../Interfaces/IWinGetFactory.cs | 55 ++ .../Interfaces/IWinGetInstallerMetadata.cs | 22 + .../Interfaces/IWinGetLogging.cs | 17 + .../Interfaces/IWinGetManifest.cs | 29 ++ ...nGetUtilIndex.cs => IWinGetSQLiteIndex.cs} | 107 ++-- .../Interfaces/IWinGetUtilities.cs | 32 ++ .../Manifest/Preview/InstallerSwitches.cs | 7 +- .../Manifest/Preview/Manifest.cs | 6 +- .../Manifest/Preview/ManifestInstaller.cs | 6 +- .../Manifest/Preview/ManifestLocalization.cs | 6 +- .../Manifest/V1/InstallerArpEntry.cs | 6 +- .../Manifest/V1/InstallerDependency.cs | 6 +- .../V1/InstallerExpectedReturnCode.cs | 6 +- .../V1/InstallerInstallationMetadata.cs | 11 +- .../Manifest/V1/InstallerMarkets.cs | 6 +- .../V1/InstallerNestedInstallerFile.cs | 13 +- .../Manifest/V1/InstallerPackageDependency.cs | 8 +- .../Manifest/V1/InstallerSwitches.cs | 6 +- src/WinGetUtilInterop/Manifest/V1/Manifest.cs | 10 +- .../Manifest/V1/ManifestDocumentation.cs | 14 +- .../Manifest/V1/ManifestIcon.cs | 15 +- .../Manifest/V1/ManifestInstaller.cs | 11 +- .../Manifest/V1/ManifestInstallerFile.cs | 12 +- .../Manifest/V1/ManifestLocalization.cs | 6 +- .../Manifest/V1/MinManifestInfo.cs | 7 +- .../Manifest/V1/PackageAgreement.cs | 6 +- .../WinGetUtilInterop.csproj | 8 +- 55 files changed, 2072 insertions(+), 577 deletions(-) create mode 100644 src/WinGetUtilInterop.UnitTests/APIUnitTests/SQLiteIndexUnitTests.cs create mode 100644 src/WinGetUtilInterop.UnitTests/TestCollateral/PackageTest.yaml create mode 100644 src/WinGetUtilInterop.UnitTests/TestCollateral/PackageTestNewName.yaml create mode 100644 src/WinGetUtilInterop.UnitTests/TestCollateral/PackageTestNewVersion.yaml create mode 100644 src/WinGetUtilInterop/Api/WinGetFactory.cs create mode 100644 src/WinGetUtilInterop/Api/WinGetInstallerMetadata.cs create mode 100644 src/WinGetUtilInterop/Api/WinGetLogging.cs create mode 100644 src/WinGetUtilInterop/Api/WinGetManifest.cs rename src/WinGetUtilInterop/{Helpers/WinGetUtilIndex.cs => Api/WinGetSQLiteIndex.cs} (53%) create mode 100644 src/WinGetUtilInterop/Api/WinGetUtilities.cs create mode 100644 src/WinGetUtilInterop/Common/Constants.cs create mode 100644 src/WinGetUtilInterop/Common/CreateManifestResult.cs create mode 100644 src/WinGetUtilInterop/Common/Enums.cs create mode 100644 src/WinGetUtilInterop/Common/ManifestValidationResult.cs create mode 100644 src/WinGetUtilInterop/Exceptions/WinGetDownloadException.cs create mode 100644 src/WinGetUtilInterop/Exceptions/WinGetInstallerMetadataException.cs create mode 100644 src/WinGetUtilInterop/Exceptions/WinGetLoggingException.cs create mode 100644 src/WinGetUtilInterop/Exceptions/WinGetManifestException.cs create mode 100644 src/WinGetUtilInterop/Exceptions/WinGetSQLiteIndexException.cs delete mode 100644 src/WinGetUtilInterop/Exceptions/WinGetUtilIndexException.cs delete mode 100644 src/WinGetUtilInterop/Helpers/WinGetUtilWrapperManifest.cs create mode 100644 src/WinGetUtilInterop/Interfaces/IWinGetFactory.cs create mode 100644 src/WinGetUtilInterop/Interfaces/IWinGetInstallerMetadata.cs create mode 100644 src/WinGetUtilInterop/Interfaces/IWinGetLogging.cs create mode 100644 src/WinGetUtilInterop/Interfaces/IWinGetManifest.cs rename src/WinGetUtilInterop/Interfaces/{IWinGetUtilIndex.cs => IWinGetSQLiteIndex.cs} (88%) create mode 100644 src/WinGetUtilInterop/Interfaces/IWinGetUtilities.cs diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0c01ebb798..514c95046d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -291,12 +291,21 @@ jobs: - task: CopyFiles@2 displayName: 'Copy Files: WinGetUtilInterop.UnitTests' inputs: - SourceFolder: '$(Build.SourcesDirectory)\src\WinGetUtilInterop.UnitTests\bin\$(BuildConfiguration)\net6.0' + SourceFolder: '$(Build.SourcesDirectory)\src\WinGetUtilInterop.UnitTests\bin\$(buildPlatform)\$(BuildConfiguration)\net6.0' TargetFolder: '$(Build.ArtifactStagingDirectory)\WinGetUtilInterop.UnitTests\' CleanTargetFolder: true OverWrite: true condition: succeededOrFailed() + - task: CopyFiles@2 + displayName: 'Copy WinGetUtil to WinGetUtilInterop.UnitTests folder' + inputs: + Contents: | + $(buildOutDir)\WinGetUtil\WinGetUtil.dll + TargetFolder: '$(Build.ArtifactStagingDirectory)\WinGetUtilInterop.UnitTests\' + flattenFolders: true + condition: succeededOrFailed() + - task: VSTest@2 displayName: 'Run tests: WinGetUtilInterop.UnitTests' inputs: @@ -304,7 +313,7 @@ jobs: testAssemblyVer2: 'WinGetUtilInterop.UnitTests.dll' searchFolder: '$(Build.ArtifactStagingDirectory)\WinGetUtilInterop.UnitTests' codeCoverageEnabled: true - platform: 'Any CPU' + platform: '$(buildPlatform)' configuration: '$(BuildConfiguration)' condition: succeededOrFailed() diff --git a/src/AppInstallerCLI.sln b/src/AppInstallerCLI.sln index 25ff8cbf9e..02c29202fc 100644 --- a/src/AppInstallerCLI.sln +++ b/src/AppInstallerCLI.sln @@ -769,34 +769,29 @@ Global {846FB88B-BF1B-4F33-9883-E589CEC99739}.TestRelease|x64.ActiveCfg = Release|Any CPU {846FB88B-BF1B-4F33-9883-E589CEC99739}.TestRelease|x86.ActiveCfg = Release|Any CPU {68808357-902B-406C-8C19-E8E26A69DE8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Debug|ARM64.ActiveCfg = Debug|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Debug|ARM64.Build.0 = Debug|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Debug|x64.ActiveCfg = Debug|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Debug|x64.Build.0 = Debug|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Debug|x86.ActiveCfg = Debug|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Debug|x86.Build.0 = Debug|Any CPU + {68808357-902B-406C-8C19-E8E26A69DE8A}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {68808357-902B-406C-8C19-E8E26A69DE8A}.Debug|x64.ActiveCfg = Debug|x64 + {68808357-902B-406C-8C19-E8E26A69DE8A}.Debug|x64.Build.0 = Debug|x64 + {68808357-902B-406C-8C19-E8E26A69DE8A}.Debug|x86.ActiveCfg = Debug|x86 + {68808357-902B-406C-8C19-E8E26A69DE8A}.Debug|x86.Build.0 = Debug|x86 {68808357-902B-406C-8C19-E8E26A69DE8A}.Fuzzing|Any CPU.ActiveCfg = Release|Any CPU {68808357-902B-406C-8C19-E8E26A69DE8A}.Fuzzing|ARM64.ActiveCfg = Debug|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Fuzzing|ARM64.Build.0 = Debug|Any CPU {68808357-902B-406C-8C19-E8E26A69DE8A}.Fuzzing|x64.ActiveCfg = Debug|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Fuzzing|x64.Build.0 = Debug|Any CPU {68808357-902B-406C-8C19-E8E26A69DE8A}.Fuzzing|x86.ActiveCfg = Debug|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Fuzzing|x86.Build.0 = Debug|Any CPU {68808357-902B-406C-8C19-E8E26A69DE8A}.PowerShell|Any CPU.ActiveCfg = Release|Any CPU {68808357-902B-406C-8C19-E8E26A69DE8A}.PowerShell|ARM64.ActiveCfg = Release|Any CPU {68808357-902B-406C-8C19-E8E26A69DE8A}.PowerShell|x64.ActiveCfg = Release|Any CPU {68808357-902B-406C-8C19-E8E26A69DE8A}.PowerShell|x86.ActiveCfg = Release|Any CPU {68808357-902B-406C-8C19-E8E26A69DE8A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Release|ARM64.ActiveCfg = Release|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Release|ARM64.Build.0 = Release|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Release|x64.ActiveCfg = Release|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Release|x64.Build.0 = Release|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Release|x86.ActiveCfg = Release|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.Release|x86.Build.0 = Release|Any CPU + {68808357-902B-406C-8C19-E8E26A69DE8A}.Release|ARM64.ActiveCfg = Release|ARM64 + {68808357-902B-406C-8C19-E8E26A69DE8A}.Release|x64.ActiveCfg = Release|x64 + {68808357-902B-406C-8C19-E8E26A69DE8A}.Release|x64.Build.0 = Release|x64 + {68808357-902B-406C-8C19-E8E26A69DE8A}.Release|x86.ActiveCfg = Release|x86 + {68808357-902B-406C-8C19-E8E26A69DE8A}.Release|x86.Build.0 = Release|x86 {68808357-902B-406C-8C19-E8E26A69DE8A}.TestRelease|Any CPU.ActiveCfg = Release|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.TestRelease|ARM64.ActiveCfg = Release|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.TestRelease|x64.ActiveCfg = Release|Any CPU - {68808357-902B-406C-8C19-E8E26A69DE8A}.TestRelease|x86.ActiveCfg = Release|Any CPU + {68808357-902B-406C-8C19-E8E26A69DE8A}.TestRelease|ARM64.ActiveCfg = Release|ARM64 + {68808357-902B-406C-8C19-E8E26A69DE8A}.TestRelease|x64.ActiveCfg = Release|x64 + {68808357-902B-406C-8C19-E8E26A69DE8A}.TestRelease|x86.ActiveCfg = Release|x86 {2046B5AF-666D-4CE8-8D3E-C32C57908A56}.Debug|Any CPU.ActiveCfg = Debug|x64 {2046B5AF-666D-4CE8-8D3E-C32C57908A56}.Debug|ARM64.ActiveCfg = Debug|ARM64 {2046B5AF-666D-4CE8-8D3E-C32C57908A56}.Debug|ARM64.Build.0 = Debug|ARM64 diff --git a/src/WinGetSourceCreator/WinGetLocalSource.cs b/src/WinGetSourceCreator/WinGetLocalSource.cs index 9cbe6b1e66..396e5fdaf0 100644 --- a/src/WinGetSourceCreator/WinGetLocalSource.cs +++ b/src/WinGetSourceCreator/WinGetLocalSource.cs @@ -6,7 +6,7 @@ namespace Microsoft.WinGetSourceCreator using global::WinGetSourceCreator.Model; using System.Text.Json.Serialization; using System.Text.Json; - using WinGetUtilInterop.Helpers; + using Microsoft.WinGetUtil.Api; public class WinGetLocalSource { @@ -113,7 +113,7 @@ public void PrepareManifest(string input) public string CreateIndex(string indexName) { string fullPath = Path.Combine(this.workingDirectory, indexName); - using var indexHelper = WinGetUtilIndex.CreateLatestVersion(fullPath); + using var indexHelper = new WinGetFactory().SQLiteIndexCreateLatestVersion(fullPath); Queue filesQueue = new(Directory.EnumerateFiles(this.workingDirectory, "*.yaml", SearchOption.AllDirectories)); while (filesQueue.Count > 0) diff --git a/src/WinGetUtilInterop.UnitTests/APIUnitTests/SQLiteIndexUnitTests.cs b/src/WinGetUtilInterop.UnitTests/APIUnitTests/SQLiteIndexUnitTests.cs new file mode 100644 index 0000000000..bc93dbc37c --- /dev/null +++ b/src/WinGetUtilInterop.UnitTests/APIUnitTests/SQLiteIndexUnitTests.cs @@ -0,0 +1,337 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace WinGetUtilInterop.UnitTests.APIUnitTests +{ + using System; + using System.IO; + using System.Reflection; + using Microsoft.WinGetUtil.Api; + using Microsoft.WinGetUtil.Exceptions; + using Microsoft.WinGetUtil.Interfaces; + using Microsoft.WinGetUtil.UnitTests.Common.Logging; + using Xunit; + using Xunit.Abstractions; + + /// + /// SQLite Index tests. + /// + public class SQLiteIndexUnitTests + { + private const string Index = "Index"; + private const string IndexLogFile = "index_log.txt"; + private const string IndexFileName = "index.db"; + + private const string PackageTest = "PackageTest.yaml"; + private const string PackageTestNewName = "PackageTestNewName.yaml"; + private const string PackageTestNewVersion = "PackageTestNewVersion.yaml"; + private const string PackageTestRelativePath = @"manifests\t\Test\Test\1.0\Test.Test.yaml"; + + private readonly string indexTestFilePath; + private readonly string indexTestLogFile; + private readonly string indexTestOutputPath; + private readonly string indexTestDataPath; + + private ITestOutputHelper log; + + /// + /// Initializes a new instance of the class. + /// + /// Output Helper. + public SQLiteIndexUnitTests(ITestOutputHelper log) + { + this.log = log; + + var assemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + this.indexTestDataPath = Path.Combine( + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), + "TestCollateral"); + + this.indexTestOutputPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString(), "WinGetUtilIndexTests"); + Directory.CreateDirectory(this.indexTestOutputPath); + + this.indexTestFilePath = Path.Combine(this.indexTestOutputPath, IndexFileName); + this.indexTestLogFile = Path.Combine(this.indexTestOutputPath, IndexLogFile); + + if (File.Exists(this.indexTestFilePath)) + { + File.Delete(this.indexTestFilePath); + } + + if (File.Exists(this.indexTestLogFile)) + { + File.Delete(this.indexTestLogFile); + } + } + + /// + /// Verify opening a existing index file succeeds. + /// + [Fact] + [DisplayTestMethodName] + public void OpenIndex() + { + this.CreateIndexHelperForIndexTest((wrapper) => true); + this.OpenIndexHelper((wrapper) => true); + } + + /// + /// Verify opening a fake file fails. + /// + [Fact] + [DisplayTestMethodName] + public void OpenIndexFileDontExist() + { + // Verify fails with non existent file. + var exception = Assert.Throws( + () => + { + var factory = new WinGetFactory(); + using var log = factory.LoggingInit(this.indexTestLogFile); + using var wrapper = factory.SQLiteIndexOpen("fakeFile.db"); + }); + Assert.NotNull(exception.InnerException); + Assert.True(exception.InnerException is System.Runtime.InteropServices.COMException); + Assert.Equal(-2018574322, exception.InnerException.HResult); + File.Delete(this.indexTestLogFile); + + // Verify fails with not an index file. + string textFile = Path.Combine(this.indexTestOutputPath, "text.txt"); + File.WriteAllText(textFile, "This is a text file."); + Assert.True(File.Exists(textFile), "File created correctly."); + var exception2 = Assert.Throws( + () => + { + var factory = new WinGetFactory(); + using var log = factory.LoggingInit(this.indexTestLogFile); + using var wrapper = factory.SQLiteIndexOpen(textFile); + }); + Assert.NotNull(exception2.InnerException); + Assert.True(exception2.InnerException is System.Runtime.InteropServices.COMException); + Assert.Equal("File opened that is not a database file (0x87AF001A)", exception2.InnerException.Message); + File.Delete(textFile); + } + + /// + /// Verifies adding a manifest to the index succeeds. + /// + [Fact] + [DisplayTestMethodName] + public void AddManifest() + { + this.CreateIndexHelperForIndexTest((wrapper) => + { + // Add manifest. + string testManifest = Path.Combine(this.indexTestDataPath, PackageTest); + wrapper.AddManifest(testManifest, PackageTestRelativePath); + return true; + }); + } + + /// + /// Verify that adding an already existing manifest fails. + /// + [Fact] + [DisplayTestMethodName] + public void AddManifestAlreadyExists() + { + this.CreateIndexHelperForIndexTest((wrapper) => + { + // Add manifest. + string testManifest = Path.Combine(this.indexTestDataPath, PackageTest); + wrapper.AddManifest(testManifest, PackageTestRelativePath); + + // Add manifest again. + var exception = Assert.Throws( + () => + { + wrapper.AddManifest(testManifest, PackageTestRelativePath); + }); + Assert.NotNull(exception.InnerException); + Assert.True(exception.InnerException is System.Runtime.InteropServices.COMException); + Assert.Equal(-2147024713, exception.InnerException.HResult); + + return true; + }); + } + + /// + /// Verify that updating a manifest with different name. + /// + [Fact] + [DisplayTestMethodName] + public void UpdateManifest() + { + this.CreateIndexHelperForIndexTest((wrapper) => + { + // Add manifest. + string addManifest = Path.Combine(this.indexTestDataPath, PackageTest); + wrapper.AddManifest(addManifest, PackageTestRelativePath); + + // Update manifest. name is different, should return true. + string updateManifest = Path.Combine(this.indexTestDataPath, PackageTestNewName); + Assert.True(wrapper.UpdateManifest(updateManifest, PackageTestRelativePath)); + + return true; + }); + } + + /// + /// Verify that updating a manifest in the index with the exact same information succeeds. + /// + [Fact] + [DisplayTestMethodName] + public void UpdateManifestNoChanges() + { + this.CreateIndexHelperForIndexTest((wrapper) => + { + // Add manifest. + string addManifest = Path.Combine(this.indexTestDataPath, PackageTest); + wrapper.AddManifest(addManifest, PackageTestRelativePath); + + // Update manifest. Same file, should succeed but return false. + Assert.False(wrapper.UpdateManifest(addManifest, PackageTestRelativePath)); + + return true; + }); + } + + /// + /// Verify that updating a manifest that doesn't exists fails. + /// + [Fact] + [DisplayTestMethodName] + public void UpdateManifestNonExistant() + { + this.CreateIndexHelperForIndexTest((wrapper) => + { + // Update manifest that doesn't exists + string updateManifest = Path.Combine(this.indexTestDataPath, PackageTest); + var exception = Assert.Throws( + () => + { + wrapper.UpdateManifest(updateManifest, PackageTestRelativePath); + }); + Assert.NotNull(exception.InnerException); + Assert.True(exception.InnerException is System.Runtime.InteropServices.COMException); + Assert.Equal(-2147023728, exception.InnerException.HResult); + + return true; + }); + } + + /// + /// Verify that updating an existing manifest in the index, but another version. + /// + [Fact] + [DisplayTestMethodName] + public void UpdateManifestDifferentVersion() + { + this.CreateIndexHelperForIndexTest((wrapper) => + { + // Add manifest. + string addManifest = Path.Combine(this.indexTestDataPath, PackageTest); + wrapper.AddManifest(addManifest, PackageTestRelativePath); + + // Update manifest. Version is different. + string updateManifest = Path.Combine(this.indexTestDataPath, PackageTestNewVersion); + var exception = Assert.Throws( + () => + { + wrapper.UpdateManifest(updateManifest, PackageTestRelativePath); + }); + Assert.NotNull(exception.InnerException); + Assert.True(exception.InnerException is System.Runtime.InteropServices.COMException); + Assert.Equal(-2147023728, exception.InnerException.HResult); + + return true; + }); + } + + /// + /// Verify that removing a manifest in the index succeeds. + /// + [Fact] + [DisplayTestMethodName] + public void RemoveManifest() + { + this.CreateIndexHelperForIndexTest((wrapper) => + { + // Add manifest. + string addManifest = Path.Combine(this.indexTestDataPath, PackageTest); + wrapper.AddManifest(addManifest, PackageTestRelativePath); + + // Remove manifest. + wrapper.RemoveManifest(addManifest, PackageTestRelativePath); + + return true; + }); + } + + /// + /// Verify that trying to delete a manifest that doesn't exists fails. + /// + [Fact] + [DisplayTestMethodName] + public void RemoveManifestNonExistant() + { + // create index, add manifest, delete. + this.CreateIndexHelperForIndexTest((wrapper) => + { + // Add manifest. + string addManifest = Path.Combine(this.indexTestDataPath, PackageTest); + + // Remove manifest. + Assert.Throws( + () => + { + wrapper.RemoveManifest(addManifest, PackageTestRelativePath); + }); + + return true; + }); + } + + private void CreateIndexHelperForIndexTest(Func lambda) + { + if (File.Exists(this.indexTestLogFile)) + { + File.Delete(this.indexTestLogFile); + } + + if (File.Exists(this.indexTestFilePath)) + { + File.Delete(this.indexTestFilePath); + } + + // Create index. + var factory = new WinGetFactory(); + using var log = factory.LoggingInit(this.indexTestLogFile); + using var wrapper = factory.SQLiteIndexCreateLatestVersion(this.indexTestFilePath); + Assert.True(lambda(wrapper), "Expression passed"); + + Assert.True(File.Exists(this.indexTestLogFile)); + Assert.True(File.Exists(this.indexTestFilePath)); + } + + private void OpenIndexHelper(Func lambda) + { + Assert.True(File.Exists(this.indexTestFilePath)); + if (File.Exists(this.indexTestLogFile)) + { + File.Delete(this.indexTestLogFile); + } + + // Open index. + var factory = new WinGetFactory(); + using var log = factory.LoggingInit(this.indexTestLogFile); + using var wrapper = factory.SQLiteIndexOpen(this.indexTestFilePath); + Assert.True(lambda(wrapper), "Expression passed"); + + Assert.True(File.Exists(this.indexTestLogFile)); + } + } +} diff --git a/src/WinGetUtilInterop.UnitTests/Common/DisplayTestMethodNameAttribute.cs b/src/WinGetUtilInterop.UnitTests/Common/DisplayTestMethodNameAttribute.cs index 8ad042b2c2..9cb26bb519 100644 --- a/src/WinGetUtilInterop.UnitTests/Common/DisplayTestMethodNameAttribute.cs +++ b/src/WinGetUtilInterop.UnitTests/Common/DisplayTestMethodNameAttribute.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.UnitTests.Common.Logging { diff --git a/src/WinGetUtilInterop.UnitTests/ManifestUnitTest/ManifestEqualityUnitTests.cs b/src/WinGetUtilInterop.UnitTests/ManifestUnitTest/ManifestEqualityUnitTests.cs index f6812532f8..f5601ea2fc 100644 --- a/src/WinGetUtilInterop.UnitTests/ManifestUnitTest/ManifestEqualityUnitTests.cs +++ b/src/WinGetUtilInterop.UnitTests/ManifestUnitTest/ManifestEqualityUnitTests.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.UnitTests.ManifestUnitTest { diff --git a/src/WinGetUtilInterop.UnitTests/ManifestUnitTest/V1ManifestReadTest.cs b/src/WinGetUtilInterop.UnitTests/ManifestUnitTest/V1ManifestReadTest.cs index c33e654ada..3b0ba78abd 100644 --- a/src/WinGetUtilInterop.UnitTests/ManifestUnitTest/V1ManifestReadTest.cs +++ b/src/WinGetUtilInterop.UnitTests/ManifestUnitTest/V1ManifestReadTest.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.UnitTests.ManifestUnitTest { @@ -55,7 +55,7 @@ public void ReadV1ManifestsAndVerifyContents() Manifest v160manifest = Manifest.CreateManifestFromPath( Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestCollateral", ManifestStrings.V160ManifestMerged)); - + this.ValidateManifestFields(v160manifest, TestManifestVersion.V160); } diff --git a/src/WinGetUtilInterop.UnitTests/TestCollateral/PackageTest.yaml b/src/WinGetUtilInterop.UnitTests/TestCollateral/PackageTest.yaml new file mode 100644 index 0000000000..e7d586395b --- /dev/null +++ b/src/WinGetUtilInterop.UnitTests/TestCollateral/PackageTest.yaml @@ -0,0 +1,18 @@ +PackageIdentifier: Test.Test +PackageVersion: 1.0 +PackageName: Test +Publisher: Test +PackageUrl: https://test.com +License: Test. +LicenseUrl: https://test.com +ShortDescription: A test +Installers: +- Architecture: x64 + InstallerUrl: https://test.com/installer.exe + InstallerType: exe + InstallerSwitches: + Silent: /silent + InstallerSha256: 00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF +PackageLocale: en-US +ManifestType: singleton +ManifestVersion: 1.0.0 diff --git a/src/WinGetUtilInterop.UnitTests/TestCollateral/PackageTestNewName.yaml b/src/WinGetUtilInterop.UnitTests/TestCollateral/PackageTestNewName.yaml new file mode 100644 index 0000000000..29d1e7c189 --- /dev/null +++ b/src/WinGetUtilInterop.UnitTests/TestCollateral/PackageTestNewName.yaml @@ -0,0 +1,18 @@ +PackageIdentifier: Test.Test +PackageVersion: 1.0 +PackageName: NewName +Publisher: Test +PackageUrl: https://test.com +License: Test. +LicenseUrl: https://test.com +ShortDescription: A test +Installers: +- Architecture: x64 + InstallerUrl: https://test.com/installer.exe + InstallerType: exe + InstallerSwitches: + Silent: /silent + InstallerSha256: 00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF +PackageLocale: en-US +ManifestType: singleton +ManifestVersion: 1.0.0 diff --git a/src/WinGetUtilInterop.UnitTests/TestCollateral/PackageTestNewVersion.yaml b/src/WinGetUtilInterop.UnitTests/TestCollateral/PackageTestNewVersion.yaml new file mode 100644 index 0000000000..59840b0d56 --- /dev/null +++ b/src/WinGetUtilInterop.UnitTests/TestCollateral/PackageTestNewVersion.yaml @@ -0,0 +1,18 @@ +PackageIdentifier: Test.Test +PackageVersion: 2.0 +PackageName: Test +Publisher: Test +PackageUrl: https://test.com +License: Test. +LicenseUrl: https://test.com +ShortDescription: A test +Installers: +- Architecture: x64 + InstallerUrl: https://test.com/installer.exe + InstallerType: exe + InstallerSwitches: + Silent: /silent + InstallerSha256: 00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF +PackageLocale: en-US +ManifestType: singleton +ManifestVersion: 1.0.0 diff --git a/src/WinGetUtilInterop.UnitTests/WinGetUtilInterop.UnitTests.csproj b/src/WinGetUtilInterop.UnitTests/WinGetUtilInterop.UnitTests.csproj index bd43371368..87a9cfe71b 100644 --- a/src/WinGetUtilInterop.UnitTests/WinGetUtilInterop.UnitTests.csproj +++ b/src/WinGetUtilInterop.UnitTests/WinGetUtilInterop.UnitTests.csproj @@ -2,6 +2,7 @@ net6.0 + x64;x86 @@ -14,10 +15,22 @@ + + all + + + + + + + Content + PreserveNewest + True + @@ -30,6 +43,15 @@ Always + + Always + + + Always + + + Always + Always diff --git a/src/WinGetUtilInterop/Api/WinGetFactory.cs b/src/WinGetUtilInterop/Api/WinGetFactory.cs new file mode 100644 index 0000000000..e0ae8df76c --- /dev/null +++ b/src/WinGetUtilInterop/Api/WinGetFactory.cs @@ -0,0 +1,208 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Api +{ + using System; + using System.Runtime.InteropServices; + using Microsoft.WinGetUtil.Common; + using Microsoft.WinGetUtil.Exceptions; + using Microsoft.WinGetUtil.Interfaces; + + /// + /// Factory methods. + /// + public sealed class WinGetFactory : IWinGetFactory + { + private const uint IndexLatestVersion = unchecked((uint)-1); + + /// + public IWinGetSQLiteIndex SQLiteIndexCreate(string indexFile, uint majorVersion, uint minorVersion) + { + try + { + WinGetSQLiteIndexCreate( + indexFile, + majorVersion, + minorVersion, + out IntPtr index); + return new WinGetSQLiteIndex(index); + } + catch (Exception e) + { + throw new WinGetSQLiteIndexException(e); + } + } + + /// + public IWinGetSQLiteIndex SQLiteIndexCreateLatestVersion(string indexFile) + { + return this.SQLiteIndexCreate(indexFile, IndexLatestVersion, IndexLatestVersion); + } + + /// + public IWinGetSQLiteIndex SQLiteIndexOpen(string indexFile) + { + try + { + WinGetSQLiteIndexOpen(indexFile, out IntPtr index); + return new WinGetSQLiteIndex(index); + } + catch (Exception e) + { + throw new WinGetSQLiteIndexException(e); + } + } + + /// + public IWinGetLogging LoggingInit(string indexLogFile) + { + try + { + WinGetLoggingInit(indexLogFile); + return new WinGetLogging(indexLogFile); + } + catch (Exception e) + { + throw new WinGetLoggingException(e); + } + } + + /// + public CreateManifestResult CreateManifest(string manifestPath, string mergedManifestPath, WinGetCreateManifestOption option) + { + try + { + bool succeeded = false; + IntPtr manifestHandle = IntPtr.Zero; + string failureOrWarningMessage = null; + WinGetCreateManifest( + manifestPath, + out succeeded, + out manifestHandle, + out failureOrWarningMessage, + mergedManifestPath, + option); + + // WinGetUtil uses exceptions for passing warning messages. When a warning is detected, + // WinGetUtil will throw so a manifest handle will not be returned, in this case, we try + // to create the manifest handle without any validation. + if (succeeded && manifestHandle == IntPtr.Zero) + { + WinGetCreateManifest( + manifestPath, + out succeeded, + out manifestHandle, + out string failureNotExpected, + null, + WinGetCreateManifestOption.NoValidation); + } + + return new CreateManifestResult(succeeded, failureOrWarningMessage, succeeded ? new WinGetManifest(manifestHandle) : null); + } + catch (Exception e) + { + throw new WinGetManifestException(e); + } + } + + /// + /// Begins the installer metadata collection process. + /// + /// input. + /// Log file path. + /// An enum of type . + /// Metadata output file path. + /// IWinGetInstallerMetadata with the handle to the installer metadata collection. + public IWinGetInstallerMetadata BeginInstallerMetadataCollection( + string input, + string logFilePath, + WinGetBeginInstallerMetadataCollectionOptions options, + string outputFilePath) + { + try + { + IntPtr collectionHandle = IntPtr.Zero; + WinGetBeginInstallerMetadataCollection( + input, + logFilePath, + options, + out collectionHandle); + + return new WinGetInstallerMetadata(collectionHandle, outputFilePath); + } + catch (Exception e) + { + throw new WinGetInstallerMetadataException(e); + } + } + + /// + /// Creates a new index file at filePath with the given version. + /// + /// File path to create index. + /// Major version. + /// Minor version. + /// Out handle of the index. + /// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetSQLiteIndexCreate(string filePath, uint majorVersion, uint minorVersion, out IntPtr index); + + /// + /// Opens an existing index at filePath. + /// + /// File path of index. + /// Out handle of the index. + /// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetSQLiteIndexOpen(string filePath, out IntPtr index); + + /// + /// Initializes the logging infrastructure. + /// + /// Log path. + /// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetLoggingInit(string logPath); + + /// + /// Creates a manifest with schema or semantic validation if needed. + /// + /// Path of manifest. + /// If create manifest succeeded. + /// Out bool is validation succeeded. + /// Out string failure message, if any. + /// Path to merged manifest file. Empty means no merged manifest needed. + /// Validate manifest option. + /// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetCreateManifest( + string inputPath, + [MarshalAs(UnmanagedType.U1)] out bool succeeded, + out IntPtr manifestHandle, + [MarshalAs(UnmanagedType.BStr)] out string failureMessage, + string mergedManifestPath, + WinGetCreateManifestOption option); + + /// + /// Begins the installer metadata collection process. By default, inputJSON is expected to be a JSON string. + /// See the WinGetBeginInstallerMetadataCollectionOptions for more options. + /// logFilePath optionally specifies where to write the log file for the collection operation. + /// The collectionHandle is owned by the caller and must be passed to WinGetCompleteInstallerMetadataCollection to free it. + /// + /// Input Json. + /// Log file path. + /// An enum of type . + /// Collection handle. + /// Metadata Collection handle. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetBeginInstallerMetadataCollection( + string inputJSON, + string logFilePath, + WinGetBeginInstallerMetadataCollectionOptions options, + out IntPtr collectionHandle); + } +} diff --git a/src/WinGetUtilInterop/Api/WinGetInstallerMetadata.cs b/src/WinGetUtilInterop/Api/WinGetInstallerMetadata.cs new file mode 100644 index 0000000000..54a38d8fa0 --- /dev/null +++ b/src/WinGetUtilInterop/Api/WinGetInstallerMetadata.cs @@ -0,0 +1,96 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Api +{ + using System; + using System.Runtime.InteropServices; + using Microsoft.WinGetUtil.Common; + using Microsoft.WinGetUtil.Exceptions; + using Microsoft.WinGetUtil.Interfaces; + + /// + /// Wrapper for WinGetInstallerMetadata operations. + /// + public sealed class WinGetInstallerMetadata : IWinGetInstallerMetadata + { + private readonly string outputFilePath; + private IntPtr collectionHandle; + + /// + /// Initializes a new instance of the class. + /// + /// Collection handle. + /// Output file path. + internal WinGetInstallerMetadata(IntPtr collectionHandle, string outputFilePath) + { + this.collectionHandle = collectionHandle; + this.outputFilePath = outputFilePath; + } + + /// + public void Complete(bool abandon = false) + { + try + { + this.CompleteInternal(abandon ? + WinGetCompleteInstallerMetadataCollectionOptions.WinGetCompleteInstallerMetadataCollectionOption_Abandon : + WinGetCompleteInstallerMetadataCollectionOptions.WinGetCompleteInstallerMetadataCollectionOption_None); + this.collectionHandle = IntPtr.Zero; + } + catch (Exception e) + { + throw new WinGetInstallerMetadataException(e); + } + } + + /// + /// Dispose method. + /// + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Dispose method to free the manifest handle. + /// + /// Bool value indicating if Dispose is being run. + public void Dispose(bool disposing) + { + if (disposing) + { + this.Complete(true); + } + } + + /// + /// Completes the installer metadata collection process, Always frees the collectionHandle. + /// WinGetCompleteInstallerMetadataCollection must be called exactly once for each call to WinGetBeginInstallerMetadataCollection. + /// + /// Collection Handle. + /// Metadata output file path. + /// An enum of type . + /// Metadata collection handle. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetCompleteInstallerMetadataCollection( + IntPtr collectionHandle, + string outputFilePath, + WinGetCompleteInstallerMetadataCollectionOptions options); + + private void CompleteInternal(WinGetCompleteInstallerMetadataCollectionOptions options) + { + if (this.collectionHandle != IntPtr.Zero) + { + WinGetCompleteInstallerMetadataCollection( + this.collectionHandle, + this.outputFilePath, + options); + } + } + } +} diff --git a/src/WinGetUtilInterop/Api/WinGetLogging.cs b/src/WinGetUtilInterop/Api/WinGetLogging.cs new file mode 100644 index 0000000000..99642805e4 --- /dev/null +++ b/src/WinGetUtilInterop/Api/WinGetLogging.cs @@ -0,0 +1,68 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Api +{ + using System; + using System.IO; + using System.Runtime.InteropServices; + using Microsoft.WinGetUtil.Common; + using Microsoft.WinGetUtil.Interfaces; + + /// + /// Wrapper class around WinGetUtil log native implementation. + /// For dll entry points are defined here: + /// https://github.com/microsoft/winget-cli/blob/master/src/WinGetUtil/WinGetUtil.h. + /// + public sealed class WinGetLogging : IWinGetLogging + { + /// + /// Initializes a new instance of the class. + /// + /// Open index file. Must be closed at dispose. + internal WinGetLogging(string logFile) + { + this.LogFile = logFile; + } + + /// + /// Gets log file. + /// + public string LogFile { get; private set; } + + /// + /// Dispose method. + /// + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Dispose method to dispose the Git desktop process runner. + /// + /// Bool value indicating if Dispose is being run. + public void Dispose(bool disposing) + { + if (disposing) + { + if (File.Exists(this.LogFile)) + { + WinGetLoggingTerm(this.LogFile); + } + } + } + + //// + //// Closes the index log file. + //// + //// Log path to close. Null for all. + //// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetLoggingTerm(string logPath); + } +} diff --git a/src/WinGetUtilInterop/Api/WinGetManifest.cs b/src/WinGetUtilInterop/Api/WinGetManifest.cs new file mode 100644 index 0000000000..156959eeb8 --- /dev/null +++ b/src/WinGetUtilInterop/Api/WinGetManifest.cs @@ -0,0 +1,110 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Api +{ + using System; + using System.Runtime.InteropServices; + using Microsoft.WinGetUtil.Common; + using Microsoft.WinGetUtil.Exceptions; + using Microsoft.WinGetUtil.Interfaces; + + /// + /// Wrapper class around WinGetUtil manifest native implementation. + /// For dll entry points are defined here: + /// https://github.com/microsoft/winget-cli/blob/master/src/WinGetUtil/WinGetUtil.h. + /// + public sealed class WinGetManifest : IWinGetManifest + { + private readonly IntPtr manifestHandle; + + /// + /// Initializes a new instance of the class. + /// + /// Handle of the manifest. + /// Logging Context. + internal WinGetManifest(IntPtr manifestHandle) + { + this.manifestHandle = manifestHandle; + } + + /// + public ManifestValidationResult ValidateManifestV3( + IntPtr indexHandle, + WinGetValidateManifestOptionV2 option, + WinGetValidateManifestOperationType operationType) + { + try + { + WinGetValidateManifestV3( + this.manifestHandle, + indexHandle, + out WinGetValidateManifestResult result, + out string failureOrWarningMessage, + option, + operationType); + + return new ManifestValidationResult(result == WinGetValidateManifestResult.Success, failureOrWarningMessage, result); + } + catch (Exception e) + { + throw new WinGetManifestException(e); + } + } + + /// + /// Dispose method. + /// + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Dispose method to free the manifest handle. + /// + /// Bool value indicating if Dispose is being run. + public void Dispose(bool disposing) + { + if (disposing) + { + if (this.manifestHandle != IntPtr.Zero) + { + WinGetCloseManifest(this.manifestHandle); + } + } + } + + /// + /// Closes the manifest handle. + /// + /// Handle of the manifest. + /// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetCloseManifest(IntPtr manifest); + + /// + /// Validates a given manifest. Returns an enum for validation result and + /// a string representing validation errors if validation failed. + /// + /// Handle of the manifest. + /// Handle of the index. + /// Out validation result. + /// Out string failure message, if any. + /// Validate manifest option. + /// Validate manifest operation type. + /// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetValidateManifestV3( + IntPtr manifestHandle, + IntPtr indexHandle, + out WinGetValidateManifestResult result, + [MarshalAs(UnmanagedType.BStr)] out string failureMessage, + WinGetValidateManifestOptionV2 option, + WinGetValidateManifestOperationType operationType); + } +} diff --git a/src/WinGetUtilInterop/Helpers/WinGetUtilIndex.cs b/src/WinGetUtilInterop/Api/WinGetSQLiteIndex.cs similarity index 53% rename from src/WinGetUtilInterop/Helpers/WinGetUtilIndex.cs rename to src/WinGetUtilInterop/Api/WinGetSQLiteIndex.cs index 7bc5bbb067..f236a82740 100644 --- a/src/WinGetUtilInterop/Helpers/WinGetUtilIndex.cs +++ b/src/WinGetUtilInterop/Api/WinGetSQLiteIndex.cs @@ -1,278 +1,200 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// ----------------------------------------------------------------------- - -namespace WinGetUtilInterop.Helpers -{ - using System; - using System.Runtime.InteropServices; - using Microsoft.WinGetUtil.Interfaces; - using WinGetUtilInterop.Exceptions; - - public class WinGetUtilIndex : IWinGetUtilIndex - { - private const string WinGetUtilDll = "WinGetUtil.dll"; - private const uint IndexLatestVersion = unchecked((uint)-1); - - /// - /// WinGet Index latest version. - /// - public const uint WinGetIndexLatestVersion = unchecked((uint)-1); - - private readonly IntPtr indexHandle; - - /// - /// Initializes a new instance of the class. - /// - /// Handle of the index. - /// Logging Context. - private WinGetUtilIndex(IntPtr indexHandle) - { - this.indexHandle = indexHandle; - } - - /// - /// Creates a new index file in the specified path. - /// - /// Index file to create. - /// Major version. - /// Minor version. - /// Logging Context. - /// Instance of IWinGetUtilSQLiteIndex. - public static IWinGetUtilIndex Create(string indexFile, uint majorVersion, uint minorVersion) - { - try - { - WinGetSQLiteIndexCreate( - indexFile, - majorVersion, - minorVersion, - out IntPtr index); - return new WinGetUtilIndex(index); - } - catch (Exception e) - { - throw new WinGetUtilIndexException(e); - } - } - - /// - /// Creates a new index file in the specified path. - /// - /// Index file to create. - /// Instance of IWinGetUtilSQLiteIndex. - public static IWinGetUtilIndex CreateLatestVersion(string indexFile) - { - return Create(indexFile, IndexLatestVersion, IndexLatestVersion); - } - - /// - /// Open the index file. - /// - /// Index file to open. - /// Instance of IWinGetUtilSQLiteIndex. - public static IWinGetUtilIndex Open(string indexFile) - { - try - { - WinGetSQLiteIndexOpen(indexFile, out IntPtr index); - return new WinGetUtilIndex(index); - } - catch (Exception e) - { - throw new WinGetUtilIndexException(e); - } - } - - /// - public void AddManifest(string manifestPath, string relativePath) - { - try - { - WinGetSQLiteIndexAddManifest(this.indexHandle, manifestPath, relativePath); - return; - } - catch (Exception e) - { - throw new WinGetUtilIndexException(e); - } - } - - /// - public bool UpdateManifest(string manifestPath, string relativePath) - { - try - { - // For now, modifying a manifest implies that the file didn't got moved in the repository. So only - // contents of the file are modified. However, in the future we might support moving which requires - // oldManifestPath, oldRelativePath, newManifestPath and oldManifestPath. - WinGetSQLiteIndexUpdateManifest( - this.indexHandle, - manifestPath, - relativePath, - out bool indexModified); - return indexModified; - } - catch (Exception e) - { - throw new WinGetUtilIndexException(e); - } - } - - /// - public void RemoveManifest(string manifestPath, string relativePath) - { - try - { - WinGetSQLiteIndexRemoveManifest(this.indexHandle, manifestPath, relativePath); - return; - } - catch (Exception e) - { - throw new WinGetUtilIndexException(e); - } - } - - /// - public void PrepareForPackaging() - { - try - { - WinGetSQLiteIndexPrepareForPackaging(this.indexHandle); - return; - } - catch (Exception e) - { - throw new WinGetUtilIndexException(e); - } - } - - /// - public bool IsIndexConsistent() - { - try - { - WinGetSQLiteIndexCheckConsistency(this.indexHandle, out bool indexModified); - return indexModified; - } - catch (Exception e) - { - throw new WinGetUtilIndexException(e); - } - } - - /// - public IntPtr GetIndexHandle() - { - return this.indexHandle; - } - - /// - /// Dispose method. - /// - public void Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Dispose method to free the sqlite index handle. - /// - /// Bool value indicating if Dispose is being run. - public void Dispose(bool disposing) - { - if (disposing) - { - if (this.indexHandle != null) - { - WinGetSQLiteIndexClose(this.indexHandle); - } - } - } - - /// - /// Creates a new index file at filePath with the given version. - /// - /// File path to create index. - /// Major version. - /// Minor version. - /// Out handle of the index. - /// HRESULT. - [DllImport(WinGetUtilDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] - private static extern IntPtr WinGetSQLiteIndexCreate(string filePath, uint majorVersion, uint minorVersion, out IntPtr index); - - /// - /// Opens an existing index at filePath. - /// - /// File path of index. - /// Out handle of the index. - /// HRESULT. - [DllImport(WinGetUtilDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] - private static extern IntPtr WinGetSQLiteIndexOpen(string filePath, out IntPtr index); - - /// - /// Closes the index. - /// - /// Handle of the index. - /// HRESULT. - [DllImport(WinGetUtilDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] - private static extern IntPtr WinGetSQLiteIndexClose(IntPtr index); - - /// - /// Adds the manifest at the repository relative path to the index. - /// If the function succeeds, the manifest has been added. - /// - /// Handle of the index. - /// Manifest to add. - /// Path of the manifest in the container. - /// HRESULT. - [DllImport(WinGetUtilDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] - private static extern IntPtr WinGetSQLiteIndexAddManifest(IntPtr index, string manifestPath, string relativePath); - - /// - /// Updates the manifest at the repository relative path in the index. - /// The out value indicates whether the index was modified by the function. - /// - /// Handle of the index. - /// Old manifest path. - /// Old relative path in the container. - /// Out bool if the index is modified. - /// HRESULT. - [DllImport(WinGetUtilDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] - private static extern IntPtr WinGetSQLiteIndexUpdateManifest( - IntPtr index, - string manifestPath, - string relativePath, - [MarshalAs(UnmanagedType.U1)] out bool indexModified); - - /// - /// Removes the manifest at the repository relative path from the index. - /// - /// Index handle. - /// Manifest path to remove. - /// Relative path in the container. - /// HRESULT. - [DllImport(WinGetUtilDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] - private static extern IntPtr WinGetSQLiteIndexRemoveManifest(IntPtr index, string manifestPath, string relativePath); - - /// - /// Removes data that is no longer needed for an index that is to be published. - /// - /// Index handle. - /// HRESULT. - [DllImport(WinGetUtilDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] - private static extern IntPtr WinGetSQLiteIndexPrepareForPackaging(IntPtr index); - - /// - /// Checks the index for consistency, ensuring that at a minimum all referenced rows actually exist. - /// - /// Index handle. - /// Does the consistency check succeeded. - /// HRESULT. - [DllImport(WinGetUtilDll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] - private static extern IntPtr WinGetSQLiteIndexCheckConsistency(IntPtr index, [MarshalAs(UnmanagedType.U1)] out bool succeeded); - } -} +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Api +{ + using System; + using System.Runtime.InteropServices; + using Microsoft.WinGetUtil.Common; + using Microsoft.WinGetUtil.Exceptions; + using Microsoft.WinGetUtil.Interfaces; + + /// + /// Wrapper class for SQLite index operations. + /// + public sealed class WinGetSQLiteIndex : IWinGetSQLiteIndex + { + private readonly IntPtr indexHandle; + + /// + /// Initializes a new instance of the class. + /// + /// Handle of the index. + internal WinGetSQLiteIndex(IntPtr indexHandle) + { + this.indexHandle = indexHandle; + } + + /// + public void AddManifest(string manifestPath, string relativePath) + { + try + { + WinGetSQLiteIndexAddManifest(this.indexHandle, manifestPath, relativePath); + return; + } + catch (Exception e) + { + throw new WinGetSQLiteIndexException(e); + } + } + + /// + public bool UpdateManifest(string manifestPath, string relativePath) + { + try + { + // For now, modifying a manifest implies that the file didn't got moved in the repository. So only + // contents of the file are modified. However, in the future we might support moving which requires + // oldManifestPath, oldRelativePath, newManifestPath and oldManifestPath. + WinGetSQLiteIndexUpdateManifest( + this.indexHandle, + manifestPath, + relativePath, + out bool indexModified); + return indexModified; + } + catch (Exception e) + { + throw new WinGetSQLiteIndexException(e); + } + } + + /// + public void RemoveManifest(string manifestPath, string relativePath) + { + try + { + WinGetSQLiteIndexRemoveManifest(this.indexHandle, manifestPath, relativePath); + return; + } + catch (Exception e) + { + throw new WinGetSQLiteIndexException(e); + } + } + + /// + public void PrepareForPackaging() + { + try + { + WinGetSQLiteIndexPrepareForPackaging(this.indexHandle); + return; + } + catch (Exception e) + { + throw new WinGetSQLiteIndexException(e); + } + } + + /// + public bool IsIndexConsistent() + { + try + { + WinGetSQLiteIndexCheckConsistency(this.indexHandle, out bool indexModified); + return indexModified; + } + catch (Exception e) + { + throw new WinGetSQLiteIndexException(e); + } + } + + /// + public IntPtr GetIndexHandle() + { + return this.indexHandle; + } + + /// + /// Dispose method. + /// + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Dispose method to free the sqlite index handle. + /// + /// Bool value indicating if Dispose is being run. + public void Dispose(bool disposing) + { + if (disposing) + { + if (this.indexHandle != IntPtr.Zero) + { + WinGetSQLiteIndexClose(this.indexHandle); + } + } + } + + /// + /// Closes the index. + /// + /// Handle of the index. + /// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetSQLiteIndexClose(IntPtr index); + + /// + /// Adds the manifest at the repository relative path to the index. + /// If the function succeeds, the manifest has been added. + /// + /// Handle of the index. + /// Manifest to add. + /// Path of the manifest in the container. + /// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetSQLiteIndexAddManifest(IntPtr index, string manifestPath, string relativePath); + + /// + /// Updates the manifest at the repository relative path in the index. + /// The out value indicates whether the index was modified by the function. + /// + /// Handle of the index. + /// Old manifest path. + /// Old relative path in the container. + /// Out bool if the index is modified. + /// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetSQLiteIndexUpdateManifest( + IntPtr index, + string manifestPath, + string relativePath, + [MarshalAs(UnmanagedType.U1)] out bool indexModified); + + /// + /// Removes the manifest at the repository relative path from the index. + /// + /// Index handle. + /// Manifest path to remove. + /// Relative path in the container. + /// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetSQLiteIndexRemoveManifest(IntPtr index, string manifestPath, string relativePath); + + /// + /// Removes data that is no longer needed for an index that is to be published. + /// + /// Index handle. + /// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetSQLiteIndexPrepareForPackaging(IntPtr index); + + /// + /// Checks the index for consistency, ensuring that at a minimum all referenced rows actually exist. + /// + /// Index handle. + /// Does the consistency check succeeded. + /// HRESULT. + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetSQLiteIndexCheckConsistency(IntPtr index, [MarshalAs(UnmanagedType.U1)] out bool succeeded); + } +} diff --git a/src/WinGetUtilInterop/Api/WinGetUtilities.cs b/src/WinGetUtilInterop/Api/WinGetUtilities.cs new file mode 100644 index 0000000000..aca9b45e55 --- /dev/null +++ b/src/WinGetUtilInterop/Api/WinGetUtilities.cs @@ -0,0 +1,63 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Api +{ + using System; + using System.Runtime.InteropServices; + using Microsoft.WinGetUtil.Common; + using Microsoft.WinGetUtil.Exceptions; + using Microsoft.WinGetUtil.Interfaces; + + /// + /// Download wrapper. + /// + public sealed class WinGetUtilities : IWinGetUtilities + { + /// + public string Download(string url, string filePath, bool enableLogging = false, string logFilePath = null) + { + IWinGetLogging log = null; + if (enableLogging) + { + if (string.IsNullOrWhiteSpace(logFilePath)) + { + throw new ArgumentNullException($"Download logging is enabled and log file path `{logFilePath}` is not provided."); + } + + log = new WinGetFactory().LoggingInit(logFilePath); + } + + try + { + byte[] sha256Hash = new byte[32]; + WinGetDownload(url, filePath, sha256Hash, (uint)sha256Hash.Length); + return BitConverter.ToString(sha256Hash).Replace("-", string.Empty); + } + catch (Exception e) + { + throw new WinGetDownloadException(e); + } + finally + { + log?.Dispose(); + } + } + + /// + public int CompareVersions(string version1, string version2) + { + WinGetCompareVersions(version1, version2, out int result); + return result; + } + + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetDownload(string url, string filePath, [MarshalAs(UnmanagedType.LPArray)] byte[] sha26Hash, uint sha256HashLength); + + [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern IntPtr WinGetCompareVersions(string version1, string version2, [MarshalAs(UnmanagedType.U4)] out int comparisonResult); + } +} diff --git a/src/WinGetUtilInterop/Common/Constants.cs b/src/WinGetUtilInterop/Common/Constants.cs new file mode 100644 index 0000000000..5825be20ba --- /dev/null +++ b/src/WinGetUtilInterop/Common/Constants.cs @@ -0,0 +1,19 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Common +{ + /// + /// Constants. + /// + public static class Constants + { + /// + /// Dll name. + /// + public const string DllName = "WinGetUtil.dll"; + } +} diff --git a/src/WinGetUtilInterop/Common/CreateManifestResult.cs b/src/WinGetUtilInterop/Common/CreateManifestResult.cs new file mode 100644 index 0000000000..ae32a8eeab --- /dev/null +++ b/src/WinGetUtilInterop/Common/CreateManifestResult.cs @@ -0,0 +1,69 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Common +{ + using System; + using Microsoft.WinGetUtil.Interfaces; + + /// + /// Class representing create manifest result. + /// + public class CreateManifestResult : IDisposable + { + /// + /// Initializes a new instance of the class. + /// + /// Is manifest valid. + /// Warning or failure validation message. + /// Created manifest handle if succeeded. + public CreateManifestResult(bool isValid, string message, IWinGetManifest manifestHandle) + { + this.IsValid = isValid; + this.Message = message; + this.ManifestHandle = manifestHandle; + } + + /// + /// Gets a value indicating whether the manifest is valid. + /// + public bool IsValid { get; } = false; + + /// + /// Gets warning or failure validation message. + /// + public string Message { get; } = null; + + /// + /// Gets created manifest handle if succeeded. + /// + public IWinGetManifest ManifestHandle { get; } = null; + + /// + /// Dispose method. + /// + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Dispose method to free the manifest handle. + /// + /// Bool value indicating if Dispose is being run. + public void Dispose(bool disposing) + { + if (disposing) + { + if (this.ManifestHandle != null) + { + this.ManifestHandle.Dispose(); + } + } + } + } +} diff --git a/src/WinGetUtilInterop/Common/Enums.cs b/src/WinGetUtilInterop/Common/Enums.cs new file mode 100644 index 0000000000..c762f638dc --- /dev/null +++ b/src/WinGetUtilInterop/Common/Enums.cs @@ -0,0 +1,197 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Common +{ + using System; + + /// + /// Options for creating a manifest for validation. + /// Must be in sync with WinGetCreateManifestOption at: + /// https://github.com/microsoft/winget-cli/blob/master/src/WinGetUtil/WinGetUtil.h. + /// + [Flags] + public enum WinGetCreateManifestOption + { + /// + /// Just create the manifest without any validation + /// + NoValidation = 0, + + /// + /// Only validate against json schema + /// + SchemaValidation = 0x1, + + /// + /// Validate against schema and also perform semantic validation + /// + SchemaAndSemanticValidation = 0x2, + + // Below options are additional validation behaviors if needed + + /// + /// Return error on manifest fields that require verified publishers, used during semantic validation + /// + ReturnErrorOnVerifiedPublisherFields = 0x1000, + } + + /// + /// Options for validating a manifest. + /// Must be in sync with WinGetValidateManifestOptionV2 at: + /// https://github.com/microsoft/winget-cli/blob/master/src/WinGetUtil/WinGetUtil.h. + /// + [Flags] + public enum WinGetValidateManifestOptionV2 + { + /// + /// No validation, caller will get E_INVALIDARG + /// + None = 0, + + /// + /// Dependencies validation against index + /// + DependenciesValidation = 0x1, + + /// + /// Arp version validation against index + /// + ArpVersionValidation = 0x2, + + /// + /// Installer validation + /// + InstallerValidation = 0x4, + } + + /// + /// Operation type for validating a manifest. + /// Must be in sync with WinGetValidateManifestOperationType at: + /// https://github.com/microsoft/winget-cli/blob/master/src/WinGetUtil/WinGetUtil.h. + /// + public enum WinGetValidateManifestOperationType + { + /// + /// Add + /// + OperationTypeAdd = 0, + + /// + /// Update + /// + OperationTypeUpdate = 1, + + /// + /// Delete + /// + OperationTypeDelete = 2, + } + + /// + /// Manifest validation result. + /// Must be in sync with WinGetValidateManifestResult at: + /// https://github.com/microsoft/winget-cli/blob/master/src/WinGetUtil/WinGetUtil.h. + /// + [Flags] + public enum WinGetValidateManifestResult + { + /// + /// Manifest validation success. + /// + Success = 0, + + // Each validation step should have an enum for corresponding failure. + + /// + /// Dependencies validation failure. + /// + DependenciesValidationFailure = 0x1, + + /// + /// Arp version validation failure. + /// + ArpVersionValidationFailure = 0x2, + + /// + /// Installer validation failure. + /// + InstallerValidationFailure = 0x4, + + // Dependencies validation result. + + /// + /// Single Manifest package has dependencies. + /// + SingleManifestPackageHasDependencies = 0x10000, + + /// + /// Multi manifest package has dependencies. + /// + MultiManifestPackageHasDependencies = 0x20000, + + /// + /// Missing manifest dependencies node. + /// + MissingManifestDependenciesNode = 0x40000, + + /// + /// No Suitable min version found for manifest. + /// + NoSuitableMinVersionDependency = 0x80000, + + /// + /// Validation encountered a loop during dependencies validation. + /// + FoundDependencyLoop = 0x100000, + + // Internal error meaning validation does not complete as desired. + + /// + /// Manifest validation internal error. + /// + InternalError = 0x1000, + } + + /// + /// Option flags for WinGetBeginInstallerMetadataCollection. + /// + [Flags] + public enum WinGetBeginInstallerMetadataCollectionOptions + { + /// + /// None. + /// + WinGetBeginInstallerMetadataCollectionOption_None = 0, + + /// + /// The inputJSON is a local file path, not a JSON string. + /// + WinGetBeginInstallerMetadataCollectionOption_InputIsFilePath = 0x1, + + /// + /// The inputJSON is a remote URI, not a JSON string. + /// + WinGetBeginInstallerMetadataCollectionOption_InputIsURI = 0x2, + } + + /// + /// Option flags for WinGetCompleteInstallerMetadataCollection. + /// + [Flags] + public enum WinGetCompleteInstallerMetadataCollectionOptions + { + /// + /// Metadata collection option none. + /// + WinGetCompleteInstallerMetadataCollectionOption_None = 0, + + /// + /// Complete will simply free the collection handle without doing any additional work. + /// + WinGetCompleteInstallerMetadataCollectionOption_Abandon = 0x1, + } +} diff --git a/src/WinGetUtilInterop/Common/ManifestValidationResult.cs b/src/WinGetUtilInterop/Common/ManifestValidationResult.cs new file mode 100644 index 0000000000..d99efebc3d --- /dev/null +++ b/src/WinGetUtilInterop/Common/ManifestValidationResult.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Common +{ + /// + /// Manifest validation result. + /// + public class ManifestValidationResult + { + /// + /// Initializes a new instance of the class. + /// + /// A value indicating whether manifest is valid. + /// Error message. + /// Result code. + public ManifestValidationResult(bool isValid, string message, WinGetValidateManifestResult resultCode) + { + this.IsValid = isValid; + this.Message = message; + this.ResultCode = resultCode; + } + + /// + /// Gets a value indicating whether manifest is valid. + /// + public bool IsValid { get; private set; } + + /// + /// Gets the message associated with the validation. + /// + public string Message { get; private set; } + + /// + /// Gets the result code associate with the validation. + /// + public WinGetValidateManifestResult ResultCode { get; private set; } + } +} diff --git a/src/WinGetUtilInterop/Exceptions/WinGetDownloadException.cs b/src/WinGetUtilInterop/Exceptions/WinGetDownloadException.cs new file mode 100644 index 0000000000..e4a02c3235 --- /dev/null +++ b/src/WinGetUtilInterop/Exceptions/WinGetDownloadException.cs @@ -0,0 +1,51 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Exceptions +{ + using System; + + /// + /// Exception for download operations. + /// + public class WinGetDownloadException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public WinGetDownloadException() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Message. + public WinGetDownloadException(string message) + : base(message) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Inner exception. + public WinGetDownloadException(Exception inner) + : base(string.Empty, inner) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Message. + /// Inner exception. + public WinGetDownloadException(string message, Exception inner) + : base(message, inner) + { + } + } +} diff --git a/src/WinGetUtilInterop/Exceptions/WinGetInstallerMetadataException.cs b/src/WinGetUtilInterop/Exceptions/WinGetInstallerMetadataException.cs new file mode 100644 index 0000000000..3952825105 --- /dev/null +++ b/src/WinGetUtilInterop/Exceptions/WinGetInstallerMetadataException.cs @@ -0,0 +1,51 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Exceptions +{ + using System; + + /// + /// Exception for installer metadata operations. + /// + public class WinGetInstallerMetadataException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public WinGetInstallerMetadataException() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Message. + public WinGetInstallerMetadataException(string message) + : base(message) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Inner exception. + public WinGetInstallerMetadataException(Exception inner) + : base(string.Empty, inner) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Message. + /// Inner exception. + public WinGetInstallerMetadataException(string message, Exception inner) + : base(message, inner) + { + } + } +} diff --git a/src/WinGetUtilInterop/Exceptions/WinGetLoggingException.cs b/src/WinGetUtilInterop/Exceptions/WinGetLoggingException.cs new file mode 100644 index 0000000000..642a3622c2 --- /dev/null +++ b/src/WinGetUtilInterop/Exceptions/WinGetLoggingException.cs @@ -0,0 +1,51 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Exceptions +{ + using System; + + /// + /// Exception for logging operations. + /// + public class WinGetLoggingException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public WinGetLoggingException() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Message. + public WinGetLoggingException(string message) + : base(message) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Inner exception. + public WinGetLoggingException(Exception inner) + : base(string.Empty, inner) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Message. + /// Inner exception. + public WinGetLoggingException(string message, Exception inner) + : base(message, inner) + { + } + } +} diff --git a/src/WinGetUtilInterop/Exceptions/WinGetManifestException.cs b/src/WinGetUtilInterop/Exceptions/WinGetManifestException.cs new file mode 100644 index 0000000000..ea9d4ea1d5 --- /dev/null +++ b/src/WinGetUtilInterop/Exceptions/WinGetManifestException.cs @@ -0,0 +1,51 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Exceptions +{ + using System; + + /// + /// Exception for manifest operations. + /// + public class WinGetManifestException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public WinGetManifestException() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Message. + public WinGetManifestException(string message) + : base(message) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Inner exception. + public WinGetManifestException(Exception inner) + : base(string.Empty, inner) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Message. + /// Inner exception. + public WinGetManifestException(string message, Exception inner) + : base(message, inner) + { + } + } +} diff --git a/src/WinGetUtilInterop/Exceptions/WinGetSQLiteIndexException.cs b/src/WinGetUtilInterop/Exceptions/WinGetSQLiteIndexException.cs new file mode 100644 index 0000000000..7a8c0a066f --- /dev/null +++ b/src/WinGetUtilInterop/Exceptions/WinGetSQLiteIndexException.cs @@ -0,0 +1,51 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Exceptions +{ + using System; + + /// + /// Exception for SQLite index operations. + /// + public class WinGetSQLiteIndexException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public WinGetSQLiteIndexException() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Message. + public WinGetSQLiteIndexException(string message) + : base(message) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Inner exception. + public WinGetSQLiteIndexException(Exception inner) + : base(string.Empty, inner) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Message. + /// Inner exception. + public WinGetSQLiteIndexException(string message, Exception inner) + : base(message, inner) + { + } + } +} diff --git a/src/WinGetUtilInterop/Exceptions/WinGetUtilIndexException.cs b/src/WinGetUtilInterop/Exceptions/WinGetUtilIndexException.cs deleted file mode 100644 index 4a92e2b446..0000000000 --- a/src/WinGetUtilInterop/Exceptions/WinGetUtilIndexException.cs +++ /dev/null @@ -1,48 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// ----------------------------------------------------------------------- - -namespace WinGetUtilInterop.Exceptions -{ - using System; - - public class WinGetUtilIndexException : Exception - { - /// - /// Initializes a new instance of the class. - /// - public WinGetUtilIndexException() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Message. - public WinGetUtilIndexException(string message) - : base(message) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Inner exception. - public WinGetUtilIndexException(Exception inner) - : base(string.Empty, inner) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Message. - /// Inner exception. - public WinGetUtilIndexException(string message, Exception inner) - : base(message, inner) - { - } - } -} diff --git a/src/WinGetUtilInterop/Helpers/WinGetUtilWrapperManifest.cs b/src/WinGetUtilInterop/Helpers/WinGetUtilWrapperManifest.cs deleted file mode 100644 index 945ec9c7b1..0000000000 --- a/src/WinGetUtilInterop/Helpers/WinGetUtilWrapperManifest.cs +++ /dev/null @@ -1,77 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. Licensed under the MIT License. -// -// ----------------------------------------------------------------------- - -namespace Microsoft.WinGetUtil.Helpers -{ - using System; - using System.Runtime.InteropServices; - - /// - /// Wrapper class around WinGetUtil manifest native implementation. - /// For dll entry points are defined here: - /// https://github.com/microsoft/winget-cli/blob/master/src/WinGetUtil/WinGetUtil.h. - /// - public sealed class WinGetUtilWrapperManifest - { - /// - /// The error from the installer. - /// Must be in sync with WinGetValidateManifestOption at: - /// https://github.com/microsoft/winget-cli/blob/master/src/WinGetUtil/WinGetUtil.h. - /// - public enum ValidateManifestOption - { - /// - /// Default validation behavior. - /// - Default, - - /// - /// Schema validation only. - /// - SchemaValidationOnly, - } - - /// - /// Validates the manifest is compliant. - /// - /// Manifest path. - /// Merged manifest output path. - /// Desired validate manifest option. - /// Message from manifest validation. - public static (bool isValid, string message) ValidateManifest( - string manifestPath, - string mergedManifestPath = null, - ValidateManifestOption option = ValidateManifestOption.Default) - { - WinGetValidateManifestV2( - manifestPath, - out bool succeeded, - out string failureOrWarningMessage, - mergedManifestPath, - option); - - return (succeeded, failureOrWarningMessage); - } - - /// - /// Validates a given manifest. Returns a bool for validation result and - /// a string representing validation errors if validation failed. - /// - /// Path to manifest file. - /// Out bool is validation succeeded. - /// Out string failure message, if any. - /// Path to merged manifest file. Empty means no merged manifest needed. - /// Validate manifest option. - /// HRESULT. - [DllImport("WinGetUtil.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)] - private static extern IntPtr WinGetValidateManifestV2( - string manifestPath, - [MarshalAs(UnmanagedType.U1)] out bool succeeded, - [MarshalAs(UnmanagedType.BStr)] out string failureMessage, - string mergedManifestPath, - ValidateManifestOption option); - } -} diff --git a/src/WinGetUtilInterop/Interfaces/IWinGetFactory.cs b/src/WinGetUtilInterop/Interfaces/IWinGetFactory.cs new file mode 100644 index 0000000000..8e450ca5de --- /dev/null +++ b/src/WinGetUtilInterop/Interfaces/IWinGetFactory.cs @@ -0,0 +1,55 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Interfaces +{ + using Microsoft.WinGetUtil.Common; + + /// + /// Factory methods. + /// + public interface IWinGetFactory + { + /// + /// Creates a new index file in the specified path. + /// + /// Index file to create. + /// Major version. + /// Minor version. + /// Instance of IWinGetSQLiteIndex. + IWinGetSQLiteIndex SQLiteIndexCreate(string indexFile, uint majorVersion, uint minorVersion); + + /// + /// Creates a new index file in the specified path. + /// + /// Index file to create. + /// Instance of IWinGetSQLiteIndex. + IWinGetSQLiteIndex SQLiteIndexCreateLatestVersion(string indexFile); + + /// + /// Open the index file. + /// + /// Index file to open. + /// Instance of IWinGetSQLiteIndex. + IWinGetSQLiteIndex SQLiteIndexOpen(string indexFile); + + /// + /// Initializes logging. + /// + /// Log index file. + /// Instance of IWinGetLogging. + IWinGetLogging LoggingInit(string logFile); + + /// + /// Validates the manifest is compliant and creates a manifest handle if succeeded. + /// + /// Manifest path. + /// Merged manifest output path. + /// Desired validate manifest option. + /// The class. + CreateManifestResult CreateManifest(string manifestPath, string mergedManifestPath, WinGetCreateManifestOption option); + } +} diff --git a/src/WinGetUtilInterop/Interfaces/IWinGetInstallerMetadata.cs b/src/WinGetUtilInterop/Interfaces/IWinGetInstallerMetadata.cs new file mode 100644 index 0000000000..9b1ba8ebee --- /dev/null +++ b/src/WinGetUtilInterop/Interfaces/IWinGetInstallerMetadata.cs @@ -0,0 +1,22 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Interfaces +{ + using System; + + /// + /// Interface for installer metadata collection. + /// + public interface IWinGetInstallerMetadata : IDisposable + { + /// + /// Completes the installer metadata collection process. + /// + /// True to abandon the operation. + void Complete(bool abandon = false); + } +} diff --git a/src/WinGetUtilInterop/Interfaces/IWinGetLogging.cs b/src/WinGetUtilInterop/Interfaces/IWinGetLogging.cs new file mode 100644 index 0000000000..513cbde9f3 --- /dev/null +++ b/src/WinGetUtilInterop/Interfaces/IWinGetLogging.cs @@ -0,0 +1,17 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Interfaces +{ + using System; + + /// + /// Logger interface. + /// + public interface IWinGetLogging : IDisposable + { + } +} diff --git a/src/WinGetUtilInterop/Interfaces/IWinGetManifest.cs b/src/WinGetUtilInterop/Interfaces/IWinGetManifest.cs new file mode 100644 index 0000000000..8e1f604e85 --- /dev/null +++ b/src/WinGetUtilInterop/Interfaces/IWinGetManifest.cs @@ -0,0 +1,29 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Interfaces +{ + using System; + using Microsoft.WinGetUtil.Common; + + /// + /// Interface for Wrapper class around WinGetUtil index modifier native implementation. + /// + public interface IWinGetManifest : IDisposable + { + /// + /// Validate the manifest. + /// + /// The index handle. + /// Manifest validation option. + /// Manifest validation operation type. + /// Result and message from manifest validation. + ManifestValidationResult ValidateManifestV3( + IntPtr indexHandle, + WinGetValidateManifestOptionV2 option, + WinGetValidateManifestOperationType operationType); + } +} diff --git a/src/WinGetUtilInterop/Interfaces/IWinGetUtilIndex.cs b/src/WinGetUtilInterop/Interfaces/IWinGetSQLiteIndex.cs similarity index 88% rename from src/WinGetUtilInterop/Interfaces/IWinGetUtilIndex.cs rename to src/WinGetUtilInterop/Interfaces/IWinGetSQLiteIndex.cs index f73920191c..d5147b0163 100644 --- a/src/WinGetUtilInterop/Interfaces/IWinGetUtilIndex.cs +++ b/src/WinGetUtilInterop/Interfaces/IWinGetSQLiteIndex.cs @@ -1,52 +1,55 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. Licensed under the MIT License. -// -// ----------------------------------------------------------------------- - -namespace Microsoft.WinGetUtil.Interfaces -{ - using System; - - public interface IWinGetUtilIndex : IDisposable - { - /// - /// Adds manifest to index. - /// - /// Manifest to add. - /// Path of the manifest in the repository. - void AddManifest(string manifestPath, string relativePath); - - /// - /// Updates manifest in the index. - /// - /// Path to manifest to modify. - /// Path of the manifest in the repository. - /// True if index was modified. - bool UpdateManifest(string manifestPath, string relativePath); - - /// - /// Delete manifest from index. - /// - /// Path to manifest to modify. - /// Path of the manifest in the repository. - void RemoveManifest(string manifestPath, string relativePath); - - /// - /// Wrapper for WinGetSQLiteIndexPrepareForPackaging. - /// - void PrepareForPackaging(); - - /// - /// Checks the index for consistency, ensuring that at a minimum all referenced rows actually exist. - /// - /// Is index consistent. - bool IsIndexConsistent(); - - /// - /// Gets the managed index handle. It is used in additional manifest validation that requires an index. - /// - /// The managed index handle. - IntPtr GetIndexHandle(); - } -} +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Interfaces +{ + using System; + + /// + /// Interface for index operations. + /// + public interface IWinGetSQLiteIndex : IDisposable + { + /// + /// Adds manifest to index. + /// + /// Manifest to add. + /// Path of the manifest in the repository. + void AddManifest(string manifestPath, string relativePath); + + /// + /// Updates manifest in the index. + /// + /// Path to manifest to modify. + /// Path of the manifest in the repository. + /// True if index was modified. + bool UpdateManifest(string manifestPath, string relativePath); + + /// + /// Delete manifest from index. + /// + /// Path to manifest to modify. + /// Path of the manifest in the repository. + void RemoveManifest(string manifestPath, string relativePath); + + /// + /// Wrapper for WinGetSQLiteIndexPrepareForPackaging. + /// + void PrepareForPackaging(); + + /// + /// Checks the index for consistency, ensuring that at a minimum all referenced rows actually exist. + /// + /// Is index consistent. + bool IsIndexConsistent(); + + /// + /// Gets the managed index handle. It is used in additional manifest validation that requires an index. + /// + /// The managed index handle. + IntPtr GetIndexHandle(); + } +} diff --git a/src/WinGetUtilInterop/Interfaces/IWinGetUtilities.cs b/src/WinGetUtilInterop/Interfaces/IWinGetUtilities.cs new file mode 100644 index 0000000000..257edd21e3 --- /dev/null +++ b/src/WinGetUtilInterop/Interfaces/IWinGetUtilities.cs @@ -0,0 +1,32 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGetUtil.Interfaces +{ + /// + /// Winget Util utilities interface. + /// + public interface IWinGetUtilities + { + /// + /// Download a file from URL. + /// + /// Installer url. + /// Destination file path. + /// Enable logging. + /// Log file path. + /// SHA256 of the installer. + string Download(string url, string filePath, bool enableLogging = false, string logFilePath = null); + + /// + /// Compare two version. + /// + /// Version 1. + /// Version 2. + /// Integer value indicating the comparison result. + int CompareVersions(string version1, string version2); + } +} diff --git a/src/WinGetUtilInterop/Manifest/Preview/InstallerSwitches.cs b/src/WinGetUtilInterop/Manifest/Preview/InstallerSwitches.cs index e5f59c73bf..e7cdf9ac11 100644 --- a/src/WinGetUtilInterop/Manifest/Preview/InstallerSwitches.cs +++ b/src/WinGetUtilInterop/Manifest/Preview/InstallerSwitches.cs @@ -1,13 +1,12 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.Preview { using System; - using System.Runtime.CompilerServices; /// /// Class that contains different types of installer switches like Default, Silent and Verbose. diff --git a/src/WinGetUtilInterop/Manifest/Preview/Manifest.cs b/src/WinGetUtilInterop/Manifest/Preview/Manifest.cs index 78da8ff40f..c3579d3f32 100644 --- a/src/WinGetUtilInterop/Manifest/Preview/Manifest.cs +++ b/src/WinGetUtilInterop/Manifest/Preview/Manifest.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.Preview { diff --git a/src/WinGetUtilInterop/Manifest/Preview/ManifestInstaller.cs b/src/WinGetUtilInterop/Manifest/Preview/ManifestInstaller.cs index d4d388f3cf..2038654579 100644 --- a/src/WinGetUtilInterop/Manifest/Preview/ManifestInstaller.cs +++ b/src/WinGetUtilInterop/Manifest/Preview/ManifestInstaller.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.Preview { diff --git a/src/WinGetUtilInterop/Manifest/Preview/ManifestLocalization.cs b/src/WinGetUtilInterop/Manifest/Preview/ManifestLocalization.cs index dc9b6b25c6..0a6203c310 100644 --- a/src/WinGetUtilInterop/Manifest/Preview/ManifestLocalization.cs +++ b/src/WinGetUtilInterop/Manifest/Preview/ManifestLocalization.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.Preview { diff --git a/src/WinGetUtilInterop/Manifest/V1/InstallerArpEntry.cs b/src/WinGetUtilInterop/Manifest/V1/InstallerArpEntry.cs index 7763818836..e610d2484c 100644 --- a/src/WinGetUtilInterop/Manifest/V1/InstallerArpEntry.cs +++ b/src/WinGetUtilInterop/Manifest/V1/InstallerArpEntry.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { diff --git a/src/WinGetUtilInterop/Manifest/V1/InstallerDependency.cs b/src/WinGetUtilInterop/Manifest/V1/InstallerDependency.cs index 2fd9729978..b38efbba33 100644 --- a/src/WinGetUtilInterop/Manifest/V1/InstallerDependency.cs +++ b/src/WinGetUtilInterop/Manifest/V1/InstallerDependency.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { diff --git a/src/WinGetUtilInterop/Manifest/V1/InstallerExpectedReturnCode.cs b/src/WinGetUtilInterop/Manifest/V1/InstallerExpectedReturnCode.cs index 468768ca67..288d8b0b24 100644 --- a/src/WinGetUtilInterop/Manifest/V1/InstallerExpectedReturnCode.cs +++ b/src/WinGetUtilInterop/Manifest/V1/InstallerExpectedReturnCode.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { diff --git a/src/WinGetUtilInterop/Manifest/V1/InstallerInstallationMetadata.cs b/src/WinGetUtilInterop/Manifest/V1/InstallerInstallationMetadata.cs index 68b017e845..9102b1f958 100644 --- a/src/WinGetUtilInterop/Manifest/V1/InstallerInstallationMetadata.cs +++ b/src/WinGetUtilInterop/Manifest/V1/InstallerInstallationMetadata.cs @@ -1,15 +1,16 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { - using System; using System.Collections.Generic; - using System.Text; + /// + /// Installation metadata. + /// public class InstallerInstallationMetadata { /// diff --git a/src/WinGetUtilInterop/Manifest/V1/InstallerMarkets.cs b/src/WinGetUtilInterop/Manifest/V1/InstallerMarkets.cs index d0652ca21c..1483b41ea0 100644 --- a/src/WinGetUtilInterop/Manifest/V1/InstallerMarkets.cs +++ b/src/WinGetUtilInterop/Manifest/V1/InstallerMarkets.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { diff --git a/src/WinGetUtilInterop/Manifest/V1/InstallerNestedInstallerFile.cs b/src/WinGetUtilInterop/Manifest/V1/InstallerNestedInstallerFile.cs index 89842ac75f..6402288d4d 100644 --- a/src/WinGetUtilInterop/Manifest/V1/InstallerNestedInstallerFile.cs +++ b/src/WinGetUtilInterop/Manifest/V1/InstallerNestedInstallerFile.cs @@ -1,9 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Text; +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { + /// + /// Installer nested installer file. + /// public class InstallerNestedInstallerFile { /// @@ -12,7 +17,7 @@ public class InstallerNestedInstallerFile public string RelativeFilePath { get; set; } /// - /// Gets or set portable command alias. + /// Gets or sets portable command alias. /// public string PortableCommandAlias { get; set; } } diff --git a/src/WinGetUtilInterop/Manifest/V1/InstallerPackageDependency.cs b/src/WinGetUtilInterop/Manifest/V1/InstallerPackageDependency.cs index 2ee747fed2..9c1f24899a 100644 --- a/src/WinGetUtilInterop/Manifest/V1/InstallerPackageDependency.cs +++ b/src/WinGetUtilInterop/Manifest/V1/InstallerPackageDependency.cs @@ -1,13 +1,11 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { - using System; - /// /// Class that contains package dependency from same source. /// diff --git a/src/WinGetUtilInterop/Manifest/V1/InstallerSwitches.cs b/src/WinGetUtilInterop/Manifest/V1/InstallerSwitches.cs index b2de9a9c92..70e310ba80 100644 --- a/src/WinGetUtilInterop/Manifest/V1/InstallerSwitches.cs +++ b/src/WinGetUtilInterop/Manifest/V1/InstallerSwitches.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { diff --git a/src/WinGetUtilInterop/Manifest/V1/Manifest.cs b/src/WinGetUtilInterop/Manifest/V1/Manifest.cs index ad69ecc1df..990f7b9f30 100644 --- a/src/WinGetUtilInterop/Manifest/V1/Manifest.cs +++ b/src/WinGetUtilInterop/Manifest/V1/Manifest.cs @@ -1,15 +1,13 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { - using System; using System.Collections.Generic; using System.IO; - using System.Linq; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; @@ -137,7 +135,7 @@ public class Manifest /// Gets or sets the release notes in default locale. /// public string ReleaseNotes { get; set; } - + /// /// Gets or sets the manifest documentation. /// diff --git a/src/WinGetUtilInterop/Manifest/V1/ManifestDocumentation.cs b/src/WinGetUtilInterop/Manifest/V1/ManifestDocumentation.cs index ef0c2ccee4..565c5b34fd 100644 --- a/src/WinGetUtilInterop/Manifest/V1/ManifestDocumentation.cs +++ b/src/WinGetUtilInterop/Manifest/V1/ManifestDocumentation.cs @@ -1,15 +1,14 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { - using System; - using System.Collections.Generic; - using System.Text; - + /// + /// Manifest documentation. + /// public class ManifestDocumentation { /// @@ -21,6 +20,5 @@ public class ManifestDocumentation /// Gets or sets the document url. /// public string DocumentUrl { get; set; } - } } diff --git a/src/WinGetUtilInterop/Manifest/V1/ManifestIcon.cs b/src/WinGetUtilInterop/Manifest/V1/ManifestIcon.cs index 44af5b20bc..4007d87a11 100644 --- a/src/WinGetUtilInterop/Manifest/V1/ManifestIcon.cs +++ b/src/WinGetUtilInterop/Manifest/V1/ManifestIcon.cs @@ -1,15 +1,14 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. All rights reserved. +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { - using System; - using System.Collections.Generic; - using System.Text; - + /// + /// Icon information. + /// public class ManifestIcon { /// diff --git a/src/WinGetUtilInterop/Manifest/V1/ManifestInstaller.cs b/src/WinGetUtilInterop/Manifest/V1/ManifestInstaller.cs index b390e04731..c042a01652 100644 --- a/src/WinGetUtilInterop/Manifest/V1/ManifestInstaller.cs +++ b/src/WinGetUtilInterop/Manifest/V1/ManifestInstaller.cs @@ -1,12 +1,11 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { - using System; using System.Collections.Generic; using YamlDotNet.Serialization; @@ -256,9 +255,9 @@ public bool Equals(ManifestInstaller other) (this.InstallerLocale == other.InstallerLocale) && (this.Scope == other.Scope) && (this.InstallerType == other.InstallerType) && - (this.Switches == other.Switches) && + (this.Switches == other.Switches) && (this.InstallationMetadata == other.InstallationMetadata) && - (this.NestedInstallerType == other.NestedInstallerType) && + (this.NestedInstallerType == other.NestedInstallerType) && (this.NestedInstallerFiles == other.NestedInstallerFiles) && (this.DisplayInstallWarnings == other.DisplayInstallWarnings); } diff --git a/src/WinGetUtilInterop/Manifest/V1/ManifestInstallerFile.cs b/src/WinGetUtilInterop/Manifest/V1/ManifestInstallerFile.cs index 03f736f935..5031a01ea7 100644 --- a/src/WinGetUtilInterop/Manifest/V1/ManifestInstallerFile.cs +++ b/src/WinGetUtilInterop/Manifest/V1/ManifestInstallerFile.cs @@ -1,15 +1,11 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. All rights reserved. +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { - using System; - using System.Collections.Generic; - using System.Text; - /// /// Represents an installer file. /// diff --git a/src/WinGetUtilInterop/Manifest/V1/ManifestLocalization.cs b/src/WinGetUtilInterop/Manifest/V1/ManifestLocalization.cs index 4cb666ae94..a9b5c3f706 100644 --- a/src/WinGetUtilInterop/Manifest/V1/ManifestLocalization.cs +++ b/src/WinGetUtilInterop/Manifest/V1/ManifestLocalization.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { diff --git a/src/WinGetUtilInterop/Manifest/V1/MinManifestInfo.cs b/src/WinGetUtilInterop/Manifest/V1/MinManifestInfo.cs index 8132344ac1..66ef5309e2 100644 --- a/src/WinGetUtilInterop/Manifest/V1/MinManifestInfo.cs +++ b/src/WinGetUtilInterop/Manifest/V1/MinManifestInfo.cs @@ -1,12 +1,11 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { - using System; using System.IO; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; diff --git a/src/WinGetUtilInterop/Manifest/V1/PackageAgreement.cs b/src/WinGetUtilInterop/Manifest/V1/PackageAgreement.cs index d5b95ce3c6..41c2fc986f 100644 --- a/src/WinGetUtilInterop/Manifest/V1/PackageAgreement.cs +++ b/src/WinGetUtilInterop/Manifest/V1/PackageAgreement.cs @@ -1,8 +1,8 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. // -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace Microsoft.WinGetUtil.Models.V1 { diff --git a/src/WinGetUtilInterop/WinGetUtilInterop.csproj b/src/WinGetUtilInterop/WinGetUtilInterop.csproj index 773d3e6fdb..6b66270457 100644 --- a/src/WinGetUtilInterop/WinGetUtilInterop.csproj +++ b/src/WinGetUtilInterop/WinGetUtilInterop.csproj @@ -1,14 +1,18 @@  - netstandard2.0 + netstandard2.1 + Microsoft.WinGetUtil - + + + all +