From a8248a7bb9555e558cb8c7eed1146c62ab024130 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 20 Aug 2018 22:26:41 +0100 Subject: Update windows frontend to use windows resources --- frontends/windows/main.c | 59 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 20 deletions(-) (limited to 'frontends/windows/main.c') diff --git a/frontends/windows/main.c b/frontends/windows/main.c index 5dd1e7316..fd22ae1fe 100644 --- a/frontends/windows/main.c +++ b/frontends/windows/main.c @@ -51,12 +51,12 @@ #include "windows/window.h" #include "windows/schedule.h" #include "windows/font.h" -#include "windows/filetype.h" +#include "windows/fetch.h" #include "windows/pointers.h" #include "windows/bitmap.h" #include "windows/gui.h" -static char **respaths; /** resource search path vector. */ +char **respaths; /** exported global defined in windows/gui.h */ char *nsw32_config_home; /* exported global defined in windows/gui.h */ @@ -119,15 +119,6 @@ static void die(const char *error) } -static nsurl *gui_get_resource_url(const char *path) -{ - char buf[PATH_MAX]; - nsurl *url = NULL; - - netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url); - - return url; -} /** * Ensures output logging stream is available @@ -135,7 +126,7 @@ static nsurl *gui_get_resource_url(const char *path) static bool nslog_ensure(FILE *fptr) { /* mwindows compile flag normally invalidates standard io unless - * already redirected + * already redirected */ if (_get_osfhandle(fileno(fptr)) == -1) { AllocConsole(); @@ -206,7 +197,7 @@ static nserror set_defaults(struct nsoption_s *defaults) } free(buf); - + /* ensure homepage option has a default */ nsoption_setnull_charp(homepage_url, strdup(NETSURF_HOMEPAGE)); @@ -269,6 +260,32 @@ static nserror nsw32_option_init(int *pargc, char** argv) return NSERROR_OK; } +/** + * Initialise messages + */ +static nserror nsw32_messages_init(char **respaths) +{ + char *messages; + nserror res; + const uint8_t *data; + size_t data_size; + + res = nsw32_get_resource_data("messages", &data, &data_size); + if (res == NSERROR_OK) { + res = messages_add_from_inline(data, data_size); + } else { + /* Obtain path to messages */ + messages = filepath_find(respaths, "messages"); + if (messages == NULL) { + res = NSERROR_NOT_FOUND; + } else { + res = messages_add_from_file(messages); + free(messages); + } + } + + return res; +} static struct gui_misc_table win32_misc_table = { .schedule = win32_schedule, @@ -288,7 +305,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) int argc = 0, argctemp = 0; size_t len; LPWSTR *argvw; - char *messages; nserror ret; const char *addr; nsurl *url; @@ -303,7 +319,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) .bitmap = win32_bitmap_table, .layout = win32_layout_table, }; - win32_fetch_table->get_resource_url = gui_get_resource_url; ret = netsurf_register(&win32_table); if (ret != NSERROR_OK) { @@ -339,7 +354,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) } /* initialise logging - not fatal if it fails but not much we - * can do about it + * can do about it */ nslog_init(nslog_ensure, &argc, argv); @@ -361,10 +376,14 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) respaths = nsws_init_resource("${APPDATA}\\NetSurf:${HOME}\\.netsurf:${NETSURFRES}:${PROGRAMFILES}\\NetSurf\\NetSurf\\:"NETSURF_WINDOWS_RESPATH); - /* message init */ - messages = filepath_find(respaths, "messages"); - messages_add_from_file(messages); - free(messages); + /* Initialise translated messages */ + ret = nsw32_messages_init(respaths); + if (ret != NSERROR_OK) { + fprintf(stderr, "Unable to load translated messages (%s)\n", + messages_get_errorcode(ret)); + NSLOG(netsurf, INFO, "Unable to load translated messages"); + /** \todo decide if message load faliure should be fatal */ + } /* common initialisation */ ret = netsurf_init(NULL); -- cgit v1.2.3