aboutsummaryrefslogtreecommitdiffstats
path: root/epan/filesystem.c
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2011-02-26 17:23:24 +0000
committerStig Bjørlykke <stig@bjorlykke.org>2011-02-26 17:23:24 +0000
commitd188988e83fb48440abc87baa5384125fc6f7520 (patch)
treeff9d82e6d356cc2b65d77c7dd27a299d0280e130 /epan/filesystem.c
parent2ea426795177774b48a02353dce3d9d483fcba8e (diff)
Added functionality for handling global profiles.
Global profiles can be installed in a "profiles" directory in the Global configuration directory, and a global profile will be copied to the users profiles on first time usage. svn path=/trunk/; revision=36077
Diffstat (limited to 'epan/filesystem.c')
-rw-r--r--epan/filesystem.c73
1 files changed, 67 insertions, 6 deletions
diff --git a/epan/filesystem.c b/epan/filesystem.c
index 10a849edfc..c7a5cbe3b5 100644
--- a/epan/filesystem.c
+++ b/epan/filesystem.c
@@ -912,6 +912,34 @@ is_default_profile(void)
return (!persconfprofile || strcmp(persconfprofile, DEFAULT_PROFILE) == 0) ? TRUE : FALSE;
}
+gboolean
+has_global_profiles(void)
+{
+ WS_DIR *dir;
+ WS_DIRENT *file;
+ const gchar *global_dir = get_global_profiles_dir();
+ gchar *filename;
+ gboolean has_global = FALSE;
+
+ if ((test_for_directory(global_dir) == EISDIR) &&
+ ((dir = ws_dir_open(global_dir, 0, NULL)) != NULL))
+ {
+ while ((file = ws_dir_read_name(dir)) != NULL) {
+ filename = g_strdup_printf ("%s%s%s", global_dir, G_DIR_SEPARATOR_S,
+ ws_dir_get_name(file));
+ if (test_for_directory(filename) == EISDIR) {
+ has_global = TRUE;
+ g_free (filename);
+ break;
+ }
+ g_free (filename);
+ }
+ ws_dir_close(dir);
+ }
+
+ return has_global;
+}
+
void
profile_store_persconffiles(gboolean store)
{
@@ -1027,6 +1055,19 @@ get_profiles_dir(void)
return profiles_dir;
}
+const char *
+get_global_profiles_dir(void)
+{
+ static char *global_profiles_dir = NULL;
+
+ if (!global_profiles_dir) {
+ global_profiles_dir = g_strdup_printf ("%s%s%s", get_datafile_dir(),
+ G_DIR_SEPARATOR_S, PROFILES_DIR);
+ }
+
+ return global_profiles_dir;
+}
+
static const char *
get_persconffile_dir(const gchar *profilename)
{
@@ -1046,10 +1087,20 @@ get_persconffile_dir(const gchar *profilename)
}
gboolean
-profile_exists(const gchar *profilename)
+profile_exists(const gchar *profilename, gboolean global)
{
- if (test_for_directory (get_persconffile_dir (profilename)) == EISDIR) {
- return TRUE;
+ if (global) {
+ gchar *path = g_strdup_printf ("%s%s%s", get_global_profiles_dir(),
+ G_DIR_SEPARATOR_S, profilename);
+ if (test_for_directory (path) == EISDIR) {
+ g_free (path);
+ return TRUE;
+ }
+ g_free (path);
+ } else {
+ if (test_for_directory (get_persconffile_dir (profilename)) == EISDIR) {
+ return TRUE;
+ }
}
return FALSE;
@@ -1222,14 +1273,24 @@ hash_table_get_keys(gpointer key, gpointer value _U_, gpointer user_data)
#endif
int
-copy_persconffile_profile(const char *toname, const char *fromname, char **pf_filename_return,
- char **pf_to_dir_path_return, char **pf_from_dir_path_return)
+copy_persconffile_profile(const char *toname, const char *fromname, gboolean from_global,
+ char **pf_filename_return, char **pf_to_dir_path_return, char **pf_from_dir_path_return)
{
- gchar *from_dir = g_strdup (get_persconffile_dir(fromname));
+ gchar *from_dir;
gchar *to_dir = g_strdup (get_persconffile_dir(toname));
gchar *filename, *from_file, *to_file;
GList *files, *file;
+ if (from_global) {
+ if (strcmp(fromname, DEFAULT_PROFILE) == 0) {
+ from_dir = g_strdup (get_global_profiles_dir());
+ } else {
+ from_dir = g_strdup_printf ("%s%s%s", get_global_profiles_dir(), G_DIR_SEPARATOR_S, fromname);
+ }
+ } else {
+ from_dir = g_strdup (get_persconffile_dir(fromname));
+ }
+
#if GLIB_CHECK_VERSION(2,14,0)
files = g_hash_table_get_keys(profile_files);
#else