GTK: Apply patch #3524058 - Auto-load/save cheats

Thanks go to unmacaque
This commit is contained in:
bgk 2013-02-03 12:59:48 +00:00
parent 76da586883
commit d193d8069d
5 changed files with 57 additions and 1 deletions

View File

@ -30,6 +30,7 @@ const DirectoriesConfigDialog::SDirEntry DirectoriesConfigDialog::m_astDirs[] =
{ "gba_roms", N_("GBA roms :"), "GBARomsDirEntry" },
{ "gb_roms", N_("GB roms :"), "GBRomsDirEntry" },
{ "batteries", N_("Batteries :"), "BatteriesDirEntry" },
{ "cheats", N_("Cheats :"), "CheatsDirEntry" },
{ "saves", N_("Saves :"), "SavesDirEntry" },
{ "captures", N_("Captures :"), "CapturesDirEntry" }
};

View File

@ -47,7 +47,7 @@ private:
Config::Section * m_poConfig;
static const SDirEntry m_astDirs[];
Gtk::FileChooserButton * m_poButtons[5];
Gtk::FileChooserButton * m_poButtons[6];
};
} // namespace VBA

View File

@ -504,6 +504,7 @@ void Window::vInitConfig()
m_poDirConfig->vSetKey("gb_roms", Glib::get_home_dir());
m_poDirConfig->vSetKey("gba_roms", Glib::get_home_dir());
m_poDirConfig->vSetKey("batteries", m_sUserDataDir);
m_poDirConfig->vSetKey("cheats", m_sUserDataDir);
m_poDirConfig->vSetKey("saves", m_sUserDataDir);
m_poDirConfig->vSetKey("captures", m_sUserDataDir);
@ -588,6 +589,11 @@ void Window::vCheckConfig()
{
m_poDirConfig->vSetKey("batteries", m_sUserDataDir);
}
sValue = m_poDirConfig->sGetKey("cheats");
if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_DIR))
{
m_poDirConfig->vSetKey("cheats", m_sUserDataDir);
}
sValue = m_poDirConfig->sGetKey("saves");
if (sValue != "" && ! Glib::file_test(sValue, Glib::FILE_TEST_IS_DIR))
{
@ -1078,6 +1084,7 @@ bool Window::bLoadROM(const std::string & _rsFile)
}
vLoadBattery();
vLoadCheats();
vUpdateScreen();
emulating = 1;
@ -1342,6 +1349,30 @@ void Window::vLoadBattery()
}
}
void Window::vLoadCheats()
{
std::string sCheats;
std::string sDir = m_poDirConfig->sGetKey("cheats");
if (sDir == "")
{
sDir = m_sUserDataDir;
}
sCheats = sDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile)) + ".clt";
if (Glib::file_test(sCheats, Glib::FILE_TEST_EXISTS))
{
if (m_eCartridge == CartridgeGB)
{
gbCheatsLoadCheatList(sCheats.c_str());
}
else if (m_eCartridge == CartridgeGBA)
{
cheatsLoadCheatList(sCheats.c_str());
}
}
}
void Window::vSaveBattery()
{
std::string sBattery;
@ -1359,6 +1390,27 @@ void Window::vSaveBattery()
}
}
void Window::vSaveCheats()
{
std::string sCheats;
std::string sDir = m_poDirConfig->sGetKey("cheats");
if (sDir == "")
{
sDir = m_sUserDataDir;
}
sCheats = sDir + "/" + sCutSuffix(Glib::path_get_basename(m_sRomFile)) + ".clt";
if (m_eCartridge == CartridgeGB)
{
gbCheatsSaveCheatList(sCheats.c_str());
}
else if (m_eCartridge == CartridgeGBA)
{
cheatsSaveCheatList(sCheats.c_str());
}
}
void Window::vStartEmu()
{
if (m_oEmuSig.connected())

View File

@ -272,7 +272,9 @@ private:
void vSetDefaultTitle();
void vCreateFileOpenDialog();
void vLoadBattery();
void vLoadCheats();
void vSaveBattery();
void vSaveCheats();
void vStartEmu();
void vStopEmu();
void vUpdateGameSlots();

View File

@ -335,6 +335,7 @@ void Window::vOnFileClose()
vSetDefaultTitle();
vDrawDefaultScreen();
vSaveBattery();
vSaveCheats();
m_stEmulator.emuCleanUp();
m_eCartridge = CartridgeNone;
emulating = 0;