mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.5.2.1
This commit is contained in:
@@ -91,14 +91,14 @@ public class App_cmd_mgr_tst {
|
||||
}
|
||||
}
|
||||
class App_cmd_mgr_fxt {
|
||||
public Gfo_usr_dlg Usr_dlg() {return dlg_mgr;} Gfo_usr_dlg dlg_mgr;
|
||||
public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} Gfo_usr_dlg usr_dlg;
|
||||
public App_cmd_mgr Mgr() {return mgr;} App_cmd_mgr mgr = new App_cmd_mgr(); Tst_mgr tst_mgr = new Tst_mgr();
|
||||
public App_cmd_mgr_fxt Clear() {
|
||||
if (dlg_mgr == null) {
|
||||
dlg_mgr = Gfo_usr_dlg_base.test_();
|
||||
if (usr_dlg == null) {
|
||||
usr_dlg = Gfo_usr_dlg_.Test();
|
||||
}
|
||||
mgr.Clear();
|
||||
dlg_mgr.Clear();
|
||||
usr_dlg.Gui_wkr().Clear();
|
||||
return this;
|
||||
}
|
||||
public App_cmd_arg arg_(String key) {return arg_(key, false);}
|
||||
@@ -124,7 +124,7 @@ class App_cmd_mgr_fxt {
|
||||
return this;
|
||||
}
|
||||
public App_cmd_mgr_fxt tst_write(String... expd) {
|
||||
String[] actl = ((Gfo_usr_dlg_ui_test)dlg_mgr.Ui_wkr()).Xto_str_ary();
|
||||
String[] actl = ((Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr()).Xto_str_ary();
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,121 +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;
|
||||
import gplx.core.strings.*;
|
||||
public class Gfo_log_wtr_base implements Gfo_log_wtr {
|
||||
public boolean Queue_enabled() {return queue_enabled;} public void Queue_enabled_(boolean v) {queue_enabled = v; if (!v) this.Flush();} private boolean queue_enabled;
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
|
||||
public Io_url Session_dir() {return session_dir;} private Io_url session_dir;
|
||||
public Io_url Session_fil() {return session_fil;} private Io_url session_fil;
|
||||
private void Flush() {
|
||||
int queued_len = queued_list.Count();
|
||||
for (int i = 0; i < queued_len; i++) {
|
||||
Usr_log_fil fil = (Usr_log_fil)queued_list.FetchAt(i);
|
||||
if (fil.Url() == null) {
|
||||
fil.Url_(session_dir.GenSubFil("session.txt"));
|
||||
}
|
||||
fil.Flush();
|
||||
}
|
||||
} private OrderedHash queued_list = OrderedHash_.new_();
|
||||
public Io_url Log_dir() {return log_dir;}
|
||||
public void Log_dir_(Io_url log_dir) {
|
||||
this.log_dir = log_dir;
|
||||
session_dir = log_dir.GenSubDir(Dir_name_current);
|
||||
session_fil = session_dir.GenSubFil("session.txt");
|
||||
err_fil = session_dir.GenSubFil("err.txt");
|
||||
} private Io_url log_dir, err_fil;
|
||||
public void Init() {
|
||||
}
|
||||
public void Term() {
|
||||
if (!enabled) return;
|
||||
Io_url[] archive_dirs = Io_mgr._.QueryDir_args(log_dir).DirInclude_().DirOnly_().ExecAsUrlAry();
|
||||
int archive_dirs_len = archive_dirs.length;
|
||||
int session_cutoff = archive_dirs_len - archive_dirs_max;
|
||||
for (int i = 0; i < session_cutoff; i++) {
|
||||
Io_url archive_dir = archive_dirs[i];
|
||||
Io_mgr._.DeleteDirDeep(archive_dir);
|
||||
this.Log_msg_to_session("archive dir del: " + session_dir.Raw());
|
||||
}
|
||||
this.Log_msg_to_session("app term");
|
||||
MoveCurrentToArchive(session_dir);
|
||||
} int archive_dirs_max = 8;
|
||||
private void MoveCurrentToArchive(Io_url dir) {Io_mgr._.MoveDirDeep(dir, dir.OwnerDir().GenSubDir(DateAdp_.Now().XtoStr_fmt_yyyyMMdd_HHmmss_fff()));}
|
||||
public void Log_msg_to_url_fmt(Io_url url, String fmt, Object... args) {
|
||||
if (!enabled) return;
|
||||
String msg = Bld_msg(String_.new_utf8_(fmtr.Fmt_(fmt).Bld_bry_many(tmp_bfr, args)));
|
||||
Log_msg(url, msg);
|
||||
Log_msg(session_fil, msg);
|
||||
} private Bry_fmtr fmtr = Bry_fmtr.tmp_(); Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
public void Log_info(boolean warn, String s) {if (warn) Log_err(s); else Log_msg_to_session(s);}
|
||||
public void Log_msg_to_session_fmt(String fmt, Object... args) {Log_msg_to_session(String_.new_utf8_(fmtr.Fmt_(fmt).Bld_bry_many(tmp_bfr, args)));}
|
||||
public void Log_msg_to_session(String s) {
|
||||
if (!enabled) return;
|
||||
String line = Bld_msg(s);
|
||||
Log_msg(session_fil, line);
|
||||
}
|
||||
public void Log_msg_to_session_direct(String s) {
|
||||
if (!enabled) return;
|
||||
Log_msg(session_fil, s);
|
||||
}
|
||||
public void Log_err(String s) {
|
||||
if (!enabled) return;
|
||||
try {
|
||||
String line = Bld_msg(s);
|
||||
Log_msg(session_fil, line);
|
||||
Log_msg(err_fil, line);
|
||||
}
|
||||
catch (Exception e) {Err_.Noop(e);} // java.lang.StringBuilder can throw exceptions in some situations when called on a different thread; ignore errors
|
||||
} private String_bldr sb = String_bldr_.new_thread(); // NOTE: use java.lang.StringBuffer to try to avoid random exceptions when called on a different thread
|
||||
private String Bld_msg(String s) {return sb.Add(DateAdp_.Now().XtoUtc().XtoStr_fmt_yyyyMMdd_HHmmss_fff()).Add(" ").Add(s).Add_char_nl().Xto_str_and_clear();}
|
||||
private void Log_msg(Io_url url, String txt) {
|
||||
if (queue_enabled) {
|
||||
String url_raw = url == null ? "mem" : url.Raw();
|
||||
Usr_log_fil fil = (Usr_log_fil)queued_list.Fetch(url_raw);
|
||||
if (fil == null) {
|
||||
fil = new Usr_log_fil(url);
|
||||
queued_list.Add(url_raw, fil);
|
||||
}
|
||||
fil.Add(txt);
|
||||
}
|
||||
else
|
||||
Io_mgr._.AppendFilStr(url, txt);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_archive_dirs_max_)) archive_dirs_max = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_log_dir_)) log_dir = m.ReadIoUrl("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} public static final String Invk_enabled_ = "enabled_", Invk_archive_dirs_max_ = "archive_dirs_max_", Invk_log_dir_ = "log_dir_";
|
||||
static final String Dir_name_log = "log", Dir_name_current = "current";
|
||||
public static final Gfo_log_wtr_base _ = new Gfo_log_wtr_base();
|
||||
}
|
||||
class Usr_log_fil {
|
||||
public Usr_log_fil(Io_url url) {this.url = url;}
|
||||
public Io_url Url() {return url;} public Usr_log_fil Url_(Io_url v) {url = v; return this;} Io_url url;
|
||||
public void Add(String text) {sb.Add(text);} String_bldr sb = String_bldr_.new_();
|
||||
public void Flush() {
|
||||
if (sb.Count() == 0) return;
|
||||
try {
|
||||
Io_mgr._.AppendFilStr(url, sb.Xto_str_and_clear());
|
||||
}
|
||||
catch (Exception e) {
|
||||
ConsoleAdp._.WriteLine(Err_.Message_gplx_brief(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
public interface Gfo_usr_dlg_ui_opt {
|
||||
public interface Gfo_usr_dlg__gui__opt {
|
||||
boolean Warn_enabled();
|
||||
boolean Note_enabled();
|
||||
}
|
||||
@@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.strings.*; import gplx.gfui.*;
|
||||
public class Gfo_usr_dlg_ui_swt implements Gfo_usr_dlg_ui, GfoInvkAble {
|
||||
private final GfuiInvkCmd cmd_sync; private final GfuiTextBox prog_box, info_box; private final Gfo_usr_dlg_ui_opt opt;
|
||||
public Gfo_usr_dlg_ui_swt(Gfui_kit kit, GfuiTextBox prog_box, GfuiTextBox info_box, GfuiTextBox warn_box, Gfo_usr_dlg_ui_opt opt) {
|
||||
public class Gfo_usr_dlg__gui__swt implements Gfo_usr_dlg__gui, GfoInvkAble {
|
||||
private final GfuiInvkCmd cmd_sync; private final GfuiTextBox prog_box, info_box; private final Gfo_usr_dlg__gui__opt opt;
|
||||
public Gfo_usr_dlg__gui__swt(Gfui_kit kit, GfuiTextBox prog_box, GfuiTextBox info_box, GfuiTextBox warn_box, Gfo_usr_dlg__gui__opt opt) {
|
||||
this.cmd_sync = kit.New_cmd_sync(this); // NOTE: cmd_sync needed else progress messages may be sent out of order
|
||||
this.prog_box = prog_box; this.info_box = info_box;
|
||||
this.opt = opt;
|
||||
@@ -1,74 +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;
|
||||
public class Gfo_usr_dlg_base implements Gfo_usr_dlg {
|
||||
private Bry_fmtr tmp_fmtr = Bry_fmtr.tmp_().Fail_when_invalid_escapes_(false); // do not fail b/c msgs may contain excerpt of random text; EX:[[User:A|~A~]] DATE:2014-11-28
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
public Gfo_usr_dlg_ui Ui_wkr() {return ui_wkr;} public void Ui_wkr_(Gfo_usr_dlg_ui v) {ui_wkr = v;} Gfo_usr_dlg_ui ui_wkr = Gfo_usr_dlg_ui_.Null;
|
||||
public Gfo_log_wtr Log_wtr() {return log_wtr;} public void Log_wtr_(Gfo_log_wtr v) {log_wtr = v;} Gfo_log_wtr log_wtr;
|
||||
@gplx.Virtual public void Clear() {ui_wkr.Clear();}
|
||||
public boolean Canceled() {return canceled;} public void Canceled_y_() {canceled = true;} public void Canceled_n_() {canceled = false;} private boolean canceled;
|
||||
public void Cancel() {canceled = true;} public void Cancel_reset() {canceled = false;}
|
||||
public String Log_many(String grp_key, String msg_key, String fmt, Object... args) {String rv = Bld_msg_many(grp_key, msg_key, fmt, args ); log_wtr.Log_msg_to_session(rv); return rv;}
|
||||
public String Warn_many(String grp_key, String msg_key, String fmt, Object... args) {String rv = Bld_msg_many(grp_key, msg_key, fmt, args ); log_wtr.Log_err(rv); ui_wkr.Write_warn(rv); return rv;}
|
||||
public String Prog_many(String grp_key, String msg_key, String fmt, Object... args) {String rv = Bld_msg_many(grp_key, msg_key, fmt, args ); ui_wkr.Write_prog(rv); return rv;}
|
||||
public String Prog_one(String grp_key, String msg_key, String fmt, Object arg) {String rv = Bld_msg_one (grp_key, msg_key, fmt, arg ); ui_wkr.Write_prog(rv); return rv;}
|
||||
public String Prog_none(String grp_key, String msg_key, String fmt) {String rv = Bld_msg_none(grp_key, msg_key, fmt ); ui_wkr.Write_prog(rv); return rv;}
|
||||
public String Prog_direct(String msg) { ui_wkr.Write_prog(msg); return msg;}
|
||||
public String Log_direct(String msg) { log_wtr.Log_msg_to_session(msg); return msg;}
|
||||
public String Note_many(String grp_key, String msg_key, String fmt, Object... args) {String rv = Bld_msg_many(grp_key, msg_key, fmt, args ); log_wtr.Log_msg_to_session(rv); ui_wkr.Write_note(rv); return rv;}
|
||||
public String Note_none(String grp_key, String msg_key, String fmt) {String rv = Bld_msg_none(grp_key, msg_key, fmt ); log_wtr.Log_msg_to_session(rv); ui_wkr.Write_note(rv); return rv;}
|
||||
public String Note_gui_none(String grp_key, String msg_key, String fmt) {String rv = Bld_msg_none(grp_key, msg_key, fmt ); ui_wkr.Write_note(rv); return rv;}
|
||||
public String Plog_many(String grp_key, String msg_key, String fmt, Object... args) {
|
||||
String rv = Log_many(grp_key, msg_key, fmt, args);
|
||||
return Prog_direct(rv);
|
||||
}
|
||||
public Err Fail_many(String grp_key, String msg_key, String fmt, Object... args) {
|
||||
Err rv = Err_.new_(Bld_msg_many(grp_key, msg_key, fmt, args));
|
||||
log_wtr.Log_err(Err_.Message_gplx(rv));
|
||||
return rv;
|
||||
}
|
||||
private String Bld_msg_many(String grp_key, String msg_key, String fmt, Object[] args) {
|
||||
tmp_fmtr.Fmt_(fmt).Bld_bfr_many(tmp_bfr, args);
|
||||
return tmp_bfr.Xto_str_and_clear();
|
||||
}
|
||||
private String Bld_msg_one(String grp_key, String msg_key, String fmt, Object val) {
|
||||
tmp_fmtr.Fmt_(fmt).Bld_bfr_one(tmp_bfr, val);
|
||||
return tmp_bfr.Xto_str_and_clear();
|
||||
}
|
||||
private String Bld_msg_none(String grp_key, String msg_key, String fmt) {
|
||||
return fmt;
|
||||
}
|
||||
private void Ui_wkr_parse(String s) {
|
||||
if (String_.Eq(s, "null")) ui_wkr = Gfo_usr_dlg_ui_.Null;
|
||||
else throw Err_.unhandled(s);
|
||||
}
|
||||
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_ui_wkr_)) Ui_wkr_parse(m.ReadStr("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_ui_wkr_ = "ui_wkr_";
|
||||
public static Gfo_usr_dlg_base test_() {
|
||||
if (Test == null) {
|
||||
Test = new Gfo_usr_dlg_base();
|
||||
Test.Ui_wkr_(Gfo_usr_dlg_ui_.Test);
|
||||
Test.Log_wtr_(Gfo_log_wtr_.Null);
|
||||
}
|
||||
return Test;
|
||||
} private static Gfo_usr_dlg_base Test;
|
||||
}
|
||||
Reference in New Issue
Block a user