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 "communication/post-office.hpp"
16 #include "extension.hpp"
18 namespace monazilla { namespace GikoMona {
20 const char* severity_names[] = {
32 boost::log::sources::severity_logger<severity_level>* severity_logger;
36 std::ostream& operator<<(std::ostream& strm, const monazilla::GikoMona::severity_level level) {
37 strm << monazilla::GikoMona::severity_names[static_cast<int>(level)];
41 namespace monazilla { namespace GikoMona { namespace core {
45 std::shared_ptr<model> app_model;
46 std::shared_ptr<extension> app_extension;
47 //std::shared_ptr<communication::post_office> app_postoffice;
51 bool init_core(const mona_string& app_name) {
52 severity_logger = new boost::log::sources::severity_logger<severity_level>;
53 boost::log::register_simple_formatter_factory<severity_level, char>( "Severity" );
54 boost::log::add_file_log(
55 boost::log::keywords::file_name = "logs/%Y%m%d.log",
56 boost::log::keywords::format = "%Severity% - [GikoMona. %TimeStamp%]:%Message%",
57 boost::log::keywords::open_mode = (std::ios::out | std::ios::app)
59 boost::log::core::get()->add_global_attribute("TimeStamp", boost::log::attributes::local_clock());
61 wxXmlResource::Get()->InitAllHandlers();
62 wxXmlResource::Get()->LoadAllFiles(wxT("resouce"));
64 boost::system::error_code reason;
65 std::stringstream path_builder;
66 path_builder << ".tmp/" << app_name;
68 // 一時解凍ファイルなどを溜め込む .tmp フォルダを作成
69 if(!boost::filesystem::exists(path_builder.str(), reason) &&
70 !boost::filesystem::create_directories(path_builder.str(), reason)) {
71 ERROR(".tmpフォルダがすでに存在するか、.tmpフォルダの作成に失敗しました。");
72 MESSAGE(".tmpフォルダが存在するか確認し、存在すれば.tmpフォルダを削除してください。");
76 app_model = std::make_shared<model>();
77 app_extension = std::make_shared<extension>();
78 //app_postoffice = std::make_shared<communication::post_office>(app_name);
83 void done_core(const mona_string& app_name) noexcept {
84 boost::system::error_code reason;
85 boost::filesystem::remove_all(".tmp", reason);
87 optimize_database("./history.db");
90 void optimize_database(const boost::filesystem::path& db_path) {
91 boost::system::error_code ec;
93 database db(db_path, ec);
94 sqlite::connection con = db.get_connection();
96 mona_string sql(u8"SELECT counts-of-deleting-value FROM file-information;");
97 auto count = sqlite::execute_statement<int>(db, sql, ec);
99 if(!count) { WARNING("libsqlitexx '" << ec.message() << "'"); }
101 if(count->at<0>(0) >= 1000) {