rename global resource path variables in win32 frontend

This commit is contained in:
Vincent Sanders 2019-12-10 22:48:42 +00:00
parent 56ddeed96c
commit 77d184913b
5 changed files with 44 additions and 26 deletions

View File

@ -79,7 +79,7 @@ static nsurl *nsw32_get_resource_url(const char *path)
char buf[PATH_MAX]; char buf[PATH_MAX];
nsurl *url = NULL; nsurl *url = NULL;
netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url); netsurf_path_to_nsurl(filepath_sfind(G_resource_pathv, buf, path), &url);
return url; return url;
} }

View File

@ -41,13 +41,15 @@
#include "windows/window.h" #include "windows/window.h"
#include "windows/gui.h" #include "windows/gui.h"
/** /* exported global defined in windows/gui.h */
* win32 application instance handle.
*
* This handle is set in the main windows entry point.
*/
HINSTANCE hinst; HINSTANCE hinst;
/* exported global defined in windows/gui.h */
char **G_resource_pathv;
/* exported global defined in windows/gui.h */
char *G_config_path;
static bool win32_quit = false; static bool win32_quit = false;
struct dialog_list_entry { struct dialog_list_entry {

View File

@ -22,13 +22,22 @@
struct gui_window; struct gui_window;
/**
* win32 application instance handle.
*
* This handle is set in the main windows entry point.
*/
extern HINSTANCE hinst; extern HINSTANCE hinst;
/** Directory where all configuration files are held. */ /**
extern char *nsw32_config_home; * path to where all user config files are held.
*/
extern char *G_config_path;
/** resource search path vector. */ /**
extern char **respaths; * resource search path vector.
*/
extern char **G_resource_pathv;
/* bounding box */ /* bounding box */
typedef struct bbox_s { typedef struct bbox_s {

View File

@ -57,9 +57,6 @@
#include "windows/clipboard.h" #include "windows/clipboard.h"
#include "windows/gui.h" #include "windows/gui.h"
char **respaths; /** exported global defined in windows/gui.h */
char *nsw32_config_home; /* exported global defined in windows/gui.h */
/** /**
* Obtain the DPI of the display. * Obtain the DPI of the display.
@ -224,28 +221,28 @@ static nserror set_defaults(struct nsoption_s *defaults)
/* cookie file default */ /* cookie file default */
fname = NULL; fname = NULL;
netsurf_mkpath(&fname, NULL, 2, nsw32_config_home, "Cookies"); netsurf_mkpath(&fname, NULL, 2, G_config_path, "Cookies");
if (fname != NULL) { if (fname != NULL) {
nsoption_setnull_charp(cookie_file, fname); nsoption_setnull_charp(cookie_file, fname);
} }
/* cookie jar default */ /* cookie jar default */
fname = NULL; fname = NULL;
netsurf_mkpath(&fname, NULL, 2, nsw32_config_home, "Cookies"); netsurf_mkpath(&fname, NULL, 2, G_config_path, "Cookies");
if (fname != NULL) { if (fname != NULL) {
nsoption_setnull_charp(cookie_jar, fname); nsoption_setnull_charp(cookie_jar, fname);
} }
/* url database default */ /* url database default */
fname = NULL; fname = NULL;
netsurf_mkpath(&fname, NULL, 2, nsw32_config_home, "URLs"); netsurf_mkpath(&fname, NULL, 2, G_config_path, "URLs");
if (fname != NULL) { if (fname != NULL) {
nsoption_setnull_charp(url_file, fname); nsoption_setnull_charp(url_file, fname);
} }
/* bookmark database default */ /* bookmark database default */
fname = NULL; fname = NULL;
netsurf_mkpath(&fname, NULL, 2, nsw32_config_home, "Hotlist"); netsurf_mkpath(&fname, NULL, 2, G_config_path, "Hotlist");
if (fname != NULL) { if (fname != NULL) {
nsoption_setnull_charp(hotlist_path, fname); nsoption_setnull_charp(hotlist_path, fname);
} }
@ -257,11 +254,16 @@ static nserror set_defaults(struct nsoption_s *defaults)
/** /**
* Initialise user options location and contents * Initialise user options location and contents
*/ */
static nserror nsw32_option_init(int *pargc, char** argv) static nserror
nsw32_option_init(int *pargc, char** argv, char **respaths, char *config_path)
{ {
nserror ret; nserror ret;
char *choices = NULL; char *choices = NULL;
/* set the globals that will be used in the set_defaults() callback */
G_resource_pathv = respaths;
G_config_path = config_path;
/* user options setup */ /* user options setup */
ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default);
if (ret != NSERROR_OK) { if (ret != NSERROR_OK) {
@ -269,7 +271,7 @@ static nserror nsw32_option_init(int *pargc, char** argv)
} }
/* Attempt to load the user choices */ /* Attempt to load the user choices */
ret = netsurf_mkpath(&choices, NULL, 2, nsw32_config_home, "Choices"); ret = netsurf_mkpath(&choices, NULL, 2, config_path, "Choices");
if (ret == NSERROR_OK) { if (ret == NSERROR_OK) {
nsoption_read(choices, nsoptions); nsoption_read(choices, nsoptions);
free(choices); free(choices);
@ -311,6 +313,10 @@ static nserror nsw32_messages_init(char **respaths)
/** /**
* Construct a unix style argc/argv * Construct a unix style argc/argv
*
* \param argc_out number of commandline arguments
* \param argv_out string vector of command line arguments
* \return NSERROR_OK on success else error code
*/ */
static nserror win32_to_unix_commandline(int *argc_out, char ***argv_out) static nserror win32_to_unix_commandline(int *argc_out, char ***argv_out)
{ {
@ -318,6 +324,7 @@ static nserror win32_to_unix_commandline(int *argc_out, char ***argv_out)
char **argv; char **argv;
int cura; int cura;
LPWSTR *argvw; LPWSTR *argvw;
size_t len;
argvw = CommandLineToArgvW(GetCommandLineW(), &argc); argvw = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argvw == NULL) { if (argvw == NULL) {
@ -367,9 +374,10 @@ static struct gui_misc_table win32_misc_table = {
int WINAPI int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
{ {
char **argv = NULL; int argc;
int argc = 0; char **argv;
size_t len; char **respaths;
char *nsw32_config_home = NULL;
nserror ret; nserror ret;
const char *addr; const char *addr;
nsurl *url; nsurl *url;
@ -414,13 +422,12 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
if (ret != NSERROR_OK) { if (ret != NSERROR_OK) {
NSLOG(netsurf, INFO, NSLOG(netsurf, INFO,
"Unable to locate a configuration directory."); "Unable to locate a configuration directory.");
nsw32_config_home = NULL;
} }
/* Initialise user options */ /* Initialise user options */
ret = nsw32_option_init(&argc, argv); ret = nsw32_option_init(&argc, argv, respaths, nsw32_config_home);
if (ret != NSERROR_OK) { if (ret != NSERROR_OK) {
NSLOG(netsurf, INFO, "Options failed to initialise (%s)\n", NSLOG(netsurf, ERROR, "Options failed to initialise (%s)\n",
messages_get_errorcode(ret)); messages_get_errorcode(ret));
return 1; return 1;
} }

View File

@ -699,7 +699,7 @@ nserror nsws_prefs_save(void)
char *choices = NULL; char *choices = NULL;
nserror res; nserror res;
res = netsurf_mkpath(&choices, NULL, 2, nsw32_config_home, "Choices"); res = netsurf_mkpath(&choices, NULL, 2, G_config_path, "Choices");
if (res == NSERROR_OK) { if (res == NSERROR_OK) {
nsoption_write(choices, NULL, NULL); nsoption_write(choices, NULL, NULL);
free(choices); free(choices);