lib: Add support for looking up files from share/ocarina/

I replace the /proc/self/exe method with a simple hard-coded string.
This means that binaries run from the source directory need to be run
from the root of the source directory.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-06-14 20:55:18 -04:00
parent f2575d9799
commit 4ed36c79df
5 changed files with 21 additions and 21 deletions

View File

@ -8,6 +8,7 @@
#include <core/idle.h>
#include <core/playlist.h>
#include <core/print.h>
#include <lib/lib.h>
#include <gui/ocarina.h>
#include <gui/tabs.h>
@ -245,7 +246,7 @@ Gtk::Window *setup_gui()
struct Callbacks *cb = get_callbacks();
builder = Gtk::Builder::create();
builder->add_from_file(share_file("ocarina6.glade"));
builder->add_from_file(lib :: share_file("ocarina6.glade"));
/* Controls */
@ -275,7 +276,7 @@ Gtk::Window *setup_gui()
window->signal_key_press_event().connect(sigc::ptr_fun(on_window_key_pressed));
window->signal_key_release_event().connect(sigc::ptr_fun(on_window_key_released));
window->set_can_focus();
window->set_icon_from_file(share_file("ocarina.png"));
window->set_icon_from_file(lib :: share_file("ocarina.png"));
/* Favorite and ban buttons */

View File

@ -6,23 +6,6 @@
#include <gui/ocarina.h>
#include <gui/tabs.h>
const std::string share_file(const std::string &file)
{
char buf[1024];
std::string res;
ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
if (len == -1)
return "";
buf[len] = '\0';
res = std::string(buf);
// len("bin/ocarina") == 11
res = res.substr(0, res.size() - 11);
return res + "share/ocarina/" + file;
}
Gtk::Window *ocarina_init(int *argc, char ***argv)
{
Gtk::Window *window = setup_gui();
@ -30,7 +13,6 @@ Gtk::Window *ocarina_init(int *argc, char ***argv)
lib :: init(argc, argv);
playlist :: select("Favorites");
share_file("ocarina6.glade");
post_init_tabs();
collection_mgr_init2();
return window;

View File

@ -15,7 +15,6 @@ void collection_mgr_update();
/* main.cpp */
const std::string share_file(const std::string &);
Gtk::Window *ocarina_init(int *, char ***);

View File

@ -5,15 +5,32 @@
#include <core/deck.h>
#include <core/library.h>
#include <core/playlist.h>
#include <core/print.h>
#include <core/tags.h>
#include <lib/lib.h>
static std::string share_dir = "";
static void setup_share(const std::string &path)
{
if (path == "/usr/bin/ocarina")
share_dir = "/usr/share/ocarina/";
else
share_dir = "./share/ocarina/";
}
void lib :: init(int *argc, char ***argv)
{
setup_share((*argv)[0]);
tagdb :: init();
library :: init();
playlist :: init();
deck :: init();
audio :: init(argc, argv);
}
const std::string lib :: share_file(const std::string &f)
{
return share_dir + f;
}

View File

@ -13,6 +13,7 @@ static void test_init(int argc, char **argv)
lib :: init(&argc, &argv);
test_equal(deck :: get_queues().size(), (size_t)2);
test_equal(lib :: share_file("saria"), (std::string)"./share/ocarina/saria");
}
int main(int argc, char **argv)