1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +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

@@ -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