Browse Source

Make `loadXmlSettings()` return `bool` value

master
Krisjanis Rijnieks 10 years ago
parent
commit
dbc4eb0d07
  1. 8
      src/Surfaces/SurfaceManager.cpp
  2. 3
      src/Surfaces/SurfaceManager.h
  3. 25
      src/ofxPiMapper.cpp

8
src/Surfaces/SurfaceManager.cpp

@ -192,7 +192,7 @@ void SurfaceManager::saveXmlSettings(string fileName){
xmlSettings.save(fileName);
}
void SurfaceManager::loadXmlSettings(string fileName){
bool SurfaceManager::loadXmlSettings(string fileName){
// Exit if there is no media server
if(mediaServer == 0){
ofLogFatalError("SurfaceManager") << "Media server not set";
@ -200,11 +200,11 @@ void SurfaceManager::loadXmlSettings(string fileName){
}
if(!xmlSettings.loadFile(fileName)){
ofLogWarning("SurfaceManager") << "Could not load XML settings";
return;
return false;
}
if(!xmlSettings.tagExists("surfaces")){
ofLogWarning("SurfaceManager") << "XML settings is empty or has wrong markup";
return;
return false;
}
xmlSettings.pushTag("surfaces");
@ -352,6 +352,8 @@ void SurfaceManager::loadXmlSettings(string fileName){
}
xmlSettings.popTag(); // surfaces
return true;
}
void SurfaceManager::setMediaServer(MediaServer * newMediaServer){

3
src/Surfaces/SurfaceManager.h

@ -37,8 +37,7 @@ class SurfaceManager {
void clear();
void saveXmlSettings(string fileName);
// TODO: Make it bool.
void loadXmlSettings(string fileName);
bool loadXmlSettings(string fileName);
void setMediaServer(MediaServer * newMediaServer);
BaseSurface * getSurface(int index);

25
src/ofxPiMapper.cpp

@ -12,12 +12,12 @@ void ofxPiMapper::setup(){
gui.setMediaServer(&mediaServer);
gui.setCmdManager(&cmdManager);
if(ofFile::doesFileExist(PIMAPPER_USER_SURFACES_XML_FILE)){
ofLogNotice("ofxPiMapper") << "Loading user surfaces from " << PIMAPPER_USER_SURFACES_XML_FILE;
surfaceManager.loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE);
}else{
ofLogNotice("ofxPiMapper") << "Loading default surfaces from " << PIMAPPER_DEF_SURFACES_XML_FILE;
surfaceManager.loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE);
if(!loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE)){
ofLogWarning("ofxPiMapper::setup()") << "Failed to load user settings, go with default" << endl;
if(!loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE)){
ofLogError("ofxPiMapper::setup()") << "Failed to load default settings, exit" << endl;
ofExit(EXIT_FAILURE);
}
}
gui.setSurfaceManager(&surfaceManager);
@ -60,17 +60,14 @@ void ofxPiMapper::registerFboSource(ofx::piMapper::FboSource & fboSource){
}
bool ofxPiMapper::loadXmlSettings(string fileName){
/*
if(surfaceManager == 0){
ofLogNotice("ofxPiMapper::loadXmlSettings()") << "Could not load XML settings as the surfaceManager is not initialized yet.";
return;
}
*/
if(!ofFile::doesFileExist(fileName)){
ofLogNotice("ofxPiMapper::loadXmlSettings()") << "Settings file does not exist.";
ofLogError("ofxPiMapper::loadXmlSettings()") << fileName << " does not exist";
return false;
}
if(!surfaceManager.loadXmlSettings(fileName)){
ofLogError("ofxPiMapper::loadXmlSettings()") << "Failed to load " << fileName << endl;
return false;
}
surfaceManager.loadXmlSettings(fileName);
return true;
}

Loading…
Cancel
Save