Skip to content

Commit 3b4632c

Browse files
authored
macOS: add marketing name (#130)
1 parent fff0ffb commit 3b4632c

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ CPU, RAM, GPU, Disks, Mainboard, ...
6464
| | Free Size | ✔️ | ✔️ | ✔️ |
6565
| | Volumes | ✔️ | ✔️ | ✔️ |
6666
| Operating System | Name | ✔️ | ✔️ | ✔️ |
67-
| | Short Name | ✔️ | | ✔️ |
67+
| | Short Name | ✔️ | | ✔️ |
6868
| | Version | ✔️ | ✔️ ||
6969
| | Kernel | ✔️ | ✔️ ||
7070
| | Architecture (Bit) | ✔️ | ✔️ | ✔️ |
@@ -82,6 +82,7 @@ link against depending on your needs.
8282
```cmake
8383
target_link_libraries(your_target PRIVATE hwinfo::hwinfo)
8484
```
85+
8586
or
8687

8788
```cmake

src/apple/os.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,84 @@
1212

1313
namespace hwinfo {
1414

15+
std::string getMarketingName(const std::string& version) {
16+
size_t dotPos = version.find('.');
17+
if (dotPos == std::string::npos) {
18+
return "";
19+
}
20+
21+
int majorVersion = 0;
22+
try {
23+
majorVersion = std::stoi(version.substr(0, dotPos));
24+
} catch (...) {
25+
return "";
26+
}
27+
28+
// map major version to marketing name
29+
switch (majorVersion) {
30+
case 26:
31+
return "Tahoe";
32+
case 15:
33+
return "Sequoia";
34+
case 14:
35+
return "Sonoma";
36+
case 13:
37+
return "Ventura";
38+
case 12:
39+
return "Monterey";
40+
case 11:
41+
return "Big Sur";
42+
case 10: {
43+
// handle 10.x versions - need to check minor version
44+
size_t secondDot = version.find('.', dotPos + 1);
45+
std::string minorStr = (secondDot != std::string::npos) ? version.substr(dotPos + 1, secondDot - dotPos - 1)
46+
: version.substr(dotPos + 1);
47+
try {
48+
switch (std::stoi(minorStr)) {
49+
case 15:
50+
return "Catalina";
51+
case 14:
52+
return "Mojave";
53+
case 13:
54+
return "High Sierra";
55+
case 12:
56+
return "Sierra";
57+
case 11:
58+
return "El Capitan";
59+
case 10:
60+
return "Yosemite";
61+
case 9:
62+
return "Mavericks";
63+
case 8:
64+
return "Mountain Lion";
65+
case 7:
66+
return "Lion";
67+
case 6:
68+
return "Snow Leopard";
69+
case 5:
70+
return "Leopard";
71+
case 4:
72+
return "Tiger";
73+
case 3:
74+
return "Panther";
75+
case 2:
76+
return "Jaguar";
77+
case 1:
78+
return "Puma";
79+
case 0:
80+
return "Cheetah";
81+
default:
82+
return "";
83+
}
84+
} catch (...) {
85+
return "";
86+
}
87+
}
88+
default:
89+
return "";
90+
}
91+
}
92+
1593
// _____________________________________________________________________________________________________________________
1694
OS::OS() {
1795
_name = "macOS";
@@ -25,6 +103,12 @@ OS::OS() {
25103
// get OS name and build version
26104
_version = utils::getSysctlString("kern.osproductversion", "<unknown> ");
27105
_version.pop_back();
106+
107+
// add marketing name if we can determine it
108+
if (std::string marketingName = getMarketingName(_version); !marketingName.empty()) {
109+
_name = _name + " " + marketingName;
110+
}
111+
28112
_version = _version + " (" + utils::getSysctlString("kern.osversion", "<unknown build> ");
29113
_version.pop_back();
30114
_version = _version + ")";

0 commit comments

Comments
 (0)