mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.3.1
This commit is contained in:
@@ -16,20 +16,43 @@ 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.apps; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Xoa_app_type {
|
||||
Xoa_app_type(int uid) {this.uid = uid;}
|
||||
public int Uid() {return uid;} private final int uid;
|
||||
public boolean Uid_is_gui() {return uid == Uid_gui;}
|
||||
public boolean Uid_is_tcp() {return uid == Uid_tcp;}
|
||||
public boolean Uid_is_http() {return uid == Uid_http;}
|
||||
private static final int Uid_cmd = 1, Uid_gui = 2, Uid_tcp = 3, Uid_http = 4;
|
||||
private static final String Key_cmd = "cmd", Key_gui = "gui", Key_tcp = "server", Key_http = "http_server";
|
||||
public static final Xoa_app_type Itm_cmd = new Xoa_app_type(Uid_cmd), Itm_gui = new Xoa_app_type(Uid_gui), Itm_tcp = new Xoa_app_type(Uid_tcp), Itm_http = new Xoa_app_type(Uid_http);
|
||||
public byte[] Name() {
|
||||
switch (uid) {
|
||||
case Uid_cmd: return Key_cmd;
|
||||
case Uid_gui: return Key_gui;
|
||||
case Uid_http: return Key_http;
|
||||
case Uid_tcp: return Key_tcp;
|
||||
case Uid_file: return Key_file;
|
||||
default: return Key_cmd; // see parse
|
||||
}
|
||||
}
|
||||
private static final int Uid_cmd = 1, Uid_gui = 2, Uid_tcp = 3, Uid_http = 4, Uid_file = 5;
|
||||
private static final byte[] Key_cmd = Bry_.new_a7("cmd"), Key_gui = Bry_.new_a7("gui"), Key_tcp = Bry_.new_a7("server"), Key_http = Bry_.new_a7("http_server"), Key_file = Bry_.new_a7("file");
|
||||
private static final Hash_adp_bry type_hash = Hash_adp_bry.cs_()
|
||||
.Add_bry_int(Key_cmd , Uid_cmd)
|
||||
.Add_bry_int(Key_gui , Uid_gui)
|
||||
.Add_bry_int(Key_http , Uid_http)
|
||||
.Add_bry_int(Key_tcp , Uid_tcp)
|
||||
.Add_bry_int(Key_file , Uid_file)
|
||||
;
|
||||
public static final Xoa_app_type Itm_cmd = new Xoa_app_type(Uid_cmd), Itm_gui = new Xoa_app_type(Uid_gui), Itm_tcp = new Xoa_app_type(Uid_tcp), Itm_http = new Xoa_app_type(Uid_http), Itm_file = new Xoa_app_type(Uid_file);
|
||||
public static Xoa_app_type parse(String s) {
|
||||
if (String_.Eq(s, Key_cmd)) return Itm_cmd;
|
||||
else if (String_.Eq(s, Key_gui)) return Itm_gui;
|
||||
else if (String_.Eq(s, Key_tcp)) return Itm_tcp;
|
||||
else if (String_.Eq(s, Key_http)) return Itm_http;
|
||||
else return Itm_cmd; // default to cmd as per early behaviour; handles mistaken "--app_mode wrong"
|
||||
Object o = type_hash.Get_by(Bry_.new_u8(s)); if (o == null) return Itm_cmd; // default to cmd as per early behaviour; handles mistaken "--app_mode wrong"
|
||||
int uid = ((Int_obj_val)o).Val();
|
||||
switch (uid) {
|
||||
case Uid_cmd: return Itm_cmd;
|
||||
case Uid_gui: return Itm_gui;
|
||||
case Uid_http: return Itm_http;
|
||||
case Uid_tcp: return Itm_tcp;
|
||||
case Uid_file: return Itm_file;
|
||||
default: throw Err_.new_unhandled(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,12 +36,12 @@ public class Xoa_gfs_mgr implements GfoInvkAble, GfoInvkRootWkr {
|
||||
else if (String_.Eq(type, "xowa_cfg_user")) url = usr_fsys_mgr.App_data_cfg_user_fil();
|
||||
else if (String_.Eq(type, "xowa_cfg_os")) {url = app_fsys_mgr.Bin_data_os_cfg_fil(); Xoa_gfs_mgr_.Cfg_os_assert(url);}
|
||||
else if (String_.Eq(type, "xowa_cfg_app")) url = app_fsys_mgr.Root_dir().GenSubFil("xowa.gfs");
|
||||
else throw Exc_.new_("invalid gfs type", "type", type);
|
||||
else throw Err_.new_wo_type("invalid gfs type", "type", type);
|
||||
try {Run_url(url);}
|
||||
catch (Exception e) { // gfs is corrupt; may happen if multiple XOWAs opened, and "Close all" chosen in OS; DATE:2014-07-01
|
||||
if (!String_.Eq(type, "xowa")) // check if user.gfs
|
||||
Io_mgr.I.MoveFil(url, url.GenNewNameOnly(url.NameOnly() + "-" + DateAdp_.Now().XtoStr_fmt_yyyyMMdd_HHmmss())); // move file
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "invalid gfs; obsoleting: src=~{0} err=~{1}", url.Raw(), Err_.Message_gplx(e));
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "invalid gfs; obsoleting: src=~{0} err=~{1}", url.Raw(), Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
public GfoMsg Parse_root_msg(String v) {return gplx.gfs.Gfs_msg_bldr._.ParseToMsg(v);}
|
||||
@@ -67,7 +67,7 @@ public class Xoa_gfs_mgr implements GfoInvkAble, GfoInvkRootWkr {
|
||||
}
|
||||
return rv;
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "error while executing script: err=~{0}", Err_.Message_gplx(e));
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "error while executing script: err=~{0}", Err_.Message_gplx_full(e));
|
||||
return GfoInvkAble_.Rv_error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class Xoa_gfs_php_mgr {
|
||||
return dirty ? bfr.Xto_bry_and_clear() : src;
|
||||
}
|
||||
private static int Xto_php_swap(Bry_bfr bfr, byte[] src, int len, int pos) {
|
||||
if (pos >= len) throw Exc_.new_("invalid gfs: tilde is last char", "src", String_.new_u8(src));
|
||||
if (pos >= len) throw Err_.new_wo_type("invalid gfs: tilde is last char", "src", String_.new_u8(src));
|
||||
byte b = src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Tilde: { // ~~ -> ~
|
||||
@@ -72,17 +72,17 @@ public class Xoa_gfs_php_mgr {
|
||||
|| num_end == len
|
||||
|| src[num_end] != Byte_ascii.Curly_end
|
||||
)
|
||||
throw Exc_.new_("invalid gfs; num_end not found", "src", String_.new_u8(src));
|
||||
throw Err_.new_wo_type("invalid gfs; num_end not found", "src", String_.new_u8(src));
|
||||
bfr.Add_byte(Byte_ascii.Dollar);
|
||||
int arg_idx = Bry_.Xto_int_or(src, num_bgn, num_end, -1);
|
||||
if (arg_idx == -1) {
|
||||
throw Exc_.new_("invalid int");
|
||||
throw Err_.new_wo_type("invalid int");
|
||||
}
|
||||
bfr.Add_int_variable(arg_idx + 1);
|
||||
return num_end + 1;
|
||||
}
|
||||
default: {
|
||||
throw Exc_.new_("invalid gfs; next char after tilde must be either tilde or open brace", "src", String_.new_u8(src));
|
||||
throw Err_.new_wo_type("invalid gfs; next char after tilde must be either tilde or open brace", "src", String_.new_u8(src));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,14 @@ 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.apps; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.consoles.*;
|
||||
public class Xoa_shell implements GfoInvkAble {
|
||||
public Xoa_shell(Xoae_app app) {this.app = app;} private Xoae_app app;
|
||||
public boolean Fetch_page_exec_async() {return fetch_page_exec_async;} private boolean fetch_page_exec_async = true;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_fetch_page)) return Fetch_page(m);
|
||||
else if (ctx.Match(k, Invk_chars_per_line_max_)) ConsoleAdp._.CharsPerLineMax_set(m.ReadInt("v"));
|
||||
else if (ctx.Match(k, Invk_backspace_by_bytes_)) ConsoleAdp._.Backspace_by_bytes_(m.ReadYn("v"));
|
||||
else if (ctx.Match(k, Invk_chars_per_line_max_)) Console_adp__sys.I.Chars_per_line_max_(m.ReadInt("v"));
|
||||
else if (ctx.Match(k, Invk_backspace_by_bytes_)) Console_adp__sys.I.Backspace_by_bytes_(m.ReadYn("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Xoa_fsys_eval implements Bry_fmtr_eval_mgr {
|
||||
case Tid_bin_plat_dir: return app_fsys_mgr.Bin_plat_dir().RawBry();
|
||||
case Tid_user_temp_dir: return usr_fsys_mgr.App_temp_dir().RawBry();
|
||||
case Tid_user_cfg_dir: return usr_fsys_mgr.App_data_cfg_dir().RawBry();
|
||||
default: throw Exc_.new_unhandled(val);
|
||||
default: throw Err_.new_unhandled(val);
|
||||
}
|
||||
}
|
||||
private static final byte Tid_bin_plat_dir = 0, Tid_user_temp_dir = 1, Tid_xowa_root_dir = 2, Tid_user_cfg_dir = 3;
|
||||
|
||||
Reference in New Issue
Block a user