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(){
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 {

31
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 <surfaces> tags.
unsigned int numPresets = xmlSettings->getNumTags("surfaces");
cout << "numPresets: " << numPresets << endl;
xmlSettings->addTag("surfaces");
}
// Count <surfaces> 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 <surfaces> tags in the XML.
for(unsigned int i = 0; i < numPresets; ++i){
// Loop through <surfaces> 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 <ofVec2f> vertices;
@ -459,4 +464,4 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
} // 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 save(SurfaceManager & surfaceManager, string fileName);
bool create(string fileName);
string getLastLoadedFilename(){ return _lastLoadedFilename; };
@ -35,4 +36,4 @@ class SettingsLoader {
};
} // namespace piMapper
} // namespace ofx
} // namespace ofx

Loading…
Cancel
Save