Skip to content

Commit

Permalink
cheats[_ws]: don't ignore custom folders for cheat files
Browse files Browse the repository at this point in the history
The code was searching only at the default paths for cheats and cheats_ws.
Now it's possible to set UseDefaultCheats[WS] at PCSX2_ui.ini to 'disabled'
and set a custom value to Cheats and/or CheatsWS and PCSX2 will respect it.
  • Loading branch information
avih committed Dec 29, 2014
1 parent d4793cc commit 95e00e0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pcsx2/Patch.cpp
Expand Up @@ -203,7 +203,8 @@ static int LoadCheatsFiles(const wxDirName& folderName, wxString& fileSpec, cons
inifile_process(f);
f.Close();
int loaded = cheatnumber - before;
Console.WriteLn((loaded ? Color_Green : Color_Gray), L"Loaded %d %s from '%s'", loaded, WX_STR(friendlyName), WX_STR(buffer));
Console.WriteLn((loaded ? Color_Green : Color_Gray), L"Loaded %d %s from '%s' at '%s'",
loaded, WX_STR(friendlyName), WX_STR(buffer), WX_STR(folderName.ToString()));
numberFoundCheatsFiles ++;
}
found = dir.GetNext(&buffer);
Expand Down Expand Up @@ -253,6 +254,9 @@ int LoadCheats(wxString name, const wxDirName& folderName, const wxString& frien
wxString filespec = name + L"*.pnach";
loaded += LoadCheatsFiles(folderName, filespec, friendlyName, numberFoundCheatsFiles);

// This message _might_ be buggy. This function (LoadCheats) loads from an explicit folder.
// This folder can be cheats or cheats_ws at either the default location or a custom one.
// This check only tests the default cheats folder, so the message it produces is possibly misleading.
if (folderName.ToString().IsSameAs(PathDefs::GetCheats().ToString()) && numberFoundCheatsFiles == 0) {
wxString pathName = Path::Combine(folderName, name.MakeUpper() + L".pnach");
Console.WriteLn(Color_Gray, L"Not found %s file: %s", WX_STR(friendlyName), WX_STR(pathName));
Expand Down
17 changes: 16 additions & 1 deletion pcsx2/gui/AppConfig.cpp
Expand Up @@ -453,9 +453,24 @@ bool AppConfig::FullpathMatchTest( PluginsEnum_t pluginId, const wxString& cmpto
return wxFileName(cmpto).SameAs( FullpathTo(pluginId) );
}

static wxDirName GetResolvedFolder(FoldersEnum_t id)
{
return g_Conf->Folders.IsDefault(id) ? PathDefs::Get(id) : g_Conf->Folders[id];
}

wxDirName GetLogFolder()
{
return g_Conf->Folders.IsDefault( FolderId_Logs ) ? PathDefs::Get(FolderId_Logs) : g_Conf->Folders[FolderId_Logs];
return GetResolvedFolder(FolderId_Logs);
}

wxDirName GetCheatsFolder()
{
return GetResolvedFolder(FolderId_Cheats);
}

wxDirName GetCheatsWsFolder()
{
return GetResolvedFolder(FolderId_CheatsWS);
}

wxDirName GetSettingsFolder()
Expand Down
2 changes: 2 additions & 0 deletions pcsx2/gui/AppConfig.h
Expand Up @@ -67,6 +67,8 @@ extern wxString GetUiSettingsFilename();
extern wxString GetUiKeysFilename();

extern wxDirName GetLogFolder();
extern wxDirName GetCheatsFolder();
extern wxDirName GetCheatsWsFolder();

enum InstallationModeType
{
Expand Down
4 changes: 2 additions & 2 deletions pcsx2/gui/AppCoreThread.cpp
Expand Up @@ -382,14 +382,14 @@ void AppCoreThread::ApplySettings( const Pcsx2Config& src )

// regular cheat patches
if (EmuConfig.EnableCheats) {
if (numberLoadedCheats = LoadCheats(gameCRC, PathDefs::GetCheats(), L"Cheats")) {
if (numberLoadedCheats = LoadCheats(gameCRC, GetCheatsFolder(), L"Cheats")) {
gameCheats.Printf(L" [%d Cheats]", numberLoadedCheats);
}
}

// wide screen patches
if (EmuConfig.EnableWideScreenPatches) {
if (numberLoadedWideScreenPatches = LoadCheats(gameCRC, PathDefs::GetCheatsWS(), L"Widescreen hacks")) {
if (numberLoadedWideScreenPatches = LoadCheats(gameCRC, GetCheatsWsFolder(), L"Widescreen hacks")) {
gameWsHacks.Printf(L" [%d widescreen hacks]", numberLoadedWideScreenPatches);
}
else {
Expand Down

1 comment on commit 95e00e0

@avih
Copy link
Contributor Author

@avih avih commented on 95e00e0 Dec 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking at historical commits, I think it used to at least partially work in the past, and later got changed over time, I'm guessing due to some Linux related changed which unknowingly changed also the windows handling.

I think there's some redundancy now at the code WRT getting the cheats and cheats_ws folders (e.g. I think the existing GetCheats() and GetCheatsWS() are no longer used and instead I added new functions GetCheatsFolder() and GetCheatsWsFolder()).

The whole folders handling is quite messy (with default paths, custom paths, custom/portable installs, paths from command line or at the registry from earlier installs, etc, as well as which paths should be saved on exit and where), but cleaning everything up will take a lot of time and will surely break something for someone, or somethings for many.

So I just hope it now works better than before.

Please sign in to comment.