winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

PortableInstaller.h (4425B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include "winget/PortableARPEntry.h"
      5 #include "winget/PortableFileEntry.h"
      6 #include <Workflows/WorkflowBase.h>
      7 #include <filesystem>
      8 
      9 using namespace AppInstaller::Registry::Portable;
     10 
     11 namespace AppInstaller::CLI::Portable
     12 {
     13     std::filesystem::path GetPortableLinksLocation(Manifest::ScopeEnum scope);
     14 
     15     std::filesystem::path GetPortableInstallRoot(Manifest::ScopeEnum scope, Utility::Architecture arch);
     16 
     17     // Object representation of the metadata and functionality required for installing a Portable package. 
     18     struct PortableInstaller
     19     {
     20         // These values are initialized based on the values from the entry in ARP
     21         std::string DisplayName;
     22         std::string DisplayVersion;
     23         std::string HelpLink;
     24         std::string InstallDate;
     25         std::filesystem::path InstallLocation;
     26         std::filesystem::path PortableSymlinkFullPath;
     27         std::filesystem::path PortableTargetFullPath;
     28         std::string Publisher;
     29         std::string SHA256;
     30         std::string URLInfoAbout;
     31         std::string UninstallString;
     32         std::string WinGetInstallerType;
     33         std::string WinGetPackageIdentifier;
     34         std::string WinGetSourceIdentifier;
     35         bool InstallDirectoryCreated = false;
     36         bool BinariesDependOnPath = false;
     37         // If we fail to create a symlink, add install directory to PATH variable
     38         bool InstallDirectoryAddedToPath = false;
     39 
     40         bool IsUpdate = false;
     41         bool Purge = false;
     42         bool RecordToIndex = false;
     43 
     44         // This is the incoming target install location determined from the context args.
     45         std::filesystem::path TargetInstallLocation;
     46 
     47         PortableInstaller(Manifest::ScopeEnum scope, Utility::Architecture arch, const std::string& productCode);
     48 
     49         bool VerifyExpectedState();
     50 
     51         void SetDesiredState(const std::vector<AppInstaller::Portable::PortableFileEntry>& desiredEntries)
     52         {
     53             m_desiredEntries = desiredEntries;
     54         };
     55 
     56         void PrepareForCleanUp()
     57         {
     58             m_expectedEntries = m_desiredEntries;
     59             m_desiredEntries = {};
     60         }
     61 
     62         void Install(AppInstaller::CLI::Workflow::OperationType operation = Workflow::OperationType::Install);
     63 
     64         void Uninstall();
     65 
     66         template<typename T>
     67         void CommitToARPEntry(PortableValueName valueName, T value)
     68         {
     69             m_portableARPEntry.SetValue(valueName, value);
     70         }
     71 
     72         std::filesystem::path GetPortableIndexFileName()
     73         {
     74             return Utility::ConvertToUTF16(GetProductCode() + ".db");
     75         }
     76 
     77         Manifest::ScopeEnum GetScope() { return m_portableARPEntry.GetScope(); };
     78 
     79         Utility::Architecture GetArch() { return m_portableARPEntry.GetArchitecture(); };
     80 
     81         std::string GetProductCode() { return m_portableARPEntry.GetProductCode(); };
     82 
     83         bool ARPEntryExists() { return m_portableARPEntry.Exists(); };
     84 
     85         std::string GetOutputMessage()
     86         {
     87             return m_stream.str();
     88         }
     89 
     90         void SetAppsAndFeaturesMetadata(
     91             const Manifest::Manifest& manifest,
     92             const std::vector<AppInstaller::Manifest::AppsAndFeaturesEntry>& entries);
     93 
     94         AppInstaller::Manifest::AppsAndFeaturesEntry GetAppsAndFeaturesEntry();
     95 
     96     private:
     97         PortableARPEntry m_portableARPEntry;
     98         std::vector<AppInstaller::Portable::PortableFileEntry> m_desiredEntries;
     99         std::vector<AppInstaller::Portable::PortableFileEntry> m_expectedEntries;
    100         std::stringstream m_stream;
    101 
    102         std::string GetStringValue(PortableValueName valueName);
    103         std::filesystem::path GetPathValue(PortableValueName valueName);
    104         bool GetBoolValue(PortableValueName valueName);
    105 
    106         void SetExpectedState();
    107         void RegisterARPEntry();
    108 
    109         void ApplyDesiredState();
    110         void InstallFile(AppInstaller::Portable::PortableFileEntry& desiredState);
    111         void RemoveFile(AppInstaller::Portable::PortableFileEntry& desiredState);
    112 
    113         void CreateTargetInstallDirectory();
    114         void RemoveInstallDirectory();
    115 
    116         void AddToPathVariable(const std::filesystem::path& value);
    117         void RemoveFromPathVariable(const std::filesystem::path& value);
    118     };
    119 }