summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-06-14 23:23:30 +0300
committerAndrei Karas <akaras@inbox.ru>2011-06-14 23:36:38 +0300
commitbf9bccc30a186e338f96c230a4f63cc924c77bd8 (patch)
treee46dbc2f022842982d89164ee598e1bcf827aa39 /src/resources
parentfb0f86589ae9e2d582383cea43e0a391e8d4739d (diff)
downloadmv-bf9bccc30a186e338f96c230a4f63cc924c77bd8.tar.gz
mv-bf9bccc30a186e338f96c230a4f63cc924c77bd8.tar.bz2
mv-bf9bccc30a186e338f96c230a4f63cc924c77bd8.tar.xz
mv-bf9bccc30a186e338f96c230a4f63cc924c77bd8.zip
Add ability to add comments to any players.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/resourcemanager.cpp51
-rw-r--r--src/resources/resourcemanager.h17
2 files changed, 67 insertions, 1 deletions
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 <physfs.h>
#include <SDL_image.h>
#include <cassert>
+#include <fstream>
+#include <iostream>
#include <sstream>
+#include <sys/stat.h>
#include <sys/time.h>
#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<std::string> ResourceManager::loadTextFile(
return lines;
}
+std::vector<std::string> ResourceManager::loadTextFileLocal(
+ const std::string &fileName)
+{
+ std::ifstream file;
+ char line[501];
+ std::vector<std::string> 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;
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 71cbdce62..0b73a796e 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -103,10 +103,16 @@ class ResourceManager
/**
* Checks whether the given file or directory exists in the search path
+ * (PhysFS)
*/
bool exists(const std::string &path);
/**
+ * Checks whether the given file or directory exists
+ */
+ bool existsLocal(const std::string &path);
+
+ /**
* Checks whether the given path is a directory.
*/
bool isDirectory(const std::string &path);
@@ -209,11 +215,20 @@ class ResourceManager
void *loadFile(const std::string &fileName, int &fileSize);
/**
- * Retrieves the contents of a text file.
+ * Retrieves the contents of a text file (PhysFS).
*/
std::vector<std::string> loadTextFile(const std::string &fileName);
/**
+ * Retrieves the contents of a text file.
+ */
+ std::vector<std::string> loadTextFileLocal(const std::string
+ &fileName);
+
+ void saveTextFile(std::string path, std::string name,
+ std::string text);
+
+ /**
* Loads the given filename as an SDL surface. The returned surface is
* expected to be freed by the caller using SDL_FreeSurface.
*/