ocarina: Use files in the lib directory
I copy images and other files to lib/ocarina/ during the build to make installing easier. The lib directory should always be relative to the bin (executable) path, so I can easily find the lib path based on executable path (/proc/self/exe). I can also use this to find bugs in the buld process, such as adding a file to the images/ directory but forgetting to add it as an install target. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
dcaeb8cbd1
commit
80cf0bb28e
|
@ -5,7 +5,7 @@ MAJOR = 5
|
|||
MINOR = 9
|
||||
BUG = 0
|
||||
EXTRA = "rc"
|
||||
DEBUG = False
|
||||
DEBUG = True
|
||||
|
||||
|
||||
env = None
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace ocarina
|
|||
|
||||
void quit();
|
||||
void idle_add();
|
||||
string full_path(string);
|
||||
string lib_file(string);
|
||||
void init_pipe();
|
||||
|
||||
};
|
||||
|
|
|
@ -8,15 +8,37 @@
|
|||
#include <ocarina/window.h>
|
||||
#include <ocarina/body.h>
|
||||
|
||||
static string path_prefix;
|
||||
static string lib_path;
|
||||
static bool using_idle = false;
|
||||
|
||||
void set_path_prefix(string prefix)
|
||||
static void find_exe_path(string &res)
|
||||
{
|
||||
unsigned int found = prefix.rfind("/");
|
||||
if (found != string::npos)
|
||||
path_prefix = prefix.substr(0, found);
|
||||
println("Path prefix: " + path_prefix);
|
||||
char buf[1024];
|
||||
ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) -1);
|
||||
if (len != -1)
|
||||
res = string(buf);
|
||||
}
|
||||
|
||||
static void rstrip_word(string &path)
|
||||
{
|
||||
unsigned int index = path.rfind("/");
|
||||
if (index != string::npos)
|
||||
path = path.substr(0, index);
|
||||
}
|
||||
|
||||
static void find_lib_path()
|
||||
{
|
||||
string exe;
|
||||
|
||||
find_exe_path(exe);
|
||||
if (exe == "")
|
||||
return;
|
||||
|
||||
rstrip_word(exe); // ocarina-player
|
||||
rstrip_word(exe); // bin/
|
||||
|
||||
lib_path = exe + "/lib/ocarina/";
|
||||
println("Lib directory? %s", lib_path.c_str());
|
||||
}
|
||||
|
||||
static gboolean idle(gpointer data)
|
||||
|
@ -42,9 +64,9 @@ static void idle_add()
|
|||
namespace ocarina
|
||||
{
|
||||
|
||||
string full_path(string path)
|
||||
string lib_file(string path)
|
||||
{
|
||||
string res = path_prefix + "/" + path;
|
||||
string res = lib_path + "/" + path;
|
||||
println("Expanding to path: " + res);
|
||||
return res;
|
||||
}
|
||||
|
@ -84,7 +106,7 @@ int main(int argc, char **argv)
|
|||
true, /* Use global pipe? */
|
||||
};
|
||||
println("Ocarina " + vers_str());
|
||||
set_path_prefix(argv[0]);
|
||||
find_lib_path();
|
||||
|
||||
libsaria::init(&ls_init);
|
||||
init(argc, argv);
|
||||
|
|
|
@ -132,7 +132,7 @@ namespace ocarina
|
|||
g_signal_connect_after(win, "key-press-event", G_CALLBACK(key_pressed_after), NULL);
|
||||
|
||||
set_title("Ocarina " + vers_str());
|
||||
set_icon(full_path("images/ocarina.png"));
|
||||
set_icon(lib_file("ocarina.png"));
|
||||
|
||||
old_w = libsaria::prefs::init("ocarina.window.w", 800);
|
||||
old_h = libsaria::prefs::init("ocarina.window.h", 600);
|
||||
|
|
Loading…
Reference in New Issue