diff --git a/ui/xui/main-menu.cc b/ui/xui/main-menu.cc index d659bff5c2..19d12f9cc7 100644 --- a/ui/xui/main-menu.cc +++ b/ui/xui/main-menu.cc @@ -782,10 +782,12 @@ void MainMenuSystemView::Draw() if (FilePicker("MCPX Boot ROM", &g_config.sys.files.bootrom_path, rom_file_filters)) { m_dirty = true; + g_main_menu.UpdateAboutViewConfigInfo(); } if (FilePicker("Flash ROM (BIOS)", &g_config.sys.files.flashrom_path, rom_file_filters)) { m_dirty = true; + g_main_menu.UpdateAboutViewConfigInfo(); } if (FilePicker("Hard Disk", &g_config.sys.files.hdd_path, qcow_file_filters)) { @@ -797,6 +799,33 @@ void MainMenuSystemView::Draw() } } +MainMenuAboutView::MainMenuAboutView(): m_config_info_text{NULL} +{} + +void MainMenuAboutView::UpdateConfigInfoText() +{ + if (m_config_info_text) { + g_free(m_config_info_text); + } + + gchar *bootrom_checksum = GetFileMD5Checksum(g_config.sys.files.bootrom_path); + if (!bootrom_checksum) { + bootrom_checksum = g_strdup("None"); + } + + gchar *flash_rom_checksum = GetFileMD5Checksum(g_config.sys.files.flashrom_path); + if (!flash_rom_checksum) { + flash_rom_checksum = g_strdup("None"); + } + + m_config_info_text = g_strdup_printf( + "MCPX Boot ROM MD5 Hash: %s\n" + "Flash ROM (BIOS) MD5 Hash: %s", + bootrom_checksum, flash_rom_checksum); + g_free(bootrom_checksum); + g_free(flash_rom_checksum); +} + void MainMenuAboutView::Draw() { static const char *build_info_text = NULL; @@ -819,6 +848,10 @@ void MainMenuAboutView::Draw() gl_renderer, gl_version, gl_shader_version); } + if (m_config_info_text == NULL) { + UpdateConfigInfoText(); + } + Logo(); SectionTitle("Build Information"); @@ -837,6 +870,14 @@ void MainMenuAboutView::Draw() ImGuiInputTextFlags_ReadOnly); ImGui::PopFont(); + SectionTitle("Config Information"); + ImGui::PushFont(g_font_mgr.m_fixed_width_font); + ImGui::InputTextMultiline("##config_info", (char *)m_config_info_text, + strlen(build_info_text), + ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 3), + ImGuiInputTextFlags_ReadOnly); + ImGui::PopFont(); + SectionTitle("Community"); ImGui::Text("Visit"); @@ -1010,6 +1051,11 @@ void MainMenuScene::HandleInput() m_had_focus_last_frame = focus; } +void MainMenuScene::UpdateAboutViewConfigInfo() +{ + m_about_view.UpdateConfigInfoText(); +} + bool MainMenuScene::Draw() { m_animation.Step(); diff --git a/ui/xui/main-menu.hh b/ui/xui/main-menu.hh index a253fbabe8..ced9db147a 100644 --- a/ui/xui/main-menu.hh +++ b/ui/xui/main-menu.hh @@ -120,7 +120,11 @@ public: class MainMenuAboutView : public virtual MainMenuTabView { +protected: + char *m_config_info_text; public: + MainMenuAboutView(); + void UpdateConfigInfoText(); void Draw() override; }; @@ -179,6 +183,7 @@ public: bool IsAnimating() override; void SetNextViewIndex(int i); void HandleInput(); + void UpdateAboutViewConfigInfo(); bool Draw() override; }; diff --git a/ui/xui/misc.hh b/ui/xui/misc.hh index b2c8a9e99d..0a31ed4a8c 100644 --- a/ui/xui/misc.hh +++ b/ui/xui/misc.hh @@ -104,3 +104,23 @@ int PushWindowTransparencySettings(bool transparent, float alpha_transparent = 0 return 5; } + +static inline gchar *GetFileMD5Checksum(const char *path) +{ + auto *checksum = g_checksum_new(G_CHECKSUM_MD5); + + auto *file = qemu_fopen(path, "rb"); + if (!file) return nullptr; + + guchar buf[512]; + size_t nread; + while ((nread = fread(buf, 1, sizeof(buf), file))) { + g_checksum_update(checksum, buf, nread); + } + + gchar *checksum_str = g_strdup(g_checksum_get_string(checksum)); + fclose(file); + g_checksum_free(checksum); + return checksum_str; +} +