From bf9bccc30a186e338f96c230a4f63cc924c77bd8 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 14 Jun 2011 23:23:30 +0300 Subject: Add ability to add comments to any players. --- src/resources/resourcemanager.cpp | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src/resources/resourcemanager.cpp') diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index aea598935..96902cb4c 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -34,11 +34,16 @@ #include "resources/soundeffect.h" #include "resources/spritedef.h" +#include "utils/mkdir.h" + #include #include #include +#include +#include #include +#include #include #include "debug.h" @@ -299,6 +304,17 @@ bool ResourceManager::exists(const std::string &path) return PHYSFS_exists(path.c_str()); } +bool ResourceManager::existsLocal(const std::string &path) +{ + bool flg(false); + std::fstream file; + file.open(path.c_str(), std::ios::in); + if (file.is_open()) + flg = true; + file.close(); + return flg; +} + bool ResourceManager::isDirectory(const std::string &path) { return PHYSFS_isDirectory(path.c_str()); @@ -644,6 +660,41 @@ std::vector ResourceManager::loadTextFile( return lines; } +std::vector ResourceManager::loadTextFileLocal( + const std::string &fileName) +{ + std::ifstream file; + char line[501]; + std::vector lines; + + file.open(fileName.c_str(), std::ios::in); + + if (!file.is_open()) + { + logger->log("Couldn't load text file: %s", fileName.c_str()); + return lines; + } + + while (file.getline(line, 500)) + lines.push_back(line); + + return lines; +} + +void ResourceManager::saveTextFile(std::string path, std::string name, + std::string text) +{ + if (!mkdir_r(path.c_str())) + { + std::ofstream file; + std::string fileName = path + "/" + name; + + file.open(fileName.c_str(), std::ios::out); + file << text << std::endl; + file.close(); + } +} + SDL_Surface *ResourceManager::loadSDLSurface(const std::string &filename) { int fileSize; -- cgit v1.2.3-60-g2f50