1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00

Cfg: Add transaction to upgrader; handle pre-existing back file; add try / catch

This commit is contained in:
gnosygnu 2017-01-01 14:21:05 -05:00
parent 360129b7de
commit 562c5b5a56
2 changed files with 44 additions and 38 deletions

View File

@ -32,7 +32,7 @@ public class Xoa_app_ {
}
}
public static final String Name = "xowa";
public static final String Version = "3.12.2.1612";
public static final String Version = "4.0.0.1701";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys_str;
public static String User_agent = "";

View File

@ -19,6 +19,7 @@ package gplx.xowa.addons.apps.cfgs.upgrades; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*;
public class Xocfg_upgrade_mgr {
public static void Convert(Xoae_app app) {
try {
// get cfg_fil; if empty, exit
Io_url cfg_fil = app.Fsys_mgr().Root_dir().GenSubFil_nest("user", "anonymous", "app", "data", "cfg", "xowa_user_cfg.gfs");
byte[] cfg_raw = Io_mgr.Instance.LoadFilBryOrNull(cfg_fil);
@ -26,7 +27,7 @@ public class Xocfg_upgrade_mgr {
// log and rename file
Gfo_usr_dlg_.Instance.Log_many("", "", "cfg.convert:old cfg found; converting");
Io_mgr.Instance.MoveFil(cfg_fil, cfg_fil.GenNewExt(".bak"));
Io_mgr.Instance.MoveFil_args(cfg_fil, cfg_fil.GenNewExt(".bak"), true).Exec();
// parse, remap, and update
Keyval[] kvs = Parse(cfg_raw);
@ -56,10 +57,15 @@ public class Xocfg_upgrade_mgr {
}
// apply
app.Cfg().Cache_mgr().Db_usr().Conn().Txn_bgn("convert");
for (Keyval kv : kvs) {
if (String_.Eq(kv.Key(), "")) continue;
app.Cfg().Set_str_app(kv.Key(), kv.Val_to_str_or_empty());
}
app.Cfg().Cache_mgr().Db_usr().Conn().Txn_end();
} catch (Exception exc) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to convert old cfg; err=~{0}", Err_.Message_gplx_log(exc));
}
}
public static Keyval[] Parse(byte[] src) {
int pos = 0; int len = src.length;