wrapper for ifstream/ofstream

git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@150 4df4b0f3-56ce-47cb-b001-ed939b7d65a6
This commit is contained in:
albertzeyer
2009-07-24 15:42:10 +00:00
parent 742176416b
commit 1ca3522656
3 changed files with 29 additions and 18 deletions

View File

@@ -23,6 +23,7 @@
#pragma warning(disable: 4503) // WARNING: decorated name length exceeded, name was truncated
#endif
#include <fstream>
#include "FindFile.h"
#include "StringUtils.h"
#include "Debug.h"
@@ -647,30 +648,37 @@ FILE *OpenGameFile(const std::string& path, const char *mode) {
}
std::ifstream* OpenGameFileR(const std::string& path) {
// TODO: unicode support! (?)
bool OpenGameFileR(std::ifstream& f, const std::string& path, std::ios_base::openmode mode) {
if(path.size() == 0)
return NULL;
return false;
std::string fullfn = GetFullFileName(path);
if(fullfn.size() != 0) {
try {
std::ifstream* f = new std::ifstream(fullfn.c_str(), std::ios::in | std::ios::binary);
if (f->is_open())
return f;
else {
delete f;
return NULL;
}
f.open(Utf8ToSystemNative(fullfn).c_str(), mode);
return f.is_open();
} catch(...) {}
return NULL;
return false;
}
return NULL;
return false;
}
bool OpenGameFileW(std::ofstream& f, const std::string& path, std::ios_base::openmode mode) {
if(path.size() == 0)
return false;
std::string fullfn = GetWriteFullFileName(path, true);
if(fullfn.size() != 0) {
try {
f.open(Utf8ToSystemNative(fullfn).c_str(), mode);
return f.is_open();
} catch(...) {}
return false;
}
return false;
}
void AddToFileList(searchpathlist* l, const std::string& f) {

View File

@@ -20,7 +20,7 @@
#ifndef __FINDFILE_H__
#define __FINDFILE_H__
#include <fstream>
#include <iomanip>
#include <string>
#include <list>
#include <vector>
@@ -80,9 +80,10 @@ extern std::string binary_dir;
#endif
class drive_t { public:
struct drive_t {
std::string name;
unsigned int type;
drive_t() : type(0) {}
};
typedef std::vector<drive_t> drive_list;
@@ -183,7 +184,9 @@ FILE* OpenGameFile(const std::string& path, const char *mode);
FILE* OpenAbsFile(const std::string& path, const char *mode);
std::ifstream* OpenGameFileR(const std::string& path);
bool OpenGameFileR(std::ifstream& f, const std::string& path, std::ios_base::openmode mode = std::ios_base::in);
bool OpenGameFileW(std::ofstream& f, const std::string& path, std::ios_base::openmode mode = std::ios_base::in);
std::string GetFileContents(const std::string& path, bool absolute = false);
std::string ExtractDirectory(const std::string& path);

View File

@@ -374,7 +374,7 @@ char CHighScores::loadHighScoreTable(void)
sBuf.append(chBuf);
sBuf.append(".dat");
ifstream ScoreTableFile (sBuf.data(), ios::binary);
ifstream ScoreTableFile (sBuf.c_str(), ios::binary);
if(ScoreTableFile == NULL)
{