1
0
mirror of synced 2024-11-24 07:40:17 +01:00

feat: show Linux distribution information on startup (#1729)

This commit is contained in:
iTrooz 2024-06-03 10:02:29 +02:00 committed by GitHub
parent cf34c4bd95
commit 984438e98d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 0 deletions

View File

@ -597,6 +597,16 @@ namespace hex {
*/
std::string getArchitecture();
struct LinuxDistro {
std::string name;
std::string version;
};
/**
* @brief Gets information related to the Linux distribution, if running on Linux
*/
std::optional<LinuxDistro> getLinuxDistro();
/**
* @brief Gets the current ImHex version
* @return ImHex version

View File

@ -15,6 +15,8 @@
#include <imgui.h>
#include <imgui_internal.h>
#include <set>
#include <fstream>
#include <algorithm>
#include <GLFW/glfw3.h>
#if defined(OS_WINDOWS)
@ -742,6 +744,25 @@ namespace hex {
#endif
}
std::optional<LinuxDistro> getLinuxDistro() {
std::ifstream file("/etc/os-release");
std::string name;
std::string version;
std::string line;
while (std::getline(file, line)) {
if (line.find("PRETTY_NAME=") != std::string::npos) {
name = line.substr(line.find("=") + 1);
name.erase(std::remove(name.begin(), name.end(), '\"'), name.end());
} else if (line.find("VERSION_ID=") != std::string::npos) {
version = line.substr(line.find("=") + 1);
version.erase(std::remove(version.begin(), version.end(), '\"'), version.end());
}
}
return {{name, version}};
}
std::string getImHexVersion(bool withBuildType) {
#if defined IMHEX_VERSION
if (withBuildType) {

View File

@ -43,6 +43,11 @@ int main(int argc, char **argv) {
log::info("Welcome to ImHex {}!", ImHexApi::System::getImHexVersion());
log::info("Compiled using commit {}@{}", ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash());
log::info("Running on {} {} ({})", ImHexApi::System::getOSName(), ImHexApi::System::getOSVersion(), ImHexApi::System::getArchitecture());
#if defined(OS_LINUX)
auto distro = ImHexApi::System::getLinuxDistro().value();
log::info("Linux distribution: {}. Version: {}", distro.name, distro.version == "" ? "None" : distro.version);
#endif
// Run ImHex
return init::runImHex();