COMMON: Make getDefaultLogFileName return a Path instead of a String

This commit is contained in:
Le Philousophe 2023-09-02 19:22:08 +02:00 committed by Eugene Sandulenko
parent fd0267cfd1
commit d9a8131ba2
31 changed files with 72 additions and 60 deletions

View File

@ -171,7 +171,7 @@ Common::String OSystem_3DS::getDefaultConfigFileName() {
return "sdmc:/3ds/scummvm/scummvm.ini";
}
Common::String OSystem_3DS::getDefaultLogFileName() {
Common::Path OSystem_3DS::getDefaultLogFileName() {
return "sdmc:/3ds/scummvm/scummvm.log";
}
@ -240,9 +240,9 @@ Common::WriteStream *OSystem_3DS::createLogFile() {
// of a failure, we know that no log file is open.
_logFilePath.clear();
Common::String logFile;
Common::Path logFile;
if (ConfMan.hasKey("logfile"))
logFile = ConfMan.get("logfile");
logFile = ConfMan.getPath("logfile");
else
logFile = getDefaultLogFileName();
if (logFile.empty())

View File

@ -197,7 +197,7 @@ private:
void flushGameScreen();
void flushCursor();
virtual Common::String getDefaultLogFileName();
virtual Common::Path getDefaultLogFileName();
virtual Common::WriteStream *createLogFile();
protected:
@ -288,7 +288,7 @@ private:
u16 _magWidth, _magHeight;
u16 _magCenterX, _magCenterY;
Common::String _logFilePath;
Common::Path _logFilePath;
public:
// Pause

View File

@ -193,7 +193,7 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
_trackball_scale(2),
_joystick_scale(10),
_defaultConfigFileName(""),
_defaultLogFileName(""),
_defaultLogFileName(),
_systemPropertiesSummaryStr(""),
_systemSDKdetectedStr(""),
_logger(nullptr) {
@ -586,7 +586,7 @@ Common::String OSystem_Android::getDefaultConfigFileName() {
return _defaultConfigFileName;
}
Common::String OSystem_Android::getDefaultLogFileName() {
Common::Path OSystem_Android::getDefaultLogFileName() {
if (_defaultLogFileName.empty()) {
_defaultLogFileName = JNI::getScummVMLogPath();
}
@ -594,12 +594,14 @@ Common::String OSystem_Android::getDefaultLogFileName() {
}
Common::WriteStream *OSystem_Android::createLogFileForAppending() {
if (getDefaultLogFileName().empty()) {
Common::String logPath(getDefaultLogFileName().toString(Common::Path::kNativeSeparator));
if (logPath.empty()) {
__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Log file path is not known upon create attempt!");
return nullptr;
}
FILE *scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "a");
FILE *scvmLogFilePtr = fopen(logPath.c_str(), "a");
if (scvmLogFilePtr != nullptr) {
// We check for log file size; if it's too big, we rewrite it.
// This happens only upon app launch, in initBackend() when createLogFileForAppending() is called
@ -608,9 +610,9 @@ Common::WriteStream *OSystem_Android::createLogFileForAppending() {
if (sz > MAX_ANDROID_SCUMMVM_LOG_FILESIZE_IN_BYTES) {
fclose(scvmLogFilePtr);
__android_log_write(ANDROID_LOG_WARN, android_log_tag, "Default log file is bigger than 100KB. It will be overwritten!");
if (!getDefaultLogFileName().empty()) {
if (!logPath.empty()) {
// Create the log file from scratch overwriting the previous one
scvmLogFilePtr = fopen(getDefaultLogFileName().c_str(), "w");
scvmLogFilePtr = fopen(logPath.c_str(), "w");
if (scvmLogFilePtr == nullptr) {
__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Could not open default log file for rewrite!");
return nullptr;
@ -622,7 +624,7 @@ Common::WriteStream *OSystem_Android::createLogFileForAppending() {
}
} else {
__android_log_write(ANDROID_LOG_ERROR, android_log_tag, "Could not open default log file for writing/appending.");
__android_log_write(ANDROID_LOG_ERROR, android_log_tag, getDefaultLogFileName().c_str());
__android_log_write(ANDROID_LOG_ERROR, android_log_tag, logPath.c_str());
}
return new PosixIoStream(scvmLogFilePtr);
}

View File

@ -166,7 +166,7 @@ private:
TouchControls _touchControls;
Common::String _defaultConfigFileName;
Common::String _defaultLogFileName;
Common::Path _defaultLogFileName;
Common::String _systemPropertiesSummaryStr;
Common::String _systemSDKdetectedStr;
@ -223,7 +223,7 @@ public:
Common::KeymapperDefaultBindings *getKeymapperDefaultBindings() override;
Common::String getDefaultConfigFileName() override;
Common::String getDefaultLogFileName() override;
Common::Path getDefaultLogFileName() override;
void registerDefaultSettings(const Common::String &target) const override;
GUI::OptionsContainerWidget *buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const override;

View File

@ -158,7 +158,7 @@ public:
bool isConnectionLimited() override;
void virtualController(bool connect);
virtual Common::String getDefaultLogFileName() override { return Common::String("/scummvm.log"); }
virtual Common::Path getDefaultLogFileName() override { return Common::Path("/scummvm.log"); }
virtual GUI::OptionsContainerWidget* buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const override;
virtual void applyBackendSettings() override;

View File

@ -57,9 +57,9 @@ Common::String OSystem_SDL_SamsungTV::getDefaultConfigFileName() {
return "/mtd_rwarea/.scummvmrc";
}
Common::String OSystem_SDL_SamsungTV::getDefaultLogFileName() {
Common::Path OSystem_SDL_SamsungTV::getDefaultLogFileName() {
if (!Posix::assureDirectoryExists("/mtd_ram", nullptr)) {
return Common::String();
return Common::Path();
}
return "/mtd_ram/scummvm.log";

View File

@ -35,7 +35,7 @@ public:
protected:
virtual Common::String getDefaultConfigFileName();
virtual Common::String getDefaultLogFileName();
virtual Common::Path getDefaultLogFileName();
};
#endif

View File

@ -108,8 +108,8 @@ Common::String OSystem_KolibriOS::getScreenshotsPath() {
return _writablePath.join(SCREENSHOTS_DIR_NAME).toString();
}
Common::String OSystem_KolibriOS::getDefaultLogFileName() {
return _writablePath.join("scummvm.log").toString();
Common::Path OSystem_KolibriOS::getDefaultLogFileName() {
return _writablePath.join("scummvm.log");
}
AudioCDManager *OSystem_KolibriOS::createAudioCDManager() {

View File

@ -39,7 +39,7 @@ public:
protected:
Common::String getDefaultConfigFileName() override;
Common::String getDefaultLogFileName() override;
Common::Path getDefaultLogFileName() override;
AudioCDManager *createAudioCDManager() override;

View File

@ -157,7 +157,9 @@ bool OSystem_MacOSX::displayLogFile() {
if (_logFilePath.empty())
return false;
CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)_logFilePath.c_str(), _logFilePath.size(), false);
Common::String logFilePath(_logFilePath.toString(Common::Path::kNativeSeparator));
CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)logFilePath.c_str(), logFilePath.size(), false);
OSStatus err = LSOpenCFURLRef(url, NULL);
CFRelease(url);
@ -236,19 +238,19 @@ Common::String OSystem_MacOSX::getDefaultConfigFileName() {
return configFile;
}
Common::String OSystem_MacOSX::getDefaultLogFileName() {
Common::Path OSystem_MacOSX::getDefaultLogFileName() {
const char *prefix = getenv("HOME");
if (prefix == nullptr) {
return Common::String();
return Common::Path();
}
if (!Posix::assureDirectoryExists("Library/Logs", prefix)) {
return Common::String();
return Common::Path();
}
Common::String appName = getMacBundleName();
appName.toLowercase();
return Common::String(prefix) + "/Library/Logs/" + appName + ".log";
return Common::Path(prefix).join(Common::String("Library/Logs/") + appName + ".log");
}
Common::String OSystem_MacOSX::getDefaultIconsPath() {

View File

@ -56,7 +56,7 @@ public:
protected:
Common::String getDefaultConfigFileName() override;
Common::String getDefaultLogFileName() override;
Common::Path getDefaultLogFileName() override;
// Override createAudioCDManager() to get our Mac-specific
// version.

View File

@ -203,7 +203,7 @@ Common::String OSystem_SDL_Miyoo::getDefaultConfigFileName() {
}
Common::String OSystem_SDL_Miyoo::getDefaultLogFileName() {
Common::Path OSystem_SDL_Miyoo::getDefaultLogFileName() {
return LOG_FILE;
}

View File

@ -36,7 +36,7 @@ public:
protected:
Common::String getDefaultConfigFileName() override;
Common::String getDefaultLogFileName() override;
Common::Path getDefaultLogFileName() override;
};
#endif

View File

@ -178,7 +178,7 @@ Common::String OSystem_SDL_Opendingux::getDefaultConfigFileName() {
}
Common::String OSystem_SDL_Opendingux::getDefaultLogFileName() {
Common::Path OSystem_SDL_Opendingux::getDefaultLogFileName() {
return LOG_FILE;
}

View File

@ -36,7 +36,7 @@ public:
protected:
Common::String getDefaultConfigFileName() override;
Common::String getDefaultLogFileName() override;
Common::Path getDefaultLogFileName() override;
};
#endif

View File

@ -335,7 +335,7 @@ void OSystem_POSIX::addSysArchivesToSearchSet(Common::SearchSet &s, int priority
OSystem_SDL::addSysArchivesToSearchSet(s, priority);
}
Common::String OSystem_POSIX::getDefaultLogFileName() {
Common::Path OSystem_POSIX::getDefaultLogFileName() {
Common::String logFile;
// On POSIX systems we follow the XDG Base Directory Specification for
@ -357,7 +357,11 @@ Common::String OSystem_POSIX::getDefaultLogFileName() {
return Common::String();
}
return Common::String::format("%s/%s/scummvm.log", prefix, logFile.c_str());
Common::Path logPath(prefix);
logPath.joinInPlace(logFile);
logPath.joinInPlace("scummvm.log");
return logPath;
}
bool OSystem_POSIX::displayLogFile() {
@ -376,7 +380,7 @@ bool OSystem_POSIX::displayLogFile() {
} else if (pid == 0) {
// Try xdg-open first
execlp("xdg-open", "xdg-open", _logFilePath.c_str(), (char *)0);
execlp("xdg-open", "xdg-open", _logFilePath.toString(Common::Path::kNativeSeparator).c_str(), (char *)0);
// If we're here, that clearly failed.
@ -385,7 +389,7 @@ bool OSystem_POSIX::displayLogFile() {
// Try xterm+less next
execlp("xterm", "xterm", "-e", "less", _logFilePath.c_str(), (char *)0);
execlp("xterm", "xterm", "-e", "less", _logFilePath.toString(Common::Path::kNativeSeparator).c_str(), (char *)0);
// TODO: If less does not exist we could fall back to 'more'.
// However, we'll have to use 'xterm -hold' for that to prevent the

View File

@ -42,7 +42,7 @@ public:
protected:
Common::String getDefaultConfigFileName() override;
Common::String getDefaultLogFileName() override;
Common::Path getDefaultLogFileName() override;
Common::String getXdgUserDir(const char *name);

View File

@ -108,7 +108,7 @@ Common::String OSystem_PS3::getDefaultConfigFileName() {
return PREFIX "/scummvm.ini";
}
Common::String OSystem_PS3::getDefaultLogFileName() {
Common::Path OSystem_PS3::getDefaultLogFileName() {
return PREFIX "/scummvm.log";
}

View File

@ -33,7 +33,7 @@ public:
protected:
Common::String getDefaultConfigFileName() override;
Common::String getDefaultLogFileName() override;
Common::Path getDefaultLogFileName() override;
};
#endif

View File

@ -186,7 +186,7 @@ Common::String OSystem_PSP2::getDefaultConfigFileName() {
return "ux0:data/scummvm/scummvm.ini";
}
Common::String OSystem_PSP2::getDefaultLogFileName() {
Common::Path OSystem_PSP2::getDefaultLogFileName() {
return "ux0:data/scummvm/scummvm.log";
}

View File

@ -39,7 +39,7 @@ public:
protected:
Common::String getDefaultConfigFileName() override;
Common::String getDefaultLogFileName() override;
Common::Path getDefaultLogFileName() override;
};
#endif

View File

@ -155,14 +155,16 @@ Common::String OSystem_RISCOS::getDefaultConfigFileName() {
return "/<Choices$Write>/ScummVM/scummvmrc";
}
Common::String OSystem_RISCOS::getDefaultLogFileName() {
Common::Path OSystem_RISCOS::getDefaultLogFileName() {
Common::String logFile = "/<Choices$Write>/ScummVM/Logs";
if (!Riscos::assureDirectoryExists(logFile)) {
return Common::String();
return Common::Path();
}
return logFile + "/scummvm";
Common::Path logPath(logFile);
logPath.joinInPlace("scummvm");
return logPath;
}
#endif

View File

@ -38,7 +38,7 @@ public:
protected:
virtual Common::String getDefaultConfigFileName();
virtual Common::String getDefaultLogFileName();
virtual Common::Path getDefaultLogFileName();
};
#endif

View File

@ -615,9 +615,9 @@ Common::WriteStream *OSystem_SDL::createLogFile() {
// of a failure, we know that no log file is open.
_logFilePath.clear();
Common::String logFile;
Common::Path logFile;
if (ConfMan.hasKey("logfile"))
logFile = ConfMan.get("logfile");
logFile = ConfMan.getPath("logfile");
else
logFile = getDefaultLogFileName();
if (logFile.empty())

View File

@ -123,7 +123,7 @@ protected:
* only use of this value is to use it to open the log file in an
* editor; for that, we need it only as a string anyway.
*/
Common::String _logFilePath;
Common::Path _logFilePath;
/**
* The event source we use for obtaining SDL events.

View File

@ -149,7 +149,7 @@ void OSystem_Switch::logMessage(LogMessageType::Type type, const char *message)
printf("%s\n", message);
}
Common::String OSystem_Switch::getDefaultLogFileName() {
Common::Path OSystem_Switch::getDefaultLogFileName() {
return "scummvm.log";
}

View File

@ -36,7 +36,7 @@ public:
virtual Common::String getSystemLanguage() const;
protected:
Common::String getDefaultLogFileName() override;
Common::Path getDefaultLogFileName() override;
};
#endif

View File

@ -161,7 +161,7 @@ bool OSystem_Win32::displayLogFile() {
// Try opening the log file with the default text editor
// log files should be registered as "txtfile" by default and thus open in the default text editor
TCHAR *tLogFilePath = Win32::stringToTchar(_logFilePath);
TCHAR *tLogFilePath = Win32::stringToTchar(_logFilePath.toString(Common::Path::kNativeSeparator));
SHELLEXECUTEINFO sei;
memset(&sei, 0, sizeof(sei));
@ -377,7 +377,7 @@ Common::String OSystem_Win32::getDefaultConfigFileName() {
return Win32::tcharToString(configFile);
}
Common::String OSystem_Win32::getDefaultLogFileName() {
Common::Path OSystem_Win32::getDefaultLogFileName() {
TCHAR logFile[MAX_PATH];
if (_isPortable) {
@ -385,7 +385,7 @@ Common::String OSystem_Win32::getDefaultLogFileName() {
} else {
// Use the Application Data directory of the user profile
if (!Win32::getApplicationDataDirectory(logFile)) {
return Common::String();
return Common::Path();
}
_tcscat(logFile, TEXT("\\Logs"));
CreateDirectory(logFile, nullptr);
@ -393,7 +393,7 @@ Common::String OSystem_Win32::getDefaultLogFileName() {
_tcscat(logFile, TEXT("\\scummvm.log"));
return Win32::tcharToString(logFile);
return Common::Path(Win32::tcharToString(logFile), Common::Path::kNativeSeparator);
}
bool OSystem_Win32::detectPortableConfigFile() {

View File

@ -55,7 +55,7 @@ public:
protected:
Common::String getDefaultConfigFileName() override;
Common::String getDefaultLogFileName() override;
Common::Path getDefaultLogFileName() override;
// Override createAudioCDManager() to get our Windows-specific
// version.

View File

@ -29,6 +29,7 @@
#include "common/ustr.h"
#include "common/str-array.h" // For OSystem::updateStartSettings()
#include "common/hash-str.h" // For OSystem::updateStartSettings()
#include "common/path.h"
#include "graphics/pixelformat.h"
#include "graphics/mode.h"
#include "graphics/opengl/context.h"
@ -1810,7 +1811,7 @@ public:
*
* Note that not all ports can use this.
*/
virtual Common::String getDefaultLogFileName() { return Common::String(); }
virtual Common::Path getDefaultLogFileName() { return Common::Path(); }
/**
* Register the default values for the settings the backend uses into the

View File

@ -2493,16 +2493,17 @@ void GlobalOptionsDialog::addPathsControls(GuiObject *boss, const Common::String
if (ConfMan.isKeyTemporary("config"))
configPathWidget->setFontColor(ThemeEngine::FontColor::kFontColorOverride);
Common::U32String logPath = g_system->getDefaultLogFileName();
Common::Path logPath = g_system->getDefaultLogFileName();
bool colorOverride = false;
if (ConfMan.hasKey("logfile")) {
logPath = ConfMan.get("logfile");
logPath = ConfMan.getPath("logfile");
if (ConfMan.isKeyTemporary("logfile"))
colorOverride = true;
}
_logPath = new StaticTextWidget(boss, prefix + "LogPath", _("ScummVM log path: ") + logPath, logPath);
Common::U32String logPathS = logPath.toString(Common::Path::kNativeSeparator);
_logPath = new StaticTextWidget(boss, prefix + "LogPath", _("ScummVM log path: ") + logPathS, logPathS);
if (colorOverride)
_logPath->setFontColor(ThemeEngine::FontColor::kFontColorOverride);
@ -3286,10 +3287,10 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
break;
case kViewLogCmd: {
Common::String logPath;
Common::Path logPath;
if (ConfMan.hasKey("logfile"))
logPath = ConfMan.get("logfile");
logPath = ConfMan.getPath("logfile");
else
logPath = g_system->getDefaultLogFileName();