summaryrefslogtreecommitdiff
path: root/src/core/paths.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-06-17 13:03:12 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-06-17 13:03:12 (GMT)
commit2cb3d9035ef9859570bf8facb1a2cc935743b0b6 (patch)
tree6ad51a7343ac133f6937228e91ca3401f9571324 /src/core/paths.c
parentd152af2b8883fb101cfbdc607601cb963f40db4a (diff)
Got access to external files thanks to new core functions.
Diffstat (limited to 'src/core/paths.c')
-rw-r--r--src/core/paths.c157
1 files changed, 157 insertions, 0 deletions
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;
+
+}