private void Download_itm(Xodb_tbl_oimg_xfer_itm fsdb) {
   try {
     tier_id_val = fsdb.Lnki_tier_id();
     page_id_val = fsdb.Lnki_page_id();
     lnki_id_val = fsdb.Lnki_id();
     fsdb.Orig_repo_name_(
         fsdb.Orig_repo_id() == Xof_repo_tid_.Tid__local
             ? wiki.Domain_bry()
             : Xow_domain_itm_.Bry__commons);
     Download_exec(fsdb);
     ++exec_count;
     if (exec_count % progress_interval == 0) Print_progress(fsdb);
     if (exec_count % poll_interval == 0) poll_mgr.Poll();
     if (exec_count % commit_interval == 0) Txn_sav();
     if (exec_count % delete_interval == 0) Delete_files();
   } catch (Exception exc) {
     ++exec_fail;
     usr_dlg.Warn_many(
         "",
         "",
         "download error; ttl=~{0} w=~{1} err=~{2}",
         fsdb.Orig_ttl(),
         fsdb.Lnki_w(),
         Err_.Message_gplx_full(exc));
   }
 }
 public static Xodb_tbl_oimg_xfer_itm new_rdr_(DataRdr rdr) {
   Xodb_tbl_oimg_xfer_itm rv = new Xodb_tbl_oimg_xfer_itm();
   rv.lnki_id = rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_id);
   rv.lnki_page_id = rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_page_id);
   rv.lnki_tier_id = rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_tier_id);
   rv.Init_at_fsdb_make(
       rdr.ReadBryByStr(Xob_xfer_regy_tbl.Fld_lnki_ttl),
       rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_ext),
       rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_w),
       rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_h) // set lnki_size; Xof_bin_mgr uses lnki_size
       ,
       Xof_lnki_time.Db_load_double(rdr, Xob_xfer_regy_tbl.Fld_lnki_time),
       Xof_lnki_page.Db_load_int(rdr, Xob_xfer_regy_tbl.Fld_lnki_page),
       rdr.ReadByte(Xob_xfer_regy_tbl.Fld_orig_repo),
       rdr.ReadInt(Xob_xfer_regy_tbl.Fld_orig_w),
       rdr.ReadInt(Xob_xfer_regy_tbl.Fld_orig_h),
       Bry_.Empty,
       rdr.ReadByte(Xob_xfer_regy_tbl.Fld_file_is_orig) == Bool_.Y_byte);
   return rv;
 }
 private void Download_exec(Xodb_tbl_oimg_xfer_itm fsdb) {
   Io_stream_rdr src_rdr = src_bin_mgr.Find_as_rdr(Xof_exec_tid.Tid_wiki_page, fsdb);
   try {
     if (src_rdr == Io_stream_rdr_.Noop) { // download failed
       ++exec_fail;
       usr_dlg.Warn_many(
           "",
           "",
           "failed: ttl=~{0}",
           String_.Format("[[File:{0}|{1}px]]", fsdb.Orig_ttl(), fsdb.Html_w()));
       Print_progress(fsdb);
     } else { // download passed
       long src_rdr_len = src_rdr.Len();
       int lnki_tier_id = fsdb.Lnki_tier_id();
       if (src_rdr_len > download_size_max && !Int_.In(lnki_tier_id, download_keep_tier_ids)) {
         usr_dlg.Warn_many(
             "",
             "",
             "skipped; ttl=~{0} w=~{1} size=~{2} tier=~{3}",
             fsdb.Orig_ttl(),
             fsdb.Lnki_w(),
             src_rdr_len,
             lnki_tier_id);
         return;
       }
       if (trg_bin_fil == null) // no trg_bin_fil
       Make_trg_bin_file(Bool_.Y, fsdb, src_rdr_len);
       else if (trg_bin_fil.Bin_len() + src_rdr_len
           > trg_bin_db_max) // or trg_bin_fil is out of space
       Make_trg_bin_file(Bool_.N, fsdb, src_rdr_len);
       else if (prv_lnki_tier_id != lnki_tier_id) { // or tier has changed
         if (prv_lnki_tier_id != -1 && !bin_db_mgr.Schema_is_1()) // do not increment dbs for v1
         Make_trg_bin_file(Bool_.Y, fsdb, src_rdr_len);
         prv_lnki_tier_id = lnki_tier_id;
       }
       trg_bin_updater.Save_bin(trg_mnt_itm, trg_atr_fil, trg_bin_fil, fsdb, src_rdr, src_rdr_len);
     }
   } finally {
     src_rdr.Rls();
   }
 }
 private void Print_progress(Xodb_tbl_oimg_xfer_itm itm) {
   int time_elapsed = System_.Ticks__elapsed_in_sec(time_bgn);
   usr_dlg.Prog_many(
       "",
       "",
       "prog: num=~{0} err=~{1} time=~{2} rate=~{3} page=~{4} lnki=~{5} ttl=~{6}",
       exec_count,
       exec_fail,
       time_elapsed,
       Math_.Div_safe_as_int(exec_count, time_elapsed),
       page_id_val,
       lnki_id_val,
       itm.Orig_ttl());
 }
 private byte Select_fsdb_itms(List_adp list) {
   list.Clear();
   boolean pages_found = false, links_found = false;
   DataRdr rdr =
       Xob_xfer_regy_tbl.Select_by_tier_page(bldr_conn, tier_id_val, page_id_val, select_interval);
   try {
     while (rdr.MoveNextPeer()) {
       pages_found = true; // at least one page found; set true
       Xodb_tbl_oimg_xfer_itm itm = Xodb_tbl_oimg_xfer_itm.new_rdr_(rdr);
       if (itm.Lnki_page_id() == page_id_val // same page_id
           && itm.Lnki_id() <= lnki_id_val // ... but lnki_id < last
       ) continue; // ... ignore; note that select is by page_id, not page_id + link_id; needed
       // else restarts would not resume exactly at same point;
       links_found = true;
       list.Add(itm);
     }
   } finally {
     rdr.Rls();
   }
   if (pages_found && !links_found)
     return Select_rv_next_page; // pages found, but all links processed
   else if (!pages_found) return Select_rv_stop; // no more pages found
   else return Select_rv_process; // pages and links found
 }
 private void Make_trg_bin_file(boolean try_nth, Xodb_tbl_oimg_xfer_itm fsdb, long src_rdr_len) {
   boolean is_solo = trg_mnt_itm.Db_mgr().File__solo_file();
   boolean make = true, use_txn = !is_solo; // solo file; should never open txn
   if (trg_bin_fil != null && use_txn) // pre-existing bin_file;
   trg_bin_fil.Conn().Txn_end(); // close txn before making new db
   int tier_id = fsdb.Lnki_tier_id();
   Xob_bin_db_itm nth_bin_db = bin_db_mgr.Get_nth_by_tier(tier_id);
   if (try_nth) { // try_nth is true; occurs for new runs or changed tier
     if (nth_bin_db.Id() != -1 // nth exists;
         && nth_bin_db.Db_len() + src_rdr_len < trg_bin_db_max) { // if src_rdr_len exceeds
       make = false; // do not make; use existing
     }
   }
   if (make) { // no nth; make it;
     int ns_id = bin_db_mgr.Get_ns_id(tier_id);
     int pt_id = bin_db_mgr.Increment_pt_id(nth_bin_db);
     String new_bin_db_name = bin_db_mgr.Gen_name(wiki.Domain_str(), ns_id, pt_id);
     this.trg_bin_fil = trg_mnt_itm.Bin_mgr().Dbs__make(new_bin_db_name);
     if (!trg_mnt_itm.Db_mgr().File__solo_file()) {
       Fsdb_db_file trg_bin_db =
           trg_mnt_itm.Db_mgr()
               .File__bin_file__at(trg_mnt_itm.Id(), trg_bin_fil.Id(), new_bin_db_name);
       if (!bin_db_mgr.Schema_is_1())
         Fsdb_db_mgr__v2_bldr.Make_cfg_data(
             wiki,
             trg_atr_fil.Url_rel(),
             trg_bin_db,
             Xow_db_file_.Tid__file_data,
             trg_bin_fil.Id() + List_adp_.Base1);
     }
   } else { // nth available; use it
     this.trg_bin_fil = trg_mnt_itm.Bin_mgr().Dbs__get_at(nth_bin_db.Id());
     trg_bin_fil.Bin_len_(nth_bin_db.Db_len());
   }
   if (use_txn) trg_bin_fil.Conn().Txn_bgn("bldr__fsdb_make__trg_bin_fil");
 }