1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

v2.10.3.1

This commit is contained in:
gnosygnu
2015-10-18 22:17:57 -04:00
parent 8e18af05b6
commit 4f43f51b18
1935 changed files with 12500 additions and 12889 deletions

View File

@@ -0,0 +1,125 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.boots; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.consoles.*;
import gplx.dbs.*;
import gplx.gfui.*; import gplx.xowa.guis.views.boots.*;
import gplx.xowa.langs.*;
import gplx.xowa.users.*;
public class Xoa_boot_mgr {
private Gfo_usr_dlg usr_dlg; private Gfo_usr_dlg__log log_wtr;
public void Run(String[] args, Xoa_cmd_arg_mgr arg_mgr) {
try {
Init_env(args);
if (arg_mgr.Process(usr_dlg, args, Env_.AppUrl().OwnerDir()))
Run_app(arg_mgr);
}
catch (Exception e) {
String err_str = Err_.Message_gplx_full(e);
log_wtr.Log_to_err(err_str);
Console_adp__sys.Instance.Write_str_w_nl(err_str);
if (log_wtr.Log_dir() == null) log_wtr.Log_dir_(Env_.AppUrl().OwnerDir().GenSubFil("xowa.log"));
log_wtr.Queue_enabled_(false);
}
}
private void Init_env(String[] args) {
Gfo_usr_dlg_.Instance = usr_dlg = Xoa_app_.usr_dlg_console_();
log_wtr = usr_dlg.Log_wkr(); log_wtr.Log_to_session_fmt("env.init: version=~{0}", Xoa_app_.Version);
GfuiEnv_.Init_swt(args, Xoa_app_.class);
Io_url jar_url = Env_.AppUrl();
Xoa_app_.Build_date = Io_mgr.Instance.QueryFil(jar_url).ModifiedTime().XtoUtc().XtoStr_fmt("yyyy-MM-dd HH:mm");
log_wtr.Log_to_session_fmt("env.init: jar_url=~{0}; build_date=~{1}", jar_url.NameAndExt(), Xoa_app_.Build_date);
log_wtr.Log_to_session_fmt("env.init: op_sys=~{0}", Op_sys.Cur().To_str());
}
private void Run_app(Xoa_cmd_arg_mgr arg_mgr) {
boolean app_type_is_gui = false;
Xoae_app app = null;
try {
// init vars
Io_url root_dir = arg_mgr.Fsys__root_dir();
Xoa_app_.Op_sys_str = arg_mgr.Fsys__bin_dir();
Xoa_app_.User_agent = String_.Format("XOWA/{0} ({1}) [gnosygnu@gmail.com]", Xoa_app_.Version, Xoa_app_.Op_sys_str);
Xoa_app_mode app_type = arg_mgr.App_type();
app_type_is_gui = app_type.Tid_is_gui();
Xog_splash_win splash_win = new Xog_splash_win(app_type_is_gui);
Db_conn_bldr.Instance.Reg_default_sqlite();
// init app
app = new Xoae_app(usr_dlg, app_type
, root_dir
, arg_mgr.Fsys__wiki_dir()
, root_dir.GenSubDir("file")
, arg_mgr.Fsys__user_dir()
, root_dir.GenSubDir_nest("user", "anonymous", "wiki")
, Xoa_app_.Op_sys_str);
usr_dlg.Log_wkr().Queue_enabled_(false); log_wtr.Log_to_session_fmt("app.init");
try {
app.Sys_cfg().Lang_(System_lang());
String launch_url = arg_mgr.Gui__home_page();
if (launch_url != null) app.Api_root().App().Startup().Tabs().Manual_(launch_url);
app.Tcp_server().Rdr_port_(arg_mgr.Tcp__port_recv()).Wtr_port_(arg_mgr.Tcp__port_send());
gplx.xowa.apps.servers.http.Http_server_mgr server_mgr = app.Http_server();
server_mgr.Port_(arg_mgr.Http__port());
server_mgr.Home_(Bry_.new_u8(arg_mgr.Http__home_page()));
server_mgr.Wkr_pool().Init(arg_mgr.Http__max_clients(), arg_mgr.Http__max_clients_timeout());
app.Init_by_app();
}
catch (Exception e) {usr_dlg.Warn_many("", "", "app init failed: ~{0}", Err_.Message_gplx_full(e));}
app.Usr_dlg().Log_wkr_(app.Log_wtr()); // NOTE: log_wtr must be set for cmd-line (else process will fail);
// run gfs
gplx.xowa.users.prefs.Prefs_rename_mgr.Instance.Check(app.Usere().Fsys_mgr().App_data_cfg_user_fil());
Io_url cmd_file = arg_mgr.Cmd__file();
try {app.Gfs_mgr().Run_url(cmd_file);}
catch (Exception e) {
usr_dlg.Warn_many("", "", "script file failed: ~{0} ~{1}", cmd_file.Raw(), Err_.Message_gplx_full(e));
if (app_type_is_gui)
GfuiEnv_.ShowMsg(Err_.Message_gplx_full(e));
}
gplx.xowa.apps.setups.Xoa_setup_mgr.Delete_old_files(app);
// launch
app.Launch();
if (app_type.Tid_is_tcp()) app.Tcp_server().Run();
else if (app_type.Tid_is_http()) app.Http_server().Run();
else {
String cmd_text = arg_mgr.Cmd__text();
if (cmd_text != null) {
gplx.xowa.apps.servers.Gxw_html_server.Init_gui_for_server(app, null); // NOTE: must init kit else "app.shell.fetch_page" will fail; DATE:2015-04-30
Console_adp__sys.Instance.Write_str_w_nl_utf8(Object_.Xto_str_strict_or_empty(app.Gfs_mgr().Run_str(cmd_text)));
}
if (app_type_is_gui)
app.Gui_mgr().Run(splash_win);
else // teardown app, else lua will keep process running
if (gplx.xowa.xtns.scribunto.Scrib_core.Core() != null) gplx.xowa.xtns.scribunto.Scrib_core.Core().Term();
}
}
catch (Exception e) {usr_dlg.Warn_many("", "", "app launch failed: ~{0}", Err_.Message_gplx_full(e));}
finally {
if (app != null && app_type_is_gui) // only cancel if app_type_is_gui is true; (force cmd_line to end process)
app.Setup_mgr().Cmd_mgr().Canceled_y_();
}
}
private static byte[] System_lang() {
String lang_code = Env_.Env_prop__user_language();
byte[] lang_code_bry = Bry_.new_a7(lang_code);
Xol_lang_stub lang_itm = Xol_lang_stub_.Get_by_key_or_null(lang_code_bry);
return lang_itm == null ? Xol_lang_itm_.Key_en : lang_itm.Key();
}
}

