From ea9101cbd8b23d15cf9955c0e3b8fd1c390162dc Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 24 Sep 2020 16:40:03 +0200 Subject: Generalise get_indexamajig_exe to get_crystfel_exe --- src/gui_index.c | 130 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/src/gui_index.c b/src/gui_index.c index fc214327..c8e3a6e9 100644 --- a/src/gui_index.c +++ b/src/gui_index.c @@ -55,7 +55,70 @@ #include "crystfel_gui.h" #include "gui_peaksearch.h" -void cell_explorer_sig(struct crystfelproject *proj) +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; +} + + +static char *get_crystfel_exe(const char *program) +{ + GFile *crystfel_path; + char *indexamajig_path; + GFile *indexamajig; + + crystfel_path = get_crystfel_path_gfile(); + if ( crystfel_path == NULL ) return NULL; + + indexamajig = g_file_get_child(crystfel_path, program); + if ( indexamajig == NULL ) return NULL; + + indexamajig_path = g_file_get_path(indexamajig); + g_object_unref(indexamajig); + g_object_unref(crystfel_path); + + return indexamajig_path; +} + + +void cell_explorer_sig(GtkWidget *widget, struct crystfelproject *proj) { GSubprocess *sp; GError *error = NULL; @@ -656,69 +719,6 @@ static void add_arg_int(char **args, int pos, const char *label, } -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; -} - - -static char *get_indexamajig_exe() -{ - GFile *crystfel_path; - char *indexamajig_path; - GFile *indexamajig; - - crystfel_path = get_crystfel_path_gfile(); - if ( crystfel_path == NULL ) return NULL; - - indexamajig = g_file_get_child(crystfel_path, "indexamajig"); - if ( indexamajig == NULL ) return NULL; - - indexamajig_path = g_file_get_path(indexamajig); - g_object_unref(indexamajig); - g_object_unref(crystfel_path); - - return indexamajig_path; -} - - char **indexamajig_command_line(const char *geom_filename, const char *n_thread_str, const char *files_list, @@ -734,7 +734,7 @@ char **indexamajig_command_line(const char *geom_filename, args = malloc(64*sizeof(char *)); if ( args == NULL ) return NULL; - indexamajig_path = get_indexamajig_exe(); + indexamajig_path = get_crystfel_exe("indexamajig"); if ( indexamajig_path == NULL ) { ERROR("Couldn't determine indexamajig path. " "This is OK provided the executable path is set " -- cgit v1.2.3