On Aug 29, 2011, at 10:48 AM, Stephen Fisher wrote:
> On Mon, Aug 29, 2011 at 10:05:33AM +0200, Anders Broman wrote:
>
>> On Linux trying to load the UI description from file the file will be
>> loaded from someting like /usr/local/share/wireshark/ui/ runing
>> Wireshark from the working directory will not find the file unless
>> Wireshark is installed (or the file manually copied). Any suggestions
>> on how to resolve/improve this?
>
> Some things, such as tools/fuzz-test.sh define the environment variable
> WIRESHARK_RUN_FROM_BUILD_DIRECTORY=1. Can this be tested for to tell
> Wireshark where to load the files from?
What should be tested is the running_in_build_directory_flag Boolean. In many cases, that's already tested. However, if the source directory isn't laid out the way the install directory is - which is the case for the UI description files, which are in the source directory gtk/ui but are installed in the directory ui - the code that figures out the path needs to call running_in_build_directory() to figure out whether to search in gtk/ui or just ui, relative to the result of get_datafile_dir().
I.e.:
gui_desc_file_name = g_strdup_printf("%s" G_DIR_SEPARATOR_S %s G_DIR_SEPARATOR_S "tree-view-ui.xml", get_datafile_dir(),
running_in_build_directory() ? "gtk/ui" : "ui");
gtk_ui_manager_add_ui_from_file(ui_manager_tree_view_menu, gui_desc_file_name, &error);
or, even better:
gchar *
get_ui_file_path(const char *filename)
{
gchar *gui_desc_file_name;
gui_desc_file_name = g_strdup_printf("%s" G_DIR_SEPARATOR_S %s G_DIR_SEPARATOR_S "%s", get_datafile_dir(),
running_in_build_directory() ? "gtk/ui" : "ui", filename);
return gui_desc_file_name;
}
and use that in all the places where stuff is loaded from a UI description file.
running_in_build_directory_flag is set to TRUE if the WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable is set.
On UN*X, it's also set if argv[0] contains the string "/.libs", so that it's automatically set if what you're running on the command line is the wrapper script built by libtool, running a binary in the .libs directory; this means you should rarely need to set WIRESHARK_RUN_FROM_BUILD_DIRECTORY yourself.
On Windows, that doesn't work. For most paths, it doesn't matter, because the Windows binary assumes the data files are installed in the same directory tree as the executable image, but for the cases where the source directory isn't laid out the way the install directory is, it does a hack^Wheuristic, wherein if the purported directory either doesn't exist or isn't a directory, it assumes you're running from the build directory. For example, the init_wspython_dir() and init_plugin_dir() routines do that; perhaps there should be an init_ui_dir() routine that behaves similarly, and a get_ui_dir() routine to return the constructed UI directory, in which case, instead of calling get_ui_file_path(), you'd do
gui_desc_file_name = g_strdup_printf("%s" G_DIR_SEPARATOR_S {file name}", get_ui_dir());