- Support for Zip Filesystem. It is now possible to zip the entire Res folder ("store" method preferred, zip so that the root of the zip has ai, player, etc...) in one single file for read only. Write access is done in another folder (hardcoded to be User/ for now, can be updated depending on platforms, etc...

-- zipFS has several limitations...
--- in a general way, seekg doesn't work... so getting a file's size needs to be done through JFileSystem.
--- getLine on files open with zipFS doesn't work so great. Not sure if it is a normal issue because files are open in binary or not... JFileSystem therefore offers a "readIntoString" function that needs to be used instead of the usual "getline" technique. However getLine can then be used on a stream connected to the string.

-- tested on Windows and PSP, I also made sure android still works, but haven't tested zip support on Android.
-- I tried to maintain backwards compatibility, but this might break on some platforms, if I broke some platforms and you can't find a way to fix them, please contact me and we'll figure something out
-- This removes wagic::ifstream. I didn't reimplement the securities that were involved in this, apologies for that. Might be useful to reimplement such securities in JFileSystem
-- I haven't tested options/profiles in a deep way, it is possible I broke that.
This commit is contained in:
wagic.the.homebrew
2011-08-21 09:04:59 +00:00
parent 14bd7b7a24
commit e27cf56fa2
73 changed files with 3539 additions and 936 deletions

View File

@@ -8,4 +8,4 @@
# project structure.
# Project target.
target=android-7
target=android-8

View File

@@ -22,6 +22,7 @@ LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/$(SDL_PATH)/include \
$(LOCAL_PATH)/$(MTG_PATH)/include \
$(LOCAL_PATH)/$(JGE_PATH)/include \
$(LOCAL_PATH)/$(JGE_PATH)/src/zipFS \
$(LOCAL_PATH)/$(BOOST_PATH) \
$(LOCAL_PATH)/$(JPEG_PATH) \
$(LOCAL_PATH)/$(PNG_PATH) \
@@ -163,9 +164,9 @@ LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.cpp \
$(JGE_PATH)/src/hge/hgeparticle.cpp \
$(JGE_PATH)/src/hge/hgerect.cpp \
$(JGE_PATH)/src/hge/hgevector.cpp \
$(JGE_PATH)/src/unzip/ioapi.c \
$(JGE_PATH)/src/unzip/mztools.c \
$(JGE_PATH)/src/unzip/unzip.c \
$(JGE_PATH)/src/zipFS/zfsystem.cpp \
$(JGE_PATH)/src/zipFS/ziphdr.cpp \
$(JGE_PATH)/src/zipFS/zstream.cpp \
$(JGE_PATH)/src/pc/JSfx.cpp \
$(JGE_PATH)/src/pc/JGfx.cpp \
$(JGE_PATH)/src/JNetwork.cpp \

View File

@@ -35,7 +35,7 @@ PSP_EBOOT_ICON = icon.png
#PSP_EBOOT_ICON1 = icon1.pmf
PSP_EBOOT_UNKPNG = pic0.png
PSP_EBOOT_PIC1 = pic1.png
INCDIR = ../../JGE/include ../../JGE/include/psp ../../JGE/include/psp/freetype2 ../../JGE/src ../../projects/mtg/include ../../Boost
INCDIR = ../../JGE/include ../../JGE/src/zipFS ../../JGE/include/psp ../../JGE/include/psp/freetype2 ../../JGE/src ../../projects/mtg/include ../../Boost
LIBDIR = ../../JGE/lib/psp
CFLAGS = -O2 -G0 -DPSPFW3XX -DDEVHOOK -DUSE_PRECOMPILED_HEADERS=1 -DPSP
else
@@ -56,7 +56,7 @@ CXXFLAGS += $(CFLAGS)
LDFLAGS += $(LIBS)
debug: CXXFLAGS += -ggdb3 -D_DEBUG -DDEBUG
debug: CXXFLAGS += -ggdb3 -D_DEBUG -DDEBUG -DDEBUG_CACHE
log: CXXFLAGS += -DDOLOG

View File

@@ -33,7 +33,7 @@ public:
CastRestrictions * clone() const
{
return NEW CastRestrictions(*this);
return NEW CastRestrictions(*this);
};
};

View File

@@ -96,7 +96,7 @@ public:
void DoTransition(int trans, int tostate, float dur = -1, bool animonly = false);
void DoAnimation(int trans, float dur = -1);
static hgeParticleSystem * Particles[6];
static int HasMusic;
static bool HasMusic;
static string systemError;
static JMusic* music;
static string currentMusicFile;

View File

@@ -402,7 +402,7 @@ public:
//These return a filepath accurate to the current mode/profile/theme, and can
//optionally fallback to a file within a certain directory.
//The sanity=false option returns the adjusted path even if the file doesn't exist.
string profileFile(string filename="", string fallback="", bool sanity=false,bool relative=false);
string profileFile(string filename="", string fallback="", bool sanity=false);
void reloadProfile(); //Reloads profile using current options[ACTIVE_PROFILE]
void checkProfile(); //Confirms that a profile is loaded and contains a collection.

View File

@@ -26,14 +26,15 @@ private:
char nbcardsStr[400];
vector<string> langs;
vector<string> primitives;
size_t mCurrentSetFolderIndex;
string mCurrentSetName;
string mCurrentSetFileName;
vector<string> setFolders;
string wallpaper;
int primitivesLoadCounter;
DIR *mDip;
struct dirent *mDit;
char mCurrentSetName[32];
char mCurrentSetFileName[512];
int mReadConf;
float timeIndex;
void fillScroller();
@@ -61,8 +62,7 @@ public:
virtual void Render();
virtual void ButtonPressed(int controllerId, int controlId);
int nextDirectory(const char * root, const char * file); // Retrieves the next directory to have matching file
void resetDirectory();
int nextSetFolder(const string & root, const string & file); // Retrieves the next directory to have matching file
void createUsersFirstDeck(int setId);
virtual ostream& toString(ostream& out) const;

View File

@@ -127,8 +127,6 @@ public:
int totalCards();
int randomCardId();
static void loadPrimitives(const char *root_directory);
static void loadSets(const char *root_directory, const char* filename);
static void loadInstance();
static void unloadAll();
static inline MTGAllCards* getInstance() { return instance; };

View File

@@ -101,8 +101,8 @@ public:
virtual string cardFile(const string& filename) = 0;
virtual string musicFile(const string& filename) = 0;
virtual string sfxFile(const string& filename) = 0;
virtual int fileOK(const string&, bool relative = false) = 0;
virtual int dirOK(const string& dirname) = 0;
virtual bool fileOK(const string&) = 0;
virtual bool dirOK(const string& dirname) = 0;
//For backwards compatibility with JWResourceManager. Avoid using these, they're not optimal.
virtual int CreateTexture(const string &textureName) = 0;

View File

@@ -173,8 +173,8 @@ public:
string cardFile(const string& filename);
string musicFile(const string& filename);
string sfxFile(const string& filename);
int fileOK(const string&, bool relative = false);
int dirOK(const string& dirname);
bool fileOK(const string&);
bool dirOK(const string& dirname);
//For backwards compatibility with JResourceManager. Avoid using these, they're not optimal.
int CreateTexture(const string &textureName);

View File

@@ -29,46 +29,6 @@
#include "DebugRoutines.h"
// enable this define to collect statistics on how many times an ifstream is created for a given file.
//#define TRACK_FILE_USAGE_STATS
namespace wagic
{
#ifdef TRACK_FILE_USAGE_STATS
class ifstream : public std::ifstream
{
public:
explicit ifstream(const char *inFilename, ios_base::openmode inMode = ios_base::in) :
std::ifstream(inFilename, inMode)
{
sFileMap[std::string(inFilename)] += 1;
DebugTrace("ifstream opened on file: " << inFilename);
}
static void Dump()
{
DebugTrace("-------------------");
DebugTrace("File Usage Statistics" << std::endl);
std::map<std::string, int>::const_iterator iter = sFileMap.begin();
for (; iter != sFileMap.end(); ++iter)
{
DebugTrace(iter->first << " -- " << iter->second);
}
DebugTrace("End File Usage Statistics");
DebugTrace("-------------------");
}
private:
static std::map<std::string, int> sFileMap;
};
#else
typedef std::ifstream ifstream;
#endif
} //namespace wagic
using std::string;
@@ -105,7 +65,6 @@ unsigned long hash_djb2(const char *str);
int loadRandValues(string s);
int filesize(const char * filename);
int fileExists(const char * filename);
int WRand();
#ifdef LINUX
@@ -135,6 +94,9 @@ u32 ramAvailable(void);
#define MAKEDIR(name) mkdir(name, 0777)
#endif
bool FileExists(const string& strFilename);
bool fileExists(const char * filename);
bool FileExists(const string & filename);
std::string buildFilePath(const vector<string> & folders, const string & filename);
#endif

View File

@@ -1322,7 +1322,7 @@ AIStats * AIPlayer::getStats()
if (!stats)
{
char statFile[512];
sprintf(statFile, JGE_GET_RES("ai/baka/stats/%s.stats").c_str(), opponent()->deckFileSmall.c_str());
sprintf(statFile, "ai/baka/stats/%s.stats", opponent()->deckFileSmall.c_str());
stats = NEW AIStats(this, statFile);
}
return stats;
@@ -1352,12 +1352,10 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op
{
found = 0;
char buffer[512];
sprintf(buffer, JGE_GET_RES("ai/baka/deck%i.txt").c_str(), nbdecks + 1);
wagic::ifstream file(buffer);
if (file)
sprintf(buffer, "ai/baka/deck%i.txt", nbdecks + 1);
if (FileExists(buffer))
{
found = 1;
file.close();
nbdecks++;
}
}
@@ -1365,7 +1363,7 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op
return NULL;
deckid = 1 + WRand() % (nbdecks);
}
sprintf(deckFile, JGE_GET_RES("ai/baka/deck%i.txt").c_str(), deckid);
sprintf(deckFile, "ai/baka/deck%i.txt", deckid);
DeckMetaData *aiMeta = DeckManager::GetInstance()->getDeckMetaDataByFilename( deckFile, true);
avatarFilename = aiMeta->getAvatarFilename();
sprintf(deckFileSmall, "ai_baka_deck%i", deckid);

