diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sysinfo.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/sysinfo.cpp b/src/sysinfo.cpp index 2cc163d..e60058e 100644 --- a/src/sysinfo.cpp +++ b/src/sysinfo.cpp @@ -387,9 +387,45 @@ namespace { }; + class GenericSysInfo + : public SysInfo + { + public: + GenericSysInfo() + { + this->load_os_release(); + } + + private: + void load_os_release() + { + std::ifstream input("/etc/os-release"); + + if (input) { + while (!input.eof()) { + string s; + int len; + std::getline(input, s); + if (s.find("NAME=") == 0) { + len = strlen("NAME="); + this->distro_name = s.substr(len); + } else if (s.find("VERSION=") == 0) { + len = strlen("VERSION="); + // also strip the surrounding quotes + this->distro_release = s.substr(len + 1, s.size() - len - 2); + } + } + } + } + }; + + SysInfo* get_sysinfo() { - if (char *p = g_find_program_in_path("lsb_release")) { + if (g_file_test ("/etc/os-release", G_FILE_TEST_EXISTS)) { + return new GenericSysInfo; + } + else if (char *p = g_find_program_in_path("lsb_release")) { g_free(p); return new LSBSysInfo; } |