1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef LUA_SCUMMVM_FILE_H 24 #define LUA_SCUMMVM_FILE_H 25 26 #include "common/str.h" 27 #include "common/file.h" 28 29 namespace Lua { 30 31 class LuaFileProxy { 32 public: 33 static LuaFileProxy *create(const Common::String &filename, const Common::String &mode); 34 public: ~LuaFileProxy()35 virtual ~LuaFileProxy() {} 36 virtual bool eof() const = 0; 37 virtual size_t read(void *ptr, size_t size, size_t count) = 0; 38 virtual size_t write(const char *ptr, size_t count) = 0; 39 }; 40 41 /** 42 * The following class acts as a proxy interface to the I/O code, pretending that the ScummVM 43 * settings are a properly formatted 'config.lua' file 44 */ 45 class LuaFileConfig : public LuaFileProxy { 46 friend class LuaFileProxy; 47 private: 48 Common::String _readData; 49 uint _readPos; 50 Common::String _settings; 51 52 Common::String formatDouble(double value); 53 void setupConfigFile(); 54 Common::String getLanguage(); 55 void setLanguage(const Common::String &lang); 56 void writeSettings(); 57 void updateSetting(const Common::String &setting, const Common::String &value); 58 59 LuaFileConfig(const Common::String &filename, const Common::String &mode); 60 public: 61 virtual ~LuaFileConfig(); 62 eof()63 virtual bool eof() const override { return _readPos >= _readData.size(); } 64 virtual size_t read(void *ptr, size_t size, size_t count) override; 65 virtual size_t write(const char *ptr, size_t count) override; 66 }; 67 68 class LuaFileRead : public LuaFileProxy { 69 private: 70 Common::File _file; 71 int32 _size; 72 public: 73 LuaFileRead(const Common::String &filename, const Common::String &mode); 74 public: ~LuaFileRead()75 virtual ~LuaFileRead() {} 76 77 virtual bool eof() const override; 78 virtual size_t read(void *ptr, size_t size, size_t count) override; 79 virtual size_t write(const char *ptr, size_t count) override; 80 }; 81 82 } // End of namespace Lua 83 84 #endif 85