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 ***************************************************************************/
22 #include "SavableHeaders.h"
23 #include "FieldImpls.h"
24 #include "TableImpls.h"
27 #include "DatabaseMgr.h"
28 #include "SqliteMgr.h"
30 #include "Initializer.h"
31 #include "GameVersion.h"
33 const int MAXSIZE
= (1<<16);
34 char m_workspace
[MAXSIZE
];
36 extern bool g_shutdown
;
42 printf("Freeing global...\n");
44 printf("Freeing tables...\n");
46 printf("Freeing sqlitemgr...\n");
48 printf("Exiting...\n");
53 int main(int argc
, char** argv
)
61 std::string
param(argv
[1]);
62 if(!param
.substr(0, 11).compare("--examples="))
64 std::string rest
= param
.substr(11);
65 exampleSize
= atoi(rest
.c_str());
69 printf("Please specify an example size, '%s' is not a valid size.\n", rest
.c_str());
75 db::TableImpls::Get()->Initialize();
77 printf("%s database initializer for db v%s.\n", game::vname
, game::vstring
);
78 std::string dbname
= game::vname
;
81 printf("Opening or creating '%s'...\n", dbname
.c_str());
82 DatabaseMgr::Initialize(dbname
);
84 Initializer
init(DatabaseMgr::Get()->DB());
86 printf("Checking if database exists...\n");
87 bool initialized
= false;
89 succes
= SqliteMgr::Get()->databasePopulated();
92 printf("Database does not exist...\n");
93 printf("Creating tables...\n");
94 init
.InitTables(db::TableImpls::Get()->begin(), db::TableImpls::Get()->end());
98 printf("checking if database version matches...\n");
99 succes
= initialized
|| init
.VerifyDatabaseVersion();
102 printf("Database version does not match!\n");
103 printf("(Move the existing database if you wish to create a fresh copy)\n");
107 printf("Database is of most recent version!\n");
109 printf("Checking if tables match...\n");
110 succes
= init
.VerifyTables(db::TableImpls::Get()->begin(), db::TableImpls::Get()->end());
113 printf("Database tables are not up to date!\n");
114 printf("(Move the existing database if you wish to create a fresh copy)\n");
118 printf("Initializing database...\n");
121 printf("Initializing colours...\n");
124 printf("Initializing commands...\n");
129 printf("Initializing example...\n");
130 init
.InitSampleChunks(exampleSize
);
134 printf("Initializing space...\n");