Browse Source

Use only one settings file (ofxpimapper.xml)

Create it if it is not there.
master
Krisjanis Rijnieks 9 years ago
parent
commit
dfd9dc8c14
  1. 12
      src/Application/Application.cpp
  2. 3
      src/Application/Application.h
  3. 31
      src/Application/SettingsLoader.cpp
  4. 3
      src/Application/SettingsLoader.h

12
src/Application/Application.cpp

@ -32,10 +32,14 @@ Application::Application(){
} }
void Application::setup(){ void Application::setup(){
if(!loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE)){ if(!loadXmlSettings(PIMAPPER_SETTINGS_FILE)){
ofLogWarning("Application::setup()") << "Failed to load user settings" << endl; if(SettingsLoader::instance()->create(PIMAPPER_SETTINGS_FILE)){
if(!loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE)){ bool success = loadXmlSettings(PIMAPPER_SETTINGS_FILE);
ofLogWarning("Application::setup()") << "Failed to load default settings" << endl; if(!success){
throw runtime_error("ofxPiMapper: Failed to load settings.");
}
}else{
throw runtime_error("ofxPiMapper: Failed to create default settings file.");
} }
} }

3
src/Application/Application.h

@ -22,8 +22,7 @@
#include "Gui.h" #include "Gui.h"
#include "TerminalListener.h" #include "TerminalListener.h"
#define PIMAPPER_DEF_SURFACES_XML_FILE "defaultSurfaces.xml" #define PIMAPPER_SETTINGS_FILE "ofxpimapper.xml"
#define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {

31
src/Application/SettingsLoader.cpp

@ -33,18 +33,18 @@ bool SettingsLoader::load(
} }
if(!xmlSettings->tagExists("surfaces")){ if(!xmlSettings->tagExists("surfaces")){
ofLogWarning("SettingsLoader::load()") << "XML settings is empty or has wrong markup"; xmlSettings->addTag("surfaces");
return false; }
}else{
// Count <surfaces> tags. // Count <surfaces> tags.
unsigned int numPresets = xmlSettings->getNumTags("surfaces"); unsigned int numPresets = xmlSettings->getNumTags("surfaces");
cout << "numPresets: " << numPresets << endl; cout << "numPresets: " << numPresets << endl;
// Clear previous presets and surfaces first. // Clear previous presets and surfaces first.
surfaceManager.clearPresets(); surfaceManager.clearPresets();
// Loop through <surfaces> tags in the XML. // Loop through <surfaces> tags in the XML.
for(unsigned int i = 0; i < numPresets; ++i){ for(unsigned int i = 0; i < numPresets; ++i){
xmlSettings->pushTag("surfaces", i); xmlSettings->pushTag("surfaces", i);
@ -135,8 +135,7 @@ bool SettingsLoader::load(
xmlSettings->popTag(); // surfaces xmlSettings->popTag(); // surfaces
} // for } // for
}
_lastLoadedFilename = fileName; _lastLoadedFilename = fileName;
@ -231,6 +230,12 @@ bool SettingsLoader::save(SurfaceManager & surfaceManager, string fileName){
xmlSettings->save(fileName); xmlSettings->save(fileName);
} }
bool SettingsLoader::create(string fileName){
ofxXmlSettings xml;
xml.addTag("surfaces");
return xml.save(fileName);
}
BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){ BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){
vector <ofVec2f> vertices; vector <ofVec2f> vertices;
@ -459,4 +464,4 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

3
src/Application/SettingsLoader.h

@ -19,6 +19,7 @@ class SettingsLoader {
bool load(SurfaceManager & surfaceManager, MediaServer & mediaServer, string fileName); bool load(SurfaceManager & surfaceManager, MediaServer & mediaServer, string fileName);
bool save(SurfaceManager & surfaceManager, string fileName); bool save(SurfaceManager & surfaceManager, string fileName);
bool create(string fileName);
string getLastLoadedFilename(){ return _lastLoadedFilename; }; string getLastLoadedFilename(){ return _lastLoadedFilename; };
@ -35,4 +36,4 @@ class SettingsLoader {
}; };
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

Loading…
Cancel
Save