mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
feat: add os version show for linux
This commit is contained in:
38
include/Cubed/tools/system_version.hpp
Normal file
38
include/Cubed/tools/system_version.hpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <Cubed/tools/log.hpp>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
#elif defined(__linux__)
|
||||||
|
inline bool get_os_version(std::string& str) {
|
||||||
|
std::ifstream file("/etc/os-release");
|
||||||
|
if (!file.is_open()) {
|
||||||
|
Logger::error("Can't Open /etc/os-release");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(file, line)) {
|
||||||
|
size_t eq_pos = line.find("=");
|
||||||
|
if (eq_pos == std::string::npos) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::string key = line.substr(0, eq_pos);
|
||||||
|
if (key != "PRETTY_NAME") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
str = line.substr(eq_pos + 1);
|
||||||
|
|
||||||
|
if (str.size() >= 2 && str.front() == '"' && str.back() == '"') {
|
||||||
|
str = str.substr(1, str.size() - 2);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <Cubed/debug_collector.hpp>
|
#include <Cubed/debug_collector.hpp>
|
||||||
|
|
||||||
|
#include <Cubed/tools/system_version.hpp>
|
||||||
#include <Cubed/tools/cubed_hash.hpp>
|
#include <Cubed/tools/cubed_hash.hpp>
|
||||||
|
|
||||||
DebugCollector::DebugCollector() {
|
DebugCollector::DebugCollector() {
|
||||||
@@ -16,6 +17,7 @@ void DebugCollector::init_text() {
|
|||||||
Text fps_text("fps");
|
Text fps_text("fps");
|
||||||
Text player_pos_text("player_pos");
|
Text player_pos_text("player_pos");
|
||||||
Text rendered_chunk_text("rendered_chunk");
|
Text rendered_chunk_text("rendered_chunk");
|
||||||
|
|
||||||
version_text
|
version_text
|
||||||
.position(0.0f, 100.0f)
|
.position(0.0f, 100.0f)
|
||||||
.scale(0.8f)
|
.scale(0.8f)
|
||||||
@@ -32,10 +34,26 @@ void DebugCollector::init_text() {
|
|||||||
.text("Rendered Chunk: 0")
|
.text("Rendered Chunk: 0")
|
||||||
.scale(0.8f)
|
.scale(0.8f)
|
||||||
.position(0.0, 200.0f);
|
.position(0.0, 200.0f);
|
||||||
|
std::string os;
|
||||||
|
|
||||||
|
Text os_text("os");
|
||||||
|
os_text
|
||||||
|
.scale(0.8f)
|
||||||
|
.position(0.0f, 250.0f);
|
||||||
|
if (get_os_version(os)) {
|
||||||
|
os_text
|
||||||
|
.text("OS: " + os);
|
||||||
|
Logger::info("System: {}", os);
|
||||||
|
} else {
|
||||||
|
os_text
|
||||||
|
.text("OS: Unknown");
|
||||||
|
|
||||||
|
}
|
||||||
m_texts.insert({version_text.uuid(), std::move(version_text)});
|
m_texts.insert({version_text.uuid(), std::move(version_text)});
|
||||||
m_texts.insert({fps_text.uuid(), std::move(fps_text)});
|
m_texts.insert({fps_text.uuid(), std::move(fps_text)});
|
||||||
m_texts.insert({player_pos_text.uuid(), std::move(player_pos_text)});
|
m_texts.insert({player_pos_text.uuid(), std::move(player_pos_text)});
|
||||||
m_texts.insert({rendered_chunk_text.uuid(), std::move(rendered_chunk_text)});
|
m_texts.insert({rendered_chunk_text.uuid(), std::move(rendered_chunk_text)});
|
||||||
|
m_texts.insert({os_text.uuid(), std::move(os_text)});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_map<std::size_t, Text>& DebugCollector::all_texts() {
|
std::unordered_map<std::size_t, Text>& DebugCollector::all_texts() {
|
||||||
|
|||||||
Reference in New Issue
Block a user