SDL: Move createLogFile implementions to the OSystem_SDL subclasses.
svn-id: r54581
This commit is contained in:
parent
91a6b7f537
commit
39aad6ece7
7 changed files with 93 additions and 95 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue