Updated JFileSystem implementation to be compatible with Qt resources.

This commit is contained in:
xawotihs
2013-12-28 00:38:02 +01:00
parent b09db0c60f
commit fec4468aea
20 changed files with 340 additions and 211 deletions

View File

@@ -1843,7 +1843,7 @@ int Tournament::getRandomDeck(bool noEasyDecks)
DeckManager *deckManager = DeckManager::GetInstance();
vector<DeckMetaData *> *deckList = deckManager->getAIDeckOrderList();
int deckNumber;
int deckNumber=0;
unsigned int random=0;
int k=0;
bool isDouble=true;

View File

@@ -300,12 +300,12 @@ string GameStateMenu::loadRandomWallpaper()
return wallpaper;
vector<string> wallpapers;
izfstream file;
if (! JFileSystem::GetInstance()->openForRead(file, "graphics/wallpapers.txt"))
JFile* jFile = JFileSystem::GetInstance()->OpenFile("graphics/wallpapers.txt");
if (!jFile)
return wallpaper;
string s;
while (std::getline(file, s))
while (JFileSystem::GetInstance()->ReadFileLine(jFile, s))
{
if (!s.size())
continue;
@@ -313,7 +313,7 @@ string GameStateMenu::loadRandomWallpaper()
s.erase(s.size() - 1); //Handle DOS files
wallpapers.push_back(s);
}
file.close();
JFileSystem::GetInstance()->CloseFile(jFile);
int rnd = rand() % (wallpapers.size());
wallpaper = wallpapers[rnd];
@@ -352,21 +352,21 @@ void GameStateMenu::loadLangMenu()
vector<string> langFiles = JFileSystem::GetInstance()->scanfolder("lang/");
for (size_t i = 0; i < langFiles.size(); ++i)
{
izfstream file;
string filePath = "lang/";
filePath.append(langFiles[i]);
if (! JFileSystem::GetInstance()->openForRead(file, filePath))
JFile* jFile = JFileSystem::GetInstance()->OpenFile(filePath);
if (!jFile)
continue;
string s;
string lang;
if (std::getline(file, s))
if (JFileSystem::GetInstance()->ReadFileLine(jFile, s))
{
lang = getLang(s);
}
file.close();
JFileSystem::GetInstance()->CloseFile(jFile);
if (lang.size())
{

View File

@@ -399,8 +399,8 @@ int MTGAllCards::load(const string &config_file, int set_id)
int lineNumber = 0;
std::string contents;
izfstream file;
if (!JFileSystem::GetInstance()->openForRead(file, config_file))
JFile* jFile = JFileSystem::GetInstance()->OpenFile(config_file);
if (!jFile)
{
DebugTrace("MTGAllCards::load: error loading: " << config_file);
return total_cards;
@@ -408,7 +408,7 @@ int MTGAllCards::load(const string &config_file, int set_id)
string s;
while (getline(file,s))
while (JFileSystem::GetInstance()->ReadFileLine(jFile, s))
{
lineNumber++;
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 (fileGrade > maxGrade)
{
file.close();
JFileSystem::GetInstance()->CloseFile(jFile);
return total_cards;
}
}
@@ -480,7 +480,7 @@ int MTGAllCards::load(const string &config_file, int set_id)
continue;
}
}
file.close();
JFileSystem::GetInstance()->CloseFile(jFile);
return total_cards;
}

View File

