10 #if !defined(Q_OS_WIN32)
11 #include <sys/utsname.h>
15 #include <QTextStream>
24 return info.Name_ +
' ' + info.Version_;
33 proc.start (QStringLiteral (
"/bin/sh"),
34 QStringList {
"-c",
"lsb_release -ds" },
36 if (proc.waitForStarted ())
38 QTextStream stream (&proc);
40 while (proc.waitForReadyRead ())
41 ret += stream.readAll ();
44 return ret.remove (
'"').trimmed ();
52 static const auto osReleaseFile = QStringLiteral (
"/etc/os-release");
53 if (!QFile::exists (osReleaseFile))
56 QSettings relFile { osReleaseFile, QSettings::IniFormat };
57 relFile.setIniCodec (
"UTF-8");
59 const auto& prettyName = relFile.value (QStringLiteral (
"PRETTY_NAME")).toString ();
60 const auto& name = relFile.value (QStringLiteral (
"NAME")).toString ();
61 const auto& version = relFile.value (QStringLiteral (
"VERSION")).toString ();
62 return !prettyName.isEmpty () ? prettyName : (name +
" " + version);
72 static const auto osptr = std::to_array<OsInfo> ({
73 { QStringLiteral (
"/etc/mandrake-release"), QStringLiteral (
"Mandrake Linux") },
74 { QStringLiteral (
"/etc/debian_version"), QStringLiteral (
"Debian GNU/Linux") },
75 { QStringLiteral (
"/etc/gentoo-release"), QStringLiteral (
"Gentoo Linux") },
76 { QStringLiteral (
"/etc/exherbo-release"), QStringLiteral (
"Exherbo") },
77 { QStringLiteral (
"/etc/arch-release"), QStringLiteral (
"Arch Linux") },
78 { QStringLiteral (
"/etc/slackware-version"), QStringLiteral (
"Slackware Linux") },
79 { QStringLiteral (
"/etc/pld-release"), {} },
80 { QStringLiteral (
"/etc/lfs-release"), QStringLiteral (
"LFS") },
81 { QStringLiteral (
"/etc/SuSE-release"), QStringLiteral (
"SuSE linux") },
82 { QStringLiteral (
"/etc/conectiva-release"), QStringLiteral (
"Connectiva") },
83 { QStringLiteral (
"/etc/.installed"), {} },
84 { QStringLiteral (
"/etc/redhat-release"), {} },
86 for (
const auto& os : osptr)
89 if (
f.open (QIODevice::ReadOnly))
91 QString data = QString (
f.read (1024)).trimmed ();
92 return os.name.isEmpty () ?
94 QStringLiteral (
"%1 (%2)").arg (os.name, data);
105 void Normalize (QString& osName)
107 auto trimQuotes = [&osName]
109 if (osName.startsWith (
'"') && osName.endsWith (
'"'))
110 osName = osName.mid (1, osName.size () - 1);
115 static const auto nameMarker = QStringLiteral (
"NAME=");
116 if (osName.startsWith (nameMarker))
117 osName = osName.mid (nameMarker.size ());
126 #if defined(Q_OS_MAC)
127 const auto retVer = [] (
const QString& version)
130 return OSInfo { .
Arch_ =
"x86_64", .Name_ =
"Mac OS X", .Version_ = version };
133 for (
auto minor = 7; minor < 16; ++minor)
134 if (QSysInfo::MacintoshVersion == Q_MV_OSX (10, minor))
135 return retVer (
"10." + QString::number (minor));
137 return retVer (
"Unknown version");
138 #elif defined(Q_OS_WIN32)
139 const auto retVer = [] (
const QString& version)
143 .Arch_ = QSysInfo::WordSize == 64 ?
"x86_64" :
"x86",
149 switch (QSysInfo::WindowsVersion)
151 case QSysInfo::WV_95:
152 return retVer (
"95");
153 case QSysInfo::WV_98:
154 return retVer (
"98");
155 case QSysInfo::WV_Me:
156 return retVer (
"Me");
157 case QSysInfo::WV_DOS_based:
158 return retVer (
"9x/Me");
159 case QSysInfo::WV_NT:
160 return retVer (
"NT 4.x");
161 case QSysInfo::WV_2000:
162 return retVer (
"2000");
163 case QSysInfo::WV_XP:
164 return retVer (
"XP");
165 case QSysInfo::WV_2003:
166 return retVer (
"2003");
167 case QSysInfo::WV_VISTA:
168 return retVer (
"Vista");
169 case QSysInfo::WV_WINDOWS7:
174 return retVer (
"8.1");
176 return retVer (
"10");
177 case QSysInfo::WV_NT_based:
178 return retVer (
"NT-based");
182 if (osName.isEmpty ())
184 if (osName.isEmpty ())
195 .Name_ = osName.isEmpty () ? u.sysname : osName,
196 .Version_ = QString (
"%1 %2 %3").arg (u.machine, u.release, u.version),
197 .Flavour_ = u.sysname,
201 return { .Arch_ =
"Unknown arch", .Name_ =
"Unknown OS", .Version_ =
"Unknown version" };