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

'v3.9.2.1'

This commit is contained in:
gnosygnu
2016-09-11 21:49:20 -04:00
parent 232838c732
commit 35d78f6106
310 changed files with 4358 additions and 5116 deletions

View File

@@ -33,6 +33,7 @@ public abstract class Xobc_cmd__base implements Xobc_cmd_itm {
public long Prog_data_cur() {return data_cur;} private long data_cur; public void Prog_data_cur_(long v) {this.data_cur = v;}
public long Prog_data_end() {return data_end;} private long data_end; public void Prog_data_end_(long v) {this.data_end = v;}
public byte Prog_status() {return status;} private byte status = Gfo_prog_ui_.Status__init; public void Prog_status_(byte v) {status = v;}
public void Prog_notify_by_msg(String msg) {task_mgr.Work_mgr().On_stat(task_id, msg);}
public boolean Canceled() {return status == Gfo_prog_ui_.Status__suspended;}
public void Cancel() {status = Gfo_prog_ui_.Status__suspended;}
@@ -64,7 +65,7 @@ public abstract class Xobc_cmd__base implements Xobc_cmd_itm {
Gfo_log_.Instance.Info("xobc_cmd task end", "task_id", task_id, "step_id", step_id, "cmd_id", cmd_id);
switch (status) {
case Gfo_prog_ui_.Status__suspended: task_mgr.Work_mgr().On_suspended(this); break;
case Gfo_prog_ui_.Status__fail: task_mgr.Work_mgr().On_fail(this, Bool_.N, cmd_exec_err); break;
case Gfo_prog_ui_.Status__fail: task_mgr.Work_mgr().On_fail(this, this.Cmd_fail_resumes(), cmd_exec_err); break;
case Gfo_prog_ui_.Status__working:
this.Prog_notify_and_chk_if_suspended(data_end, data_end); // fire one more time for 100%; note that 100% may not fire due to timer logic below
task_mgr.Work_mgr().On_done(this);

View File

@@ -18,10 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.progs.*; import gplx.core.net.downloads.*;
public class Xobc_cmd__download extends Xobc_cmd__base {
private final Xobc_task_mgr task_mgr;
private final String src_url; private final Io_url trg_url;
private final long expd_size;
private final Http_download_wkr wkr;
public Xobc_cmd__download(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_id, String src_url, Io_url trg_url, long file_size_zip) {super(task_mgr, task_id, step_id, cmd_id);
this.task_mgr = task_mgr;
this.src_url = src_url; this.trg_url = trg_url; this.expd_size = file_size_zip;
this.wkr = Http_download_wkr_.Proto.Make_new();
this.Prog_data_end_(expd_size);
@@ -31,8 +33,31 @@ public class Xobc_cmd__download extends Xobc_cmd__base {
@Override public boolean Cmd_suspendable() {return true;}
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
if (wkr.Exec(this, src_url, trg_url, expd_size) == Gfo_prog_ui_.Status__fail)
this.Cmd_exec_err_(wkr.Fail_msg());
int error_wait = 10000, error_tries_max = 6, error_tries_cur = 0; // retry every 10 seconds for a total of 6 tries (1 min)
while (true) {
long trg_size_bgn = Io_mgr.Instance.QueryFil(wkr.Tmp_url()).Size();
byte status = wkr.Exec(this, src_url, trg_url, expd_size);
if (status == Gfo_prog_ui_.Status__fail) {
// check if anything more downloaded; if so, then reset to 0; DATE:2016-09-03
long trg_size_cur = Io_mgr.Instance.QueryFil(wkr.Tmp_url()).Size();
if (trg_size_cur > trg_size_bgn) {
error_tries_cur = 0;
trg_size_bgn = trg_size_cur;
}
// retry
if (error_tries_cur++ < error_tries_max) {
task_mgr.Work_mgr().On_stat(this.Task_id(), String_.Format("connection interrupted: retrying in {0} seconds; attempt {1} of {2}", error_wait / 1000, error_tries_cur, error_tries_max));
Gfo_usr_dlg_.Instance.Log_many("", "", "xobc_cmd task download interrupted; ~{0} ~{1} ~{2} ~{3}", this.Task_id(), this.Step_id(), trg_url, Io_mgr.Instance.QueryFil(trg_url).Size());
gplx.core.threads.Thread_adp_.Sleep(error_wait);
continue;
}
this.Cmd_exec_err_(wkr.Fail_msg());
break;
}
else
break;
}
Gfo_log_.Instance.Info("xobc_cmd task download", "task_id", this.Task_id(), "step_id", this.Step_id(), "trg_url", trg_url, "trg_len", Io_mgr.Instance.QueryFil(trg_url).Size());
}
@Override public void Cmd_cleanup() {

View File

@@ -137,4 +137,7 @@ public class Xobc_task_regy__work extends Xobc_task_regy__base {
Xod_power_mgr_.Instance.Wake_lock__rls("task_mgr");
task_mgr.Send_json("xo.bldr.work.prog__fail__recv", Gfobj_nde.New().Add_int("task_id", task.Task_id()).Add_str("err", msg).Add_bool("resume", resume));
}
public void On_stat(int task_id, String msg) {
task_mgr.Send_json("xo.bldr.work.prog__stat__recv", Gfobj_nde.New().Add_int("task_id", task_id).Add_str("msg", msg));
}
}