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.
Path path = filename.NavigateUp();
// This check is just to avoid logging.
if (!File::Exists(path)) {
File::CreateFullPath(path);
}
Path parent = filename.NavigateUp();
// We try to create the path and ignore if it fails (already exists).
File::CreateFullPath(parent);
return filename;
}

View file

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

View file

@ -607,8 +607,14 @@ void DrawHLEModules(ImConfig &config) {
ImDebugger::ImDebugger() {
reqToken_ = g_requestManager.GenerateRequesterToken();
cfg_.LoadConfig(ConfigPath());
}
ImDebugger::~ImDebugger() {
cfg_.SaveConfig(ConfigPath());
}
void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebug) {
// Snapshot the coreState to avoid inconsistency.
const CoreState coreState = ::coreState;
@ -921,6 +927,62 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, bool *open, CoreState c
ImGui::End();
}
void ImDebugger::LoadConfig() {
IniFile ini;
Path ImDebugger::ConfigPath() {
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 {
bool disasmOpen = true;
bool demoOpen = false;
bool regsOpen = true;
bool threadsOpen = true;
bool callstackOpen = true;
bool breakpointsOpen = false;
bool modulesOpen = true;
bool hleModulesOpen = false;
bool atracOpen = true;
bool structViewerOpen = false;
bool framebuffersOpen = false;
bool displayOpen = false;
bool styleEditorOpen = false;
bool filesystemBrowserOpen = false;
bool kernelObjectsOpen = false;
// Defaults for saved settings are set in SyncConfig.
bool disasmOpen;
bool demoOpen;
bool regsOpen;
bool threadsOpen;
bool callstackOpen;
bool breakpointsOpen;
bool modulesOpen;
bool hleModulesOpen;
bool atracOpen;
bool structViewerOpen;
bool framebuffersOpen;
bool displayOpen;
bool styleEditorOpen;
bool filesystemBrowserOpen;
bool kernelObjectsOpen;
// HLE explorer settings
// bool filterByUsed = true;
@ -85,6 +87,12 @@ struct ImConfig {
int selectedMemCheck = -1;
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 {
@ -98,13 +106,12 @@ struct ImUiCommand {
class ImDebugger {
public:
ImDebugger();
~ImDebugger();
void Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebug);
private:
// We use a separate ini file from the main PPSSPP config.
void LoadConfig();
void SaveConfig();
Path ConfigPath();
RequesterToken reqToken_;
@ -112,5 +119,5 @@ private:
ImStructViewer structViewer_;
// Open variables.
ImConfig cfg_;
ImConfig cfg_{};
};

View file

@ -1,8 +1,10 @@
#include "ext/imgui/imgui.h"
#include "Common/File/Path.h"
#include "Common/Input/KeyCodes.h"
#include "Common/Data/Encoding/Utf8.h"
#include "Common/System/Display.h"
#include "Common/TimeUtil.h"
#include "Common/StringUtils.h"
#include "Common/Log.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) {
// Ignore for now.
}

View file

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

View file

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