diff --git a/JGE/include/JFileSystem.h b/JGE/include/JFileSystem.h index 3dbe494b9..17a91bd4c 100644 --- a/JGE/include/JFileSystem.h +++ b/JGE/include/JFileSystem.h @@ -11,6 +11,9 @@ #ifndef _FILE_SYSTEM_H_ #define _FILE_SYSTEM_H_ +#define JGE_GET_RES(filename) JFileSystem::GetInstance()->GetResourceFile(filename) +#define JGE_GET_RESPATH() JFileSystem::GetInstance()->GetResourceRoot() + #include #include #include @@ -109,6 +112,10 @@ public: /// ////////////////////////////////////////////////////////////////////////// void SetResourceRoot(const string& resourceRoot); + string GetResourceRoot(); + + // Returns a string prefixed with the resource path + string GetResourceFile(string filename); protected: JFileSystem(); diff --git a/JGE/include/JGE.h b/JGE/include/JGE.h index b354dd8df..a34956cb7 100644 --- a/JGE/include/JGE.h +++ b/JGE/include/JGE.h @@ -11,7 +11,6 @@ #ifndef _JGE_H_ #define _JGE_H_ - #include #include #include diff --git a/JGE/lib/win/jge.lib b/JGE/lib/win/jge.lib index 8550724e1..e8bc0c012 100644 Binary files a/JGE/lib/win/jge.lib and b/JGE/lib/win/jge.lib differ diff --git a/JGE/src/JFileSystem.cpp b/JGE/src/JFileSystem.cpp index 6ba9320aa..e3387874e 100644 --- a/JGE/src/JFileSystem.cpp +++ b/JGE/src/JFileSystem.cpp @@ -257,3 +257,14 @@ void JFileSystem::SetResourceRoot(const string& resourceRoot) { mResourceRoot = resourceRoot; } + +string JFileSystem::GetResourceRoot() +{ + return mResourceRoot; +} + +string JFileSystem::GetResourceFile(string filename) +{ + string result = mResourceRoot; + return result.append(filename); +} \ No newline at end of file diff --git a/JGE/src/JGfx.cpp b/JGE/src/JGfx.cpp index 135d29ecc..c54c6ba12 100644 --- a/JGE/src/JGfx.cpp +++ b/JGE/src/JGfx.cpp @@ -965,11 +965,7 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode JLOG("JRenderer::LoadJPG"); textureInfo.mBits = NULL; char filenamenew[4096]; -#ifdef RESPATH - sprintf(filenamenew, RESPATH"/%s", filename); -#else - sprintf(filenamenew, "Res/%s", filename); -#endif + sprintf(filenamenew, JGE_GET_RES(filename).c_str()); bool useVideoRAM = (mode == TEX_TYPE_USE_VRAM); diff --git a/JGE/src/JSfx.cpp b/JGE/src/JSfx.cpp index 80a909eb6..2bab04ce8 100644 --- a/JGE/src/JSfx.cpp +++ b/JGE/src/JSfx.cpp @@ -9,6 +9,7 @@ //------------------------------------------------------------------------------------- #include "../include/JSoundSystem.h" +#include "../include/JFileSystem.h" #include "../include/JAudio.h" #include "../include/JMP3.h" #include @@ -108,12 +109,9 @@ void JSoundSystem::DestroySoundSystem() JMusic *JSoundSystem::LoadMusic(const char *fileName) { -#ifdef RESPATH - string s = RESPATH"/"; -#else - string s = "Res/"; -#endif - s.append(fileName); + + string s = JGE_GET_RES(fileName); + JMusic *music = new JMusic(); if (music) { diff --git a/projects/mtg/include/GameOptions.h b/projects/mtg/include/GameOptions.h index 39306422b..815e7384d 100644 --- a/projects/mtg/include/GameOptions.h +++ b/projects/mtg/include/GameOptions.h @@ -10,7 +10,7 @@ using std::string; #include "SimplePad.h" #include "GameApp.h" -#define GLOBAL_SETTINGS RESPATH"/settings/options.txt" +#define GLOBAL_SETTINGS "settings/options.txt" #define PLAYER_SAVEFILE "data.dat" #define PLAYER_SETTINGS "options.txt" #define PLAYER_COLLECTION "collection.dat" diff --git a/projects/mtg/include/Logger.h b/projects/mtg/include/Logger.h index 76d0c3093..b9a232ee1 100644 --- a/projects/mtg/include/Logger.h +++ b/projects/mtg/include/Logger.h @@ -2,10 +2,10 @@ #define _LOGGER_H_ //TODO Remove this and use the jge logging facility (same system) -//#define DOLOG +#define DOLOG #ifdef DOLOG -#define LOG_FILE RESPATH"/debug.txt" +#define LOG_FILE "debug.txt" class Logger{ public: diff --git a/projects/mtg/include/PrecompiledHeader.h b/projects/mtg/include/PrecompiledHeader.h index 330cbac45..2a556df9b 100644 --- a/projects/mtg/include/PrecompiledHeader.h +++ b/projects/mtg/include/PrecompiledHeader.h @@ -16,5 +16,6 @@ #include #include "JGE.h" +#include "JFileSystem.h" #endif //PRECOMPILEDHEADER_H \ No newline at end of file diff --git a/projects/mtg/include/StoryFlow.h b/projects/mtg/include/StoryFlow.h index 7192d2aba..3df63dd60 100644 --- a/projects/mtg/include/StoryFlow.h +++ b/projects/mtg/include/StoryFlow.h @@ -9,7 +9,7 @@ using namespace std; #include class GameObserver; class MTGDeck; -#define CAMPAIGNS_FOLDER "Res/campaigns/" +#define CAMPAIGNS_FOLDER "campaigns/" class StoryDialogElement:public JGuiObject { diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index f518be71d..98c825828 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -654,7 +654,7 @@ int AIPlayer::combatDamages(){ AIStats * AIPlayer::getStats(){ if (!stats){ char statFile[512]; - sprintf(statFile, RESPATH"/ai/baka/stats/%s.stats", opponent()->deckFileSmall.c_str()); + sprintf(statFile,JGE_GET_RES("ai/baka/stats/%s.stats").c_str(), opponent()->deckFileSmall.c_str()); stats = NEW AIStats(this, statFile); } return stats; @@ -677,7 +677,7 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op while (found){ found = 0; char buffer[512]; - sprintf(buffer, RESPATH"/ai/baka/deck%i.txt",nbdecks+1); + sprintf(buffer, JGE_GET_RES("ai/baka/deck%i.txt").c_str(),nbdecks+1); std::ifstream file(buffer); if(file){ found = 1; @@ -688,7 +688,7 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op if (!nbdecks) return NULL; deckid = 1 + WRand() % (nbdecks); } - sprintf(deckFile, RESPATH"/ai/baka/deck%i.txt",deckid); + sprintf(deckFile, JGE_GET_RES("ai/baka/deck%i.txt").c_str(),deckid); sprintf(avatarFile, "avatar%i.jpg",deckid); sprintf(deckFileSmall, "ai_baka_deck%i",deckid); } diff --git a/projects/mtg/src/Credits.cpp b/projects/mtg/src/Credits.cpp index 4656184f6..8ed1a2035 100644 --- a/projects/mtg/src/Credits.cpp +++ b/projects/mtg/src/Credits.cpp @@ -255,7 +255,7 @@ int Credits::isDifficultyUnlocked(){ found = 0; char buffer[512]; char aiSmallDeckName[512]; - sprintf(buffer, RESPATH"/ai/baka/deck%i.txt",nbAIDecks+1); + sprintf(buffer, JGE_GET_RES("ai/baka/deck%i.txt").c_str(),nbAIDecks+1); if(fileExists(buffer)){ found = 1; nbAIDecks++; diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index c114c6841..3d30e0248 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -90,6 +90,21 @@ void GameApp::Create() //_CrtSetBreakAlloc(368); LOG("starting Game"); + //Find the Res folder + std::ifstream mfile("Res.txt"); + string resPath; + if(mfile){ + if (std::getline(mfile, resPath)) { + if (resPath[resPath.size()-1] == '\r') resPath.erase(resPath.size()-1); //Handle DOS files + //TODO ERROR Handling if file does not exist + JFileSystem::GetInstance()->SetResourceRoot(trim(resPath)); + } + mfile.close(); + } + LOG("Res Root:"); + LOG(JFileSystem::GetInstance()->GetResourceRoot().c_str()); + + //Link this to our settings manager. options.theGame = this; @@ -99,16 +114,14 @@ void GameApp::Create() LOG("Checking for music files"); //Test for Music files presence - string filepath = RESPATH; - filepath = filepath + "/" + resources.musicFile("Track0.mp3"); + string filepath = JGE_GET_RES(resources.musicFile("Track0.mp3")); std::ifstream file(filepath.c_str()); if (file) file.close(); else HasMusic = 0; - filepath = RESPATH; - filepath = filepath + "/" + resources.musicFile("Track1.mp3"); + filepath = JGE_GET_RES(resources.musicFile("Track1.mp3")); std::ifstream file2(filepath.c_str()); if (file2) file2.close(); @@ -129,7 +142,8 @@ void GameApp::Create() manaIcons[Constants::MTG_COLOR_ARTIFACT] = resources.RetrieveQuad("menuicons.png", 2 + 6*36, 38, 32, 32, "c_artifact",RETRIEVE_MANAGE); - for (int i = sizeof(manaIcons)/sizeof(manaIcons[0]) - 1; i >= 0; --i) manaIcons[i]->SetHotSpot(16,16); + for (int i = sizeof(manaIcons)/sizeof(manaIcons[0]) - 1; i >= 0; --i) + if (manaIcons[i]) manaIcons[i]->SetHotSpot(16,16); LOG("--Loading back.jpg"); resources.RetrieveTexture("back.jpg",RETRIEVE_MANAGE); @@ -142,9 +156,9 @@ void GameApp::Create() LOG("--Loading particles.png"); resources.RetrieveTexture("particles.png",RETRIEVE_MANAGE); jq = resources.RetrieveQuad("particles.png", 0, 0, 32, 32, "particles",RETRIEVE_MANAGE); - jq->SetHotSpot(16,16); + if (jq) jq->SetHotSpot(16,16); jq = resources.RetrieveQuad("particles.png", 64, 0, 32, 32, "stars",RETRIEVE_MANAGE); - jq->SetHotSpot(16,16); + if (jq) jq->SetHotSpot(16,16); LOG("--Loading fonts"); string lang = options[Options::LANG].str; @@ -163,11 +177,11 @@ void GameApp::Create() resources.RetrieveTexture("shadow.png",RETRIEVE_MANAGE); jq = resources.RetrieveQuad("BattleIcon.png", 0, 0, 25, 25,"BattleIcon",RETRIEVE_MANAGE); - jq->SetHotSpot(12, 12); + if (jq) jq->SetHotSpot(12, 12); jq = resources.RetrieveQuad("DefenderIcon.png", 0, 0, 24, 23,"DefenderIcon",RETRIEVE_MANAGE); - jq->SetHotSpot(12, 12); + if (jq) jq->SetHotSpot(12, 12); jq = resources.RetrieveQuad("shadow.png", 0, 0, 16, 16,"shadow",RETRIEVE_MANAGE); - jq->SetHotSpot(8, 8); + if (jq) jq->SetHotSpot(8, 8); jq = resources.RetrieveQuad("phasebar.png",0,0,0,0,"phasebar",RETRIEVE_MANAGE); LOG("Init Collection"); diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index ecc603582..e2e00ac3c 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -498,7 +498,7 @@ int GameSettings::save(){ if(profileOptions){ //Force our directories to exist. - MAKEDIR(RESPATH"/profiles"); + MAKEDIR(JGE_GET_RES("profiles").c_str()); string temp = profileFile("","",false,false); MAKEDIR(temp.c_str()); temp+="/stats"; @@ -521,11 +521,11 @@ string GameSettings::profileFile(string filename, string fallback,bool sanity, b if(!(*this)[Options::ACTIVE_PROFILE].isDefault()) { //No file, return root of profile directory if(filename == ""){ - sprintf(buf,"%sprofiles/%s",( relative ? "" : RESPATH"/" ),profile.c_str()); + sprintf(buf,"%sprofiles/%s",( relative ? "" : JGE_GET_RES("").c_str() ),profile.c_str()); return buf; } //Return file - sprintf(buf,RESPATH"/profiles/%s/%s",profile.c_str(),filename.c_str()); + sprintf(buf,JGE_GET_RES("profiles/%s/%s").c_str(),profile.c_str(),filename.c_str()); if(fileExists(buf)){ if(relative) sprintf(buf,"profiles/%s/%s",profile.c_str(),filename.c_str()); @@ -534,13 +534,13 @@ string GameSettings::profileFile(string filename, string fallback,bool sanity, b } else{ //Use the default directory. - sprintf(buf,"%splayer%s%s",(relative ? "" : RESPATH"/"),(filename == "" ? "" : "/"), filename.c_str()); + sprintf(buf,"%splayer%s%s",(relative ? "" :JGE_GET_RES("").c_str()),(filename == "" ? "" : "/"), filename.c_str()); return buf; } //Don't fallback if sanity checking is disabled.. if(!sanity){ - sprintf(buf,"%sprofiles/%s%s%s",(relative ? "" : RESPATH"/"),profile.c_str(),(filename == "" ? "" : "/"), filename.c_str()); + sprintf(buf,"%sprofiles/%s%s%s",(relative ? "" : JGE_GET_RES("").c_str()),profile.c_str(),(filename == "" ? "" : "/"), filename.c_str()); return buf; } @@ -548,7 +548,7 @@ string GameSettings::profileFile(string filename, string fallback,bool sanity, b if(fallback == "") return ""; - sprintf(buf,"%s%s%s%s",(relative ? "" : RESPATH"/"),fallback.c_str(),(filename == "" ? "" : "/"), filename.c_str()); + sprintf(buf,"%s%s%s%s",(relative ? "" : JGE_GET_RES("").c_str()),fallback.c_str(),(filename == "" ? "" : "/"), filename.c_str()); return buf; } @@ -561,7 +561,7 @@ void GameSettings::reloadProfile(bool images){ void GameSettings::checkProfile(){ if(!globalOptions) - globalOptions = NEW GameOptions(GLOBAL_SETTINGS); + globalOptions = NEW GameOptions(JGE_GET_RES(GLOBAL_SETTINGS)); //If it doesn't exist, load current profile. if(!profileOptions){ @@ -589,7 +589,7 @@ void GameSettings::checkProfile(){ //Make the proper directories if(profileOptions){ //Force our directories to exist. - MAKEDIR(RESPATH"/profiles"); + MAKEDIR(JGE_GET_RES("profiles").c_str()); string temp = profileFile("","",false,false); MAKEDIR(temp.c_str()); temp+="/stats"; diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index 330bd8a1b..8e12dae31 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -214,7 +214,7 @@ void GameStateDeckViewer::Start() lastPos = 0; lastTotal = 0; - pricelist = NEW PriceList(RESPATH"/settings/prices.dat",mParent->collection); + pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(),mParent->collection); playerdata = NEW PlayerData(mParent->collection); myCollection = NEW DeckDataWrapper(playerdata->collection); myCollection->Sort(WSrcCards::SORT_ALPHA); @@ -306,7 +306,7 @@ void GameStateDeckViewer::saveDeck(){ void GameStateDeckViewer::saveAsAIDeck( string deckName ) { DeckManager * deckManager = DeckManager::GetInstance(); - vector aiDecks = GameState::getValidDeckMetaData( RESPATH"/ai/baka", "ai_baka", NULL); + vector aiDecks = GameState::getValidDeckMetaData( JGE_GET_RES("ai/baka"), "ai_baka", NULL); int nbAiDecks = aiDecks.size() + 1; aiDecks.clear(); @@ -320,8 +320,8 @@ void GameStateDeckViewer::saveAsAIDeck( string deckName ) else oss << myDeck->parent->meta_desc; string deckDesc = oss.str(); - string filepath = RESPATH; - filepath.append("/ai/baka/").append( defaultAiDeckName ).append( ".txt" ); + string filepath = JGE_GET_RES("ai/baka/"); + filepath.append( defaultAiDeckName ).append( ".txt" ); DebugTrace("saving AI deck " << filepath); myDeck->save( filepath, true, deckName, deckDesc); } @@ -1503,7 +1503,7 @@ int GameStateDeckViewer::loadDeck(int deckid){ found = 0; char buffer[512]; char smallDeckName[512]; - sprintf(buffer, "%s/deck%i.txt",RESPATH"/ai/baka",nbDecks+1); + sprintf(buffer, "%s/deck%i.txt",JGE_GET_RES("ai/baka").c_str(),nbDecks+1); if(fileExists(buffer)){ MTGDeck * mtgd = NEW MTGDeck(buffer,NULL,1); found = 1; diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 0c488020c..ca4d0dd08 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -81,7 +81,7 @@ void GameStateDuel::Start() #ifdef TESTSUITE SAFE_DELETE(testSuite); - testSuite = NEW TestSuite(RESPATH"/test/_tests.txt",mParent->collection); + testSuite = NEW TestSuite(JGE_GET_RES("test/_tests.txt").c_str(),mParent->collection); #endif mGamePhase = DUEL_STATE_CHOOSE_DECK1; @@ -126,7 +126,7 @@ void GameStateDuel::Start() else deckmenu->Add( MENUITEM_NEW_DECK, "Create your Deck!", "Highly recommended to get\nthe full Wagic experience!"); premadeDeck = true; - fillDeckMenu(deckmenu,RESPATH"/player/premade"); + fillDeckMenu(deckmenu,JGE_GET_RES("player/premade")); } deckmenu->Add( MENUITEM_NEW_DECK, "New Deck...", "Create a new deck to play with."); deckmenu->Add( MENUITEM_CANCEL, "Main Menu", "Return to Main Menu"); @@ -143,7 +143,7 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){ if (!isAI) { //Human Player char deckFile[255]; if(premadeDeck) - sprintf(deckFile, RESPATH"/player/premade/deck%i.txt",decknb); + sprintf(deckFile, JGE_GET_RES("player/premade/deck%i.txt").c_str(),decknb); else sprintf(deckFile, "%s/deck%i.txt",options.profileFile().c_str(), decknb); char deckFileSmall[255]; @@ -226,8 +226,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 = RESPATH; - filepath = filepath + "/" + resources.musicFile(FileName); + string filepath = JGE_GET_RES(resources.musicFile(FileName)); std::ifstream file(filepath.c_str()); if (file) { file.close(); @@ -244,7 +243,7 @@ void GameStateDuel::ensureOpponentMenu(){ if (options[Options::EVILTWIN_MODE_UNLOCKED].number) opponentMenu->Add( MENUITEM_EVIL_TWIN, "Evil Twin", _("Can you play against yourself?").c_str()); DeckManager * deckManager = DeckManager::GetInstance(); - vector opponentDeckList = fillDeckMenu( opponentMenu, RESPATH"/ai/baka", "ai_baka", mPlayers[0]); + vector opponentDeckList = fillDeckMenu( opponentMenu, JGE_GET_RES("ai/baka"), "ai_baka", mPlayers[0]); deckManager->updateMetaDataList(&opponentDeckList, true); opponentMenu->Add( MENUITEM_CANCEL, "Cancel", _("Choose a different player deck").c_str()); opponentDeckList.clear(); diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index fe4c22c32..d3e1d821f 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -103,7 +103,7 @@ void GameStateMenu::Create() for (int j=0;j<2;j++){ sprintf(buf,"menuicons%d%d",i,j); mIcons[n] = resources.RetrieveQuad("menuicons.png", 2 + i * 36.0f, 2.0f + j * 36.0f, 32.0f, 32.0f, buf); - mIcons[n]->SetHotSpot(16,16); + if(mIcons[n]) mIcons[n]->SetHotSpot(16,16); n++; } } @@ -112,7 +112,7 @@ void GameStateMenu::Create() bool langChosen = false; string lang = options[Options::LANG].str; if (lang.size()){ - lang = "Res/lang/" + lang + ".txt"; + lang = JGE_GET_RES("lang/") + lang + ".txt"; if (fileExists(lang.c_str())) langChosen = true; } if (!langChosen){ @@ -155,7 +155,7 @@ void GameStateMenu::Start(){ bgTexture = resources.RetrieveTexture("menutitle.png", RETRIEVE_LOCK); mBg = resources.RetrieveQuad("menutitle.png", 0, 0, 256, 166); // Create background quad for rendering. - mBg->SetHotSpot(128,50); + if (mBg) mBg->SetHotSpot(128,50); if (MENU_STATE_MAJOR_MAINMENU == currentState) currentState = currentState | MENU_STATE_MINOR_FADEIN; @@ -286,7 +286,7 @@ string GameStateMenu::loadRandomWallpaper() { return wallpaper; vector wallpapers; - std::ifstream file("Res/graphics/wallpapers.txt"); + std::ifstream file(JGE_GET_RES("graphics/wallpapers.txt").c_str()); if (!file) return wallpaper; @@ -322,11 +322,11 @@ void GameStateMenu::loadLangMenu(){ if (!subMenuController) return; resetDirectory(); if (!mDip){ - mDip = opendir("Res/lang"); + mDip = opendir(JGE_GET_RES("lang").c_str()); } while ((mDit = readdir(mDip))){ - string filename = "Res/lang/"; + string filename = JGE_GET_RES("lang/"); filename += mDit->d_name; std::ifstream file(filename.c_str()); string s; @@ -352,11 +352,11 @@ void GameStateMenu::listPrimitives(){ LOG("GameStateMenu::listPrimitives"); resetDirectory(); if (!mDip){ - mDip = opendir("Res/sets/primitives/"); + mDip = opendir(JGE_GET_RES("sets/primitives/").c_str()); } while ((mDit = readdir(mDip))){ - string filename = "Res/sets/primitives/"; + string filename = JGE_GET_RES("sets/primitives/"); filename += mDit->d_name; std::ifstream file(filename.c_str()); if(!file) continue; @@ -414,7 +414,7 @@ void GameStateMenu::Update(float dt) }else{ mReadConf = 1; } - if (!nextDirectory(RESPATH"/sets/","_cards.dat")){ + if (!nextDirectory(JGE_GET_RES("sets/").c_str(),"_cards.dat")){ //Remove temporary translations Translator::GetInstance()->tempValues.clear(); diff --git a/projects/mtg/src/GameStateShop.cpp b/projects/mtg/src/GameStateShop.cpp index aa3cf64b3..49a34e993 100644 --- a/projects/mtg/src/GameStateShop.cpp +++ b/projects/mtg/src/GameStateShop.cpp @@ -79,7 +79,7 @@ void GameStateShop::Start(){ MTGAllCards * ac = GameApp::collection; playerdata = NEW PlayerData(ac); myCollection = NEW DeckDataWrapper(playerdata->collection); - pricelist = NEW PriceList(RESPATH"/settings/prices.dat",ac); + pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(),ac); for(int i=0;i::iterator it; for ( it=cards.begin() ; it != cards.end(); it++ ){ int nb = it->second; @@ -932,7 +932,7 @@ MTGSetInfo::MTGSetInfo(string _id) { counts[i] = 0; char myFilename[4096]; - sprintf(myFilename, RESPATH"/sets/%s/booster.txt", id.c_str()); + sprintf(myFilename, JGE_GET_RES("sets/%s/booster.txt").c_str(), id.c_str()); mPack = NEW MTGPack(myFilename); if(!mPack->isValid()){ SAFE_DELETE(mPack); diff --git a/projects/mtg/src/MTGPack.cpp b/projects/mtg/src/MTGPack.cpp index dd365d4aa..0cd1d4dd9 100644 --- a/projects/mtg/src/MTGPack.cpp +++ b/projects/mtg/src/MTGPack.cpp @@ -220,13 +220,13 @@ MTGPack * MTGPacks::randomPack(int key){ return packs[key%s]; } void MTGPacks::loadAll(){ - DIR *mDip = opendir(RESPATH"/packs/"); + DIR *mDip = opendir(JGE_GET_RES("packs/").c_str()); struct dirent *mDit; if(!mDip) return; while ((mDit = readdir(mDip))){ char myFilename[4096]; - sprintf(myFilename, RESPATH"/packs/%s", mDit->d_name); + sprintf(myFilename, JGE_GET_RES("packs/%s").c_str(), mDit->d_name); if(mDit->d_name[0] == '.') continue; if(!strcmp(mDit->d_name,"default_booster.txt")) continue; MTGPack * p = NEW MTGPack(myFilename); @@ -276,7 +276,7 @@ bool MTGPack::isUnlocked(){ MTGPack * MTGPacks::getDefault(){ if(!defaultBooster.isValid()){ - defaultBooster.load(RESPATH"/packs/default_booster.txt"); + defaultBooster.load(JGE_GET_RES("packs/default_booster.txt")); defaultBooster.unlockStatus = 1; if(!defaultBooster.isValid()){ MTGPackSlot * ps = NEW MTGPackSlot(); ps->copies = 1; diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index c2de5266b..ece1e7bb6 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -94,7 +94,7 @@ void OptionSelect::addSelection(string s){ //OptionProfile const string OptionProfile::DIRTESTER = "collection.dat"; -OptionProfile::OptionProfile(GameApp * _app, JGuiListener * jgl) : OptionDirectory(RESPATH"/profiles", Options::ACTIVE_PROFILE, "Profile", DIRTESTER){ +OptionProfile::OptionProfile(GameApp * _app, JGuiListener * jgl) : OptionDirectory(JGE_GET_RES("profiles"), Options::ACTIVE_PROFILE, "Profile", DIRTESTER){ app = _app; listener = jgl; height=60; @@ -271,10 +271,10 @@ void OptionLanguage::Reload(){ struct dirent *mDit; DIR *mDip; - mDip = opendir("Res/lang"); + mDip = opendir(JGE_GET_RES("lang").c_str()); while ((mDit = readdir(mDip))){ - string filename = "Res/lang/"; + string filename = JGE_GET_RES("lang/"); filename += mDit->d_name; std::ifstream file(filename.c_str()); string s; @@ -368,7 +368,7 @@ OptionDirectory::OptionDirectory(string root, int id, string displayValue, strin } const string OptionTheme::DIRTESTER = "preview.png"; -OptionTheme::OptionTheme(OptionThemeStyle * style) : OptionDirectory(RESPATH"/themes", Options::ACTIVE_THEME, "Current Theme", DIRTESTER){ +OptionTheme::OptionTheme(OptionThemeStyle * style) : OptionDirectory(JGE_GET_RES("themes"), Options::ACTIVE_THEME, "Current Theme", DIRTESTER){ addSelection("Default"); sort(selections.begin(),selections.end()); initSelections(); @@ -402,9 +402,9 @@ void OptionTheme::Render(){ author = ""; bChecked = true; if(selections[value] == "Default") - sprintf(buf,RESPATH"/graphics/themeinfo.txt"); + sprintf(buf,JGE_GET_RES("graphics/themeinfo.txt").c_str()); else - sprintf(buf,RESPATH"/themes/%s/themeinfo.txt",selections[value].c_str()); + sprintf(buf,JGE_GET_RES("themes/%s/themeinfo.txt").c_str(),selections[value].c_str()); std::ifstream file(buf); if(file){ string temp; diff --git a/projects/mtg/src/Rules.cpp b/projects/mtg/src/Rules.cpp index 3b67f7a86..47318618b 100644 --- a/projects/mtg/src/Rules.cpp +++ b/projects/mtg/src/Rules.cpp @@ -383,7 +383,7 @@ int Rules::load(string _filename){ if (fileExists(_filename.c_str())){ sprintf(filename, "%s", _filename.c_str()); }else{ - sprintf(filename, RESPATH"/rules/%s", _filename.c_str()); + sprintf(filename, JGE_GET_RES("rules/%s").c_str(), _filename.c_str()); } std::ifstream file(filename); std::string s; diff --git a/projects/mtg/src/StoryFlow.cpp b/projects/mtg/src/StoryFlow.cpp index c17379699..44d3e80aa 100644 --- a/projects/mtg/src/StoryFlow.cpp +++ b/projects/mtg/src/StoryFlow.cpp @@ -269,7 +269,7 @@ void StoryDuel::init(){ Player * players[2]; char folder[255], deckFile[255],deckFileSmall[255]; - sprintf(folder, CAMPAIGNS_FOLDER"%s/%s" ,mParent->folder.c_str(), pageId.c_str()); + sprintf(folder, JGE_GET_RES(CAMPAIGNS_FOLDER"%s/%s").c_str() ,mParent->folder.c_str(), pageId.c_str()); sprintf(deckFile, "%s/deck.txt", folder); MTGDeck * tempDeck = NEW MTGDeck(deckFile, GameApp::collection); diff --git a/projects/mtg/src/StyleManager.cpp b/projects/mtg/src/StyleManager.cpp index fc6cf4d5c..797b9417d 100644 --- a/projects/mtg/src/StyleManager.cpp +++ b/projects/mtg/src/StyleManager.cpp @@ -40,7 +40,7 @@ string WStyle::stylized(string filename){ void StyleManager::loadRules(){ killRules(); //TODO Placeholder until XML format available. - string filename = RESPATH"/" + resources.graphicsFile("style.txt"); + string filename = JGE_GET_RES(resources.graphicsFile("style.txt")); TiXmlDocument xmlfile(filename.c_str()); if(!xmlfile.LoadFile()) return; diff --git a/projects/mtg/src/Tasks.cpp b/projects/mtg/src/Tasks.cpp index d8280b199..ac71b1239 100644 --- a/projects/mtg/src/Tasks.cpp +++ b/projects/mtg/src/Tasks.cpp @@ -165,7 +165,7 @@ void Task::loadAIDeckNames() { while (found){ found = 0; char buffer[512]; - sprintf(buffer, "%s/deck%i.txt",RESPATH"/ai/baka",nbDecks + 1); + sprintf(buffer, "%s/deck%i.txt",JGE_GET_RES("ai/baka").c_str(),nbDecks + 1); if(fileExists(buffer)){ found = 1; diff --git a/projects/mtg/src/TestSuiteAI.cpp b/projects/mtg/src/TestSuiteAI.cpp index d046780b1..8d40639b3 100644 --- a/projects/mtg/src/TestSuiteAI.cpp +++ b/projects/mtg/src/TestSuiteAI.cpp @@ -316,7 +316,7 @@ void TestSuite::initGame(){ DebugTrace("TESTUITE Init Game Done !"); } int TestSuite::Log(const char * text){ - ofstream file (RESPATH"/test/results.html",ios_base::app); + ofstream file (JGE_GET_RES("test/results.html").c_str(),ios_base::app); if (file){ file << text; file << "\n"; @@ -429,7 +429,7 @@ TestSuite::TestSuite(const char * filename,MTGAllCards* _collection){ file.close(); } - ofstream file2 (RESPATH"/test/results.html"); + ofstream file2 (JGE_GET_RES("/test/results.html").c_str()); if (file2){ file2 << ""; #ifdef WIN32 @@ -496,7 +496,7 @@ int TestSuite::load(const char * _filename){ forceAbility = false; gameType = GAME_TYPE_CLASSIC; char filename[4096]; - sprintf(filename, RESPATH"/test/%s", _filename); + sprintf(filename, JGE_GET_RES("/test/%s").c_str(), _filename); std::ifstream file(filename); std::string s; loadRandValues(""); diff --git a/projects/mtg/src/Translate.cpp b/projects/mtg/src/Translate.cpp index 56b2cc5d5..fa3fa59cd 100644 --- a/projects/mtg/src/Translate.cpp +++ b/projects/mtg/src/Translate.cpp @@ -37,7 +37,7 @@ string Translator::translate(string value){ Translator::~Translator(){ #if defined DEBUG_TRANSLATE if (!checkMisses) return; - std::ofstream file("Res/lang/missing.txt"); + std::ofstream file(JGE_GET_RES("lang/missing.txt").c_str()); char writer[4096]; if (file){ map::iterator it; @@ -78,7 +78,7 @@ void Translator::load(string filename, map * dictionary) { #if defined DEBUG_TRANSLATE if (!checkMisses) return; - std::ifstream file2("Res/lang/dontcare.txt"); + std::ifstream file2(JGE_GET_RES("lang/dontcare.txt").c_str()); if(file2){ string s; @@ -98,14 +98,14 @@ void Translator::load(string filename, map * dictionary) { void Translator::initCards(){ string lang = options[Options::LANG].str; if (!lang.size()) return; - string cards_dict = "Res/lang/" + lang + "_cards.txt"; + string cards_dict = JGE_GET_RES("lang/") + lang + "_cards.txt"; load(cards_dict,&tempValues); } void Translator::initDecks(){ string lang = options[Options::LANG].str; if (!lang.size()) return; - string decks_dict = "Res/lang/" + lang + "_decks.txt"; + string decks_dict = JGE_GET_RES("lang/") + lang + "_decks.txt"; // Load file std::ifstream file(decks_dict.c_str()); @@ -136,7 +136,7 @@ void Translator::init() { #endif string lang = options[Options::LANG].str; if (!lang.size()) return; - string name = "Res/lang/" + lang + ".txt"; + string name = JGE_GET_RES("lang/") + lang + ".txt"; if (fileExists(name.c_str())){ // fixup for Chinese language support. diff --git a/projects/mtg/src/WDataSrc.cpp b/projects/mtg/src/WDataSrc.cpp index 11f8375df..fa6d8ccaf 100644 --- a/projects/mtg/src/WDataSrc.cpp +++ b/projects/mtg/src/WDataSrc.cpp @@ -489,7 +489,7 @@ int WSrcDeck::getCount(int count){ } int WSrcDeck::totalPrice(){ int total = 0; - PriceList * pricelist = NEW PriceList(RESPATH"/settings/prices.dat",GameApp::collection); + PriceList * pricelist = NEW PriceList(JGE_GET_RES("settings/prices.dat").c_str(),GameApp::collection); map::iterator it; for ( it=copies.begin() ; it != copies.end(); it++ ){ int nb = it->second; diff --git a/projects/mtg/src/WResourceManager.cpp b/projects/mtg/src/WResourceManager.cpp index ce3af67bc..e461a5fb9 100644 --- a/projects/mtg/src/WResourceManager.cpp +++ b/projects/mtg/src/WResourceManager.cpp @@ -683,7 +683,7 @@ string WResourceManager::cardFile(const string filename){ if(set.size()){ char zipname[512]; - sprintf(zipname, "Res/themes/%s/sets/%s/%s.zip", theme.c_str(), set.c_str(),set.c_str()); + sprintf(zipname, JGE_GET_RES("themes/%s/sets/%s/%s.zip").c_str(), theme.c_str(), set.c_str(),set.c_str()); if (fs->AttachZipFile(zipname)) return filename.substr(i+1); } @@ -718,7 +718,7 @@ string WResourceManager::cardFile(const string filename){ if(set.size()){ char zipname[512]; - sprintf(zipname, "Res/sets/%s/%s.zip", set.c_str(),set.c_str()); + sprintf(zipname, JGE_GET_RES("sets/%s/%s.zip").c_str(), set.c_str(),set.c_str()); if (fs->AttachZipFile(zipname)) return filename.substr(i+1); } @@ -808,13 +808,13 @@ int WResourceManager::dirOK(string dirname){ char fname[512]; #if defined (WIN32) - sprintf(fname,RESPATH"/%s",dirname.c_str()); + 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,RESPATH"/%s",dirname.c_str()); + sprintf(fname,JGE_GET_RES(dirname).c_str()); struct stat st; if(stat(fname,&st) == 0) return 1; @@ -824,11 +824,9 @@ char fname[512]; int WResourceManager::fileOK(string filename, bool relative){ - char fname[512]; std::ifstream * fp = NULL; if(relative){ - sprintf(fname,RESPATH"/%s",filename.c_str()); - fp = NEW std::ifstream(fname); + fp = NEW std::ifstream(JGE_GET_RES(filename).c_str()); } else fp = NEW std::ifstream(filename.c_str()); diff --git a/projects/mtg/src/utils.cpp b/projects/mtg/src/utils.cpp index 707cd8cc0..628ee744a 100644 --- a/projects/mtg/src/utils.cpp +++ b/projects/mtg/src/utils.cpp @@ -64,9 +64,7 @@ if(fichier){ return 1; } -char alternateFilename[512]; -sprintf(alternateFilename, RESPATH"/%s",filename); - std::ifstream fichier2(alternateFilename); +std::ifstream fichier2(JGE_GET_RES(filename).c_str()); if(fichier2){ fichier2.close(); return 1;