From 9ede342c17f3350c95c8d446580056b2b1bf7f98 Mon Sep 17 00:00:00 2001 From: Karel Matas Date: Fri, 5 Jul 2013 14:51:35 +0200 Subject: [PATCH] DB download - initial version finished --- CHANGELOG | 2 +- ROADMAP | 3 +++ src/aoi.cxx | 25 +++++++++++++++++++++++++ src/aoi.hxx | 3 ++- src/config.cxx | 2 +- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 19e2bce..558ef40 100755 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,7 +4,7 @@ alpha.03 - show all known informations about the selected word (temporary replacement of EditWord) - example sentences from Tatoeba project (initial version) -- downloading the database from internet +- downloading the pre-built database from internet alpha.02 - JLPT and Grade are now separate fields, not flags. diff --git a/ROADMAP b/ROADMAP index ff22298..ae28802 100755 --- a/ROADMAP +++ b/ROADMAP @@ -9,3 +9,6 @@ beta.XX - example words for kanji - synchronization of the user database with a newly generated one - export to CSV/HTML/Anki (filtered by flags) + +??? + - xz compression ( db.v00.gz: 38MB, db.v00.xz: 25 MB) diff --git a/src/aoi.cxx b/src/aoi.cxx index ee39496..9b37f5c 100755 --- a/src/aoi.cxx +++ b/src/aoi.cxx @@ -510,6 +510,7 @@ void App::load_dbscript ( const char *fname ) ui_->progress(95, "Checking indexes..."); check_indexes(); + ui_->progress_hide(); // show informations about db cb_manage_db(); } @@ -536,6 +537,30 @@ void App::cb_download_db () log_w("App::cb_download_db(): Not a file: "+path); return; } + + log("Closing old database."); + db_->close(); + + string dbfile = get_config("db/file_main"); + + log("Renaming old database to main.db.bckp."); + rename( dbfile.c_str(), DB_BACKUP_FILE ); + + log("Decompressing downloaded file"); + utils::gzip_decompress_file( path.c_str(), dbfile.c_str() ); + + log("Switching to the new database"); + open_database(); + + ui_->progress(10, "Checking tables..."); + check_tables(); + ui_->progress(50, "Checking indexes..."); + check_indexes(); + + remove( path.c_str() ); + ui_->progress_hide(); + // show informations about db + cb_manage_db(); } diff --git a/src/aoi.hxx b/src/aoi.hxx index 05e4968..515ee27 100755 --- a/src/aoi.hxx +++ b/src/aoi.hxx @@ -304,6 +304,7 @@ class App * Loads database stored as SQLite script. File may be GZipped. */ void load_dbscript ( const char *fname ); + inline void load_dbscript ( const string &fname ){ load_dbscript(fname.c_str());}; /*! * Calls input parser. Resets GUI (pos chekboxes). @@ -349,7 +350,7 @@ class App void cb_set_components (); /*! - * + * Downloads prebuilt (gzipped) database from aoi.souko.cz. */ void cb_download_db(); diff --git a/src/config.cxx b/src/config.cxx index 443d812..2d64110 100755 --- a/src/config.cxx +++ b/src/config.cxx @@ -48,7 +48,7 @@ Config::Config () data_["color/pos"] = {"0xff000000", "Color of the part-of-speech data (n,adj,exp,...). Default: red",COLOR}; // - data_["sources/url_database"] = {"http://aoi.souko.cz/downloads/dbscript.sql.gz", + data_["sources/url_database"] = {"http://aoi.souko.cz/downloads/main.db.gz", "URL for downloading database", STRING}, data_["sources/url_jmdict"] = {"http://ftp.monash.edu.au/pub/nihongo/JMdict_e.gz", "URL for downloading JMdict.", STRING}; -- 2.11.4.GIT