mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
App_update: Redownload update_db if download fails
This commit is contained in:
parent
a114880f2b
commit
e389bcbee9
@ -18,24 +18,33 @@ import gplx.core.gfobjs.*; import gplx.core.progs.*; import gplx.core.progs.rate
|
||||
import gplx.xowa.guis.cbks.*;
|
||||
public class Xojs_wkr__base implements Gfo_prog_ui, Gfo_invk {
|
||||
private final Gfo_invk_cmd done_cbk;
|
||||
private final Gfo_invk_cmd fail_cbk;
|
||||
private final Gfo_rate_list rate_list = new Gfo_rate_list(32);
|
||||
private final long notify_delay = 1000;
|
||||
private final double delta_threshold = .25d; // allow variance of up to 25% before updating rate
|
||||
private final String js_cbk, task_type;
|
||||
private long time_prv;
|
||||
private double rate_cur;
|
||||
public Xojs_wkr__base(Xog_cbk_mgr cbk_mgr, Xog_cbk_trg cbk_trg, String js_cbk, Gfo_invk_cmd done_cbk, String task_type) {
|
||||
public Xojs_wkr__base(Xog_cbk_mgr cbk_mgr, Xog_cbk_trg cbk_trg, String js_cbk, Gfo_invk_cmd done_cbk, Gfo_invk_cmd fail_cbk, String task_type) {
|
||||
this.cbk_mgr = cbk_mgr;
|
||||
this.cbk_trg = cbk_trg;
|
||||
this.js_cbk = js_cbk;
|
||||
this.done_cbk = done_cbk;
|
||||
this.fail_cbk = fail_cbk;
|
||||
this.task_type = task_type;
|
||||
rate_list.Add(1024 * 1024, 1); // add default rate of 1 MB per second;
|
||||
}
|
||||
public void Exec() {
|
||||
this.time_prv = gplx.core.envs.System_.Ticks();
|
||||
this.Exec_run();
|
||||
done_cbk.Exec_by_ctx(GfsCtx.Instance, GfoMsg_.new_cast_("m").Add("v", this));
|
||||
try {
|
||||
this.time_prv = gplx.core.envs.System_.Ticks();
|
||||
this.Exec_run();
|
||||
done_cbk.Exec_by_ctx(GfsCtx.Instance, GfoMsg_.new_cast_("m").Add("v", this));
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to run task; task=~{0} err=~{1}", task_type, Err_.Message_gplx_log(e));
|
||||
cbk_mgr.Send_notify(cbk_trg, String_.Format("failed to run task: task={0} err={1}", task_type, Err_.Message_lang(e)));
|
||||
if (fail_cbk != null)
|
||||
fail_cbk.Exec();
|
||||
}
|
||||
}
|
||||
@gplx.Virtual protected void Exec_run() {}
|
||||
public void Exec_async(String thread_name) {
|
||||
|
@ -17,7 +17,7 @@ package gplx.xowa.addons.apps.updates.js; import gplx.*; import gplx.xowa.*; imp
|
||||
import gplx.xowa.guis.cbks.*;
|
||||
import gplx.core.net.downloads.*;
|
||||
public class Xojs_wkr__download extends Xojs_wkr__base {
|
||||
public Xojs_wkr__download(Xog_cbk_mgr cbk_mgr, Xog_cbk_trg cbk_trg, String js_cbk, Gfo_invk_cmd done_cbk, String src, Io_url trg, long src_len) {super(cbk_mgr, cbk_trg, js_cbk, done_cbk, "downloading");
|
||||
public Xojs_wkr__download(Xog_cbk_mgr cbk_mgr, Xog_cbk_trg cbk_trg, String js_cbk, Gfo_invk_cmd done_cbk, Gfo_invk_cmd fail_cbk, String src, Io_url trg, long src_len) {super(cbk_mgr, cbk_trg, js_cbk, done_cbk, fail_cbk, "downloading");
|
||||
this.src = src;
|
||||
this.src_len = src_len;
|
||||
this.trg = trg;
|
||||
|
@ -18,7 +18,7 @@ import gplx.xowa.guis.cbks.*;
|
||||
public class Xojs_wkr__replace extends Xojs_wkr__base {
|
||||
private final Io_url src_dir, trg_dir;
|
||||
private final Io_url[] src_fils;
|
||||
public Xojs_wkr__replace(Xog_cbk_mgr cbk_mgr, Xog_cbk_trg cbk_trg, String js_cbk, Gfo_invk_cmd done_cbk, Io_url src_dir, Io_url trg_dir) {super(cbk_mgr, cbk_trg, js_cbk, done_cbk, "unzipping");
|
||||
public Xojs_wkr__replace(Xog_cbk_mgr cbk_mgr, Xog_cbk_trg cbk_trg, String js_cbk, Gfo_invk_cmd done_cbk, Io_url src_dir, Io_url trg_dir) {super(cbk_mgr, cbk_trg, js_cbk, done_cbk, null, "replacing");
|
||||
this.src_dir = src_dir;
|
||||
this.trg_dir = trg_dir;
|
||||
this.src_fils = Io_mgr.Instance.QueryDir_args(src_dir).Recur_().ExecAsUrlAry();
|
||||
|
@ -17,7 +17,7 @@ package gplx.xowa.addons.apps.updates.js; import gplx.*; import gplx.xowa.*; imp
|
||||
import gplx.xowa.guis.cbks.*;
|
||||
import gplx.core.ios.zips.*;
|
||||
public class Xojs_wkr__unzip extends Xojs_wkr__base {
|
||||
public Xojs_wkr__unzip(Xog_cbk_mgr cbk_mgr, Xog_cbk_trg cbk_trg, String js_cbk, Gfo_invk_cmd done_cbk, Io_url src, Io_url trg, long prog_data_end) {super(cbk_mgr, cbk_trg, js_cbk, done_cbk, "unzipping");
|
||||
public Xojs_wkr__unzip(Xog_cbk_mgr cbk_mgr, Xog_cbk_trg cbk_trg, String js_cbk, Gfo_invk_cmd done_cbk, Io_url src, Io_url trg, long prog_data_end) {super(cbk_mgr, cbk_trg, js_cbk, done_cbk, null, "unzipping");
|
||||
this.src = src; this.trg = trg;
|
||||
this.Prog_data_end_(prog_data_end);
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ public class Xoa_update_html extends Xow_special_wtr__base {
|
||||
Xopg_tag_wtr_.Add__xolog (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__gui__progbars (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xoajax (head_tags, app.Fsys_mgr().Http_root(), app);
|
||||
Xopg_tag_wtr_.Add__jquery (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xonotify (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_alertify_.Add_tags (head_tags, app.Fsys_mgr().Http_root());
|
||||
|
||||
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xoa_update.css")));
|
||||
|
@ -23,6 +23,7 @@ class Xoa_update_svc implements Gfo_invk {
|
||||
private Xoa_app app;
|
||||
private Io_url app_root_dir, update_dir, update_jar_fil, version_root;
|
||||
private Xoa_app_version_itm version_itm;
|
||||
private Xoa_update_db_mgr db_mgr;
|
||||
public Xoa_update_svc(Xoa_app app) {this.app = app;}
|
||||
private Xoa_update_db_mgr Init_db() {
|
||||
this.app_root_dir = app.Fsys_mgr().Root_dir();
|
||||
@ -32,7 +33,7 @@ class Xoa_update_svc implements Gfo_invk {
|
||||
}
|
||||
public void Install(String version_name) {
|
||||
// get app_version from db
|
||||
Xoa_update_db_mgr db_mgr = Init_db();
|
||||
this.db_mgr = Init_db();
|
||||
this.version_itm = db_mgr.Tbl__app_version().Select_by_name_or_null(version_name);
|
||||
|
||||
// get src, trg, etc..
|
||||
@ -45,7 +46,7 @@ class Xoa_update_svc implements Gfo_invk {
|
||||
// start download
|
||||
Xojs_wkr__download download_wkr = new Xojs_wkr__download
|
||||
( app.Gui__cbk_mgr(), Xog_cbk_trg.New(Xoa_update_special.Prototype.Special__meta().Ttl_bry())
|
||||
, "xo.app_updater.download__prog", Gfo_invk_cmd.New_by_key(this, Invk__download_done), src, trg, src_len);
|
||||
, "xo.app_updater.download__prog", Gfo_invk_cmd.New_by_key(this, Invk__download_done), Gfo_invk_cmd.New_by_key(this, Invk__download_fail), src, trg, src_len);
|
||||
download_wkr.Exec_async("app_updater");
|
||||
}
|
||||
public void Skip(String version_name) {
|
||||
@ -59,6 +60,12 @@ class Xoa_update_svc implements Gfo_invk {
|
||||
Xojs_wkr__unzip unzip_wkr = new Xojs_wkr__unzip(download_wkr.Cbk_mgr(), download_wkr.Cbk_trg(), "xo.app_updater.download__prog", Gfo_invk_cmd.New_by_key(this, Invk__unzip_done), src, trg, -1);
|
||||
unzip_wkr.Exec_async("app_updater");
|
||||
}
|
||||
private void On_download_fail(GfoMsg m) {
|
||||
// in case of bad urls or withdrawn patches, delete update_db and force redownload
|
||||
db_mgr.Conn().Rls_conn();
|
||||
Io_mgr.Instance.DeleteFil(db_mgr.Url());
|
||||
Xoa_update_db_mgr_.Download_from_inet(app, Bool_.N, db_mgr.Url());
|
||||
}
|
||||
private void On_unzip_done(GfoMsg m) {
|
||||
Xojs_wkr__unzip unzip_wkr = (Xojs_wkr__unzip)m.ReadObj("v");
|
||||
Io_url src = unzip_wkr.Trg();
|
||||
@ -106,11 +113,13 @@ class Xoa_update_svc implements Gfo_invk {
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk__download_done)) On_download_done(m);
|
||||
else if (ctx.Match(k, Invk__download_fail)) On_download_fail(m);
|
||||
else if (ctx.Match(k, Invk__unzip_done)) On_unzip_done(m);
|
||||
else if (ctx.Match(k, Invk__replace_done)) On_replace_done(m);
|
||||
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";
|
||||
}
|
||||
private static final String Invk__download_done = "download_done", Invk__download_fail = "download_fail", 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
|
||||
|
Loading…
Reference in New Issue
Block a user