Exemple #1
0
bool GVDBBulletin::Store (GVdb * db, hDB handle)
{
	wxASSERT (m_turn != -1);

	SQLiteFile* sql = db->GetSQL(handle);
	if(!sql) {
		return false;
	}

	Query q = sql->GetQuery();

	q << "DELETE FROM bulletins WHERE turn=" << m_turn;
	if (!q.Execute()) {
		return false;
	}

	for (unsigned int i = 0; i < m_bulletins.GetCount (); i++) {
		wxString bulletin = m_bulletins[i];
		GVdb::EscapeSQL(bulletin);
		q << "INSERT INTO bulletins VALUES(" << m_turn << ", " << i
			<< ", \'" << bulletin.c_str() << "\')";

		if (!q.Execute()) {
			return false;
		}

	}
	return true;
}
Exemple #2
0
bool GVFrame::NewGame (wxString gamename, wxString turn0, wxString type)
{
	wxFileConfig *cf = (wxFileConfig *)wxConfigBase::Get (false);

	// create database
	wxString turnDir = cf->Read (_("/") + gamename + _("/GameDir"), "");
	if (turnDir.IsEmpty ()) {
		// GameDirectory is Empty
		return false;
	}

	// get game directory
	wxString gameDir = cf->Read(_T("/GalaxyView/GameDirectory"), "");
	if(gameDir.IsEmpty()) {
		return false;
	}

	// create turn directory if it doesnt exist
	if (!::wxDirExists (turnDir)) {
		::wxMkdir (turnDir);
	}

	// create game directory if it doesn't exist
	if(!::wxDirExists(gameDir)) {
		::wxMkdir(gameDir);
	}

	wxString dbfilename = gameDir + _("/") + gamename + _(".gdf"); 
	m_currentDB = m_db->Open (gamename, dbfilename);

	long game_init = cf->Read (_("/") + gamename + _("/Initialized"), 0L);
	if (!game_init) {
		// TODO: Database Init.
		GVApp::DBInit (m_db, m_currentDB);

		// Set initialized = 1
		cf->Write (_("/") + gamename + _("/Initialized"), 1L);

		// set show as active
		cf->Write (_("/") + gamename + _("/Active"), 1L);

		::wxSetCursor (*wxHOURGLASS_CURSOR);

		if(type=="GalaxyNG") {

			// Parse First Report - TODO: game types
			GVGalaxyNGReport* p = new GVGalaxyNGReport;

			if (p->ParseReport(m_db, m_currentDB, turn0)) {
				wxLogMessage (_T ("Turn Imported Into Database"));
			}
			else {
				wxLogMessage (_T ("Error Parsing"));
			}

			// Now Write additional data to the database (preferencesgame)
			SQLiteFile* sql = m_db->GetSQL(m_currentDB);
			if(!sql) return false;

			Query q = sql->GetQuery();

			// If there are already settings delete them
			q << "SELECT * FROM preferencesgame";
			Result res = q.Store();
			if(!res.Empty()) {
				q << "DELETE * FROM preferencesgame";
				q.Execute();
			}

			GVApp::GetGalaxy()->SetDatabase(m_db, m_currentDB);

			GVGalaxyNGFeatures* f = p->GetFeatures();

			GVGameData settings;
			settings.password = p->GetPassword();
			settings.gametype = "GalaxyNG";
			settings.gamename = p->GetGamename();
			settings.homeplanesnum = 0; /* TODO: Read from dialog */
			settings.homeplanetssize = ""; /* TODO: Read from dialog */
			settings.racename = p->GetPlayerRace();
			settings.size = f->size;

			GVApp::GetGalaxy()->GetGame()->Save(&settings);
			if(settings.valid) {
				wxLogMessage("Updated Preferences");
			} else {
				wxLogMessage("Failed to Update Preferences");
			}

			m_currentTurn = p->GetTurn();

			GVApp::GetGalaxy()->LoadTurn(m_currentTurn);
			m_map->SetMapSize(settings.size);
			m_map->SetTurn(m_currentTurn);

			delete p;

		} else {
			wxMessageBox("Gametype " + type + " not supported yet.", "Sorrry :(");
			return false;
		}

		::wxSetCursor (*wxSTANDARD_CURSOR);

	}	


	// setup ini file
	wxString gameList;
	cf->Read (_T ("/GalaxyView/Games"), &gameList);
	if (gameList.IsEmpty ()) {
		gameList = gamename;
	}
	else {
		gameList.Append (_(",") + gamename);
	}
	cf->Write (_T ("/GalaxyView/Games"), gameList);
	cf->Write (_T ("/GalaxyView/CurrentGame"), gamename);

	return true;
}