[Scummvm-git-logs] scummvm master -> 8b8fb6d3a4748ded6f47cf057fc22f9aeab225d0

bluegr bluegr at gmail.com
Mon Aug 5 09:01:33 CEST 2019


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
8b8fb6d3a4 SDL: Simplify implementation of createLogFile()


Commit: 8b8fb6d3a4748ded6f47cf057fc22f9aeab225d0
    https://github.com/scummvm/scummvm/commit/8b8fb6d3a4748ded6f47cf057fc22f9aeab225d0
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2019-08-05T10:01:30+03:00

Commit Message:
SDL: Simplify implementation of createLogFile()

Changed paths:
    backends/platform/samsungtv/samsungtv.cpp
    backends/platform/samsungtv/samsungtv.h
    backends/platform/sdl/macosx/macosx.cpp
    backends/platform/sdl/macosx/macosx.h
    backends/platform/sdl/posix/posix.cpp
    backends/platform/sdl/posix/posix.h
    backends/platform/sdl/ps3/ps3.cpp
    backends/platform/sdl/ps3/ps3.h
    backends/platform/sdl/psp2/psp2.cpp
    backends/platform/sdl/psp2/psp2.h
    backends/platform/sdl/riscos/riscos.cpp
    backends/platform/sdl/riscos/riscos.h
    backends/platform/sdl/sdl.cpp
    backends/platform/sdl/sdl.h
    backends/platform/sdl/switch/switch.cpp
    backends/platform/sdl/switch/switch.h
    backends/platform/sdl/win32/win32.cpp
    backends/platform/sdl/win32/win32.h


diff --git a/backends/platform/samsungtv/samsungtv.cpp b/backends/platform/samsungtv/samsungtv.cpp
index a766916..e72b1ee 100644
--- a/backends/platform/samsungtv/samsungtv.cpp
+++ b/backends/platform/samsungtv/samsungtv.cpp
@@ -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
diff --git a/backends/platform/samsungtv/samsungtv.h b/backends/platform/samsungtv/samsungtv.h
index fdd1015..aad946a 100644
--- a/backends/platform/samsungtv/samsungtv.h
+++ b/backends/platform/samsungtv/samsungtv.h
@@ -34,6 +34,9 @@ public:
 	virtual void initBackend();
 	virtual void quit();
 	virtual void fatalError();
+
+protected:
+	virtual Common::String getDefaultLogFileName();
 };
 
 #endif
diff --git a/backends/platform/sdl/macosx/macosx.cpp b/backends/platform/sdl/macosx/macosx.cpp
index ae9203f..3628168 100644
--- a/backends/platform/sdl/macosx/macosx.cpp
+++ b/backends/platform/sdl/macosx/macosx.cpp
@@ -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())
diff --git a/backends/platform/sdl/macosx/macosx.h b/backends/platform/sdl/macosx/macosx.h
index 6f960db..b860b71 100644
--- a/backends/platform/sdl/macosx/macosx.h
+++ b/backends/platform/sdl/macosx/macosx.h
@@ -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();
diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp
index 227f8ef..b204daa 100644
--- a/backends/platform/sdl/posix/posix.cpp
+++ b/backends/platform/sdl/posix/posix.cpp
@@ -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() {
diff --git a/backends/platform/sdl/posix/posix.h b/backends/platform/sdl/posix/posix.h
index fd9bbad..5df6738 100644
--- a/backends/platform/sdl/posix/posix.h
+++ b/backends/platform/sdl/posix/posix.h
@@ -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);
 
diff --git a/backends/platform/sdl/ps3/ps3.cpp b/backends/platform/sdl/ps3/ps3.cpp
index b13088a..78b02d7 100644
--- a/backends/platform/sdl/ps3/ps3.cpp
+++ b/backends/platform/sdl/ps3/ps3.cpp
@@ -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";
 }
