From 951f58445c073818c4005375f9028eb73a4fbd73 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Fri, 1 Jan 2021 11:40:23 +0100 Subject: [PATCH] Fix path detection on Haiku --- COPYRIGHT.txt | 2 +- src/haiku.cpp | 16 +++++++++++++++- src/haiku.h | 1 + src/setup.c | 2 ++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt index 161513d0..c7fa127a 100644 --- a/COPYRIGHT.txt +++ b/COPYRIGHT.txt @@ -118,7 +118,7 @@ Copyright 2010 Fernando Mastandrea (masta.uy) Copyright 2008-2009 Peter Gordon Copyright 2008-2012 Franck Charlet Copyright 2008-2020 Yves Rizoud -Copyright 2007-2020 Adrien Destugues +Copyright 2007-2021 Adrien Destugues Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud) GNU GPL version 2. diff --git a/src/haiku.cpp b/src/haiku.cpp index 6ede53d9..708564ce 100644 --- a/src/haiku.cpp +++ b/src/haiku.cpp @@ -2,7 +2,7 @@ */ /* Grafx2 - The Ultimate 256-color bitmap paint program - Copyright 2007 Adrien Destugues + Copyright 2007-2021 Adrien Destugues Grafx2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -26,8 +26,10 @@ #ifdef __HAIKU__ #include #include +#include #include +#include #include #include "haiku.h" @@ -57,4 +59,16 @@ char* haiku_get_clipboard() } return NULL; } + +const char* haiku_get_app_path() +{ + static image_info info; + static int32 cookie = 0; + + if (cookie == 0) do { + get_next_image_info(B_CURRENT_TEAM, &cookie, &info); + } while (info.type != B_APP_IMAGE); + + return info.name; +} #endif diff --git a/src/haiku.h b/src/haiku.h index 07349b55..8b0018a9 100644 --- a/src/haiku.h +++ b/src/haiku.h @@ -31,6 +31,7 @@ extern "C" { #endif qword haiku_get_free_space(char* path); char* haiku_get_clipboard(); +const char* haiku_get_app_path(); #ifdef __cplusplus } #endif diff --git a/src/setup.c b/src/setup.c index 6fac52e0..104d126d 100644 --- a/src/setup.c +++ b/src/setup.c @@ -137,6 +137,8 @@ char * Get_program_directory(const char * argv0) } else program_dir = Extract_path(NULL, argv0); + #elif defined(__HAIKU__) + program_dir = Extract_path(NULL, haiku_get_app_path()); // Others: The part of argv[0] before the executable name. // Keep the last \ or /.