Add config save/load for imdebugger, move the imgui.ini to PSP/SYSTEM

This commit is contained in:
Henrik Rydgård 2024-11-27 09:15:03 +01:00
parent c685373444
commit 1df3b9b905
7 changed files with 107 additions and 26 deletions

View file

@ -1677,11 +1677,10 @@ const Path Config::FindConfigFile(const std::string &baseFilename) {
} }
// Make sure at least the directory it's supposed to be in exists. // Make sure at least the directory it's supposed to be in exists.
Path path = filename.NavigateUp(); Path parent = filename.NavigateUp();
// This check is just to avoid logging.
if (!File::Exists(path)) { // We try to create the path and ignore if it fails (already exists).
File::CreateFullPath(path); File::CreateFullPath(parent);
}
return filename; return filename;
} }

View file

@ -1670,6 +1670,7 @@ void EmuScreen::renderImDebugger() {
Draw::DrawContext *draw = screenManager()->getDrawContext(); Draw::DrawContext *draw = screenManager()->getDrawContext();
if (!imguiInited_) { if (!imguiInited_) {
imguiInited_ = true; imguiInited_ = true;
ImGui_ImplPlatform_Init(GetSysDirectory(DIRECTORY_SYSTEM) / "imgui.ini");
imDebugger_ = std::make_unique<ImDebugger>(); imDebugger_ = std::make_unique<ImDebugger>();
// Read the TTF font // Read the TTF font

View file

@ -607,8 +607,14 @@ void DrawHLEModules(ImConfig &config) {
ImDebugger::ImDebugger() { ImDebugger::ImDebugger() {
reqToken_ = g_requestManager.GenerateRequesterToken(); reqToken_ = g_requestManager.GenerateRequesterToken();
cfg_.LoadConfig(ConfigPath());
} }
ImDebugger::~ImDebugger() {
cfg_.SaveConfig(ConfigPath());
}
void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebug) { void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebug) {
// Snapshot the coreState to avoid inconsistency. // Snapshot the coreState to avoid inconsistency.
const CoreState coreState = ::coreState; const CoreState coreState = ::coreState;
@ -921,6 +927,62 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, bool *open, CoreState c
ImGui::End(); ImGui::End();
} }
void ImDebugger::LoadConfig() { Path ImDebugger::ConfigPath() {
IniFile ini; return GetSysDirectory(DIRECTORY_SYSTEM) / "imdebugger.ini";
}
// TODO: Move this into the main config at some point.
// But, I don't really want Core to know about the ImDebugger..
void ImConfig::LoadConfig(const Path &iniFile) {
IniFile ini;
ini.Load(iniFile); // Ignore return value, might not exist yet. In that case we'll end up loading defaults.
SyncConfig(&ini, false);
}
void ImConfig::SaveConfig(const Path &iniFile) {
IniFile ini;
ini.Load(iniFile); // ignore return value, might not exist yet
SyncConfig(&ini, true);
ini.Save(iniFile);
}
class Syncer {
public:
explicit Syncer(bool save) : save_(save) {}
void SetSection(Section *section) { section_ = section; }
template<class T>
void Sync(std::string_view key, T *value, T defaultValue) {
if (save_) {
section_->Set(key, *value);
} else {
section_->Get(key, value, defaultValue);
}
}
private:
Section *section_ = nullptr;
bool save_;
};
void ImConfig::SyncConfig(IniFile *ini, bool save) {
Syncer sync(save);
sync.SetSection(ini->GetOrCreateSection("Windows"));
sync.Sync("disasmOpen", &disasmOpen, true);
sync.Sync("demoOpen ", &demoOpen, false);
sync.Sync("regsOpen", &regsOpen, true);
sync.Sync("threadsOpen", &threadsOpen, false);
sync.Sync("callstackOpen", &callstackOpen, false);
sync.Sync("breakpointsOpen", &breakpointsOpen, false);
sync.Sync("modulesOpen", &modulesOpen, false);
sync.Sync("hleModulesOpen", &hleModulesOpen, false);
sync.Sync("atracOpen", &atracOpen, false);
sync.Sync("structViewerOpen", &structViewerOpen, false);
sync.Sync("framebuffersOpen", &framebuffersOpen, false);
sync.Sync("displayOpen", &displayOpen, true);
sync.Sync("styleEditorOpen", &styleEditorOpen, false);
sync.Sync("filesystemBrowserOpen", &filesystemBrowserOpen, false);
sync.Sync("kernelObjectsOpen", &kernelObjectsOpen, false);
sync.SetSection(ini->GetOrCreateSection("Settings"));
sync.Sync("displayLatched", &displayLatched, false);
} }

View file

@ -58,21 +58,23 @@ private:
}; };
struct ImConfig { struct ImConfig {
bool disasmOpen = true; // Defaults for saved settings are set in SyncConfig.
bool demoOpen = false;
bool regsOpen = true; bool disasmOpen;
bool threadsOpen = true; bool demoOpen;
bool callstackOpen = true; bool regsOpen;
bool breakpointsOpen = false; bool threadsOpen;
bool modulesOpen = true; bool callstackOpen;
bool hleModulesOpen = false; bool breakpointsOpen;
bool atracOpen = true; bool modulesOpen;
bool structViewerOpen = false; bool hleModulesOpen;
bool framebuffersOpen = false; bool atracOpen;
bool displayOpen = false; bool structViewerOpen;
bool styleEditorOpen = false; bool framebuffersOpen;
bool filesystemBrowserOpen = false; bool displayOpen;
bool kernelObjectsOpen = false; bool styleEditorOpen;
bool filesystemBrowserOpen;
bool kernelObjectsOpen;
// HLE explorer settings // HLE explorer settings
// bool filterByUsed = true; // bool filterByUsed = true;
@ -85,6 +87,12 @@ struct ImConfig {
int selectedMemCheck = -1; int selectedMemCheck = -1;
bool displayLatched = false; bool displayLatched = false;
// We use a separate ini file from the main PPSSPP config.
void LoadConfig(const Path &iniFile);
void SaveConfig(const Path &iniFile);
void SyncConfig(IniFile *ini, bool save);
}; };
enum ImUiCmd { enum ImUiCmd {
@ -98,13 +106,12 @@ struct ImUiCommand {
class ImDebugger { class ImDebugger {
public: public:
ImDebugger(); ImDebugger();
~ImDebugger();
void Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebug); void Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebug);
private: private:
// We use a separate ini file from the main PPSSPP config. Path ConfigPath();
void LoadConfig();
void SaveConfig();
RequesterToken reqToken_; RequesterToken reqToken_;
@ -112,5 +119,5 @@ private:
ImStructViewer structViewer_; ImStructViewer structViewer_;
// Open variables. // Open variables.
ImConfig cfg_; ImConfig cfg_{};
}; };

View file

@ -1,8 +1,10 @@
#include "ext/imgui/imgui.h" #include "ext/imgui/imgui.h"
#include "Common/File/Path.h"
#include "Common/Input/KeyCodes.h" #include "Common/Input/KeyCodes.h"
#include "Common/Data/Encoding/Utf8.h" #include "Common/Data/Encoding/Utf8.h"
#include "Common/System/Display.h" #include "Common/System/Display.h"
#include "Common/TimeUtil.h" #include "Common/TimeUtil.h"
#include "Common/StringUtils.h"
#include "Common/Log.h" #include "Common/Log.h"
#include "imgui_impl_platform.h" #include "imgui_impl_platform.h"
@ -73,6 +75,12 @@ void ImGui_ImplPlatform_TouchEvent(const TouchInput &touch) {
} }
} }
void ImGui_ImplPlatform_Init(const Path &configPath) {
static char path[1024];
truncate_cpy(path, configPath.ToString());
ImGui::GetIO().IniFilename = path;
}
void ImGui_ImplPlatform_AxisEvent(const AxisInput &axis) { void ImGui_ImplPlatform_AxisEvent(const AxisInput &axis) {
// Ignore for now. // Ignore for now.
} }

View file

@ -4,8 +4,11 @@
#include "Common/Input/KeyCodes.h" #include "Common/Input/KeyCodes.h"
#include "Common/Input/InputState.h" #include "Common/Input/InputState.h"
class Path;
ImGuiKey KeyCodeToImGui(InputKeyCode keyCode); ImGuiKey KeyCodeToImGui(InputKeyCode keyCode);
void ImGui_ImplPlatform_Init(const Path &configPath);
void ImGui_ImplPlatform_NewFrame(); void ImGui_ImplPlatform_NewFrame();
void ImGui_ImplPlatform_KeyEvent(const KeyInput &key); void ImGui_ImplPlatform_KeyEvent(const KeyInput &key);

View file

@ -2,3 +2,4 @@ org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.nonTransitiveRClass=true android.nonTransitiveRClass=true
android.nonFinalResIds=true android.nonFinalResIds=true
android.ndk.suppressMinSdkVersionError=21