diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index e1be7cc..5526c38 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -32,10 +32,14 @@ Application::Application(){ } void Application::setup(){ - if(!loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE)){ - ofLogWarning("Application::setup()") << "Failed to load user settings" << endl; - if(!loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE)){ - ofLogWarning("Application::setup()") << "Failed to load default settings" << endl; + if(!loadXmlSettings(PIMAPPER_SETTINGS_FILE)){ + if(SettingsLoader::instance()->create(PIMAPPER_SETTINGS_FILE)){ + bool success = loadXmlSettings(PIMAPPER_SETTINGS_FILE); + if(!success){ + throw runtime_error("ofxPiMapper: Failed to load settings."); + } + }else{ + throw runtime_error("ofxPiMapper: Failed to create default settings file."); } } diff --git a/src/Application/Application.h b/src/Application/Application.h index 4c61537..7516948 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -22,8 +22,7 @@ #include "Gui.h" #include "TerminalListener.h" -#define PIMAPPER_DEF_SURFACES_XML_FILE "defaultSurfaces.xml" -#define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml" +#define PIMAPPER_SETTINGS_FILE "ofxpimapper.xml" namespace ofx { namespace piMapper { diff --git a/src/Application/SettingsLoader.cpp b/src/Application/SettingsLoader.cpp index 6af4394..8dd461d 100644 --- a/src/Application/SettingsLoader.cpp +++ b/src/Application/SettingsLoader.cpp @@ -33,18 +33,18 @@ bool SettingsLoader::load( } if(!xmlSettings->tagExists("surfaces")){ - ofLogWarning("SettingsLoader::load()") << "XML settings is empty or has wrong markup"; - return false; - }else{ - // Count tags. - unsigned int numPresets = xmlSettings->getNumTags("surfaces"); - cout << "numPresets: " << numPresets << endl; + xmlSettings->addTag("surfaces"); + } + + // Count tags. + unsigned int numPresets = xmlSettings->getNumTags("surfaces"); + cout << "numPresets: " << numPresets << endl; - // Clear previous presets and surfaces first. - surfaceManager.clearPresets(); + // Clear previous presets and surfaces first. + surfaceManager.clearPresets(); - // Loop through tags in the XML. - for(unsigned int i = 0; i < numPresets; ++i){ + // Loop through tags in the XML. + for(unsigned int i = 0; i < numPresets; ++i){ xmlSettings->pushTag("surfaces", i); @@ -135,8 +135,7 @@ bool SettingsLoader::load( xmlSettings->popTag(); // surfaces - } // for - } + } // for _lastLoadedFilename = fileName; @@ -231,6 +230,12 @@ bool SettingsLoader::save(SurfaceManager & surfaceManager, string fileName){ xmlSettings->save(fileName); } +bool SettingsLoader::create(string fileName){ + ofxXmlSettings xml; + xml.addTag("surfaces"); + return xml.save(fileName); +} + BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){ vector vertices; @@ -459,4 +464,4 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){ } // namespace piMapper -} // namespace ofx \ No newline at end of file +} // namespace ofx diff --git a/src/Application/SettingsLoader.h b/src/Application/SettingsLoader.h index eee6327..329385d 100644 --- a/src/Application/SettingsLoader.h +++ b/src/Application/SettingsLoader.h @@ -19,6 +19,7 @@ class SettingsLoader { bool load(SurfaceManager & surfaceManager, MediaServer & mediaServer, string fileName); bool save(SurfaceManager & surfaceManager, string fileName); + bool create(string fileName); string getLastLoadedFilename(){ return _lastLoadedFilename; }; @@ -35,4 +36,4 @@ class SettingsLoader { }; } // namespace piMapper -} // namespace ofx \ No newline at end of file +} // namespace ofx