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 const QSettings relFile { osReleaseFile, QSettings::IniFormat };
57 const auto& prettyName = relFile.value (QStringLiteral (
"PRETTY_NAME")).toString ();
58 const auto& name = relFile.value (QStringLiteral (
"NAME")).toString ();
59 const auto& version = relFile.value (QStringLiteral (
"VERSION")).toString ();
60 return !prettyName.isEmpty () ? prettyName : (name +
" " + version);
70 static const auto osptr = std::to_array<OsInfo> ({
71 { QStringLiteral (
"/etc/mandrake-release"), QStringLiteral (
"Mandrake Linux") },
72 { QStringLiteral (
"/etc/debian_version"), QStringLiteral (
"Debian GNU/Linux") },
73 { QStringLiteral (
"/etc/gentoo-release"), QStringLiteral (
"Gentoo Linux") },
74 { QStringLiteral (
"/etc/exherbo-release"), QStringLiteral (
"Exherbo") },
75 { QStringLiteral (
"/etc/arch-release"), QStringLiteral (
"Arch Linux") },
76 { QStringLiteral (
"/etc/slackware-version"), QStringLiteral (
"Slackware Linux") },
77 { QStringLiteral (
"/etc/pld-release"), {} },
78 { QStringLiteral (
"/etc/lfs-release"), QStringLiteral (
"LFS") },
79 { QStringLiteral (
"/etc/SuSE-release"), QStringLiteral (
"SuSE linux") },
80 { QStringLiteral (
"/etc/conectiva-release"), QStringLiteral (
"Connectiva") },
81 { QStringLiteral (
"/etc/.installed"), {} },
82 { QStringLiteral (
"/etc/redhat-release"), {} },
84 for (
const auto& os : osptr)
87 if (
f.open (QIODevice::ReadOnly))
89 QString data = QString (
f.read (1024)).trimmed ();
90 return os.name.isEmpty () ?
92 QStringLiteral (
"%1 (%2)").arg (os.name, data);
103 void Normalize (QString& osName)
105 auto trimQuotes = [&osName]
107 if (osName.startsWith (
'"') && osName.endsWith (
'"'))
108 osName = osName.mid (1, osName.size () - 1);
113 static const auto nameMarker = QStringLiteral (
"NAME=");
114 if (osName.startsWith (nameMarker))
115 osName = osName.mid (nameMarker.size ());
124 #if defined(Q_OS_MAC) || defined(Q_OS_WIN32) 127 .
Arch_ = QSysInfo::currentCpuArchitecture (),
128 .Name_ = QSysInfo::productType (),
129 .Version_ = QSysInfo::productVersion (),
133 if (osName.isEmpty ())
135 if (osName.isEmpty ())
146 .Name_ = osName.isEmpty () ? u.sysname : osName,
147 .Version_ = QString (
"%1 %2 %3").arg (u.machine, u.release, u.version),
148 .Flavour_ = u.sysname,
152 return { .Arch_ =
"Unknown arch", .Name_ =
"Unknown OS", .Version_ =
"Unknown version", .Flavour_ = {} };
constexpr detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, detail::MemberPtrs< Ptr > > f
QString GetOSName()
Returns a string of OS name and version joined together.
Describes the OS running LeechCraft.
QString Arch_
Describes the CPU architecture of the OS.
OSInfo GetOSInfo()
Returns more precise information about OS name and version.