From 06519be2052776e4f052838905b230623e41befe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Wed, 18 Jan 2023 14:12:14 +0000 Subject: [PATCH] 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. --- CMakeLists.txt | 18 +++-- doc/CMakeLists.txt | 14 +++- packaging/debian/libwireshark-data.install | 1 + packaging/rpm/wireshark.spec.in | 5 +- .../share/{ => doc}/wireshark/ipmap.html | 0 ui/CMakeLists.txt | 2 - ui/help_url.c | 35 +++++---- wsutil/CMakeLists.txt | 4 + wsutil/filesystem.c | 77 +++++++++++++++++++ wsutil/filesystem.h | 15 ++++ 10 files changed, 138 insertions(+), 33 deletions(-) rename resources/share/{ => doc}/wireshark/ipmap.html (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6a05d5d51..a248e2ca0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1935,12 +1935,14 @@ set(INSTALL_FILES resources/share/wireshark/colorfilters resources/share/wireshark/dfilter_macros resources/share/wireshark/dfilters - resources/share/wireshark/ipmap.html resources/share/wireshark/pdml2html.xsl resources/share/wireshark/smi_modules services wka ) +set(DOC_FILES + resources/share/doc/wireshark/ipmap.html +) if (BUILD_logray) set(LOG_INSTALL_FILES @@ -1953,6 +1955,8 @@ endif() if (ASCIIDOCTOR_FOUND) list(APPEND INSTALL_FILES ${CMAKE_BINARY_DIR}/doc/AUTHORS-SHORT + ) + list(APPEND DOC_FILES ${CMAKE_BINARY_DIR}/doc/androiddump.html ${CMAKE_BINARY_DIR}/doc/udpdump.html ${CMAKE_BINARY_DIR}/doc/capinfos.html @@ -1975,20 +1979,20 @@ if (ASCIIDOCTOR_FOUND) ${CMAKE_BINARY_DIR}/doc/wireshark-filter.html ) if(MAXMINDDB_FOUND) - list(APPEND INSTALL_FILES ${CMAKE_BINARY_DIR}/doc/mmdbresolve.html) + list(APPEND DOC_FILES ${CMAKE_BINARY_DIR}/doc/mmdbresolve.html) endif() if (BUILD_corbaidl2wrs) - list(APPEND INSTALL_FILES ${CMAKE_BINARY_DIR}/doc/idl2wrs.html) + list(APPEND DOC_FILES ${CMAKE_BINARY_DIR}/doc/idl2wrs.html) endif() if (BUILD_xxx2deb) - list(APPEND INSTALL_FILES + list(APPEND DOC_FILES ${CMAKE_BINARY_DIR}/doc/asn2deb.html ${CMAKE_BINARY_DIR}/doc/idl2deb.html ) endif() if (BUILD_logray) - list(APPEND LOG_INSTALL_FILES + list(APPEND DOC_FILES ${CMAKE_BINARY_DIR}/doc/falcodump.html ) endif() @@ -1996,7 +2000,7 @@ endif() if(NOT WIN32) # We do this for Windows further down in the copy_data_files target. - list(APPEND INSTALL_FILES COPYING) + list(APPEND DOC_FILES COPYING) endif() if(USE_REPOSITORY) @@ -2228,7 +2232,7 @@ if(WIN32 AND NOT USE_MSYSTEM) endforeach() endif() -foreach(_install_file ${INSTALL_FILES}) +foreach(_install_file ${INSTALL_FILES} ${DOC_FILES}) get_filename_component(_install_file_src "${_install_file}" ABSOLUTE) get_filename_component(_install_basename "${_install_file}" NAME) set(_output_file "${DATAFILE_DIR}/${_install_basename}") diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 88ee77a9a6..88ea9a2982 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -133,10 +133,16 @@ if(ASCIIDOCTOR_FOUND) ) endif() -# -# Installation of HTML manuals is done -# elsewhere to CMAKE_INSTALL_DATADIR. -# +list(APPEND HTML_INSTALL_FILES + ${CMAKE_SOURCE_DIR}/resources/share/doc/wireshark/ipmap.html +) + +install( + FILES + ${HTML_INSTALL_FILES} + DESTINATION + ${CMAKE_INSTALL_DOCDIR} +) # # Editor modelines - https://www.wireshark.org/tools/modelines.html diff --git a/packaging/debian/libwireshark-data.install b/packaging/debian/libwireshark-data.install index db23b3d876..7504bfbb22 100644 --- a/packaging/debian/libwireshark-data.install +++ b/packaging/debian/libwireshark-data.install @@ -1,3 +1,4 @@ usr/share/wireshark/* +usr/share/doc/wireshark/* etc/wireshark/init.lua packaging/debian/maxmind_db_paths /usr/share/wireshark diff --git a/packaging/rpm/wireshark.spec.in b/packaging/rpm/wireshark.spec.in index 56df607747..2bec7461e3 100644 --- a/packaging/rpm/wireshark.spec.in +++ b/packaging/rpm/wireshark.spec.in @@ -472,14 +472,11 @@ update-mime-database %{_datadir}/mime &> /dev/null || : %defattr(-,root,root) %doc AUTHORS COPYING NEWS README.md +%doc %{_datadir}/doc/wireshark/*.html # Include the User Guide: %if %{with guides} %docdir %{_datadir}/doc/wireshark/ -# HTML manuals are installed to %%{_datadir}/wireshark because that is -# where Wireshark's Help menu expects to launch them from. -%exclude %{_datadir}/doc/wireshark/*.html -%{_datadir}/doc/wireshark/ %endif # Don't pick up any of the wireshark (GUI) binaries here diff --git a/resources/share/wireshark/ipmap.html b/resources/share/doc/wireshark/ipmap.html similarity index 100% rename from resources/share/wireshark/ipmap.html rename to resources/share/doc/wireshark/ipmap.html diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index 9e3ac40366..0aba6e3bbd 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -122,8 +122,6 @@ if(MSVC) ) endif() -add_definitions(-DDOC_DIR="${CMAKE_INSTALL_FULL_DOCDIR}") - CHECKAPI( NAME ui-base diff --git a/ui/help_url.c b/ui/help_url.c index c0b0d059d6..e755d961a4 100644 --- a/ui/help_url.c +++ b/ui/help_url.c @@ -43,12 +43,15 @@ user_guide_url(const gchar *page) { g_string_printf(url, "file:///%s/%s", ug_dir->str, page); } g_string_free(ug_dir, TRUE); -#elif defined(DOC_DIR) - if (g_file_test(DOC_DIR "/guides/wsug_html_chunked", G_FILE_TEST_IS_DIR)) { - /* try to open the HTML page from wireshark.org instead */ - g_string_printf(url, "file://" DOC_DIR "/guides/wsug_html_chunked/%s", page); +#else + char *path = g_build_filename(get_doc_dir(), "wsug_html_chunked", page, NULL); + if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { + /* try to open the HTML page from the filesystem */ + g_string_printf(url, "file://%s", path); } -#endif /* _WIN32 / DOC_DIR */ + g_free(path); + path = NULL; +#endif /* _WIN32 */ /* Fall back to wireshark.org. */ @@ -107,34 +110,34 @@ topic_action_url(topic_action_e action) /* local manual pages */ case(LOCALPAGE_MAN_WIRESHARK): - url = data_file_url("wireshark.html"); + url = doc_file_url("wireshark.html"); break; case(LOCALPAGE_MAN_WIRESHARK_FILTER): - url = data_file_url("wireshark-filter.html"); + url = doc_file_url("wireshark-filter.html"); break; case(LOCALPAGE_MAN_CAPINFOS): - url = data_file_url("capinfos.html"); + url = doc_file_url("capinfos.html"); break; case(LOCALPAGE_MAN_DUMPCAP): - url = data_file_url("dumpcap.html"); + url = doc_file_url("dumpcap.html"); break; case(LOCALPAGE_MAN_EDITCAP): - url = data_file_url("editcap.html"); + url = doc_file_url("editcap.html"); break; case(LOCALPAGE_MAN_MERGECAP): - url = data_file_url("mergecap.html"); + url = doc_file_url("mergecap.html"); break; case(LOCALPAGE_MAN_RAWSHARK): - url = data_file_url("rawshark.html"); + url = doc_file_url("rawshark.html"); break; case(LOCALPAGE_MAN_REORDERCAP): - url = data_file_url("reordercap.html"); + url = doc_file_url("reordercap.html"); break; case(LOCALPAGE_MAN_TEXT2PCAP): - url = data_file_url("text2pcap.html"); + url = doc_file_url("text2pcap.html"); break; case(LOCALPAGE_MAN_TSHARK): - url = data_file_url("tshark.html"); + url = doc_file_url("tshark.html"); break; /* local help pages (User's Guide) */ @@ -202,7 +205,7 @@ topic_action_url(topic_action_e action) url = user_guide_url("ChAdvExpert.html"); break; case(HELP_EXTCAP_OPTIONS_DIALOG): - url = data_file_url("extcap.html"); + url = doc_file_url("extcap.html"); break; case(HELP_STATS_SUMMARY_DIALOG): url = user_guide_url("ChStatSummary.html"); 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 @@ -123,6 +123,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,