OSDN Git Service

* raw-pointerの排除
[gikomona/libcore.git] / src / GikoMona.cpp
1 #include <exception>
2 #include <memory>
3
4 #include <boost/filesystem.hpp>
5 #include <boost/log/trivial.hpp>
6
7 #include <wx/xrc/xmlres.h>
8 #include <wx/msgdlg.h>
9
10 #include "GikoMona.hpp"
11 #include "database.hpp"
12 #include "model.hpp"
13
14 #include "extension.hpp"
15
16 namespace monazilla { namespace GikoMona { namespace core {
17
18 namespace {
19
20 std::shared_ptr<model> app_model;
21 std::shared_ptr<extension> app_extension;
22
23 }
24
25 bool init_core() {
26     wxXmlResource::Get()->InitAllHandlers();
27     wxXmlResource::Get()->LoadAllFiles(wxT("resouce"));
28     
29     boost::system::error_code reason;
30     
31     // 一時解凍ファイルなどを溜め込む .tmp フォルダを作成
32     if(!boost::filesystem::create_directory(".tmp", reason)) {
33         // log
34         std::terminate();
35     }
36     
37     app_model = std::make_shared<model>();
38     app_extension = std::make_shared<extension>();
39     
40     return true;
41 }
42
43 void done_core() noexcept {
44     boost::system::error_code reason;
45     boost::filesystem::remove_all(".tmp", reason);
46     
47     optimize_database("./history.db");
48 }
49
50 void optimize_database(const boost::filesystem::path& db_path) {
51     boost::system::error_code ec;
52     
53     database db(db_path, ec);
54     sqlite::connection con = db.get_connection();
55     
56     mona_string sql(u8"SELECT counts-of-deleting-value FROM file-information;");
57     auto count = sqlite::execute_statement<int>(db, sql, ec);
58
59     if(!count) { /* log */ }
60     
61     if(count->at<0>(0) >= 1000) {
62         db.optimize(ec);
63     }
64 }
65
66 } } }