SDL: Move createLogFile implementions to the OSystem_SDL subclasses.

svn-id: r54581
This commit is contained in:
Johannes Schickel 2010-11-29 18:30:23 +00:00
parent 91a6b7f537
commit 39aad6ece7
7 changed files with 93 additions and 95 deletions

View File

@ -36,6 +36,10 @@ public:
virtual void initBackend();
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);
virtual void setupIcon();
private:
// TODO: Implement log file support for Mac OS X
virtual Common::WriteStream *createLogFile() { return 0; }
};
#endif

View File

@ -31,6 +31,9 @@
#include "backends/saves/posix/posix-saves.h"
#include "backends/fs/posix/posix-fs-factory.h"
#include <errno.h>
#include <sys/stat.h>
OSystem_POSIX::OSystem_POSIX(Common::String baseConfigName)
:
_baseConfigName(baseConfigName) {
@ -67,4 +70,52 @@ Common::String OSystem_POSIX::getDefaultConfigFileName() {
return configFile;
}
Common::WriteStream *OSystem_POSIX::createLogFile() {
const char *home = getenv("HOME");
if (home == NULL)
return 0;
Common::String logFile(home);
logFile += "/.scummvm";
struct stat sb;
// Check whether the dir exists
if (stat(logFile.c_str(), &sb) == -1) {
// The dir does not exist, or stat failed for some other reason.
if (errno != ENOENT)
return 0;
// If the problem was that the path pointed to nothing, try
// to create the dir.
if (mkdir(logFile.c_str(), 0755) != 0)
return 0;
} else if (!S_ISDIR(sb.st_mode)) {
// Path is no directory. Oops
return 0;
}
logFile += "/logs";
// Check whether the dir exists
if (stat(logFile.c_str(), &sb) == -1) {
// The dir does not exist, or stat failed for some other reason.
if (errno != ENOENT)
return 0;
// If the problem was that the path pointed to nothing, try
// to create the dir.
if (mkdir(logFile.c_str(), 0755) != 0)
return 0;
} else if (!S_ISDIR(sb.st_mode)) {
// Path is no directory. Oops
return 0;
}
logFile += "/scummvm.log";
Common::FSNode file(logFile);
return file.createWriteStream();
}
#endif

View File

@ -43,6 +43,8 @@ protected:
Common::String _baseConfigName;
virtual Common::String getDefaultConfigFileName();
virtual Common::WriteStream *createLogFile();
};
#endif

View File

@ -47,12 +47,6 @@
#include <time.h> // for getTimeAndDate()
// For logging
#ifdef UNIX
#include <errno.h>
#include <sys/stat.h>
#endif
#ifdef USE_DETECTLANG
#ifndef WIN32
#include <locale.h>
@ -254,94 +248,6 @@ Common::WriteStream *OSystem_SDL::createConfigWriteStream() {
return file.createWriteStream();
}
#define DEFAULT_LOG_FILE "scummvm.log"
Common::WriteStream *OSystem_SDL::createLogFile() {
#if defined(MACOSX)
return 0;
#elif defined(UNIX)
const char *home = getenv("HOME");
if (home == NULL)
return 0;
Common::String logFile(home);
logFile += "/.scummvm";
struct stat sb;
// Check whether the dir exists
if (stat(logFile.c_str(), &sb) == -1) {
// The dir does not exist, or stat failed for some other reason.
if (errno != ENOENT)
return 0;
// If the problem was that the path pointed to nothing, try
// to create the dir.
if (mkdir(logFile.c_str(), 0755) != 0)
return 0;
} else if (!S_ISDIR(sb.st_mode)) {
// Path is no directory. Oops
return 0;
}
logFile += "/logs";
// Check whether the dir exists
if (stat(logFile.c_str(), &sb) == -1) {
// The dir does not exist, or stat failed for some other reason.
if (errno != ENOENT)
return 0;
// If the problem was that the path pointed to nothing, try
// to create the dir.
if (mkdir(logFile.c_str(), 0755) != 0)
return 0;
} else if (!S_ISDIR(sb.st_mode)) {
// Path is no directory. Oops
return 0;
}
logFile += "/" DEFAULT_LOG_FILE;
Common::FSNode file(logFile);
return file.createWriteStream();
#elif defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
char logFile[MAXPATHLEN];
OSVERSIONINFO win32OsVersion;
ZeroMemory(&win32OsVersion, sizeof(OSVERSIONINFO));
win32OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&win32OsVersion);
// Check for non-9X version of Windows.
if (win32OsVersion.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) {
// Use the Application Data directory of the user profile.
if (win32OsVersion.dwMajorVersion >= 5) {
if (!GetEnvironmentVariable("APPDATA", logFile, sizeof(logFile)))
error("Unable to access application data directory");
} else {
if (!GetEnvironmentVariable("USERPROFILE", logFile, sizeof(logFile)))
error("Unable to access user profile directory");
strcat(logFile, "\\Application Data");
CreateDirectory(logFile, NULL);
}
strcat(logFile, "\\ScummVM");
CreateDirectory(logFile, NULL);
strcat(logFile, "\\Logs");
CreateDirectory(logFile, NULL);
strcat(logFile, "\\" DEFAULT_LOG_FILE);
Common::FSNode file(logFile);
return file.createWriteStream();
} else {
return 0;
}
#else
return 0;
#endif
}
void OSystem_SDL::setWindowCaption(const char *caption) {
Common::String cap;
byte c;

View File

@ -113,7 +113,7 @@ protected:
virtual Common::String getDefaultConfigFileName();
// Logging
virtual Common::WriteStream *createLogFile();
virtual Common::WriteStream *createLogFile() { return 0; }
Backends::Log::Log *_logger;
#ifdef USE_OPENGL

View File

@ -134,4 +134,38 @@ Common::String OSystem_Win32::getDefaultConfigFileName() {
return configFile;
}
Common::WriteStream *OSystem_Win32::createLogFile() {
char logFile[MAXPATHLEN];
OSVERSIONINFO win32OsVersion;
ZeroMemory(&win32OsVersion, sizeof(OSVERSIONINFO));
win32OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&win32OsVersion);
// Check for non-9X version of Windows.
if (win32OsVersion.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) {
// Use the Application Data directory of the user profile.
if (win32OsVersion.dwMajorVersion >= 5) {
if (!GetEnvironmentVariable("APPDATA", logFile, sizeof(logFile)))
error("Unable to access application data directory");
} else {
if (!GetEnvironmentVariable("USERPROFILE", logFile, sizeof(logFile)))
error("Unable to access user profile directory");
strcat(logFile, "\\Application Data");
CreateDirectory(logFile, NULL);
}
strcat(logFile, "\\ScummVM");
CreateDirectory(logFile, NULL);
strcat(logFile, "\\Logs");
CreateDirectory(logFile, NULL);
strcat(logFile, "\\scummvm.log");
Common::FSNode file(logFile);
return file.createWriteStream();
} else {
return 0;
}
}
#endif

View File

@ -34,6 +34,7 @@ public:
protected:
virtual Common::String getDefaultConfigFileName();
virtual Common::WriteStream *createLogFile();
};
#endif