aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_inventory.cpp
Commit message (Expand)AuthorAge
* Use "core" namespace internallyShadowNinja2014-05-08
* Only push the Lua error handler onceShadowNinja2014-04-27
* Add more informative error messages for inventory and item method errorsShadowNinja2014-03-15
* Remove lua_State parameter from LuaError::LuaErrorShadowNinja2014-03-15
* Revert "Make sure we get a stacktrace for as many lua errors as possible"ShadowNinja2014-03-15
* Make sure we get a stacktrace for as many lua errors as possibleSfan52014-03-15
* Correct misleading detached inventory error messageCiaran Gultnieks2014-03-09
* Handle LuaErrors in Lua -> C++ calls on LuaJITShadowNinja2013-12-18
* Pass a errfunc to lua_pcall to get a tracebackShadowNinja2013-11-15
* Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenuKahrl2013-08-14
* Move scriptapi to separate folder (by sapier)sapier2013-05-25
dation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "filecache.h" #include "network/networkprotocol.h" #include "log.h" #include "filesys.h" #include <string> #include <iostream> #include <fstream> #include <stdlib.h> bool FileCache::loadByPath(const std::string &path, std::ostream &os) { std::ifstream fis(path.c_str(), std::ios_base::binary); if(!fis.good()){ verbosestream<<"FileCache: File not found in cache: " <<path<<std::endl; return false; } bool bad = false; for(;;){ char buf[1024]; fis.read(buf, 1024); std::streamsize len = fis.gcount(); os.write(buf, len); if(fis.eof()) break; if(!fis.good()){ bad = true; break; } } if(bad){ errorstream<<"FileCache: Failed to read file from cache: \"" <<path<<"\""<<std::endl; } return !bad; } bool FileCache::updateByPath(const std::string &path, const std::string &data) { std::ofstream file(path.c_str(), std::ios_base::binary | std::ios_base::trunc); if(!file.good()) { errorstream<<"FileCache: Can't write to file at " <<path<<std::endl; return false; } file.write(data.c_str(), data.length()); file.close(); return !file.fail(); } bool FileCache::update(const std::string &name, const std::string &data) { std::string path = m_dir + DIR_DELIM + name; return updateByPath(path, data); } bool FileCache::load(const std::string &name, std::ostream &os) { std::string path = m_dir + DIR_DELIM + name; return loadByPath(path, os); }