From 2ac075e5692f45b2ca3a3ceac98e3bba290a45a0 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Wed, 31 Oct 2007 13:59:59 +0000 Subject: Removed the Common::File::removeFile() methods, and moved their implementation to the Common::DefaultSaveFileManager::removeSavefile() method, as per Marcus' appraisal and Max's approval. svn-id: r29337 --- backends/saves/default/default-saves.cpp | 19 +++++++++++++------ common/file.cpp | 30 ------------------------------ common/file.h | 3 --- 3 files changed, 13 insertions(+), 39 deletions(-) diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp index d2e01b420a..b47a9e24f6 100644 --- a/backends/saves/default/default-saves.cpp +++ b/backends/saves/default/default-saves.cpp @@ -120,7 +120,7 @@ Common::StringList DefaultSaveFileManager::listSavefiles(const char *regex) { Common::String search(regex); if (savePath.lookupFile(savefiles, search, false, true)) { - for (FSList::const_iterator file = savefiles.begin(); file != savefiles.end(); file++) { + for (FSList::const_iterator file = savefiles.begin(); file != savefiles.end(); ++file) { results.push_back(file->getPath()); } } @@ -219,7 +219,6 @@ Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename) } #endif - join_paths(filename, savePath, buf, sizeof(buf)); StdioSaveFile *sf = new StdioSaveFile(buf, true); @@ -235,10 +234,18 @@ Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename) bool DefaultSaveFileManager::removeSavefile(const char *filename) { char buf[256]; join_paths(filename, getSavePath(), buf, sizeof(buf)); - - Common::File file; - FilesystemNode savePath((const char *)buf); - return file.removeFile(savePath); + + if (remove(buf) != 0) { + if (errno == EACCES) + setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied")); + + if (errno == ENOENT) + setError(SFM_DIR_NOENT, Common::String("A component of the path path does not exist, or the path is an empty string")); + + return false; + } else { + return true; + } } #endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER) diff --git a/common/file.cpp b/common/file.cpp index 40f1a296f3..2c08753696 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -423,36 +423,6 @@ bool File::open(const FilesystemNode &node, AccessMode mode) { return true; } -bool File::removeFile(const String &filename){ - if (remove(filename.c_str()) != 0) { - if (errno == EACCES) { - //TODO: read-only file - } - if (errno == ENOENT) { - //TODO: non-existent file - } - - return false; - } else { - return true; - } -} - -bool File::removeFile(const FilesystemNode &node){ - if (remove(node.getPath().c_str()) != 0) { - if (errno == EACCES) { - //TODO: read-only file - } - if (errno == ENOENT) { - //TODO: non-existent file - } - - return false; - } else { - return true; - } -} - bool File::exists(const String &filename) { FilesystemNode* file; String fname = filename; diff --git a/common/file.h b/common/file.h index d966d95f2d..25c51a0afe 100644 --- a/common/file.h +++ b/common/file.h @@ -85,9 +85,6 @@ public: virtual void close(); - virtual bool removeFile(const String &filename); - virtual bool removeFile(const FilesystemNode &node); - /** * Checks if the object opened a file successfully. * -- cgit v1.2.3