ppsspp/Core/Config.cpp

265 lines
9.6 KiB
C++
Raw Normal View History

2012-11-01 15:19:01 +00:00
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
2012-11-01 15:19:01 +00:00
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "Common/FileUtil.h"
2012-11-01 15:19:01 +00:00
#include "Config.h"
#include "file/ini_file.h"
#include "HLE/sceUtility.h"
2013-05-01 12:08:01 +00:00
#include "Common/CPUDetect.h"
2012-11-01 15:19:01 +00:00
Config g_Config;
2012-11-01 15:19:01 +00:00
#define MAX_RECENT 12
2013-03-29 17:50:08 +00:00
#ifdef IOS
extern bool isJailed;
#endif
Config::Config()
2012-11-01 15:19:01 +00:00
{
}
Config::~Config()
2012-11-01 15:19:01 +00:00
{
}
void Config::Load(const char *iniFileName)
2012-11-01 15:19:01 +00:00
{
iniFilename_ = iniFileName;
INFO_LOG(LOADER, "Loading config: %s", iniFileName);
2012-11-01 15:19:01 +00:00
bSaveSettings = true;
IniFile iniFile;
if (!iniFile.Load(iniFileName)) {
ERROR_LOG(LOADER, "Failed to read %s. Setting config to default.", iniFileName);
// Continue anyway to initialize the config.
}
2012-11-01 15:19:01 +00:00
IniFile::Section *general = iniFile.GetOrCreateSection("General");
bSpeedLimit = false;
general->Get("FirstRun", &bFirstRun, true);
general->Get("AutoLoadLast", &bAutoLoadLast, false);
general->Get("AutoRun", &bAutoRun, true);
2013-02-17 19:39:31 +00:00
general->Get("Browse", &bBrowse, false);
2012-11-01 15:19:01 +00:00
general->Get("ConfirmOnQuit", &bConfirmOnQuit, false);
general->Get("IgnoreBadMemAccess", &bIgnoreBadMemAccess, true);
general->Get("CurrentDirectory", &currentDirectory, "");
2012-12-04 16:04:24 +00:00
general->Get("ShowDebuggerOnLoad", &bShowDebuggerOnLoad, false);
general->Get("Language", &languageIni, "en_US");
2013-05-01 12:08:01 +00:00
general->Get("NumWorkerThreads", &iNumWorkerThreads, cpu_info.num_cores);
// "default" means let emulator decide, "" means disable.
general->Get("ReportHost", &sReportHost, "default");
general->Get("Recent", recentIsos);
2013-03-30 16:49:02 +00:00
general->Get("WindowX", &iWindowX, 40);
general->Get("WindowY", &iWindowY, 100);
general->Get("AutoSaveSymbolMap", &bAutoSaveSymbolMap, false);
2013-03-30 16:49:02 +00:00
2013-03-29 17:50:08 +00:00
if (recentIsos.size() > MAX_RECENT)
recentIsos.resize(MAX_RECENT);
IniFile::Section *cpu = iniFile.GetOrCreateSection("CPU");
#ifdef IOS
if(isJailed == true)
cpu->Get("Jit", &bJit, false);
else
cpu->Get("Jit", &bJit, true);
#else
cpu->Get("Jit", &bJit, true);
#endif
//FastMemory Default set back to True when solve UNIMPL _sceAtracGetContextAddress making game crash
cpu->Get("FastMemory", &bFastMemory, false);
IniFile::Section *graphics = iniFile.GetOrCreateSection("Graphics");
graphics->Get("ShowFPSCounter", &bShowFPSCounter, false);
graphics->Get("DisplayFramebuffer", &bDisplayFramebuffer, false);
#ifdef _WIN32
graphics->Get("WindowZoom", &iWindowZoom, 2);
#else
graphics->Get("WindowZoom", &iWindowZoom, 1);
#endif
graphics->Get("BufferedRendering", &bBufferedRendering, true);
graphics->Get("HardwareTransform", &bHardwareTransform, true);
2012-12-28 15:23:42 +00:00
graphics->Get("LinearFiltering", &bLinearFiltering, false);
2013-01-26 23:15:39 +00:00
graphics->Get("SSAA", &SSAntiAliasing, 0);
graphics->Get("VBO", &bUseVBO, false);
graphics->Get("FrameSkip", &iFrameSkip, 0);
2013-03-04 14:39:42 +00:00
graphics->Get("UseMediaEngine", &bUseMediaEngine, true);
#ifdef USING_GLES2
graphics->Get("AnisotropyLevel", &iAnisotropyLevel, 0);
#else
graphics->Get("AnisotropyLevel", &iAnisotropyLevel, 8);
#endif
2013-01-26 16:26:07 +00:00
graphics->Get("VertexCache", &bVertexCache, true);
graphics->Get("FullScreen", &bFullScreen, false);
graphics->Get("StretchToDisplay", &bStretchToDisplay, false);
graphics->Get("TrueColor", &bTrueColor, true);
#ifdef USING_GLES2
graphics->Get("MipMap", &bMipMap, true);
#else
graphics->Get("MipMap", &bMipMap, false);
#endif
graphics->Get("TexScalingLevel", &iTexScalingLevel, 1);
graphics->Get("TexScalingType", &iTexScalingType, 0);
2013-05-03 14:21:46 +00:00
graphics->Get("TexDeposterize", &bTexDeposterize, false);
2012-11-01 15:19:01 +00:00
IniFile::Section *sound = iniFile.GetOrCreateSection("Sound");
sound->Get("Enable", &bEnableSound, true);
IniFile::Section *control = iniFile.GetOrCreateSection("Control");
control->Get("ShowStick", &bShowAnalogStick, false);
#ifdef USING_GLES2
control->Get("ShowTouchControls", &bShowTouchControls, true);
#else
control->Get("ShowTouchControls", &bShowTouchControls,false);
#endif
2013-01-26 16:26:07 +00:00
control->Get("LargeControls", &bLargeControls, false);
control->Get("KeyMapping",iMappingMap);
control->Get("AccelerometerToAnalogHoriz", &bAccelerometerToAnalogHoriz, false);
control->Get("ForceInputDevice", &iForceInputDevice, -1);
IniFile::Section *pspConfig = iniFile.GetOrCreateSection("SystemParam");
pspConfig->Get("NickName", &sNickName, "shadow");
pspConfig->Get("Language", &ilanguage, PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
2013-01-21 13:35:31 +00:00
pspConfig->Get("TimeFormat", &itimeformat, PSP_SYSTEMPARAM_TIME_FORMAT_24HR);
pspConfig->Get("DateFormat", &iDateFormat, PSP_SYSTEMPARAM_DATE_FORMAT_YYYYMMDD);
pspConfig->Get("TimeZone", &iTimeZone, 0);
pspConfig->Get("DayLightSavings", &bDayLightSavings, PSP_SYSTEMPARAM_DAYLIGHTSAVINGS_STD);
pspConfig->Get("ButtonPreference", &bButtonPreference, PSP_SYSTEMPARAM_BUTTON_CROSS);
2013-04-20 16:01:03 +00:00
pspConfig->Get("LockParentalLevel", &iLockParentalLevel, 0);
pspConfig->Get("WlanAdhocChannel", &iWlanAdhocChannel, PSP_SYSTEMPARAM_ADHOC_CHANNEL_AUTOMATIC);
pspConfig->Get("WlanPowerSave", &bWlanPowerSave, PSP_SYSTEMPARAM_WLAN_POWERSAVE_OFF);
pspConfig->Get("EncryptSave", &bEncryptSave, true);
CleanRecent();
// Ephemeral settings
bDrawWireframe = false;
2012-11-01 15:19:01 +00:00
}
void Config::Save()
2012-11-01 15:19:01 +00:00
{
if (iniFilename_.size() && g_Config.bSaveSettings) {
CleanRecent();
2012-11-01 15:19:01 +00:00
IniFile iniFile;
if (!iniFile.Load(iniFilename_.c_str())) {
ERROR_LOG(LOADER, "Error saving config - can't read ini %s", iniFilename_.c_str());
}
2012-11-01 15:19:01 +00:00
IniFile::Section *general = iniFile.GetOrCreateSection("General");
general->Set("FirstRun", bFirstRun);
general->Set("AutoLoadLast", bAutoLoadLast);
general->Set("AutoRun", bAutoRun);
2013-02-17 19:39:31 +00:00
general->Set("Browse", bBrowse);
2012-11-01 15:19:01 +00:00
general->Set("ConfirmOnQuit", bConfirmOnQuit);
general->Set("IgnoreBadMemAccess", bIgnoreBadMemAccess);
general->Set("CurrentDirectory", currentDirectory);
2012-12-04 16:04:24 +00:00
general->Set("ShowDebuggerOnLoad", bShowDebuggerOnLoad);
general->Set("ReportHost", sReportHost);
general->Set("Recent", recentIsos);
2013-03-30 16:49:02 +00:00
general->Set("WindowX", iWindowX);
general->Set("WindowY", iWindowY);
general->Set("AutoSaveSymbolMap", bAutoSaveSymbolMap);
general->Set("Language", languageIni);
2013-05-01 12:08:01 +00:00
general->Set("NumWorkerThreads", iNumWorkerThreads);
IniFile::Section *cpu = iniFile.GetOrCreateSection("CPU");
cpu->Set("Jit", bJit);
cpu->Set("FastMemory", bFastMemory);
IniFile::Section *graphics = iniFile.GetOrCreateSection("Graphics");
graphics->Set("ShowFPSCounter", bShowFPSCounter);
graphics->Set("DisplayFramebuffer", bDisplayFramebuffer);
graphics->Set("WindowZoom", iWindowZoom);
graphics->Set("BufferedRendering", bBufferedRendering);
graphics->Set("HardwareTransform", bHardwareTransform);
2012-12-28 15:23:42 +00:00
graphics->Set("LinearFiltering", bLinearFiltering);
2013-01-26 23:15:39 +00:00
graphics->Set("SSAA", SSAntiAliasing);
graphics->Set("VBO", bUseVBO);
graphics->Set("FrameSkip", iFrameSkip);
graphics->Set("UseMediaEngine", bUseMediaEngine);
graphics->Set("AnisotropyLevel", iAnisotropyLevel);
graphics->Set("VertexCache", bVertexCache);
graphics->Set("FullScreen", bFullScreen);
graphics->Set("StretchToDisplay", bStretchToDisplay);
graphics->Set("TrueColor", bTrueColor);
graphics->Set("MipMap", bMipMap);
graphics->Set("TexScalingLevel", iTexScalingLevel);
graphics->Set("TexScalingType", iTexScalingType);
2013-05-03 14:21:46 +00:00
graphics->Set("TexDeposterize", bTexDeposterize);
2012-11-01 15:19:01 +00:00
IniFile::Section *sound = iniFile.GetOrCreateSection("Sound");
sound->Set("Enable", bEnableSound);
IniFile::Section *control = iniFile.GetOrCreateSection("Control");
control->Set("ShowStick", bShowAnalogStick);
2012-12-01 22:20:08 +00:00
control->Set("ShowTouchControls", bShowTouchControls);
2013-01-26 16:26:07 +00:00
control->Set("LargeControls", bLargeControls);
control->Set("KeyMapping",iMappingMap);
control->Set("AccelerometerToAnalogHoriz", bAccelerometerToAnalogHoriz);
control->Set("ForceInputDevice", iForceInputDevice);
2012-11-01 15:19:01 +00:00
IniFile::Section *pspConfig = iniFile.GetOrCreateSection("SystemParam");
pspConfig->Set("NickName", sNickName.c_str());
pspConfig->Set("Language", ilanguage);
2013-01-21 13:35:31 +00:00
pspConfig->Set("TimeFormat", itimeformat);
pspConfig->Set("DateFormat", iDateFormat);
pspConfig->Set("TimeZone", iTimeZone);
pspConfig->Set("DayLightSavings", bDayLightSavings);
pspConfig->Set("ButtonPreference", bButtonPreference);
2013-04-20 16:01:03 +00:00
pspConfig->Set("LockParentalLevel", iLockParentalLevel);
pspConfig->Set("WlanAdhocChannel", iWlanAdhocChannel);
pspConfig->Set("WlanPowerSave", bWlanPowerSave);
pspConfig->Set("EncryptSave", bEncryptSave);
if (!iniFile.Save(iniFilename_.c_str())) {
ERROR_LOG(LOADER, "Error saving config - can't write ini %s", iniFilename_.c_str());
return;
}
INFO_LOG(LOADER, "Config saved: %s", iniFilename_.c_str());
} else {
INFO_LOG(LOADER, "Not saving config");
2012-11-01 15:19:01 +00:00
}
}
void Config::AddRecent(const std::string &file) {
for (auto str = recentIsos.begin(); str != recentIsos.end(); str++) {
if (*str == file) {
recentIsos.erase(str);
recentIsos.insert(recentIsos.begin(), file);
2013-03-29 17:50:08 +00:00
if (recentIsos.size() > MAX_RECENT)
recentIsos.resize(MAX_RECENT);
return;
}
}
recentIsos.insert(recentIsos.begin(), file);
2013-03-29 17:50:08 +00:00
if (recentIsos.size() > MAX_RECENT)
recentIsos.resize(MAX_RECENT);
}
void Config::CleanRecent() {
std::vector<std::string> cleanedRecent;
for (size_t i = 0; i < recentIsos.size(); i++) {
if (File::Exists(recentIsos[i]))
cleanedRecent.push_back(recentIsos[i]);
}
recentIsos = cleanedRecent;
}