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.


svn path=/trunk/; revision=20417
This commit is contained in:
Graeme Lunt 2007-01-13 16:06:28 +00:00
parent 7d3a4e9264
commit 6fd190ecec
4 changed files with 87 additions and 3 deletions

View File

@ -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);
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -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);