View File

@@ -0,0 +1,102 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.boots; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.consoles.*;
import gplx.xowa.apps.*;
public class Xoa_cmd_arg_mgr {
Xoa_cmd_arg_mgr(Gfo_cmd_arg_mgr arg_mgr) {this.arg_mgr = arg_mgr;}
public Gfo_cmd_arg_mgr Arg_mgr() {return arg_mgr;} private final Gfo_cmd_arg_mgr arg_mgr;
public Xoa_app_mode App_type() {return app_type;} private Xoa_app_mode app_type;
public Io_url Fsys__root_dir() {return fsys__root_dir;} private Io_url fsys__root_dir;
public String Fsys__bin_dir() {return fsys__bin_dir;} private String fsys__bin_dir;
public Io_url Fsys__user_dir() {return fsys__user_dir;} private Io_url fsys__user_dir;
public Io_url Fsys__wiki_dir() {return fsys__wiki_dir;} private Io_url fsys__wiki_dir;
public Io_url Cmd__file() {return cmd__file;} private Io_url cmd__file;
public String Cmd__text() {return cmd__text;} private String cmd__text;
public int Tcp__port_recv() {return tcp__port_recv;} private int tcp__port_recv;
public int Tcp__port_send() {return tcp__port_send;} private int tcp__port_send;
public int Http__port() {return http__port;} private int http__port;
public String Http__home_page() {return http__home_page;} private String http__home_page;
public int Http__max_clients() {return http__max_clients;} private int http__max_clients;
public int Http__max_clients_timeout() {return http__max_clients_timeout;} private int http__max_clients_timeout;
public String Gui__home_page() {return gui__home_page;} private String gui__home_page;
public boolean Process(Gfo_usr_dlg usr_dlg, String[] args, Io_url jar_dir) {
arg_mgr.Parse(args);
if (!Print(usr_dlg)) return false;
this.app_type = Xoa_app_mode.parse(arg_mgr.Get_by("app_mode").Val_as_str_or("gui"));
this.fsys__root_dir = arg_mgr.Get_by("root_dir").Val_as_url__rel_dir_or(jar_dir, jar_dir);
this.fsys__user_dir = arg_mgr.Get_by("user_dir").Val_as_url__rel_dir_or(fsys__root_dir.GenSubDir("user"), fsys__root_dir.GenSubDir_nest("user", User_name_default));
this.fsys__wiki_dir = arg_mgr.Get_by("wiki_dir").Val_as_url__rel_dir_or(fsys__root_dir.GenSubDir("wiki"), fsys__root_dir.GenSubDir("wiki"));
this.cmd__file = arg_mgr.Get_by("cmd_file").Val_as_url__rel_fil_or(jar_dir, fsys__root_dir.GenSubFil_nest("bin", "any", "xowa", "cfg" ,"app", "xowa.gfs"));
this.cmd__text = arg_mgr.Get_by("cmd_text").Val_as_str_or(null);
this.tcp__port_recv = arg_mgr.Get_by("server_port_recv").Val_as_int_or(55000);
this.tcp__port_send = arg_mgr.Get_by("server_port_send").Val_as_int_or(55001);
this.http__port = arg_mgr.Get_by("http_server_port").Val_as_int_or(8080);
this.http__home_page = arg_mgr.Get_by("http_server_home").Val_as_str_or("home/wiki/Main_Page");
this.http__max_clients = arg_mgr.Get_by("http_server.max_clients").Val_as_int_or(0);
this.http__max_clients_timeout = arg_mgr.Get_by("http_server.max_clients_timeout").Val_as_int_or(50);
this.gui__home_page = arg_mgr.Get_by("url").Val_as_str_or(null);
this.fsys__bin_dir = arg_mgr.Get_by("bin_dir_name").Val_as_str_or(Bin_dir_name());
return true;
}
private boolean Print(Gfo_usr_dlg usr_dlg) {
String header = String_.Concat_lines_nl_skip_last
( Env_.GenHdr(false, "XOWA", "XOWA: the XOWA Offline Wiki Application\n", "")
, String_.Repeat("-", 80)
, ""
, "version: " + Xoa_app_.Version + "; build date: " + Xoa_app_.Build_date
);
Gfo_cmd_arg_mgr_printer printer = new Gfo_cmd_arg_mgr_printer(arg_mgr);
return printer.Print(usr_dlg, header, Xoa_app_.Name, "help", "show_license", "show_args");
}
public static Xoa_cmd_arg_mgr new_() {
Gfo_cmd_arg_mgr arg_mgr = new Gfo_cmd_arg_mgr().Reg_many
( Gfo_cmd_arg_itm_.opt_("root_dir").Example_url_("C:\\xowa").Note_("root directory for xowa; defaults to current directory of xowa.jar")
, Gfo_cmd_arg_itm_.opt_("user_dir").Example_url_("C:\\xowa\\user\\" + User_name_default).Note_("directory for user_data; defaults to '/xowa/user/" + User_name_default + "'")
, Gfo_cmd_arg_itm_.opt_("wiki_dir").Example_url_("C:\\xowa\\wiki\\").Note_("directory for wikis; defaults to '/xowa/wiki/'")
, Gfo_cmd_arg_itm_.opt_("bin_dir_name").Example_("windows").Note_("platform-dependent directory name inside /xowa/bin/; valid values are 'linux', 'macosx', 'windows', 'linux_64', 'macosx_64', 'windows_64'; defaults to detected version")
, Gfo_cmd_arg_itm_.opt_("app_mode").Example_("gui").Note_("type of app to run; valid values are 'gui', 'cmd', 'server', 'http_server'; defaults to 'gui'")
, Gfo_cmd_arg_itm_.opt_("cmd_file").Example_url_("C:\\xowa\\bin\\any\\xowa\\cfg\\app\\xowa.gfs").Note_("file_path of script to execute; defaults to 'xowa.gfs'")
, Gfo_cmd_arg_itm_.opt_("cmd_text").Example_("\"app.shell.fetch_page('en.wikipedia.org/wiki/Earth', 'html');\"").Note_("script to run; runs after cmd_file; does nothing if empty; default is empty.\nCurrently a useful cmd is to do 'java -jar xowa_your_platform.jar --app_mode cmd --show_license n --show_args n --cmd_text \"app.shell.fetch_page('en.wikipedia.org/wiki/Earth' 'html');\"'. This will output the page's html to the console. You can also change 'html' to 'wiki' to get the wikitext.")
, Gfo_cmd_arg_itm_.opt_("url").Example_("en.wikipedia.org/wiki/Earth").Note_("url to be shown when xowa first launches; default is home/wiki/Main_Page")
, Gfo_cmd_arg_itm_.opt_("server_port_recv").Example_("55000").Note_("applies to --app_mode server; port where xowa server will receive messages; clients should send messages to this port")
, Gfo_cmd_arg_itm_.opt_("server_port_send").Example_("55001").Note_("applies to --app_mode server; port where xowa server will send messages; clients should listen for messages from this port")
, Gfo_cmd_arg_itm_.opt_("http_server_port").Example_("8080").Note_("applies to --app_mode http_server; port used by http_server; default is 8080")
, Gfo_cmd_arg_itm_.opt_("http_server_home").Example_("home/wiki/Main_Page").Note_("applies to --app_mode http_server; default home page for root address. EX: navigating to localhost:8080 will navigate to localhost:8080/home/wiki/Main_Page")
, Gfo_cmd_arg_itm_.opt_("http_server.max_clients").Example_("15").Note_("applies to --app_mode http_server; limits maximum number of concurrent connections; default is 0 (no limit)")
, Gfo_cmd_arg_itm_.opt_("http_server.max_clients_timeout").Example_("50").Note_("applies to --app_mode http_server; time in milliseconds to wait before checking again to see if a connection is free; default is 50 (wait 50 ms)")
, Gfo_cmd_arg_itm_.sys_("show_license").Dflt_(true)
, Gfo_cmd_arg_itm_.sys_("show_args").Dflt_(true)
, Gfo_cmd_arg_itm_.new_(Gfo_cmd_arg_itm_.Tid_system, "help", Bool_.N, Gfo_cmd_arg_itm_.Val_tid_string)
);
return new Xoa_cmd_arg_mgr(arg_mgr);
}
private static final String User_name_default = gplx.xowa.users.Xoue_user.Key_xowa_user;
private static String Bin_dir_name() {
String rv = "";
Op_sys op_sys = Op_sys.Cur();
switch (op_sys.Tid()) {
case Op_sys.Tid_lnx: rv = "linux"; break;
case Op_sys.Tid_wnt: rv = "windows"; break;
case Op_sys.Tid_osx: rv = "macosx"; break;
default: throw Err_.new_unhandled("unknown platform " + Op_sys.Cur());
}
if (op_sys.Bitness() == Op_sys.Bitness_64) rv += "_64";
return rv;
}
}