@@ -326,16 +326,16 @@ void OptionLanguage::Reload()
vector<string> langFiles = JFileSystem::GetInstance()->scanfolder("lang/");
for (size_t i = 0; i < langFiles.size(); ++i)
{
izfstream file;
string filePath = "lang/";
filePath.append(langFiles[i]);
if (! JFileSystem::GetInstance()->openForRead(file, filePath))
JFile* jFile = JFileSystem::GetInstance()->OpenFile(filePath);
if (!jFile)
continue;
string s;
string lang;
if (std::getline(file, s))
if (JFileSystem::GetInstance()->ReadFileLine(jFile, s))
{
if (!s.size())
{
@@ -352,7 +352,7 @@ void OptionLanguage::Reload()
lang = s.substr(6);
}
}
file.close();
JFileSystem::GetInstance()->CloseFile(jFile);
if (lang.size())
{

View File

@@ -599,16 +599,17 @@ bool StoryFlow::parse(string path)
JFileSystem *fileSystem = JFileSystem::GetInstance();
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];
fileSystem->ReadFile(xmlBuffer, size);
fileSystem->ReadFile(jFile, xmlBuffer, size);
TiXmlDocument doc;
doc.Parse(xmlBuffer);
fileSystem->CloseFile();
fileSystem->CloseFile(jFile);
delete[] xmlBuffer;
for (TiXmlNode* node = doc.FirstChild(); node; node = node->NextSibling())

View File

@@ -333,8 +333,9 @@ bool WCachedParticles::Attempt(const string& filename, int, int & error)
{
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;
return false;
@@ -345,12 +346,12 @@ bool WCachedParticles::Attempt(const string& filename, int, int & error)
particles = NEW hgeParticleSystemInfo;
// We Skip reading the pointer as it may be larger than 4 bytes in the structure
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.
// Note that this fix is only to avoid the largest problems, filling a structure
// by directly reading a file, is really a bad idea ...
fileSys->ReadFile(&(particles->nEmission), sizeof(hgeParticleSystemInfo) - sizeof(void*));
fileSys->CloseFile();
fileSys->ReadFile(jFile, &(particles->nEmission), sizeof(hgeParticleSystemInfo) - sizeof(void*));
fileSys->CloseFile(jFile);
particles->sprite = NULL;
error = CACHE_ERROR_NONE;

View File

@@ -171,20 +171,22 @@ WFont(inFontID), mTexture(0)
unsigned char height;
} sizeStr = { 0, 0, 0 };
if (!fileSys->OpenFile(engFileName)) return;
size = fileSys->GetFileSize();
JFile* jFile = fileSys->OpenFile(engFileName);
if (!jFile) return;
size = fileSys->GetFileSize(jFile);
mStdFont = NEW u8[size];
fileSys->ReadFile(mStdFont, size);
fileSys->CloseFile();
fileSys->ReadFile(jFile, mStdFont, size);
fileSys->CloseFile(jFile);
if (!fileSys->OpenFile(fontname)) return;
fileSys->ReadFile(&sizeStr, 4); // Works only for little-endian machines (PSP and PC are)
jFile = fileSys->OpenFile(fontname);
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;
mExtraFont = NEW u8[size]; // 4 bits for a pixel
mIndex = NEW u16[65536];
fileSys->ReadFile(mIndex, 65536 * sizeof(u16));
fileSys->ReadFile(mExtraFont, size);
fileSys->CloseFile();
fileSys->ReadFile(jFile, mIndex, 65536 * sizeof(u16));
fileSys->ReadFile(jFile, mExtraFont, size);
fileSys->CloseFile(jFile);
mColor0 = ARGB(255, 255, 255, 255);
mColor = mColor0;
@@ -612,17 +614,19 @@ WGBKFont::WGBKFont(int inFontID, const char *fontname, int lineheight, bool) :
JFileSystem *fileSys = JFileSystem::GetInstance();
int size = 0;
if (!fileSys->OpenFile(fontname)) return;
size = fileSys->GetFileSize();
JFile* jFile = fileSys->OpenFile(fontname);
if (!jFile) return;
size = fileSys->GetFileSize(jFile);
mExtraFont = NEW u8[size];
fileSys->ReadFile(mExtraFont, size);
fileSys->CloseFile();
fileSys->ReadFile(jFile, mExtraFont, size);
fileSys->CloseFile(jFile);
if (!fileSys->OpenFile(engFileName)) return;
size = fileSys->GetFileSize();
jFile = fileSys->OpenFile(engFileName);
if (!jFile) return;
size = fileSys->GetFileSize(jFile);
mStdFont = NEW u8[size];
fileSys->ReadFile(mStdFont, size);
fileSys->CloseFile();
fileSys->ReadFile(jFile, mStdFont, size);
fileSys->CloseFile(jFile);
mIndex = 0;