1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
23 #include "DatabaseMgr.h"
24 #include "FieldImpls.h"
25 #include "GameVersion.h"
27 #include "Initializer.h"
28 #include "SavableHeaders.h"
29 #include "SqliteMgr.h"
30 #include "TableImpls.h"
32 const int MAXSIZE
= (1<<16);
33 char m_workspace
[MAXSIZE
];
35 extern bool g_shutdown
;
41 printf("Freeing global...\n");
43 printf("Freeing tables...\n");
45 printf("Freeing sqlitemgr...\n");
47 printf("Exiting...\n");
52 int main(int argc
, char** argv
)
60 std::string
param(argv
[1]);
61 if(!param
.substr(0, 11).compare("--examples="))
63 std::string rest
= param
.substr(11);
64 exampleSize
= atoi(rest
.c_str());
68 printf("Please specify an example size, '%s' is not a valid size.\n", rest
.c_str());
74 db::TableImpls::Get()->Initialize();
76 printf("%s database initializer for db v%s.\n", game::vname
, game::vstring
);
77 std::string dbname
= game::vname
;
80 printf("Opening or creating '%s'...\n", dbname
.c_str());
81 DatabaseMgr::Initialize(dbname
);
83 Initializer
init(DatabaseMgr::Get()->DB());
85 printf("Checking if database exists...\n");
86 bool initialized
= false;
88 succes
= SqliteMgr::Get()->databasePopulated();
91 printf("Database does not exist...\n");
92 printf("Creating tables...\n");
93 init
.InitTables(db::TableImpls::Get()->begin(), db::TableImpls::Get()->end());
97 printf("checking if database version matches...\n");
98 succes
= initialized
|| init
.VerifyDatabaseVersion();
101 printf("Database version does not match!\n");
102 printf("(Move the existing database if you wish to create a fresh copy)\n");
106 printf("Database is of most recent version!\n");
108 printf("Checking if tables match...\n");
109 succes
= init
.VerifyTables(db::TableImpls::Get()->begin(), db::TableImpls::Get()->end());
112 printf("Database tables are not up to date!\n");
113 printf("(Move the existing database if you wish to create a fresh copy)\n");
117 printf("Initializing database...\n");
120 printf("Initializing colours...\n");
123 printf("Initializing commands...\n");
128 printf("Initializing example...\n");
129 init
.InitSampleChunks(exampleSize
);
133 printf("Initializing space...\n");