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. 13
      src/Application/SettingsLoader.cpp
  4. 1
      src/Application/SettingsLoader.h

12
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.");
}
}

3
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 {

13
src/Application/SettingsLoader.cpp

@ -33,9 +33,9 @@ bool SettingsLoader::load(
}
if(!xmlSettings->tagExists("surfaces")){
ofLogWarning("SettingsLoader::load()") << "XML settings is empty or has wrong markup";
return false;
}else{
xmlSettings->addTag("surfaces");
}
// Count <surfaces> tags.
unsigned int numPresets = xmlSettings->getNumTags("surfaces");
cout << "numPresets: " << numPresets << endl;
@ -136,7 +136,6 @@ bool SettingsLoader::load(
xmlSettings->popTag(); // surfaces
} // 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 <ofVec2f> vertices;

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

Loading…
Cancel
Save