SDL: Simplify implementation of createLogFile()
This commit is contained in:
parent
d10c69d0d1
commit
8b8fb6d3a4
18 changed files with 86 additions and 114 deletions
|
@ -57,4 +57,12 @@ void OSystem_SDL_SamsungTV::fatalError() {
|
|||
for (;;) {}
|
||||
}
|
||||
|
||||
Common::String OSystem_SDL_SamsungTV::getDefaultLogFileName() {
|
||||
if (!Posix::assureDirectoryExists("/mtd_ram", nullptr)) {
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
return "/mtd_ram/scummvm.log";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -34,6 +34,9 @@ public:
|
|||
virtual void initBackend();
|
||||
virtual void quit();
|
||||
virtual void fatalError();
|
||||
|
||||
protected:
|
||||
virtual Common::String getDefaultLogFileName();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "backends/taskbar/macosx/macosx-taskbar.h"
|
||||
#include "backends/dialogs/macosx/macosx-dialogs.h"
|
||||
#include "backends/platform/sdl/macosx/macosx_wrapper.h"
|
||||
#include "backends/fs/posix/posix-fs.h"
|
||||
|
||||
#include "common/archive.h"
|
||||
#include "common/config-manager.h"
|
||||
|
@ -198,6 +199,19 @@ Common::String OSystem_MacOSX::getSystemLanguage() const {
|
|||
#endif // USE_DETECTLANG
|
||||
}
|
||||
|
||||
Common::String OSystem_MacOSX::getDefaultLogFileName() {
|
||||
const char *prefix = getenv("HOME");
|
||||
if (prefix == nullptr) {
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
if (!Posix::assureDirectoryExists("Library/Logs", prefix)) {
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
return Common::String(prefix) + "/Library/Logs/scummvm.log";
|
||||
}
|
||||
|
||||
Common::String OSystem_MacOSX::getScreenshotsPath() {
|
||||
Common::String path = ConfMan.get("screenshotpath");
|
||||
if (path.empty())
|
||||
|
|
|
@ -50,6 +50,8 @@ public:
|
|||
virtual Common::String getScreenshotsPath();
|
||||
|
||||
protected:
|
||||
virtual Common::String getDefaultLogFileName();
|
||||
|
||||
// Override createAudioCDManager() to get our Mac-specific
|
||||
// version.
|
||||
virtual AudioCDManager *createAudioCDManager();
|
||||
|
|
|
@ -269,55 +269,29 @@ void OSystem_POSIX::addSysArchivesToSearchSet(Common::SearchSet &s, int priority
|
|||
OSystem_SDL::addSysArchivesToSearchSet(s, priority);
|
||||
}
|
||||
|
||||
Common::WriteStream *OSystem_POSIX::createLogFile() {
|
||||
// Start out by resetting _logFilePath, so that in case
|
||||
// of a failure, we know that no log file is open.
|
||||
_logFilePath.clear();
|
||||
|
||||
const char *prefix = nullptr;
|
||||
Common::String OSystem_POSIX::getDefaultLogFileName() {
|
||||
Common::String logFile;
|
||||
#ifdef MACOSX
|
||||
prefix = getenv("HOME");
|
||||
if (prefix == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
logFile = "Library/Logs";
|
||||
#elif SAMSUNGTV
|
||||
prefix = nullptr;
|
||||
logFile = "/mtd_ram";
|
||||
#else
|
||||
// On POSIX systems we follow the XDG Base Directory Specification for
|
||||
// where to store files. The version we based our code upon can be found
|
||||
// over here: http://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
|
||||
prefix = getenv("XDG_CACHE_HOME");
|
||||
const char *prefix = getenv("XDG_CACHE_HOME");
|
||||
if (prefix == nullptr || !*prefix) {
|
||||
prefix = getenv("HOME");
|
||||
if (prefix == nullptr) {
|
||||
return 0;
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
logFile = ".cache/";
|
||||
}
|
||||
|
||||
logFile += "scummvm/logs";
|
||||
#endif
|
||||
|
||||
if (!Posix::assureDirectoryExists(logFile, prefix)) {
|
||||
return 0;
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
if (prefix) {
|
||||
logFile = Common::String::format("%s/%s", prefix, logFile.c_str());
|
||||
}
|
||||
|
||||
logFile += "/scummvm.log";
|
||||
|
||||
Common::FSNode file(logFile);
|
||||
Common::WriteStream *stream = file.createWriteStream();
|
||||
if (stream)
|
||||
_logFilePath = logFile;
|
||||
return stream;
|
||||
return Common::String::format("%s/%s/scummvm.log", prefix, logFile.c_str());
|
||||
}
|
||||
|
||||
bool OSystem_POSIX::displayLogFile() {
|
||||
|
|
|
@ -52,19 +52,8 @@ protected:
|
|||
*/
|
||||
Common::String _baseConfigName;
|
||||
|
||||
/**
|
||||
* The path of the currently open log file, if any.
|
||||
*
|
||||
* @note This is currently a string and not an FSNode for simplicity;
|
||||
* e.g. we don't need to include fs.h here, and currently the
|
||||
* 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;
|
||||
|
||||
virtual Common::String getDefaultConfigFileName();
|
||||
|
||||
virtual Common::WriteStream *createLogFile();
|
||||
virtual Common::String getDefaultLogFileName();
|
||||
|
||||
Common::String getXdgUserDir(const char *name);
|
||||
|
||||
|
|
|
@ -78,7 +78,6 @@ Common::String OSystem_PS3::getDefaultConfigFileName() {
|
|||
return PREFIX "/" + _baseConfigName;
|
||||
}
|
||||
|
||||
Common::WriteStream *OSystem_PS3::createLogFile() {
|
||||
Common::FSNode file(PREFIX "/scummvm.log");
|
||||
return file.createWriteStream();
|
||||
Common::String OSystem_PS3::getDefaultLogFileName() {
|
||||
return PREFIX "/scummvm.log";
|
||||
}
|
||||
|
|
|
@ -40,8 +40,7 @@ protected:
|
|||
Common::String _baseConfigName;
|
||||
|
||||
virtual Common::String getDefaultConfigFileName();
|
||||
|
||||
virtual Common::WriteStream *createLogFile();
|
||||
virtual Common::String getDefaultLogFileName();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -169,7 +169,6 @@ Common::String OSystem_PSP2::getDefaultConfigFileName() {
|
|||
return "ux0:data/scummvm/" + _baseConfigName;
|
||||
}
|
||||
|
||||
Common::WriteStream *OSystem_PSP2::createLogFile() {
|
||||
Common::FSNode file("ux0:data/scummvm/scummvm.log");
|
||||
return file.createWriteStream();
|
||||
Common::String OSystem_PSP2::getDefaultLogFileName() {
|
||||
return "ux0:data/scummvm/scummvm.log";
|
||||
}
|
||||
|
|
|
@ -47,8 +47,7 @@ protected:
|
|||
Common::String _baseConfigName;
|
||||
|
||||
virtual Common::String getDefaultConfigFileName() override;
|
||||
|
||||
virtual Common::WriteStream *createLogFile() override;
|
||||
virtual Common::String getDefaultLogFileName() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -119,24 +119,14 @@ Common::String OSystem_RISCOS::getDefaultConfigFileName() {
|
|||
return "/<Choices$Write>/ScummVM/scummvmrc";
|
||||
}
|
||||
|
||||
Common::WriteStream *OSystem_RISCOS::createLogFile() {
|
||||
// Start out by resetting _logFilePath, so that in case
|
||||
// of a failure, we know that no log file is open.
|
||||
_logFilePath.clear();
|
||||
|
||||
Common::String OSystem_RISCOS::getDefaultLogFileName() {
|
||||
Common::String logFile = "/<Choices$Write>/ScummVM/Logs";
|
||||
|
||||
if (!Riscos::assureDirectoryExists(logFile)) {
|
||||
return 0;
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
logFile += "/scummvm";
|
||||
|
||||
Common::FSNode file(logFile);
|
||||
Common::WriteStream *stream = file.createWriteStream();
|
||||
if (stream)
|
||||
_logFilePath = logFile;
|
||||
return stream;
|
||||
return logFile + "/scummvm";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -37,18 +37,8 @@ public:
|
|||
virtual void logMessage(LogMessageType::Type type, const char *message);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The path of the currently open log file, if any.
|
||||
*
|
||||
* @note This is currently a string and not an FSNode for simplicity;
|
||||
* e.g. we don't need to include fs.h here, and currently the
|
||||
* 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;
|
||||
|
||||
virtual Common::String getDefaultConfigFileName();
|
||||
virtual Common::WriteStream *createLogFile();
|
||||
virtual Common::String getDefaultLogFileName();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -406,6 +406,22 @@ void OSystem_SDL::logMessage(LogMessageType::Type type, const char *message) {
|
|||
_logger->print(message);
|
||||
}
|
||||
|
||||
Common::WriteStream *OSystem_SDL::createLogFile() {
|
||||
// Start out by resetting _logFilePath, so that in case
|
||||
// of a failure, we know that no log file is open.
|
||||
_logFilePath.clear();
|
||||
|
||||
Common::String logFile = getDefaultLogFileName();
|
||||
if (logFile.empty())
|
||||
return nullptr;
|
||||
|
||||
Common::FSNode file(logFile);
|
||||
Common::WriteStream *stream = file.createWriteStream();
|
||||
if (stream)
|
||||
_logFilePath = logFile;
|
||||
return stream;
|
||||
}
|
||||
|
||||
Common::String OSystem_SDL::getSystemLanguage() const {
|
||||
#if defined(USE_DETECTLANG) && !defined(WIN32)
|
||||
// Activating current locale settings
|
||||
|
|
|
@ -93,6 +93,16 @@ protected:
|
|||
bool _initedSDLnet;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The path of the currently open log file, if any.
|
||||
*
|
||||
* @note This is currently a string and not an FSNode for simplicity;
|
||||
* e.g. we don't need to include fs.h here, and currently the
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Mixer manager that configures and setups SDL for
|
||||
* the wrapped Audio::Mixer, the true mixer.
|
||||
|
@ -122,7 +132,8 @@ protected:
|
|||
virtual AudioCDManager *createAudioCDManager();
|
||||
|
||||
// Logging
|
||||
virtual Common::WriteStream *createLogFile() { return 0; }
|
||||
virtual Common::String getDefaultLogFileName() { return Common::String(); }
|
||||
virtual Common::WriteStream *createLogFile();
|
||||
Backends::Log::Log *_logger;
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
|
|
|
@ -124,7 +124,6 @@ Common::String OSystem_Switch::getDefaultConfigFileName() {
|
|||
return _baseConfigName;
|
||||
}
|
||||
|
||||
Common::WriteStream *OSystem_Switch::createLogFile() {
|
||||
Common::FSNode file("scummvm.log");
|
||||
return file.createWriteStream();
|
||||
Common::String OSystem_Switch::getDefaultLogFileName() {
|
||||
return "scummvm.log";
|
||||
}
|
||||
|
|
|
@ -44,8 +44,7 @@ protected:
|
|||
Common::String _baseConfigName;
|
||||
|
||||
virtual Common::String getDefaultConfigFileName() override;
|
||||
|
||||
virtual Common::WriteStream *createLogFile() override;
|
||||
virtual Common::String getDefaultLogFileName() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -278,31 +278,22 @@ Common::String OSystem_Win32::getDefaultConfigFileName() {
|
|||
return configFile;
|
||||
}
|
||||
|
||||
Common::WriteStream *OSystem_Win32::createLogFile() {
|
||||
// Start out by resetting _logFilePath, so that in case
|
||||
// of a failure, we know that no log file is open.
|
||||
_logFilePath.clear();
|
||||
|
||||
Common::String OSystem_Win32::getDefaultLogFileName() {
|
||||
char logFile[MAXPATHLEN];
|
||||
|
||||
// Use the Application Data directory of the user profile.
|
||||
if (SHGetFolderPathFunc(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, logFile) == S_OK) {
|
||||
if (SHGetFolderPathFunc(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, logFile) != S_OK) {
|
||||
warning("Unable to access application data directory");
|
||||
return Common::String();
|
||||
}
|
||||
|
||||
strcat(logFile, "\\ScummVM");
|
||||
CreateDirectory(logFile, NULL);
|
||||
strcat(logFile, "\\Logs");
|
||||
CreateDirectory(logFile, NULL);
|
||||
strcat(logFile, "\\scummvm.log");
|
||||
|
||||
Common::FSNode file(logFile);
|
||||
Common::WriteStream *stream = file.createWriteStream();
|
||||
if (stream)
|
||||
_logFilePath= logFile;
|
||||
|
||||
return stream;
|
||||
} else {
|
||||
warning("Unable to access application data directory");
|
||||
return 0;
|
||||
}
|
||||
return logFile;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -46,18 +46,8 @@ public:
|
|||
virtual Common::String getScreenshotsPath();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The path of the currently open log file, if any.
|
||||
*
|
||||
* @note This is currently a string and not an FSNode for simplicity;
|
||||
* e.g. we don't need to include fs.h here, and currently the
|
||||
* 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;
|
||||
|
||||
virtual Common::String getDefaultConfigFileName();
|
||||
virtual Common::WriteStream *createLogFile();
|
||||
virtual Common::String getDefaultLogFileName();
|
||||
|
||||
// Override createAudioCDManager() to get our Mac-specific
|
||||
// version.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue