aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-10-24 07:18:39 +0000
committerGuy Harris <guy@alum.mit.edu>2001-10-24 07:18:39 +0000
commit509f30374efd07a3efeaa367f7f48dfae765f97e (patch)
treeef5a0eee067a920b7bbe92f3f75ae7e64d502eb5 /epan
parentd453f6d99253d5946a4c150c57a7ab8bce2a0715 (diff)
Have a routine that takes a file name for a personal configuration file
and generates the path name; have it, if the file is to be opened for reading on Win32, check whether it exists and, if not, check for it in the old home directory-based configuration directory and, if so, return that path instead, so that files saved with earlier versions of Ethereal will be seen. svn path=/trunk/; revision=4072
Diffstat (limited to 'epan')
-rw-r--r--epan/filesystem.c111
-rw-r--r--epan/filesystem.h19
-rw-r--r--epan/plugins.c9
-rw-r--r--epan/resolv.c18
4 files changed, 129 insertions, 28 deletions
diff --git a/epan/filesystem.c b/epan/filesystem.c
index 997b1fd816..be2085f891 100644
--- a/epan/filesystem.c
+++ b/epan/filesystem.c
@@ -1,7 +1,7 @@
/* filesystem.c
* Filesystem utility routines
*
- * $Id: filesystem.c,v 1.13 2001/10/24 06:13:05 guy Exp $
+ * $Id: filesystem.c,v 1.14 2001/10/24 07:18:37 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -311,7 +311,7 @@ get_systemfile_dir(void)
* or, if %APPDATA% isn't set, it's "%USERPROFILE%\Application Data"
* (which is what %APPDATA% normally is on Windows 2000).
*/
-const char *
+static const char *
get_persconffile_dir(void)
{
#ifdef WIN32
@@ -444,3 +444,110 @@ create_persconffile_dir(char **pf_dir_path_return)
*pf_dir_path_return = g_strdup(pf_dir_path);
return ret;
}
+
+#ifdef WIN32
+/*
+ * Returns the user's home directory on Win32.
+ */
+static const char *
+get_home_dir(void)
+{
+ static const char *home = NULL;
+ char *homedrive, *homepath;
+ char *homestring;
+ char *lastsep;
+
+ /* Return the cached value, if available */
+ if (home)
+ return home;
+
+ /*
+ * XXX - should we use USERPROFILE anywhere in this process?
+ * Is there a chance that it might be set but one or more of
+ * HOMEDRIVE or HOMEPATH isn't set?
+ */
+ homedrive = getenv("HOMEDRIVE");
+ if (homedrive != NULL) {
+ homepath = getenv("HOMEPATH");
+ if (homepath != NULL) {
+ /*
+ * This is cached, so we don't need to worry about
+ * allocating multiple ones of them.
+ */
+ homestring =
+ g_malloc(strlen(homedrive) + strlen(homepath) + 1);
+ strcpy(homestring, homedrive);
+ strcat(homestring, homepath);
+
+ /*
+ * Trim off any trailing slash or backslash.
+ */
+ lastsep = find_last_pathname_separator(homestring);
+ if (lastsep != NULL && *(lastsep + 1) == '\0') {
+ /*
+ * Last separator is the last character
+ * in the string. Nuke it.
+ */
+ *lastsep = '\0';
+ }
+ home = homestring;
+ } else
+ home = homedrive;
+ } else {
+ /*
+ * Give up and use C:.
+ */
+ home = "C:";
+ }
+}
+#endif
+
+/*
+ * Construct the path name of a personal configuration file, given the
+ * file name.
+ *
+ * On Win32, if "for_writing" is FALSE, we check whether the file exists
+ * and, if not, construct a path name relative to the ".ethereal"
+ * subdirectory of the user's home directory, and check whether that
+ * exists; if it does, we return that, so that configuration files
+ * from earlier versions can be read.
+ */
+char *
+get_persconffile_path(const char *filename, gboolean for_writing)
+{
+ char *path;
+#ifdef WIN32
+ struct stat s_buf;
+ char *old_path;
+#endif
+
+ path = (gchar *) g_malloc(strlen(get_persconffile_dir()) +
+ strlen(filename) + 2);
+ sprintf(path, "%s" G_DIR_SEPARATOR_S "%s", get_persconffile_dir(),
+ filename);
+#ifdef WIN32
+ if (!for_writing) {
+ if (stat(path, &s_buf) != 0 && errno == ENOENT) {
+ /*
+ * OK, it's not in the personal configuration file
+ * directory; is it in the ".ethereal" subdirectory
+ * of their home directory?
+ */
+ old_path = (gchar *) g_malloc(strlen(get_home_dir()) +
+ strlen(".ethereal") + strlen(filename) + 3);
+ sprintf(old_path,
+ "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR ".ethereal",
+ get_home_dir(), filename);
+ if (stat(old_path, &s_buf) == 0) {
+ /*
+ * OK, it exists; return it instead.
+ */
+ g_free(path);
+ path = old_path;
+ }
+ }
+ }
+#endif
+
+ return path;
+}
diff --git a/epan/filesystem.h b/epan/filesystem.h
index 0e6a2dbbb4..6ad4078473 100644
--- a/epan/filesystem.h
+++ b/epan/filesystem.h
@@ -1,7 +1,7 @@
/* filesystem.h
* Filesystem utility definitions
*
- * $Id: filesystem.h,v 1.9 2001/10/24 06:13:05 guy Exp $
+ * $Id: filesystem.h,v 1.10 2001/10/24 07:18:37 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -72,11 +72,6 @@ const char *get_datafile_dir(void);
const char *get_systemfile_dir(void);
/*
- * Get the directory in which personal configuration files are stored.
- */
-const char *get_persconffile_dir(void);
-
-/*
* Create the directory that holds personal configuration files, if
* necessary. If we attempted to create it, and failed, return -1 and
* set "*pf_dir_path_return" to the pathname of the directory we failed
@@ -85,4 +80,16 @@ const char *get_persconffile_dir(void);
*/
int create_persconffile_dir(char **pf_dir_path_return);
+/*
+ * Construct the path name of a personal configuration file, given the
+ * file name.
+ *
+ * On Win32, if "for_writing" is FALSE, we check whether the file exists
+ * and, if not, construct a path name relative to the ".ethereal"
+ * subdirectory of the user's home directory, and check whether that
+ * exists; if it does, we return that, so that configuration files
+ * from earlier versions can be read.
+ */
+char *get_persconffile_path(const char *filename, gboolean for_writing);
+
#endif /* FILESYSTEM_H */
diff --git a/epan/plugins.c b/epan/plugins.c
index f1c8ef2229..69ca623e5a 100644
--- a/epan/plugins.c
+++ b/epan/plugins.c
@@ -1,7 +1,7 @@
/* plugins.c
* plugin routines
*
- * $Id: plugins.c,v 1.36 2001/10/22 22:59:25 guy Exp $
+ * $Id: plugins.c,v 1.37 2001/10/24 07:18:37 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -503,12 +503,7 @@ init_plugins(const char *plugin_dir)
}
#endif
if (!user_plug_dir)
- {
- user_plug_dir = (gchar *)g_malloc(strlen(get_persconffile_dir()) +
- strlen(PLUGINS_DIR_NAME) + 2);
- sprintf(user_plug_dir, "%s" G_DIR_SEPARATOR_S "%s",
- get_persconffile_dir(), PLUGINS_DIR_NAME);
- }
+ user_plug_dir = get_persconffile_path(PLUGINS_DIR_NAME, FALSE);
plugins_scan_dir(user_plug_dir);
}
}
diff --git a/epan/resolv.c b/epan/resolv.c
index 35861e27f6..287e45bfe3 100644
--- a/epan/resolv.c
+++ b/epan/resolv.c
@@ -1,7 +1,7 @@
/* resolv.c
* Routines for network object lookup
*
- * $Id: resolv.c,v 1.15 2001/10/22 22:59:25 guy Exp $
+ * $Id: resolv.c,v 1.16 2001/10/24 07:18:37 guy Exp $
*
* Laurent Deniel <deniel@worldnet.fr>
*
@@ -637,12 +637,8 @@ static void initialize_ethers(void)
/* Set g_pethers_path here, but don't actually do anything
* with it. It's used in get_ethbyname() and get_ethbyaddr()
*/
- if (g_pethers_path == NULL) {
- g_pethers_path = g_malloc(strlen(get_persconffile_dir()) +
- strlen(ENAME_ETHERS) + 2);
- sprintf(g_pethers_path, "%s" G_DIR_SEPARATOR_S "%s",
- get_persconffile_dir(), ENAME_ETHERS);
- }
+ if (g_pethers_path == NULL)
+ g_pethers_path = get_persconffile_path(ENAME_ETHERS, FALSE);
/* manuf hash table initialization */
@@ -949,12 +945,8 @@ static void initialize_ipxnets(void)
/* Set g_pipxnets_path here, but don't actually do anything
* with it. It's used in get_ipxnetbyname() and get_ipxnetbyaddr()
*/
- if (g_pipxnets_path == NULL) {
- g_pipxnets_path = g_malloc(strlen(get_persconffile_dir()) +
- strlen(ENAME_IPXNETS) + 2);
- sprintf(g_pipxnets_path, "%s" G_DIR_SEPARATOR_S "%s",
- get_persconffile_dir(), ENAME_IPXNETS);
- }
+ if (g_pipxnets_path == NULL)
+ g_pipxnets_path = get_persconffile_path(ENAME_IPXNETS, FALSE);
} /* initialize_ipxnets */