mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-22 10:17:22 +00:00
* turned DefaultSaveFileManager::checkPath into a virtual method
* add a subclass of DefaultSaveFileManager for UNIX, POSIXSaveFileManager, which overloads checkPath * switched SDL backend to use POSIXSaveFileManager if UNIX is #defined svn-id: r34872
This commit is contained in:
parent
282ebbb0e5
commit
d0c9b0cb23
@ -30,6 +30,7 @@ MODULE_OBJS := \
|
||||
saves/savefile.o \
|
||||
saves/default/default-saves.o \
|
||||
saves/compressed/compressed-saves.o \
|
||||
saves/posix/posix-saves.o \
|
||||
timer/default/default-timer.o
|
||||
|
||||
# Include common rules
|
||||
|
@ -37,7 +37,11 @@
|
||||
#include "common/events.h"
|
||||
#include "common/util.h"
|
||||
|
||||
#include "backends/saves/default/default-saves.h"
|
||||
#ifdef UNIX
|
||||
#include "backends/saves/posix/posix-saves.h"
|
||||
#else
|
||||
#include "backends/saves/default/default-saves.h"
|
||||
#endif
|
||||
#include "backends/timer/default/default-timer.h"
|
||||
#include "sound/mixer_intern.h"
|
||||
|
||||
@ -150,7 +154,11 @@ void OSystem_SDL::initBackend() {
|
||||
// Create the savefile manager, if none exists yet (we check for this to
|
||||
// allow subclasses to provide their own).
|
||||
if (_savefile == 0) {
|
||||
_savefile = new DefaultSaveFileManager();
|
||||
#ifdef UNIX
|
||||
_savefile = new POSIXSaveFileManager();
|
||||
#else
|
||||
_savefile = new DefaultSaveFileManager();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Create and hook up the mixer, if none exists yet (we check for this to
|
||||
|
@ -25,44 +25,18 @@
|
||||
|
||||
#if !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
|
||||
|
||||
#include "backends/saves/default/default-saves.h"
|
||||
#include "backends/saves/compressed/compressed-saves.h"
|
||||
|
||||
#include "common/savefile.h"
|
||||
#include "common/util.h"
|
||||
#include "common/fs.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "backends/saves/default/default-saves.h"
|
||||
#include "backends/saves/compressed/compressed-saves.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <errno.h> // for removeSavefile()
|
||||
|
||||
#if defined(UNIX)
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#ifdef UNIX
|
||||
#ifdef MACOSX
|
||||
#define DEFAULT_SAVE_PATH "Documents/ScummVM Savegames"
|
||||
#else
|
||||
#define DEFAULT_SAVE_PATH ".scummvm"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
DefaultSaveFileManager::DefaultSaveFileManager() {
|
||||
// Register default savepath
|
||||
// TODO: Remove this code here, and instead leave setting the
|
||||
// default savepath to the ports using this class.
|
||||
#ifdef DEFAULT_SAVE_PATH
|
||||
Common::String savePath;
|
||||
#if defined(UNIX) && !defined(IPHONE)
|
||||
const char *home = getenv("HOME");
|
||||
if (home && *home && strlen(home) < MAXPATHLEN) {
|
||||
savePath = home;
|
||||
savePath += "/" DEFAULT_SAVE_PATH;
|
||||
ConfMan.registerDefault("savepath", savePath);
|
||||
}
|
||||
#endif
|
||||
#endif // #ifdef DEFAULT_SAVE_PATH
|
||||
}
|
||||
|
||||
DefaultSaveFileManager::DefaultSaveFileManager(const Common::String &defaultSavepath) {
|
||||
@ -86,78 +60,12 @@ Common::StringList DefaultSaveFileManager::listSavefiles(const char *pattern) {
|
||||
}
|
||||
|
||||
void DefaultSaveFileManager::checkPath(const Common::FSNode &dir) {
|
||||
const Common::String path = dir.getPath();
|
||||
clearError();
|
||||
|
||||
#if defined(UNIX)
|
||||
struct stat sb;
|
||||
|
||||
// Check whether the dir exists
|
||||
if (stat(path.c_str(), &sb) == -1) {
|
||||
// The dir does not exist, or stat failed for some other reason.
|
||||
// If the problem was that the path pointed to nothing, try
|
||||
// to create the dir (ENOENT case).
|
||||
switch (errno) {
|
||||
case EACCES:
|
||||
setError(SFM_DIR_ACCESS, "Search or write permission denied: "+path);
|
||||
break;
|
||||
case ELOOP:
|
||||
setError(SFM_DIR_LOOP, "Too many symbolic links encountered while traversing the path: "+path);
|
||||
break;
|
||||
case ENAMETOOLONG:
|
||||
setError(SFM_DIR_NAMETOOLONG, "The path name is too long: "+path);
|
||||
break;
|
||||
case ENOENT:
|
||||
if (mkdir(path.c_str(), 0755) != 0) {
|
||||
// mkdir could fail for various reasons: The parent dir doesn't exist,
|
||||
// or is not writeable, the path could be completly bogus, etc.
|
||||
warning("mkdir for '%s' failed!", path.c_str());
|
||||
perror("mkdir");
|
||||
|
||||
switch (errno) {
|
||||
case EACCES:
|
||||
setError(SFM_DIR_ACCESS, "Search or write permission denied: "+path);
|
||||
break;
|
||||
case EMLINK:
|
||||
setError(SFM_DIR_LINKMAX, "The link count of the parent directory would exceed {LINK_MAX}: "+path);
|
||||
break;
|
||||
case ELOOP:
|
||||
setError(SFM_DIR_LOOP, "Too many symbolic links encountered while traversing the path: "+path);
|
||||
break;
|
||||
case ENAMETOOLONG:
|
||||
setError(SFM_DIR_NAMETOOLONG, "The path name is too long: "+path);
|
||||
break;
|
||||
case ENOENT:
|
||||
setError(SFM_DIR_NOENT, "A component of the path does not exist, or the path is an empty string: "+path);
|
||||
break;
|
||||
case ENOTDIR:
|
||||
setError(SFM_DIR_NOTDIR, "A component of the path prefix is not a directory: "+path);
|
||||
break;
|
||||
case EROFS:
|
||||
setError(SFM_DIR_ROFS, "The parent directory resides on a read-only file system:"+path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ENOTDIR:
|
||||
setError(SFM_DIR_NOTDIR, "A component of the path prefix is not a directory: "+path);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// So stat() succeeded. But is the path actually pointing to a directory?
|
||||
if (!S_ISDIR(sb.st_mode)) {
|
||||
setError(SFM_DIR_NOTDIR, "The given savepath is not a directory: "+path);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (!dir.exists()) {
|
||||
// TODO: We could try to mkdir the directory here; or rather, we could
|
||||
// add a mkdir method to FSNode and invoke that here.
|
||||
setError(SFM_DIR_NOENT, "A component of the path does not exist, or the path is an empty string: "+path);
|
||||
setError(SFM_DIR_NOENT, "A component of the path does not exist, or the path is an empty string: "+dir.getPath());
|
||||
} else if (!dir.isDirectory()) {
|
||||
setError(SFM_DIR_NOTDIR, "The given savepath is not a directory: "+path);
|
||||
setError(SFM_DIR_NOTDIR, "The given savepath is not a directory: "+dir.getPath());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename) {
|
||||
|
@ -26,6 +26,7 @@
|
||||
#if !defined(BACKEND_SAVES_DEFAULT_H) && !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
|
||||
#define BACKEND_SAVES_DEFAULT_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "common/savefile.h"
|
||||
#include "common/str.h"
|
||||
#include "common/fs.h"
|
||||
@ -55,7 +56,7 @@ protected:
|
||||
* Checks the given path for read access, existence, etc.
|
||||
* Sets the internal error and error message accordingly.
|
||||
*/
|
||||
void checkPath(const Common::FSNode &dir);
|
||||
virtual void checkPath(const Common::FSNode &dir);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
128
backends/saves/posix/posix-saves.cpp
Normal file
128
backends/saves/posix/posix-saves.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* $URL$
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(UNIX) && !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
|
||||
|
||||
#include "backends/saves/posix/posix-saves.h"
|
||||
|
||||
#include "common/config-manager.h"
|
||||
#include "common/savefile.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
#ifdef MACOSX
|
||||
#define DEFAULT_SAVE_PATH "Documents/ScummVM Savegames"
|
||||
#else
|
||||
#define DEFAULT_SAVE_PATH ".scummvm"
|
||||
#endif
|
||||
|
||||
POSIXSaveFileManager::POSIXSaveFileManager() {
|
||||
// Register default savepath based on HOME
|
||||
Common::String savePath;
|
||||
const char *home = getenv("HOME");
|
||||
if (home && *home && strlen(home) < MAXPATHLEN) {
|
||||
savePath = home;
|
||||
savePath += "/" DEFAULT_SAVE_PATH;
|
||||
ConfMan.registerDefault("savepath", savePath);
|
||||
}
|
||||
}
|
||||
/*
|
||||
POSIXSaveFileManager::POSIXSaveFileManager(const Common::String &defaultSavepath)
|
||||
: DefaultSaveFileManager(defaultSavepath) {
|
||||
}
|
||||
*/
|
||||
|
||||
#if defined(UNIX)
|
||||
void POSIXSaveFileManager::checkPath(const Common::FSNode &dir) {
|
||||
const Common::String path = dir.getPath();
|
||||
clearError();
|
||||
|
||||
struct stat sb;
|
||||
|
||||
// Check whether the dir exists
|
||||
if (stat(path.c_str(), &sb) == -1) {
|
||||
// The dir does not exist, or stat failed for some other reason.
|
||||
// If the problem was that the path pointed to nothing, try
|
||||
// to create the dir (ENOENT case).
|
||||
switch (errno) {
|
||||
case EACCES:
|
||||
setError(SFM_DIR_ACCESS, "Search or write permission denied: "+path);
|
||||
break;
|
||||
case ELOOP:
|
||||
setError(SFM_DIR_LOOP, "Too many symbolic links encountered while traversing the path: "+path);
|
||||
break;
|
||||
case ENAMETOOLONG:
|
||||
setError(SFM_DIR_NAMETOOLONG, "The path name is too long: "+path);
|
||||
break;
|
||||
case ENOENT:
|
||||
if (mkdir(path.c_str(), 0755) != 0) {
|
||||
// mkdir could fail for various reasons: The parent dir doesn't exist,
|
||||
// or is not writeable, the path could be completly bogus, etc.
|
||||
warning("mkdir for '%s' failed!", path.c_str());
|
||||
perror("mkdir");
|
||||
|
||||
switch (errno) {
|
||||
case EACCES:
|
||||
setError(SFM_DIR_ACCESS, "Search or write permission denied: "+path);
|
||||
break;
|
||||
case EMLINK:
|
||||
setError(SFM_DIR_LINKMAX, "The link count of the parent directory would exceed {LINK_MAX}: "+path);
|
||||
break;
|
||||
case ELOOP:
|
||||
setError(SFM_DIR_LOOP, "Too many symbolic links encountered while traversing the path: "+path);
|
||||
break;
|
||||
case ENAMETOOLONG:
|
||||
setError(SFM_DIR_NAMETOOLONG, "The path name is too long: "+path);
|
||||
break;
|
||||
case ENOENT:
|
||||
setError(SFM_DIR_NOENT, "A component of the path does not exist, or the path is an empty string: "+path);
|
||||
break;
|
||||
case ENOTDIR:
|
||||
setError(SFM_DIR_NOTDIR, "A component of the path prefix is not a directory: "+path);
|
||||
break;
|
||||
case EROFS:
|
||||
setError(SFM_DIR_ROFS, "The parent directory resides on a read-only file system:"+path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ENOTDIR:
|
||||
setError(SFM_DIR_NOTDIR, "A component of the path prefix is not a directory: "+path);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// So stat() succeeded. But is the path actually pointing to a directory?
|
||||
if (!S_ISDIR(sb.st_mode)) {
|
||||
setError(SFM_DIR_NOTDIR, "The given savepath is not a directory: "+path);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
53
backends/saves/posix/posix-saves.h
Normal file
53
backends/saves/posix/posix-saves.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* $URL$
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(BACKEND_POSIX_SAVES_H) && !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
|
||||
#define BACKEND_POSIX_SAVES_H
|
||||
|
||||
#include "backends/saves/default/default-saves.h"
|
||||
|
||||
#if defined(UNIX)
|
||||
/**
|
||||
* Customization of the DefaultSaveFileManager for POSIX platforms.
|
||||
* The only two differences are that the default constructor sets
|
||||
* up the savepath based on HOME, and that checkPath tries to
|
||||
* create the savedir, if missing, via the mkdir() syscall.
|
||||
*/
|
||||
class POSIXSaveFileManager : public DefaultSaveFileManager {
|
||||
public:
|
||||
POSIXSaveFileManager();
|
||||
// POSIXSaveFileManager(const Common::String &defaultSavepath);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Checks the given path for read access, existence, etc.
|
||||
* In addition, tries to create a missing savedir, if possible.
|
||||
* Sets the internal error and error message accordingly.
|
||||
*/
|
||||
virtual void checkPath(const Common::FSNode &dir);
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user