commit 76e1f563018c963e55362145a4529d04da74ea22 parent 9d57d6381fa8fc182b2f446528e51f670fce4bbc Author: JohnMcPMS <johnmcp@microsoft.com> Date: Fri, 10 Jan 2020 17:13:55 -0800 Create SQLite index utility binary (#19) Diffstat:
21 files changed, 549 insertions(+), 21 deletions(-)
diff --git a/src/AppInstallerCLI.sln b/src/AppInstallerCLI.sln @@ -27,6 +27,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "YamlCppLib", "YamlCppLib\Ya EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AppInstallerCommonCore", "AppInstallerCommonCore\AppInstallerCommonCore.vcxproj", "{5890D6ED-7C3B-40F3-B436-B54F640D9E65}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AppInstallerSQLiteIndexUtil", "AppInstallerSQLiteIndexUtil\AppInstallerSQLiteIndexUtil.vcxproj", "{FB313532-38B0-4676-9303-AB200AA13576}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution catch2\catch2.vcxitems*{5295e21e-9868-4de2-a177-fbb97b36579b}*SharedItemsImports = 9 @@ -159,6 +161,22 @@ Global {5890D6ED-7C3B-40F3-B436-B54F640D9E65}.Release|x64.Build.0 = Release|x64 {5890D6ED-7C3B-40F3-B436-B54F640D9E65}.Release|x86.ActiveCfg = Release|Win32 {5890D6ED-7C3B-40F3-B436-B54F640D9E65}.Release|x86.Build.0 = Release|Win32 + {FB313532-38B0-4676-9303-AB200AA13576}.Debug|ARM.ActiveCfg = Debug|ARM + {FB313532-38B0-4676-9303-AB200AA13576}.Debug|ARM.Build.0 = Debug|ARM + {FB313532-38B0-4676-9303-AB200AA13576}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {FB313532-38B0-4676-9303-AB200AA13576}.Debug|ARM64.Build.0 = Debug|ARM64 + {FB313532-38B0-4676-9303-AB200AA13576}.Debug|x64.ActiveCfg = Debug|x64 + {FB313532-38B0-4676-9303-AB200AA13576}.Debug|x64.Build.0 = Debug|x64 + {FB313532-38B0-4676-9303-AB200AA13576}.Debug|x86.ActiveCfg = Debug|Win32 + {FB313532-38B0-4676-9303-AB200AA13576}.Debug|x86.Build.0 = Debug|Win32 + {FB313532-38B0-4676-9303-AB200AA13576}.Release|ARM.ActiveCfg = Release|ARM + {FB313532-38B0-4676-9303-AB200AA13576}.Release|ARM.Build.0 = Release|ARM + {FB313532-38B0-4676-9303-AB200AA13576}.Release|ARM64.ActiveCfg = Release|ARM64 + {FB313532-38B0-4676-9303-AB200AA13576}.Release|ARM64.Build.0 = Release|ARM64 + {FB313532-38B0-4676-9303-AB200AA13576}.Release|x64.ActiveCfg = Release|x64 + {FB313532-38B0-4676-9303-AB200AA13576}.Release|x64.Build.0 = Release|x64 + {FB313532-38B0-4676-9303-AB200AA13576}.Release|x86.ActiveCfg = Release|Win32 + {FB313532-38B0-4676-9303-AB200AA13576}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/AppInstallerCLITests/YamlManifest.cpp b/src/AppInstallerCLITests/YamlManifest.cpp @@ -7,7 +7,7 @@ using namespace AppInstaller::Manifest; TEST_CASE("ReadGoodManifestAndVerifyContents", "[PackageManifestHelper]") { - Manifest manifest = Manifest::CreatePackageManifestFromFile("GoodManifest.yml"); + Manifest manifest = Manifest::CreateFromPath("GoodManifest.yml"); REQUIRE(manifest.Id == "microsoft.msixsdk"); REQUIRE(manifest.Name == "MSIX SDK"); @@ -71,5 +71,5 @@ TEST_CASE("ReadGoodManifestAndVerifyContents", "[PackageManifestHelper]") TEST_CASE("ReadBadManifestAndVerifyThrow", "[PackageManifestHelper]") { - REQUIRE_THROWS_WITH(Manifest::CreatePackageManifestFromFile("BadManifest-MissingName.yml"), "invalid node; first invalid key: \"Name\""); + REQUIRE_THROWS_WITH(Manifest::CreateFromPath("BadManifest-MissingName.yml"), "invalid node; first invalid key: \"Name\""); } diff --git a/src/AppInstallerRepositoryCore/Manifest/InstallerSwitches.cpp b/src/AppInstallerRepositoryCore/Manifest/InstallerSwitches.cpp @@ -6,7 +6,7 @@ namespace AppInstaller::Manifest { - void InstallerSwitches::PopulateSwitchesFields(YAML::Node switchesNode) + void InstallerSwitches::PopulateSwitchesFields(const YAML::Node& switchesNode) { this->Default = switchesNode["Default"] ? switchesNode["Default"].as<std::string>() : ""; this->Silent = switchesNode["Silent"] ? switchesNode["Silent"].as<std::string>() : ""; diff --git a/src/AppInstallerRepositoryCore/Manifest/InstallerSwitches.h b/src/AppInstallerRepositoryCore/Manifest/InstallerSwitches.h @@ -1,8 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. - #pragma once #include <string> + +namespace YAML { class Node; } + namespace AppInstaller::Manifest { class InstallerSwitches @@ -14,6 +16,6 @@ namespace AppInstaller::Manifest std::string Verbose; - void PopulateSwitchesFields(YAML::Node switchesNode); + void PopulateSwitchesFields(const YAML::Node& switchesNode); }; } \ No newline at end of file diff --git a/src/AppInstallerRepositoryCore/Manifest/Manifest.cpp b/src/AppInstallerRepositoryCore/Manifest/Manifest.cpp @@ -1,6 +1,5 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. - #include "pch.h" #include "Manifest.h" @@ -58,9 +57,9 @@ namespace AppInstaller::Manifest } } - Manifest Manifest::CreatePackageManifestFromFile(const std::string& inputFile) + Manifest Manifest::CreateFromPath(const std::filesystem::path& inputFile) { - YAML::Node rootNode = YAML::LoadFile(inputFile); + YAML::Node rootNode = YAML::LoadFile(inputFile.u8string()); Manifest manifest; manifest.PopulateManifestFields(rootNode); @@ -68,7 +67,7 @@ namespace AppInstaller::Manifest return manifest; } - Manifest Manifest::CreatePackageManifest(const std::string& input) + Manifest Manifest::Create(const std::string& input) { Manifest manifest; diff --git a/src/AppInstallerRepositoryCore/Manifest/Manifest.h b/src/AppInstallerRepositoryCore/Manifest/Manifest.h @@ -1,13 +1,14 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. - #pragma once -#include <string> -#include <vector> -#include <optional> #include "ManifestInstaller.h" #include "ManifestLocalization.h" +#include <filesystem> +#include <string> +#include <optional> +#include <vector> + namespace AppInstaller::Manifest { // Our representation of the parsed manifest file. @@ -66,8 +67,8 @@ namespace AppInstaller::Manifest void PopulateManifestFields(const YAML::Node& rootNode); - static Manifest CreatePackageManifestFromFile(const std::string& inputFile); + static Manifest CreateFromPath(const std::filesystem::path& inputFile); - static Manifest CreatePackageManifest(const std::string& input); + static Manifest Create(const std::string& input); }; } \ No newline at end of file diff --git a/src/AppInstallerRepositoryCore/Manifest/ManifestInstaller.cpp b/src/AppInstallerRepositoryCore/Manifest/ManifestInstaller.cpp @@ -6,7 +6,7 @@ namespace AppInstaller::Manifest { - void ManifestInstaller::PopulateInstallerFields(YAML::Node installerNode) + void ManifestInstaller::PopulateInstallerFields(const YAML::Node& installerNode) { // Required fields this->Arch = installerNode["Arch"].as<std::string>(); diff --git a/src/AppInstallerRepositoryCore/Manifest/ManifestInstaller.h b/src/AppInstallerRepositoryCore/Manifest/ManifestInstaller.h @@ -1,6 +1,5 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. - #pragma once #include <string> #include <optional> @@ -32,6 +31,6 @@ namespace AppInstaller::Manifest // If present, has more presedence than root std::optional<InstallerSwitches> Switches; - void PopulateInstallerFields(YAML::Node installerNode); + void PopulateInstallerFields(const YAML::Node& installerNode); }; } \ No newline at end of file diff --git a/src/AppInstallerRepositoryCore/Manifest/ManifestLocalization.cpp b/src/AppInstallerRepositoryCore/Manifest/ManifestLocalization.cpp @@ -6,7 +6,7 @@ namespace AppInstaller::Manifest { - void ManifestLocalization::PopulateLocalizationFields(YAML::Node localizationNode) + void ManifestLocalization::PopulateLocalizationFields(const YAML::Node& localizationNode) { // Required this->Language = localizationNode["Language"].as<std::string>(); diff --git a/src/AppInstallerRepositoryCore/Manifest/ManifestLocalization.h b/src/AppInstallerRepositoryCore/Manifest/ManifestLocalization.h @@ -1,9 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. - #pragma once #include <string> +namespace YAML { class Node; } + namespace AppInstaller::Manifest { class ManifestLocalization @@ -18,6 +19,6 @@ namespace AppInstaller::Manifest std::string LicenseUrl; - void PopulateLocalizationFields(YAML::Node localizationNode); + void PopulateLocalizationFields(const YAML::Node& localizationNode); }; } \ No newline at end of file diff --git a/src/AppInstallerRepositoryCore/Microsoft/SQLiteIndex.cpp b/src/AppInstallerRepositoryCore/Microsoft/SQLiteIndex.cpp @@ -118,4 +118,46 @@ namespace AppInstaller::Repository::Microsoft m_interface = version.CreateISQLiteIndex(); m_version = m_interface->GetVersion(); } + + void SQLiteIndex::AddManifest(const std::filesystem::path& manifestPath, const std::filesystem::path& relativePath) + { + Manifest::Manifest manifest = Manifest::Manifest::CreateFromPath(manifestPath); + AddManifest(manifest, relativePath); + } + + void SQLiteIndex::AddManifest(const Manifest::Manifest& manifest, const std::filesystem::path& relativePath) + { + UNREFERENCED_PARAMETER(manifest); + UNREFERENCED_PARAMETER(relativePath); + THROW_HR(E_NOTIMPL); + } + + void SQLiteIndex::UpdateManifest(const std::filesystem::path& oldManifestPath, const std::filesystem::path& oldRelativePath, const std::filesystem::path& newManifestPath, const std::filesystem::path& newRelativePath) + { + Manifest::Manifest oldManifest = Manifest::Manifest::CreateFromPath(oldManifestPath); + Manifest::Manifest newManifest = Manifest::Manifest::CreateFromPath(newManifestPath); + UpdateManifest(oldManifest, oldRelativePath, newManifest, newRelativePath); + } + + void SQLiteIndex::UpdateManifest(const Manifest::Manifest& oldManifest, const std::filesystem::path& oldRelativePath, const Manifest::Manifest& newManifest, const std::filesystem::path& newRelativePath) + { + UNREFERENCED_PARAMETER(oldManifest); + UNREFERENCED_PARAMETER(oldRelativePath); + UNREFERENCED_PARAMETER(newManifest); + UNREFERENCED_PARAMETER(newRelativePath); + THROW_HR(E_NOTIMPL); + } + + void SQLiteIndex::RemoveManifest(const std::filesystem::path& manifestPath, const std::filesystem::path& relativePath) + { + Manifest::Manifest manifest = Manifest::Manifest::CreateFromPath(manifestPath); + RemoveManifest(manifest, relativePath); + } + + void SQLiteIndex::RemoveManifest(const Manifest::Manifest& manifest, const std::filesystem::path& relativePath) + { + UNREFERENCED_PARAMETER(manifest); + UNREFERENCED_PARAMETER(relativePath); + THROW_HR(E_NOTIMPL); + } } diff --git a/src/AppInstallerRepositoryCore/Microsoft/SQLiteIndex.h b/src/AppInstallerRepositoryCore/Microsoft/SQLiteIndex.h @@ -42,13 +42,23 @@ namespace AppInstaller::Repository::Microsoft Schema::Version GetVersion() const { return m_version; } // Adds the manifest at the repository relative path to the index. + void AddManifest(const std::filesystem::path& manifestPath, const std::filesystem::path& relativePath); + + // Adds the manifest at the repository relative path to the index. void AddManifest(const Manifest::Manifest& manifest, const std::filesystem::path& relativePath); // Updates the manifest at the repository relative path in the index. // If the old manifest does not exist in the index, this is equivalent to AddManifest(newManifest, newRelativePath). + void UpdateManifest(const std::filesystem::path& oldManifestPath, const std::filesystem::path& oldRelativePath, const std::filesystem::path& newManifestPath, const std::filesystem::path& newRelativePath); + + // Updates the manifest at the repository relative path in the index. + // If the old manifest does not exist in the index, this is equivalent to AddManifest(newManifest, newRelativePath). void UpdateManifest(const Manifest::Manifest& oldManifest, const std::filesystem::path& oldRelativePath, const Manifest::Manifest& newManifest, const std::filesystem::path& newRelativePath); // Removes the manifest at the repository relative path from the index. + void RemoveManifest(const std::filesystem::path& manifestPath, const std::filesystem::path& relativePath); + + // Removes the manifest at the repository relative path from the index. void RemoveManifest(const Manifest::Manifest& manifest, const std::filesystem::path& relativePath); private: diff --git a/src/AppInstallerSQLiteIndexUtil/AppInstallerSQLiteIndexUtil.h b/src/AppInstallerSQLiteIndexUtil/AppInstallerSQLiteIndexUtil.h @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#pragma once + +extern "C" +{ + // A handle to the index. + typedef void* APPINSTALLER_SQLITE_INDEX_HANDLE; + + // A string taken in by the utility; in UTF16. + typedef wchar_t const* const APPINSTALLER_SQLITE_INDEX_STRING; + +#define APPINSTALLER_SQLITE_INDEX_API HRESULT __stdcall + +#define APPINSTALLER_SQLITE_INDEX_VERSION_LATEST ((UINT32)-1) + + // Creates a new index file at filePath with the given version. + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexCreate( + APPINSTALLER_SQLITE_INDEX_STRING filePath, + UINT32 majorVersion, + UINT32 minorVersion, + APPINSTALLER_SQLITE_INDEX_HANDLE* index); + + // Opens an existing index at filePath. + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexOpen( + APPINSTALLER_SQLITE_INDEX_STRING filePath, + APPINSTALLER_SQLITE_INDEX_HANDLE* index); + + // Closes the index. + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexClose( + APPINSTALLER_SQLITE_INDEX_HANDLE index); + + // Adds a manifest to the index. + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexAddManifest( + APPINSTALLER_SQLITE_INDEX_HANDLE index, + APPINSTALLER_SQLITE_INDEX_STRING manifestPath, + APPINSTALLER_SQLITE_INDEX_STRING relativePath); + + // Updates a manifest in the index. + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexUpdateManifest( + APPINSTALLER_SQLITE_INDEX_HANDLE index, + APPINSTALLER_SQLITE_INDEX_STRING oldManifestPath, + APPINSTALLER_SQLITE_INDEX_STRING oldRelativePath, + APPINSTALLER_SQLITE_INDEX_STRING newManifestPath, + APPINSTALLER_SQLITE_INDEX_STRING newRelativePath); + + // Removes a manifest from the index. + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexRemoveManifest( + APPINSTALLER_SQLITE_INDEX_HANDLE index, + APPINSTALLER_SQLITE_INDEX_STRING manifestPath, + APPINSTALLER_SQLITE_INDEX_STRING relativePath); +} diff --git a/src/AppInstallerSQLiteIndexUtil/AppInstallerSQLiteIndexUtil.vcxproj b/src/AppInstallerSQLiteIndexUtil/AppInstallerSQLiteIndexUtil.vcxproj @@ -0,0 +1,221 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.191111.2\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.191111.2\build\native\Microsoft.Windows.CppWinRT.props')" /> + <PropertyGroup Label="Globals"> + <CppWinRTOptimized>true</CppWinRTOptimized> + <CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge> + <MinimalCoreWin>true</MinimalCoreWin> + <VCProjectVersion>15.0</VCProjectVersion> + <ProjectGuid>{FB313532-38B0-4676-9303-AB200AA13576}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>AppInstallerSQLiteIndexUtil</RootNamespace> + <WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.18362.0</WindowsTargetPlatformVersion> + <WindowsTargetPlatformMinVersion>10.0.16299.0</WindowsTargetPlatformMinVersion> + <WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport> + <WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|ARM"> + <Configuration>Debug</Configuration> + <Platform>ARM</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|ARM64"> + <Configuration>Debug</Configuration> + <Platform>ARM64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|ARM"> + <Configuration>Release</Configuration> + <Platform>ARM</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|ARM64"> + <Configuration>Release</Configuration> + <Platform>ARM64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <PlatformToolset>v140</PlatformToolset> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration"> + <UseDebugLibraries>true</UseDebugLibraries> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration"> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared" /> + <ImportGroup Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets"> + <Import Project="PropertySheet.props" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)x86\$(Configuration)\$(ProjectName)\</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(SolutionDir)x86\$(Configuration)\$(ProjectName)\</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> + </PropertyGroup> + <ItemDefinitionGroup> + <ClCompile> + <PrecompiledHeader>Use</PrecompiledHeader> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile> + <PreprocessorDefinitions>_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <WarningLevel>Level4</WarningLevel> + <AdditionalOptions>%(AdditionalOptions) /permissive- /bigobj</AdditionalOptions> + </ClCompile> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'"> + <ClCompile> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <GenerateWindowsMetadata>false</GenerateWindowsMetadata> + <SubSystem Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Windows</SubSystem> + <SubSystem Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Windows</SubSystem> + <SubSystem Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Windows</SubSystem> + <ModuleDefinitionFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Source.def</ModuleDefinitionFile> + <ModuleDefinitionFile Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Source.def</ModuleDefinitionFile> + <ModuleDefinitionFile Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Source.def</ModuleDefinitionFile> + <AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">winsqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies> + <AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">winsqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies> + <AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">winsqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Platform)'=='Win32'"> + <ClCompile> + <PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <SubSystem Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Windows</SubSystem> + <ModuleDefinitionFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Source.def</ModuleDefinitionFile> + <AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">winsqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)'=='Release'"> + <ClCompile> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateWindowsMetadata>false</GenerateWindowsMetadata> + <SubSystem Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Windows</SubSystem> + <SubSystem Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Windows</SubSystem> + <SubSystem Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Windows</SubSystem> + <SubSystem Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Windows</SubSystem> + <ModuleDefinitionFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Source.def</ModuleDefinitionFile> + <ModuleDefinitionFile Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Source.def</ModuleDefinitionFile> + <ModuleDefinitionFile Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Source.def</ModuleDefinitionFile> + <ModuleDefinitionFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Source.def</ModuleDefinitionFile> + <AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">winsqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies> + <AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">winsqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies> + <AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">winsqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies> + <AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">winsqlite3.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClInclude Include="AppInstallerSQLiteIndexUtil.h" /> + <ClInclude Include="pch.h" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="Exports.cpp" /> + <ClCompile Include="pch.cpp"> + <PrecompiledHeader>Create</PrecompiledHeader> + </ClCompile> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + <None Include="PropertySheet.props" /> + <None Include="Source.def" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\AppInstallerCommonCore\AppInstallerCommonCore.vcxproj"> + <Project>{5890d6ed-7c3b-40f3-b436-b54f640d9e65}</Project> + </ProjectReference> + <ProjectReference Include="..\AppInstallerRepositoryCore\AppInstallerRepositoryCore.vcxproj"> + <Project>{5eb88068-5fb9-4e69-89b2-72dbc5e068f9}</Project> + </ProjectReference> + <ProjectReference Include="..\YamlCppLib\YamlCppLib.vcxproj"> + <Project>{8bb94bb8-374f-4294-bca1-c7811514a6b7}</Project> + </ProjectReference> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + <Import Project="$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.191111.2\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.191111.2\build\native\Microsoft.Windows.CppWinRT.targets')" /> + <Import Project="$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" /> + </ImportGroup> + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> + <PropertyGroup> + <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> + </PropertyGroup> + <Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.191111.2\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.191111.2\build\native\Microsoft.Windows.CppWinRT.props'))" /> + <Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.191111.2\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.191111.2\build\native\Microsoft.Windows.CppWinRT.targets'))" /> + <Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" /> + </Target> +</Project>+ \ No newline at end of file diff --git a/src/AppInstallerSQLiteIndexUtil/AppInstallerSQLiteIndexUtil.vcxproj.filters b/src/AppInstallerSQLiteIndexUtil/AppInstallerSQLiteIndexUtil.vcxproj.filters @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClInclude Include="pch.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="AppInstallerSQLiteIndexUtil.h"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> + <ItemGroup> + <ClCompile Include="pch.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="Exports.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <None Include="PropertySheet.props" /> + <None Include="packages.config" /> + <None Include="Source.def"> + <Filter>Source Files</Filter> + </None> + </ItemGroup> +</Project>+ \ No newline at end of file diff --git a/src/AppInstallerSQLiteIndexUtil/Exports.cpp b/src/AppInstallerSQLiteIndexUtil/Exports.cpp @@ -0,0 +1,93 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#include "pch.h" +#include "AppInstallerSQLiteIndexUtil.h" + + +using namespace AppInstaller::Utility; +using namespace AppInstaller::Repository::Microsoft; + +extern "C" +{ + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexCreate(APPINSTALLER_SQLITE_INDEX_STRING filePath, UINT32 majorVersion, UINT32 minorVersion, APPINSTALLER_SQLITE_INDEX_HANDLE* index) try + { + THROW_HR_IF(E_INVALIDARG, !filePath); + THROW_HR_IF(E_INVALIDARG, !index); + THROW_HR_IF(E_INVALIDARG, !!*index); + + std::string filePathUtf8 = ConvertToUTF8(filePath); + Schema::Version internalVersion{ majorVersion, minorVersion }; + + std::unique_ptr<SQLiteIndex> result = std::make_unique<SQLiteIndex>(SQLiteIndex::CreateNew(filePathUtf8, internalVersion)); + + *index = static_cast<APPINSTALLER_SQLITE_INDEX_HANDLE>(result.release()); + + return S_OK; + } + CATCH_RETURN() + + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexOpen(APPINSTALLER_SQLITE_INDEX_STRING filePath, APPINSTALLER_SQLITE_INDEX_HANDLE* index) try + { + THROW_HR_IF(E_INVALIDARG, !filePath); + THROW_HR_IF(E_INVALIDARG, !index); + THROW_HR_IF(E_INVALIDARG, !!*index); + + std::string filePathUtf8 = ConvertToUTF8(filePath); + + std::unique_ptr<SQLiteIndex> result = std::make_unique<SQLiteIndex>(SQLiteIndex::Open(filePathUtf8, SQLiteIndex::OpenDisposition::ReadWrite)); + + *index = static_cast<APPINSTALLER_SQLITE_INDEX_HANDLE>(result.release()); + + return S_OK; + } + CATCH_RETURN() + + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexClose(APPINSTALLER_SQLITE_INDEX_HANDLE index) try + { + std::unique_ptr<SQLiteIndex> toClose(reinterpret_cast<SQLiteIndex*>(index)); + + return S_OK; + } + CATCH_RETURN() + + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexAddManifest(APPINSTALLER_SQLITE_INDEX_HANDLE index, APPINSTALLER_SQLITE_INDEX_STRING manifestPath, APPINSTALLER_SQLITE_INDEX_STRING relativePath) try + { + THROW_HR_IF(E_INVALIDARG, !index); + THROW_HR_IF(E_INVALIDARG, !manifestPath); + THROW_HR_IF(E_INVALIDARG, !relativePath); + + reinterpret_cast<SQLiteIndex*>(index)->AddManifest(manifestPath, relativePath); + + return S_OK; + } + CATCH_RETURN() + + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexUpdateManifest( + APPINSTALLER_SQLITE_INDEX_HANDLE index, + APPINSTALLER_SQLITE_INDEX_STRING oldManifestPath, APPINSTALLER_SQLITE_INDEX_STRING oldRelativePath, + APPINSTALLER_SQLITE_INDEX_STRING newManifestPath, APPINSTALLER_SQLITE_INDEX_STRING newRelativePath) try + { + THROW_HR_IF(E_INVALIDARG, !index); + THROW_HR_IF(E_INVALIDARG, !oldManifestPath); + THROW_HR_IF(E_INVALIDARG, !oldRelativePath); + THROW_HR_IF(E_INVALIDARG, !newManifestPath); + THROW_HR_IF(E_INVALIDARG, !newRelativePath); + + reinterpret_cast<SQLiteIndex*>(index)->UpdateManifest(oldManifestPath, oldRelativePath, newManifestPath, newRelativePath); + + return S_OK; + } + CATCH_RETURN() + + APPINSTALLER_SQLITE_INDEX_API AppInstallerSQLiteIndexRemoveManifest(APPINSTALLER_SQLITE_INDEX_HANDLE index, APPINSTALLER_SQLITE_INDEX_STRING manifestPath, APPINSTALLER_SQLITE_INDEX_STRING relativePath) try + { + THROW_HR_IF(E_INVALIDARG, !index); + THROW_HR_IF(E_INVALIDARG, !manifestPath); + THROW_HR_IF(E_INVALIDARG, !relativePath); + + reinterpret_cast<SQLiteIndex*>(index)->RemoveManifest(manifestPath, relativePath); + + return S_OK; + } + CATCH_RETURN() +} diff --git a/src/AppInstallerSQLiteIndexUtil/PropertySheet.props b/src/AppInstallerSQLiteIndexUtil/PropertySheet.props @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ImportGroup Label="PropertySheets" /> + <PropertyGroup Label="UserMacros" /> + <!-- + To customize common C++/WinRT project properties: + * right-click the project node + * expand the Common Properties item + * select the C++/WinRT property page + + For more advanced scenarios, and complete documentation, please see: + https://github.com/Microsoft/xlang/tree/master/src/package/cppwinrt/nuget + --> + <PropertyGroup /> + <ItemDefinitionGroup /> +</Project>+ \ No newline at end of file diff --git a/src/AppInstallerSQLiteIndexUtil/Source.def b/src/AppInstallerSQLiteIndexUtil/Source.def @@ -0,0 +1,8 @@ +LIBRARY AppInstallerSQLiteIndexUtil +EXPORTS + AppInstallerSQLiteIndexCreate + AppInstallerSQLiteIndexOpen + AppInstallerSQLiteIndexClose + AppInstallerSQLiteIndexAddManifest + AppInstallerSQLiteIndexUpdateManifest + AppInstallerSQLiteIndexRemoveManifest diff --git a/src/AppInstallerSQLiteIndexUtil/packages.config b/src/AppInstallerSQLiteIndexUtil/packages.config @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Microsoft.Windows.CppWinRT" version="2.0.191111.2" targetFramework="native" /> + <package id="Microsoft.Windows.ImplementationLibrary" version="1.0.191107.2" targetFramework="native" /> +</packages>+ \ No newline at end of file diff --git a/src/AppInstallerSQLiteIndexUtil/pch.cpp b/src/AppInstallerSQLiteIndexUtil/pch.cpp @@ -0,0 +1,3 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#include "pch.h" diff --git a/src/AppInstallerSQLiteIndexUtil/pch.h b/src/AppInstallerSQLiteIndexUtil/pch.h @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#pragma once + +#define NOMINMAX +#include <Windows.h> + +#include <Public/AppInstallerStrings.h> +#include <Microsoft/SQLiteIndex.h> + +#include <wil/result_macros.h> + +#include <memory> +#include <string>