View File

@@ -146,34 +146,33 @@ AIStat * AIStats::find(MTGCard * source)
void AIStats::load(char * filename)
{
wagic::ifstream file(filename);
std::string s;
if (file)
std::string contents;
if (JFileSystem::GetInstance()->readIntoString(filename, contents))
{
while (std::getline(file, s))
std::stringstream stream(contents);
std::string s;
while (std::getline(stream, s))
{
int cardid = atoi(s.c_str());
std::getline(file, s);
std::getline(stream, s);
int value = atoi(s.c_str());
std::getline(file, s);
std::getline(stream, s);
bool direct = atoi(s.c_str()) > 0;
AIStat * stat = NEW AIStat(cardid, value, 1, direct);
stats.push_back(stat);
}
file.close();
}
else
{
//TODO Error management
DebugTrace("FATAL: AIStats.cpp:load : can't load" << filename);
}
}
void AIStats::save()
{
std::ofstream file(filename.c_str());
char writer[128];
if (file)
std::ofstream file;
if (JFileSystem::GetInstance()->openForWrite(file, filename))
{
char writer[128];
list<AIStat *>::iterator it;
for (it = stats.begin(); it != stats.end(); it++)
{

View File

@@ -336,7 +336,7 @@ int Credits::isDifficultyUnlocked(DeckStats * stats)
found = 0;
char buffer[512];
char aiSmallDeckName[512];
sprintf(buffer, JGE_GET_RES("ai/baka/deck%i.txt").c_str(), nbAIDecks + 1);
sprintf(buffer, "ai/baka/deck%i.txt", nbAIDecks + 1);
if (fileExists(buffer))
{
found = 1;
@@ -486,12 +486,10 @@ int Credits::IsMoreAIDecksUnlocked(DeckStats * stats) {
{
found = 0;
char buffer[512];
sprintf(buffer, JGE_GET_RES("ai/baka/deck%i.txt").c_str(), nbdecks + 1);
wagic::ifstream file(buffer);
if (file)
sprintf(buffer, "ai/baka/deck%i.txt", nbdecks + 1);
if (JFileSystem::GetInstance()->FileExists(buffer))
{
found = 1;
file.close();
nbdecks++;
if (nbdecks > currentlyUnlocked)
return 1;

View File

@@ -114,11 +114,12 @@ void DeckStats::load(const std::string& filename)
{
return;
}
wagic::ifstream file(filename.c_str());
std::string s;
if (file)
std::string contents;
if (JFileSystem::GetInstance()->readIntoString(filename, contents))
{
std::stringstream stream(contents);
std::string s;
// get the associated player deck file:
int deckId = atoi(filename.substr(filename.find("_deck") + 5, filename.find(".txt")).c_str());
char buffer[512];
@@ -128,31 +129,30 @@ void DeckStats::load(const std::string& filename)
if (!playerDeckMetaData)
{
DebugTrace("DeckStats.cpp:CONSISTENCY ERROR: DeckStats are set, but no deck meta data");
file.close();
return;
}
// check if this player deck has already been profiled for manacolors
char next = file.peek();
char next = stream.peek();
string manaColorIndex = "";
if ( next == 'M')
{
std::getline(file, s );
std::getline(stream, s );
manaColorIndex = s.substr( s.find(":") + 1);
playerDeckMetaData->setColorIndex( manaColorIndex );
}
while (std::getline(file, s))
while (std::getline(stream, s))
{
string deckfile = s;
std::getline(file, s);
std::getline(stream, s);
int games = atoi(s.c_str());
std::getline(file, s);
std::getline(stream, s);
int victories = atoi(s.c_str());
next = file.peek();
next = stream.peek();
if ( next == 'M')
{
std::getline(file, s );
std::getline(stream, s );
manaColorIndex = s.substr( s.find(":") + 1);
}
if ( masterDeckStats[filename].find(deckfile) != masterDeckStats[filename].end())
@@ -162,16 +162,15 @@ void DeckStats::load(const std::string& filename)
DeckStat * newDeckStat = NEW DeckStat(games, victories, manaColorIndex);
(masterDeckStats[filename])[deckfile] = newDeckStat;
}
file.close();
}
}
void DeckStats::save(const std::string& filename)
{
std::ofstream file(filename.c_str());
char writer[512];
if (file)
std::ofstream file;
if (JFileSystem::GetInstance()->openForWrite(file, filename))
{
char writer[512];
map<string, DeckStat *> stats = masterDeckStats[currentDeck];
map<string, DeckStat *>::iterator it;
string manaColorIndex = "";
@@ -327,7 +326,7 @@ void StatsWrapper::initStatistics(string deckstats)
char smallDeckName[512];
ostringstream oss;
oss << "deck" << (nbDecks + 1);
string bakaDir = JGE_GET_RES("/ai/baka");
string bakaDir = "ai/baka/";
string deckFilename = oss.str();
sprintf(buffer, "%s/%s.txt", bakaDir.c_str(), deckFilename.c_str());
if (fileExists(buffer))

View File

@@ -28,11 +28,12 @@
#include "WFilter.h"
#include "Rules.h"
#include "ModRules.h"
#include "JFileSystem.h"
#define DEFAULT_DURATION .25
int GameApp::players[] = { 0, 0 };
int GameApp::HasMusic = 1;
bool GameApp::HasMusic = true;
JMusic * GameApp::music = NULL;
string GameApp::currentMusicFile = "";
string GameApp::systemError = "";
@@ -95,28 +96,22 @@ void GameApp::Create()
LOG("starting Game");
WResourceManager::Instance()->ResetCacheLimits();
//Find the Res folder
wagic::ifstream mfile("Res.txt");
string resPath;
if (mfile)
JFileSystem::init("User/", "Res/");
// Create User Folders (for write access) if they don't exist
{
bool found = false;
while (!found && std::getline(mfile, resPath))
const char* folders[] = { "ai", "ai/baka", "ai/baka/stats", "campaigns", "graphics", "lang", "packs", "player", "player/stats", "profiles", "rules", "sets", "settings", "sound", "sound/sfx", "themes"};
string userRoot = JFileSystem::GetInstance()->GetUserRoot();
MAKEDIR(userRoot.c_str());
for (size_t i = 0; i < sizeof(folders)/sizeof(folders[0]); ++i)
{
if (resPath[resPath.size() - 1] == '\r')
resPath.erase(resPath.size() - 1); //Handle DOS files
string testfile = resPath;
testfile.append("graphics/simon.dat");
if (fileExists(testfile.c_str()))
{
JFileSystem::GetInstance()->SetResourceRoot(trim(resPath));
found = true;
}
string current(folders[i]);
string folder = userRoot + current;
MAKEDIR(folder.c_str());
}
mfile.close();
}
LOG("Res Root:");
LOG(JFileSystem::GetInstance()->GetResourceRoot().c_str());
//Load Mod Rules before everything else
gModRules.load("rules/modrules.xml");
@@ -130,19 +125,8 @@ void GameApp::Create()
LOG("Checking for music files");
//Test for Music files presence
string filepath = JGE_GET_RES(WResourceManager::Instance()->musicFile("Track0.mp3"));
wagic::ifstream file(filepath.c_str());
if (file)
file.close();
else
HasMusic = 0;
filepath = JGE_GET_RES(WResourceManager::Instance()->musicFile("Track1.mp3"));
wagic::ifstream file2(filepath.c_str());
if (file2)
file2.close();
else
HasMusic = 0;
JFileSystem * jfs = JFileSystem::GetInstance();
HasMusic = jfs->FileExists(WResourceManager::Instance()->musicFile("Track0.mp3")) && jfs->FileExists(WResourceManager::Instance()->musicFile("Track1.mp3"));
LOG("Loading Textures");
LOG("--Loading menuicons.png");

View File

@@ -317,12 +317,13 @@ GameOptions::GameOptions(string filename)
int GameOptions::load()
{
wagic::ifstream file(mFilename.c_str());
std::string s;
if (file)
std::string contents;
if (JFileSystem::GetInstance()->readIntoString(mFilename, contents))
{
while (std::getline(file, s))
std::stringstream stream(contents);
string s;
while (std::getline(stream, s))
{
if (!s.size())
continue;
@@ -340,7 +341,6 @@ int GameOptions::load()
(*this)[id].read(val);
}
file.close();
}
// (PSY) Make sure that cheatmode is switched off for ineligible profiles:
if (options[Options::ACTIVE_PROFILE].str != SECRET_PROFILE)
@@ -369,8 +369,8 @@ int GameOptions::save()
(*this)[Options::CHEATMODEAIDECK].number = 0;
}
std::ofstream file(mFilename.c_str());
if (file)
std::ofstream file;
if (JFileSystem::GetInstance()->openForWrite(file, mFilename))
{
for (int x = 0; x < (int) values.size(); x++)
{
@@ -640,14 +640,15 @@ int GameSettings::save()
if (profileOptions)
{
//Force our directories to exist.
MAKEDIR(JGE_GET_RES("profiles").c_str());
string temp = profileFile("", "", false, false);
//Create a temp directory
// Erwan 2011/08/14: what does this really do? temp is never used.
/*
string temp = profileFile("", "", false);
MAKEDIR(temp.c_str());
temp += "/stats";
MAKEDIR(temp.c_str());
temp = profileFile(PLAYER_SETTINGS, "", false);
*/
profileOptions->save();
}
@@ -656,7 +657,7 @@ int GameSettings::save()
return 1;
}
string GameSettings::profileFile(string filename, string fallback, bool sanity, bool relative)
string GameSettings::profileFile(string filename, string fallback, bool sanity)
{
char buf[512];
string profile = (*this)[Options::ACTIVE_PROFILE].str;
@@ -666,30 +667,27 @@ string GameSettings::profileFile(string filename, string fallback, bool sanity,
//No file, return root of profile directory
if (filename == "")
{
sprintf(buf, "%sprofiles/%s", (relative ? "" : JGE_GET_RES("").c_str()), profile.c_str());
sprintf(buf, "profiles/%s", profile.c_str());
return buf;
}
//Return file
sprintf(buf, JGE_GET_RES("profiles/%s/%s").c_str(), profile.c_str(), filename.c_str());
sprintf(buf, "profiles/%s/%s", profile.c_str(), filename.c_str());
if (fileExists(buf))
{
if (relative)
sprintf(buf, "profiles/%s/%s", profile.c_str(), filename.c_str());
return buf;
}
}
else
{
//Use the default directory.
sprintf(buf, "%splayer%s%s", (relative ? "" : JGE_GET_RES("").c_str()), (filename == "" ? "" : "/"), filename.c_str());
sprintf(buf, "player%s%s", (filename == "" ? "" : "/"), filename.c_str());
return buf;
}
//Don't fallback if sanity checking is disabled..
if (!sanity)
{
sprintf(buf, "%sprofiles/%s%s%s", (relative ? "" : JGE_GET_RES("").c_str()), profile.c_str(), (filename == "" ? "" : "/"),
filename.c_str());
sprintf(buf, "profiles/%s%s%s", profile.c_str(), (filename == "" ? "" : "/"), filename.c_str());
return buf;
}
@@ -697,8 +695,7 @@ string GameSettings::profileFile(string filename, string fallback, bool sanity,
if (fallback == "")
return "";
sprintf(buf, "%s%s%s%s", (relative ? "" : JGE_GET_RES("").c_str()), fallback.c_str(), (filename == "" ? "" : "/"),
filename.c_str());
sprintf(buf, "%s%s%s", fallback.c_str(), (filename == "" ? "" : "/"), filename.c_str());
return buf;
}
@@ -711,7 +708,7 @@ void GameSettings::reloadProfile()
void GameSettings::checkProfile()
{
if (!globalOptions)
globalOptions = NEW GameOptions(JGE_GET_RES(GLOBAL_SETTINGS));
globalOptions = NEW GameOptions(GLOBAL_SETTINGS);
//If it doesn't exist, load current profile.
if (!profileOptions)
@@ -744,13 +741,13 @@ void GameSettings::checkProfile()
if (profileOptions)
{
//Force our directories to exist.
MAKEDIR(JGE_GET_RES("profiles").c_str());
string temp = profileFile("", "", false, false);
/*
string temp = profileFile("", "", false);
MAKEDIR(temp.c_str());
temp += "/stats";
MAKEDIR(temp.c_str());
temp = profileFile(PLAYER_SETTINGS, "", false);
*/
profileOptions->save();
}
}

View File

@@ -218,7 +218,7 @@ void GameStateDeckViewer::Start()
lastPos = 0;
lastTotal = 0;
pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(), MTGCollection());
pricelist = NEW PriceList("settings/prices.dat", MTGCollection());
playerdata = NEW PlayerData(MTGCollection());
myCollection = NEW DeckDataWrapper(playerdata->collection);
myCollection->Sort(WSrcCards::SORT_ALPHA);
@@ -321,7 +321,7 @@ void GameStateDeckViewer::saveDeck()
void GameStateDeckViewer::saveAsAIDeck(string deckName)
{
vector<DeckMetaData *> aiDecks = GameState::BuildDeckList(JGE_GET_RES("ai/baka"), "ai_baka", NULL);
vector<DeckMetaData *> aiDecks = GameState::BuildDeckList("ai/baka", "ai_baka", NULL);
int nbAiDecks = aiDecks.size() + 1;
aiDecks.clear();
@@ -335,7 +335,7 @@ void GameStateDeckViewer::saveAsAIDeck(string deckName)
else
oss << myDeck->parent->meta_desc;
string deckDesc = oss.str();
string filepath = JGE_GET_RES("ai/baka/");
string filepath = "ai/baka/";
filepath.append(defaultAiDeckName).append(".txt");
DebugTrace("saving AI deck " << filepath);
myDeck->save(filepath, true, deckName, deckDesc);
@@ -1496,7 +1496,7 @@ int GameStateDeckViewer::loadDeck(int deckid)
SAFE_DELETE(myDeck->parent);
SAFE_DELETE(myDeck);
}
myDeck = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(deckname, "", false, false).c_str(), MTGCollection()));
myDeck = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(deckname, "", false).c_str(), MTGCollection()));
// Check whether the cards in the deck are actually available in the player's collection:
int cheatmode = options[Options::CHEATMODE].number;

View File

@@ -102,7 +102,7 @@ void GameStateDuel::Start()
#ifdef TESTSUITE
SAFE_DELETE(testSuite);
testSuite = NEW TestSuite(JGE_GET_RES("test/_tests.txt").c_str(),MTGCollection());
testSuite = NEW TestSuite("test/_tests.txt",MTGCollection());
#endif
mGamePhase = DUEL_STATE_CHOOSE_DECK1;
@@ -156,7 +156,7 @@ void GameStateDuel::Start()
deckmenu->Add(MENUITEM_NEW_DECK, "Create your Deck!", desc);
}
premadeDeck = true;
fillDeckMenu(deckmenu, JGE_GET_RES("player/premade"));
fillDeckMenu(deckmenu, "player/premade");
}
else if (gModRules.general.hasDeckEditor())
{
@@ -181,7 +181,7 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, bool isAI, bool isNetwo
{
char deckFile[255];
if (premadeDeck)
sprintf(deckFile, JGE_GET_RES("player/premade/deck%i.txt").c_str(), decknb);
sprintf(deckFile, "player/premade/deck%i.txt", decknb);
else
sprintf(deckFile, "%s/deck%i.txt", options.profileFile().c_str(), decknb);
char deckFileSmall[255];
@@ -286,15 +286,7 @@ void GameStateDuel::End()
//TODO Move This to utils or ResourceManager. Don't we have more generic functions that can do that?
bool GameStateDuel::MusicExist(string FileName)
{
string filepath = JGE_GET_RES(WResourceManager::Instance()->musicFile(FileName));
wagic::ifstream file(filepath.c_str());
if (file)
{
file.close();
return true;
}
else
return false;
return FileExists(WResourceManager::Instance()->musicFile(FileName));
}
void GameStateDuel::ConstructOpponentMenu()
@@ -309,7 +301,7 @@ void GameStateDuel::ConstructOpponentMenu()
DeckManager * deckManager = DeckManager::GetInstance();
vector<DeckMetaData*> opponentDeckList;
int nbUnlockedDecks = options[Options::CHEATMODEAIDECK].number ? 1000 : options[Options::AIDECKS_UNLOCKED].number;
opponentDeckList = fillDeckMenu(opponentMenu, JGE_GET_RES("ai/baka"), "ai_baka", mPlayers[0], nbUnlockedDecks);
opponentDeckList = fillDeckMenu(opponentMenu, "ai/baka", "ai_baka", mPlayers[0], nbUnlockedDecks);
deckManager->updateMetaDataList(&opponentDeckList, true);
opponentMenu->Add(MENUITEM_CANCEL, "Cancel", _("Choose a different player deck").c_str());
opponentDeckList.clear();

View File

@@ -71,10 +71,8 @@ GameStateMenu::~GameStateMenu()
void GameStateMenu::Create()
{
mDip = NULL;
mGuiController = NULL;
mReadConf = 0;
mCurrentSetName[0] = 0;
//load all the icon images. Menu icons are managed, so we can do this here.
int n = 0;
@@ -97,8 +95,10 @@ void GameStateMenu::Create()
string lang = options[Options::LANG].str;
if (lang.size())
{
lang = JGE_GET_RES("lang/") + lang + ".txt";
if (fileExists(lang.c_str()))
string langpath = "lang/";
langpath.append(lang);
langpath.append(".txt");
if (JFileSystem::GetInstance()->FileExists(langpath))
langChosen = true;
}
if (!langChosen)
@@ -110,6 +110,8 @@ void GameStateMenu::Create()
splashTex = NULL;
JFileSystem::GetInstance()->scanfolder("sets/", setFolders);
mCurrentSetFolderIndex = 0;
}
void GameStateMenu::Destroy()
@@ -265,35 +267,27 @@ void GameStateMenu::fillScroller()
scrollerSet = 1;
scroller->setRandom();
}
void GameStateMenu::resetDirectory()
int GameStateMenu::nextSetFolder(const string & root, const string & file)
{
if (mDip != NULL)
bool found = false;
while (!found && (mCurrentSetFolderIndex < setFolders.size()))
{
closedir(mDip);
mDip = NULL;
}
}
int GameStateMenu::nextDirectory(const char * root, const char * file)
{
int found = 0;
if (!mDip)
{
mDip = opendir(root);
vector<string> folders;
folders.push_back(root);
folders.push_back(setFolders[mCurrentSetFolderIndex]);
mCurrentSetFileName = buildFilePath(folders, file);
if (JFileSystem::GetInstance()->FileExists(mCurrentSetFileName))
{
mCurrentSetName = setFolders[mCurrentSetFolderIndex];
if (mCurrentSetName.length() && (mCurrentSetName[mCurrentSetName.length() - 1] == '/'))
mCurrentSetName.resize(mCurrentSetName.length() - 1);
found = true;
}
mCurrentSetFolderIndex++;
}
while (!found && (mDit = readdir(mDip)))
{
sprintf(mCurrentSetFileName, "%s/%s/%s", root, mDit->d_name, file);
wagic::ifstream file(mCurrentSetFileName);
if (file)
{
sprintf(mCurrentSetName, "%s", mDit->d_name);
file.close();
found = 1;
}
}
if (!found)
resetDirectory();
return found;
}
@@ -311,9 +305,8 @@ string GameStateMenu::loadRandomWallpaper()
return wallpaper;
vector<string> wallpapers;
wagic::ifstream file(JGE_GET_RES("graphics/wallpapers.txt").c_str());
if (!file)
izfstream file;
if (! JFileSystem::GetInstance()->openForRead(file, "graphics/wallpapers.txt"))
return wallpaper;
string s;
@@ -325,6 +318,7 @@ string GameStateMenu::loadRandomWallpaper()
s.erase(s.size() - 1); //Handle DOS files
wallpapers.push_back(s);
}
file.close();
int rnd = rand() % (wallpapers.size());
wallpaper = wallpapers[rnd];
@@ -359,66 +353,60 @@ void GameStateMenu::loadLangMenu()
subMenuController = NEW SimpleMenu(MENU_LANGUAGE_SELECTION, this, Fonts::MENU_FONT, 150, 60);
if (!subMenuController)
return;
resetDirectory();
if (!mDip)
{
mDip = opendir(JGE_GET_RES("lang").c_str());
}
while ((mDit = readdir(mDip)))
vector<string> langFiles = JFileSystem::GetInstance()->scanfolder("lang/");
for (size_t i = 0; i < langFiles.size(); ++i)
{
string filename = JGE_GET_RES("lang/");
filename += mDit->d_name;
wagic::ifstream file(filename.c_str());
izfstream file;
string filePath = "lang/";
filePath.append(langFiles[i]);
if (! JFileSystem::GetInstance()->openForRead(file, filePath))
continue;
string s;
string lang;
if (file)
if (std::getline(file, s))
{
if (std::getline(file, s))
{
lang = getLang(s);
}
file.close();
lang = getLang(s);
}
file.close();
if (lang.size())
{
langChoices = true;
string filen = mDit->d_name;
string filen = langFiles[i];
langs.push_back(filen.substr(0, filen.size() - 4));
subMenuController->Add(langs.size(), lang.c_str());
}
}
resetDirectory();
LOG("GameStateMenu::loadLangMenu - Done");
}
void GameStateMenu::listPrimitives()
{
LOG("GameStateMenu::listPrimitives");
resetDirectory();
if (!mDip)
{
mDip = opendir(JGE_GET_RES("sets/primitives/").c_str());
}
vector<string> primitiveFiles = JFileSystem::GetInstance()->scanfolder("sets/primitives/");
if (!mDip)
if (!primitiveFiles.size())
{
DebugTrace("GameStateMenu.cpp:WARNING:Primitives folder is missing");
primitivesLoadCounter = 0;
return;
}
while ((mDit = readdir(mDip)))
for (size_t i = 0; i < primitiveFiles.size(); ++i)
{
string filename = JGE_GET_RES("sets/primitives/");
filename += mDit->d_name;
wagic::ifstream file(filename.c_str());
if (!file)
string filename = "sets/primitives/";
filename.append(primitiveFiles[i]);
izfstream file;
if (! JFileSystem::GetInstance()->openForRead(file, filename))
continue;
file.close();
primitives.push_back(filename);
}
resetDirectory();
primitivesLoadCounter = 0;
LOG("GameStateMenu::listPrimitives - Done");
}
@@ -513,13 +501,13 @@ void GameStateMenu::Update(float dt)
primitivesLoadCounter = primitives.size() + 1;
if (mReadConf)
{
MTGCollection()->load(mCurrentSetFileName, mCurrentSetName);
MTGCollection()->load(mCurrentSetFileName.c_str(), mCurrentSetName.c_str());
}
else
{
mReadConf = 1;
}
if (!nextDirectory(JGE_GET_RES("sets/").c_str(), "_cards.dat"))
if (!nextSetFolder("sets/", "_cards.dat"))
{
//Remove temporary translations
Translator::GetInstance()->tempValues.clear();
@@ -537,10 +525,8 @@ void GameStateMenu::Update(float dt)
splashTex = NULL;
//check for deleted collection / first-timer
wagic::ifstream file(options.profileFile(PLAYER_COLLECTION).c_str());
if (file)
if (JFileSystem::GetInstance()->FileExists(options.profileFile(PLAYER_COLLECTION)))
{
file.close();
currentState = MENU_STATE_MAJOR_MAINMENU;
}
else
@@ -551,7 +537,6 @@ void GameStateMenu::Update(float dt)
//Reload list of unlocked sets, now that we know about the sets.
options.reloadProfile();
genNbCardsStr();
resetDirectory();
//All major things have been loaded, resize the cache to use it as efficiently as possible
WResourceManager::Instance()->ResetCacheLimits();
}
@@ -736,9 +721,9 @@ void GameStateMenu::Render()
}
char text[512];
if (mCurrentSetName[0])
if (mCurrentSetName.size())
{
sprintf(text, _("LOADING SET: %s").c_str(), mCurrentSetName);
sprintf(text, _("LOADING SET: %s").c_str(), mCurrentSetName.c_str());
}
else
{
@@ -929,8 +914,6 @@ ostream& GameStateMenu::toString(ostream& out) const
<< " ; currentState : " << currentState
<< " ; mVolume : " << mVolume
<< " ; nbcardsStr : " << nbcardsStr
<< " ; mDip : " << mDip
<< " ; mDit : " << mDit
<< " ; mCurrentSetName : " << mCurrentSetName
<< " ; mCurrentSetFileName : " << mCurrentSetFileName
<< " ; mReadConf : " << mReadConf

View File

@@ -106,7 +106,7 @@ void GameStateShop::Start()
MTGAllCards * ac = MTGCollection();
playerdata = NEW PlayerData(ac);
myCollection = NEW DeckDataWrapper(playerdata->collection);
pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(), ac);
pricelist = NEW PriceList("settings/prices.dat", ac);
for (int i = 0; i < SHOP_SLOTS; i++)
{
WGuiCardDistort * dist;

View File

@@ -22,24 +22,17 @@ void GameStateStory::loadStoriesMenu(const char * root)
{
SAFE_DELETE(menu);
stories.clear();
DIR *mDip;
struct dirent *mDit;
vector<string>subFolders = JFileSystem::GetInstance()->scanfolder(root);
mDip = opendir(root);
while ((mDit = readdir(mDip)))
for (size_t i = 0; i < subFolders.size(); ++i)
{
char buffer[4096];
sprintf(buffer, "%s%s/story.xml", root, mDit->d_name);
wagic::ifstream file(buffer);
if (file)
string filename = root + subFolders[i] + "story.xml";
if (FileExists(filename))
{
string fname = mDit->d_name;
stories.push_back(fname);
file.close();
subFolders[i].resize(subFolders[i].length() - 1); //remove trailing slash
stories.push_back(subFolders[i]);
}
}
closedir(mDip);
switch (stories.size())
{
@@ -63,7 +56,7 @@ void GameStateStory::Start()
{
flow = NULL;
menu = NULL;
loadStoriesMenu(JGE_GET_RES("campaigns/").c_str());
loadStoriesMenu("campaigns/");
}
void GameStateStory::Update(float dt)

View File

@@ -1047,6 +1047,7 @@ JSample * MTGCardInstance::getSample()
for (int i = types.size() - 1; i > 0; i--)
{
string type = Subtypes::subtypesList->find(types[i]);
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
type = type + ".wav";
js = WResourceManager::Instance()->RetrieveSample(type);
if (js)

View File

@@ -311,41 +311,6 @@ void MTGAllCards::init()
initCounters();
}
void MTGAllCards::loadPrimitives(const char *root_directory)
{
DIR *dir = opendir(root_directory);
struct dirent *dit;
while ((dit = readdir(dir)))
{
char fullname[1000];
sprintf(fullname, "%s/%s", root_directory, dit->d_name);
wagic::ifstream file(fullname);
if (!file)
continue;
file.close();
MTGCollection()->load(fullname);
}
closedir(dir);
}
void MTGAllCards::loadSets(const char *root_directory, const char* filename)
{
DIR *dir = opendir(root_directory);
struct dirent *dit;
while ((dit = readdir(dir)))
{
char fullname[1000];
sprintf(fullname, "%s/%s/%s", root_directory, dit->d_name, filename);
wagic::ifstream file(fullname);
if (!file)
continue;
file.close();
MTGCollection()->load(fullname, dit->d_name);
}
closedir(dir);}
int MTGAllCards::load(const char * config_file, const char * set_name, int autoload)
{
conf_read_mode = 0;
@@ -353,17 +318,10 @@ int MTGAllCards::load(const char * config_file, const char * set_name, int autol
MTGSetInfo *si = setlist.getInfo(set_id);
int lineNumber = 0;
wagic::ifstream setFile(config_file, ios::in | ios::ate);
if (!setFile) return total_cards;
streampos fileSize = setFile.tellg();
setFile.seekg(0, ios::beg);
std::string contents;
contents.resize((std::string::size_type) fileSize);
setFile.read(&contents[0], fileSize);
if (!JFileSystem::GetInstance()->readIntoString(config_file, contents))
return total_cards;
std::stringstream stream(contents);
string s;
while (true)
@@ -379,7 +337,14 @@ int MTGAllCards::load(const char * config_file, const char * set_name, int autol
if (s[0] == '[')
{
currentGrade = Constants::GRADE_SUPPORTED; // Default value
conf_read_mode = ('m' == s[1]) ? MTGAllCards::READ_METADATA : MTGAllCards::READ_CARD; // M for metadata.
if (s.size() < 2)
{
DebugTrace("FATAL: Card file incorrect");
}
else
{
conf_read_mode = ('m' == s[1]) ? MTGAllCards::READ_METADATA : MTGAllCards::READ_CARD; // M for metadata.
}
}
else
{
@@ -679,7 +644,7 @@ MTGDeck::MTGDeck(MTGAllCards * _allcards)
int MTGDeck::totalPrice()
{
int total = 0;
PriceList * pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(), MTGCollection());
PriceList * pricelist = NEW PriceList("settings/prices.dat", MTGCollection());
map<int, int>::iterator it;
for (it = cards.begin(); it != cards.end(); it++)
{
@@ -699,14 +664,16 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
size_t dot = filename.find(".");
meta_name = filename.substr(slash + 1, dot - slash - 1);
meta_id = atoi(meta_name.substr(4).c_str());
wagic::ifstream file(config_file);
std::string s;
if (file)
std::string contents;
if (JFileSystem::GetInstance()->readIntoString(config_file, contents))
{
while (std::getline(file, s))
std::stringstream stream(contents);
std::string s;
while (std::getline(stream, s))
{
if (!s.size()) continue;
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
if (!s.size()) continue;
if (s[0] == '#')
{
size_t found = s.find("NAME:");
@@ -773,11 +740,10 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
DebugTrace("could not find Card matching name: " << s);
}
}
file.close();
}
else
{
//TODO Error management
DebugTrace("FATAL:MTGDeck.cpp:MTGDeck - can't load deck file");
}
}
@@ -979,10 +945,10 @@ int MTGDeck::save(const string& destFileName, bool useExpandedDescriptions, cons
{
string tmp = destFileName;
tmp.append(".tmp"); //not thread safe
std::ofstream file(tmp.c_str());
char writer[512];
if (file)
std::ofstream file;
if (JFileSystem::GetInstance()->openForWrite(file, tmp))
{
char writer[512];
DebugTrace("Saving Deck: " << deckTitle << " to " << destFileName );
if (meta_name.size())
{
@@ -1025,8 +991,7 @@ int MTGDeck::save(const string& destFileName, bool useExpandedDescriptions, cons
}
}
file.close();
std::remove(destFileName.c_str());
rename(tmp.c_str(), destFileName.c_str());
JFileSystem::GetInstance()->Rename(tmp, destFileName);
}
return 1;
}
@@ -1272,7 +1237,7 @@ MTGSetInfo::MTGSetInfo(string _id)
counts[i] = 0;
char myFilename[4096];
sprintf(myFilename, JGE_GET_RES("sets/%s/booster.txt").c_str(), id.c_str());
sprintf(myFilename, "sets/%s/booster.txt", id.c_str());
mPack = NEW MTGPack(myFilename);
if (!mPack->isValid())
{

View File

@@ -287,18 +287,15 @@ MTGPack * MTGPacks::randomPack(int key)
}
void MTGPacks::loadAll()
{
DIR *mDip = opendir(JGE_GET_RES("packs/").c_str());
struct dirent *mDit;
if (!mDip)
return;
while ((mDit = readdir(mDip)))
vector<string>packFiles = JFileSystem::GetInstance()->scanfolder("packs/");
for (size_t i = 0; i < packFiles.size(); ++i)
{
string relative = packFiles[i];
char myFilename[4096];
sprintf(myFilename, JGE_GET_RES("packs/%s").c_str(), mDit->d_name);
if (mDit->d_name[0] == '.')
sprintf(myFilename, "packs/%s",relative.c_str());
if (relative[0] == '.')
continue;
if (!strcmp(mDit->d_name, "default_booster.txt"))
if (!strcmp(relative.c_str(), "default_booster.txt"))
continue;
MTGPack * p = NEW MTGPack(myFilename);
if (!p->isValid())
@@ -308,7 +305,6 @@ void MTGPacks::loadAll()
}
packs.push_back(p);
}
closedir(mDip);
}
string MTGPack::getName()
{
@@ -356,7 +352,7 @@ MTGPack * MTGPacks::getDefault()
{
if (!defaultBooster.isValid())
{
defaultBooster.load(JGE_GET_RES("packs/default_booster.txt"));
defaultBooster.load("packs/default_booster.txt");
defaultBooster.unlockStatus = 1;
if (!defaultBooster.isValid())
{

View File

@@ -10,24 +10,15 @@ ModRules gModRules;
bool ModRules::load(string filename)
{
JFileSystem *fileSystem = JFileSystem::GetInstance();
if (!fileSystem) return false;
if (!fileSystem->OpenFile(filename.c_str()))
std::string xmlBuffer;
if (! JFileSystem::GetInstance()->readIntoString(filename, xmlBuffer))
{
DebugTrace("FATAL: " << filename << "Does not exist");
DebugTrace("FATAL: cannot find modrules.xml");
return false;
}
int size = fileSystem->GetFileSize();
char *xmlBuffer = NEW char[size];
fileSystem->ReadFile(xmlBuffer, size);
TiXmlDocument doc;
doc.Parse(xmlBuffer);
fileSystem->CloseFile();
delete[] xmlBuffer;
doc.Parse(xmlBuffer.c_str());
for (TiXmlNode* node = doc.FirstChild(); node; node = node->NextSibling())
{

View File

@@ -108,7 +108,7 @@ void OptionSelect::addSelection(string s)
//OptionProfile
const string OptionProfile::DIRTESTER = "collection.dat";
OptionProfile::OptionProfile(GameApp * _app, JGuiListener * jgl) :
OptionDirectory(JGE_GET_RES("profiles"), Options::ACTIVE_PROFILE, "Profile", DIRTESTER)
OptionDirectory("profiles/", Options::ACTIVE_PROFILE, "Profile", DIRTESTER)
{
app = _app;
listener = jgl;
@@ -165,16 +165,16 @@ void OptionProfile::populate()
PlayerData * pdata = NEW PlayerData(MTGCollection());
int unlocked = 0, sets = setlist.size();
wagic::ifstream file(options.profileFile(PLAYER_SETTINGS).c_str());
std::string s;
if (file)
std::string contents;
if (JFileSystem::GetInstance()->readIntoString(options.profileFile(PLAYER_SETTINGS), contents))
{
while (std::getline(file, s))
std::stringstream stream(contents);
std::string s;
while (std::getline(stream, s))
{
if (s.substr(0, 9) == "unlocked_")
unlocked++;
}
file.close();
}
options[Options::ACTIVE_PROFILE] = temp;
@@ -321,47 +321,44 @@ void OptionLanguage::confirmChange(bool confirmed)
void OptionLanguage::Reload()
{
struct dirent *mDit;
DIR *mDip;
mDip = opendir(JGE_GET_RES("lang").c_str());
while ((mDit = readdir(mDip)))
vector<string> langFiles = JFileSystem::GetInstance()->scanfolder("lang/");
for (size_t i = 0; i < langFiles.size(); ++i)
{
string filename = JGE_GET_RES("lang/");
filename += mDit->d_name;
wagic::ifstream file(filename.c_str());
izfstream file;
string filePath = "lang/";
filePath.append(langFiles[i]);
if (! JFileSystem::GetInstance()->openForRead(file, filePath))
continue;
string s;
string lang;
if (file)
if (std::getline(file, s))
{
if (std::getline(file, s))
if (!s.size())
{
if (!s.size())
{
lang = "";
}
else
{
if (s[s.size() - 1] == '\r')
s.erase(s.size() - 1); //Handle DOS files
size_t found = s.find("#LANG:");
if (found != 0)
lang = "";
else
lang = s.substr(6);
}
lang = "";
}
else
{
if (s[s.size() - 1] == '\r')
s.erase(s.size() - 1); //Handle DOS files
size_t found = s.find("#LANG:");
if (found != 0)
lang = "";
else
lang = s.substr(6);
}
file.close();
}
file.close();
if (lang.size())
{
string filen = mDit->d_name;
string filen = langFiles[i];
addSelection(filen.substr(0, filen.size() - 4), lang);
}
}
closedir(mDip);
initSelections();
}
@@ -398,59 +395,39 @@ bool OptionLanguage::Selectable()
//OptionDirectory
void OptionDirectory::Reload()
{
DIR *mDip;
struct dirent *mDit;
char buf[PATH_MAX];
mDip = opendir(root.c_str());
if (!mDip)
return;
while ((mDit = readdir(mDip)))
vector<string> subfolders = JFileSystem::GetInstance()->scanfolder(root);
for (size_t i = 0; i < subfolders.size(); ++i)
{
sprintf(buf, "%s/%s/%s", root.c_str(), mDit->d_name, type.c_str());
wagic::ifstream file(buf);
if (!file)
string filename = root + "/" + subfolders[i] + "/" + type;
if (!JFileSystem::GetInstance()->FileExists(filename))
continue;
file.close();
if (find(selections.begin(), selections.end(), mDit->d_name) == selections.end())
addSelection(mDit->d_name);
if (find(selections.begin(), selections.end(), subfolders[i]) == selections.end())
addSelection(subfolders[i]);
}
closedir(mDip);
mDip = NULL;
initSelections();
}
OptionDirectory::OptionDirectory(string root, int id, string displayValue, string type) :
OptionSelect(id, displayValue), root(root), type(type)
{
DIR *mDip;
struct dirent *mDit;
char buf[PATH_MAX];
mDip = opendir(root.c_str());
if (!mDip)
return;
while ((mDit = readdir(mDip)))
vector<string> subfolders = JFileSystem::GetInstance()->scanfolder(root);
for (size_t i = 0; i < subfolders.size(); ++i)
{
sprintf(buf, "%s/%s/%s", root.c_str(), mDit->d_name, type.c_str());
wagic::ifstream file(buf);
if (!file)
continue;
file.close();
addSelection(mDit->d_name);
string subfolder = subfolders[i].substr(0, subfolders[i].length() - 1); //remove trailing "/"
vector<string> path;
path.push_back(root);
path.push_back(subfolder);
string filePath = buildFilePath(path, type);
if (JFileSystem::GetInstance()->FileExists(filePath))
addSelection(subfolder);
}
closedir(mDip);
mDip = NULL;
initSelections();
}
const string OptionTheme::DIRTESTER = "preview.png";
OptionTheme::OptionTheme(OptionThemeStyle * style) :
OptionDirectory(JGE_GET_RES("themes"), Options::ACTIVE_THEME, "Current Theme", DIRTESTER)
OptionDirectory("themes", Options::ACTIVE_THEME, "Current Theme", DIRTESTER)
{
addSelection("Default");
sort(selections.begin(), selections.end());
@@ -492,20 +469,20 @@ void OptionTheme::Render()
author = "";
bChecked = true;
if (selections[value] == "Default")
sprintf(buf, "%s", JGE_GET_RES("graphics/themeinfo.txt").c_str());
sprintf(buf, "%s", "graphics/themeinfo.txt");
else
sprintf(buf, "%s%s", JGE_GET_RES("themes/%s/themeinfo.txt").c_str(), selections[value].c_str());
wagic::ifstream file(buf);
if (file)
sprintf(buf, "themes/%s/themeinfo.txt", selections[value].c_str());
string contents;
if (JFileSystem::GetInstance()->readIntoString(buf, contents))
{
std::stringstream stream(contents);
string temp;
std::getline(file, temp);
std::getline(stream, temp);
for (unsigned int x = 0; x < 17 && x < temp.size(); x++)
{
if (isprint(temp[x])) //Clear stuff that breaks mFont->DrawString, cuts to 16 chars.
author += temp[x];
}
file.close();
}
}
sprintf(buf, _("Theme: %s").c_str(), selections[value].c_str());

View File

@@ -24,11 +24,12 @@ void PlayerData::init()
//CREDITS
credits = 3000; //Default value
wagic::ifstream file(options.profileFile(PLAYER_SAVEFILE).c_str());
std::string s;
if (file)
std::string contents;
if (JFileSystem::GetInstance()->readIntoString(options.profileFile(PLAYER_SAVEFILE), contents))
{
if (std::getline(file, s))
std::stringstream stream(contents);
std::string s;
if (std::getline(stream, s))
{
credits = atoi(s.c_str());
}
@@ -38,7 +39,7 @@ void PlayerData::init()
}
//Story Saves
while (std::getline(file, s))
while (std::getline(stream, s))
{
if (!s.size()) continue;
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
@@ -54,7 +55,6 @@ void PlayerData::init()
key = key.substr(2);
storySaves[key] = value;
}
file.close();
}
taskList = NEW TaskList(options.profileFile(PLAYER_TASKS).c_str());
@@ -62,10 +62,10 @@ void PlayerData::init()
int PlayerData::save()
{
std::ofstream file(options.profileFile(PLAYER_SAVEFILE).c_str());
char writer[512];
if (file)
std::ofstream file;
if (JFileSystem::GetInstance()->openForWrite(file, options.profileFile(PLAYER_SAVEFILE)))
{
char writer[512];
sprintf(writer, "%i\n", credits);
file << writer;

View File

@@ -10,17 +10,17 @@ PriceList::PriceList(const char * _filename, MTGAllCards * _collection) :
collection(_collection)
{
filename = _filename;
wagic::ifstream file(_filename);
std::string cardid;
std::string price;
if (file)
std::string contents;
if (JFileSystem::GetInstance()->readIntoString(filename, contents))
{
while (std::getline(file, cardid))
std::stringstream stream(contents);
std::string cardid;
std::string price;
while (std::getline(stream, cardid))
{
std::getline(file, price);
std::getline(stream, price);
prices[atoi(cardid.c_str())] = atoi(price.c_str());
}
file.close();
}
if (randomKey == 0) randomKey = rand();
}
@@ -31,10 +31,10 @@ PriceList::~PriceList()
int PriceList::save()
{
std::ofstream file(filename.c_str());
char writer[20];
if (file)
std::ofstream file;
if (JFileSystem::GetInstance()->openForWrite(file, filename))
{
char writer[20];
map<int, int>::iterator it = prices.begin();
while (it != prices.end())
{

View File

@@ -13,7 +13,6 @@
#include "AIPlayer.h"
#include <JLogger.h>
vector<Rules *> Rules::RulesList = vector<Rules *>();
//Sorting by dissplayName
@@ -35,13 +34,11 @@ Rules * Rules::getRulesByFilename(string _filename)
int Rules::loadAllRules()
{
DIR *dip = opendir(JGE_GET_RES("rules").c_str());
struct dirent *dit;
while ((dit = readdir(dip)))
vector<string> rulesFiles = JFileSystem::GetInstance()->scanfolder("rules");
for (size_t i = 0; i < rulesFiles.size(); ++i)
{
Rules * rules = NEW Rules();
if (rules->load(dit->d_name))
if (rules->load(rulesFiles[i]))
{
RulesList.push_back(rules);
}
@@ -53,7 +50,6 @@ int Rules::loadAllRules()
//Kind of a hack here, we sort Rules alphabetically because it turns out to be matching
// The historical order of Game modes: Classic, Momir Basic, Random 1, Random 2, Story
std::sort(RulesList.begin(),RulesList.end(),RulesMenuCmp_);
closedir(dip);
return 1;
}
@@ -597,22 +593,23 @@ int Rules::load(string _filename)
}
else
{
sprintf(c_filename, JGE_GET_RES("rules/%s").c_str(), _filename.c_str());
sprintf(c_filename, "rules/%s", _filename.c_str());
}
wagic::ifstream file(c_filename);
std::string contents;
if (!JFileSystem::GetInstance()->readIntoString(c_filename, contents))
return 0;
std::stringstream stream(contents);
std::string s;
int state = PARSE_UNDEFINED;
// std::cout << std::endl << std::endl << "!!!" << file << std::endl << std::endl;
if (!file) return 0;
cleanup();
while (std::getline(file, s))
while (std::getline(stream, s))
{
if (!s.size()) continue;
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
if (!s.size()) continue;
if (s[0] == '#') continue;
string scopy = s;
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
@@ -689,7 +686,6 @@ int Rules::load(string _filename)
break;
}
}
file.close();
return 1;
}

View File

@@ -302,7 +302,7 @@ void StoryDuel::init()
Player * players[2];
char folder[255], deckFile[255], deckFileSmall[255];
sprintf(folder, JGE_GET_RES(CAMPAIGNS_FOLDER"%s/%s").c_str(), mParent->folder.c_str(), pageId.c_str());
sprintf(folder, CAMPAIGNS_FOLDER"%s/%s", mParent->folder.c_str(), pageId.c_str());
sprintf(deckFile, "%s/deck.txt", folder);
sprintf(deckFileSmall, "campaign_%s", mParent->folder.c_str());

View File

@@ -45,9 +45,15 @@ void StyleManager::loadRules()
{
killRules();
//TODO Placeholder until XML format available.
string filename = JGE_GET_RES(WResourceManager::Instance()->graphicsFile("style.txt"));
TiXmlDocument xmlfile(filename.c_str());
if (!xmlfile.LoadFile()) return;
string filename = WResourceManager::Instance()->graphicsFile("style.txt");
std::string xmlBuffer;
if (! JFileSystem::GetInstance()->readIntoString(filename, xmlBuffer))
return;
TiXmlDocument xmlfile;
xmlfile.Parse(xmlBuffer.c_str());
TiXmlHandle hDoc(&xmlfile);
TiXmlElement * pRule;
for (pRule = hDoc.FirstChildElement().Element(); pRule != NULL; pRule = pRule->NextSiblingElement())

View File

@@ -160,7 +160,7 @@ void Task::LoadAIDeckNames()
{
found = 0;
std::ostringstream stream;
stream << JGE_GET_RES("ai/baka") << "/deck" << nbDecks + 1 << ".txt";
stream << "ai/baka" << "/deck" << nbDecks + 1 << ".txt";
if (fileExists(stream.str().c_str()))
{
found = 1;
@@ -281,8 +281,8 @@ int TaskList::save(string _fileName)
return -1;
}
std::ofstream file(fileName.c_str());
if (file)
std::ofstream file;
if (JFileSystem::GetInstance()->openForWrite(file, fileName))
{
#if defined (WIN32) || defined (LINUX)
DebugTrace("\nsaving tasks\n");
@@ -309,48 +309,39 @@ int TaskList::load(string _fileName)
}
if (fileName == "")
{
#if defined (WIN32) || defined (LINUX)
DebugTrace("\nTaskList::load: No filename specified\n");
#endif
return -1;
}
wagic::ifstream file(fileName.c_str());
std::string s;
if (file)
std::string contents;
if (!JFileSystem::GetInstance()->readIntoString(fileName, contents))
{
while (std::getline(file, s))
{
if (!s.size()) continue;
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
if (s[0] == '#')
{
continue;
}
task = Task::createFromStr(s);
if (task)
{
this->addTask(task);
}
else
{
#if defined (WIN32) || defined (LINUX)
DebugTrace("\nTaskList::load: error creating task\n");
#endif
}
}
file.close();
}
else
{
#if defined (WIN32) || defined (LINUX)
DebugTrace("\nTaskList::load: Failed to open file\n");
#endif
return -1;
}
std::stringstream stream(contents);
std::string s;
while (std::getline(stream, s))
{
if (!s.size()) continue;
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
if (s[0] == '#')
{
continue;
}
task = Task::createFromStr(s);
if (task)
{
this->addTask(task);
}
else
{
DebugTrace("\nTaskList::load: error creating task\n");
}
}
return 1;
}

View File

@@ -436,8 +436,8 @@ DebugTrace("TESTUITE Init Game Done !");
}
int TestSuite::Log(const char * text)
{
ofstream file(JGE_GET_RES("test/results.html").c_str(), ios_base::app);
if (file)
ofstream file;
if (JFileSystem::GetInstance()->openForWrite(file, "test/results.html", ios_base::app))
{
file << text;
file << "\n";
@@ -555,7 +555,7 @@ TestSuite::TestSuite(const char * filename, MTGAllCards* _collection)
{
collection = _collection;
timerLimit = 0;
wagic::ifstream file(filename);
std::string s;
nbfiles = 0;
currentfile = 0;
@@ -567,9 +567,12 @@ TestSuite::TestSuite(const char * filename, MTGAllCards* _collection)
seed = 0;
forceAbility = false;
aiMaxCalls = -1;
if (file)
std::string contents;
if (JFileSystem::GetInstance()->readIntoString(filename, contents))
{
while (std::getline(file, s))
std::stringstream stream(contents);
while (std::getline(stream, s))
{
if (!s.size()) continue;
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
@@ -581,11 +584,10 @@ TestSuite::TestSuite(const char * filename, MTGAllCards* _collection)
}
if (s[0] == '*' && s[1] == '/') comment = 0;
}
file.close();
}
ofstream file2(JGE_GET_RES("/test/results.html").c_str());
if (file2)
ofstream file2;
if (JFileSystem::GetInstance()->openForWrite(file2, "/test/results.html"))
{
file2 << "<html><head>";
#ifdef WIN32
@@ -662,18 +664,20 @@ int TestSuite::load(const char * _filename)
forceAbility = false;
gameType = GAME_TYPE_CLASSIC;
char filename[4096];
sprintf(filename, JGE_GET_RES("/test/%s").c_str(), _filename);
wagic::ifstream file(filename);
sprintf(filename, "test/%s", _filename);
std::string s;
loadRandValues("");
int state = -1;
// std::cout << std::endl << std::endl << "!!!" << file << std::endl << std::endl;
if (file)
std::string contents;
if (JFileSystem::GetInstance()->readIntoString(filename, contents))
{
std::stringstream stream(contents);
cleanup();
while (std::getline(file, s))
while (std::getline(stream, s))
{
if (!s.size()) continue;
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
@@ -786,7 +790,6 @@ int TestSuite::load(const char * _filename)
break;
}
}
file.close();
}
else
{

View File

@@ -42,10 +42,10 @@ Translator::~Translator()
{
#if defined DEBUG_TRANSLATE
if (!checkMisses) return;
std::ofstream file(JGE_GET_RES("lang/missing.txt").c_str());
char writer[4096];
if (file)
std::ofstream file;
if (JFileSystem::GetInstance()->openForWrite(file, "lang/missing.txt"))
{
char writer[4096];
map<string,int>::iterator it;
for (it = missingValues.begin(); it!=missingValues.end(); it++)
{
@@ -65,16 +65,18 @@ Translator::Translator()
void Translator::load(string filename, map<string, string> * dictionary)
{
wagic::ifstream file(filename.c_str());
if (file)
std::string contents;
if (JFileSystem::GetInstance()->readIntoString(filename, contents))
{
std::stringstream stream(contents);
string s;
initDone = true;
#if defined DEBUG_TRANSLATE
checkMisses = 1;
#endif
while (std::getline(file, s))
while (std::getline(stream, s))
{
if (!s.size()) continue;
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
@@ -84,17 +86,16 @@ void Translator::load(string filename, map<string, string> * dictionary)
string s2 = s.substr(found + 1);
(*dictionary)[s1] = s2;
}
file.close();
}
#if defined DEBUG_TRANSLATE
if (!checkMisses) return;
wagic::ifstream file2(JGE_GET_RES("lang/dontcare.txt").c_str());
if(file2)
if (JFileSystem::GetInstance()->readIntoString("lang/dontcare.txt", contents))
{
std::stringstream stream(contents);
string s;
while(std::getline(file2,s))
while(std::getline(stream,s))
{
if (!s.size()) continue;
if (s[s.size()-1] == '\r') s.erase(s.size()-1); //Handle DOS files
@@ -103,7 +104,6 @@ void Translator::load(string filename, map<string, string> * dictionary)
s = s.substr(0,found);
dontCareValues[s] = 1;
}
file2.close();
}
#endif
}
@@ -112,7 +112,7 @@ void Translator::initCards()
{
string lang = options[Options::LANG].str;
if (!lang.size()) return;
string cards_dict = JGE_GET_RES("lang/") + lang + "_cards.txt";
string cards_dict = "lang/" + lang + "_cards.txt";
load(cards_dict, &tempValues);
}
@@ -120,15 +120,16 @@ void Translator::initDecks()
{
string lang = options[Options::LANG].str;
if (!lang.size()) return;
string decks_dict = JGE_GET_RES("lang/") + lang + "_decks.txt";
string decks_dict = "lang/" + lang + "_decks.txt";
// Load file
wagic::ifstream file(decks_dict.c_str());
if (file)
std::string contents;
if (JFileSystem::GetInstance()->readIntoString(decks_dict, contents))
{
std::stringstream stream(contents);
string s;
initDone = true;
while (std::getline(file, s))
while (std::getline(stream, s))
{
if (!s.size()) continue;
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
@@ -143,7 +144,6 @@ void Translator::initDecks()
string s2 = s.substr(found + 1);
deckValues[s1] = s2;
}
file.close();
}
}
@@ -154,7 +154,7 @@ void Translator::init()
#endif
string lang = options[Options::LANG].str;
if (!lang.size()) return;
string name = JGE_GET_RES("lang/") + lang + ".txt";
string name = "lang/" + lang + ".txt";
if (fileExists(name.c_str()))
{

View File

@@ -349,7 +349,7 @@ bool WCachedParticles::Attempt(const string& filename, int submode, int & error)
// 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));
fileSys->ReadFile(&(particles->nEmission), sizeof(hgeParticleSystemInfo) - 4);
fileSys->CloseFile();
particles->sprite = NULL;

View File

@@ -550,7 +550,7 @@ int WSrcDeck::getCount(int count)
int WSrcDeck::totalPrice()
{
int total = 0;
PriceList * pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(), MTGCollection());
PriceList * pricelist = NEW PriceList("settings/prices.dat", MTGCollection());
map<int, int>::iterator it;
for (it = copies.begin(); it != copies.end(); it++)
{

View File

@@ -561,14 +561,14 @@ string ResourceManagerImpl::graphicsFile(const string& filename)
if (ws)
{
sprintf(buf, "themes/%s/%s", theme.c_str(), ws->stylized(filename).c_str());
if (fileOK(buf, true)) return buf;
if (fileOK(buf)) return buf;
}
}
if (theme != "" && theme != "Default")
{
sprintf(buf, "themes/%s/%s", theme.c_str(), filename.c_str());
if (fileOK(buf, true)) return buf;
if (fileOK(buf)) return buf;
}
/*
//FIXME Put back when we're using modes.
@@ -584,15 +584,15 @@ string ResourceManagerImpl::graphicsFile(const string& filename)
//Failure. Check graphics
char graphdir[512];
sprintf(graphdir, "graphics/%s", filename.c_str());
if (fileOK(graphdir, true)) return graphdir;
if (fileOK(graphdir)) return graphdir;
//Failure. Check sets.
sprintf(buf, "sets/%s", filename.c_str());
if (fileOK(buf, true)) return buf;
if (fileOK(buf)) return buf;
//Failure. Check raw faile.
sprintf(buf, "%s", filename.c_str());
if (fileOK(buf, true)) return buf;
if (fileOK(buf)) return buf;
//Complete abject failure. Probably a crash...
return graphdir;
@@ -608,12 +608,12 @@ string ResourceManagerImpl::avatarFile(const string& filename)
if (profile != "" && profile != "Default")
{
sprintf(buf, "profiles/%s/%s", profile.c_str(), filename.c_str());
if (fileOK(buf, true)) return buf;
if (fileOK(buf)) return buf;
}
else
{
sprintf(buf, "player/%s", filename.c_str());
if (fileOK(buf, true)) return buf;
if (fileOK(buf)) return buf;
}
//Check the theme folder.
@@ -622,7 +622,7 @@ string ResourceManagerImpl::avatarFile(const string& filename)
if (theme != "" && theme != "Default")
{
sprintf(buf, "themes/%s/%s", theme.c_str(), filename.c_str());
if (fileOK(buf, true)) return buf;
if (fileOK(buf)) return buf;
}
/*
//FIXME Put back when we're using modes.
@@ -638,15 +638,15 @@ string ResourceManagerImpl::avatarFile(const string& filename)
//Failure. Check Baka
sprintf(buf, "ai/baka/avatars/%s", filename.c_str());
if (fileOK(buf, true)) return buf;
if (fileOK(buf)) return buf;
//Failure. Check graphics
sprintf(buf, "graphics/%s", filename.c_str());
if (fileOK(buf, true)) return buf;
if (fileOK(buf)) return buf;
//Failure. Check raw faile.
sprintf(buf, "%s", filename.c_str());
if (fileOK(buf, true)) return buf;
if (fileOK(buf)) return buf;
//Complete abject failure. Probably a crash...
return "";
@@ -678,12 +678,12 @@ string ResourceManagerImpl::cardFile(const string& filename)
if (set.size())
{
char zipname[512];
sprintf(zipname, JGE_GET_RES("themes/%s/sets/%s/%s.zip").c_str(), theme.c_str(), set.c_str(), set.c_str());
sprintf(zipname, "themes/%s/sets/%s/%s.zip", theme.c_str(), set.c_str(), set.c_str());
if (fs->AttachZipFile(zipname)) return filename.substr(i + 1);
}
sprintf(buf, "themes/%s/sets/%s", theme.c_str(), filename.c_str());
if (fileOK(buf, true)) return buf; //Themed, unzipped.
if (fileOK(buf)) return buf; //Themed, unzipped.
}
}
@@ -712,14 +712,14 @@ string ResourceManagerImpl::cardFile(const string& filename)
if (set.size())
{
char zipname[512];
sprintf(zipname, JGE_GET_RES("sets/%s/%s.zip").c_str(), set.c_str(), set.c_str());
sprintf(zipname, "sets/%s/%s.zip", set.c_str(), set.c_str());
if (fs->AttachZipFile(zipname)) return filename.substr(i + 1);
}
//Failure. Check for unzipped file in sets
char defdir[512];
sprintf(defdir, "sets/%s", filename.c_str());
if (fileOK(defdir, true)) return defdir;
if (fileOK(defdir)) return defdir;
//Complete failure.
return "";
@@ -735,7 +735,7 @@ string ResourceManagerImpl::musicFile(const string& filename)
if (theme != "" && theme != "Default")
{
sprintf(buf, "themes/%s/sound/%s", theme.c_str(), filename.c_str());
if (fileOK(buf, true)) return buf;
if (fileOK(buf)) return buf;
}
/*
@@ -752,11 +752,11 @@ string ResourceManagerImpl::musicFile(const string& filename)
//Failure. Check sound
char defdir[512];
sprintf(defdir, "sound/%s", filename.c_str());
if (fileOK(defdir, true)) return defdir;
if (fileOK(defdir)) return defdir;
//Failure. Check raw faile.
sprintf(defdir, "%s", filename.c_str());
if (fileOK(defdir, true)) return defdir;
if (fileOK(defdir)) return defdir;
//Complete abject failure. Probably a crash...
return "";
@@ -772,7 +772,7 @@ string ResourceManagerImpl::sfxFile(const string& filename)
if (theme != "" && theme != "Default")
{
sprintf(buf, "themes/%s/sound/sfx/%s", theme.c_str(), filename.c_str());
if (fileOK(buf, true)) return buf;
if (fileOK(buf)) return buf;
}
/*
@@ -788,49 +788,20 @@ string ResourceManagerImpl::sfxFile(const string& filename)
//Failure. Check sound
char defdir[512];
sprintf(defdir, "sound/sfx/%s", filename.c_str());
if (fileOK(defdir, true)) return defdir;
if (fileOK(defdir)) return defdir;
//Complete abject failure. Probably a crash...
return "";
}
int ResourceManagerImpl::dirOK(const string& dirname)
bool ResourceManagerImpl::dirOK(const string& dirname)
{
char fname[512];
#if defined (WIN32)
sprintf(fname,JGE_GET_RES(dirname).c_str());
struct _stat statBuffer;
return (_stat(fname, &statBuffer) >= 0 && // make sure it exists
statBuffer.st_mode & S_IFDIR); // and it's not a file
#else
sprintf(fname, "%s", JGE_GET_RES(dirname).c_str());
struct stat st;
if (stat(fname, &st) == 0) return 1;
#endif
return 0;
return JFileSystem::GetInstance()->DirExists(dirname);
}
int ResourceManagerImpl::fileOK(const string& filename, bool relative)
bool ResourceManagerImpl::fileOK(const string& filename)
{
wagic::ifstream * fp = NULL;
if (relative)
{
fp = NEW wagic::ifstream(JGE_GET_RES(filename).c_str());
}
else
fp = NEW wagic::ifstream(filename.c_str());
int result = 0;
if (fp)
{
if (*fp) result = 1;
fp->close();
delete fp;
}
return result;
return JFileSystem::GetInstance()->FileExists(filename);
}
void ResourceManagerImpl::InitFonts(const std::string& inLang)

View File

@@ -78,62 +78,16 @@ int filesize(const char * filename)
return file_size;
}
// check to see if a file exists on the file system.
int fileExists(const char * filename)
bool fileExists(const char * filename)
{
wagic::ifstream fichier(filename);
if (fichier)
{
fichier.close();
return 1;
}
wagic::ifstream fichier2(JGE_GET_RES(filename).c_str());
if (fichier2)
{
fichier2.close();
return 1;
}
return 0;
return JFileSystem::GetInstance()->FileExists(filename);
}
// check to see if a file exists on the file system.
// this can be used to extract last modified date of a file.
bool FileExists(const string& strFilename)
{
struct stat stFileInfo;
bool blnReturn = false;
int intStat;
// Attempt to get the file attributes
intStat = stat(strFilename.c_str(),&stFileInfo);
if(intStat == 0)
{
// We were able to get the file attributes
// so the file obviously exists.
blnReturn = true;
}
else
{
// We were not able to get the file attributes.
// This may mean that we don't have permission to
// access the folder which contains this file. If you
// need to do that level of checking, lookup the
// return values of stat which will give you
// more details on why stat failed.
// try to search in the resource directory
if ( stat( JGE_GET_RES(strFilename).c_str(), &stFileInfo ) == 0)
blnReturn = true;
else
blnReturn = false;
}
return(blnReturn);
bool FileExists(const string & filename)
{
return JFileSystem::GetInstance()->FileExists(filename);
}
/*
#ifdef LINUX
@@ -396,4 +350,21 @@ unsigned long hash_djb2(const char *str)
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash;
}
std::string buildFilePath(const vector<string> & folders, const string & filename)
{
string result = "";
for (size_t i = 0; i < folders.size(); ++i)
{
result.append(folders[i]);
if (result[result.length()-1] != '/')
{
result.append("/");
}
}
result.append(filename);
return result;
}

View File

@@ -156,7 +156,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>./include;$(MTGEXTRAS);../../JGE/include;../../JGE/Dependencies/include;../../Boost;../../JGE/Dependencies/SDL/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>./include;$(MTGEXTRAS);../../JGE/include;../../JGE/Dependencies/include;../../Boost;../../JGE/Dependencies/SDL/include;../../JGE/src/zipFS;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>SDL_CONFIG;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -181,7 +181,7 @@
<Link>
<AdditionalDependencies>glu32.lib;opengl32.lib;odbc32.lib;odbccp32.lib;SDL.lib;libpngd.lib;fmodvc.lib;libjpeg-static-mt-debug.lib;freetype.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>..\..\JGE\Dependencies\lib;..\..\JGE\lib\win;..\..\Boost\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>..\..\zipFS;..\..\JGE\Dependencies\lib;..\..\JGE\lib\win;..\..\Boost\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>LIBCD;LIBC;MSVCRT;LIBCMTD;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>.\Debug/template.pdb</ProgramDatabaseFile>

View File

@@ -30,7 +30,7 @@ unix:INCLUDEPATH += /usr/include/GL
unix:INCLUDEPATH += /usr/local/include/SDL
macx:INCLUDEPATH += /opt/include
INCLUDEPATH += ../../JGE/include
INCLUDEPATH += ../../JGE/include/unzip
INCLUDEPATH += ../../JGE/src/zipFS
INCLUDEPATH += ../../Boost
INCLUDEPATH += include
OBJECTS_DIR = objs
@@ -297,9 +297,9 @@ SOURCES += \
../../JGE/src/hge/hgeparticle.cpp\
../../JGE/src/hge/hgerect.cpp\
../../JGE/src/hge/hgevector.cpp\
../../JGE/src/unzip/ioapi.c\
../../JGE/src/unzip/mztools.c\
../../JGE/src/unzip/unzip.c\
../../JGE/src/zipFS/zfsystem.cpp\
../../JGE/src/zipFS/ziphdr.cpp\
../../JGE/src/zipFS/zstream.cpp\
../../JGE/src/pc/JSfx.cpp\
../../JGE/src/pc/JGfx.cpp\
../../JGE/src/JNetwork.cpp\

View File

@@ -34,6 +34,7 @@ windows:INCLUDEPATH += extra
unix:!symbian:INCLUDEPATH += /usr/include/GL
macx:INCLUDEPATH += /opt/include
INCLUDEPATH += ../../JGE/include
INCLUDEPATH += ../../JGE/src/zipFS
INCLUDEPATH += ../../Boost
INCLUDEPATH += include
OBJECTS_DIR = objs
@@ -292,9 +293,9 @@ SOURCES += \
../../JGE/src/hge/hgeparticle.cpp\
../../JGE/src/hge/hgerect.cpp\
../../JGE/src/hge/hgevector.cpp\
../../JGE/src/unzip/ioapi.c\
../../JGE/src/unzip/mztools.c\
../../JGE/src/unzip/unzip.c\
../../JGE/src/zipFS/zfsystem.cpp\
../../JGE/src/zipFS/ziphdr.cpp\
../../JGE/src/zipFS/zstream.cpp\
../../JGE/src/pc/JSfx.cpp\
../../JGE/src/pc/JGfx.cpp