diff options
author | gal <gal@f5534014-38df-0310-8fa8-9805f1628bb7> | 2007-01-13 16:06:28 +0000 |
---|---|---|
committer | gal <gal@f5534014-38df-0310-8fa8-9805f1628bb7> | 2007-01-13 16:06:28 +0000 |
commit | 9ddb6c0c6a1b291b5f1dddb419629d3010a63170 (patch) | |
tree | 184e2fc60ca51afc9fea343a60e1d1e83cff7874 | |
parent | cfa1eb0b494df2fc2a4b94b2a4dd45cfd201f890 (diff) |
U3 support for "recent" files.
When the "recent" file is written, any references to files on the U3 device itself are modified to have the drive replace with "$U3_DEVICE_PATH". Similarly, when the recent file is read, "$U3_DEVICE_PATH" is replaced with the current U3 device path.
This ensures that if/when the U3 device path changes when inserting it into different machines, recent captures on the U3 device itself can still be opened from the recent menu.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@20417 f5534014-38df-0310-8fa8-9805f1628bb7
-rw-r--r-- | gtk/menu.c | 4 | ||||
-rw-r--r-- | gtk/recent.c | 17 | ||||
-rw-r--r-- | gtk/u3.c | 65 | ||||
-rw-r--r-- | gtk/u3.h | 4 |
4 files changed, 87 insertions, 3 deletions
diff --git a/gtk/menu.c b/gtk/menu.c index 98db138a05..9d5ffb2d5f 100644 --- a/gtk/menu.c +++ b/gtk/menu.c @@ -81,6 +81,7 @@ #include "ssl-dlg.h" #include "sctp_stat.h" #include "firewall_dlg.h" +#include "u3.h" GtkWidget *popup_menu_object; @@ -1521,6 +1522,9 @@ menu_recent_file_write_all(FILE *rf) { /* get capture filename from the menu item label */ cf_name = OBJECT_GET_DATA(child->data, MENU_RECENT_FILES_KEY); if (cf_name) { + if(u3_active()) + fprintf (rf, RECENT_KEY_CAPTURE_FILE ": %s\n", u3_contract_device_path(cf_name)); + else fprintf (rf, RECENT_KEY_CAPTURE_FILE ": %s\n", cf_name); } diff --git a/gtk/recent.c b/gtk/recent.c index 94b77f5892..929c65558b 100644 --- a/gtk/recent.c +++ b/gtk/recent.c @@ -47,6 +47,7 @@ #include "cfilter_combo_utils.h" #include "simple_dialog.h" #include "file_util.h" +#include "u3.h" #define RECENT_KEY_MAIN_TOOLBAR_SHOW "gui.toolbar_main_show" #define RECENT_KEY_FILTER_TOOLBAR_SHOW "gui.filter_toolbar_show" @@ -259,7 +260,11 @@ write_recent(void) if (get_last_open_dir() != NULL) { fprintf(rf, "\n# Last directory navigated to in File Open dialog.\n"); - fprintf(rf, RECENT_GUI_FILEOPEN_REMEMBERED_DIR ": %s\n", get_last_open_dir()); + + if(u3_active()) + fprintf(rf, RECENT_GUI_FILEOPEN_REMEMBERED_DIR ": %s\n", u3_contract_device_path(get_last_open_dir())); + else + fprintf(rf, RECENT_GUI_FILEOPEN_REMEMBERED_DIR ": %s\n", get_last_open_dir()); } window_geom_recent_write_all(rf); @@ -434,7 +439,10 @@ read_set_recent_pair_static(gchar *key, gchar *value, void *private_data _U_) recent.gui_geometry_status_pane = num; recent.has_gui_geometry_status_pane = TRUE; } else if (strcmp(key, RECENT_GUI_FILEOPEN_REMEMBERED_DIR) == 0) { - set_last_open_dir(value); + if(u3_active()) + set_last_open_dir(u3_expand_device_path(value)); + else + set_last_open_dir(value); } else if (strncmp(key, RECENT_GUI_GEOMETRY, sizeof(RECENT_GUI_GEOMETRY)-1) == 0) { /* now have something like "gui.geom.main.x", split it into win and sub_key */ char *win = &key[sizeof(RECENT_GUI_GEOMETRY)-1]; @@ -455,7 +463,10 @@ static prefs_set_pref_e read_set_recent_pair_dynamic(gchar *key, gchar *value, void *private_data _U_) { if (strcmp(key, RECENT_KEY_CAPTURE_FILE) == 0) { - add_menu_recent_capture_file(value); + if(u3_active()) + add_menu_recent_capture_file(u3_expand_device_path(value)); + else + add_menu_recent_capture_file(value); } else if (strcmp(key, RECENT_KEY_DISPLAY_FILTER) == 0) { dfilter_combo_add_recent(value); } else if (strcmp(key, RECENT_KEY_CAPTURE_FILTER) == 0) { @@ -51,8 +51,26 @@ #include <gtk/u3.h> +#define U3_DEVICE_PATH_VAR "$U3_DEVICE_PATH" static char *pid_file = NULL; +static char *u3devicepath = (char*)-1; +static gchar *newpath = NULL; + +static char *u3_change_path(char *path, const char *old, const char *new); + +gboolean u3_active() +{ + + return ( +#ifdef _WIN32 + getenv_utf8 +#else + getenv +#endif + ("U3_HOST_EXEC_PATH") != NULL); + +} void u3_register_pid() { @@ -100,3 +118,50 @@ void u3_deregister_pid() } } + +char *u3_expand_device_path(char *path) +{ + return u3_change_path(path, U3_DEVICE_PATH_VAR, NULL); +} + + +char *u3_contract_device_path(char *path) +{ + return u3_change_path(path, NULL, U3_DEVICE_PATH_VAR); +} + +static char *u3_change_path(char *path, const char *old, const char *new) +{ + + if(u3devicepath == (char*)-1) { + /* cache the device path */ + u3devicepath = +#ifdef _WIN32 + getenv_utf8 +#else + getenv +#endif + ("U3_DEVICE_PATH"); + } + + if(new == NULL) + new = u3devicepath; + if(old == NULL) + old = u3devicepath; + + if(newpath == NULL) { + g_free(newpath); + newpath = NULL; + } + + if((path != NULL) && (u3devicepath != NULL) && (strncmp(path, old, strlen(old)) == 0)) { + + newpath = g_strconcat(new, path + strlen(old), NULL); + + return newpath; + + } + + return path; + +} @@ -22,6 +22,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +gboolean u3_active(); void u3_register_pid(void); void u3_deregister_pid(void); + +char * u3_expand_device_path(char *path); +char * u3_contract_device_path(char *path); |