feat: show Linux distribution information on startup (#1729)
This commit is contained in:
parent
cf34c4bd95
commit
984438e98d
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user