* 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{
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
#endif

View File

@@ -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];
}
}

View File

@@ -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;
}
}