aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2023-01-18 14:12:14 +0000
committerJoão Valverde <j@v6e.pt>2023-01-19 01:40:59 +0000
commit06519be2052776e4f052838905b230623e41befe (patch)
tree49b3e6580938532b6a6efc0f2fbb2acfa29dbdd6 /wsutil
parent9c9c5343d88440d53b17151f225be4830bb7d699 (diff)
Install documentation (HTML manuals) to DOCDIR
Install documentation to DOCDIR instead of DATADIR. The code must be fixed to open the Help URLs from this new path. This only affects Unix-like FHS platforms. Windows installation does its own thing. Needs testing with macOS packaging.
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/CMakeLists.txt4
-rw-r--r--wsutil/filesystem.c77
-rw-r--r--wsutil/filesystem.h15
3 files changed, 96 insertions, 0 deletions
diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt
index 53002eaa4d..ef45a20248 100644
--- a/wsutil/CMakeLists.txt
+++ b/wsutil/CMakeLists.txt
@@ -16,14 +16,18 @@ if(UNIX OR USE_MSYSTEM)
string(REPLACE "\\" "\\\\" _extcap_dir "${_dir}")
file(TO_NATIVE_PATH "${CMAKE_INSTALL_DATADIR}" _dir)
string(REPLACE "\\" "\\\\" _data_dir "${_dir}")
+ file(TO_NATIVE_PATH "${CMAKE_INSTALL_DOCDIR}" _dir)
+ string(REPLACE "\\" "\\\\" _doc_dir "${_dir}")
elseif(UNIX)
set(_plugin_dir "${PLUGIN_INSTALL_FULL_LIBDIR}")
set(_extcap_dir "${EXTCAP_INSTALL_FULL_LIBDIR}")
set(_data_dir "${CMAKE_INSTALL_FULL_DATADIR}")
+ set(_doc_dir "${CMAKE_INSTALL_FULL_DOCDIR}")
endif()
add_definitions(-DPLUGIN_DIR=\"${_plugin_dir}\")
add_definitions(-DEXTCAP_DIR=\"${_extcap_dir}\")
add_definitions(-DDATA_DIR=\"${_data_dir}\")
+ add_definitions(-DDOC_DIR=\"${_doc_dir}\")
endif()
add_subdirectory(wmem)
diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c
index a463a01974..460501bec3 100644
--- a/wsutil/filesystem.c
+++ b/wsutil/filesystem.c
@@ -74,6 +74,7 @@ char *persconffile_dir = NULL;
char *datafile_dir = NULL;
char *persdatafile_dir = NULL;
char *persconfprofile = NULL;
+char *doc_dir = NULL;
/* Directory from which the executable came. */
static char *progfile_dir = NULL;
@@ -1044,6 +1045,59 @@ get_datafile_dir(void)
return datafile_dir;
}
+const char *
+get_doc_dir(void)
+{
+ if (doc_dir != NULL)
+ return doc_dir;
+
+#if defined(__MINGW64__)
+ if (running_in_build_directory_flag) {
+ doc_dir = g_strdup(install_prefix);
+ } else {
+ doc_dir = g_build_filename(install_prefix, DOC_DIR, (gchar *)NULL);
+ }
+#elif defined(_WIN32)
+ if (progfile_dir != NULL) {
+ doc_dir = g_strdup(progfile_dir);
+ } else {
+ /* Fall back on the default installation directory. */
+ doc_dir = g_strdup("C:\\Program Files\\Wireshark\\");
+ }
+#else
+
+ /* No environment variable for this. */
+ if (false) {
+ ;
+ }
+#ifdef __APPLE__
+ /*
+ * If we're running from an app bundle and weren't started
+ * with special privileges, use the Contents/Resources/share/wireshark
+ * subdirectory of the app bundle.
+ *
+ * (appbundle_dir is not set to a non-null value if we're
+ * started with special privileges, so we need only check
+ * it; we don't need to call started_with_special_privs().)
+ */
+ else if (appbundle_dir != NULL) {
+ doc_dir = ws_strdup_printf("%s/Contents/Resources/%s",
+ appbundle_dir, DOC_DIR);
+ }
+#endif
+ else if (running_in_build_directory_flag && progfile_dir != NULL) {
+ /*
+ * We're (probably) being run from the build directory and
+ * weren't started with special privileges.
+ */
+ doc_dir = g_strdup(progfile_dir);
+ } else {
+ doc_dir = g_strdup(DOC_DIR);
+ }
+#endif
+ return doc_dir;
+}
+
/*
* Find the directory where the plugins are stored.
*
@@ -2530,6 +2584,27 @@ data_file_url(const gchar *filename)
return uri;
}
+gchar *
+doc_file_url(const gchar *filename)
+{
+ gchar *file_path;
+ gchar *uri;
+
+ /* Absolute path? */
+ if(g_path_is_absolute(filename)) {
+ file_path = g_strdup(filename);
+ } else {
+ file_path = ws_strdup_printf("%s/%s", get_doc_dir(), filename);
+ }
+
+ /* XXX - check, if the file is really existing, otherwise display a simple_dialog about the problem */
+
+ /* convert filename to uri */
+ uri = g_filename_to_uri(file_path, NULL, NULL);
+ g_free(file_path);
+ return uri;
+}
+
void
free_progdirs(void)
{
@@ -2543,6 +2618,8 @@ free_progdirs(void)
persconfprofile = NULL;
g_free(progfile_dir);
progfile_dir = NULL;
+ g_free(doc_dir);
+ doc_dir = NULL;
#ifdef __MINGW64__
g_free(install_prefix);
install_prefix = NULL;
diff --git a/wsutil/filesystem.h b/wsutil/filesystem.h
index ee84b0f657..627b7f55bb 100644
--- a/wsutil/filesystem.h
+++ b/wsutil/filesystem.h
@@ -124,6 +124,21 @@ WS_DLL_PUBLIC const char *get_datafile_dir(void);
WS_DLL_PUBLIC char *get_datafile_path(const char *filename);
/*
+ * Get the directory in which global documentation files are
+ * stored.
+ */
+WS_DLL_PUBLIC const char *get_doc_dir(void);
+
+/*
+ * Construct the path name of a global documentation file, given the
+ * file name.
+ *
+ * The returned file name was g_malloc()'d so it must be g_free()d when the
+ * caller is done with it.
+ */
+WS_DLL_PUBLIC char *doc_file_url(const char *filename);
+
+/*
* Get the directory in which files that, at least on UNIX, are
* system files (such as "/etc/ethers") are stored; on Windows,
* there's no "/etc" directory, so we get them from the Wireshark