2011-04-04 02:01:37 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Vincent Sanders <vince@simtec.co.uk>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdbool.h>
|
2012-08-11 01:22:59 +04:00
|
|
|
|
|
|
|
#include "utils/config.h"
|
|
|
|
|
2011-04-04 02:01:37 +04:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include "desktop/gui.h"
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2011-04-04 02:01:37 +04:00
|
|
|
#include "desktop/browser.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/log.h"
|
2013-02-22 18:34:23 +04:00
|
|
|
#include "utils/messages.h"
|
2011-04-04 02:01:37 +04:00
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/filepath.h"
|
|
|
|
#include "content/fetchers/resource.h"
|
|
|
|
|
|
|
|
#include "windows/findfile.h"
|
|
|
|
#include "windows/drawable.h"
|
|
|
|
#include "windows/gui.h"
|
2014-01-16 19:00:43 +04:00
|
|
|
#include "windows/download.h"
|
2011-04-04 02:01:37 +04:00
|
|
|
|
|
|
|
static char **respaths; /** resource search path vector. */
|
|
|
|
|
|
|
|
char *options_file_location;
|
|
|
|
|
2014-01-15 03:31:54 +04:00
|
|
|
static nsurl *gui_get_resource_url(const char *path)
|
2011-04-04 02:01:37 +04:00
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
2011-10-05 12:32:52 +04:00
|
|
|
char *raw;
|
|
|
|
nsurl *url = NULL;
|
|
|
|
|
|
|
|
raw = path_to_url(filepath_sfind(respaths, buf, path));
|
|
|
|
if (raw != NULL) {
|
|
|
|
nsurl_create(raw, &url);
|
|
|
|
free(raw);
|
|
|
|
}
|
|
|
|
|
|
|
|
return url;
|
2011-04-04 02:01:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-23 14:50:57 +04:00
|
|
|
* Ensures output logging stream is available
|
2011-04-04 02:01:37 +04:00
|
|
|
*/
|
2013-05-23 14:50:57 +04:00
|
|
|
static bool nslog_ensure(FILE *fptr)
|
2011-04-04 02:01:37 +04:00
|
|
|
{
|
|
|
|
/* mwindows compile flag normally invalidates standard io unless
|
|
|
|
* already redirected
|
|
|
|
*/
|
|
|
|
if (_get_osfhandle(fileno(fptr)) == -1) {
|
|
|
|
AllocConsole();
|
|
|
|
freopen("CONOUT$", "w", fptr);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-28 18:19:06 +04:00
|
|
|
/**
|
|
|
|
* Set option defaults for framebuffer frontend
|
|
|
|
*
|
|
|
|
* @param defaults The option table to update.
|
|
|
|
* @return error status.
|
|
|
|
*/
|
|
|
|
static nserror set_defaults(struct nsoption_s *defaults)
|
2012-10-17 17:20:18 +04:00
|
|
|
{
|
|
|
|
/* Set defaults for absent option strings */
|
|
|
|
|
|
|
|
/* ensure homepage option has a default */
|
|
|
|
nsoption_setnull_charp(homepage_url, strdup(NETSURF_HOMEPAGE));
|
2013-05-28 18:19:06 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
2012-10-17 17:20:18 +04:00
|
|
|
}
|
|
|
|
|
2014-01-11 18:20:30 +04:00
|
|
|
|
|
|
|
|
2011-04-04 02:01:37 +04:00
|
|
|
/**
|
|
|
|
* Entry point from operating system
|
|
|
|
**/
|
|
|
|
int WINAPI
|
|
|
|
WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
|
|
|
|
{
|
|
|
|
char **argv = NULL;
|
|
|
|
int argc = 0, argctemp = 0;
|
|
|
|
size_t len;
|
|
|
|
LPWSTR *argvw;
|
|
|
|
char *messages;
|
|
|
|
nserror ret;
|
2013-02-14 22:21:11 +04:00
|
|
|
const char *addr;
|
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
2014-01-15 23:37:05 +04:00
|
|
|
struct gui_table win32_gui_table = {
|
|
|
|
.browser = win32_browser_table,
|
|
|
|
.window = win32_window_table,
|
|
|
|
.clipboard = win32_clipboard_table,
|
|
|
|
.download = win32_download_table,
|
|
|
|
};
|
2014-01-16 19:21:12 +04:00
|
|
|
win32_browser_table->get_resource_url = gui_get_resource_url;
|
2011-04-04 02:01:37 +04:00
|
|
|
|
|
|
|
if (SLEN(lpcli) > 0) {
|
|
|
|
argvw = CommandLineToArgvW(GetCommandLineW(), &argc);
|
|
|
|
}
|
|
|
|
|
|
|
|
setbuf(stderr, NULL);
|
|
|
|
|
|
|
|
/* Construct a unix style argc/argv */
|
|
|
|
argv = malloc(sizeof(char *) * argc);
|
|
|
|
while (argctemp < argc) {
|
|
|
|
len = wcstombs(NULL, argvw[argctemp], 0) + 1;
|
|
|
|
if (len > 0) {
|
|
|
|
argv[argctemp] = malloc(len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argv[argctemp] != NULL) {
|
|
|
|
wcstombs(argv[argctemp], argvw[argctemp], len);
|
|
|
|
/* alter windows-style forward slash flags to
|
|
|
|
* hyphen flags.
|
|
|
|
*/
|
|
|
|
if (argv[argctemp][0] == '/')
|
|
|
|
argv[argctemp][0] = '-';
|
|
|
|
}
|
|
|
|
argctemp++;
|
|
|
|
}
|
|
|
|
|
2012-08-13 00:50:36 +04:00
|
|
|
respaths = nsws_init_resource("${APPDATA}\\NetSurf:${HOME}\\.netsurf:${NETSURFRES}:${PROGRAMFILES}\\NetSurf\\NetSurf\\:"NETSURF_WINDOWS_RESPATH);
|
2011-04-04 02:01:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
options_file_location = filepath_find(respaths, "preferences");
|
|
|
|
|
2013-05-23 14:50:57 +04:00
|
|
|
/* initialise logging - not fatal if it fails but not much we
|
|
|
|
* can do about it
|
|
|
|
*/
|
|
|
|
nslog_init(nslog_ensure, &argc, argv);
|
|
|
|
|
2013-05-28 18:19:06 +04:00
|
|
|
/* user options setup */
|
|
|
|
ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default);
|
2013-05-23 14:50:57 +04:00
|
|
|
if (ret != NSERROR_OK) {
|
2013-05-28 18:19:06 +04:00
|
|
|
die("Options failed to initialise");
|
2013-05-23 14:50:57 +04:00
|
|
|
}
|
2013-05-28 18:19:06 +04:00
|
|
|
nsoption_read(options_file_location, NULL);
|
|
|
|
nsoption_commandline(&argc, argv, NULL);
|
2011-04-04 02:01:37 +04:00
|
|
|
|
2013-05-28 18:19:06 +04:00
|
|
|
/* common initialisation */
|
|
|
|
messages = filepath_find(respaths, "messages");
|
2014-01-15 23:37:05 +04:00
|
|
|
ret = netsurf_init(messages, &win32_gui_table);
|
2011-04-04 02:01:37 +04:00
|
|
|
free(messages);
|
2013-05-28 18:19:06 +04:00
|
|
|
if (ret != NSERROR_OK) {
|
|
|
|
free(options_file_location);
|
|
|
|
LOG(("NetSurf failed to initialise"));
|
|
|
|
return 1;
|
|
|
|
}
|
2011-04-04 02:01:37 +04:00
|
|
|
|
|
|
|
ret = nsws_create_main_class(hInstance);
|
|
|
|
ret = nsws_create_drawable_class(hInstance);
|
|
|
|
ret = nsws_create_localhistory_class(hInstance);
|
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_set_bool(target_blank, false);
|
2011-04-04 02:01:37 +04:00
|
|
|
|
|
|
|
nsws_window_init_pointers(hInstance);
|
|
|
|
|
|
|
|
/* If there is a url specified on the command line use it */
|
2012-03-22 13:34:34 +04:00
|
|
|
if (argc > 1) {
|
2011-04-04 02:01:37 +04:00
|
|
|
addr = argv[1];
|
2013-02-14 22:21:11 +04:00
|
|
|
} else if (nsoption_charp(homepage_url) != NULL) {
|
2012-03-22 13:34:34 +04:00
|
|
|
addr = nsoption_charp(homepage_url);
|
2013-02-14 22:21:11 +04:00
|
|
|
} else {
|
|
|
|
addr = NETSURF_HOMEPAGE;
|
2012-03-22 13:34:34 +04:00
|
|
|
}
|
2011-04-04 02:01:37 +04:00
|
|
|
|
|
|
|
LOG(("calling browser_window_create"));
|
|
|
|
|
2013-02-14 22:21:11 +04:00
|
|
|
error = nsurl_create(addr, &url);
|
|
|
|
if (error == NSERROR_OK) {
|
2013-02-18 15:51:42 +04:00
|
|
|
error = browser_window_create(BROWSER_WINDOW_VERIFIABLE |
|
|
|
|
BROWSER_WINDOW_HISTORY,
|
2013-02-14 22:21:11 +04:00
|
|
|
url,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
nsurl_unref(url);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
warn_user(messages_get_errorcode(error), 0);
|
|
|
|
} else {
|
|
|
|
netsurf_main_loop();
|
|
|
|
}
|
2011-04-04 02:01:37 +04:00
|
|
|
|
|
|
|
netsurf_exit();
|
|
|
|
|
|
|
|
free(options_file_location);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|