diff --git a/400_xowa/src/gplx/xowa/addons/apps/updates/apps/Xoa_manifest_item.java b/400_xowa/src/gplx/xowa/addons/apps/updates/apps/Xoa_manifest_item.java new file mode 100644 index 000000000..af5922c28 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/apps/updates/apps/Xoa_manifest_item.java @@ -0,0 +1,26 @@ +/* +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 . +*/ +package gplx.xowa.addons.apps.updates.apps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.updates.*; +class Xoa_manifest_item { + public Xoa_manifest_item(Io_url src, Io_url trg) { + this.src = src; + this.trg = trg; + } + public Io_url Src() {return src;} private final Io_url src; + public Io_url Trg() {return trg;} private final Io_url trg; +} diff --git a/400_xowa/src/gplx/xowa/addons/apps/updates/apps/Xoa_manifest_list.java b/400_xowa/src/gplx/xowa/addons/apps/updates/apps/Xoa_manifest_list.java new file mode 100644 index 000000000..9847d5f33 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/apps/updates/apps/Xoa_manifest_list.java @@ -0,0 +1,61 @@ +/* +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 . +*/ +package gplx.xowa.addons.apps.updates.apps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.updates.*; +class Xoa_manifest_list { + private final Ordered_hash hash = Ordered_hash_.New(); + public int Len() {return hash.Len();} + public Xoa_manifest_item Get_at(int i) {return (Xoa_manifest_item)hash.Get_at(i);} + public void Del_at(int i) { + Xoa_manifest_item item = (Xoa_manifest_item)hash.Get_at(i); + hash.Del(item.Src().Raw()); + } + public void Add(Io_url src, Io_url trg) { + Xoa_manifest_item item = new Xoa_manifest_item(src, trg); + hash.Add(src.Raw(), item); + } + public void Save(Bry_bfr bfr) { + // save as "src\ttrg\n" + int len = hash.Len(); + for (int i = 0; i < len; i++) { + Xoa_manifest_item item = (Xoa_manifest_item)hash.Get_at(i); + bfr.Add_str_u8(item.Src().Raw()); + bfr.Add_byte(Byte_ascii.Tab); + bfr.Add_str_u8(item.Trg().Raw()); + bfr.Add_byte(Byte_ascii.Nl); + } + } + public void Load(byte[] src, int src_bgn, int src_end) { + int pos = src_bgn; + // load by "src\ttrg\n" + while (pos < src_end) { + // get pos + int tab_pos = Bry_find_.Find_fwd(src, Byte_ascii.Tab, pos, src_end); + if (tab_pos == Bry_find_.Not_found) throw Err_.new_wo_type("failed to find tab", "excerpt", Bry_.Mid(src, pos, src_end)); + int nl_pos = Bry_find_.Find_fwd(src, Byte_ascii.Nl, tab_pos + 1, src_end); + if (nl_pos == Bry_find_.Not_found) throw Err_.new_wo_type("failed to find nl", "excerpt", Bry_.Mid(src, pos, src_end)); + + // create + Io_url src_url = Io_url_.new_fil_(String_.new_u8(src, pos, tab_pos)); + Io_url trg_url = Io_url_.new_fil_(String_.new_u8(src, tab_pos + 1, nl_pos)); + Xoa_manifest_item item = new Xoa_manifest_item(src_url, trg_url); + hash.Add(src_url.Raw(), item); + + pos = nl_pos + 1; + } + } +} diff --git a/400_xowa/src/gplx/xowa/addons/apps/updates/apps/Xoa_manifest_view.java b/400_xowa/src/gplx/xowa/addons/apps/updates/apps/Xoa_manifest_view.java new file mode 100644 index 000000000..eac89ca9c --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/apps/updates/apps/Xoa_manifest_view.java @@ -0,0 +1,32 @@ +/* +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 . +*/ +package gplx.xowa.addons.apps.updates.apps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.updates.*; +public class Xoa_manifest_view { + private final Xoa_manifest_wkr wkr; + public Xoa_manifest_view(String manifest_url) { + this.wkr = new Xoa_manifest_wkr(this); + wkr.Init(manifest_url); + } + public void Append(String s) { + } + + public static void Run(String manifest_url) { + if (!gplx.core.envs.Op_sys.Cur().Tid_is_osx()) + new Xoa_manifest_view(manifest_url); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/apps/updates/apps/Xoa_manifest_wkr.java b/400_xowa/src/gplx/xowa/addons/apps/updates/apps/Xoa_manifest_wkr.java new file mode 100644 index 000000000..c565ba497 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/apps/updates/apps/Xoa_manifest_wkr.java @@ -0,0 +1,85 @@ +/* +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 . +*/ +package gplx.xowa.addons.apps.updates.apps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.updates.*; +class Xoa_manifest_wkr { + private final Xoa_manifest_view view; + private final Xoa_manifest_list list = new Xoa_manifest_list(); + private Io_url manifest_url; + private byte[] run_xowa_cmd; + public Xoa_manifest_wkr(Xoa_manifest_view view) { + this.view = view; + } + public void Init(String manifest_url_str) { + // load manifest + view.Append("loading manifest from: " + manifest_url_str); + this.manifest_url = Io_url_.new_any_(manifest_url_str); + byte[] src = Io_mgr.Instance.LoadFilBry(manifest_url); + + // parse manifest + int nl_pos = Bry_find_.Find_fwd(src, Byte_ascii.Nl); + if (nl_pos == Bry_find_.Not_found) throw Err_.new_wo_type("could not find nl in manifest", "manifest_url", manifest_url_str); + this.run_xowa_cmd = Bry_.Mid(src, 0, nl_pos); + list.Load(src, nl_pos + 1, src.length); + + this.Wait(); + } + private void Wait() { + int tries = 0; + while (tries++ < 100) { + gplx.core.threads.Thread_adp_.Sleep(1000); + if (Copy_files()) + break; + else { + String topmost = "#error"; + if (list.Len() > 0) { + Xoa_manifest_item item = (Xoa_manifest_item)list.Get_at(0); + topmost = item.Src().Raw(); + } + view.Append("waiting for XOWA to release file: " + topmost); + } + } + } + public void On_exit() { + Io_mgr.Instance.DeleteFil(manifest_url); + if (run_xowa_cmd != null) + // gplx.core.envs.Process_adp.run_wait_arg_; + gplx.core.envs.System_.Exit(); + } + private boolean Copy_files() { + // loop list and copy items + int len = list.Len(); + int idx = 0; + for (idx = 0; idx < len; idx++) { + Xoa_manifest_item item = (Xoa_manifest_item)list.Get_at(idx); + try { + Io_mgr.Instance.DeleteFil_args(item.Trg()).MissingFails_off().Exec(); + Io_mgr.Instance.CopyFil(item.Src(), item.Trg(), true); + } + catch (Exception exc) { + view.Append(String_.Format("failed to copy file: src={0} trg ={1} err={2}", item.Src().Raw(), item.Trg().Raw(), Err_.Message_lang(exc))); + return false; + } + } + + // remove completed items + for (int i = 0; i < idx; i++) { + list.Del_at(0); + } + return true; + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/Xofts_addon.java b/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/Xofts_addon.java new file mode 100644 index 000000000..2cede370c --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/Xofts_addon.java @@ -0,0 +1,29 @@ +/* +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 . +*/ +//namespace gplx.xowa.addons.wikis.fulltexts { +// using gplx.xowa.bldrs.wkrs; +// public class Xofts_addon : Xoax_addon_itm, Xoax_addon_itm__bldr { +// public Xob_cmd[] Bldr_cmds() { +// return new Xob_cmd[] +// { Xofts_make_cmd.Prototype +// }; +// } +// +// public String Addon__key() {return "xowa.wikis.fulltexts";} +// } +//} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/Xofts_make_cmd.java b/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/Xofts_make_cmd.java new file mode 100644 index 000000000..df8f80d9c --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/Xofts_make_cmd.java @@ -0,0 +1,31 @@ +/* +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 . +*/ +//namespace gplx.xowa.addons.wikis.fulltexts { +// using gplx.dbs; +// using gplx.xowa.bldrs; using gplx.xowa.bldrs.wkrs; using gplx.xowa.htmls.core.htmls; +// public class Xofts_make_cmd : Xob_cmd__base { +// public Xofts_make_cmd(Xob_bldr bldr, Xowe_wiki wiki) : super(bldr, wiki) {} +// public override void Cmd_run() { +// } +// +// public static final String BLDR_CMD_KEY = "fulltext.make"; +// public override String Cmd_key() {return BLDR_CMD_KEY;} +// public static final Xob_cmd Prototype = new Xofts_make_cmd(null, null); +// public override Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xofts_make_cmd(bldr, wiki);} +// } +//}