From 54791762b1fb1046ec6b1f1132cbbf188381bf07 Mon Sep 17 00:00:00 2001 From: "jean.chalard" Date: Thu, 17 Dec 2009 17:29:24 +0000 Subject: [PATCH] J : * Fix a bug where valid directories would be ignored and invalid ones would be accepted for profiles and themes. * Fix a compilation fault when compiling in debug mode. --- projects/mtg/include/OptionItem.h | 15 ++++++--- projects/mtg/src/MTGDeck.cpp | 4 +-- projects/mtg/src/OptionItem.cpp | 53 +++++++++++++------------------ 3 files changed, 34 insertions(+), 38 deletions(-) diff --git a/projects/mtg/include/OptionItem.h b/projects/mtg/include/OptionItem.h index 56942477c..8d3870478 100644 --- a/projects/mtg/include/OptionItem.h +++ b/projects/mtg/include/OptionItem.h @@ -474,15 +474,18 @@ protected: class OptionDirectory:public OptionSelect{ public: virtual void Reload(); - OptionDirectory(string _root, int _id, string _displayValue); + OptionDirectory(string root, int id, string displayValue, const string type); protected: - string root; + const string root; + const string type; }; class OptionTheme:public OptionDirectory{ + private: + static const string DIRTESTER; public: OptionTheme(); - JQuad * getImage(); + JQuad * getImage(); virtual void updateValue(); virtual float getHeight(); virtual void Render(); @@ -495,9 +498,11 @@ protected: }; class OptionProfile:public OptionDirectory{ + private: + static const string DIRTESTER; public: OptionProfile(GameApp * _app, JGuiListener * jgl); - virtual void addSelection(string s); + virtual void addSelection(string s); virtual bool Selectable() {return canSelect;}; virtual bool Changed() {return (initialValue != value);}; virtual void Entering(u32 key); @@ -514,4 +519,4 @@ private: string preview; size_t initialValue; }; -#endif \ No newline at end of file +#endif diff --git a/projects/mtg/src/MTGDeck.cpp b/projects/mtg/src/MTGDeck.cpp index 2b7f55505..63c6a0777 100644 --- a/projects/mtg/src/MTGDeck.cpp +++ b/projects/mtg/src/MTGDeck.cpp @@ -115,7 +115,7 @@ int MTGAllCards::processConfLine(string s, MTGCard *card){ card->setType( "Error"); #if defined (_DEBUG) char buffer[4096]; - sprintf(buffer, "MTGDECK: Bad Card Type in %s/_cards.dat:\n %s\n", setlist[card->setId], s.c_str()); + sprintf(buffer, "MTGDECK: Bad Card Type in %s/_cards.dat:\n %s\n", setlist[card->setId].c_str(), s.c_str()); OutputDebugString(buffer); #endif break; @@ -799,4 +799,4 @@ string MTGSetInfo::getBlock(){ return "None"; return setlist.blocks[block]; -} \ No newline at end of file +} diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index ef676383e..8280a0b77 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -157,7 +157,8 @@ void OptionSelect::addSelection(string s){ } //OptionProfile -OptionProfile::OptionProfile(GameApp * _app, JGuiListener * jgl): OptionDirectory(RESPATH"/profiles",Options::ACTIVE_PROFILE, "Profile"){ +const string OptionProfile::DIRTESTER = "collection.dat"; +OptionProfile::OptionProfile(GameApp * _app, JGuiListener * jgl) : OptionDirectory(RESPATH"/profiles", Options::ACTIVE_PROFILE, "Profile", DIRTESTER){ app = _app; listener = jgl; height=60; @@ -372,23 +373,18 @@ bool OptionLanguage::Selectable(){ void OptionDirectory::Reload(){ DIR *mDip; struct dirent *mDit; - char buf[4096]; + char buf[PATH_MAX]; mDip = opendir(root.c_str()); - if(!mDip) - return; + if (!mDip) return; while ((mDit = readdir(mDip))){ - if(mDit->d_name[0] != '.'){ - sprintf(buf,"%s/%s",root.c_str(),mDit->d_name); - std::ifstream file(buf); - if(file){ - file.close(); - continue; - } - if(find(selections.begin(),selections.end(),mDit->d_name) == selections.end()) - addSelection(mDit->d_name); - } + sprintf(buf,"%s/%s/%s", root.c_str(), mDit->d_name, type.c_str()); + std::ifstream file(buf); + if (!file) continue; + file.close(); + if (find(selections.begin(), selections.end(), mDit->d_name) == selections.end()) + addSelection(mDit->d_name); } closedir(mDip); @@ -396,26 +392,20 @@ void OptionDirectory::Reload(){ initSelections(); } -OptionDirectory::OptionDirectory(string _root, int _id, string _displayValue): OptionSelect(_id, _displayValue){ +OptionDirectory::OptionDirectory(string root, int id, string displayValue, string type): OptionSelect(id, displayValue), root(root), type(type){ DIR *mDip; struct dirent *mDit; - char buf[4096]; - root = _root; - mDip = opendir(root.c_str()); + char buf[PATH_MAX]; - if(!mDip) - return; + mDip = opendir(root.c_str()); + if(!mDip) return; while ((mDit = readdir(mDip))){ - if(mDit->d_name[0] != '.'){ - sprintf(buf,"%s/%s",root.c_str(),mDit->d_name); - std::ifstream file(buf); - if(file){ - file.close(); - continue; - } - addSelection(mDit->d_name); - } + sprintf(buf,"%s/%s/%s", root.c_str(), mDit->d_name, type.c_str()); + cout << buf << endl; + std::ifstream file(buf); + if (!file) continue; + addSelection(mDit->d_name); } closedir(mDip); @@ -626,7 +616,8 @@ void WGuiList::ButtonPressed(int controllerId, int controlId){ it->ButtonPressed(controllerId,controlId); } -OptionTheme::OptionTheme(): OptionDirectory(RESPATH"/themes",Options::ACTIVE_THEME, "Current Theme"){ +const string OptionTheme::DIRTESTER = "preview.png"; +OptionTheme::OptionTheme() : OptionDirectory(RESPATH"/themes", Options::ACTIVE_THEME, "Current Theme", DIRTESTER){ addSelection("Default"); sort(selections.begin(),selections.end()); initSelections(); @@ -1476,4 +1467,4 @@ bool WSrcMTGSet::thisCard(int mtgid){ } } return false; -} \ No newline at end of file +}