forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArchitecture.cpp
More file actions
117 lines (105 loc) · 3.6 KB
/
Copy pathArchitecture.cpp
File metadata and controls
117 lines (105 loc) · 3.6 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "Public/AppInstallerArchitecture.h"
#include "Public/AppInstallerLogging.h"
#include "Public/AppInstallerRuntime.h"
#include "Public/AppInstallerStrings.h"
namespace AppInstaller::Utility
{
Architecture ConvertToArchitectureEnum(const std::string& archStr)
{
if (ToLower(archStr) == "x86")
{
return Architecture::X86;
}
else if (ToLower(archStr) == "x64")
{
return Architecture::X64;
}
if (ToLower(archStr) == "arm")
{
return Architecture::Arm;
}
else if (ToLower(archStr) == "arm64")
{
return Architecture::Arm64;
}
else if (ToLower(archStr) == "neutral")
{
return Architecture::Neutral;
}
AICLI_LOG(YAML, Info, << "Convert to architecture enum. Unknown architecture: " << archStr);
return Architecture::Unknown;
}
Architecture GetSystemArchitecture()
{
Architecture systemArchitecture = Architecture::Unknown;
SYSTEM_INFO systemInfo;
ZeroMemory(&systemInfo, sizeof(SYSTEM_INFO));
GetNativeSystemInfo(&systemInfo);
switch (systemInfo.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_AMD64:
case PROCESSOR_ARCHITECTURE_IA64:
systemArchitecture = Architecture::X64;
break;
case PROCESSOR_ARCHITECTURE_ARM:
systemArchitecture = Architecture::Arm;
break;
case PROCESSOR_ARCHITECTURE_ARM64:
systemArchitecture = Architecture::Arm64;
break;
case PROCESSOR_ARCHITECTURE_INTEL:
systemArchitecture = Architecture::X86;
break;
}
return systemArchitecture;
}
std::vector<Architecture> GetApplicableArchitectures()
{
static std::vector<Architecture> applicableArchs;
if (!applicableArchs.empty())
{
return applicableArchs;
}
switch (GetSystemArchitecture())
{
case Architecture::Arm64:
applicableArchs.push_back(Architecture::Arm64);
applicableArchs.push_back(Architecture::Neutral);
applicableArchs.push_back(Architecture::Arm);
applicableArchs.push_back(Architecture::X86);
break;
case Architecture::Arm:
applicableArchs.push_back(Architecture::Arm);
applicableArchs.push_back(Architecture::Neutral);
break;
case Architecture::X86:
applicableArchs.push_back(Architecture::X86);
applicableArchs.push_back(Architecture::Neutral);
break;
case Architecture::X64:
applicableArchs.push_back(Architecture::X64);
applicableArchs.push_back(Architecture::Neutral);
applicableArchs.push_back(Architecture::X86);
break;
default:
applicableArchs.push_back(Architecture::Neutral);
}
return applicableArchs;
}
int IsApplicableArchitecture(Architecture arch)
{
std::vector<Architecture> applicableArchs = GetApplicableArchitectures();
auto it = std::find(applicableArchs.begin(), applicableArchs.end(), arch);
if (it != applicableArchs.end())
{
return static_cast<int>(std::distance(it, applicableArchs.end()));
}
else
{
return -1;
}
}
}