5 #include <boost/filesystem.hpp>
6 #include <boost/log/trivial.hpp>
8 #include <wx/xrc/xmlres.h>
11 #include "GikoMona.hpp"
12 #include "database.hpp"
14 #include "post-office.hpp"
16 #include "extension.hpp"
18 namespace monazilla { namespace GikoMona { namespace core {
22 std::shared_ptr<model> app_model;
23 std::shared_ptr<extension> app_extension;
24 std::shared_ptr<communication::post_office> app_postoffice;
28 bool init_core(const mona_string& app_name) {
29 wxXmlResource::Get()->InitAllHandlers();
30 wxXmlResource::Get()->LoadAllFiles(wxT("resouce"));
32 boost::system::error_code reason;
33 std::stringstream path_builder;
34 path_builder << ".tmp/" << app_name;
36 // 一時解凍ファイルなどを溜め込む .tmp フォルダを作成
37 if(!boost::filesystem::exists(path_builder.str(), reason) &&
38 !boost::filesystem::create_directories(path_builder.str(), reason)) {
43 app_model = std::make_shared<model>();
44 app_extension = std::make_shared<extension>();
45 app_postoffice = std::make_shared<communication::post_office>(app_name);
50 void done_core(const mona_string& app_name) noexcept {
51 boost::system::error_code reason;
52 boost::filesystem::remove_all(".tmp", reason);
54 optimize_database("./history.db");
57 void optimize_database(const boost::filesystem::path& db_path) {
58 boost::system::error_code ec;
60 database db(db_path, ec);
61 sqlite::connection con = db.get_connection();
63 mona_string sql(u8"SELECT counts-of-deleting-value FROM file-information;");
64 auto count = sqlite::execute_statement<int>(db, sql, ec);
66 if(!count) { /* log */ }
68 if(count->at<0>(0) >= 1000) {