diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Makefile.am | 1 | ||||
-rw-r--r-- | src/core/core.c | 4 | ||||
-rw-r--r-- | src/core/paths.c | 157 | ||||
-rw-r--r-- | src/core/paths.h | 37 |
4 files changed, 195 insertions, 4 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 4dcf6e7..89dd345 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -10,6 +10,7 @@ libcore_la_SOURCES = \ logs.h logs.c \ nproc.h nproc.c \ params.h params.c \ + paths.h paths.c \ processors.h processors.c \ queue.h queue.c diff --git a/src/core/core.c b/src/core/core.c index bc1a9dc..3f0d244 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -44,7 +44,6 @@ #include "../common/io.h" #include "../common/xdg.h" #include "../glibext/linesegment.h" -#include "../gtkext/support.h" @@ -76,9 +75,6 @@ bool load_all_basic_components(void) srand(time(NULL) + getpid()); - add_pixmap_directory(PIXMAPS_DIR); - add_pixmap_directory(PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "pixmaps"); - cfgdir = get_xdg_config_dir("chrysalide" G_DIR_SEPARATOR_S "chrysalide"); result &= (ensure_path_exists(cfgdir) == 0); free(cfgdir); diff --git a/src/core/paths.c b/src/core/paths.c new file mode 100644 index 0000000..13b9cbe --- /dev/null +++ b/src/core/paths.c @@ -0,0 +1,157 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * paths.c - récupération de fichiers secondaires + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "paths.h" + + +#include <glib.h> +#include <malloc.h> +#include <stdio.h> +#include <unistd.h> + + +#include <config.h> + + + +/* Trouve le chemin d'accès complet à un fichier donné. */ +static char *find_file_in_directory(const char *, const char *); + + + +/****************************************************************************** +* * +* Paramètres : dirname = répertoire de travail à fouiller. * +* filename = nom de fichier seul comme indice. * +* * +* Description : Trouve le chemin d'accès complet à un fichier donné. * +* * +* Retour : Chemin trouvé à libérer de la mémoire ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static char *find_file_in_directory(const char *dirname, const char *filename) +{ + char *result; /* Trouvaille à renvoyer */ + int ret; /* Bilan du test de présence */ + + asprintf(&result, "%s%s%s", dirname, G_DIR_SEPARATOR_S, filename); + + ret = access(result, F_OK); + + if (ret != 0) + { + free(result); + result = NULL; + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : filename = nom de fichier seul comme indice. * +* * +* Description : Trouve le chemin d'accès complet à un fichier d'image. * +* * +* Retour : Chemin trouvé à libérer de la mémoire ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +char *find_pixmap_file(const char *filename) +{ + char *result; /* Trouvaille à renvoyer */ + + /** + * On privilégie si possible les sources fraiches. + */ + +#ifndef DISCARD_LOCAL + + result = find_file_in_directory(PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "pixmaps", filename); + +#else + + result = NULL; + +#endif + + if (result == NULL) + result = find_file_in_directory(PIXMAPS_DIR, filename); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : pgname = nom du greffon concerné. * +* filename = nom de fichier seul comme indice. * +* * +* Description : Trouve le chemin d'accès complet à un fichier de greffon. * +* * +* Retour : Chemin trouvé à libérer de la mémoire ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +char *find_plugin_file(const char *pgname, const char *filename) +{ + char *result; /* Trouvaille à renvoyer */ +#ifndef DISCARD_LOCAL + char *dirname; /* Répertoire à cibler */ +#endif + + /** + * On privilégie si possible les sources fraiches. + */ + +#ifndef DISCARD_LOCAL + + asprintf(&dirname, "%s%splugins%s%s%s%s", + PACKAGE_SOURCE_DIR, G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S, pgname, G_DIR_SEPARATOR_S, filename); + + result = find_file_in_directory(dirname, filename); + + free(dirname); + +#else + + result = NULL; + +#endif + + if (result == NULL) + result = find_file_in_directory(PLUGINS_DIR, filename); + + return result; + +} diff --git a/src/core/paths.h b/src/core/paths.h new file mode 100644 index 0000000..c16a278 --- /dev/null +++ b/src/core/paths.h @@ -0,0 +1,37 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * paths.h - prototypes pour la récupération de fichiers secondaires + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _CORE_PATHS_H +#define _CORE_PATHS_H + + + +/* Trouve le chemin d'accès complet à un fichier d'image. */ +char *find_pixmap_file(const char *); + +/* Trouve le chemin d'accès complet à un fichier de greffon. */ +char *find_plugin_file(const char *, const char *); + + + +#endif /* _CORE_PATHS_H */ |