From 31786643ec42205776553ec2b72875c6849d6e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Wed, 21 Jun 2017 10:43:21 -0400 Subject: Qt: Write a list of profile files at startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This file will contain all personal config files which will be fetched from a profile. Change-Id: I430ca84ccefc17f0e21c8efb93a92602ab8d5661 Reviewed-on: https://code.wireshark.org/review/22303 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman (cherry picked from commit a14ef98540af979f0dbc39c728f9fc31a687a16f) Reviewed-on: https://code.wireshark.org/review/22313 Reviewed-by: Stig Bjørlykke --- wireshark-qt.cpp | 1 + wsutil/filesystem.c | 34 ++++++++++++++++++++++++++++++++++ wsutil/filesystem.h | 5 +++++ 3 files changed, 40 insertions(+) diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp index 7e4d597c7a..45cf6a80fb 100644 --- a/wireshark-qt.cpp +++ b/wireshark-qt.cpp @@ -915,6 +915,7 @@ int main(int argc, char *qt_argv[]) g_free(get_persconffile_path("io_graphs", TRUE)); profile_store_persconffiles(FALSE); + profile_write_info_file(); ret_val = wsApp->exec(); diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c index af8d9aba74..32ad9c79b1 100644 --- a/wsutil/filesystem.c +++ b/wsutil/filesystem.c @@ -68,6 +68,7 @@ #define PROFILES_DIR "profiles" #define PLUGINS_DIR_NAME "plugins" +#define PROFILES_INFO_NAME "profile_files.txt" char *persconffile_dir = NULL; char *persdatafile_dir = NULL; @@ -1237,6 +1238,39 @@ profile_store_persconffiles(gboolean store) do_store_persconffiles = store; } +static gint +compare_filename(gconstpointer dissector_a, gconstpointer dissector_b) +{ + return strcmp((const char*)dissector_a, (const char*)dissector_b); +} + +void +profile_write_info_file(void) +{ + gchar *profile_dir, *info_file, *filename; + GList *files, *file; + int fd; + + profile_dir = get_profiles_dir(); + info_file = g_strdup_printf("%s%s%s", profile_dir, G_DIR_SEPARATOR_S, PROFILES_INFO_NAME); + fd = ws_open(info_file, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); + + files = g_hash_table_get_keys(profile_files); + files = g_list_sort(files, compare_filename); + file = g_list_first(files); + while (file) { + filename = (gchar *)file->data; + ws_write(fd, filename, (unsigned int)strlen(filename)); + ws_write(fd, "\n", 1); + file = g_list_next(file); + } + g_list_free(files); + + ws_close(fd); + g_free(info_file); + g_free(profile_dir); +} + /* * Get the directory in which personal configuration files reside. * diff --git a/wsutil/filesystem.h b/wsutil/filesystem.h index f09e5ccaea..8b2d9faf54 100644 --- a/wsutil/filesystem.h +++ b/wsutil/filesystem.h @@ -142,6 +142,11 @@ WS_DLL_PUBLIC char *get_global_profiles_dir(void); */ WS_DLL_PUBLIC void profile_store_persconffiles(gboolean store); +/* + * Store a list of all personal config files which belongs in a profile. + */ +WS_DLL_PUBLIC void profile_write_info_file(void); + /* * Check if given configuration profile exists. */ -- cgit v1.2.1