Gamerom

From LinuxMCE
Jump to: navigation, search
This article needs to be fixed and/or categorized.
Please contribute by fixing this article or other that needs to be fixed.


GAMEROM.h

/****************************************/
/* GAMEROM - Class to return metadata 	*/
/* For a given GAME ROM. 		*/
/*				      	*/
/* @author <thom.cherryhomes@gmail.com> */
/****************************************/

#define GAME_RELEASE 0.122u7

#include <string>
#include <map>
#include <iostream>

/* sql2cpp classes */
#include "lmce_game/Database_lmce_game.h"  
#include "lmce_game/Define_RomAttributeType.h"
#include "lmce_game/Define_Rom_RomAttribute.h"
#include "lmce_game/TableRow.h"
#include "lmce_game/Table_RomAttributeType.h"  
#include "lmce_game/Table_Rom_RomAttribute.h"
#include "lmce_game/Define_RomAttribute.h"   
#include "lmce_game/Define_Rom.h" 
#include "lmce_game/Define_GameSystem.h"      
#include "lmce_game/Table_RomAttribute.h"  
#include "lmce_game/Table_Rom.h"           
#include "lmce_game/Table_GameSystem.h"

#include "DCE/Logger.h"
#include "PlutoUtils/DBHelper.h"

using namespace std;

	class GAMEROM 
	{
	
			public:
			
			map<string,string> mRomTitleList, mRomYearList, mRomManufacturerList, mRomList, mRomGenreList;	
			Database_lmce_game *m_pMyDatabase;

			string getTitleForROM(string sROMName);
			string getYearForROM(string sROMName);
			string getManufacturerForROM(string sROMName);
			string getGenreForROM(string sROMName);		
			void InitDatabase();

	 		GAMEROM();	
			virtual ~GAMEROM();

	};

GAMEROM.cpp

/****************************************/
/* GAMEROM - Class to return metadata 	*/
/* For a given GAME ROM. 	  	*/
/*				      	*/
/* @author <thom.cherryhomes@gmail.com> */
/****************************************/

#include "GAMEROM.h"

GAMEROM::GAMEROM()
{

}


GAMEROM::~GAMEROM() 
{
}

void GAMEROM::InitDatabase()
{
	LoggerWrapper::GetInstance()->Write(LV_STATUS,"GAMEROM::InitDatabase() start");
    	m_pMyDatabase = new Database_lmce_game(LoggerWrapper::GetInstance());
	m_pMyDatabase->Connect("localhost","root","","lmce_game",3306);
	LoggerWrapper::GetInstance()->Write(LV_STATUS,"GAMEROM::InitDatabase() successful.");
}

string GAMEROM::getTitleForROM(string sROMName) 
{
	Row_Rom 				*pRow_Rom;
	Row_RomAttribute				*pRow_RomAttribute;
	vector<class Row_Rom *> 		v_Rom;	
	vector<class Row_Rom_RomAttribute *>	v_Rom_RomAttributes;
	string 					sRomName = sROMName + ".zip";
	string					s_WhereQuery = "WHERE Romname = '"+sRomName+"'";

	if (!m_pMyDatabase->Rom_get()->GetRows(s_WhereQuery,&v_Rom)) 
	{
		LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Could not get Rom matching ROMName: %s",sRomName.c_str());
		return "NOMATCH";
	} 

	if (v_Rom.size() == 0)
	{
		LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Could not get Rom matching ROMName: %s",sRomName.c_str());
		return "NOMATCH";
	}

	pRow_Rom = m_pMyDatabase->Rom_get()->GetRow(v_Rom[0]->PK_Rom_get());
	pRow_Rom->Rom_RomAttribute_FK_Rom_getrows(&v_Rom_RomAttributes);

	// Iterate through the resulting matching RomAttributes for a Rom
	for (unsigned int i=0;i<v_Rom_RomAttributes.size();i++) 
	{
		pRow_RomAttribute = m_pMyDatabase->RomAttribute_get()->GetRow(v_Rom_RomAttributes[i]->FK_RomAttribute_get());
		if (pRow_RomAttribute-> FK_RomAttributeType_get() == ROMATTRIBUTETYPE_title_CONST) 
		{
			return pRow_RomAttribute->Name_get();
		}
	}

	// Nothing was found, return a message.
	LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Could not Find Title RomAttribute for ROMName: %s",sRomName.c_str());
	return "NOMATCH";

}

