1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-28 22:40:50 +00:00

App_update: Move constants to config

This commit is contained in:
gnosygnu 2016-11-26 10:03:36 -05:00
parent cea5072c2a
commit 9e1bbe0235
6 changed files with 92 additions and 19 deletions

View File

@ -27,9 +27,9 @@ public class Xoa_url_ {
public static void Invalid_warn(String url) {Xoa_app_.Usr_dlg().Plog_many("", "", "invalid url; url=~{0}", url);}
public static String Main_page__home_str = gplx.xowa.wikis.domains.Xow_domain_itm_.Str__home + gplx.xowa.htmls.hrefs.Xoh_href_.Str__wiki + gplx.xowa.Xoa_page_.Main_page_str; // EX:home/wiki/Main_Page
public static final byte[]
Qarg__redirect = Bry_.new_a7("redirect")
, Qarg__redirect__no = Bry_.new_a7("no")
, Qarg__action = Bry_.new_a7("action")
, Qarg__action__edit = Bry_.new_a7("edit")
Qarg__redirect = Bry_.new_a7("redirect")
, Qarg__redirect__no = Bry_.new_a7("no")
, Qarg__action = Bry_.new_a7("action")
, Qarg__action__edit = Bry_.new_a7("edit")
;
}

View File

@ -20,9 +20,12 @@ import gplx.xowa.guis.cbks.*;
import gplx.core.gfobjs.*;
import gplx.xowa.addons.apps.updates.dbs.*; import gplx.xowa.addons.apps.updates.js.*;
import gplx.xowa.addons.apps.updates.apps.*;
import gplx.core.envs.*;
class Xoa_update_controller implements Gfo_invk {
private Io_url app_root_dir, update_dir;
private Xoa_app app;
private Io_url app_root_dir, update_dir, update_jar_fil;
public void Update_app(Xoa_app app, String version_name) {
this.app = app;
// get app_version from db
this.app_root_dir = app.Fsys_mgr().Root_dir();
this.update_dir = app_root_dir.GenSubDir_nest("user", "app", "update");
@ -52,12 +55,12 @@ class Xoa_update_controller implements Gfo_invk {
private void On_unzip_done(GfoMsg m) {
Xojs_wkr__unzip unzip_wkr = (Xojs_wkr__unzip)m.ReadObj("v");
Io_url src = unzip_wkr.Trg();
Io_url trg = Io_url_.new_dir_("D:\\xowa_temp\\");
Io_url trg = app_root_dir;
// copy update_jar
Io_url src_jar_fil = app_root_dir.GenSubFil_nest("bin", "any", "xowa", "addon", "app", "update", "xoa_update.jar");
Io_url trg_jar_fil = update_dir.GenSubFil_nest("xoa_update.jar");
Io_mgr.Instance.MoveFil_args(src_jar_fil, trg_jar_fil, true).MissingFails_off().Exec();
Io_url src_jar_fil = src.GenSubFil_nest("bin", "any", "xowa", "addon", "app", "update", "xoa_update.jar");
this.update_jar_fil = app_root_dir.GenSubFil_nest("user", "app", "update", "xoa_update.jar");
Io_mgr.Instance.MoveFil_args(src_jar_fil, update_jar_fil, true).Exec();
Xojs_wkr__replace replace_wkr = new Xojs_wkr__replace(unzip_wkr.Cbk_mgr(), unzip_wkr.Cbk_trg(), "xo.app_updater.download__prog", Gfo_invk_cmd.New_by_key(this, Invk__replace_done), src, trg);
replace_wkr.Exec_async("app_updater");
@ -76,15 +79,13 @@ class Xoa_update_controller implements Gfo_invk {
// write failed
Bry_bfr bfr = Bry_bfr_.New();
Write_restart(bfr);
bfr.Add_str_u8(App__update__restart_cmd(app.Api_root().Addon().App__update__restart_cmd(), Env_.AppUrl(), Op_sys.Cur().Tid(), Op_sys.Cur().Bitness()) + "\n");
list.Save(bfr);
Io_mgr.Instance.SaveFilBfr(update_dir.GenSubFil("xoa_update.txt"), bfr);
replace_wkr.Cbk_mgr().Send_json(replace_wkr.Cbk_trg(), "xo.app_updater.download__prog", Gfobj_nde.New().Add_bool("done", true));
}
private void Write_restart(Bry_bfr bfr) {
String restart = String_.Format("D:\\xowa_temp\\xowa_64.exe\n");
bfr.Add_str_u8(restart);
Runtime_.Exec("java -jar " + update_jar_fil.Raw());
System_.Exit();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__download_done)) On_download_done(m);
@ -93,4 +94,27 @@ class Xoa_update_controller implements Gfo_invk {
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk__download_done = "download_done", Invk__unzip_done = "unzip_done", Invk__replace_done = "replace_done";
public static String App__update__restart_cmd(String current, Io_url app_url, byte op_sys_tid, byte bitness) {
String rv = current;
if (!String_.Eq(rv, String_.Empty)) return rv; // something specified; return it
String bitness_str = bitness == Op_sys.Bitness_32 ? "" : "_64";
Io_url root_dir = app_url.OwnerDir();
String prepend_sh = op_sys_tid == Op_sys.Tid_wnt ? "" : "sh ";
String file_fmt = "";
switch (op_sys_tid) {
case Op_sys.Tid_lnx:
file_fmt = "xowa_linux{0}.sh";
break;
case Op_sys.Tid_osx:
file_fmt = "xowa_macosx{0}";
break;
case Op_sys.Tid_wnt:
file_fmt = "xowa{0}.exe";
break;
default:
throw Err_.new_unhandled_default(op_sys_tid);
}
return prepend_sh + root_dir.GenSubFil(String_.Format(file_fmt, bitness_str)).Raw();
}
}

View File

@ -0,0 +1,37 @@
/*
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.addons.apps.updates.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.updates.*;
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
public class Xoa_update_controller__tst {
private final Xoa_update_controller__fxt fxt = new Xoa_update_controller__fxt();
@Test public void Restart_cmd() {
Io_url jar_fil = Io_url_.new_dir_("/home/gnosygnu/xowa/xowa.jar");
fxt.Test__restart_cmd("manual" , jar_fil, Op_sys.Tid_lnx, Op_sys.Bitness_64, "manual");
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_lnx, Op_sys.Bitness_64, "sh /home/gnosygnu/xowa/xowa_linux_64.sh");
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_lnx, Op_sys.Bitness_32, "sh /home/gnosygnu/xowa/xowa_linux.sh");
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_osx, Op_sys.Bitness_64, "sh /home/gnosygnu/xowa/xowa_macosx_64");
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_osx, Op_sys.Bitness_32, "sh /home/gnosygnu/xowa/xowa_macosx");
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_wnt, Op_sys.Bitness_64, "/home/gnosygnu/xowa/xowa_64.exe");
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_wnt, Op_sys.Bitness_32, "/home/gnosygnu/xowa/xowa.exe");
}
}
class Xoa_update_controller__fxt {
public void Test__restart_cmd(String current, Io_url app_url, byte op_sys_tid, byte bitness, String expd) {
Gftest.Eq__str(expd, Xoa_update_controller.App__update__restart_cmd(current, app_url, op_sys_tid, bitness), "restart_cmd");
}
}

View File

@ -32,9 +32,8 @@ class Xoa_update_html extends Xow_special_wtr__base {
if (web_access_enabled) {
// check text file to see if version changed
Io_url trg_summary_fil = update_db_url.OwnerDir().GenSubFil("xoa_update.txt");
int trg_summary_version = Int_.parse_or(Io_mgr.Instance.LoadFilStr(trg_summary_fil), -1);
// String src_summary_server = "http://xowa.org";
String src_summary_server = "http://localhost/xowa.org";
int trg_summary_version = Bry_.To_int_or(Io_mgr.Instance.LoadFilBryOr(trg_summary_fil, Bry_.new_a7("-1")), -1);
String src_summary_server = app.Api_root().Addon().App__update__update_db_src(); // "http://xowa.org";
int src_summary_version = Bry_.To_int(Io_mgr.Instance.DownloadFil_args("", Io_url_.Empty).Exec_as_bry(src_summary_server + "/admin/app_update/xoa_update.txt"));
// download database

View File

@ -23,6 +23,8 @@ public class Xoapi_addon implements Gfo_invk {
public Xoapi_addon_bldr Bldr() {return bldr;} private final Xoapi_addon_bldr bldr = new Xoapi_addon_bldr();
public boolean Wikis__ctgs__hidden_enabled() {return wikis__ctgs__hidden_enabled;} private boolean wikis__ctgs__hidden_enabled = false;
public boolean App__scripting__enabled() {return app__scripting__enabled;} private boolean app__scripting__enabled = false;
public String App__update__restart_cmd() {return app__update__restart_cmd;} private String app__update__restart_cmd = "";
public String App__update__update_db_src() {return app__update__update_db_src;} private String app__update__update_db_src = "http://xowa.org";
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__search)) return search;
else if (ctx.Match(k, Invk__bldr)) return bldr;
@ -32,6 +34,10 @@ public class Xoapi_addon implements Gfo_invk {
else if (ctx.Match(k, Invk__app__scripting__enabled_)) app__scripting__enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk__app__page_history__log_all)) return Yn.To_str(app__page_history__log_all);
else if (ctx.Match(k, Invk__app__page_history__log_all_)) app__page_history__log_all = m.ReadYn("v");
else if (ctx.Match(k, Invk__app__update__restart_cmd)) return app__update__restart_cmd;
else if (ctx.Match(k, Invk__app__update__restart_cmd_)) app__update__restart_cmd = m.ReadStr("v");
else if (ctx.Match(k, Invk__app__update__update_db_src)) return app__update__update_db_src;
else if (ctx.Match(k, Invk__app__update__update_db_src_)) app__update__update_db_src = m.ReadStr("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
@ -42,6 +48,10 @@ public class Xoapi_addon implements Gfo_invk {
, Invk__app__scripting__enabled_ = "app__scripting__enabled_"
, Invk__app__page_history__log_all = "app__page_history__log_all"
, Invk__app__page_history__log_all_ = "app__page_history__log_all_"
, Invk__app__update__restart_cmd = "app__update__restart_cmd"
, Invk__app__update__restart_cmd_ = "app__update__restart_cmd_"
, Invk__app__update__update_db_src = "app__update__update_db_src"
, Invk__app__update__update_db_src_ = "app__update__update_db_src_"
;
public static boolean app__page_history__log_all;
}

View File

@ -22,8 +22,11 @@ import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.wikis.pages.*;
public class Xog_tab_itm_read_mgr {
public static void Show_page(Xog_tab_itm tab, Xoae_page new_page, boolean reset_to_read) {Show_page(tab, new_page, reset_to_read, false, false, Xog_history_stack.Nav_fwd);}
public static void Show_page(Xog_tab_itm tab, Xoae_page new_page, boolean reset_to_read, boolean new_page_is_same, boolean show_is_err, byte history_nav_type) {
if (reset_to_read) tab.View_mode_(Xopg_page_.Tid_read);
if (new_page.Url().Qargs_mgr().Match(Xoa_url_.Qarg__action, Xoa_url_.Qarg__action__edit)) tab.View_mode_(Xopg_page_.Tid_edit);
if (reset_to_read)
tab.View_mode_(Xopg_page_.Tid_read);
if (new_page.Url().Qargs_mgr().Match(Xoa_url_.Qarg__action, Xoa_url_.Qarg__action__edit))
tab.View_mode_(Xopg_page_.Tid_edit);
Xoae_page cur_page = tab.Page(); Xog_html_itm html_itm = tab.Html_itm(); Gfui_html html_box = html_itm.Html_box();
Xog_win_itm win = tab.Tab_mgr().Win();
if (cur_page != null && !new_page_is_same) { // if new_page_is_same, don't update DocPos; will "lose" current position