Sorted Socket.
[UnsignedByte.git] / src / Initializer / main.cpp
blobeb9aa0248f219f770c02fda247290097080bcf66
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>
22 #include "SavableHeaders.h"
23 #include "FieldImpls.h"
24 #include "TableImpls.h"
26 #include "Global.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;
38 void exitfunc()
40 g_shutdown = true;
42 printf("Freeing global...\n");
43 Global::Free();
44 printf("Freeing tables...\n");
45 Tables::Free();
46 printf("Freeing sqlitemgr...\n");
47 SqliteMgr::Free();
48 printf("Exiting...\n");
49 // std::cin.get();
50 return;
53 int main(int argc, char** argv)
55 atexit(exitfunc);
57 int exampleSize = 0;
59 if(argc > 1)
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());
67 if(exampleSize <= 0)
69 printf("Please specify an example size, '%s' is not a valid size.\n", rest.c_str());
70 return -1;
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;
79 dbname.append(".db");
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;
88 bool succes;
89 succes = SqliteMgr::Get()->databasePopulated();
90 if(!succes)
92 printf("Database does not exist...\n");
93 printf("Creating tables...\n");
94 init.InitTables(db::TableImpls::Get()->begin(), db::TableImpls::Get()->end());
95 initialized = true;
98 printf("checking if database version matches...\n");
99 succes = initialized || init.VerifyDatabaseVersion();
100 if(!succes)
102 printf("Database version does not match!\n");
103 printf("(Move the existing database if you wish to create a fresh copy)\n");
104 return 1;
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());
111 if(!succes)
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");
115 return 1;
118 printf("Initializing database...\n");
119 init.InitDatabase();
121 printf("Initializing colours...\n");
122 init.InitColours();
124 printf("Initializing commands...\n");
125 init.InitCommands();
127 if(exampleSize > 0)
129 printf("Initializing example...\n");
130 init.InitSampleChunks(exampleSize);
132 else
134 printf("Initializing space...\n");
135 init.InitSpace();
138 return 0;