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