Added a EditorSocial.
[UnsignedByte.git] / src / Initializer / main.cpp
blob3b62518c36a14bf608cd1939aae61e9f2037a5ba
1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
21 #include <iostream>
23 #include "DatabaseMgr.h"
24 #include "FieldImpls.h"
25 #include "GameVersion.h"
26 #include "Global.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;
37 void exitfunc()
39 g_shutdown = true;
41 printf("Freeing global...\n");
42 Global::Free();
43 printf("Freeing tables...\n");
44 Tables::Free();
45 printf("Freeing sqlitemgr...\n");
46 SqliteMgr::Free();
47 printf("Exiting...\n");
48 // std::cin.get();
49 return;
52 int main(int argc, char** argv)
54 atexit(exitfunc);
56 int exampleSize = 0;
58 if(argc > 1)
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());
66 if(exampleSize <= 0)
68 printf("Please specify an example size, '%s' is not a valid size.\n", rest.c_str());
69 return -1;
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;
78 dbname.append(".db");
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;
87 bool succes;
88 succes = SqliteMgr::Get()->databasePopulated();
89 if(!succes)
91 printf("Database does not exist...\n");
92 printf("Creating tables...\n");
93 init.InitTables(db::TableImpls::Get()->begin(), db::TableImpls::Get()->end());
94 initialized = true;
97 printf("checking if database version matches...\n");
98 succes = initialized || init.VerifyDatabaseVersion();
99 if(!succes)
101 printf("Database version does not match!\n");
102 printf("(Move the existing database if you wish to create a fresh copy)\n");
103 return 1;
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());
110 if(!succes)
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");
114 return 1;
117 printf("Initializing database...\n");
118 init.InitDatabase();
120 printf("Initializing colours...\n");
121 init.InitColours();
123 printf("Initializing commands...\n");
124 init.InitCommands();
126 if(exampleSize > 0)
128 printf("Initializing example...\n");
129 init.InitSampleChunks(exampleSize);
131 else
133 printf("Initializing space...\n");
134 init.InitSpace();
137 return 0;