diff options
| author | Travis Howell | 2006-05-02 03:23:03 +0000 |
|---|---|---|
| committer | Travis Howell | 2006-05-02 03:23:03 +0000 |
| commit | 01c92cf6f5efbfe36c48f9d00122c93cc4f5d2cd (patch) | |
| tree | 2357149f0f0bbd6d77665c6e716830d3d3c19536 /common | |
| parent | 84b2a4f76fed5848b8a4ff49fd2fcfd9604a0c92 (diff) | |
| download | scummvm-rg350-01c92cf6f5efbfe36c48f9d00122c93cc4f5d2cd.tar.gz scummvm-rg350-01c92cf6f5efbfe36c48f9d00122c93cc4f5d2cd.tar.bz2 scummvm-rg350-01c92cf6f5efbfe36c48f9d00122c93cc4f5d2cd.zip | |
Add support for reading/writing config files through saveGameManager and use for config files in HE games
svn-id: r22273
Diffstat (limited to 'common')
| -rw-r--r-- | common/config-file.cpp | 27 | ||||
| -rw-r--r-- | common/config-file.h | 2 |
2 files changed, 29 insertions, 0 deletions
diff --git a/common/config-file.cpp b/common/config-file.cpp index 5d01e4402d..af991b931d 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -24,6 +24,8 @@ #include "common/config-file.h" #include "common/file.h" +#include "common/savefile.h" +#include "common/system.h" #include "common/util.h" #define MAXLINELEN 256 @@ -74,6 +76,18 @@ bool ConfigFile::loadFromFile(const String &filename) { return false; } +bool ConfigFile::loadFromSaveFile(const char *filename) { + SaveFileManager *saveFileMan = g_system->getSavefileManager(); + SeekableReadStream *loadFile; + + if (!(loadFile = saveFileMan->openForLoading(filename))) + return false; + + bool status = loadFromStream(*loadFile); + delete loadFile; + return status; +} + bool ConfigFile::loadFromStream(SeekableReadStream &stream) { char buf[MAXLINELEN]; Section section; @@ -176,6 +190,18 @@ bool ConfigFile::saveToFile(const String &filename) { return false; } +bool ConfigFile::saveToSaveFile(const char *filename) { + SaveFileManager *saveFileMan = g_system->getSavefileManager(); + WriteStream *saveFile; + + if (!(saveFile = saveFileMan->openForSaving(filename))) + return false; + + bool status = saveToStream(*saveFile); + delete saveFile; + return status; +} + bool ConfigFile::saveToStream(WriteStream &stream) { for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) { // Write out the section comment, if any @@ -203,6 +229,7 @@ bool ConfigFile::saveToStream(WriteStream &stream) { } } + stream.flush(); return !stream.ioFailed(); } diff --git a/common/config-file.h b/common/config-file.h index a7588a049d..2e1e80ed10 100644 --- a/common/config-file.h +++ b/common/config-file.h @@ -99,8 +99,10 @@ public: void clear(); bool loadFromFile(const String &filename); + bool loadFromSaveFile(const char *filename); bool loadFromStream(SeekableReadStream &stream); bool saveToFile(const String &filename); + bool saveToSaveFile(const char *filename); bool saveToStream(WriteStream &stream); bool hasSection(const String §ion) const; |
