Updated JFileSystem implementation to be compatible with Qt resources.
This commit is contained in:
+38
-12
@@ -1,6 +1,10 @@
|
|||||||
#ifndef _J_FILE_SYSTEM_H_
|
#ifndef _J_FILE_SYSTEM_H_
|
||||||
#define _J_FILE_SYSTEM_H_
|
#define _J_FILE_SYSTEM_H_
|
||||||
|
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
#include <QFile>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "zfsystem.h"
|
#include "zfsystem.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
using zip_file_system::filesystem;
|
using zip_file_system::filesystem;
|
||||||
@@ -18,13 +22,38 @@ using namespace std;
|
|||||||
/// archive file.
|
/// archive file.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
class JFile {
|
||||||
|
friend class JFileSystem;
|
||||||
|
filesystem::limited_file_info * mCurrentFileInZip;
|
||||||
|
izfstream mFile;
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
QFile *mpqFile;
|
||||||
|
#endif
|
||||||
|
public:
|
||||||
|
JFile() : mCurrentFileInZip(0),
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
mpqFile(0)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
};
|
||||||
|
~JFile() {
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
if(mpqFile) {
|
||||||
|
mpqFile->close();
|
||||||
|
delete mpqFile;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (mFile)
|
||||||
|
mFile.close();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class JZipCache {
|
class JZipCache {
|
||||||
public:
|
public:
|
||||||
JZipCache();
|
JZipCache();
|
||||||
~JZipCache();
|
~JZipCache();
|
||||||
map<string, filesystem::limited_file_info> dir;
|
map<string, filesystem::limited_file_info> dir;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class JFileSystem {
|
class JFileSystem {
|
||||||
@@ -32,23 +61,21 @@ private:
|
|||||||
string mSystemFSPath, mUserFSPath;
|
string mSystemFSPath, mUserFSPath;
|
||||||
filesystem * mSystemFS, * mUserFS;
|
filesystem * mSystemFS, * mUserFS;
|
||||||
static JFileSystem* mInstance;
|
static JFileSystem* mInstance;
|
||||||
izfstream mFile;
|
|
||||||
|
|
||||||
map<string,JZipCache *>mZipCache;
|
map<string,JZipCache *>mZipCache;
|
||||||
unsigned int mZipCachedElementsCount;
|
unsigned int mZipCachedElementsCount;
|
||||||
string mZipFileName;
|
string mZipFileName;
|
||||||
int mFileSize;
|
|
||||||
char *mPassword;
|
char *mPassword;
|
||||||
bool mZipAvailable;
|
bool mZipAvailable;
|
||||||
void preloadZip(const string& filename);
|
void preloadZip(const string& filename);
|
||||||
izfstream mZipFile;
|
izfstream mZipFile;
|
||||||
filesystem::limited_file_info * mCurrentFileInZip;
|
|
||||||
|
|
||||||
std::vector<std::string>& scanRealFolder(const std::string& folderName, std::vector<std::string>& results);
|
std::vector<std::string>& scanRealFolder(const std::string& folderName, std::vector<std::string>& results);
|
||||||
|
bool openForRead(izfstream & File, const string & FilePath);
|
||||||
|
int GetFileSize(izfstream & file);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Attach ZIP archive to the file system.
|
/// Attach ZIP archive to the file system.
|
||||||
///
|
///
|
||||||
@@ -83,7 +110,7 @@ public:
|
|||||||
/// Open file for reading.
|
/// Open file for reading.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool OpenFile(const string &filename);
|
JFile* OpenFile(const string &filename);
|
||||||
|
|
||||||
//Fills the vector results with a list of children of the given folder
|
//Fills the vector results with a list of children of the given folder
|
||||||
std::vector<std::string>& scanfolder(const std::string& folderName, std::vector<std::string>& results);
|
std::vector<std::string>& scanfolder(const std::string& folderName, std::vector<std::string>& results);
|
||||||
@@ -97,20 +124,19 @@ public:
|
|||||||
/// @return Number of bytes read.
|
/// @return Number of bytes read.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int ReadFile(void *buffer, int size);
|
int ReadFile(JFile*, void *buffer, int size);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get size of file.
|
/// Get size of file.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int GetFileSize();
|
int GetFileSize(JFile*);
|
||||||
int GetFileSize(izfstream & file);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Close file.
|
/// Close file.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void CloseFile();
|
void CloseFile(JFile*);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set root for all the following file operations
|
/// Set root for all the following file operations
|
||||||
@@ -124,8 +150,8 @@ public:
|
|||||||
void SetUSerRoot(const string& resourceRoot);
|
void SetUSerRoot(const string& resourceRoot);
|
||||||
string GetUserRoot() { return mUserFSPath; };
|
string GetUserRoot() { return mUserFSPath; };
|
||||||
|
|
||||||
bool openForRead(izfstream & File, const string & FilePath);
|
|
||||||
bool readIntoString(const string & FilePath, string & target);
|
bool readIntoString(const string & FilePath, string & target);
|
||||||
|
bool ReadFileLine(JFile*, string&);
|
||||||
bool openForWrite(ofstream & File, const string & FilePath, ios_base::openmode mode = ios_base::out );
|
bool openForWrite(ofstream & File, const string & FilePath, ios_base::openmode mode = ios_base::out );
|
||||||
bool Rename(string from, string to);
|
bool Rename(string from, string to);
|
||||||
|
|
||||||
@@ -163,4 +189,4 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -178,7 +178,6 @@ private:
|
|||||||
float mSpacing;
|
float mSpacing;
|
||||||
|
|
||||||
PIXEL_TYPE mColor;
|
PIXEL_TYPE mColor;
|
||||||
int mBlend;
|
|
||||||
|
|
||||||
int mBase;
|
int mBase;
|
||||||
|
|
||||||
|
|||||||
@@ -44,11 +44,12 @@ bool JAnimator::Load(const char* scriptFile)
|
|||||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||||
if (fileSystem == NULL) return false;
|
if (fileSystem == NULL) return false;
|
||||||
|
|
||||||
if (!fileSystem->OpenFile(scriptFile)) return false;
|
JFile* jFile = fileSystem->OpenFile(scriptFile);
|
||||||
|
if (!jFile) return false;
|
||||||
|
|
||||||
int size = fileSystem->GetFileSize();
|
int size = fileSystem->GetFileSize(jFile);
|
||||||
char *xmlBuffer = new char[size];
|
char *xmlBuffer = new char[size];
|
||||||
fileSystem->ReadFile(xmlBuffer, size);
|
fileSystem->ReadFile(jFile, xmlBuffer, size);
|
||||||
|
|
||||||
TiXmlDocument doc;
|
TiXmlDocument doc;
|
||||||
doc.Parse(xmlBuffer);
|
doc.Parse(xmlBuffer);
|
||||||
@@ -173,7 +174,7 @@ bool JAnimator::Load(const char* scriptFile)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile(jFile);
|
||||||
delete[] xmlBuffer;
|
delete[] xmlBuffer;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+164
-71
@@ -107,7 +107,6 @@ JFileSystem* JFileSystem::GetInstance()
|
|||||||
// Tries to set the system and user paths.
|
// Tries to set the system and user paths.
|
||||||
// On some OSes, the parameters get overriden by hardcoded values
|
// On some OSes, the parameters get overriden by hardcoded values
|
||||||
JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
|
JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
|
||||||
|
|
||||||
{
|
{
|
||||||
string systemPath = _systemPath;
|
string systemPath = _systemPath;
|
||||||
string userPath = _userPath;
|
string userPath = _userPath;
|
||||||
@@ -131,8 +130,8 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
|
|||||||
dir.mkdir(USERDIR);
|
dir.mkdir(USERDIR);
|
||||||
dir.cd(USERDIR);
|
dir.cd(USERDIR);
|
||||||
|
|
||||||
userPath = QDir::toNativeSeparators(dir.absolutePath()).toStdString();
|
|
||||||
systemPath = QDir::toNativeSeparators(sysDir.absolutePath()).toStdString();
|
systemPath = QDir::toNativeSeparators(sysDir.absolutePath()).toStdString();
|
||||||
|
userPath = QDir::toNativeSeparators(dir.absolutePath()).toStdString();
|
||||||
|
|
||||||
DebugTrace("User path " << userPath);
|
DebugTrace("User path " << userPath);
|
||||||
DebugTrace("System path " << systemPath);
|
DebugTrace("System path " << systemPath);
|
||||||
@@ -192,9 +191,6 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
|
|||||||
mZipAvailable = false;
|
mZipAvailable = false;
|
||||||
mZipCachedElementsCount = 0;
|
mZipCachedElementsCount = 0;
|
||||||
mPassword = NULL;
|
mPassword = NULL;
|
||||||
mFileSize = 0;
|
|
||||||
mCurrentFileInZip = NULL;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void JFileSystem::Destroy()
|
void JFileSystem::Destroy()
|
||||||
@@ -208,14 +204,26 @@ void JFileSystem::Destroy()
|
|||||||
|
|
||||||
bool JFileSystem::DirExists(const string& strDirname)
|
bool JFileSystem::DirExists(const string& strDirname)
|
||||||
{
|
{
|
||||||
return (mSystemFS && mSystemFS->DirExists(strDirname)) || mUserFS->DirExists(strDirname);
|
return (
|
||||||
|
(mSystemFS && mSystemFS->DirExists(strDirname))
|
||||||
|
|| mUserFS->DirExists(strDirname)
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
|| QDir(QString(":/") + strDirname.c_str()).exists()
|
||||||
|
#endif
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JFileSystem::FileExists(const string& strFilename)
|
bool JFileSystem::FileExists(const string& strFilename)
|
||||||
{
|
{
|
||||||
if (strFilename.length() < 1 ) return false;
|
if (strFilename.length() < 1 ) return false;
|
||||||
|
|
||||||
return (mSystemFS && mSystemFS->FileExists(strFilename)) || mUserFS->FileExists(strFilename);
|
return (
|
||||||
|
(mSystemFS && mSystemFS->FileExists(strFilename))
|
||||||
|
|| mUserFS->FileExists(strFilename)
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
|| QFile(QString(":/") + strFilename.c_str()).exists()
|
||||||
|
#endif
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JFileSystem::MakeDir(const string & dir)
|
bool JFileSystem::MakeDir(const string & dir)
|
||||||
@@ -275,7 +283,6 @@ bool JFileSystem::AttachZipFile(const string &zipfile, char *password /* = NULL
|
|||||||
}
|
}
|
||||||
mZipAvailable = true;
|
mZipAvailable = true;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -285,7 +292,6 @@ void JFileSystem::DetachZipFile()
|
|||||||
{
|
{
|
||||||
mZipFile.close();
|
mZipFile.close();
|
||||||
}
|
}
|
||||||
mCurrentFileInZip = NULL;
|
|
||||||
mZipAvailable = false;
|
mZipAvailable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,28 +313,58 @@ bool JFileSystem::openForRead(izfstream & File, const string & FilePath) {
|
|||||||
|
|
||||||
bool JFileSystem::readIntoString(const string & FilePath, string & target)
|
bool JFileSystem::readIntoString(const string & FilePath, string & target)
|
||||||
{
|
{
|
||||||
izfstream file;
|
bool result = false;
|
||||||
if (!openForRead(file, FilePath))
|
|
||||||
return false;
|
// Trying first with a izfstream
|
||||||
|
do {
|
||||||
int fileSize = GetFileSize(file);
|
izfstream file;
|
||||||
|
if (!openForRead(file, FilePath))
|
||||||
|
break;
|
||||||
|
|
||||||
|
int fileSize = GetFileSize(file);
|
||||||
|
|
||||||
#ifndef __MINGW32__
|
#ifndef __MINGW32__
|
||||||
try {
|
try {
|
||||||
#endif
|
#endif
|
||||||
target.resize((std::string::size_type) fileSize);
|
target.resize((std::string::size_type) fileSize);
|
||||||
#ifndef __MINGW32__
|
#ifndef __MINGW32__
|
||||||
} catch (bad_alloc&) {
|
} catch (bad_alloc&) {
|
||||||
return false;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (fileSize)
|
||||||
|
file.read(&target[0], fileSize);
|
||||||
if (fileSize)
|
|
||||||
file.read(&target[0], fileSize);
|
file.close();
|
||||||
|
result = true;
|
||||||
file.close();
|
} while (0);
|
||||||
return true;
|
#ifdef QT_CONFIG
|
||||||
|
// Now we try with qrc if we haven't finc anything yet
|
||||||
|
if (!result) do {
|
||||||
|
string path = string(":/") + FilePath.c_str();
|
||||||
|
QFile qfile(path.c_str());
|
||||||
|
qfile.open(QIODevice::ReadOnly);
|
||||||
|
if(!qfile.isReadable())
|
||||||
|
break;
|
||||||
|
int fileSize = qfile.size();
|
||||||
|
#ifndef __MINGW32__
|
||||||
|
try {
|
||||||
|
#endif
|
||||||
|
target.resize((std::string::size_type) fileSize);
|
||||||
|
#ifndef __MINGW32__
|
||||||
|
} catch (bad_alloc&) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (fileSize)
|
||||||
|
qfile.read(&target[0], fileSize);
|
||||||
|
|
||||||
|
qfile.close();
|
||||||
|
result = true;
|
||||||
|
} while (0);
|
||||||
|
#endif //QT_CONFIG
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JFileSystem::openForWrite(ofstream & File, const string & FilePath, ios_base::openmode mode)
|
bool JFileSystem::openForWrite(ofstream & File, const string & FilePath, ios_base::openmode mode)
|
||||||
@@ -374,57 +410,72 @@ bool JFileSystem::openForWrite(ofstream & File, const string & FilePath, ios_bas
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JFileSystem::OpenFile(const string &filename)
|
JFile* JFileSystem::OpenFile(const string &filename)
|
||||||
{
|
{
|
||||||
mCurrentFileInZip = NULL;
|
bool result;
|
||||||
|
JFile* jFile = new JFile();
|
||||||
|
jFile->mCurrentFileInZip = NULL;
|
||||||
|
|
||||||
if (!mZipAvailable || !mZipFile)
|
do {
|
||||||
return openForRead(mFile, filename);
|
if (!mZipAvailable || !mZipFile) {
|
||||||
|
result = openForRead(jFile->mFile, filename);
|
||||||
|
if(!result) {
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
string path = string(":/") + filename.c_str();
|
||||||
|
jFile->mpqFile = new QFile(path.c_str());
|
||||||
|
jFile->mpqFile->open(QIODevice::ReadOnly);
|
||||||
|
result = jFile->mpqFile->isReadable();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
preloadZip(mZipFileName);
|
preloadZip(mZipFileName);
|
||||||
map<string,JZipCache *>::iterator it = mZipCache.find(mZipFileName);
|
map<string,JZipCache *>::iterator it = mZipCache.find(mZipFileName);
|
||||||
if (it == mZipCache.end())
|
if (it == mZipCache.end())
|
||||||
{
|
{
|
||||||
//DetachZipFile();
|
//DetachZipFile();
|
||||||
//return OpenFile(filename);
|
//return OpenFile(filename);
|
||||||
return openForRead(mFile, filename);
|
result = openForRead(jFile->mFile, filename);
|
||||||
}
|
break;
|
||||||
JZipCache * zc = it->second;
|
}
|
||||||
map<string, filesystem::limited_file_info>::iterator it2 = zc->dir.find(filename);
|
JZipCache * zc = it->second;
|
||||||
if (it2 == zc->dir.end())
|
map<string, filesystem::limited_file_info>::iterator it2 = zc->dir.find(filename);
|
||||||
{
|
if (it2 == zc->dir.end())
|
||||||
/*DetachZipFile();
|
{
|
||||||
|
/*DetachZipFile();
|
||||||
return OpenFile(filename); */
|
return OpenFile(filename); */
|
||||||
return openForRead(mFile, filename);
|
result = openForRead(jFile->mFile, filename);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
jFile->mCurrentFileInZip = &(it2->second);
|
||||||
|
result = true;
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
if(result)
|
||||||
|
return jFile;
|
||||||
|
else {
|
||||||
|
delete jFile;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mCurrentFileInZip = &(it2->second);
|
|
||||||
mFileSize = it2->second.m_Size;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JFileSystem::CloseFile()
|
void JFileSystem::CloseFile(JFile* jFile)
|
||||||
{
|
{
|
||||||
if (mZipAvailable && mZipFile)
|
delete jFile;
|
||||||
{
|
|
||||||
mCurrentFileInZip = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mFile)
|
|
||||||
mFile.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns 0 if less than "size" bits were read
|
//returns 0 if less than "size" bits were read
|
||||||
int JFileSystem::ReadFile(void *buffer, int size)
|
int JFileSystem::ReadFile(JFile* jFile, void *buffer, int size)
|
||||||
{
|
{
|
||||||
if (mCurrentFileInZip)
|
if (jFile->mCurrentFileInZip)
|
||||||
{
|
{
|
||||||
assert(mZipFile);
|
assert(mZipFile);
|
||||||
if((size_t)size > mCurrentFileInZip->m_Size) //only support "store" method for zip inside zips
|
if((size_t)size > jFile->mCurrentFileInZip->m_Size) //only support "store" method for zip inside zips
|
||||||
return 0;
|
return 0;
|
||||||
std::streamoff offset = filesystem::SkipLFHdr(mZipFile, mCurrentFileInZip->m_Offset);
|
std::streamoff offset = filesystem::SkipLFHdr(mZipFile, jFile->mCurrentFileInZip->m_Offset);
|
||||||
if (!mZipFile.seekg(offset))
|
if (!mZipFile.seekg(offset))
|
||||||
return 0;
|
return 0;
|
||||||
mZipFile.read((char *) buffer, size);
|
mZipFile.read((char *) buffer, size);
|
||||||
@@ -432,16 +483,43 @@ int JFileSystem::ReadFile(void *buffer, int size)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mFile)
|
#ifdef QT_CONFIG
|
||||||
|
if(jFile->mpqFile) {
|
||||||
|
return jFile->mpqFile->read((char*)buffer, size);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!jFile->mFile)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
assert(!mFile.Zipped() || (size_t)size <= mFile.getUncompSize());
|
assert(!jFile->mFile.Zipped() || (size_t)size <= jFile->mFile.getUncompSize());
|
||||||
mFile.read((char *)buffer, size);
|
jFile->mFile.read((char *)buffer, size);
|
||||||
if (mFile.eof())
|
if (jFile->mFile.eof())
|
||||||
return 0;
|
return 0;
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool JFileSystem::ReadFileLine(JFile* jFile, string& s)
|
||||||
|
{
|
||||||
|
if(!jFile) return false;
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
if(jFile->mpqFile) {
|
||||||
|
QString qs = jFile->mpqFile->readLine();
|
||||||
|
if(qs.isEmpty())
|
||||||
|
return false;
|
||||||
|
else {
|
||||||
|
s = qs.toStdString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if(!jFile->mFile)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
assert(!jFile->mFile.Zipped());
|
||||||
|
return std::getline(jFile->mFile, s);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string>& JFileSystem::scanRealFolder(const std::string& folderName, std::vector<std::string>& results)
|
std::vector<std::string>& JFileSystem::scanRealFolder(const std::string& folderName, std::vector<std::string>& results)
|
||||||
{
|
{
|
||||||
DIR *dip = opendir(folderName.c_str());
|
DIR *dip = opendir(folderName.c_str());
|
||||||
@@ -529,8 +607,17 @@ std::vector<std::string>& JFileSystem::scanfolder(const std::string& _folderName
|
|||||||
seen[systemReal[i]] = true;
|
seen[systemReal[i]] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
string path = string(":/") + folderName;
|
||||||
|
QDir dir(path.c_str());
|
||||||
|
QStringList list = dir.entryList();
|
||||||
|
for(int i = 0; i < list.size(); i++)
|
||||||
|
{
|
||||||
|
seen[list.at(i).toStdString()] = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
for(map<string,bool>::iterator it = seen.begin(); it != seen.end(); ++it)
|
for(map<string,bool>::iterator it = seen.begin(); it != seen.end(); ++it)
|
||||||
{
|
{
|
||||||
results.push_back(it->first);
|
results.push_back(it->first);
|
||||||
}
|
}
|
||||||
@@ -544,12 +631,18 @@ std::vector<std::string> JFileSystem::scanfolder(const std::string& folderName)
|
|||||||
return scanfolder(folderName, result);
|
return scanfolder(folderName, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
int JFileSystem::GetFileSize()
|
int JFileSystem::GetFileSize(JFile* jFile)
|
||||||
{
|
{
|
||||||
if (mCurrentFileInZip)
|
if (jFile->mCurrentFileInZip)
|
||||||
return mFileSize;
|
return jFile->mCurrentFileInZip->m_Size;
|
||||||
|
|
||||||
return GetFileSize(mFile);
|
#ifdef QT_CONFIG
|
||||||
|
if(jFile->mpqFile) {
|
||||||
|
return jFile->mpqFile->size();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return GetFileSize(jFile->mFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JFileSystem::Rename(string _from, string _to)
|
bool JFileSystem::Rename(string _from, string _to)
|
||||||
|
|||||||
+4
-3
@@ -42,10 +42,11 @@ JLBFont::JLBFont(const char *fontname, int lineheight, bool useVideoRAM)
|
|||||||
|
|
||||||
//FILE *file;
|
//FILE *file;
|
||||||
JFileSystem *fileSys = JFileSystem::GetInstance();
|
JFileSystem *fileSys = JFileSystem::GetInstance();
|
||||||
if (!fileSys->OpenFile(filename)) return;
|
JFile* jFile = fileSys->OpenFile(filename);
|
||||||
|
if (!jFile) return;
|
||||||
|
|
||||||
fileSys->ReadFile((u8 *)buffer, 2048);
|
fileSys->ReadFile(jFile, (u8 *)buffer, 2048);
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile(jFile);
|
||||||
|
|
||||||
sprintf(filename, "%s.png", fontname);
|
sprintf(filename, "%s.png", fontname);
|
||||||
mTexture = mRenderer->LoadTexture(filename, useVideoRAM);
|
mTexture = mRenderer->LoadTexture(filename, useVideoRAM);
|
||||||
|
|||||||
@@ -96,7 +96,8 @@ bool JMD2Model::Load(char *filename, char *textureName)
|
|||||||
// open the model file
|
// open the model file
|
||||||
|
|
||||||
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||||
if (!fileSystem->OpenFile(filename))
|
JFile* jFile = fileSystem->OpenFile(filename);
|
||||||
|
if (!jFile)
|
||||||
return false;
|
return false;
|
||||||
//filePtr = fopen(filename, "rb");
|
//filePtr = fopen(filename, "rb");
|
||||||
//if (filePtr == NULL)
|
//if (filePtr == NULL)
|
||||||
@@ -107,13 +108,13 @@ bool JMD2Model::Load(char *filename, char *textureName)
|
|||||||
//fileLen = ftell(filePtr);
|
//fileLen = ftell(filePtr);
|
||||||
//fseek(filePtr, 0, SEEK_SET);
|
//fseek(filePtr, 0, SEEK_SET);
|
||||||
|
|
||||||
fileLen = fileSystem->GetFileSize();
|
fileLen = fileSystem->GetFileSize(jFile);
|
||||||
|
|
||||||
// read entire file into buffer
|
// read entire file into buffer
|
||||||
buffer = (char*)malloc(fileLen + 1);
|
buffer = (char*)malloc(fileLen + 1);
|
||||||
//fread(buffer, sizeof(char), fileLen, filePtr);
|
//fread(buffer, sizeof(char), fileLen, filePtr);
|
||||||
fileSystem->ReadFile(buffer, fileLen);
|
fileSystem->ReadFile(jFile, buffer, fileLen);
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile(jFile);
|
||||||
|
|
||||||
// extract model file header from buffer
|
// extract model file header from buffer
|
||||||
modelHeader = (modelHeader_t*)buffer;
|
modelHeader = (modelHeader_t*)buffer;
|
||||||
|
|||||||
@@ -47,14 +47,15 @@ bool JOBJModel::Load(const char *modelName, const char *textureName)
|
|||||||
{
|
{
|
||||||
|
|
||||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||||
if (!fileSys->OpenFile(modelName))
|
JFile* jFile = fileSys->OpenFile(modelName);
|
||||||
|
if (!jFile)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int size = fileSys->GetFileSize();
|
int size = fileSys->GetFileSize(jFile);
|
||||||
char *buffer = new char[size];
|
char *buffer = new char[size];
|
||||||
|
|
||||||
fileSys->ReadFile(buffer, size);
|
fileSys->ReadFile(jFile, buffer, size);
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile(jFile);
|
||||||
|
|
||||||
Vector3D vert;
|
Vector3D vert;
|
||||||
|
|
||||||
|
|||||||
@@ -55,11 +55,12 @@ bool JParticleEffect::Load(const char* filename)
|
|||||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||||
if (fileSystem == NULL) return false;
|
if (fileSystem == NULL) return false;
|
||||||
|
|
||||||
if (!fileSystem->OpenFile(filename)) return false;
|
JFile* jFile = fileSystem->OpenFile(filename);
|
||||||
|
if (!jFile) return false;
|
||||||
|
|
||||||
int size = fileSystem->GetFileSize();
|
int size = fileSystem->GetFileSize(jFile);
|
||||||
char *xmlBuffer = new char[size];
|
char *xmlBuffer = new char[size];
|
||||||
fileSystem->ReadFile(xmlBuffer, size);
|
fileSystem->ReadFile(jFile, xmlBuffer, size);
|
||||||
|
|
||||||
TiXmlDocument doc;
|
TiXmlDocument doc;
|
||||||
|
|
||||||
@@ -296,7 +297,7 @@ bool JParticleEffect::Load(const char* filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile(jFile);
|
||||||
delete[] xmlBuffer;
|
delete[] xmlBuffer;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -93,13 +93,13 @@ bool JResourceManager::LoadResource(const string& resourceName)
|
|||||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||||
if (fileSystem == NULL) return false;
|
if (fileSystem == NULL) return false;
|
||||||
|
|
||||||
|
JFile* jFile = fileSystem->OpenFile(path.c_str());
|
||||||
|
|
||||||
|
if (!jFile) return false;
|
||||||
|
|
||||||
if (!fileSystem->OpenFile(path.c_str())) return false;
|
int size = fileSystem->GetFileSize(jFile);
|
||||||
|
|
||||||
int size = fileSystem->GetFileSize();
|
|
||||||
char *xmlBuffer = new char[size];
|
char *xmlBuffer = new char[size];
|
||||||
fileSystem->ReadFile(xmlBuffer, size);
|
fileSystem->ReadFile(jFile, xmlBuffer, size);
|
||||||
|
|
||||||
TiXmlDocument doc;
|
TiXmlDocument doc;
|
||||||
doc.Parse(xmlBuffer);
|
doc.Parse(xmlBuffer);
|
||||||
@@ -179,7 +179,7 @@ bool JResourceManager::LoadResource(const string& resourceName)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile(jFile);
|
||||||
delete[] xmlBuffer;
|
delete[] xmlBuffer;
|
||||||
// JGERelease();
|
// JGERelease();
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -41,11 +41,12 @@ bool JSpline::Load(const char *filename, float xscale, float yscale)
|
|||||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||||
|
|
||||||
if (fileSystem == NULL) return false;
|
if (fileSystem == NULL) return false;
|
||||||
if (!fileSystem->OpenFile(filename)) return false;
|
JFile* jFile = fileSystem->OpenFile(filename);
|
||||||
|
if (!jFile) return false;
|
||||||
|
|
||||||
int size = fileSystem->GetFileSize();
|
int size = fileSystem->GetFileSize(jFile);
|
||||||
char *xmlBuffer = new char[size];
|
char *xmlBuffer = new char[size];
|
||||||
fileSystem->ReadFile(xmlBuffer, size);
|
fileSystem->ReadFile(jFile, xmlBuffer, size);
|
||||||
|
|
||||||
TiXmlDocument doc;
|
TiXmlDocument doc;
|
||||||
doc.Parse(xmlBuffer);
|
doc.Parse(xmlBuffer);
|
||||||
@@ -76,7 +77,7 @@ bool JSpline::Load(const char *filename, float xscale, float yscale)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile(jFile);
|
||||||
delete[] xmlBuffer;
|
delete[] xmlBuffer;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -57,19 +57,20 @@ hgeFont::hgeFont(const char *szFont, bool bMipmap __attribute__((unused)))
|
|||||||
// Load font description
|
// Load font description
|
||||||
|
|
||||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||||
if (!fileSys->OpenFile(szFont)) return;
|
JFile* jFile = fileSys->OpenFile(szFont);
|
||||||
|
if (!jFile) return;
|
||||||
|
|
||||||
//data=hge->Resource_Load(szFont, &size);
|
//data=hge->Resource_Load(szFont, &size);
|
||||||
//if(!data) return;
|
//if(!data) return;
|
||||||
size = fileSys->GetFileSize();
|
size = fileSys->GetFileSize(jFile);
|
||||||
|
|
||||||
desc = new char[size+1];
|
desc = new char[size+1];
|
||||||
//memcpy(desc,data,size);
|
//memcpy(desc,data,size);
|
||||||
fileSys->ReadFile(desc, size);
|
fileSys->ReadFile(jFile, desc, size);
|
||||||
desc[size]=0;
|
desc[size]=0;
|
||||||
|
|
||||||
//hge->Resource_Free(data);
|
//hge->Resource_Free(data);
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile(jFile);
|
||||||
|
|
||||||
pdesc=_get_line(desc,linebuf);
|
pdesc=_get_line(desc,linebuf);
|
||||||
if(strcmp(linebuf, FNTHEADERTAG))
|
if(strcmp(linebuf, FNTHEADERTAG))
|
||||||
|
|||||||
+35
-40
@@ -50,46 +50,41 @@ float Random_Float(float min, float max)
|
|||||||
|
|
||||||
hgeParticleSystem::hgeParticleSystem(const char *filename, JQuad *sprite)
|
hgeParticleSystem::hgeParticleSystem(const char *filename, JQuad *sprite)
|
||||||
{
|
{
|
||||||
//void *psi;
|
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||||
//hgeParticleSystemInfo psi;
|
JFile* jFile = fileSys->OpenFile(filename);
|
||||||
|
if (!jFile) return;
|
||||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
|
||||||
//hge=hgeCreate(HGE_VERSION);
|
//if(!psi) return;
|
||||||
|
|
||||||
//psi=hge->Resource_Load(filename);
|
//memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
|
||||||
if (!fileSys->OpenFile(filename)) return;
|
//hge->Resource_Free(psi);
|
||||||
|
|
||||||
//if(!psi) return;
|
// Skip reading the pointer as it may be larger than 4 bytes in the structure
|
||||||
|
void *dummyPointer;
|
||||||
//memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
|
fileSys->ReadFile(jFile, &dummyPointer, 4);
|
||||||
//hge->Resource_Free(psi);
|
// we're actually trying to read more than the file size now, but it's no problem.
|
||||||
|
// Note that this fix is only to avoid the largest problems, filling a structure
|
||||||
// Skip reading the pointer as it may be larger than 4 bytes in the structure
|
// by directly reading a file, is really a bad idea ...
|
||||||
void *dummyPointer;
|
fileSys->ReadFile(jFile, &(info.nEmission), sizeof(hgeParticleSystemInfo) - 4);
|
||||||
fileSys->ReadFile(&dummyPointer, 4);
|
fileSys->CloseFile(jFile);
|
||||||
// we're actually trying to read more than the file size now, but it's no problem.
|
|
||||||
// Note that this fix is only to avoid the largest problems, filling a structure
|
info.sprite=sprite;
|
||||||
// by directly reading a file, is really a bad idea ...
|
// info.fGravityMin *= 100;
|
||||||
fileSys->ReadFile(&(info.nEmission), sizeof(hgeParticleSystemInfo) - 4);
|
// info.fGravityMax *= 100;
|
||||||
fileSys->CloseFile();
|
// info.fSpeedMin *= 100;
|
||||||
|
// info.fSpeedMax *= 100;
|
||||||
info.sprite=sprite;
|
|
||||||
// info.fGravityMin *= 100;
|
vecLocation.x=vecPrevLocation.x=0.0f;
|
||||||
// info.fGravityMax *= 100;
|
vecLocation.y=vecPrevLocation.y=0.0f;
|
||||||
// info.fSpeedMin *= 100;
|
fTx=fTy=0;
|
||||||
// info.fSpeedMax *= 100;
|
|
||||||
|
fEmissionResidue=0.0f;
|
||||||
vecLocation.x=vecPrevLocation.x=0.0f;
|
nParticlesAlive=0;
|
||||||
vecLocation.y=vecPrevLocation.y=0.0f;
|
fAge=-2.0;
|
||||||
fTx=fTy=0;
|
mTimer = 0.0f;
|
||||||
|
|
||||||
fEmissionResidue=0.0f;
|
rectBoundingBox.Clear();
|
||||||
nParticlesAlive=0;
|
bUpdateBoundingBox=false;
|
||||||
fAge=-2.0;
|
|
||||||
mTimer = 0.0f;
|
|
||||||
|
|
||||||
rectBoundingBox.Clear();
|
|
||||||
bUpdateBoundingBox=false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hgeParticleSystem::hgeParticleSystem(hgeParticleSystemInfo *psi)
|
hgeParticleSystem::hgeParticleSystem(hgeParticleSystemInfo *psi)
|
||||||
|
|||||||
+15
-12
@@ -2130,7 +2130,8 @@ void JRenderer::LoadGIF(TextureInfo &textureInfo, const char *filename, int mode
|
|||||||
///*
|
///*
|
||||||
//FILE * fp = fopen(filename, "rb");
|
//FILE * fp = fopen(filename, "rb");
|
||||||
JFileSystem *fileSys = JFileSystem::GetInstance();
|
JFileSystem *fileSys = JFileSystem::GetInstance();
|
||||||
if (!fileSys->OpenFile(filename))
|
JFile* jFile = fileSystem->OpenFile(filename);
|
||||||
|
if (!jFile))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//if(fp == NULL)
|
//if(fp == NULL)
|
||||||
@@ -2140,7 +2141,7 @@ void JRenderer::LoadGIF(TextureInfo &textureInfo, const char *filename, int mode
|
|||||||
if(result!=0)
|
if(result!=0)
|
||||||
textureInfo.mBits=NULL;
|
textureInfo.mBits=NULL;
|
||||||
//fclose(fp);
|
//fclose(fp);
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile(jFile);
|
||||||
return ;//*/
|
return ;//*/
|
||||||
}
|
}
|
||||||
#endif //(!defined IOS) && (!defined QT_CONFIG) && (!defined SDL_CONFIG)
|
#endif //(!defined IOS) && (!defined QT_CONFIG) && (!defined SDL_CONFIG)
|
||||||
@@ -2161,20 +2162,21 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm
|
|||||||
UIImage *image = NULL;
|
UIImage *image = NULL;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (!fileSystem->OpenFile(filename))
|
JFile* jFile = fileSystem->OpenFile(filename);
|
||||||
|
if (!jFile)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
rawsize = fileSystem->GetFileSize();
|
rawsize = fileSystem->GetFileSize(jFile);
|
||||||
rawdata = new BYTE[rawsize];
|
rawdata = new BYTE[rawsize];
|
||||||
|
|
||||||
if (!rawdata)
|
if (!rawdata)
|
||||||
{
|
{
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile(jFile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSystem->ReadFile(rawdata, rawsize);
|
fileSystem->ReadFile(jFile, rawdata, rawsize);
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile(jFile);
|
||||||
|
|
||||||
texData = [[NSData alloc] initWithBytes:rawdata length:rawsize];
|
texData = [[NSData alloc] initWithBytes:rawdata length:rawsize];
|
||||||
image = [[UIImage alloc] initWithData:texData];
|
image = [[UIImage alloc] initWithData:texData];
|
||||||
@@ -2254,20 +2256,21 @@ JTexture* JRenderer::LoadTexture(const char* filename, int, int)
|
|||||||
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (!fileSystem->OpenFile(filename))
|
JFile* jFile = fileSystem->OpenFile(filename);
|
||||||
|
if (!jFile)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
rawsize = fileSystem->GetFileSize();
|
rawsize = fileSystem->GetFileSize(jFile);
|
||||||
rawdata = new BYTE[rawsize];
|
rawdata = new BYTE[rawsize];
|
||||||
|
|
||||||
if (!rawdata)
|
if (!rawdata)
|
||||||
{
|
{
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile(jFile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSystem->ReadFile(rawdata, rawsize);
|
fileSystem->ReadFile(jFile, rawdata, rawsize);
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile(jFile);
|
||||||
|
|
||||||
QImage tmpImage = QImage::fromData(rawdata, rawsize);
|
QImage tmpImage = QImage::fromData(rawdata, rawsize);
|
||||||
if(tmpImage.isNull())
|
if(tmpImage.isNull())
|
||||||
|
|||||||
@@ -1843,7 +1843,7 @@ int Tournament::getRandomDeck(bool noEasyDecks)
|
|||||||
DeckManager *deckManager = DeckManager::GetInstance();
|
DeckManager *deckManager = DeckManager::GetInstance();
|
||||||
vector<DeckMetaData *> *deckList = deckManager->getAIDeckOrderList();
|
vector<DeckMetaData *> *deckList = deckManager->getAIDeckOrderList();
|
||||||
|
|
||||||
int deckNumber;
|
int deckNumber=0;
|
||||||
unsigned int random=0;
|
unsigned int random=0;
|
||||||
int k=0;
|
int k=0;
|
||||||
bool isDouble=true;
|
bool isDouble=true;
|
||||||
|
|||||||
@@ -300,12 +300,12 @@ string GameStateMenu::loadRandomWallpaper()
|
|||||||
return wallpaper;
|
return wallpaper;
|
||||||
|
|
||||||
vector<string> wallpapers;
|
vector<string> wallpapers;
|
||||||
izfstream file;
|
JFile* jFile = JFileSystem::GetInstance()->OpenFile("graphics/wallpapers.txt");
|
||||||
if (! JFileSystem::GetInstance()->openForRead(file, "graphics/wallpapers.txt"))
|
if (!jFile)
|
||||||
return wallpaper;
|
return wallpaper;
|
||||||
|
|
||||||
string s;
|
string s;
|
||||||
while (std::getline(file, s))
|
while (JFileSystem::GetInstance()->ReadFileLine(jFile, s))
|
||||||
{
|
{
|
||||||
if (!s.size())
|
if (!s.size())
|
||||||
continue;
|
continue;
|
||||||
@@ -313,7 +313,7 @@ string GameStateMenu::loadRandomWallpaper()
|
|||||||
s.erase(s.size() - 1); //Handle DOS files
|
s.erase(s.size() - 1); //Handle DOS files
|
||||||
wallpapers.push_back(s);
|
wallpapers.push_back(s);
|
||||||
}
|
}
|
||||||
file.close();
|
JFileSystem::GetInstance()->CloseFile(jFile);
|
||||||
|
|
||||||
int rnd = rand() % (wallpapers.size());
|
int rnd = rand() % (wallpapers.size());
|
||||||
wallpaper = wallpapers[rnd];
|
wallpaper = wallpapers[rnd];
|
||||||
@@ -352,21 +352,21 @@ void GameStateMenu::loadLangMenu()
|
|||||||
vector<string> langFiles = JFileSystem::GetInstance()->scanfolder("lang/");
|
vector<string> langFiles = JFileSystem::GetInstance()->scanfolder("lang/");
|
||||||
for (size_t i = 0; i < langFiles.size(); ++i)
|
for (size_t i = 0; i < langFiles.size(); ++i)
|
||||||
{
|
{
|
||||||
izfstream file;
|
|
||||||
string filePath = "lang/";
|
string filePath = "lang/";
|
||||||
filePath.append(langFiles[i]);
|
filePath.append(langFiles[i]);
|
||||||
if (! JFileSystem::GetInstance()->openForRead(file, filePath))
|
JFile* jFile = JFileSystem::GetInstance()->OpenFile(filePath);
|
||||||
|
if (!jFile)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string s;
|
string s;
|
||||||
string lang;
|
string lang;
|
||||||
|
|
||||||
if (std::getline(file, s))
|
if (JFileSystem::GetInstance()->ReadFileLine(jFile, s))
|
||||||
{
|
{
|
||||||
lang = getLang(s);
|
lang = getLang(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
JFileSystem::GetInstance()->CloseFile(jFile);
|
||||||
|
|
||||||
if (lang.size())
|
if (lang.size())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -399,8 +399,8 @@ int MTGAllCards::load(const string &config_file, int set_id)
|
|||||||
|
|
||||||
int lineNumber = 0;
|
int lineNumber = 0;
|
||||||
std::string contents;
|
std::string contents;
|
||||||
izfstream file;
|
JFile* jFile = JFileSystem::GetInstance()->OpenFile(config_file);
|
||||||
if (!JFileSystem::GetInstance()->openForRead(file, config_file))
|
if (!jFile)
|
||||||
{
|
{
|
||||||
DebugTrace("MTGAllCards::load: error loading: " << config_file);
|
DebugTrace("MTGAllCards::load: error loading: " << config_file);
|
||||||
return total_cards;
|
return total_cards;
|
||||||
@@ -408,7 +408,7 @@ int MTGAllCards::load(const string &config_file, int set_id)
|
|||||||
|
|
||||||
string s;
|
string s;
|
||||||
|
|
||||||
while (getline(file,s))
|
while (JFileSystem::GetInstance()->ReadFileLine(jFile, s))
|
||||||
{
|
{
|
||||||
lineNumber++;
|
lineNumber++;
|
||||||
if (!s.size()) continue;
|
if (!s.size()) continue;
|
||||||
@@ -448,7 +448,7 @@ int MTGAllCards::load(const string &config_file, int set_id)
|
|||||||
if (!maxGrade) maxGrade = Constants::GRADE_BORDERLINE; //Default setting for grade is borderline?
|
if (!maxGrade) maxGrade = Constants::GRADE_BORDERLINE; //Default setting for grade is borderline?
|
||||||
if (fileGrade > maxGrade)
|
if (fileGrade > maxGrade)
|
||||||
{
|
{
|
||||||
file.close();
|
JFileSystem::GetInstance()->CloseFile(jFile);
|
||||||
return total_cards;
|
return total_cards;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -480,7 +480,7 @@ int MTGAllCards::load(const string &config_file, int set_id)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file.close();
|
JFileSystem::GetInstance()->CloseFile(jFile);
|
||||||
return total_cards;
|
return total_cards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -326,16 +326,16 @@ void OptionLanguage::Reload()
|
|||||||
vector<string> langFiles = JFileSystem::GetInstance()->scanfolder("lang/");
|
vector<string> langFiles = JFileSystem::GetInstance()->scanfolder("lang/");
|
||||||
for (size_t i = 0; i < langFiles.size(); ++i)
|
for (size_t i = 0; i < langFiles.size(); ++i)
|
||||||
{
|
{
|
||||||
izfstream file;
|
|
||||||
string filePath = "lang/";
|
string filePath = "lang/";
|
||||||
filePath.append(langFiles[i]);
|
filePath.append(langFiles[i]);
|
||||||
if (! JFileSystem::GetInstance()->openForRead(file, filePath))
|
JFile* jFile = JFileSystem::GetInstance()->OpenFile(filePath);
|
||||||
|
if (!jFile)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string s;
|
string s;
|
||||||
string lang;
|
string lang;
|
||||||
|
|
||||||
if (std::getline(file, s))
|
if (JFileSystem::GetInstance()->ReadFileLine(jFile, s))
|
||||||
{
|
{
|
||||||
if (!s.size())
|
if (!s.size())
|
||||||
{
|
{
|
||||||
@@ -352,7 +352,7 @@ void OptionLanguage::Reload()
|
|||||||
lang = s.substr(6);
|
lang = s.substr(6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file.close();
|
JFileSystem::GetInstance()->CloseFile(jFile);
|
||||||
|
|
||||||
if (lang.size())
|
if (lang.size())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -599,16 +599,17 @@ bool StoryFlow::parse(string path)
|
|||||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||||
if (!fileSystem) return false;
|
if (!fileSystem) return false;
|
||||||
|
|
||||||
if (!fileSystem->OpenFile(path.c_str())) return false;
|
JFile* jFile = fileSystem->OpenFile(path.c_str());
|
||||||
|
if (!jFile) return false;
|
||||||
|
|
||||||
int size = fileSystem->GetFileSize();
|
int size = fileSystem->GetFileSize(jFile);
|
||||||
char *xmlBuffer = NEW char[size];
|
char *xmlBuffer = NEW char[size];
|
||||||
fileSystem->ReadFile(xmlBuffer, size);
|
fileSystem->ReadFile(jFile, xmlBuffer, size);
|
||||||
|
|
||||||
TiXmlDocument doc;
|
TiXmlDocument doc;
|
||||||
doc.Parse(xmlBuffer);
|
doc.Parse(xmlBuffer);
|
||||||
|
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile(jFile);
|
||||||
delete[] xmlBuffer;
|
delete[] xmlBuffer;
|
||||||
|
|
||||||
for (TiXmlNode* node = doc.FirstChild(); node; node = node->NextSibling())
|
for (TiXmlNode* node = doc.FirstChild(); node; node = node->NextSibling())
|
||||||
|
|||||||
@@ -333,8 +333,9 @@ bool WCachedParticles::Attempt(const string& filename, int, int & error)
|
|||||||
{
|
{
|
||||||
|
|
||||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||||
|
JFile* jFile = fileSys->OpenFile(WResourceManager::Instance()->graphicsFile(filename));
|
||||||
|
|
||||||
if (!fileSys->OpenFile(WResourceManager::Instance()->graphicsFile(filename)))
|
if (!jFile)
|
||||||
{
|
{
|
||||||
error = CACHE_ERROR_404;
|
error = CACHE_ERROR_404;
|
||||||
return false;
|
return false;
|
||||||
@@ -345,12 +346,12 @@ bool WCachedParticles::Attempt(const string& filename, int, int & error)
|
|||||||
particles = NEW hgeParticleSystemInfo;
|
particles = NEW hgeParticleSystemInfo;
|
||||||
// We Skip reading the pointer as it may be larger than 4 bytes in the structure
|
// We Skip reading the pointer as it may be larger than 4 bytes in the structure
|
||||||
void *dummyPointer;
|
void *dummyPointer;
|
||||||
fileSys->ReadFile(&dummyPointer, 4);
|
fileSys->ReadFile(jFile, &dummyPointer, 4);
|
||||||
// we're actually trying to read more than the file size now, but it's no problem.
|
// we're actually trying to read more than the file size now, but it's no problem.
|
||||||
// Note that this fix is only to avoid the largest problems, filling a structure
|
// Note that this fix is only to avoid the largest problems, filling a structure
|
||||||
// by directly reading a file, is really a bad idea ...
|
// by directly reading a file, is really a bad idea ...
|
||||||
fileSys->ReadFile(&(particles->nEmission), sizeof(hgeParticleSystemInfo) - sizeof(void*));
|
fileSys->ReadFile(jFile, &(particles->nEmission), sizeof(hgeParticleSystemInfo) - sizeof(void*));
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile(jFile);
|
||||||
|
|
||||||
particles->sprite = NULL;
|
particles->sprite = NULL;
|
||||||
error = CACHE_ERROR_NONE;
|
error = CACHE_ERROR_NONE;
|
||||||
|
|||||||
+21
-17
@@ -171,20 +171,22 @@ WFont(inFontID), mTexture(0)
|
|||||||
unsigned char height;
|
unsigned char height;
|
||||||
} sizeStr = { 0, 0, 0 };
|
} sizeStr = { 0, 0, 0 };
|
||||||
|
|
||||||
if (!fileSys->OpenFile(engFileName)) return;
|
JFile* jFile = fileSys->OpenFile(engFileName);
|
||||||
size = fileSys->GetFileSize();
|
if (!jFile) return;
|
||||||
|
size = fileSys->GetFileSize(jFile);
|
||||||
mStdFont = NEW u8[size];
|
mStdFont = NEW u8[size];
|
||||||
fileSys->ReadFile(mStdFont, size);
|
fileSys->ReadFile(jFile, mStdFont, size);
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile(jFile);
|
||||||
|
|
||||||
if (!fileSys->OpenFile(fontname)) return;
|
jFile = fileSys->OpenFile(fontname);
|
||||||
fileSys->ReadFile(&sizeStr, 4); // Works only for little-endian machines (PSP and PC are)
|
if (!jFile) return;
|
||||||
|
fileSys->ReadFile(jFile, &sizeStr, 4); // Works only for little-endian machines (PSP and PC are)
|
||||||
size = sizeStr.chars * sizeStr.width * sizeStr.height / 2;
|
size = sizeStr.chars * sizeStr.width * sizeStr.height / 2;
|
||||||
mExtraFont = NEW u8[size]; // 4 bits for a pixel
|
mExtraFont = NEW u8[size]; // 4 bits for a pixel
|
||||||
mIndex = NEW u16[65536];
|
mIndex = NEW u16[65536];
|
||||||
fileSys->ReadFile(mIndex, 65536 * sizeof(u16));
|
fileSys->ReadFile(jFile, mIndex, 65536 * sizeof(u16));
|
||||||
fileSys->ReadFile(mExtraFont, size);
|
fileSys->ReadFile(jFile, mExtraFont, size);
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile(jFile);
|
||||||
|
|
||||||
mColor0 = ARGB(255, 255, 255, 255);
|
mColor0 = ARGB(255, 255, 255, 255);
|
||||||
mColor = mColor0;
|
mColor = mColor0;
|
||||||
@@ -612,17 +614,19 @@ WGBKFont::WGBKFont(int inFontID, const char *fontname, int lineheight, bool) :
|
|||||||
JFileSystem *fileSys = JFileSystem::GetInstance();
|
JFileSystem *fileSys = JFileSystem::GetInstance();
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
if (!fileSys->OpenFile(fontname)) return;
|
JFile* jFile = fileSys->OpenFile(fontname);
|
||||||
size = fileSys->GetFileSize();
|
if (!jFile) return;
|
||||||
|
size = fileSys->GetFileSize(jFile);
|
||||||
mExtraFont = NEW u8[size];
|
mExtraFont = NEW u8[size];
|
||||||
fileSys->ReadFile(mExtraFont, size);
|
fileSys->ReadFile(jFile, mExtraFont, size);
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile(jFile);
|
||||||
|
|
||||||
if (!fileSys->OpenFile(engFileName)) return;
|
jFile = fileSys->OpenFile(engFileName);
|
||||||
size = fileSys->GetFileSize();
|
if (!jFile) return;
|
||||||
|
size = fileSys->GetFileSize(jFile);
|
||||||
mStdFont = NEW u8[size];
|
mStdFont = NEW u8[size];
|
||||||
fileSys->ReadFile(mStdFont, size);
|
fileSys->ReadFile(jFile, mStdFont, size);
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile(jFile);
|
||||||
|
|
||||||
mIndex = 0;
|
mIndex = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user