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:
parent
360129b7de
commit
562c5b5a56
@ -32,7 +32,7 @@ public class Xoa_app_ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static final String Name = "xowa";
|
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 Build_date = "2012-12-30 00:00:00";
|
||||||
public static String Op_sys_str;
|
public static String Op_sys_str;
|
||||||
public static String User_agent = "";
|
public static String User_agent = "";
|
||||||
|
@ -19,46 +19,52 @@ package gplx.xowa.addons.apps.cfgs.upgrades; import gplx.*; import gplx.xowa.*;
|
|||||||
import gplx.dbs.*;
|
import gplx.dbs.*;
|
||||||
public class Xocfg_upgrade_mgr {
|
public class Xocfg_upgrade_mgr {
|
||||||
public static void Convert(Xoae_app app) {
|
public static void Convert(Xoae_app app) {
|
||||||
// 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);
|
|
||||||
if (cfg_raw == null) return;
|
|
||||||
|
|
||||||
// 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"));
|
|
||||||
|
|
||||||
// parse, remap, and update
|
|
||||||
Keyval[] kvs = Parse(cfg_raw);
|
|
||||||
|
|
||||||
// get mappings
|
|
||||||
Ordered_hash mappings = Ordered_hash_.New();
|
|
||||||
Db_conn conn = app.Cfg().Cache_mgr().Db_app().Conn();
|
|
||||||
Db_rdr rdr = conn.Stmt_sql("SELECT * FROM cfg_upgrade").Exec_select__rls_auto();
|
|
||||||
try {
|
try {
|
||||||
while (rdr.Move_next()) {
|
// get cfg_fil; if empty, exit
|
||||||
String cfg_old = rdr.Read_str("cfg_old");
|
Io_url cfg_fil = app.Fsys_mgr().Root_dir().GenSubFil_nest("user", "anonymous", "app", "data", "cfg", "xowa_user_cfg.gfs");
|
||||||
String cfg_new = rdr.Read_str("cfg_new");
|
byte[] cfg_raw = Io_mgr.Instance.LoadFilBryOrNull(cfg_fil);
|
||||||
mappings.Add(cfg_old, Keyval_.new_(cfg_old, cfg_new));
|
if (cfg_raw == null) return;
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {rdr.Rls();}
|
|
||||||
|
|
||||||
// remap
|
// log and rename file
|
||||||
for (Keyval kv : kvs) {
|
Gfo_usr_dlg_.Instance.Log_many("", "", "cfg.convert:old cfg found; converting");
|
||||||
Keyval mapping = (Keyval)mappings.Get_by(kv.Key());
|
Io_mgr.Instance.MoveFil_args(cfg_fil, cfg_fil.GenNewExt(".bak"), true).Exec();
|
||||||
if (mapping == null) {
|
|
||||||
Gfo_usr_dlg_.Instance.Log_many("", "", "cfg.convert:could not find mapping; key=~{0} val=~{1}", kv.Key(), kv.Val());
|
|
||||||
kv.Key_("");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
kv.Key_(mapping.Val());
|
|
||||||
}
|
|
||||||
|
|
||||||
// apply
|
// parse, remap, and update
|
||||||
for (Keyval kv : kvs) {
|
Keyval[] kvs = Parse(cfg_raw);
|
||||||
if (String_.Eq(kv.Key(), "")) continue;
|
|
||||||
app.Cfg().Set_str_app(kv.Key(), kv.Val_to_str_or_empty());
|
// get mappings
|
||||||
|
Ordered_hash mappings = Ordered_hash_.New();
|
||||||
|
Db_conn conn = app.Cfg().Cache_mgr().Db_app().Conn();
|
||||||
|
Db_rdr rdr = conn.Stmt_sql("SELECT * FROM cfg_upgrade").Exec_select__rls_auto();
|
||||||
|
try {
|
||||||
|
while (rdr.Move_next()) {
|
||||||
|
String cfg_old = rdr.Read_str("cfg_old");
|
||||||
|
String cfg_new = rdr.Read_str("cfg_new");
|
||||||
|
mappings.Add(cfg_old, Keyval_.new_(cfg_old, cfg_new));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {rdr.Rls();}
|
||||||
|
|
||||||
|
// remap
|
||||||
|
for (Keyval kv : kvs) {
|
||||||
|
Keyval mapping = (Keyval)mappings.Get_by(kv.Key());
|
||||||
|
if (mapping == null) {
|
||||||
|
Gfo_usr_dlg_.Instance.Log_many("", "", "cfg.convert:could not find mapping; key=~{0} val=~{1}", kv.Key(), kv.Val());
|
||||||
|
kv.Key_("");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
kv.Key_(mapping.Val());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
public static Keyval[] Parse(byte[] src) {
|
||||||
|
Loading…
Reference in New Issue
Block a user