mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.5.1.1
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
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.threads; import gplx.*;
|
||||
public interface Gfo_thread_cmd extends GfoInvkAble {
|
||||
void Cmd_ctor();
|
||||
String Async_key();
|
||||
int Async_sleep_interval();
|
||||
boolean Async_prog_enabled();
|
||||
void Async_prog_run(int async_sleep_sum);
|
||||
byte Async_init();
|
||||
boolean Async_term();
|
||||
void Async_run();
|
||||
boolean Async_running();
|
||||
Gfo_thread_cmd Async_next_cmd(); void Async_next_cmd_(Gfo_thread_cmd next);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
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.threads; import gplx.*;
|
||||
public class Gfo_thread_cmd_ {
|
||||
public static final int Async_sleep_interval_1_second = 1000;
|
||||
public static final byte Init_ok = 0, Init_cancel_step = 1, Init_cancel_all = 2;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
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.threads; import gplx.*;
|
||||
import gplx.gfui.*;
|
||||
public class Gfo_thread_cmd_base implements Gfo_thread_cmd {
|
||||
@gplx.Virtual public String Async_key() {return "undefined";}
|
||||
public void Cmd_ctor() {}
|
||||
public Gfo_thread_cmd_base Ctor(Gfo_usr_dlg usr_dlg, Gfui_kit kit) {this.usr_dlg = usr_dlg; this.kit = kit; return this;} protected Gfo_usr_dlg usr_dlg; protected Gfui_kit kit;
|
||||
public GfoInvkAble Owner() {return owner;} public Gfo_thread_cmd_base Owner_(GfoInvkAble v) {owner = v; return this;} GfoInvkAble owner;
|
||||
public Bry_fmtr_eval_mgr Url_eval_mgr() {return url_eval_mgr;} public Gfo_thread_cmd_base Url_eval_mgr_(Bry_fmtr_eval_mgr v) {url_eval_mgr = v; return this;} Bry_fmtr_eval_mgr url_eval_mgr;
|
||||
public Gfo_thread_cmd Async_next_cmd() {return next_cmd;} public void Async_next_cmd_(Gfo_thread_cmd v) {next_cmd = v;} Gfo_thread_cmd next_cmd;
|
||||
@gplx.Virtual public int Async_sleep_interval() {return Gfo_thread_cmd_.Async_sleep_interval_1_second;}
|
||||
@gplx.Virtual public boolean Async_prog_enabled() {return false;}
|
||||
@gplx.Virtual public byte Async_init() {return Gfo_thread_cmd_.Init_ok;}
|
||||
@gplx.Virtual public boolean Async_term() {return true;}
|
||||
@gplx.Virtual public void Async_prog_run(int async_sleep_sum) {}
|
||||
@gplx.Virtual public void Async_bgn() {}
|
||||
@gplx.Virtual public boolean Async_running() {return false;}
|
||||
@gplx.Virtual public void Async_run() {}
|
||||
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) return owner;
|
||||
else if (ctx.Match(k, Invk_async_bgn)) Async_bgn();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_owner = "owner", Invk_async_bgn = "async_bgn";
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
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.threads; import gplx.*;
|
||||
import gplx.gfui.*;
|
||||
public class Gfo_thread_cmd_download implements Gfo_thread_cmd {
|
||||
public Gfo_thread_cmd Ctor(Gfo_usr_dlg usr_dlg, Gfui_kit kit) {this.usr_dlg = usr_dlg; this.kit = kit; xrg.Prog_dlg_(usr_dlg); return this;}
|
||||
public Gfo_thread_cmd_download Init(String prog_fmt_hdr, String src, Io_url trg) {
|
||||
this.src = src; this.trg = trg;
|
||||
xrg.Prog_fmt_hdr_(prog_fmt_hdr).Init(src, trg);
|
||||
return this;
|
||||
} String src; protected Gfui_kit kit; Gfo_usr_dlg usr_dlg; Io_url trg;
|
||||
public GfoInvkAble Owner() {return owner;} public Gfo_thread_cmd_download Owner_(GfoInvkAble v) {owner = v; return this;} GfoInvkAble owner;
|
||||
public Bry_fmtr_eval_mgr Url_eval_mgr() {return url_eval_mgr;} public Gfo_thread_cmd_download Url_eval_mgr_(Bry_fmtr_eval_mgr v) {url_eval_mgr = v; return this;} Bry_fmtr_eval_mgr url_eval_mgr;
|
||||
public void Cmd_ctor() {}
|
||||
public Gfo_thread_cmd Async_next_cmd() {return next_cmd;} public void Async_next_cmd_(Gfo_thread_cmd v) {next_cmd = v;} Gfo_thread_cmd next_cmd;
|
||||
@gplx.Virtual public String Async_key() {return KEY;}
|
||||
public int Async_sleep_interval() {return Gfo_thread_cmd_.Async_sleep_interval_1_second;}
|
||||
public boolean Async_prog_enabled() {return false;}
|
||||
@gplx.Virtual public byte Async_init() {
|
||||
if (Io_mgr._.ExistsFil(trg)) {
|
||||
int rslt = kit.Ask_yes_no_cancel(GRP_KEY, "target_exists", "Target file already exists: '~{0}'.\nDo you want to delete it?", trg.Raw());
|
||||
switch (rslt) {
|
||||
case Gfui_dlg_msg_.Btn_yes: Io_mgr._.DeleteFil(trg); break;
|
||||
case Gfui_dlg_msg_.Btn_no: return Gfo_thread_cmd_.Init_cancel_step;
|
||||
case Gfui_dlg_msg_.Btn_cancel: return Gfo_thread_cmd_.Init_cancel_all;
|
||||
default: throw Err_mgr._.unhandled_(rslt);
|
||||
}
|
||||
}
|
||||
usr_dlg.Prog_many(GRP_KEY, "download.bgn", "contacting web server: '~{0}'", src); // update progress; some servers (like WMF dump servers) are slow to respond
|
||||
return Gfo_thread_cmd_.Init_ok;
|
||||
}
|
||||
public boolean Async_term() {
|
||||
usr_dlg.Prog_many(GRP_KEY, "clear", "");
|
||||
return download_pass;
|
||||
}
|
||||
public void Async_prog_run(int async_sleep_sum) {}
|
||||
public boolean Async_running() {return xrg.Prog_running();}
|
||||
public void Async_run() {ThreadAdp_.invk_(gplx.xowa.apps.Xoa_thread_.Key_bldr_download, this, Invk_async_bgn).Start();}
|
||||
private void Download() {
|
||||
download_pass = true;
|
||||
if (!xrg.Exec()) {
|
||||
xrg.Prog_running_(false);
|
||||
download_pass = false;
|
||||
kit.Ask_ok(GRP_KEY, "download.fail", "download failed. Please select 'read from file' if you've already downloaded a dump: url=~{0} error=~{1}", src, xrg.Rslt_err_str());
|
||||
}
|
||||
} boolean download_pass = true;
|
||||
protected gplx.ios.IoEngine_xrg_downloadFil xrg = Io_mgr._.DownloadFil_args("", Io_url_.Null);
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_async_bgn)) Download();
|
||||
else if (ctx.Match(k, Invk_owner)) return owner;
|
||||
else if (ctx.Match(k, Invk_src_)) src = m.ReadStr("v");
|
||||
else if (ctx.Match(k, Invk_trg_)) trg = Bry_fmtr_eval_mgr_.Eval_url(url_eval_mgr, m.ReadBry("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_async_bgn = "async_bgn", Invk_owner = "owner", Invk_src_ = "src_", Invk_trg_ = "trg_";
|
||||
static final String GRP_KEY = "gfo.thread.file.download";
|
||||
public static final String KEY = "file.download";
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
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.threads; import gplx.*;
|
||||
import gplx.gfui.*;
|
||||
public class Gfo_thread_cmd_replace implements Gfo_thread_cmd {
|
||||
public Gfo_thread_cmd Init(Gfo_usr_dlg usr_dlg, Gfui_kit kit, Io_url fil) {
|
||||
this.usr_dlg = usr_dlg; this.kit = kit; this.fil = fil;
|
||||
return this;
|
||||
} Gfui_kit kit; Gfo_usr_dlg usr_dlg; Io_url fil;
|
||||
public GfoInvkAble Owner() {return owner;} public Gfo_thread_cmd_replace Owner_(GfoInvkAble v) {owner = v; return this;} GfoInvkAble owner;
|
||||
public Bry_fmtr_eval_mgr Url_eval_mgr() {return url_eval_mgr;} public Gfo_thread_cmd_replace Url_eval_mgr_(Bry_fmtr_eval_mgr v) {url_eval_mgr = v; return this;} Bry_fmtr_eval_mgr url_eval_mgr;
|
||||
public String Async_key() {return KEY;}
|
||||
public void Cmd_ctor() {}
|
||||
public Gfo_thread_cmd Async_next_cmd() {return next_cmd;} public void Async_next_cmd_(Gfo_thread_cmd v) {next_cmd = v;} Gfo_thread_cmd next_cmd;
|
||||
public int Async_sleep_interval() {return Gfo_thread_cmd_.Async_sleep_interval_1_second;}
|
||||
public boolean Async_prog_enabled() {return false;}
|
||||
@gplx.Virtual public byte Async_init() {
|
||||
if (!Io_mgr._.ExistsFil(fil)) {kit.Ask_ok(GRP_KEY, "file_missing", "File does not exist: '~{0}'", fil.Raw()); return Gfo_thread_cmd_.Init_cancel_step;}
|
||||
return Gfo_thread_cmd_.Init_ok;
|
||||
}
|
||||
public boolean Async_term() {return true;}
|
||||
public void Async_prog_run(int async_sleep_sum) {}
|
||||
public boolean Async_running() {return false;}
|
||||
@gplx.Virtual public void Async_run() {Exec_find_replace();} // NOTE: do not run async; if multiple commands for same file then they will not always work
|
||||
public void Exec_find_replace() {
|
||||
String raw = Io_mgr._.LoadFilStr(fil);
|
||||
int pairs_len = pairs.Count();
|
||||
for (int i = 0; i < pairs_len; i++) {
|
||||
KeyVal kv = (KeyVal)pairs.FetchAt(i);
|
||||
raw = String_.Replace(raw, kv.Key(), kv.Val_to_str_or_null());
|
||||
}
|
||||
Io_mgr._.SaveFilStr(fil, raw);
|
||||
usr_dlg.Prog_many(GRP_KEY, "done", "replace completed: ~{0} ~{1}", fil.Raw(), pairs_len);
|
||||
}
|
||||
public ListAdp pairs = ListAdp_.new_();
|
||||
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_async_bgn)) Exec_find_replace();
|
||||
else if (ctx.Match(k, Invk_owner)) return owner;
|
||||
else if (ctx.Match(k, Invk_fil_)) fil = Bry_fmtr_eval_mgr_.Eval_url(url_eval_mgr, m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_add)) pairs.Add(KeyVal_.new_(m.ReadStr("find"), m.ReadStr("replace")));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_async_bgn = "async_bgn", Invk_owner = "owner", Invk_fil_ = "fil_", Invk_add = "add";
|
||||
static final String GRP_KEY = "gfo.thread.file.download";
|
||||
public static final String KEY = "text.replace";
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
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.threads; import gplx.*;
|
||||
import gplx.gfui.*; import gplx.xowa.bldrs.cmds.utils.*;
|
||||
public class Gfo_thread_cmd_unzip implements Gfo_thread_cmd {
|
||||
public Gfo_thread_cmd_unzip Init(Gfo_usr_dlg usr_dlg, Gfui_kit kit, ProcessAdp bzip2_process, ProcessAdp zip_process, ProcessAdp gz_process, Io_url src, Io_url trg) {
|
||||
this.src = src; this.trg = trg; this.kit = kit; this.usr_dlg = usr_dlg;
|
||||
unzip_wkr = new Xob_unzip_wkr().Init(bzip2_process, zip_process, gz_process).Process_run_mode_(ProcessAdp.Run_mode_async);
|
||||
return this;
|
||||
} private Io_url src, trg; private Gfui_kit kit; private Gfo_usr_dlg usr_dlg; private Xob_unzip_wkr unzip_wkr;
|
||||
public GfoInvkAble Owner() {return owner;} public Gfo_thread_cmd_unzip Owner_(GfoInvkAble v) {owner = v; return this;} GfoInvkAble owner;
|
||||
public void Cmd_ctor() {}
|
||||
@gplx.Virtual public String Async_key() {return KEY;}
|
||||
public Gfo_thread_cmd Async_next_cmd() {return next_cmd;} public void Async_next_cmd_(Gfo_thread_cmd v) {next_cmd = v;} Gfo_thread_cmd next_cmd;
|
||||
public Bry_fmtr_eval_mgr Url_eval_mgr() {return url_eval_mgr;} public Gfo_thread_cmd_unzip Url_eval_mgr_(Bry_fmtr_eval_mgr v) {url_eval_mgr = v; return this;} Bry_fmtr_eval_mgr url_eval_mgr;
|
||||
public int Async_sleep_interval() {return Gfo_thread_cmd_.Async_sleep_interval_1_second;}
|
||||
public boolean Async_prog_enabled() {return true;}
|
||||
public void Async_prog_run(int async_sleep_sum) {
|
||||
String size_str = " please wait...";
|
||||
if (trg.Type_fil()) size_str = gplx.ios.Io_size_.Xto_str(Io_mgr._.QueryFil(trg).Size());
|
||||
usr_dlg.Prog_many(GRP_KEY, "unzip", "unzipping: ~{0}", size_str);
|
||||
}
|
||||
@gplx.Virtual public byte Async_init() {
|
||||
if (!Io_mgr._.ExistsFil(src)) {
|
||||
kit.Ask_ok(GRP_KEY, "source_missing", "Source file does not exist: '~{0}'", src.Raw());
|
||||
return Gfo_thread_cmd_.Init_cancel_step;
|
||||
}
|
||||
trg_is_dir = trg.Type_dir();
|
||||
if (delete_trg_if_exists
|
||||
&& (( trg_is_dir && Io_mgr._.ExistsDir(trg))
|
||||
|| (!trg_is_dir && Io_mgr._.ExistsFil(trg)))
|
||||
) {
|
||||
int rslt = kit.Ask_yes_no_cancel(GRP_KEY, "target_exists", "Target file already exists: '~{0}'.\nDo you want to delete it?", trg.Raw());
|
||||
switch (rslt) {
|
||||
case Gfui_dlg_msg_.Btn_yes: if (trg_is_dir) Io_mgr._.DeleteDirDeep(trg); else Io_mgr._.DeleteFil(trg); break;
|
||||
case Gfui_dlg_msg_.Btn_no: return Gfo_thread_cmd_.Init_cancel_step;
|
||||
case Gfui_dlg_msg_.Btn_cancel: return Gfo_thread_cmd_.Init_cancel_all;
|
||||
}
|
||||
}
|
||||
return Gfo_thread_cmd_.Init_ok;
|
||||
}
|
||||
public boolean Async_running() {return unzip_wkr.Process_exit_code() == ProcessAdp.Exit_init;}
|
||||
public void Async_run() {
|
||||
usr_dlg.Prog_many(GRP_KEY, "bgn", "unzipping");
|
||||
unzip_wkr.Decompress(src, trg);
|
||||
}
|
||||
public boolean Async_term() {
|
||||
if (rename_dir) {
|
||||
Io_url[] dirs = Io_mgr._.QueryDir_args(trg.OwnerDir()).DirOnly_().Recur_(false).ExecAsUrlAry();
|
||||
int dirs_len = dirs.length;
|
||||
Io_url zip_dir = Io_url_.Null;
|
||||
for (int i = 0; i < dirs_len; i++) {
|
||||
Io_url dir = dirs[i];
|
||||
if (String_.HasAtBgn(String_.Lower(dir.NameOnly()), String_.Lower(trg.NameOnly()))) { // HACK: check that directory starts with archive name; DATE:2013-12-22
|
||||
zip_dir = dir;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (zip_dir == Io_url_.Null) {
|
||||
kit.Ask_ok(GRP_KEY, "rename.fail", "unable to find directory: trg=~{0}", trg.Raw());
|
||||
return false;
|
||||
}
|
||||
if (!String_.Eq(String_.Lower(zip_dir.Raw()), String_.Lower(trg.Raw()))) // HACK: inkscape is itself
|
||||
Io_mgr._.MoveDirDeep(zip_dir, trg);
|
||||
}
|
||||
switch (term_cmd_for_src) {
|
||||
case Term_cmd_for_src_noop: break;
|
||||
case Term_cmd_for_src_delete: Io_mgr._.DeleteFil(src); break;
|
||||
case Term_cmd_for_src_move:
|
||||
if (term_cmd_for_src_url == Io_url_.Null) throw Err_mgr._.fmt_(GRP_KEY, "url_missing", "move specified, but no url");
|
||||
Io_mgr._.MoveFil_args(src, term_cmd_for_src_url, true).Exec();
|
||||
break;
|
||||
default: throw Err_mgr._.unhandled_(term_cmd_for_src);
|
||||
}
|
||||
usr_dlg.Prog_many(GRP_KEY, "done", "");
|
||||
return true;
|
||||
}
|
||||
public static final byte Term_cmd_for_src_noop = 0, Term_cmd_for_src_delete = 1, Term_cmd_for_src_move = 2;
|
||||
boolean rename_dir = false, trg_is_dir = false, delete_trg_if_exists = true;
|
||||
public byte Term_cmd_for_src() {return term_cmd_for_src;} public void Term_cmd_for_src_(byte v) {term_cmd_for_src = v;} private byte term_cmd_for_src = Term_cmd_for_src_delete;
|
||||
public Io_url Term_cmd_for_src_url() {return term_cmd_for_src_url;} public void Term_cmd_for_src_url_(Io_url v) {this.term_cmd_for_src_url = v;} Io_url term_cmd_for_src_url = Io_url_.Null;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) return owner;
|
||||
else if (ctx.Match(k, Invk_src_)) src = Bry_fmtr_eval_mgr_.Eval_url(url_eval_mgr, m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_trg_)) trg = Bry_fmtr_eval_mgr_.Eval_url(url_eval_mgr, m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_rename_dir_)) rename_dir = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_delete_trg_if_exists_)) delete_trg_if_exists = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_term_cmd_for_src_)) term_cmd_for_src = Term_cmd_for_src_parse_(m.ReadStr("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_owner = "owner", Invk_src_ = "src_", Invk_trg_ = "trg_", Invk_rename_dir_ = "rename_dir_", Invk_delete_trg_if_exists_ = "delete_trg_if_exists_", Invk_term_cmd_for_src_ = "term_cmd_for_src_";
|
||||
private static byte Term_cmd_for_src_parse_(String s) {
|
||||
if (String_.Eq(s, "noop")) return Term_cmd_for_src_noop;
|
||||
else if (String_.Eq(s, "delete")) return Term_cmd_for_src_delete;
|
||||
else if (String_.Eq(s, "move")) return Term_cmd_for_src_move;
|
||||
else throw Err_mgr._.unhandled_(s);
|
||||
}
|
||||
static final String GRP_KEY = "xowa.thread.file.unzip";
|
||||
public static final String KEY = "file.unzip";
|
||||
}
|
||||
@@ -40,23 +40,24 @@ public class Xoa_css_extractor {
|
||||
failover_dir = app.Fsys_mgr().Bin_any_dir().GenSubDir_nest("html", "xowa", "import");
|
||||
url_encoder = Xoa_app_.Utl__encoder_mgr().Url();
|
||||
}
|
||||
public void Install_assert(boolean download_from_css_tbl, Xowe_wiki wiki, Io_url wiki_html_dir) {
|
||||
public void Install(Xow_wiki wiki, String css_key) {
|
||||
try {
|
||||
Io_url css_common_url = wiki_html_dir.GenSubFil(Css_common_name);
|
||||
Io_url css_wiki_url = wiki_html_dir.GenSubFil(Css_wiki_name);
|
||||
Xoh_page_wtr_mgr wiki_article = wiki.Html_mgr().Page_wtr_mgr();
|
||||
wiki_article.Css_common_bry_(css_common_url).Css_wiki_bry_(css_wiki_url);
|
||||
this.wiki_html_dir = wiki.App().Fsys_mgr().Wiki_css_dir(wiki.Domain_str()); // EX: /xowa/user/anonymous/wiki/en.wikipedia.org
|
||||
Io_url css_comm_fil = wiki_html_dir.GenSubFil(Css_common_name);
|
||||
Io_url css_wiki_fil = wiki_html_dir.GenSubFil(Css_wiki_name);
|
||||
wiki.Html__page_wtr_mgr().Init_css_urls(css_comm_fil, css_wiki_fil);
|
||||
if (wiki.Domain_tid() == Xow_domain_.Tid_int_home || Env_.Mode_testing()) return; // NOTE: do not download if home_wiki; also needed for TEST
|
||||
if (Io_mgr._.ExistsFil(css_wiki_url)) return; // css file exists; nothing to generate
|
||||
wiki.Appe().Usr_dlg().Log_many("", "", "generating css for '~{0}'", wiki.Domain_str());
|
||||
if (download_from_css_tbl) {
|
||||
if (Install_by_db(wiki, wiki_html_dir)) return;
|
||||
if (Io_mgr._.ExistsFil(css_wiki_fil)) return; // css file exists; nothing to generate
|
||||
wiki.App().Usr_dlg().Log_many("", "", "generating css for '~{0}'", wiki.Domain_str());
|
||||
if (css_key != null) {
|
||||
if (Install_by_db(wiki, wiki_html_dir, css_key)) return;
|
||||
}
|
||||
this.Install_by_wmf(wiki, wiki_html_dir);
|
||||
if (wiki.Type_is_edit())
|
||||
this.Install_by_wmf((Xowe_wiki)wiki, wiki_html_dir);
|
||||
}
|
||||
catch (Exception e) { // if error, failover; paranoia catch for outliers like bad network connectivity fail, or MediaWiki: message not existing; DATE:2013-11-21
|
||||
wiki.Appe().Usr_dlg().Warn_many("", "", "failed while trying to generate css; failing over; wiki='~{0}' err=~{1}", wiki.Domain_str(), Err_.Message_gplx(e));
|
||||
Css_common_failover(); // only failover xowa_common.css; xowa_wiki.css comes from MediaWiki:Common.css / Vector.css
|
||||
wiki.App().Usr_dlg().Warn_many("", "", "failed while trying to generate css; failing over; wiki='~{0}' err=~{1}", wiki.Domain_str(), Err_.Message_gplx(e));
|
||||
Css_common_failover(); // only failover xowa_common.css; xowa_wiki.css comes from MediaWiki:Common.css / Vector.css
|
||||
}
|
||||
}
|
||||
private void Install_by_wmf(Xowe_wiki wiki, Io_url wiki_html_dir) {
|
||||
@@ -74,7 +75,7 @@ public class Xoa_css_extractor {
|
||||
Css_wiki_setup();
|
||||
Logo_setup();
|
||||
}
|
||||
private boolean Install_by_db(Xowe_wiki wiki, Io_url wiki_html_dir) {
|
||||
private boolean Install_by_db(Xow_wiki wiki, Io_url wiki_html_dir, String css_key) {
|
||||
Xowd_db_mgr core_db_mgr = wiki.Data_mgr__core_mgr();
|
||||
if ( core_db_mgr == null
|
||||
|| core_db_mgr.Props() == null
|
||||
@@ -82,7 +83,7 @@ public class Xoa_css_extractor {
|
||||
|| !core_db_mgr.Tbl__cfg().Select_yn_or(Xow_cfg_consts.Grp__wiki_schema, Xowd_db_file_schema_props.Key__tbl_css_core, Bool_.N)
|
||||
) return false;
|
||||
Xowd_db_file core_db = core_db_mgr.Db__core();
|
||||
gplx.xowa.html.css.Xowd_css_core_mgr.Get(core_db.Tbl__css_core(), core_db.Tbl__css_file(), wiki_html_dir);
|
||||
gplx.xowa.html.css.Xowd_css_core_mgr.Get(core_db.Tbl__css_core(), core_db.Tbl__css_file(), wiki_html_dir, css_key);
|
||||
return true;
|
||||
}
|
||||
public void Css_common_setup() {
|
||||
|
||||
@@ -16,7 +16,7 @@ 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; import gplx.*;
|
||||
import gplx.threads.*; import gplx.xowa.wikis.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.threads.*; import gplx.xowa.wikis.*; import gplx.xowa.bldrs.*;
|
||||
abstract class Xoi_cmd_base implements Gfo_thread_cmd {
|
||||
public void Ctor(Xoi_setup_mgr install_mgr, String wiki_key) {
|
||||
this.install_mgr = install_mgr; this.wiki_key = wiki_key;
|
||||
@@ -37,7 +37,7 @@ abstract class Xoi_cmd_base implements Gfo_thread_cmd {
|
||||
public void Async_run() {
|
||||
running = true;
|
||||
// install_mgr.App().Gui_wtr().Log_many(GRP_KEY, "import.bgn", "import.bgn ~{0} ~{1} ~{2}", wiki_key, wiki_date, dump_type);
|
||||
ThreadAdp_.invk_(this.Async_key(), this, Invk_process_async).Start();
|
||||
Thread_adp_.invk_(this.Async_key(), this, Invk_process_async).Start();
|
||||
}
|
||||
public boolean Async_running() {return running;} private boolean running;
|
||||
public void Process_async() {
|
||||
|
||||
@@ -16,7 +16,7 @@ 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; import gplx.*;
|
||||
import gplx.threads.*;
|
||||
import gplx.core.threads.*;
|
||||
class Xoi_cmd_dumpfile {
|
||||
public byte[] Domain() {return domain;} private byte[] domain;
|
||||
public Io_url Bz2_url() {return bz2_url;} Io_url bz2_url;
|
||||
|
||||
@@ -16,7 +16,7 @@ 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; import gplx.*;
|
||||
import gplx.threads.*;
|
||||
import gplx.core.threads.*;
|
||||
public class Xoi_cmd_mgr implements GfoInvkAble {
|
||||
ListAdp cmds = ListAdp_.new_();
|
||||
public Xoi_cmd_mgr(Xoi_setup_mgr install_mgr) {this.app = install_mgr.App(); this.install_mgr = install_mgr;} private Xoae_app app; Xoi_setup_mgr install_mgr;
|
||||
@@ -33,7 +33,7 @@ public class Xoi_cmd_mgr implements GfoInvkAble {
|
||||
while (cmd.Async_running()) {
|
||||
if (canceled) {working = false; return;}
|
||||
if (async_prog_enabled) cmd.Async_prog_run(async_sleep_sum);
|
||||
ThreadAdp_.Sleep(async_sleep_interval);
|
||||
Thread_adp_.Sleep(async_sleep_interval);
|
||||
async_sleep_sum += async_sleep_interval; // NOTE: this is not exact
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class Xoi_cmd_mgr implements GfoInvkAble {
|
||||
else
|
||||
working = false;
|
||||
}
|
||||
private void Run_async(Gfo_thread_cmd cmd) {ThreadAdp_.invk_msg_(cmd.Async_key(), this, GfoMsg_.new_cast_(Invk_process_async).Add("v", cmd)).Start();}
|
||||
private void Run_async(Gfo_thread_cmd cmd) {Thread_adp_.invk_msg_(cmd.Async_key(), this, GfoMsg_.new_cast_(Invk_process_async).Add("v", cmd)).Start();}
|
||||
private void Cmds_run() {
|
||||
if (working) {
|
||||
app.Gui_mgr().Kit().Ask_ok("", "", "An import is in progress. Please wait for it to complete. If you want to do multiple imports at once, see Help:Import/Script.");
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.gfui.*;
|
||||
import gplx.threads.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.utils.*;
|
||||
import gplx.core.threads.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.utils.*;
|
||||
class Xoi_cmd_wiki_download extends Gfo_thread_cmd_download implements Gfo_thread_cmd { private Xoi_setup_mgr install_mgr; private String wiki_key, dump_date, dump_type;
|
||||
public Xoi_cmd_wiki_download Ctor_download_(Xoi_setup_mgr install_mgr, String wiki_key, String dump_date, String dump_type) {
|
||||
this.install_mgr = install_mgr;
|
||||
@@ -168,7 +168,7 @@ class Xoi_cmd_wiki_zip implements Gfo_thread_cmd {
|
||||
public void Async_run() {
|
||||
running = true;
|
||||
install_mgr.App().Usr_dlg().Log_many(GRP_KEY, "zip.bgn", "zip.bgn ~{0}", wiki_key);
|
||||
ThreadAdp_.invk_(this.Async_key(), this, Invk_process_async).Start();
|
||||
Thread_adp_.invk_(this.Async_key(), this, Invk_process_async).Start();
|
||||
}
|
||||
public boolean Async_running() {
|
||||
return running;
|
||||
|
||||
@@ -16,7 +16,7 @@ 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; import gplx.*;
|
||||
import gplx.threads.*; import gplx.xowa.bldrs.*; import gplx.xowa.gui.views.*; import gplx.xowa.bldrs.cmds.utils.*;
|
||||
import gplx.core.threads.*; import gplx.xowa.bldrs.*; import gplx.xowa.gui.views.*; import gplx.xowa.bldrs.cmds.utils.*;
|
||||
class Xoi_cmd_wiki_import implements Gfo_thread_cmd {
|
||||
public Xoi_cmd_wiki_import(Xoi_setup_mgr install_mgr, String wiki_key, String wiki_date, String dump_type) {this.install_mgr = install_mgr; this.Owner_(install_mgr); this.wiki_key = wiki_key; this.wiki_date = wiki_date; this.dump_type = dump_type;} private Xoi_setup_mgr install_mgr; String wiki_key, wiki_date, dump_type;
|
||||
public static final String KEY = "wiki.import";
|
||||
@@ -35,7 +35,7 @@ class Xoi_cmd_wiki_import implements Gfo_thread_cmd {
|
||||
public void Async_run() {
|
||||
running = true;
|
||||
install_mgr.App().Usr_dlg().Log_many(GRP_KEY, "import.bgn", "import.bgn ~{0} ~{1} ~{2}", wiki_key, wiki_date, dump_type);
|
||||
ThreadAdp_.invk_(this.Async_key(), this, Invk_process_async).Start();
|
||||
Thread_adp_.invk_(this.Async_key(), this, Invk_process_async).Start();
|
||||
}
|
||||
public boolean Async_running() {
|
||||
return running;
|
||||
|
||||
@@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import org.junit.*;
|
||||
import gplx.brys.*; import gplx.threads.*; import gplx.xowa.wikis.*; import gplx.xowa.setup.maints.*; import gplx.xowa.xtns.wdatas.imports.*;
|
||||
import gplx.brys.*; import gplx.core.threads.*; import gplx.xowa.wikis.*; import gplx.xowa.setup.maints.*; import gplx.xowa.xtns.wdatas.imports.*;
|
||||
public class Xoi_cmd_wiki_tst {
|
||||
@Test public void Run() { // MAINT
|
||||
@Test public void Run() { // MAIN
|
||||
// Bld_import_list(Xow_wmf_api_mgr.Wikis);
|
||||
// Bld_cfg_files(Xow_wmf_api_mgr.Wikis); // NOTE: remember to carry over the wikisource / page / index commands from the existing xowa_build_cfg.gfs; also, only run the xowa_build_cfg.gfs once; DATE:2013-10-15; last run: DATE:2014-09-09
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public class Xoi_cmd_wiki_tst {
|
||||
dump_file.Server_url_(Xob_dump_file_.Server_wmf);
|
||||
if (dump_file.Connect()) break;
|
||||
Tfds.WriteText(String_.Format("retrying: {0} {1}\n", count, dump_file.File_modified()));
|
||||
ThreadAdp_.Sleep(15000); // wait for connection to reset
|
||||
Thread_adp_.Sleep(15000); // wait for connection to reset
|
||||
}
|
||||
if (count == 10) {
|
||||
Tfds.WriteText(String_.Format("failed: {0}\n", dump_file.File_url()));
|
||||
@@ -101,7 +101,7 @@ public class Xoi_cmd_wiki_tst {
|
||||
// bfr.Add_byte_pipe();
|
||||
bfr.Add_str(dump_file.Dump_date());
|
||||
bfr.Add_byte_nl();
|
||||
ThreadAdp_.Sleep(1000);
|
||||
Thread_adp_.Sleep(1000);
|
||||
}
|
||||
*/
|
||||
public void Bld_cfg_files(String... ary) {
|
||||
|
||||
Reference in New Issue
Block a user