One allocation less each time, less fragmentation.
static gboolean
formhistory_prepare_js ()
{
- gchar* data_path;
gchar* autosuggest;
gchar* style;
guint i;
gchar* file;
- data_path = g_build_filename (PACKAGE_NAME, "res", "autosuggestcontrol.js", NULL);
- file = sokoke_find_data_filename (data_path);
+ file = sokoke_find_data_filename ("autosuggestcontrol.js", TRUE);
if (!g_file_get_contents (file, &autosuggest, NULL, NULL))
{
- g_free (data_path);
g_free (file);
return FALSE;
}
g_strchomp (autosuggest);
- katze_assign (data_path, g_build_filename (PACKAGE_NAME, "res", "autosuggestcontrol.css", NULL));
- katze_assign (file, sokoke_find_data_filename (data_path));
+ katze_assign (file, sokoke_find_data_filename ("autosuggestcontrol.css", TRUE));
if (!g_file_get_contents (file, &style, NULL, NULL))
{
- g_free (data_path);
g_free (file);
return FALSE;
}
autosuggest,
style);
g_strstrip (jsforms);
- g_free (data_path);
g_free (file);
g_free (style);
g_free (autosuggest);
else
#ifdef G_OS_WIN32
{
- gchar* path = sokoke_find_data_filename ("locale");
+ gchar* path = sokoke_find_data_filename ("locale", FALSE);
bindtextdomain (GETTEXT_PACKAGE, path);
g_free (path);
}
#ifdef G_OS_WIN32
{
#ifdef DOCDIR
- gchar* path = sokoke_find_data_filename ("doc/midori/faq.html");
+ gchar* path = sokoke_find_data_filename ("doc/midori/faq.html", FALSE);
uri = free_uri = g_filename_to_uri (path, NULL, NULL);
if (g_access (path, F_OK) != 0)
{
if (g_str_has_prefix (uri, "res://"))
{
- gchar* filename = g_build_filename ("midori", "res", &uri[6], NULL);
- gchar* filepath = sokoke_find_data_filename (filename);
- gchar* file_uri;
-
- g_free (filename);
- file_uri = g_filename_to_uri (filepath, NULL, NULL);
+ gchar* filepath = sokoke_find_data_filename (&uri[6], TRUE);
+ gchar* file_uri = g_filename_to_uri (filepath, NULL, NULL);
g_free (filepath);
webkit_network_request_set_uri (request, file_uri);
g_free (file_uri);
const gchar* try_again,
WebKitWebFrame* web_frame)
{
- gchar* template_file = g_build_filename ("midori", "res", "error.html", NULL);
- gchar* path = sokoke_find_data_filename (template_file);
+ gchar* path = sokoke_find_data_filename ("error.html", TRUE);
gchar* template;
- g_free (template_file);
if (g_file_get_contents (path, &template, NULL, NULL))
{
gchar* title_escaped;
guint slot_count = 1, i, grid_index = 3, slot_size;
gchar* speed_dial_head;
gchar* file_path;
- gchar* file_name;
gchar** groups;
g_object_get (browser, "speed-dial", &key_file, NULL);
- if (!key_file)
- return g_strdup ("");
-
- file_name = g_build_filename ("midori", "res",
- "speeddial-head-" MIDORI_VERSION ".html", NULL);
- file_path = sokoke_find_data_filename (file_name);
- g_free (file_name);
+ file_path = sokoke_find_data_filename ("speeddial-head-" MIDORI_VERSION ".html", TRUE);
- if (g_access (file_path, F_OK) == 0
+ if (key_file != NULL
+ && g_access (file_path, F_OK) == 0
&& g_file_get_contents (file_path, &speed_dial_head, NULL, NULL))
{
gchar* header = sokoke_replace_variables (speed_dial_head,
* Return value: a newly allocated full path
**/
gchar*
-sokoke_find_data_filename (const gchar* filename)
+sokoke_find_data_filename (const gchar* filename,
+ gboolean res)
{
+ const gchar* res1 = res ? PACKAGE_NAME : "";
+ const gchar* res2 = res ? "res" : "";
const gchar* const* data_dirs = g_get_system_data_dirs ();
guint i = 0;
const gchar* data_dir;
#ifdef G_OS_WIN32
gchar* install_path = g_win32_get_package_installation_directory_of_module (NULL);
- path = g_build_filename (install_path, "share", filename, NULL);
+ path = g_build_filename (install_path, "share", res1, res2, filename, NULL);
g_free (install_path);
if (g_access (path, F_OK) == 0)
return path;
g_free (path);
#endif
- path = g_build_filename (g_get_user_data_dir (), filename, NULL);
+ path = g_build_filename (g_get_user_data_dir (), res1, res2, filename, NULL);
if (g_access (path, F_OK) == 0)
return path;
g_free (path);
while ((data_dir = data_dirs[i++]))
{
- path = g_build_filename (data_dir, filename, NULL);
+ path = g_build_filename (data_dir, res1, res2, filename, NULL);
if (g_access (path, F_OK) == 0)
return path;
g_free (path);
}
- return g_build_filename (MDATADIR, filename, NULL);
+ return g_build_filename (MDATADIR, res1, res2, filename, NULL);
}
/**
sokoke_find_lib_path (const gchar* folder);
gchar*
-sokoke_find_data_filename (const gchar* filename);
+sokoke_find_data_filename (const gchar* filename,
+ gboolean res);
gchar**
sokoke_get_argv (gchar** argument_vector);