diff options
author | Thomas White <taw@physics.org> | 2020-11-30 16:16:48 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2020-11-30 17:32:30 +0100 |
commit | 0ae37898f3d5ed0a8d73fa35d92f99ae179d13e6 (patch) | |
tree | 23ad68b7af316775b71848c56a27320fc0929de6 /src/crystfel_gui.c | |
parent | d4a5907123f3fa4a401e6f45a68ee6885a1086c9 (diff) |
Move get_crystfel_exe and get_crystfel_path_str to crystfel_gui.c
Diffstat (limited to 'src/crystfel_gui.c')
-rw-r--r-- | src/crystfel_gui.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c index 8ceef8fb..7be8e67b 100644 --- a/src/crystfel_gui.c +++ b/src/crystfel_gui.c @@ -1187,3 +1187,71 @@ void add_running_task(struct crystfelproject *proj, g_timeout_add(500, update_info_bar, task); } + + +static GFile *get_crystfel_path_gfile() +{ + GFile *self; + GFileInfo *self_info; + const char *self_target; + GFile *tar; + GFile *parent_dir; + GError *error = NULL; + + self = g_file_new_for_path("/proc/self/exe"); + self_info = g_file_query_info(self, "standard", + G_FILE_QUERY_INFO_NONE, + NULL, &error); + if ( self_info == NULL ) return NULL; + + self_target = g_file_info_get_symlink_target(self_info); + if ( self_target == NULL ) return NULL; + + tar = g_file_new_for_path(self_target); + if ( tar == NULL ) return NULL; + + parent_dir = g_file_get_parent(tar); + if ( parent_dir == NULL ) return NULL; + + g_object_unref(self); + g_object_unref(self_info); + g_object_unref(tar); + + return parent_dir; +} + + +char *get_crystfel_path_str() +{ + char *path; + GFile *crystfel_path = get_crystfel_path_gfile(); + if ( crystfel_path == NULL ) return NULL; + path = g_file_get_path(crystfel_path); + g_object_unref(crystfel_path); + return path; +} + + +char *get_crystfel_exe(const char *program) +{ + GFile *crystfel_path; + char *exe_path; + GFile *exe; + + crystfel_path = get_crystfel_path_gfile(); + if ( crystfel_path == NULL ) return NULL; + + exe = g_file_get_child(crystfel_path, program); + if ( exe == NULL ) { + ERROR("Couldn't determine executable path. " + "This is OK provided the executable " + "path is set correctly.\n"); + exe_path = strdup(program); + } + + exe_path = g_file_get_path(exe); + g_object_unref(exe); + g_object_unref(crystfel_path); + + return exe_path; +} |