* 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.
This commit is contained in:
jean.chalard
2009-12-17 17:29:24 +00:00
parent 92e7d8831b
commit 54791762b1
3 changed files with 34 additions and 38 deletions

View File

@@ -474,15 +474,18 @@ protected:
class OptionDirectory:public OptionSelect{ class OptionDirectory:public OptionSelect{
public: public:
virtual void Reload(); virtual void Reload();
OptionDirectory(string _root, int _id, string _displayValue); OptionDirectory(string root, int id, string displayValue, const string type);
protected: protected:
string root; const string root;
const string type;
}; };
class OptionTheme:public OptionDirectory{ class OptionTheme:public OptionDirectory{
private:
static const string DIRTESTER;
public: public:
OptionTheme(); OptionTheme();
JQuad * getImage(); JQuad * getImage();
virtual void updateValue(); virtual void updateValue();
virtual float getHeight(); virtual float getHeight();
virtual void Render(); virtual void Render();
@@ -495,9 +498,11 @@ protected:
}; };
class OptionProfile:public OptionDirectory{ class OptionProfile:public OptionDirectory{
private:
static const string DIRTESTER;
public: public:
OptionProfile(GameApp * _app, JGuiListener * jgl); OptionProfile(GameApp * _app, JGuiListener * jgl);
virtual void addSelection(string s); virtual void addSelection(string s);
virtual bool Selectable() {return canSelect;}; virtual bool Selectable() {return canSelect;};
virtual bool Changed() {return (initialValue != value);}; virtual bool Changed() {return (initialValue != value);};
virtual void Entering(u32 key); virtual void Entering(u32 key);
@@ -514,4 +519,4 @@ private:
string preview; string preview;
size_t initialValue; size_t initialValue;
}; };
#endif #endif

View File

@@ -115,7 +115,7 @@ int MTGAllCards::processConfLine(string s, MTGCard *card){
card->setType( "Error"); card->setType( "Error");
#if defined (_DEBUG) #if defined (_DEBUG)
char buffer[4096]; 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); OutputDebugString(buffer);
#endif #endif
break; break;
@@ -799,4 +799,4 @@ string MTGSetInfo::getBlock(){
return "None"; return "None";
return setlist.blocks[block]; return setlist.blocks[block];
} }

View File

@@ -157,7 +157,8 @@ void OptionSelect::addSelection(string s){
} }
//OptionProfile //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; app = _app;
listener = jgl; listener = jgl;
height=60; height=60;
@@ -372,23 +373,18 @@ bool OptionLanguage::Selectable(){
void OptionDirectory::Reload(){ void OptionDirectory::Reload(){
DIR *mDip; DIR *mDip;
struct dirent *mDit; struct dirent *mDit;
char buf[4096]; char buf[PATH_MAX];
mDip = opendir(root.c_str()); mDip = opendir(root.c_str());
if(!mDip) if (!mDip) return;
return;
while ((mDit = readdir(mDip))){ while ((mDit = readdir(mDip))){
if(mDit->d_name[0] != '.'){ sprintf(buf,"%s/%s/%s", root.c_str(), mDit->d_name, type.c_str());
sprintf(buf,"%s/%s",root.c_str(),mDit->d_name); std::ifstream file(buf);
std::ifstream file(buf); if (!file) continue;
if(file){ file.close();
file.close(); if (find(selections.begin(), selections.end(), mDit->d_name) == selections.end())
continue; addSelection(mDit->d_name);
}
if(find(selections.begin(),selections.end(),mDit->d_name) == selections.end())
addSelection(mDit->d_name);
}
} }
closedir(mDip); closedir(mDip);
@@ -396,26 +392,20 @@ void OptionDirectory::Reload(){
initSelections(); 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; DIR *mDip;
struct dirent *mDit; struct dirent *mDit;
char buf[4096]; char buf[PATH_MAX];
root = _root;
mDip = opendir(root.c_str());
if(!mDip) mDip = opendir(root.c_str());
return; if(!mDip) return;
while ((mDit = readdir(mDip))){ while ((mDit = readdir(mDip))){
if(mDit->d_name[0] != '.'){ sprintf(buf,"%s/%s/%s", root.c_str(), mDit->d_name, type.c_str());
sprintf(buf,"%s/%s",root.c_str(),mDit->d_name); cout << buf << endl;
std::ifstream file(buf); std::ifstream file(buf);
if(file){ if (!file) continue;
file.close(); addSelection(mDit->d_name);
continue;
}
addSelection(mDit->d_name);
}
} }
closedir(mDip); closedir(mDip);
@@ -626,7 +616,8 @@ void WGuiList::ButtonPressed(int controllerId, int controlId){
it->ButtonPressed(controllerId,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"); addSelection("Default");
sort(selections.begin(),selections.end()); sort(selections.begin(),selections.end());
initSelections(); initSelections();
@@ -1476,4 +1467,4 @@ bool WSrcMTGSet::thisCard(int mtgid){
} }
} }
return false; return false;
} }