string GAMEROM::getYearForROM(string sROMName)
{
	Row_Rom 				*pRow_Rom;
	Row_RomAttribute				*pRow_RomAttribute;
	vector<class Row_Rom *> 		v_Rom;	
	vector<class Row_Rom_RomAttribute *>	v_Rom_RomAttributes;
	string 					sRomName = sROMName + ".zip";
	string					s_WhereQuery = "WHERE Romname = '"+sRomName+"'";

	if (!m_pMyDatabase->Rom_get()->GetRows(s_WhereQuery,&v_Rom)) 
	{
		LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Could not get Rom matching ROMName: %s",sRomName.c_str());
		return "NOMATCH";
	} 

	if (v_Rom.size() == 0)
	{
		LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Could not get Rom matching ROMName: %s",sRomName.c_str());
		return "NOMATCH";
	}
	
	pRow_Rom = m_pMyDatabase->Rom_get()->GetRow(v_Rom[0]->PK_Rom_get());
	pRow_Rom->Rom_RomAttribute_FK_Rom_getrows(&v_Rom_RomAttributes);

	// Iterate through the resulting matching RomAttributes for a Rom
	for (unsigned int i=0;i<v_Rom_RomAttributes.size();i++) 
	{
		pRow_RomAttribute = m_pMyDatabase->RomAttribute_get()->GetRow(v_Rom_RomAttributes[i]->FK_RomAttribute_get());
		if (pRow_RomAttribute-> FK_RomAttributeType_get() == ROMATTRIBUTETYPE_year_CONST) 
		{
			return pRow_RomAttribute->Name_get();
		}
	}

	// Nothing was found, return a message.
	LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Could not Find Year RomAttribute for ROMName: %s",sRomName.c_str());
	return "NOMATCH";

}

string GAMEROM::getManufacturerForROM(string sROMName)
{
	Row_Rom 				*pRow_Rom;
	Row_RomAttribute				*pRow_RomAttribute;
	vector<class Row_Rom *> 		v_Rom;	
	vector<class Row_Rom_RomAttribute *>	v_Rom_RomAttributes;
	string 					sRomName = sROMName + ".zip";
	string					s_WhereQuery = "WHERE Romname = '"+sRomName+"'";

	if (!m_pMyDatabase->Rom_get()->GetRows(s_WhereQuery,&v_Rom)) 
	{
		LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Could not get Rom matching ROMName: %s",sRomName.c_str());
		return "NOMATCH";
	} 

	if (v_Rom.size() == 0)
	{
		LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Could not get Rom matching ROMName: %s",sRomName.c_str());
		return "NOMATCH";
	}
	
	pRow_Rom = m_pMyDatabase->Rom_get()->GetRow(v_Rom[0]->PK_Rom_get());
	pRow_Rom->Rom_RomAttribute_FK_Rom_getrows(&v_Rom_RomAttributes);

	// Iterate through the resulting matching RomAttributes for a Rom
	for (unsigned int i=0;i<v_Rom_RomAttributes.size();i++) 
	{
		pRow_RomAttribute = m_pMyDatabase->RomAttribute_get()->GetRow(v_Rom_RomAttributes[i]->FK_RomAttribute_get());
		if (pRow_RomAttribute-> FK_RomAttributeType_get() == ROMATTRIBUTETYPE_manufacturer_CONST) 
		{
			return pRow_RomAttribute->Name_get();
		}
	}

	// Nothing was found, return a message.
	LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Could not Find Manufacturer RomAttribute for ROMName: %s",sRomName.c_str());
	return "NOMATCH";
}

string GAMEROM::getGenreForROM(string sROMName)
{
	Row_Rom 				*pRow_Rom;
	Row_RomAttribute				*pRow_RomAttribute;
	vector<class Row_Rom *> 		v_Rom;	
	vector<class Row_Rom_RomAttribute *>	v_Rom_RomAttributes;
	string 					sRomName = sROMName + ".zip";
	string					s_WhereQuery = "WHERE Romname = '"+sRomName+"'";

	if (!m_pMyDatabase->Rom_get()->GetRows(s_WhereQuery,&v_Rom)) 
	{
		LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Could not get Rom matching ROMName: %s",sRomName.c_str());
		return "NOMATCH";
	} 

	if (v_Rom.size() == 0)
	{
		LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Could not get Rom matching ROMName: %s",sRomName.c_str());
		return "NOMATCH";
	}
	
	pRow_Rom = m_pMyDatabase->Rom_get()->GetRow(v_Rom[0]->PK_Rom_get());
	pRow_Rom->Rom_RomAttribute_FK_Rom_getrows(&v_Rom_RomAttributes);

	// Iterate through the resulting matching RomAttributes for a Rom
	for (unsigned int i=0;i<v_Rom_RomAttributes.size();i++) 
	{
		pRow_RomAttribute = m_pMyDatabase->RomAttribute_get()->GetRow(v_Rom_RomAttributes[i]->FK_RomAttribute_get());
		if (pRow_RomAttribute-> FK_RomAttributeType_get() == ROMATTRIBUTETYPE_genre_CONST) 
		{
			return pRow_RomAttribute->Name_get();
		}
	}

	// Nothing was found, return a message.
	LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Could not Find Genre RomAttribute for ROMName: %s",sRomName.c_str());
	return "NOMATCH";
}