summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/GladeFile.hpp51
-rw-r--r--src/binary_location.h22
-rw-r--r--src/main.cpp7
3 files changed, 46 insertions, 34 deletions
diff --git a/src/GladeFile.hpp b/src/GladeFile.hpp
index 2f6ad4b..da9ea3b 100644
--- a/src/GladeFile.hpp
+++ b/src/GladeFile.hpp
@@ -25,35 +25,50 @@
#include <libglademm/xml.h>
-#include "patchage-config.h"
+#include "raul/log.hpp"
-#ifdef BUNDLE
+#include "patchage-config.h"
+#ifdef PATCHAGE_BINLOC
#include "binary_location.h"
#endif
class GladeFile {
public:
+ inline static bool is_readable(const std::string& filename) {
+ std::ifstream fs(filename.c_str());
+ const bool fail = fs.fail();
+ fs.close();
+ return !fail;
+ }
+
static Glib::RefPtr<Gnome::Glade::Xml> open(const std::string& base_name) {
std::string glade_filename;
-#ifdef BUNDLE
- char* loc = binary_location();
- std::string bundle = loc;
- bundle = bundle.substr(0, bundle.find_last_of("/"));
- glade_filename = bundle + "/" + PATCHAGE_DATA_DIR + "/" + base_name + ".glade";
- free(loc);
-#else
- glade_filename = std::string(PATCHAGE_DATA_DIR) + "/" + base_name + ".glade";
+ char* loc = NULL;
+#ifdef PATCHAGE_BINLOC
+ loc = binary_location();
+ if (loc) {
+ std::string bundle = loc;
+ bundle = bundle.substr(0, bundle.find_last_of("/"));
+ glade_filename = bundle + "/" + base_name + ".glade";
+ free(loc);
+ if (is_readable(glade_filename)) {
+ Raul::info << "Loading glade file " << glade_filename << std::endl;
+ return Gnome::Glade::Xml::create(glade_filename);
+ }
+ }
#endif
- std::ifstream fs(glade_filename.c_str());
- if (fs.fail()) {
- std::ostringstream ss;
- ss << "Unable to find " << base_name << ".glade in " << PATCHAGE_DATA_DIR << std::endl;
- throw std::runtime_error(ss.str());
+ glade_filename = std::string(PATCHAGE_DATA_DIR) + "/" + base_name + ".glade";
+ if (is_readable(glade_filename)) {
+ Raul::info << "Loading glade file " << glade_filename << std::endl;
+ return Gnome::Glade::Xml::create(glade_filename);
}
- fs.close();
-
- return Gnome::Glade::Xml::create(glade_filename);
+ std::stringstream ss;
+ ss << "Unable to find " << base_name << ".glade in " << loc
+ << " or " << PATCHAGE_DATA_DIR << std::endl;
+ throw std::runtime_error(ss.str());
+ return Glib::RefPtr<Gnome::Glade::Xml>();
+ //return Gnome::Glade::Xml::create(glade_filename);
}
};
diff --git a/src/binary_location.h b/src/binary_location.h
index 58868a7..033dcae 100644
--- a/src/binary_location.h
+++ b/src/binary_location.h
@@ -1,5 +1,5 @@
/* Find the location of the program in the filesytem.
- * Copyright (C) 2008-2009 David Robillard <http://drobilla.net>
+ * Copyright (C) 2008-2010 David Robillard <http://drobilla.net>
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
@@ -19,10 +19,10 @@
#define _GNU_SOURCE
#endif
-#include <dlfcn.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <assert.h>
#include <limits.h>
+#include <stdlib.h>
+#include <dlfcn.h>
/** Return the absolute path of the binary.
* Returned value must be freed by caller.
@@ -31,11 +31,11 @@ static char*
binary_location()
{
Dl_info dli;
- dladdr((void*)&binary_location, &dli);
-
- char* bin_loc = (char*)calloc(PATH_MAX, sizeof(char));
- realpath(dli.dli_fname, bin_loc);
-
- return bin_loc;
+ const int ret = dladdr((void*)&binary_location, &dli);
+ if (ret) {
+ char* const bin_loc = (char*)calloc(PATH_MAX, sizeof(char));
+ realpath(dli.dli_fname, bin_loc);
+ return bin_loc;
+ }
+ return NULL;
}
-
diff --git a/src/main.cpp b/src/main.cpp
index 2087e2a..7c90ea5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,13 +36,10 @@ main(int argc, char** argv)
app.run(*patchage.window());
} catch (std::exception& e) {
- Raul::error << "Caught exception, aborting. Error message was: "
- << e.what() << std::endl;
+ Raul::error << "patchage: error: " << e.what() << std::endl;
return 1;
-
} catch (Glib::Exception& e) {
- Raul::error << "Caught exception, aborting. Error message was: "
- << e.what() << std::endl;
+ Raul::error << "patchage: error: " << e.what() << std::endl;
return 1;
}