diff --git a/backends/platform/sdl/ps3/ps3.h b/backends/platform/sdl/ps3/ps3.h
index d812a13..a0c0d80 100644
--- a/backends/platform/sdl/ps3/ps3.h
+++ b/backends/platform/sdl/ps3/ps3.h
@@ -40,8 +40,7 @@ protected:
 	Common::String _baseConfigName;
 
 	virtual Common::String getDefaultConfigFileName();
-
-	virtual Common::WriteStream *createLogFile();
+	virtual Common::String getDefaultLogFileName();
 };
 
 #endif
diff --git a/backends/platform/sdl/psp2/psp2.cpp b/backends/platform/sdl/psp2/psp2.cpp
index 6919343..5a127b0 100644
--- a/backends/platform/sdl/psp2/psp2.cpp
+++ b/backends/platform/sdl/psp2/psp2.cpp
@@ -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";
 }
diff --git a/backends/platform/sdl/psp2/psp2.h b/backends/platform/sdl/psp2/psp2.h
index db9140e..a90272b 100644
--- a/backends/platform/sdl/psp2/psp2.h
+++ b/backends/platform/sdl/psp2/psp2.h
@@ -47,8 +47,7 @@ protected:
 	Common::String _baseConfigName;
 
 	virtual Common::String getDefaultConfigFileName() override;
-
-	virtual Common::WriteStream *createLogFile() override;
+	virtual Common::String getDefaultLogFileName() override;
 };
 
 #endif
diff --git a/backends/platform/sdl/riscos/riscos.cpp b/backends/platform/sdl/riscos/riscos.cpp
index 3cd9616..a0173ed 100644
--- a/backends/platform/sdl/riscos/riscos.cpp
+++ b/backends/platform/sdl/riscos/riscos.cpp
@@ -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
diff --git a/backends/platform/sdl/riscos/riscos.h b/backends/platform/sdl/riscos/riscos.h
index 49ac5a22..7abeb4f 100644
--- a/backends/platform/sdl/riscos/riscos.h
+++ b/backends/platform/sdl/riscos/riscos.h
@@ -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
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 57f77fd..e4726dc 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -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
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index c746d2d..521e67a 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -94,6 +94,16 @@ protected:
 #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
diff --git a/backends/platform/sdl/switch/switch.cpp b/backends/platform/sdl/switch/switch.cpp
index ef44cb4..85e7b7a 100644
--- a/backends/platform/sdl/switch/switch.cpp
+++ b/backends/platform/sdl/switch/switch.cpp
@@ -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";
 }
diff --git a/backends/platform/sdl/switch/switch.h b/backends/platform/sdl/switch/switch.h
index b9e41e6..61b4f3c 100644
--- a/backends/platform/sdl/switch/switch.h
+++ b/backends/platform/sdl/switch/switch.h
@@ -44,8 +44,7 @@ protected:
 	Common::String _baseConfigName;
 
 	virtual Common::String getDefaultConfigFileName() override;
-
-	virtual Common::WriteStream *createLogFile() override;
+	virtual Common::String getDefaultLogFileName() override;
 };
 
 #endif
diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp
index a116e71..cb65fa8 100644
--- a/backends/platform/sdl/win32/win32.cpp
+++ b/backends/platform/sdl/win32/win32.cpp
@@ -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) {
-		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 {
+	if (SHGetFolderPathFunc(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, logFile) != S_OK) {
 		warning("Unable to access application data directory");
-		return 0;
+		return Common::String();
 	}
+
+	strcat(logFile, "\\ScummVM");
+	CreateDirectory(logFile, NULL);
+	strcat(logFile, "\\Logs");
+	CreateDirectory(logFile, NULL);
+	strcat(logFile, "\\scummvm.log");
+
+	return logFile;
 }
 
 namespace {
diff --git a/backends/platform/sdl/win32/win32.h b/backends/platform/sdl/win32/win32.h
index 9919495..050137f 100644
--- a/backends/platform/sdl/win32/win32.h
+++ b/backends/platform/sdl/win32/win32.h
@@ -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.





More information about the Scummvm-git-logs mailing list