OSDN Git Service

fix build system ofmoflib1 and saisei1
[moflib/moflib.git] / saisei-1.0 / src / Settings.cpp
1 #include <windows.h>
2 #include <iostream>
3 #include <cstring>
4 #include "extlib/sqlite3.h"
5 #include "Settings.hpp"
6 #include <memory>
7 #include <boost/lexical_cast.hpp>
8 #include <boost/format.hpp>
9 #include <mof/GraphicsDevice.hpp>
10
11 namespace 
12 {
13         sqlite3* db;
14 }
15
16 //{{{ callback_load_settings
17 static int callback_load_settings(void* data, int argc, char** argv, char** colnames)
18 {
19         Settings* settings = static_cast<Settings*>(data);
20         for (int i = 0 ; i < argc; i++) {
21                 char* colname = colnames[i];    
22                 char* value = argv[i];  
23                 if (!strcmp(colname, "screen_width")) settings->screen.width = boost::lexical_cast<int>(value);
24                 else if (!strcmp(colname, "screen_height")) settings->screen.height = boost::lexical_cast<int>(value);
25                 else if (!strcmp(colname, "screen_mode")) settings->screen_mode = boost::lexical_cast<int>(value);
26                 else if (!strcmp(colname, "input_mode")) settings->input_mode = boost::lexical_cast<int>(value);
27                 else if (!strcmp(colname, "enable_output_frame")) settings->enable_output_frame = boost::lexical_cast<int>(value);
28                 else if (!strcmp(colname, "enable_output_audio")) settings->enable_output_audio = boost::lexical_cast<int>(value);
29                 else if (!strcmp(colname, "fps")) settings->fps = boost::lexical_cast<int>(value);
30         }
31         return 0;
32 }
33 //}}}
34 //{{{ LoadSettings
35 int LoadSettings(Settings* p)
36 {
37         int result;
38         sqlite3* db;
39         result = sqlite3_open("settings.db", &db);
40         if (SQLITE_OK != result) return 0;
41         static const char* sql = "SELECT * FROM settings WHERE id = 1";
42         char *err;
43         result = sqlite3_exec(db, sql, callback_load_settings, (void*)p, &err);
44         if (err) {
45                 std::cout << err << std::endl;
46                 free(err);
47         }
48         sqlite3_close(db);
49         if (SQLITE_OK != result) return 0;
50         return 1;
51 }
52 //}}}