commit 7858b006876bb6e3dd36fdd48effbe2612bf84ca parent fb4bf346ad59a7222ebe3c82cc5573e8494c3eef Author: JohnMcPMS <johnmcp@microsoft.com> Date: Fri, 13 Jan 2023 10:21:41 -0800 Refactor some code into shared library (#2844) Refactor some code into a static library for use in future work. The main goal in the separation is to ensure that the winget specifics (settings, telemetry, etc.) aren't brought in accidentally. The biggest code changes required were: 1. Moving the logger helpers into their respective owning types 2. Refactoring `ThreadGlobals` into an interface that can be implemented by the using component Everything else should be changes to account for that. Diffstat:
56 files changed, 1416 insertions(+), 898 deletions(-)
diff --git a/src/AppInstallerCLI.sln b/src/AppInstallerCLI.sln @@ -147,6 +147,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PureLib", "PureLib\PureLib.vcxproj", "{BB14D603-F44E-4415-8770-BF3E13F4C17F}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AppInstallerSharedLib", "AppInstallerSharedLib\AppInstallerSharedLib.vcxproj", "{F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1076,6 +1078,46 @@ Global {BB14D603-F44E-4415-8770-BF3E13F4C17F}.TestRelease|x64.Build.0 = Release|x64 {BB14D603-F44E-4415-8770-BF3E13F4C17F}.TestRelease|x86.ActiveCfg = Release|Win32 {BB14D603-F44E-4415-8770-BF3E13F4C17F}.TestRelease|x86.Build.0 = Release|Win32 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Debug|Any CPU.ActiveCfg = Debug|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Debug|Any CPU.Build.0 = Debug|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Debug|ARM.ActiveCfg = Debug|ARM + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Debug|ARM.Build.0 = Debug|ARM + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Debug|ARM64.Build.0 = Debug|ARM64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Debug|x64.ActiveCfg = Debug|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Debug|x64.Build.0 = Debug|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Debug|x86.ActiveCfg = Debug|Win32 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Debug|x86.Build.0 = Debug|Win32 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Fuzzing|Any CPU.ActiveCfg = Fuzzing|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Fuzzing|Any CPU.Build.0 = Fuzzing|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Fuzzing|ARM.ActiveCfg = Fuzzing|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Fuzzing|ARM.Build.0 = Fuzzing|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Fuzzing|ARM64.ActiveCfg = Fuzzing|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Fuzzing|ARM64.Build.0 = Fuzzing|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Fuzzing|x64.ActiveCfg = Fuzzing|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Fuzzing|x64.Build.0 = Fuzzing|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Fuzzing|x86.ActiveCfg = Fuzzing|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Fuzzing|x86.Build.0 = Fuzzing|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Release|Any CPU.ActiveCfg = Release|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Release|Any CPU.Build.0 = Release|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Release|ARM.ActiveCfg = Release|ARM + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Release|ARM.Build.0 = Release|ARM + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Release|ARM64.ActiveCfg = Release|ARM64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Release|ARM64.Build.0 = Release|ARM64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Release|x64.ActiveCfg = Release|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Release|x64.Build.0 = Release|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Release|x86.ActiveCfg = Release|Win32 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.Release|x86.Build.0 = Release|Win32 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.TestRelease|Any CPU.ActiveCfg = Release|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.TestRelease|Any CPU.Build.0 = Release|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.TestRelease|ARM.ActiveCfg = Release|ARM + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.TestRelease|ARM.Build.0 = Release|ARM + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.TestRelease|ARM64.ActiveCfg = Release|ARM64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.TestRelease|ARM64.Build.0 = Release|ARM64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.TestRelease|x64.ActiveCfg = Release|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.TestRelease|x64.Build.0 = Release|x64 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.TestRelease|x86.ActiveCfg = Release|Win32 + {F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}.TestRelease|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1132,6 +1174,7 @@ Global WinGetSchemas\WinGetSchemas.vcxitems*{89b1aab4-2bbc-4b65-9ed7-a01d5cf88230}*SharedItemsImports = 4 WinGetSchemas\WinGetSchemas.vcxitems*{952b513f-8a00-4d74-9271-925afb3c6252}*SharedItemsImports = 9 CertificateResources\CertificateResources.vcxitems*{b0bbbd92-943b-408f-b2b2-dbbab4a22d23}*SharedItemsImports = 9 + Valijson\Valijson.vcxitems*{f3f6e699-bc5d-4950-8a05-e49dd9eb0d51}*SharedItemsImports = 4 binver\binver.vcxitems*{fb313532-38b0-4676-9303-ab200aa13576}*SharedItemsImports = 4 ManifestSchema\ManifestSchema.vcxitems*{fb313532-38b0-4676-9303-ab200aa13576}*SharedItemsImports = 4 EndGlobalSection diff --git a/src/AppInstallerCLICore/AppInstallerCLICore.vcxproj b/src/AppInstallerCLICore/AppInstallerCLICore.vcxproj @@ -162,9 +162,9 @@ <ClCompile> <Optimization>Disabled</Optimization> <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatWarningAsError> @@ -185,7 +185,7 @@ <ItemDefinitionGroup Condition="'$(Platform)'=='Win32'"> <ClCompile> <PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</TreatWarningAsError> <SDLCheck Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</SDLCheck> <EnablePREfast Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</EnablePREfast> @@ -200,10 +200,10 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</TreatWarningAsError> diff --git a/src/AppInstallerCLICore/COMContext.cpp b/src/AppInstallerCLICore/COMContext.cpp @@ -2,6 +2,8 @@ // Licensed under the MIT License. #include "pch.h" #include "COMContext.h" +#include <AppInstallerFileLogger.h> +#include <winget/TraceLogger.h> namespace AppInstaller::CLI::Execution { @@ -74,10 +76,10 @@ namespace AppInstaller::CLI::Execution Logging::Log().EnableChannel(Logging::Channel::All); // TODO: Log to file for COM API calls only when debugging in visual studio - Logging::AddFileLogger(s_comLogFileNamePrefix); - Logging::BeginLogFileCleanup(); + Logging::FileLogger::Add(s_comLogFileNamePrefix); + Logging::FileLogger::BeginCleanup(); - Logging::AddTraceLogger(); + Logging::TraceLogger::Add(); Logging::EnableWilFailureTelemetry(); } diff --git a/src/AppInstallerCLICore/Core.cpp b/src/AppInstallerCLICore/Core.cpp @@ -8,6 +8,7 @@ #include <winget/UserSettings.h> #include "Commands/InstallCommand.h" #include "COMContext.h" +#include <AppInstallerFileLogger.h> #ifndef AICLI_DISABLE_TEST_HOOKS #include <winget/Debugging.h> @@ -67,7 +68,7 @@ namespace AppInstaller::CLI // Enable all logging for this phase; we will update once we have the arguments Logging::Log().EnableChannel(Logging::Channel::All); Logging::Log().SetLevel(Settings::User().Get<Settings::Setting::LoggingLevelPreference>()); - Logging::AddFileLogger(); + Logging::FileLogger::Add(); Logging::EnableWilFailureTelemetry(); // Set output to UTF8 @@ -77,7 +78,7 @@ namespace AppInstaller::CLI Logging::Telemetry().LogStartup(); // Initiate the background cleanup of the log file location. - Logging::BeginLogFileCleanup(); + Logging::FileLogger::BeginCleanup(); context << Workflow::ReportExecutionStage(Workflow::ExecutionStage::ParseArgs); diff --git a/src/AppInstallerCLICore/ExecutionContext.cpp b/src/AppInstallerCLICore/ExecutionContext.cpp @@ -241,7 +241,7 @@ namespace AppInstaller::CLI::Execution GetThreadGlobals().GetTelemetryLogger().SetExecutionStage(static_cast<uint32_t>(m_executionStage)); } - AppInstaller::ThreadLocalStorage::ThreadGlobals& Context::GetThreadGlobals() + AppInstaller::ThreadLocalStorage::WingetThreadGlobals& Context::GetThreadGlobals() { return m_threadGlobals; } diff --git a/src/AppInstallerCLICore/ExecutionContext.h b/src/AppInstallerCLICore/ExecutionContext.h @@ -77,9 +77,9 @@ namespace AppInstaller::CLI::Execution Context(std::ostream& out, std::istream& in) : Reporter(out, in) {} // Constructor for creating a sub-context. - Context(Execution::Reporter& reporter, ThreadLocalStorage::ThreadGlobals& threadGlobals) : + Context(Execution::Reporter& reporter, ThreadLocalStorage::WingetThreadGlobals& threadGlobals) : Reporter(reporter, Execution::Reporter::clone_t{}), - m_threadGlobals(threadGlobals, ThreadLocalStorage::ThreadGlobals::create_sub_thread_globals_t{}) {} + m_threadGlobals(threadGlobals, ThreadLocalStorage::WingetThreadGlobals::create_sub_thread_globals_t{}) {} virtual ~Context(); @@ -139,7 +139,7 @@ namespace AppInstaller::CLI::Execution virtual void SetExecutionStage(Workflow::ExecutionStage stage); // Get Globals for Current Context - AppInstaller::ThreadLocalStorage::ThreadGlobals& GetThreadGlobals(); + AppInstaller::ThreadLocalStorage::WingetThreadGlobals& GetThreadGlobals(); std::unique_ptr<AppInstaller::ThreadLocalStorage::PreviousThreadGlobals> SetForCurrentThread(); @@ -170,7 +170,7 @@ namespace AppInstaller::CLI::Execution size_t m_CtrlSignalCount = 0; ContextFlag m_flags = ContextFlag::None; Workflow::ExecutionStage m_executionStage = Workflow::ExecutionStage::Initial; - AppInstaller::ThreadLocalStorage::ThreadGlobals m_threadGlobals; + AppInstaller::ThreadLocalStorage::WingetThreadGlobals m_threadGlobals; AppInstaller::CLI::Command* m_executingCommand = nullptr; }; } diff --git a/src/AppInstallerCLITests/AppInstallerCLITests.vcxproj b/src/AppInstallerCLITests/AppInstallerCLITests.vcxproj @@ -112,7 +112,7 @@ <ClCompile> <Optimization>Disabled</Optimization> <PreprocessorDefinitions>_NO_ASYNCRTIMP;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(MSBuildThisFileDirectory)..\AppInstallerCommonCore;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore;$(MSBuildThisFileDirectory)..\AppInstallerCommonCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(MSBuildThisFileDirectory)..\AppInstallerCommonCore;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore;$(MSBuildThisFileDirectory)..\AppInstallerCommonCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerSharedLib\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatWarningAsError> </ClCompile> <Link> @@ -130,7 +130,7 @@ <ItemDefinitionGroup Condition="'$(Platform)'=='Win32'"> <ClCompile> <PreprocessorDefinitions>_NO_ASYNCRTIMP;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(MSBuildThisFileDirectory)..\AppInstallerCommonCore;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore;$(MSBuildThisFileDirectory)..\AppInstallerCommonCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(MSBuildThisFileDirectory)..\AppInstallerCommonCore;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore;$(MSBuildThisFileDirectory)..\AppInstallerCommonCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerSharedLib\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</TreatWarningAsError> </ClCompile> <Link> @@ -149,8 +149,8 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>_NO_ASYNCRTIMP;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(MSBuildThisFileDirectory)..\AppInstallerCommonCore;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore;$(MSBuildThisFileDirectory)..\AppInstallerCommonCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(MSBuildThisFileDirectory)..\AppInstallerCommonCore;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore;$(MSBuildThisFileDirectory)..\AppInstallerCommonCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(MSBuildThisFileDirectory)..\AppInstallerCommonCore;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore;$(MSBuildThisFileDirectory)..\AppInstallerCommonCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerSharedLib\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(MSBuildThisFileDirectory)..\AppInstallerCommonCore;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerRepositoryCore;$(MSBuildThisFileDirectory)..\AppInstallerCommonCore\Public;$(MSBuildThisFileDirectory)..\AppInstallerSharedLib\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore\Public;$(MSBuildThisFileDirectory)..\AppInstallerCLICore;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</TreatWarningAsError> </ClCompile> diff --git a/src/AppInstallerCLITests/RestInterface_1_0.cpp b/src/AppInstallerCLITests/RestInterface_1_0.cpp @@ -8,7 +8,7 @@ #include <AppInstallerVersions.h> #include <AppInstallerErrors.h> #include <winget/ManifestValidation.h> -#include <Public/AppInstallerSHA256.h> +#include <AppInstallerSHA256.h> using namespace TestCommon; using namespace AppInstaller::Utility; diff --git a/src/AppInstallerCLITests/main.cpp b/src/AppInstallerCLITests/main.cpp @@ -7,7 +7,8 @@ #include <string> #include <vector> -#include <Public/AppInstallerLogging.h> +#include <AppInstallerLogging.h> +#include <AppInstallerFileLogger.h> #include <Public/AppInstallerTelemetry.h> #include <Telemetry/TraceLogging.h> @@ -89,12 +90,12 @@ int main(int argc, char** argv) } else if ("-log"s == argv[i]) { - Logging::AddFileLogger(); + Logging::FileLogger::Add(); } else if ("-logto"s == argv[i]) { ++i; - Logging::AddFileLogger(std::filesystem::path{ argv[i] }); + Logging::FileLogger::Add(std::filesystem::path{ argv[i] }); } else if ("-tdd"s == argv[i]) { diff --git a/src/AppInstallerCommonCore/AppInstallerCommonCore.vcxproj b/src/AppInstallerCommonCore/AppInstallerCommonCore.vcxproj @@ -178,9 +178,9 @@ <ClCompile> <Optimization>Disabled</Optimization> <PreprocessorDefinitions>_NO_ASYNCRTIMP;_DEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\PureLib\pure;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\PureLib\pure;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\PureLib\pure;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\AppInstallerSharedLib;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\PureLib\pure;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\AppInstallerSharedLib;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\PureLib\pure;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\AppInstallerSharedLib;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\PureLib\pure;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatWarningAsError> @@ -201,7 +201,7 @@ <ItemDefinitionGroup Condition="'$(Platform)'=='Win32'"> <ClCompile> <PreprocessorDefinitions>_NO_ASYNCRTIMP;WIN32;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\PureLib\pure;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\AppInstallerSharedLib;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\PureLib\pure;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</TreatWarningAsError> <SDLCheck Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</SDLCheck> <EnablePREfast Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</EnablePREfast> @@ -216,10 +216,10 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>_NO_ASYNCRTIMP;NDEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\PureLib\pure;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\PureLib\pure;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\PureLib\pure;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\PureLib\pure;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\AppInstallerSharedLib;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\PureLib\pure;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\AppInstallerSharedLib;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\PureLib\pure;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\AppInstallerSharedLib;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\PureLib\pure;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\AppInstallerSharedLib;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\PureLib\pure;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</TreatWarningAsError> @@ -249,7 +249,7 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>_NO_ASYNCRTIMP;NDEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD;WINGET_DISABLE_FOR_FUZZING</PreprocessorDefinitions> - <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\AppInstallerSharedLib;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError>true</TreatWarningAsError> <LanguageStandard>stdcpp17</LanguageStandard> <RuntimeLibrary>MultiThreaded</RuntimeLibrary> @@ -290,29 +290,21 @@ <ClInclude Include="HttpStream\HttpLocalCache.h" /> <ClInclude Include="HttpStream\HttpRandomAccessStream.h" /> <ClInclude Include="pch.h" /> - <ClInclude Include="Public\AppInstallerDateTime.h" /> <ClInclude Include="Public\AppInstallerDeployment.h" /> <ClInclude Include="Public\AppInstallerDownloader.h" /> - <ClInclude Include="Public\AppInstallerErrors.h" /> <ClInclude Include="Public\AppInstallerFileLogger.h" /> <ClInclude Include="Public\AppInstallerProgress.h" /> - <ClInclude Include="Public\AppInstallerLanguageUtilities.h" /> <ClInclude Include="Public\AppInstallerMsixInfo.h" /> <ClInclude Include="Public\AppInstallerRuntime.h" /> - <ClInclude Include="Public\AppInstallerSHA256.h" /> - <ClInclude Include="Public\AppInstallerStrings.h" /> <ClInclude Include="Public\AppInstallerSynchronization.h" /> <ClInclude Include="Public\AppInstallerTelemetry.h" /> - <ClInclude Include="Public\AppInstallerLogging.h" /> <ClInclude Include="Public\AppInstallerArchitecture.h" /> <ClInclude Include="Public\AppInstallerVersions.h" /> <ClInclude Include="Public\winget\Archive.h" /> <ClInclude Include="Public\winget\ExperimentalFeature.h" /> <ClInclude Include="Public\winget\ExtensionCatalog.h" /> - <ClInclude Include="Public\winget\JsonSchemaValidation.h" /> <ClInclude Include="Public\winget\JsonUtil.h" /> <ClInclude Include="Public\winget\Locale.h" /> - <ClInclude Include="Public\winget\LocIndependent.h" /> <ClInclude Include="Public\winget\ManagedFile.h" /> <ClInclude Include="Public\winget\Manifest.h" /> <ClInclude Include="Public\winget\ManifestInstaller.h" /> @@ -333,16 +325,13 @@ <ClInclude Include="Public\winget\PortableARPEntry.h" /> <ClInclude Include="Public\winget\PortableFileEntry.h" /> <ClInclude Include="Public\winget\ManifestSchemaValidation.h" /> - <ClInclude Include="Public\winget\Resources.h" /> <ClInclude Include="Public\winget\Settings.h" /> <ClInclude Include="Public\winget\ThreadGlobals.h" /> <ClInclude Include="Public\winget\TraceLogger.h" /> <ClInclude Include="Public\winget\UserSettings.h" /> - <ClInclude Include="Public\winget\Yaml.h" /> <ClInclude Include="Telemetry\MicrosoftTelemetry.h" /> <ClInclude Include="Telemetry\TraceLogging.h" /> <ClInclude Include="Telemetry\WinEventLogLevels.h" /> - <ClInclude Include="YamlWrapper.h" /> </ItemGroup> <ItemGroup> <ClCompile Include="AdminSettings.cpp" /> @@ -355,14 +344,10 @@ <ClCompile Include="GroupPolicy.cpp"> <ExcludedFromBuild Condition="'$(Configuration)'=='Fuzzing'">true</ExcludedFromBuild> </ClCompile> - <ClCompile Include="AppInstallerLogging.cpp" /> - <ClCompile Include="AppInstallerStrings.cpp" /> - <ClCompile Include="DateTime.cpp" /> <ClCompile Include="Deployment.cpp"> <ExcludedFromBuild Condition="'$(Configuration)'=='Fuzzing'">true</ExcludedFromBuild> </ClCompile> <ClCompile Include="Downloader.cpp" /> - <ClCompile Include="Errors.cpp" /> <ClCompile Include="ExperimentalFeature.cpp" /> <ClCompile Include="ExtensionCatalog.cpp"> <ExcludedFromBuild Condition="'$(Configuration)'=='Fuzzing'">true</ExcludedFromBuild> @@ -377,7 +362,6 @@ <ClCompile Include="HttpStream\HttpRandomAccessStream.cpp"> <ExcludedFromBuild Condition="'$(Configuration)'=='Fuzzing'">true</ExcludedFromBuild> </ClCompile> - <ClCompile Include="JsonSchemaValidation.cpp" /> <ClCompile Include="JsonUtil.cpp" /> <ClCompile Include="Locale.cpp" /> <ClCompile Include="ManagedFile.cpp" /> @@ -399,7 +383,6 @@ <ClCompile Include="Progress.cpp" /> <ClCompile Include="Regex.cpp" /> <ClCompile Include="Registry.cpp" /> - <ClCompile Include="Resources.cpp" /> <ClCompile Include="Runtime.cpp" /> <ClCompile Include="pch.cpp"> <PrecompiledHeader>Create</PrecompiledHeader> @@ -407,7 +390,6 @@ <ClCompile Include="AppInstallerTelemetry.cpp" /> <ClCompile Include="Archive.cpp" /> <ClCompile Include="Settings.cpp" /> - <ClCompile Include="SHA256.cpp" /> <ClCompile Include="PathVariable.cpp" /> <ClCompile Include="PortableARPEntry.cpp" /> <ClCompile Include="Synchronization.cpp" /> @@ -417,13 +399,16 @@ <ClCompile Include="TraceLogger.cpp" /> <ClCompile Include="UserSettings.cpp" /> <ClCompile Include="Versions.cpp" /> - <ClCompile Include="Yaml.cpp" /> - <ClCompile Include="YamlWrapper.cpp" /> </ItemGroup> <ItemGroup> <None Include="packages.config" /> <None Include="PropertySheet.props" /> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\AppInstallerSharedLib\AppInstallerSharedLib.vcxproj"> + <Project>{f3f6e699-bc5d-4950-8a05-e49dd9eb0d51}</Project> + </ProjectReference> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> <Import Project="$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.210204.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.210204.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" /> diff --git a/src/AppInstallerCommonCore/AppInstallerCommonCore.vcxproj.filters b/src/AppInstallerCommonCore/AppInstallerCommonCore.vcxproj.filters @@ -45,30 +45,15 @@ <ClInclude Include="Public\AppInstallerTelemetry.h"> <Filter>Public</Filter> </ClInclude> - <ClInclude Include="Public\AppInstallerLogging.h"> - <Filter>Public</Filter> - </ClInclude> - <ClInclude Include="Public\AppInstallerStrings.h"> - <Filter>Public</Filter> - </ClInclude> <ClInclude Include="Public\AppInstallerRuntime.h"> <Filter>Public</Filter> </ClInclude> - <ClInclude Include="Public\AppInstallerSHA256.h"> - <Filter>Public</Filter> - </ClInclude> <ClInclude Include="Public\AppInstallerDownloader.h"> <Filter>Public</Filter> </ClInclude> <ClInclude Include="Public\AppInstallerArchitecture.h"> <Filter>Public</Filter> </ClInclude> - <ClInclude Include="Public\AppInstallerErrors.h"> - <Filter>Public</Filter> - </ClInclude> - <ClInclude Include="Public\AppInstallerLanguageUtilities.h"> - <Filter>Public</Filter> - </ClInclude> <ClInclude Include="HttpStream\HttpClientWrapper.h"> <Filter>HttpStream</Filter> </ClInclude> @@ -84,9 +69,6 @@ <ClInclude Include="Public\AppInstallerFileLogger.h"> <Filter>Public</Filter> </ClInclude> - <ClInclude Include="Public\AppInstallerDateTime.h"> - <Filter>Public</Filter> - </ClInclude> <ClInclude Include="Public\AppInstallerSynchronization.h"> <Filter>Public</Filter> </ClInclude> @@ -102,9 +84,6 @@ <ClInclude Include="Public\winget\ExtensionCatalog.h"> <Filter>Public\winget</Filter> </ClInclude> - <ClInclude Include="Public\winget\LocIndependent.h"> - <Filter>Public\winget</Filter> - </ClInclude> <ClInclude Include="Public\winget\Settings.h"> <Filter>Public\winget</Filter> </ClInclude> @@ -114,12 +93,6 @@ <ClInclude Include="Public\winget\ExperimentalFeature.h"> <Filter>Public\winget</Filter> </ClInclude> - <ClInclude Include="YamlWrapper.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="Public\winget\Yaml.h"> - <Filter>Public\winget</Filter> - </ClInclude> <ClInclude Include="Public\winget\ManifestInstaller.h"> <Filter>Public\winget</Filter> </ClInclude> @@ -153,15 +126,9 @@ <ClInclude Include="Public\winget\ManifestCommon.h"> <Filter>Public\winget</Filter> </ClInclude> - <ClInclude Include="Public\winget\JsonSchemaValidation.h"> - <Filter>Public\winget</Filter> - </ClInclude> <ClInclude Include="Public\winget\GroupPolicy.h"> <Filter>Public\winget</Filter> </ClInclude> - <ClInclude Include="Public\winget\Resources.h"> - <Filter>Public\winget</Filter> - </ClInclude> <ClInclude Include="Public\winget\Locale.h"> <Filter>Public\winget</Filter> </ClInclude> @@ -236,24 +203,12 @@ <ClCompile Include="AppInstallerTelemetry.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="AppInstallerLogging.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="AppInstallerStrings.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="FileLogger.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="DateTime.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="Runtime.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="SHA256.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="Downloader.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -281,9 +236,6 @@ <ClCompile Include="Versions.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="Errors.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="ExtensionCatalog.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -299,12 +251,6 @@ <ClCompile Include="ExperimentalFeature.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="YamlWrapper.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Yaml.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="Manifest\ManifestValidation.cpp"> <Filter>Manifest</Filter> </ClCompile> @@ -332,9 +278,6 @@ <ClCompile Include="Manifest\Manifest.cpp"> <Filter>Manifest</Filter> </ClCompile> - <ClCompile Include="JsonSchemaValidation.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="GroupPolicy.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -377,9 +320,6 @@ <ClCompile Include="Certificates.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="Resources.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="FolderFileWatcher.cpp"> <Filter>Source Files</Filter> </ClCompile> diff --git a/src/AppInstallerCommonCore/AppInstallerLogging.cpp b/src/AppInstallerCommonCore/AppInstallerLogging.cpp @@ -1,190 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -#include "pch.h" -#include "Public/AppInstallerLogging.h" - -#include "Public/AppInstallerFileLogger.h" -#include "Public/winget/TraceLogger.h" -#include "Public/AppInstallerTelemetry.h" -#include "Public/AppInstallerDateTime.h" -#include "Public/AppInstallerRuntime.h" -#include "Public/winget/ThreadGlobals.h" - -namespace AppInstaller::Logging -{ - namespace - { - template <typename E> - std::underlying_type_t<E> AsNum(E e) - { - return static_cast<std::underlying_type_t<E>>(e); - } - - uint64_t ConvertChannelToBitmask(Channel channel) - { - if (channel == Channel::All) - { - return std::numeric_limits<uint64_t>::max(); - } - else - { - return (1ull << AsNum(channel)); - } - } - } - - char const* GetChannelName(Channel channel) - { - switch(channel) - { - case Channel::Fail: return "FAIL"; - case Channel::CLI: return "CLI"; - case Channel::SQL: return "SQL"; - case Channel::Repo: return "REPO"; - case Channel::YAML: return "YAML"; - case Channel::Core: return "CORE"; - case Channel::Test: return "TEST"; - default: return "NONE"; - } - } - - size_t GetMaxChannelNameLength() { return 4; } - - void DiagnosticLogger::AddLogger(std::unique_ptr<ILogger>&& logger) - { - m_loggers.emplace_back(std::move(logger)); - } - - bool DiagnosticLogger::ContainsLogger(const std::string& name) - { - for (auto i = m_loggers.begin(); i != m_loggers.end(); ++i) - { - if ((*i)->GetName() == name) - { - return true; - } - } - - return false; - } - - std::unique_ptr<ILogger> DiagnosticLogger::RemoveLogger(const std::string& name) - { - std::unique_ptr<ILogger> result; - - for (auto i = m_loggers.begin(); i != m_loggers.end(); ++i) - { - if ((*i)->GetName() == name) - { - result = std::move(*i); - m_loggers.erase(i); - break; - } - } - - return result; - } - - void DiagnosticLogger::RemoveAllLoggers() - { - m_loggers.clear(); - } - - void DiagnosticLogger::EnableChannel(Channel channel) - { - m_enabledChannels |= ConvertChannelToBitmask(channel); - } - - void DiagnosticLogger::DisableChannel(Channel channel) - { - m_enabledChannels &= ~ConvertChannelToBitmask(channel); - } - - void DiagnosticLogger::SetLevel(Level level) - { - m_enabledLevel = level; - } - - bool DiagnosticLogger::IsEnabled(Channel channel, Level level) const - { - return (!m_loggers.empty() && - (m_enabledChannels & ConvertChannelToBitmask(channel)) != 0 && - (AsNum(level) >= AsNum(m_enabledLevel))); - } - - void DiagnosticLogger::Write(Channel channel, Level level, std::string_view message) - { - THROW_HR_IF_MSG(E_INVALIDARG, channel == Channel::All, "Cannot write to all channels"); - - if (IsEnabled(channel, level)) - { - for (auto& logger : m_loggers) - { - logger->Write(channel, level, message); - } - } - } - - void DiagnosticLogger::WriteDirect(Channel channel, Level level, std::string_view message) - { - THROW_HR_IF_MSG(E_INVALIDARG, channel == Channel::All, "Cannot write to all channels"); - - if (IsEnabled(channel, level)) - { - for (auto& logger : m_loggers) - { - logger->WriteDirect(message); - } - } - } - - DiagnosticLogger& Log() - { - ThreadLocalStorage::ThreadGlobals* pThreadGlobals = ThreadLocalStorage::ThreadGlobals::GetForCurrentThread(); - if (pThreadGlobals) - { - return pThreadGlobals->GetDiagnosticLogger(); - } - else - { - static DiagnosticLogger processGlobalLogger; - return processGlobalLogger; - } - } - - void AddFileLogger() - { - Log().AddLogger(std::make_unique<FileLogger>()); - } - - void AddFileLogger(const std::filesystem::path& filePath) - { - Log().AddLogger(std::make_unique<FileLogger>(filePath)); - } - - void AddFileLogger(std::string_view fileNamePrefix) - { - Log().AddLogger(std::make_unique<FileLogger>(fileNamePrefix)); - } - - void AddTraceLogger() - { - Log().AddLogger(std::make_unique<TraceLogger>()); - } - - void BeginLogFileCleanup() - { - FileLogger::BeginCleanup(Runtime::GetPathTo(Runtime::PathName::DefaultLogLocation)); - } - - std::ostream& SetHRFormat(std::ostream& out) - { - return out << std::hex << std::setw(8) << std::setfill('0'); - } -} - -std::ostream& operator<<(std::ostream& out, const std::chrono::system_clock::time_point& time) -{ - AppInstaller::Utility::OutputTimePoint(out, time); - return out; -} diff --git a/src/AppInstallerCommonCore/FileLogger.cpp b/src/AppInstallerCommonCore/FileLogger.cpp @@ -83,6 +83,26 @@ namespace AppInstaller::Logging // Just eat any exceptions here; better than losing logs } + void FileLogger::Add() + { + Log().AddLogger(std::make_unique<FileLogger>()); + } + + void FileLogger::Add(const std::filesystem::path& filePath) + { + Log().AddLogger(std::make_unique<FileLogger>(filePath)); + } + + void FileLogger::Add(std::string_view fileNamePrefix) + { + Log().AddLogger(std::make_unique<FileLogger>(fileNamePrefix)); + } + + void FileLogger::BeginCleanup() + { + BeginCleanup(Runtime::GetPathTo(Runtime::PathName::DefaultLogLocation)); + } + void FileLogger::BeginCleanup(const std::filesystem::path& filePath) { std::thread([filePath]() diff --git a/src/AppInstallerCommonCore/Public/AppInstallerFileLogger.h b/src/AppInstallerCommonCore/Public/AppInstallerFileLogger.h @@ -37,7 +37,13 @@ namespace AppInstaller::Logging void WriteDirect(std::string_view message) noexcept override; + // Adds a FileLogger to the current Log + static void Add(); + static void Add(const std::filesystem::path& filePath); + static void Add(std::string_view fileNamePrefix); + // Starts a background task to clean up old log files. + static void BeginCleanup(); static void BeginCleanup(const std::filesystem::path& filePath); private: diff --git a/src/AppInstallerCommonCore/Public/AppInstallerLogging.h b/src/AppInstallerCommonCore/Public/AppInstallerLogging.h @@ -1,198 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -#pragma once - -#include <chrono> -#include <filesystem> -#include <memory> -#include <sstream> -#include <string> -#include <string_view> -#include <type_traits> -#include <vector> - -#define AICLI_LOG(_channel_,_level_,_outstream_) \ - do { \ - auto _aicli_log_channel = AppInstaller::Logging::Channel:: _channel_; \ - auto _aicli_log_level = AppInstaller::Logging::Level:: _level_; \ - auto& _aicli_log_log = AppInstaller::Logging::Log(); \ - if (_aicli_log_log.IsEnabled(_aicli_log_channel, _aicli_log_level)) \ - { \ - AppInstaller::Logging::LoggingStream _aicli_log_strstr; \ - _aicli_log_strstr _outstream_; \ - _aicli_log_log.Write(_aicli_log_channel, _aicli_log_level, _aicli_log_strstr.str()); \ - } \ - } while (0, 0) - -// Consider using this macro when the string might be larger than 4K. -// The normal macro has some buffering that occurs; it can cut off larger strings and is slower. -#define AICLI_LOG_LARGE_STRING(_channel_,_level_,_headerStream_,_largeString_) \ - do { \ - auto _aicli_log_channel = AppInstaller::Logging::Channel:: _channel_; \ - auto _aicli_log_level = AppInstaller::Logging::Level:: _level_; \ - auto& _aicli_log_log = AppInstaller::Logging::Log(); \ - if (_aicli_log_log.IsEnabled(_aicli_log_channel, _aicli_log_level)) \ - { \ - AppInstaller::Logging::LoggingStream _aicli_log_strstr; \ - _aicli_log_strstr _headerStream_; \ - _aicli_log_log.Write(_aicli_log_channel, _aicli_log_level, _aicli_log_strstr.str()); \ - _aicli_log_log.WriteDirect(_aicli_log_channel, _aicli_log_level, _largeString_); \ - } \ - } while (0, 0) - -namespace AppInstaller::Logging -{ - // The channel that the log is from. - // Channels enable large groups of logs to be enabled or disabled together. - enum class Channel : uint32_t - { - Fail, - CLI, - SQL, - Repo, - YAML, - Core, - Test, - All, - }; - - // Gets the channel's name as a string. - char const* GetChannelName(Channel channel); - - // Gets the maximum channel name length in characters. - size_t GetMaxChannelNameLength(); - - // The level of the log. - enum class Level - { - Verbose, - Info, - Warning, - Error, - Crit, - }; - - // The interface that a log target must implement. - struct ILogger - { - virtual ~ILogger() = default; - - // Gets the name of the logger for internal use. - virtual std::string GetName() const = 0; - - // Informs the logger of the given log. - virtual void Write(Channel channel, Level level, std::string_view message) noexcept = 0; - - // Informs the logger of the given log with the intention that no buffering occurs (in winget code). - virtual void WriteDirect(std::string_view message) noexcept = 0; - }; - - // This type contains the set of loggers that diagnostic logging will be sent to. - // Each binary that leverages it must configure any loggers and filters to their - // desired level, as nothing is enabled by default. - struct DiagnosticLogger - { - DiagnosticLogger() = default; - - ~DiagnosticLogger() = default; - - DiagnosticLogger(const DiagnosticLogger&) = delete; - DiagnosticLogger& operator=(const DiagnosticLogger&) = delete; - - DiagnosticLogger(DiagnosticLogger&&) = delete; - DiagnosticLogger& operator=(DiagnosticLogger&&) = delete; - - // Gets the singleton instance of this type. - static DiagnosticLogger& GetInstance(); - - // NOTE: The logger management functionality is *SINGLE THREAD SAFE*. - // This includes with logging itself. - // As it is not expected that adding/removing loggers is an - // extremely frequent operation, no care has been made to protect - // it from modifying loggers while logging may be occurring. - - // Adds a logger to the active set. - void AddLogger(std::unique_ptr<ILogger>&& logger); - - // Determines if a logger with the given name is present. - bool ContainsLogger(const std::string& name); - - // Removes a logger from the active set, returning it. - std::unique_ptr<ILogger> RemoveLogger(const std::string& name); - - // Removes all loggers. - void RemoveAllLoggers(); - - // Enables the given channel. - void EnableChannel(Channel channel); - - // Disables the given channel. - void DisableChannel(Channel channel); - - // Sets the enabled level. - // All levels higher than this level will be enabled. - // For example; SetLevel(Verbose) will enable all logs. - void SetLevel(Level level); - - // Checks whether a given channel and level are enabled. - bool IsEnabled(Channel channel, Level level) const; - - // Writes a log line, if the given channel and level are enabled. - void Write(Channel channel, Level level, std::string_view message); - - // Writes a log line, if the given channel and level are enabled. - // Use to make large logs more efficient by writing directly to the output streams. - void WriteDirect(Channel channel, Level level, std::string_view message); - - private: - - std::vector<std::unique_ptr<ILogger>> m_loggers; - uint64_t m_enabledChannels = 0; - Level m_enabledLevel = Level::Info; - }; - - DiagnosticLogger& Log(); - - // Adds the default file logger to the DiagnosticLogger. - void AddFileLogger(); - void AddFileLogger(const std::filesystem::path& filePath); - void AddFileLogger(std::string_view fileNamePrefix); - - // Adds the trace logger to the DiagnosticLogger. - void AddTraceLogger(); - - // Starts a background task to clean up old log files. - void BeginLogFileCleanup(); - - // Calls the various stream format functions to produce an 8 character hexadecimal output. - std::ostream& SetHRFormat(std::ostream& out); - - // This type allows us to override the default behavior of output operators for logging. - struct LoggingStream - { - // Force use of the UTF-8 string from a file path. - // This should not be necessary when we move to C++20 and convert to using u8string. - friend AppInstaller::Logging::LoggingStream& operator<<(AppInstaller::Logging::LoggingStream& out, const std::filesystem::path& path) - { - out.m_out << path.u8string(); - return out; - } - - // Everything else. - template <typename T> - friend std::enable_if_t<!std::is_same_v<std::decay_t<T>, std::filesystem::path>, AppInstaller::Logging::LoggingStream&> - operator<<(AppInstaller::Logging::LoggingStream& out, T&& t) - { - out.m_out << std::forward<T>(t); - return out; - } - - std::string str() const { return m_out.str(); } - - private: - std::stringstream m_out; - }; -} - -// Enable output of system_clock time_points. -std::ostream& operator<<(std::ostream& out, const std::chrono::system_clock::time_point& time); diff --git a/src/AppInstallerCommonCore/Public/winget/ThreadGlobals.h b/src/AppInstallerCommonCore/Public/winget/ThreadGlobals.h @@ -1,33 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. #pragma once - #include <AppInstallerLogging.h> +#include <winget/SharedThreadGlobals.h> #include <AppInstallerTelemetry.h> #include <mutex> namespace AppInstaller::ThreadLocalStorage { - - struct PreviousThreadGlobals; - - struct ThreadGlobals + struct WingetThreadGlobals : public ThreadGlobals { - ThreadGlobals() = default; - ~ThreadGlobals() = default; + WingetThreadGlobals() = default; + virtual ~WingetThreadGlobals() = default; // Request that a sub ThreadGlobals be constructed from the given parent. struct create_sub_thread_globals_t {}; - ThreadGlobals(ThreadGlobals& parent, create_sub_thread_globals_t); + WingetThreadGlobals(WingetThreadGlobals& parent, create_sub_thread_globals_t); - AppInstaller::Logging::DiagnosticLogger& GetDiagnosticLogger(); + AppInstaller::Logging::DiagnosticLogger& GetDiagnosticLogger() override; - AppInstaller::Logging::TelemetryTraceLogger& GetTelemetryLogger(); + AppInstaller::Logging::TelemetryTraceLogger& GetTelemetryLogger() override; // Set Globals for Current Thread // Return RAII object with it's ownership to set the AppInstaller ThreadLocalStorage back to previous state - std::unique_ptr<AppInstaller::ThreadLocalStorage::PreviousThreadGlobals> SetForCurrentThread(); - - // Return Globals for Current Thread - static ThreadGlobals* GetForCurrentThread(); + std::unique_ptr<AppInstaller::ThreadLocalStorage::PreviousThreadGlobals> SetForCurrentThread() override; private: @@ -37,15 +33,4 @@ namespace AppInstaller::ThreadLocalStorage std::unique_ptr<AppInstaller::Logging::TelemetryTraceLogger> m_pTelemetryLogger; std::once_flag m_loggerInitOnceFlag; }; - - struct PreviousThreadGlobals - { - ~PreviousThreadGlobals(); - - PreviousThreadGlobals(ThreadGlobals* previous) : m_previous(previous) {}; - - private: - - ThreadGlobals* m_previous; - }; } diff --git a/src/AppInstallerCommonCore/Public/winget/TraceLogger.h b/src/AppInstallerCommonCore/Public/winget/TraceLogger.h @@ -23,5 +23,8 @@ namespace AppInstaller::Logging void Write(Channel channel, Level, std::string_view message) noexcept override; void WriteDirect(std::string_view message) noexcept override; + + // Adds a TraceLogger to the current Log + static void Add(); }; } diff --git a/src/AppInstallerCommonCore/Resources.cpp b/src/AppInstallerCommonCore/Resources.cpp @@ -1,123 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -#include "pch.h" -#include "winget/Resources.h" -#include "Public/AppInstallerLogging.h" -#include "Public/AppInstallerStrings.h" -#include "Public/AppInstallerErrors.h" -#include "Public/AppInstallerTelemetry.h" - -namespace AppInstaller -{ - namespace Resource - { - namespace - { - std::pair<void*, size_t> GetResourceData(PCWSTR resourceName, PCWSTR resourceType) - { - HMODULE resourceModule = nullptr; - GetModuleHandleExW( - GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - reinterpret_cast<PCWSTR>(GetResourceData), - &resourceModule); - THROW_LAST_ERROR_IF_NULL(resourceModule); - - HRSRC resourceInfoHandle = FindResourceW(resourceModule, resourceName, resourceType); - THROW_LAST_ERROR_IF_NULL(resourceInfoHandle); - - HGLOBAL resourceMemoryHandle = LoadResource(resourceModule, resourceInfoHandle); - THROW_LAST_ERROR_IF_NULL(resourceMemoryHandle); - - DWORD resourceSize = SizeofResource(resourceModule, resourceInfoHandle); - THROW_LAST_ERROR_IF(resourceSize == 0); - - void* resourceContent = LockResource(resourceMemoryHandle); - THROW_HR_IF_NULL(E_UNEXPECTED, resourceContent); - - return std::make_pair(resourceContent, static_cast<size_t>(resourceSize)); - } - } - - std::string_view GetResourceAsString(int resourceName, int resourceType) - { - return GetResourceAsString(MAKEINTRESOURCE(resourceName), MAKEINTRESOURCE(resourceType)); - } - - std::string_view GetResourceAsString(PCWSTR resourceName, PCWSTR resourceType) - { - auto resourceData = GetResourceData(resourceName, resourceType); - return { reinterpret_cast<char*>(resourceData.first), resourceData.second }; - } - - std::pair<const BYTE*, size_t> GetResourceAsBytes(int resourceName, int resourceType) - { - return GetResourceAsBytes(MAKEINTRESOURCE(resourceName), MAKEINTRESOURCE(resourceType)); - } - - std::pair<const BYTE*, size_t> GetResourceAsBytes(PCWSTR resourceName, PCWSTR resourceType) - { - auto resourceData = GetResourceData(resourceName, resourceType); - return std::make_pair(reinterpret_cast<BYTE*>(resourceData.first), resourceData.second); - } - - // Utility class to load resources - struct Loader - { - // Gets the singleton instance of the resource loader. - static const Loader& Instance() - { - static Loader instance; - return instance; - } - - // Gets the string resource value. - std::string ResolveString(std::wstring_view resKey) const - { - if (m_wingetLoader) - { - return Utility::ConvertToUTF8(m_wingetLoader.GetString(resKey)); - } - - // Loader failed to load resource file, print the resource key instead. - return Utility::ConvertToUTF8(resKey); - } - - private: - winrt::Windows::ApplicationModel::Resources::ResourceLoader m_wingetLoader; - - Loader() : m_wingetLoader(nullptr) - { - try - { - // The default constructor of ResourceLoader throws a winrt::hresult_error exception - // when resource.pri is not found. ResourceLoader::GetForViewIndependentUse also throws - // a winrt::hresult_error but for reasons unknown it only gets caught when running on the - // debugger. Running without a debugger will result in a crash that not even adding a - // catch all will fix. To provide a good error message we call the default constructor - // before calling GetForViewIndependentUse. - m_wingetLoader = winrt::Windows::ApplicationModel::Resources::ResourceLoader(); - m_wingetLoader = winrt::Windows::ApplicationModel::Resources::ResourceLoader::GetForViewIndependentUse(L"winget"); - } - catch (const winrt::hresult_error& hre) - { - // This message cannot be localized. - AICLI_LOG(CLI, Error, << "Failure loading resource file with error: " << hre.code()); - m_wingetLoader = nullptr; - } - } - }; - } - - namespace StringResource - { - std::string StringId::Resolve() const - { - return Resource::Loader::Instance().ResolveString(*this); - } - - std::ostream& operator<<(std::ostream& out, StringId si) - { - return (out << Resource::LocString{ si }); - } - } -} diff --git a/src/AppInstallerCommonCore/SHA256.cpp b/src/AppInstallerCommonCore/SHA256.cpp @@ -1,177 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -#include <pch.h> -#define WIN32_NO_STATUS -#include <bcrypt.h> -#include "Public/AppInstallerSHA256.h" -#include "Public/AppInstallerRuntime.h" -#include "Public/AppInstallerErrors.h" -#include "Public/AppInstallerStrings.h" - -using namespace AppInstaller::Runtime; - -namespace AppInstaller::Utility { - - struct SHA256Context - { - wil::unique_bcrypt_algorithm algHandle; - wil::unique_bcrypt_hash hashHandle; - DWORD hashLength = 0; - }; - - SHA256::SHA256() : context(new SHA256Context{}) - { - BCRYPT_ALG_HANDLE algHandleT{}; - BCRYPT_HASH_HANDLE hashHandleT; - DWORD resultLength = 0; - - // Open an algorithm handle - THROW_IF_NTSTATUS_FAILED_MSG(BCryptOpenAlgorithmProvider( - &algHandleT, // Alg Handle pointer - BCRYPT_SHA256_ALGORITHM, // Cryptographic Algorithm name (null terminated unicode string) - nullptr, // Provider name; if null, the default provider is loaded - 0), // Flags - "failed opening SHA256 algorithm provider"); - context->algHandle.reset(algHandleT); - - // Obtain the length of the hash - THROW_IF_NTSTATUS_FAILED_MSG(BCryptGetProperty( - context->algHandle.get(), // Handle to a CNG object - BCRYPT_HASH_LENGTH, // Property name (null terminated unicode string) - (PBYTE) & (context->hashLength), // Address of the output buffer which receives the property value - sizeof(context->hashLength), // Size of the buffer in bytes - &resultLength, // Number of bytes that were copied into the buffer - 0), // Flags - "failed getting SHA256 hash length"); - - if (resultLength != sizeof(context->hashLength)) - { - THROW_HR_MSG(E_UNEXPECTED, "failed getting SHA256 hash length"); - } - - // Create a hash handle - THROW_IF_NTSTATUS_FAILED_MSG(BCryptCreateHash( - context->algHandle.get(), // Handle to an algorithm provider - &hashHandleT, // A pointer to a hash handle - can be a hash or hmac object - nullptr, // Pointer to the buffer that receives the hash/hmac object - 0, // Size of the buffer in bytes - nullptr, // A pointer to a key to use for the hash or MAC - 0, // Size of the key in bytes - 0), // Flags - "failed creating SHA256 hash object"); - context->hashHandle.reset(hashHandleT); - } - - void SHA256::Add(const uint8_t* buffer, size_t cbBuffer) - { - EnsureNotFinished(); - - // Add the data - THROW_IF_NTSTATUS_FAILED_MSG( - BCryptHashData(context->hashHandle.get(), const_cast<PUCHAR>(buffer), static_cast<ULONG>(cbBuffer), 0), - "failed adding SHA256 data"); - } - - void SHA256::Get(HashBuffer& hash) - { - EnsureNotFinished(); - - // Size the hash buffer appropriately - hash.resize(context->hashLength); - - // Obtain the hash of the message(s) into the hash buffer - THROW_IF_NTSTATUS_FAILED_MSG(BCryptFinishHash( - context->hashHandle.get(), // Handle to the hash or MAC object - hash.data(), // A pointer to a buffer that receives the hash or MAC value - context->hashLength, // Size of the buffer in bytes - 0), // Flags - "failed getting SHA256 hash"); - - context.reset(); - } - - std::string SHA256::ConvertToString(const HashBuffer& hashBuffer) - { - return Utility::ConvertToHexString(hashBuffer, HashBufferSizeInBytes); - } - - std::wstring SHA256::ConvertToWideString(const HashBuffer& hashBuffer) - { - return ConvertToUTF16(SHA256::ConvertToString(hashBuffer)); - } - - SHA256::HashBuffer SHA256::ConvertToBytes(const std::string& hashStr) - { - return Utility::ParseFromHexString(hashStr, HashBufferSizeInBytes); - } - - SHA256::HashBuffer SHA256::ComputeHash(const std::uint8_t* buffer, std::uint32_t cbBuffer) - { - SHA256 hasher; - hasher.Add(buffer, cbBuffer); - return hasher.Get(); - } - - SHA256::HashBuffer SHA256::ComputeHash(std::string_view buffer) - { - return ComputeHash(reinterpret_cast<const std::uint8_t*>(buffer.data()), static_cast<std::uint32_t>(buffer.size())); - } - - SHA256::HashBuffer SHA256::ComputeHash(std::istream& in) - { - // Throw exceptions on badbit - auto excState = in.exceptions(); - auto revertExcState = wil::scope_exit([excState, &in]() { in.exceptions(excState); }); - in.exceptions(std::ios_base::badbit); - - const int bufferSize = 1024 * 1024; // 1MB - auto buffer = std::make_unique<uint8_t[]>(bufferSize); - - SHA256 hasher; - - while (in.good()) - { - in.read((char*)(buffer.get()), bufferSize); - if (in.gcount()) - { - hasher.Add(buffer.get(), static_cast<size_t>(in.gcount())); - } - } - - if (in.eof()) - { - return hasher.Get(); - } - else - { - THROW_HR(APPINSTALLER_CLI_ERROR_STREAM_READ_FAILURE); - } - } - - - SHA256::HashBuffer SHA256::ComputeHashFromFile(const std::filesystem::path& path) - { - std::ifstream inStream{ path, std::ifstream::binary }; - const Utility::SHA256::HashBuffer& targetFileHash = Utility::SHA256::ComputeHash(inStream); - inStream.close(); - return targetFileHash; - } - - void SHA256::SHA256ContextDeleter::operator()(SHA256Context* context) - { - delete context; - } - - bool SHA256::AreEqual(const HashBuffer& first, const HashBuffer& second) - { - return (first.size() == second.size() && std::equal(first.begin(), first.end(), second.begin())); - } - - void SHA256::EnsureNotFinished() const - { - if (!context) - { - THROW_HR_MSG(E_UNEXPECTED, "The hash is already finished"); - } - } -}- \ No newline at end of file diff --git a/src/AppInstallerCommonCore/ThreadGlobals.cpp b/src/AppInstallerCommonCore/ThreadGlobals.cpp @@ -1,3 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. #include "pch.h" #include "Public/winget/ThreadGlobals.h" @@ -5,10 +7,7 @@ namespace AppInstaller::ThreadLocalStorage { using namespace AppInstaller::Logging; - // Set and return Globals for Current Thread - static ThreadGlobals* SetOrGetThreadGlobals(bool setThreadGlobals, ThreadGlobals* pThreadGlobals = nullptr); - - ThreadGlobals::ThreadGlobals(ThreadGlobals& parent, create_sub_thread_globals_t) + WingetThreadGlobals::WingetThreadGlobals(WingetThreadGlobals& parent, create_sub_thread_globals_t) { parent.Initialize(); m_pDiagnosticLogger = parent.m_pDiagnosticLogger; @@ -17,26 +16,23 @@ namespace AppInstaller::ThreadLocalStorage std::call_once(m_loggerInitOnceFlag, []() {}); } - DiagnosticLogger& ThreadGlobals::GetDiagnosticLogger() + DiagnosticLogger& WingetThreadGlobals::GetDiagnosticLogger() { return *(m_pDiagnosticLogger); } - TelemetryTraceLogger& ThreadGlobals::GetTelemetryLogger() + TelemetryTraceLogger& WingetThreadGlobals::GetTelemetryLogger() { return *(m_pTelemetryLogger); } - std::unique_ptr<PreviousThreadGlobals> ThreadGlobals::SetForCurrentThread() + std::unique_ptr<PreviousThreadGlobals> WingetThreadGlobals::SetForCurrentThread() { Initialize(); - - std::unique_ptr<PreviousThreadGlobals> p_prevThreadGlobals = std::make_unique<PreviousThreadGlobals>(SetOrGetThreadGlobals(true, this)); - - return p_prevThreadGlobals; + return ThreadGlobals::SetForCurrentThread(); } - void ThreadGlobals::Initialize() + void WingetThreadGlobals::Initialize() { try { @@ -56,28 +52,4 @@ namespace AppInstaller::ThreadLocalStorage // Loggers are best effort and shouldn't block core functionality. So eat up the exceptions here } } - - ThreadGlobals* ThreadGlobals::GetForCurrentThread() - { - return SetOrGetThreadGlobals(false); - } - - ThreadGlobals* SetOrGetThreadGlobals(bool setThreadGlobals, ThreadGlobals* pThreadGlobals) - { - thread_local AppInstaller::ThreadLocalStorage::ThreadGlobals* t_pThreadGlobals = nullptr; - - if (setThreadGlobals == true) - { - AppInstaller::ThreadLocalStorage::ThreadGlobals* previous_pThreadGlobals = t_pThreadGlobals; - t_pThreadGlobals = pThreadGlobals; - return previous_pThreadGlobals; - } - - return t_pThreadGlobals; - } - - PreviousThreadGlobals::~PreviousThreadGlobals() - { - std::ignore = SetOrGetThreadGlobals(true, m_previous); - } } diff --git a/src/AppInstallerCommonCore/TraceLogger.cpp b/src/AppInstallerCommonCore/TraceLogger.cpp @@ -41,4 +41,9 @@ namespace AppInstaller::Logging { return "Trace"; } + + void TraceLogger::Add() + { + Log().AddLogger(std::make_unique<TraceLogger>()); + } } diff --git a/src/AppInstallerRepositoryCore/AppInstallerRepositoryCore.vcxproj b/src/AppInstallerRepositoryCore/AppInstallerRepositoryCore.vcxproj @@ -161,9 +161,9 @@ <ClCompile> <Optimization>Disabled</Optimization> <PreprocessorDefinitions>_NO_ASYNCRTIMP;_DEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatWarningAsError> @@ -184,7 +184,7 @@ <ItemDefinitionGroup Condition="'$(Platform)'=='Win32'"> <ClCompile> <PreprocessorDefinitions>_NO_ASYNCRTIMP;WIN32;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</TreatWarningAsError> <SDLCheck Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</SDLCheck> <EnablePREfast Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</EnablePREfast> @@ -199,10 +199,10 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>_NO_ASYNCRTIMP;NDEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(ProjectDir)\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</TreatWarningAsError> diff --git a/src/AppInstallerRepositoryCore/InstallerMetadataCollectionContext.cpp b/src/AppInstallerRepositoryCore/InstallerMetadataCollectionContext.cpp @@ -6,6 +6,8 @@ #include <AppInstallerDownloader.h> #include <AppInstallerErrors.h> #include <AppInstallerLogging.h> +#include <AppInstallerFileLogger.h> +#include <winget/TraceLogger.h> #include <AppInstallerStrings.h> #include <winget/ManifestJSONParser.h> @@ -590,7 +592,7 @@ namespace AppInstaller::Repository::Metadata std::wstring InstallerMetadataCollectionContext::Merge(const std::wstring& json, size_t maximumSizeInBytes, const std::filesystem::path& logFile) { - ThreadLocalStorage::ThreadGlobals threadGlobals; + ThreadLocalStorage::WingetThreadGlobals threadGlobals; auto globalsLifetime = InitializeLogging(threadGlobals, logFile); AICLI_LOG(Repo, Info, << "Parsing input JSON:\n" << ConvertToUTF8(json)); @@ -676,18 +678,18 @@ namespace AppInstaller::Repository::Metadata outputJSON.serialize(output); } - std::unique_ptr<ThreadLocalStorage::PreviousThreadGlobals> InstallerMetadataCollectionContext::InitializeLogging(ThreadLocalStorage::ThreadGlobals& threadGlobals, const std::filesystem::path& logFile) + std::unique_ptr<ThreadLocalStorage::PreviousThreadGlobals> InstallerMetadataCollectionContext::InitializeLogging(ThreadLocalStorage::WingetThreadGlobals& threadGlobals, const std::filesystem::path& logFile) { auto threadGlobalsLifetime = threadGlobals.SetForCurrentThread(); Logging::Log().SetLevel(Logging::Level::Info); Logging::Log().EnableChannel(Logging::Channel::All); Logging::EnableWilFailureTelemetry(); - Logging::AddTraceLogger(); + Logging::TraceLogger::Add(); if (!logFile.empty()) { - Logging::AddFileLogger(logFile); + Logging::FileLogger::Add(logFile); } Logging::Telemetry().SetCaller("installer-metadata-collection"); diff --git a/src/AppInstallerRepositoryCore/Public/winget/InstallerMetadataCollectionContext.h b/src/AppInstallerRepositoryCore/Public/winget/InstallerMetadataCollectionContext.h @@ -105,7 +105,7 @@ namespace AppInstaller::Repository::Metadata private: // Initializes the context runtime, including the log file if provided. - static std::unique_ptr<ThreadLocalStorage::PreviousThreadGlobals> InitializeLogging(ThreadLocalStorage::ThreadGlobals& threadGlobals, const std::filesystem::path& logFile); + static std::unique_ptr<ThreadLocalStorage::PreviousThreadGlobals> InitializeLogging(ThreadLocalStorage::WingetThreadGlobals& threadGlobals, const std::filesystem::path& logFile); std::unique_ptr<ThreadLocalStorage::PreviousThreadGlobals> InitializeLogging(const std::filesystem::path& logFile); // Sets the collection context input and the preinstall state. @@ -135,7 +135,7 @@ namespace AppInstaller::Repository::Metadata // Merge using merge input version 1.0 static web::json::value Merge_1_0(web::json::value& input, size_t maximumSizeInBytes); - ThreadLocalStorage::ThreadGlobals m_threadGlobals; + ThreadLocalStorage::WingetThreadGlobals m_threadGlobals; // Parsed input Utility::Version m_inputVersion; diff --git a/src/AppInstallerSharedLib/AppInstallerLogging.cpp b/src/AppInstallerSharedLib/AppInstallerLogging.cpp @@ -0,0 +1,161 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#include "pch.h" +#include "Public/AppInstallerLogging.h" + +#include "Public/AppInstallerDateTime.h" +#include "Public/winget/SharedThreadGlobals.h" + +namespace AppInstaller::Logging +{ + namespace + { + template <typename E> + std::underlying_type_t<E> AsNum(E e) + { + return static_cast<std::underlying_type_t<E>>(e); + } + + uint64_t ConvertChannelToBitmask(Channel channel) + { + if (channel == Channel::All) + { + return std::numeric_limits<uint64_t>::max(); + } + else + { + return (1ull << AsNum(channel)); + } + } + } + + char const* GetChannelName(Channel channel) + { + switch(channel) + { + case Channel::Fail: return "FAIL"; + case Channel::CLI: return "CLI"; + case Channel::SQL: return "SQL"; + case Channel::Repo: return "REPO"; + case Channel::YAML: return "YAML"; + case Channel::Core: return "CORE"; + case Channel::Test: return "TEST"; + default: return "NONE"; + } + } + + size_t GetMaxChannelNameLength() { return 4; } + + void DiagnosticLogger::AddLogger(std::unique_ptr<ILogger>&& logger) + { + m_loggers.emplace_back(std::move(logger)); + } + + bool DiagnosticLogger::ContainsLogger(const std::string& name) + { + for (auto i = m_loggers.begin(); i != m_loggers.end(); ++i) + { + if ((*i)->GetName() == name) + { + return true; + } + } + + return false; + } + + std::unique_ptr<ILogger> DiagnosticLogger::RemoveLogger(const std::string& name) + { + std::unique_ptr<ILogger> result; + + for (auto i = m_loggers.begin(); i != m_loggers.end(); ++i) + { + if ((*i)->GetName() == name) + { + result = std::move(*i); + m_loggers.erase(i); + break; + } + } + + return result; + } + + void DiagnosticLogger::RemoveAllLoggers() + { + m_loggers.clear(); + } + + void DiagnosticLogger::EnableChannel(Channel channel) + { + m_enabledChannels |= ConvertChannelToBitmask(channel); + } + + void DiagnosticLogger::DisableChannel(Channel channel) + { + m_enabledChannels &= ~ConvertChannelToBitmask(channel); + } + + void DiagnosticLogger::SetLevel(Level level) + { + m_enabledLevel = level; + } + + bool DiagnosticLogger::IsEnabled(Channel channel, Level level) const + { + return (!m_loggers.empty() && + (m_enabledChannels & ConvertChannelToBitmask(channel)) != 0 && + (AsNum(level) >= AsNum(m_enabledLevel))); + } + + void DiagnosticLogger::Write(Channel channel, Level level, std::string_view message) + { + THROW_HR_IF_MSG(E_INVALIDARG, channel == Channel::All, "Cannot write to all channels"); + + if (IsEnabled(channel, level)) + { + for (auto& logger : m_loggers) + { + logger->Write(channel, level, message); + } + } + } + + void DiagnosticLogger::WriteDirect(Channel channel, Level level, std::string_view message) + { + THROW_HR_IF_MSG(E_INVALIDARG, channel == Channel::All, "Cannot write to all channels"); + + if (IsEnabled(channel, level)) + { + for (auto& logger : m_loggers) + { + logger->WriteDirect(message); + } + } + } + + DiagnosticLogger& Log() + { + ThreadLocalStorage::ThreadGlobals* pThreadGlobals = ThreadLocalStorage::ThreadGlobals::GetForCurrentThread(); + if (pThreadGlobals) + { + return pThreadGlobals->GetDiagnosticLogger(); + } + else + { + static DiagnosticLogger processGlobalLogger; + return processGlobalLogger; + } + } + + std::ostream& SetHRFormat(std::ostream& out) + { + return out << std::hex << std::setw(8) << std::setfill('0'); + } +} + +std::ostream& operator<<(std::ostream& out, const std::chrono::system_clock::time_point& time) +{ + AppInstaller::Utility::OutputTimePoint(out, time); + return out; +} diff --git a/src/AppInstallerSharedLib/AppInstallerSharedLib.vcxproj b/src/AppInstallerSharedLib/AppInstallerSharedLib.vcxproj @@ -0,0 +1,331 @@ +<?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.210505.3\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.210505.3\build\native\Microsoft.Windows.CppWinRT.props')" /> + <PropertyGroup Label="Globals"> + <CppWinRTOptimized>true</CppWinRTOptimized> + <CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge> + <MinimalCoreWin>true</MinimalCoreWin> + <VCProjectVersion>15.0</VCProjectVersion> + <ProjectGuid>{F3F6E699-BC5D-4950-8A05-E49DD9EB0D51}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <WindowsTargetPlatformVersion>10.0.22000.0</WindowsTargetPlatformVersion> + <WindowsTargetPlatformMinVersion>10.0.17763.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="Fuzzing|x64"> + <Configuration>Fuzzing</Configuration> + <Platform>x64</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>StaticLibrary</ConfigurationType> + <PlatformToolset>v140</PlatformToolset> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '17.0'">v143</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> + <PropertyGroup Condition="'$(Configuration)'=='Fuzzing'" Label="Configuration"> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>false</WholeProgramOptimization> + <LinkIncremental>false</LinkIncremental> + <EnableASAN>true</EnableASAN> + </PropertyGroup> + <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|ARM'"> + <SpectreMitigation>Spectre</SpectreMitigation> + </PropertyGroup> + <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'"> + <SpectreMitigation>Spectre</SpectreMitigation> + </PropertyGroup> + <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <SpectreMitigation>Spectre</SpectreMitigation> + </PropertyGroup> + <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <SpectreMitigation>Spectre</SpectreMitigation> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + <Import Project="..\Valijson\Valijson.vcxitems" Label="Shared" /> + </ImportGroup> + <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> + <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors> + <RunCodeAnalysis>true</RunCodeAnalysis> + <CodeAnalysisRuleSet>..\CodeAnalysis.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> + <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors> + <RunCodeAnalysis>true</RunCodeAnalysis> + <CodeAnalysisRuleSet>..\CodeAnalysis.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> + <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors> + <RunCodeAnalysis>true</RunCodeAnalysis> + <CodeAnalysisRuleSet>..\CodeAnalysis.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)x86\$(Configuration)\$(ProjectName)\</OutDir> + <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors> + <RunCodeAnalysis>true</RunCodeAnalysis> + <CodeAnalysisRuleSet>..\CodeAnalysis.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(SolutionDir)x86\$(Configuration)\$(ProjectName)\</OutDir> + <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors> + <RunCodeAnalysis>false</RunCodeAnalysis> + <CodeAnalysisRuleSet>..\CodeAnalysis.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> + <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors> + <RunCodeAnalysis>false</RunCodeAnalysis> + <CodeAnalysisRuleSet>..\CodeAnalysis.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Fuzzing|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> + <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors> + <RunCodeAnalysis>false</RunCodeAnalysis> + <CodeAnalysisRuleSet>..\CodeAnalysis.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> + <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors> + <RunCodeAnalysis>false</RunCodeAnalysis> + <CodeAnalysisRuleSet>..\CodeAnalysis.ruleset</CodeAnalysisRuleSet> + </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- /D _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING</AdditionalOptions> + </ClCompile> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'"> + <ClCompile> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>_NO_ASYNCRTIMP;_DEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\PureLib\pure;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\PureLib\pure;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\PureLib\pure;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</TreatWarningAsError> + <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</TreatWarningAsError> + <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatWarningAsError> + <SDLCheck Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</SDLCheck> + <SDLCheck Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</SDLCheck> + <SDLCheck Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</SDLCheck> + <EnablePREfast Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</EnablePREfast> + <EnablePREfast Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</EnablePREfast> + <EnablePREfast Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</EnablePREfast> + </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> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Platform)'=='Win32'"> + <ClCompile> + <PreprocessorDefinitions>_NO_ASYNCRTIMP;WIN32;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\PureLib\pure;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</TreatWarningAsError> + <SDLCheck Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</SDLCheck> + <EnablePREfast Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</EnablePREfast> + </ClCompile> + <Link> + <SubSystem Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Windows</SubSystem> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)'=='Release'"> + <ClCompile> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>_NO_ASYNCRTIMP;NDEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\PureLib\pure;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\PureLib\pure;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\PureLib\pure;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\PureLib\pure;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</TreatWarningAsError> + <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</TreatWarningAsError> + <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</TreatWarningAsError> + <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</TreatWarningAsError> + <SDLCheck Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</SDLCheck> + <SDLCheck Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</SDLCheck> + <SDLCheck Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</SDLCheck> + <SDLCheck Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</SDLCheck> + <EnablePREfast Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">false</EnablePREfast> + <EnablePREfast Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</EnablePREfast> + <EnablePREfast Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</EnablePREfast> + <EnablePREfast Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</EnablePREfast> + </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> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)'=='Fuzzing'"> + <ClCompile> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>_NO_ASYNCRTIMP;NDEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD;WINGET_DISABLE_FOR_FUZZING</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)Public;$(ProjectDir)Telemetry;$(ProjectDir)..\binver;$(ProjectDir)..\YamlCppLib\libyaml\include;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <TreatWarningAsError>true</TreatWarningAsError> + <LanguageStandard>stdcpp17</LanguageStandard> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + <AdditionalOptions>%(AdditionalOptions) /fsanitize-coverage=inline-8bit-counters /fsanitize-coverage=edge /fsanitize-coverage=trace-cmp /fsanitize-coverage=trace-div</AdditionalOptions> + </ClCompile> + <Link> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateWindowsMetadata>false</GenerateWindowsMetadata> + <SubSystem>Windows</SubSystem> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(WingetDisableTestHooks)'=='true'"> + <ClCompile> + <PreprocessorDefinitions>AICLI_DISABLE_TEST_HOOKS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(WingetDisableExperimentalFeatures)'=='true'"> + <ClCompile> + <PreprocessorDefinitions>WINGET_DISABLE_EXPERIMENTAL_FEATURES;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(WingetEnableReleaseBuild)'=='true'"> + <ClCompile> + <PreprocessorDefinitions>WINGET_ENABLE_RELEASE_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + </ItemDefinitionGroup> + <ItemGroup> + <ClInclude Include="pch.h" /> + <ClInclude Include="Public\AppInstallerDateTime.h" /> + <ClInclude Include="Public\AppInstallerErrors.h" /> + <ClInclude Include="Public\AppInstallerLanguageUtilities.h" /> + <ClInclude Include="Public\AppInstallerSHA256.h" /> + <ClInclude Include="Public\AppInstallerStrings.h" /> + <ClInclude Include="Public\AppInstallerLogging.h" /> + <ClInclude Include="Public\winget\JsonSchemaValidation.h" /> + <ClInclude Include="Public\winget\LocIndependent.h" /> + <ClInclude Include="Public\winget\Resources.h" /> + <ClInclude Include="Public\winget\SharedThreadGlobals.h" /> + <ClInclude Include="Public\winget\Yaml.h" /> + <ClInclude Include="YamlWrapper.h" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="AppInstallerLogging.cpp" /> + <ClCompile Include="AppInstallerStrings.cpp" /> + <ClCompile Include="DateTime.cpp" /> + <ClCompile Include="Errors.cpp" /> + <ClCompile Include="JsonSchemaValidation.cpp" /> + <ClCompile Include="Resources.cpp" /> + <ClCompile Include="pch.cpp"> + <PrecompiledHeader>Create</PrecompiledHeader> + </ClCompile> + <ClCompile Include="SHA256.cpp" /> + <ClCompile Include="SharedThreadGlobals.cpp" /> + <ClCompile Include="Yaml.cpp" /> + <ClCompile Include="YamlWrapper.cpp" /> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + <None Include="PropertySheet.props" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\JsonCppLib\JsonCppLib.vcxproj"> + <Project>{82b39fda-e86b-4713-a873-9d56de00247a}</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.ImplementationLibrary.1.0.210204.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.210204.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" /> + <Import Project="$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.210505.3\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.210505.3\build\native\Microsoft.Windows.CppWinRT.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.ImplementationLibrary.1.0.210204.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.210204.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" /> + <Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.210505.3\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.210505.3\build\native\Microsoft.Windows.CppWinRT.props'))" /> + <Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.210505.3\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.210505.3\build\native\Microsoft.Windows.CppWinRT.targets'))" /> + </Target> +</Project>+ \ No newline at end of file diff --git a/src/AppInstallerSharedLib/AppInstallerSharedLib.vcxproj.filters b/src/AppInstallerSharedLib/AppInstallerSharedLib.vcxproj.filters @@ -0,0 +1,99 @@ +<?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="Public"> + <UniqueIdentifier>{5cdf3fa3-e657-4d84-81bb-f740aa476143}</UniqueIdentifier> + </Filter> + <Filter Include="Public\winget"> + <UniqueIdentifier>{41035fd6-dc74-4464-b9b1-4ffe95d6789c}</UniqueIdentifier> + </Filter> + </ItemGroup> + <ItemGroup> + <ClInclude Include="pch.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="Public\AppInstallerLogging.h"> + <Filter>Public</Filter> + </ClInclude> + <ClInclude Include="Public\AppInstallerStrings.h"> + <Filter>Public</Filter> + </ClInclude> + <ClInclude Include="Public\AppInstallerSHA256.h"> + <Filter>Public</Filter> + </ClInclude> + <ClInclude Include="Public\AppInstallerErrors.h"> + <Filter>Public</Filter> + </ClInclude> + <ClInclude Include="Public\AppInstallerDateTime.h"> + <Filter>Public</Filter> + </ClInclude> + <ClInclude Include="YamlWrapper.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="Public\winget\Yaml.h"> + <Filter>Public\winget</Filter> + </ClInclude> + <ClInclude Include="Public\winget\JsonSchemaValidation.h"> + <Filter>Public\winget</Filter> + </ClInclude> + <ClInclude Include="Public\winget\Resources.h"> + <Filter>Public\winget</Filter> + </ClInclude> + <ClInclude Include="Public\winget\SharedThreadGlobals.h"> + <Filter>Public\winget</Filter> + </ClInclude> + <ClInclude Include="Public\winget\LocIndependent.h"> + <Filter>Public\winget</Filter> + </ClInclude> + <ClInclude Include="Public\AppInstallerLanguageUtilities.h"> + <Filter>Public</Filter> + </ClInclude> + </ItemGroup> + <ItemGroup> + <ClCompile Include="pch.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="AppInstallerLogging.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="AppInstallerStrings.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="DateTime.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="SHA256.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="Errors.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="YamlWrapper.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="Yaml.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="JsonSchemaValidation.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="SharedThreadGlobals.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="Resources.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <None Include="PropertySheet.props" /> + <None Include="packages.config" /> + </ItemGroup> +</Project>+ \ No newline at end of file diff --git a/src/AppInstallerCommonCore/AppInstallerStrings.cpp b/src/AppInstallerSharedLib/AppInstallerStrings.cpp diff --git a/src/AppInstallerCommonCore/DateTime.cpp b/src/AppInstallerSharedLib/DateTime.cpp diff --git a/src/AppInstallerCommonCore/Errors.cpp b/src/AppInstallerSharedLib/Errors.cpp diff --git a/src/AppInstallerCommonCore/JsonSchemaValidation.cpp b/src/AppInstallerSharedLib/JsonSchemaValidation.cpp diff --git a/src/AppInstallerSharedLib/PropertySheet.props b/src/AppInstallerSharedLib/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/AppInstallerCommonCore/Public/AppInstallerDateTime.h b/src/AppInstallerSharedLib/Public/AppInstallerDateTime.h diff --git a/src/AppInstallerCommonCore/Public/AppInstallerErrors.h b/src/AppInstallerSharedLib/Public/AppInstallerErrors.h diff --git a/src/AppInstallerCommonCore/Public/AppInstallerLanguageUtilities.h b/src/AppInstallerSharedLib/Public/AppInstallerLanguageUtilities.h diff --git a/src/AppInstallerSharedLib/Public/AppInstallerLogging.h b/src/AppInstallerSharedLib/Public/AppInstallerLogging.h @@ -0,0 +1,187 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#pragma once + +#include <chrono> +#include <filesystem> +#include <memory> +#include <sstream> +#include <string> +#include <string_view> +#include <type_traits> +#include <vector> + +#define AICLI_LOG(_channel_,_level_,_outstream_) \ + do { \ + auto _aicli_log_channel = AppInstaller::Logging::Channel:: _channel_; \ + auto _aicli_log_level = AppInstaller::Logging::Level:: _level_; \ + auto& _aicli_log_log = AppInstaller::Logging::Log(); \ + if (_aicli_log_log.IsEnabled(_aicli_log_channel, _aicli_log_level)) \ + { \ + AppInstaller::Logging::LoggingStream _aicli_log_strstr; \ + _aicli_log_strstr _outstream_; \ + _aicli_log_log.Write(_aicli_log_channel, _aicli_log_level, _aicli_log_strstr.str()); \ + } \ + } while (0, 0) + +// Consider using this macro when the string might be larger than 4K. +// The normal macro has some buffering that occurs; it can cut off larger strings and is slower. +#define AICLI_LOG_LARGE_STRING(_channel_,_level_,_headerStream_,_largeString_) \ + do { \ + auto _aicli_log_channel = AppInstaller::Logging::Channel:: _channel_; \ + auto _aicli_log_level = AppInstaller::Logging::Level:: _level_; \ + auto& _aicli_log_log = AppInstaller::Logging::Log(); \ + if (_aicli_log_log.IsEnabled(_aicli_log_channel, _aicli_log_level)) \ + { \ + AppInstaller::Logging::LoggingStream _aicli_log_strstr; \ + _aicli_log_strstr _headerStream_; \ + _aicli_log_log.Write(_aicli_log_channel, _aicli_log_level, _aicli_log_strstr.str()); \ + _aicli_log_log.WriteDirect(_aicli_log_channel, _aicli_log_level, _largeString_); \ + } \ + } while (0, 0) + +namespace AppInstaller::Logging +{ + // The channel that the log is from. + // Channels enable large groups of logs to be enabled or disabled together. + enum class Channel : uint32_t + { + Fail, + CLI, + SQL, + Repo, + YAML, + Core, + Test, + All, + }; + + // Gets the channel's name as a string. + char const* GetChannelName(Channel channel); + + // Gets the maximum channel name length in characters. + size_t GetMaxChannelNameLength(); + + // The level of the log. + enum class Level + { + Verbose, + Info, + Warning, + Error, + Crit, + }; + + // The interface that a log target must implement. + struct ILogger + { + virtual ~ILogger() = default; + + // Gets the name of the logger for internal use. + virtual std::string GetName() const = 0; + + // Informs the logger of the given log. + virtual void Write(Channel channel, Level level, std::string_view message) noexcept = 0; + + // Informs the logger of the given log with the intention that no buffering occurs (in winget code). + virtual void WriteDirect(std::string_view message) noexcept = 0; + }; + + // This type contains the set of loggers that diagnostic logging will be sent to. + // Each binary that leverages it must configure any loggers and filters to their + // desired level, as nothing is enabled by default. + struct DiagnosticLogger + { + DiagnosticLogger() = default; + + ~DiagnosticLogger() = default; + + DiagnosticLogger(const DiagnosticLogger&) = delete; + DiagnosticLogger& operator=(const DiagnosticLogger&) = delete; + + DiagnosticLogger(DiagnosticLogger&&) = delete; + DiagnosticLogger& operator=(DiagnosticLogger&&) = delete; + + // Gets the singleton instance of this type. + static DiagnosticLogger& GetInstance(); + + // NOTE: The logger management functionality is *SINGLE THREAD SAFE*. + // This includes with logging itself. + // As it is not expected that adding/removing loggers is an + // extremely frequent operation, no care has been made to protect + // it from modifying loggers while logging may be occurring. + + // Adds a logger to the active set. + void AddLogger(std::unique_ptr<ILogger>&& logger); + + // Determines if a logger with the given name is present. + bool ContainsLogger(const std::string& name); + + // Removes a logger from the active set, returning it. + std::unique_ptr<ILogger> RemoveLogger(const std::string& name); + + // Removes all loggers. + void RemoveAllLoggers(); + + // Enables the given channel. + void EnableChannel(Channel channel); + + // Disables the given channel. + void DisableChannel(Channel channel); + + // Sets the enabled level. + // All levels higher than this level will be enabled. + // For example; SetLevel(Verbose) will enable all logs. + void SetLevel(Level level); + + // Checks whether a given channel and level are enabled. + bool IsEnabled(Channel channel, Level level) const; + + // Writes a log line, if the given channel and level are enabled. + void Write(Channel channel, Level level, std::string_view message); + + // Writes a log line, if the given channel and level are enabled. + // Use to make large logs more efficient by writing directly to the output streams. + void WriteDirect(Channel channel, Level level, std::string_view message); + + private: + + std::vector<std::unique_ptr<ILogger>> m_loggers; + uint64_t m_enabledChannels = 0; + Level m_enabledLevel = Level::Info; + }; + + DiagnosticLogger& Log(); + + // Calls the various stream format functions to produce an 8 character hexadecimal output. + std::ostream& SetHRFormat(std::ostream& out); + + // This type allows us to override the default behavior of output operators for logging. + struct LoggingStream + { + // Force use of the UTF-8 string from a file path. + // This should not be necessary when we move to C++20 and convert to using u8string. + friend AppInstaller::Logging::LoggingStream& operator<<(AppInstaller::Logging::LoggingStream& out, const std::filesystem::path& path) + { + out.m_out << path.u8string(); + return out; + } + + // Everything else. + template <typename T> + friend std::enable_if_t<!std::is_same_v<std::decay_t<T>, std::filesystem::path>, AppInstaller::Logging::LoggingStream&> + operator<<(AppInstaller::Logging::LoggingStream& out, T&& t) + { + out.m_out << std::forward<T>(t); + return out; + } + + std::string str() const { return m_out.str(); } + + private: + std::stringstream m_out; + }; +} + +// Enable output of system_clock time_points. +std::ostream& operator<<(std::ostream& out, const std::chrono::system_clock::time_point& time); diff --git a/src/AppInstallerCommonCore/Public/AppInstallerSHA256.h b/src/AppInstallerSharedLib/Public/AppInstallerSHA256.h diff --git a/src/AppInstallerCommonCore/Public/AppInstallerStrings.h b/src/AppInstallerSharedLib/Public/AppInstallerStrings.h diff --git a/src/AppInstallerCommonCore/Public/winget/JsonSchemaValidation.h b/src/AppInstallerSharedLib/Public/winget/JsonSchemaValidation.h diff --git a/src/AppInstallerCommonCore/Public/winget/LocIndependent.h b/src/AppInstallerSharedLib/Public/winget/LocIndependent.h diff --git a/src/AppInstallerCommonCore/Public/winget/Resources.h b/src/AppInstallerSharedLib/Public/winget/Resources.h diff --git a/src/AppInstallerSharedLib/Public/winget/SharedThreadGlobals.h b/src/AppInstallerSharedLib/Public/winget/SharedThreadGlobals.h @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#pragma once +#include <AppInstallerLogging.h> + +namespace AppInstaller::Logging +{ + struct TelemetryTraceLogger; +} + +namespace AppInstaller::ThreadLocalStorage +{ + struct PreviousThreadGlobals; + + // Interface for access to values that are stored on a per-thread object. + struct ThreadGlobals + { + ThreadGlobals() = default; + virtual ~ThreadGlobals() = default; + + virtual AppInstaller::Logging::DiagnosticLogger& GetDiagnosticLogger() = 0; + + virtual AppInstaller::Logging::TelemetryTraceLogger& GetTelemetryLogger() = 0; + + // Set Globals for Current Thread + // Return RAII object with it's ownership to set the AppInstaller ThreadLocalStorage back to previous state + virtual std::unique_ptr<AppInstaller::ThreadLocalStorage::PreviousThreadGlobals> SetForCurrentThread(); + + // Return Globals for Current Thread + static ThreadGlobals* GetForCurrentThread(); + }; + + // RAII object used to + struct PreviousThreadGlobals + { + ~PreviousThreadGlobals(); + + PreviousThreadGlobals(ThreadGlobals* previous) : m_previous(previous) {}; + + private: + ThreadGlobals* m_previous; + }; +} diff --git a/src/AppInstallerCommonCore/Public/winget/Yaml.h b/src/AppInstallerSharedLib/Public/winget/Yaml.h diff --git a/src/AppInstallerSharedLib/Resources.cpp b/src/AppInstallerSharedLib/Resources.cpp @@ -0,0 +1,122 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#include "pch.h" +#include "winget/Resources.h" +#include "Public/AppInstallerLogging.h" +#include "Public/AppInstallerStrings.h" +#include "Public/AppInstallerErrors.h" + +namespace AppInstaller +{ + namespace Resource + { + namespace + { + std::pair<void*, size_t> GetResourceData(PCWSTR resourceName, PCWSTR resourceType) + { + HMODULE resourceModule = nullptr; + GetModuleHandleExW( + GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast<PCWSTR>(GetResourceData), + &resourceModule); + THROW_LAST_ERROR_IF_NULL(resourceModule); + + HRSRC resourceInfoHandle = FindResourceW(resourceModule, resourceName, resourceType); + THROW_LAST_ERROR_IF_NULL(resourceInfoHandle); + + HGLOBAL resourceMemoryHandle = LoadResource(resourceModule, resourceInfoHandle); + THROW_LAST_ERROR_IF_NULL(resourceMemoryHandle); + + DWORD resourceSize = SizeofResource(resourceModule, resourceInfoHandle); + THROW_LAST_ERROR_IF(resourceSize == 0); + + void* resourceContent = LockResource(resourceMemoryHandle); + THROW_HR_IF_NULL(E_UNEXPECTED, resourceContent); + + return std::make_pair(resourceContent, static_cast<size_t>(resourceSize)); + } + } + + std::string_view GetResourceAsString(int resourceName, int resourceType) + { + return GetResourceAsString(MAKEINTRESOURCE(resourceName), MAKEINTRESOURCE(resourceType)); + } + + std::string_view GetResourceAsString(PCWSTR resourceName, PCWSTR resourceType) + { + auto resourceData = GetResourceData(resourceName, resourceType); + return { reinterpret_cast<char*>(resourceData.first), resourceData.second }; + } + + std::pair<const BYTE*, size_t> GetResourceAsBytes(int resourceName, int resourceType) + { + return GetResourceAsBytes(MAKEINTRESOURCE(resourceName), MAKEINTRESOURCE(resourceType)); + } + + std::pair<const BYTE*, size_t> GetResourceAsBytes(PCWSTR resourceName, PCWSTR resourceType) + { + auto resourceData = GetResourceData(resourceName, resourceType); + return std::make_pair(reinterpret_cast<BYTE*>(resourceData.first), resourceData.second); + } + + // Utility class to load resources + struct Loader + { + // Gets the singleton instance of the resource loader. + static const Loader& Instance() + { + static Loader instance; + return instance; + } + + // Gets the string resource value. + std::string ResolveString(std::wstring_view resKey) const + { + if (m_wingetLoader) + { + return Utility::ConvertToUTF8(m_wingetLoader.GetString(resKey)); + } + + // Loader failed to load resource file, print the resource key instead. + return Utility::ConvertToUTF8(resKey); + } + + private: + winrt::Windows::ApplicationModel::Resources::ResourceLoader m_wingetLoader; + + Loader() : m_wingetLoader(nullptr) + { + try + { + // The default constructor of ResourceLoader throws a winrt::hresult_error exception + // when resource.pri is not found. ResourceLoader::GetForViewIndependentUse also throws + // a winrt::hresult_error but for reasons unknown it only gets caught when running on the + // debugger. Running without a debugger will result in a crash that not even adding a + // catch all will fix. To provide a good error message we call the default constructor + // before calling GetForViewIndependentUse. + m_wingetLoader = winrt::Windows::ApplicationModel::Resources::ResourceLoader(); + m_wingetLoader = winrt::Windows::ApplicationModel::Resources::ResourceLoader::GetForViewIndependentUse(L"winget"); + } + catch (const winrt::hresult_error& hre) + { + // This message cannot be localized. + AICLI_LOG(CLI, Error, << "Failure loading resource file with error: " << hre.code()); + m_wingetLoader = nullptr; + } + } + }; + } + + namespace StringResource + { + std::string StringId::Resolve() const + { + return Resource::Loader::Instance().ResolveString(*this); + } + + std::ostream& operator<<(std::ostream& out, StringId si) + { + return (out << Resource::LocString{ si }); + } + } +} diff --git a/src/AppInstallerSharedLib/SHA256.cpp b/src/AppInstallerSharedLib/SHA256.cpp @@ -0,0 +1,174 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#include <pch.h> +#define WIN32_NO_STATUS +#include <bcrypt.h> +#include "Public/AppInstallerSHA256.h" +#include "Public/AppInstallerErrors.h" +#include "Public/AppInstallerStrings.h" + +namespace AppInstaller::Utility { + + struct SHA256Context + { + wil::unique_bcrypt_algorithm algHandle; + wil::unique_bcrypt_hash hashHandle; + DWORD hashLength = 0; + }; + + SHA256::SHA256() : context(new SHA256Context{}) + { + BCRYPT_ALG_HANDLE algHandleT{}; + BCRYPT_HASH_HANDLE hashHandleT; + DWORD resultLength = 0; + + // Open an algorithm handle + THROW_IF_NTSTATUS_FAILED_MSG(BCryptOpenAlgorithmProvider( + &algHandleT, // Alg Handle pointer + BCRYPT_SHA256_ALGORITHM, // Cryptographic Algorithm name (null terminated unicode string) + nullptr, // Provider name; if null, the default provider is loaded + 0), // Flags + "failed opening SHA256 algorithm provider"); + context->algHandle.reset(algHandleT); + + // Obtain the length of the hash + THROW_IF_NTSTATUS_FAILED_MSG(BCryptGetProperty( + context->algHandle.get(), // Handle to a CNG object + BCRYPT_HASH_LENGTH, // Property name (null terminated unicode string) + (PBYTE) & (context->hashLength), // Address of the output buffer which receives the property value + sizeof(context->hashLength), // Size of the buffer in bytes + &resultLength, // Number of bytes that were copied into the buffer + 0), // Flags + "failed getting SHA256 hash length"); + + if (resultLength != sizeof(context->hashLength)) + { + THROW_HR_MSG(E_UNEXPECTED, "failed getting SHA256 hash length"); + } + + // Create a hash handle + THROW_IF_NTSTATUS_FAILED_MSG(BCryptCreateHash( + context->algHandle.get(), // Handle to an algorithm provider + &hashHandleT, // A pointer to a hash handle - can be a hash or hmac object + nullptr, // Pointer to the buffer that receives the hash/hmac object + 0, // Size of the buffer in bytes + nullptr, // A pointer to a key to use for the hash or MAC + 0, // Size of the key in bytes + 0), // Flags + "failed creating SHA256 hash object"); + context->hashHandle.reset(hashHandleT); + } + + void SHA256::Add(const uint8_t* buffer, size_t cbBuffer) + { + EnsureNotFinished(); + + // Add the data + THROW_IF_NTSTATUS_FAILED_MSG( + BCryptHashData(context->hashHandle.get(), const_cast<PUCHAR>(buffer), static_cast<ULONG>(cbBuffer), 0), + "failed adding SHA256 data"); + } + + void SHA256::Get(HashBuffer& hash) + { + EnsureNotFinished(); + + // Size the hash buffer appropriately + hash.resize(context->hashLength); + + // Obtain the hash of the message(s) into the hash buffer + THROW_IF_NTSTATUS_FAILED_MSG(BCryptFinishHash( + context->hashHandle.get(), // Handle to the hash or MAC object + hash.data(), // A pointer to a buffer that receives the hash or MAC value + context->hashLength, // Size of the buffer in bytes + 0), // Flags + "failed getting SHA256 hash"); + + context.reset(); + } + + std::string SHA256::ConvertToString(const HashBuffer& hashBuffer) + { + return Utility::ConvertToHexString(hashBuffer, HashBufferSizeInBytes); + } + + std::wstring SHA256::ConvertToWideString(const HashBuffer& hashBuffer) + { + return ConvertToUTF16(SHA256::ConvertToString(hashBuffer)); + } + + SHA256::HashBuffer SHA256::ConvertToBytes(const std::string& hashStr) + { + return Utility::ParseFromHexString(hashStr, HashBufferSizeInBytes); + } + + SHA256::HashBuffer SHA256::ComputeHash(const std::uint8_t* buffer, std::uint32_t cbBuffer) + { + SHA256 hasher; + hasher.Add(buffer, cbBuffer); + return hasher.Get(); + } + + SHA256::HashBuffer SHA256::ComputeHash(std::string_view buffer) + { + return ComputeHash(reinterpret_cast<const std::uint8_t*>(buffer.data()), static_cast<std::uint32_t>(buffer.size())); + } + + SHA256::HashBuffer SHA256::ComputeHash(std::istream& in) + { + // Throw exceptions on badbit + auto excState = in.exceptions(); + auto revertExcState = wil::scope_exit([excState, &in]() { in.exceptions(excState); }); + in.exceptions(std::ios_base::badbit); + + const int bufferSize = 1024 * 1024; // 1MB + auto buffer = std::make_unique<uint8_t[]>(bufferSize); + + SHA256 hasher; + + while (in.good()) + { + in.read((char*)(buffer.get()), bufferSize); + if (in.gcount()) + { + hasher.Add(buffer.get(), static_cast<size_t>(in.gcount())); + } + } + + if (in.eof()) + { + return hasher.Get(); + } + else + { + THROW_HR(APPINSTALLER_CLI_ERROR_STREAM_READ_FAILURE); + } + } + + + SHA256::HashBuffer SHA256::ComputeHashFromFile(const std::filesystem::path& path) + { + std::ifstream inStream{ path, std::ifstream::binary }; + const Utility::SHA256::HashBuffer& targetFileHash = Utility::SHA256::ComputeHash(inStream); + inStream.close(); + return targetFileHash; + } + + void SHA256::SHA256ContextDeleter::operator()(SHA256Context* context) + { + delete context; + } + + bool SHA256::AreEqual(const HashBuffer& first, const HashBuffer& second) + { + return (first.size() == second.size() && std::equal(first.begin(), first.end(), second.begin())); + } + + void SHA256::EnsureNotFinished() const + { + if (!context) + { + THROW_HR_MSG(E_UNEXPECTED, "The hash is already finished"); + } + } +}+ \ No newline at end of file diff --git a/src/AppInstallerSharedLib/SharedThreadGlobals.cpp b/src/AppInstallerSharedLib/SharedThreadGlobals.cpp @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#include "pch.h" +#include "Public/winget/SharedThreadGlobals.h" + +namespace AppInstaller::ThreadLocalStorage +{ + using namespace AppInstaller::Logging; + + static ThreadGlobals* SetOrGetThreadGlobals(bool setThreadGlobals, ThreadGlobals* pThreadGlobals = nullptr) + { + thread_local AppInstaller::ThreadLocalStorage::ThreadGlobals* t_pThreadGlobals = nullptr; + + if (setThreadGlobals) + { + AppInstaller::ThreadLocalStorage::ThreadGlobals* previous_pThreadGlobals = t_pThreadGlobals; + t_pThreadGlobals = pThreadGlobals; + return previous_pThreadGlobals; + } + + return t_pThreadGlobals; + } + + std::unique_ptr<PreviousThreadGlobals> ThreadGlobals::SetForCurrentThread() + { + return std::make_unique<PreviousThreadGlobals>(SetOrGetThreadGlobals(true, this)); + } + + ThreadGlobals* ThreadGlobals::GetForCurrentThread() + { + return SetOrGetThreadGlobals(false); + } + + PreviousThreadGlobals::~PreviousThreadGlobals() + { + std::ignore = SetOrGetThreadGlobals(true, m_previous); + } +} diff --git a/src/AppInstallerCommonCore/Yaml.cpp b/src/AppInstallerSharedLib/Yaml.cpp diff --git a/src/AppInstallerCommonCore/YamlWrapper.cpp b/src/AppInstallerSharedLib/YamlWrapper.cpp diff --git a/src/AppInstallerCommonCore/YamlWrapper.h b/src/AppInstallerSharedLib/YamlWrapper.h diff --git a/src/AppInstallerSharedLib/packages.config b/src/AppInstallerSharedLib/packages.config @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Microsoft.Windows.CppWinRT" version="2.0.210505.3" targetFramework="native" /> + <package id="Microsoft.Windows.ImplementationLibrary" version="1.0.210204.1" targetFramework="native" /> +</packages>+ \ No newline at end of file diff --git a/src/AppInstallerSharedLib/pch.cpp b/src/AppInstallerSharedLib/pch.cpp @@ -0,0 +1,3 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#include "pch.h" diff --git a/src/AppInstallerSharedLib/pch.h b/src/AppInstallerSharedLib/pch.h @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#pragma once + +#define NOMINMAX +#include <Windows.h> +#include <icu.h> + +#define YAML_DECLARE_STATIC +#include <yaml.h> + +// TODO: See if we can get down to having just one JSON parser... +#include <json/json.h> + +#pragma warning( push ) +#pragma warning ( disable : 4458 4100 4702 6031 ) +#include <valijson/schema.hpp> +#include <valijson/schema_parser.hpp> +#include <valijson/validator.hpp> +#include <valijson/adapters/jsoncpp_adapter.hpp> +#pragma warning( pop ) + +#include <algorithm> +#include <chrono> +#include <cwctype> +#include <filesystem> +#include <fstream> +#include <functional> +#include <iomanip> +#include <limits> +#include <memory> +#include <mutex> +#include <optional> +#include <ostream> +#include <set> +#include <string> +#include <sstream> +#include <string_view> +#include <type_traits> +#include <vector> + +#pragma warning( push ) +#pragma warning ( disable : 6001 6285 6287 6340 6387 6388 28196 ) +#include <wil/resource.h> +#include <wil/result.h> +#include <wil/result_macros.h> +#include <wil/safecast.h> +#include <wil/token_helpers.h> +#include <wil/com.h> +#include <wil/filesystem.h> +#pragma warning( pop ) + +#ifndef WINGET_DISABLE_FOR_FUZZING +#include <wil/cppwinrt.h> + +#include <winrt/Windows.ApplicationModel.Resources.h> +#include <winrt/Windows.Foundation.h> +#endif diff --git a/src/Microsoft.Management.Deployment/Microsoft.Management.Deployment.vcxproj b/src/Microsoft.Management.Deployment/Microsoft.Management.Deployment.vcxproj @@ -105,7 +105,7 @@ <SDLCheck>true</SDLCheck> <PreprocessorDefinitions>_WINRT_DLL;WIN32_LEAN_AND_MEAN;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories> - <AdditionalIncludeDirectories>$(ProjectDir)..\AppInstallerCLICore;$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>$(ProjectDir)..\AppInstallerCLICore;$(ProjectDir);$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> <Link> <SubSystem>Console</SubSystem> diff --git a/src/WinGetUtil/Exports.cpp b/src/WinGetUtil/Exports.cpp @@ -36,7 +36,7 @@ extern "C" { THROW_HR_IF(E_INVALIDARG, !logPath); - thread_local AppInstaller::ThreadLocalStorage::ThreadGlobals threadGlobals; + thread_local AppInstaller::ThreadLocalStorage::WingetThreadGlobals threadGlobals; thread_local std::once_flag initLogging; std::call_once(initLogging, []() { @@ -55,7 +55,7 @@ extern "C" if (!AppInstaller::Logging::Log().ContainsLogger(loggerName)) { // Let FileLogger use default file prefix - AppInstaller::Logging::AddFileLogger(pathAsPath); + AppInstaller::Logging::FileLogger::Add(pathAsPath); } return S_OK; diff --git a/src/WinGetUtil/WinGetUtil.vcxproj b/src/WinGetUtil/WinGetUtil.vcxproj @@ -162,9 +162,9 @@ <ClCompile> <Optimization>Disabled</Optimization> <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\JsonCppLib\json;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\JsonCppLib\json;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\JsonCppLib\json;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\JsonCppLib\json;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\JsonCppLib\json;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\JsonCppLib\json;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatWarningAsError> @@ -206,7 +206,7 @@ <ItemDefinitionGroup Condition="'$(Platform)'=='Win32'"> <ClCompile> <PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\JsonCppLib\json;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;$(ProjectDir)..\JsonCppLib\json;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</TreatWarningAsError> <ControlFlowGuard Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ControlFlowGuard> <SDLCheck Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</SDLCheck> @@ -228,10 +228,10 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);CLICOREDLLBUILD</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCommonCore;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerRepositoryCore\Public;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\cpprestsdk\cpprestsdk\Release\include;$(ProjectDir)..\JsonCppLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</TreatWarningAsError> diff --git a/src/WindowsPackageManager/WindowsPackageManager.vcxproj b/src/WindowsPackageManager/WindowsPackageManager.vcxproj @@ -166,9 +166,9 @@ <ClCompile> <Optimization>Disabled</Optimization> <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatWarningAsError> @@ -210,7 +210,7 @@ <ItemDefinitionGroup Condition="'$(Platform)'=='Win32'"> <ClCompile> <PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\JsonCppLib\json;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</TreatWarningAsError> <ControlFlowGuard Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ControlFlowGuard> <LanguageStandard Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">stdcpp17</LanguageStandard> @@ -227,10 +227,10 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(ProjectDir)..\AppInstallerCLICore\Public\;$(ProjectDir)..\AppInstallerRepositoryCore;$(ProjectDir)..\AppInstallerCommonCore\Public;$(ProjectDir)..\AppInstallerSharedLib\Public;$(ProjectDir)..\Microsoft.Management.Deployment\Public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</TreatWarningAsError> <TreatWarningAsError Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</TreatWarningAsError>