1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

File_shrink: Add initial classes for file_shrink

This commit is contained in:
gnosygnu
2017-01-04 12:10:20 -05:00
parent 063cc43047
commit 2dc6d8c20b
4 changed files with 129 additions and 23 deletions

View File

@@ -0,0 +1,30 @@
/*
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.xowa.addons.bldrs.files.shrinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xoshrink_cmd extends Xob_cmd__base {
public Xoshrink_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
wiki.Init_assert();
new Xoshrink_mgr().Exec(wiki);
}
@Override public String Cmd_key() {return BLDR_CMD_KEY;} private static final String BLDR_CMD_KEY = "fsdb.shrink";
public static final Xob_cmd Prototype = new Xoshrink_cmd(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xoshrink_cmd(bldr, wiki);}
}

View File

@@ -0,0 +1,73 @@
/*
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.xowa.addons.bldrs.files.shrinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.core.envs.*;
import gplx.dbs.*;
import gplx.fsdb.*; import gplx.fsdb.data.*; import gplx.fsdb.meta.*;
class Xoshrink_mgr {
private Io_url src_url, trg_url;
private Process_adp convert_cmd;
public void Exec(Xowe_wiki wiki) {
// init
src_url = wiki.Fsys_mgr().Root_dir().GenSubFil_nest("tmp", "shrink", "src.file");
trg_url = wiki.Fsys_mgr().Root_dir().GenSubFil_nest("tmp", "shrink", "trg.file");
Io_url convert_exe_url = wiki.Appe().Prog_mgr().App_resize_img().Exe_url();
convert_cmd = Process_adp.New(Gfo_usr_dlg_.Instance, wiki.Appe().Url_cmd_eval(), Process_adp.Run_mode_sync_timeout, 1 * 60, convert_exe_url.Raw(), "-resample ~{w}x~{h}");
// get bin_mgr
Fsm_bin_mgr bin_mgr = wiki.File__mnt_mgr().Mnts__get_main().Bin_mgr();
int len = bin_mgr.Dbs__len();
// loop bin_dbs
for (int i = 0; i < len; i++) {
Shrink(bin_mgr.Dbs__get_at(i));
}
}
private void Shrink(Fsm_bin_fil fil) {
// init
Fsd_bin_tbl tbl = fil.Tbl();
Db_conn conn = fil.Conn();
// prep for update
conn.Txn_bgn("tbl_update");
Db_stmt stmt = conn.Stmt_update(tbl.Tbl_name(), String_.Ary(tbl.fld__owner_id), tbl.fld__data);
// get rdr
Db_rdr rdr = conn.Stmt_select_all(tbl.Tbl_name(), tbl.Flds()).Exec_select__rls_auto();
try {
// loop each row and convert
while (rdr.Move_next()) {
// db.read and fs.save
int id = rdr.Read_int(tbl.fld__owner_id);
byte[] data = rdr.Read_bry(tbl.fld__data);
Io_mgr.Instance.SaveFilBry(src_url, data);
// convert
convert_cmd.Run();// get w and h
// fs.load and db.save
data = Io_mgr.Instance.LoadFilBry(trg_url);
tbl.Update(stmt, id, data);
}
} finally {
conn.Txn_end();
rdr.Rls();
stmt.Rls();
}
}
}