Ejemplo n.º 1
0
// -----------------------------------------------------------------------------
// OpenDatabaseL()
// The function will open database
// -----------------------------------------------------------------------------
//
void CDcfRepSrv::OpenDatabaseL()
{
#ifdef _DRM_TESTING
    WriteL(_L8("OpenDatabaseL"));
#endif


    TInt err = CreateDataBase(iFs);
    if ( err==KErrAlreadyExists )
    {
        err = KErrNone;
    }

    User::LeaveIfError(iDbs.Connect());

#ifndef RD_MULTIPLE_DRIVE

    User::LeaveIfError(iDb.Open(iDbs,DataFile().FullName()));

#else // RD_MULTIPLE_DRIVE

    User::LeaveIfError(iDb.Open(iDbs,DataFile(iFs).FullName()));

#endif
}
Ejemplo n.º 2
0
// -----------------------------------------------------------------------------
// CreateDataBase
// Create database with client side database access
// -----------------------------------------------------------------------------
//
LOCAL_C TInt CreateDataBase(RFs& aFs)
{
#ifdef _DRM_TESTING
    TRAPD(r,WriteL(_L8("CreateDataBase")));
#endif

    RDbNamedDatabase database;
    TInt err = 0;
    TFileName file;

#ifndef RD_MULTIPLE_DRIVE

    file = DataFile().FullName();


#else // RD_MULTIPLE_DRIVE

    file = DataFile( aFs ).FullName();

#endif

    if (!err)
    {
#ifdef _DRM_TESTING
        TRAP(r,WriteL(_L8("CreateDataBase->DataFile"),err));
#endif
        err = CreateDataBasePath(aFs);

        err = database.Create(aFs,file);
        if (!err)
        {
#ifdef _DRM_TESTING
            TRAP(r,WriteL(_L8("CreateDataBase->database.Create"),err));
#endif
            TRAP( err , CreateTablesL(database) );
#ifdef _DRM_TESTING
            TRAP(r,WriteL(_L8("CreateDataBase->CreateTablesL"),err));
#endif
        }
        database.Close();
    }
    return err;
}
Ejemplo n.º 3
0
// -----------------------------------------------------------------------------
// CreateDataBasePath
// Create database with client side database access
// -----------------------------------------------------------------------------
//
LOCAL_C TInt CreateDataBasePath(RFs& aFs)
{
#ifdef _DRM_TESTING
    TRAPD(r,WriteL(_L8("CreateDataBasePath")));
#endif

    TInt err = 0;

#ifndef RD_MULTIPLE_DRIVE

    err = aFs.MkDirAll( DataFile(). DriveAndPath() );

#else //RD_MULTIPLE_DRIVE

    err = aFs.MkDirAll( DataFile( aFs ). DriveAndPath() );

#endif

    return err;
}
Ejemplo n.º 4
0
ALERROR CResourceDb::LoadEntities (CString *retsError)

//	LoadEntities
//
//	Loads the entities of a game file

	{
	ALERROR error;

	if (m_pMainDb == NULL)
		{
		if (m_bGameFileInDb && m_pDb)
			{
			ASSERT(m_pResourceMap);

			CString sGameFile;
			if ((error = m_pDb->ReadEntry(m_iGameFile, &sGameFile)))
				{
				*retsError = strPatternSubst(CONSTLIT("%s is corrupt"), m_sGameFile.GetASCIIZPointer());
				return error;
				}

			//	Parse the XML file from the buffer

			CBufferReadBlock GameFile(sGameFile);

			CString sError;
			if ((error = CXMLElement::ParseEntityTable(&GameFile, &m_Entities, &sError)))
				{
				*retsError = strPatternSubst(CONSTLIT("Unable to parse %s: %s"), m_sGameFile.GetASCIIZPointer(), sError.GetASCIIZPointer());
				return error;
				}
			}
		else
			{
			//	Parse the XML file on disk

			CFileReadBlock DataFile(pathAddComponent(m_sRoot, m_sGameFile));
			CString sError;

			if ((error = CXMLElement::ParseEntityTable(&DataFile, &m_Entities, &sError)))
				{
				*retsError = strPatternSubst(CONSTLIT("Unable to parse %s: %s"), m_sGameFile.GetASCIIZPointer(), sError.GetASCIIZPointer());
				return error;
				}
			}
		}

	return NOERROR;
	}
Ejemplo n.º 5
0
void TOrdEntryForm::ReadFile(TFileName OrderFile)
{
  ifstream DataFile(OrderFile.c_str());
  if (!DataFile) return;

  // avoid painting while file is loaded
  LockWindowUpdate(Handle);
  while (!DataFile.read((char *)&TR, sizeof(TR)).eof()) {
    AddRecord();
  }
  LockWindowUpdate(0);
  DataFile.close();
  OvcVirtualListbox1->Repaint();
  OvcVirtualListbox1->ItemIndex = 0;
}
Ejemplo n.º 6
0
ALERROR ParseGameFile (const CString &sFilename, CXMLElement **retpData)
	{
	ALERROR error;
	CFileReadBlock DataFile(sFilename);
	CString sError;

	printf("Parsing %s...", sFilename.GetASCIIZPointer());
	if (error = CXMLElement::ParseXML(&DataFile, retpData, &sError))
		{
		printf("\n%s\n", sError.GetASCIIZPointer());
		return error;
		}

	printf("done.\n");

	return NOERROR;
	}
Ejemplo n.º 7
0
ALERROR CHighScoreList::Save (const CString &sFilename)

//	Save
//
//	Save the high score list

	{
	ALERROR error;

	if (m_bModified)
		{
		CFileWriteStream DataFile(sFilename, FALSE);

		if (error = DataFile.Create())
			return error;

		//	Write the XML header

		CString sData = strPatternSubst(CONSTLIT("<?xml version=\"1.0\"?>\r\n\r\n<TranscendenceHighScores lastPlayerName=\"%s\" lastPlayerGenome=\"%d\">\r\n\r\n"),
				m_sMostRecentPlayerName,
				m_iMostRecentPlayerGenome);
		if (error = DataFile.Write(sData.GetPointer(), sData.GetLength(), NULL))
			return error;

		//	Loop over scores

		for (int i = 0; i < m_iCount; i++)
			{
			if (error = m_List[i].WriteToXML(DataFile))
				return error;
			}

		//	Done

		sData = CONSTLIT("\r\n</TranscendenceHighScores>\r\n");
		if (error = DataFile.Write(sData.GetPointer(), sData.GetLength(), NULL))
			return error;

		if (error = DataFile.Close())
			return error;
		}

	return NOERROR;
	}
Ejemplo n.º 8
0
ALERROR CHighScoreList::Load (const CString &sFilename)

//	Load
//
//	Load the high score list

	{
	ALERROR error;

	m_iCount = 0;

	//	Load XML

	CFileReadBlock DataFile(sFilename);
	CXMLElement *pData;
	CString sError;
	if (error = CXMLElement::ParseXML(&DataFile, &pData, &sError))
		//	Means we can't find it or is corrupt...
		return NOERROR;

	//	Get the most recent player name

	m_sMostRecentPlayerName = pData->GetAttribute(LAST_PLAYER_NAME_ATTRIB);
	m_iMostRecentPlayerGenome = CGameRecord::LoadGenome(pData->GetAttribute(LAST_PLAYER_GENOME_ATTRIB));

	//	Fill the structures

	for (int i = 0; i < pData->GetContentElementCount(); i++)
		{
		if (error = m_List[m_iCount].InitFromXML(pData->GetContentElement(i)))
			return error;

		m_iCount++;
		}

	m_bModified = false;

	//	Done

	delete pData;

	return NOERROR;
	}
Ejemplo n.º 9
0
CString CResourceDb::GetRootTag (void)

//	GetRootTag
//
//	Returns the tag of the root element (or NULL_STR if there is an error)

	{
	if (m_bGameFileInDb && m_pDb)
		{
		ASSERT(m_pResourceMap);

		int iReadSize = Min(m_pDb->GetEntryLength(m_iGameFile), 1024);

		CString sGameFile;
		if (m_pDb->ReadEntryPartial(m_iGameFile, 0, iReadSize, &sGameFile) != NOERROR)
			return NULL_STR;

		//	Parse the XML file from the buffer

		CBufferReadBlock GameFile(sGameFile);
		CString sTag;

		if (CXMLElement::ParseRootTag(&GameFile, &sTag) != NOERROR)
			return NULL_STR;

		return sTag;
		}
	else
		{
		//	Parse the XML file on disk

		CFileReadBlock DataFile(pathAddComponent(m_sRoot, m_sGameFile));
		CString sTag;

		if (CXMLElement::ParseRootTag(&DataFile, &sTag) != NOERROR)
			return NULL_STR;

		return sTag;
		}
	}
Ejemplo n.º 10
0
void ViewWithGNUplot::run(const std::string& Data,
                          const std::string& DateFormat,
                          const std::string& ColSeparator,
                          const std::string& CommentChar,
                          bool SingleWindow)
{

  if (DateFormat.find(ColSeparator) != std::string::npos)
  {
    openfluid::guicommon::DialogBoxFactory::showSimpleWarningMessage(_("Unable to plot file with GNUplot:\nColumn separator is present in date format."));
    return;
  }

  boost::filesystem::create_directories(boost::filesystem::path(openfluid::base::RuntimeEnvironment::getInstance()->getTempDir()));

  std::string DataFilename = boost::filesystem::path(openfluid::base::RuntimeEnvironment::getInstance()->getTempDir()+"/gprun.data").string();
  std::string ScriptFilename = boost::filesystem::path(openfluid::base::RuntimeEnvironment::getInstance()->getTempDir()+"/gprun.gp").string();

  std::ofstream DataFile(DataFilename.c_str());
  DataFile << Data;
  DataFile.close();

  std::map<std::string,unsigned int> VarColumns = getPlottableColumns(Data,ColSeparator,CommentChar);



  if (VarColumns.size() <1 )
  {
    openfluid::guicommon::DialogBoxFactory::showSimpleErrorMessage(_("No data found for plotting"));
    return;
  }


  std::map<std::string,unsigned int>::iterator bVC = VarColumns.begin();
  std::map<std::string,unsigned int>::iterator eVC = VarColumns.end();
  std::map<std::string,unsigned int>::iterator iVC;


  if (SingleWindow)
  {
    // determine columns and rows
    unsigned int Columns = 1;
    unsigned int Rows = 1;

    if (VarColumns.size() > 1)
    {
      Columns = (unsigned int)(std::ceil(std::sqrt(VarColumns.size())));
      Rows = (unsigned int)(std::ceil(double(VarColumns.size()) / double(Columns)));
    }


    // generate script
    std::ofstream ScriptFile(ScriptFilename.c_str());
    ScriptFile << "set nokey\n";
    ScriptFile << "set xdata time\n";
    ScriptFile << "set timefmt \"" << DateFormat << "\"\n";
    ScriptFile << "set datafile separator \"" << ColSeparator << "\n";
    ScriptFile << "set datafile commentschars \"" << CommentChar << "\n";
    ScriptFile << "set format x \"%Y-%m-%d\\n%H:%M:%S\"\n";
    ScriptFile << "set xtics autofreq font \",7\"\n";
    ScriptFile << "set ytics autofreq font \",7\"\n";

    ScriptFile << "set origin 0,0\n";
    ScriptFile << "set multiplot layout " << Rows << "," << Columns << " rowsfirst scale 1,1\n";

    for (iVC=bVC; iVC!=eVC;++iVC)
    {
      ScriptFile << "set title \"" << (*iVC).first << "\" font \",9\"\n";
      ScriptFile << "plot \""<< DataFilename << "\" using 1:"<< ((*iVC).second+2) <<" with lines\n";
    }

    ScriptFile << "unset multiplot\n";

    ScriptFile.close();

    if(system(std::string(m_GNUplotProgram + " --persist " + ScriptFilename).c_str()) != 0)
      openfluid::guicommon::DialogBoxFactory::showSimpleErrorMessage(_("GNUplot error"));
  }
  else
  {
    for (iVC=bVC; iVC!=eVC;++iVC)
    {
      // generate script
      std::ofstream ScriptFile(ScriptFilename.c_str());
      ScriptFile << "set nokey\n";
      ScriptFile << "set xdata time\n";
      ScriptFile << "set timefmt \"" << DateFormat << "\"\n";
      ScriptFile << "set datafile separator \"" << ColSeparator << "\n";
      ScriptFile << "set datafile commentschars \"" << CommentChar << "\n";
      ScriptFile << "set format x \"%Y-%m-%d\\n%H:%M:%S\"\n";
      ScriptFile << "set xtics autofreq font \",7\"\n";
      ScriptFile << "set ytics autofreq font \",7\"\n";
      ScriptFile << "set title \"" << (*iVC).first << "\" font \",9\"\n";
      ScriptFile << "plot \""<< DataFilename << "\" using 1:"<< ((*iVC).second+2) <<" with lines\n";
      ScriptFile.close();

      if(system(std::string(m_GNUplotProgram + " --persist " + ScriptFilename).c_str()) != 0)
        openfluid::guicommon::DialogBoxFactory::showSimpleErrorMessage(_("GNUplot error"));

    }
  }
}
Ejemplo n.º 11
0
ALERROR WriteModule (const CString &sFilename, 
					 const CString &sFolder, 
					 CExternalEntityTable *pEntityTable,
					 CSymbolTable &Resources, 
					 CDataFile &Out, 
					 int *retiModuleEntry)
	{
	ALERROR error;
	int i;

	//	Parse the file

	CXMLElement *pModule;
	CExternalEntityTable EntityTable;
	if (pEntityTable)
		{
		CFileReadBlock DataFile(sFilename);
		CString sError;

		printf("Parsing %s...", sFilename.GetASCIIZPointer());
		if (error = CXMLElement::ParseXML(&DataFile, pEntityTable, &pModule, &sError))
			{
			printf("\n%s\n", sError.GetASCIIZPointer());
			return error;
			}

		printf("done.\n");
		}
	else
		{
		CFileReadBlock DataFile(sFilename);
		CString sError;

		printf("Parsing %s...", sFilename.GetASCIIZPointer());
		if (error = CXMLElement::ParseXML(&DataFile, &pModule, &sError, &EntityTable))
			{
			printf("\n%s\n", sError.GetASCIIZPointer());
			return error;
			}

		pEntityTable = &EntityTable;
		printf("done.\n");
		}

	//	Write the module itself

	int iEntry;
	if (error = WriteGameFile(sFilename, Out, &iEntry))
		return error;

	//	If the caller doesn't want the module entry, then it means that this is
	//	a module (instead of the main file). If so, add it to the resources table

	if (retiModuleEntry == NULL)
		Resources.AddEntry(sFilename, (CObject *)iEntry);

	//	Store all the image resources

	if (error = WriteModuleImages(pModule, sFolder, Resources, Out))
		return error;

	//	Store all the sound resources

	if (error = WriteModuleSounds(pModule, sFolder, Resources, Out))
		return error;

	//	Store all modules

	CXMLElement *pModules = pModule->GetContentElementByTag(TAG_MODULES);
	if (pModules)
		{
		for (i = 0; i < pModules->GetContentElementCount(); i++)
			{
			CXMLElement *pItem = pModules->GetContentElement(i);

			CString sFilename = pItem->GetAttribute(ATTRIB_FILENAME);
			if (error = WriteModule(sFilename, sFolder, pEntityTable, Resources, Out, NULL))
				continue;
			}
		}

	//	Done

	if (retiModuleEntry)
		*retiModuleEntry = iEntry;

	return NOERROR;
	}
Ejemplo n.º 12
0
ALERROR WriteModule (CTDBCompiler &Ctx, 
					 const CString &sFilename, 
					 const CString &sFolder, 
					 CDataFile &Out, 
					 int *retiModuleEntry,
					 bool bCore)
	{
	ALERROR error;
	int i;

	//	Parse the file

	CXMLElement *pModule;
	CExternalEntityTable *pEntityTable = new CExternalEntityTable;
	CFileReadBlock DataFile(pathAddComponent(Ctx.GetRootPath(), sFilename));
	CString sError;

	printf("Parsing %s...", sFilename.GetASCIIZPointer());
	if (error = CXMLElement::ParseXML(&DataFile, Ctx.GetCoreEntities(), &pModule, &sError, pEntityTable))
		{
		printf("\n");
		Ctx.ReportError(sError);
		return error;
		}

	//	If this is a core module (embedded in the root XML) then we add these
	//	entities to the core. [Ctx takes ownership.]

	if (bCore)
		Ctx.AddEntityTable(pEntityTable);

	//	Chain entity tables (so that any modules that we load get the benefit).
	//	This will chain Ctx.pCoreEntities (and restore it in the destructor).
	//
	//	NOTE: If this is a core module, then we don't do this, since we've
	//	already added the entities to the context block.

	CSaveEntitiesTable SavedEntities(Ctx, (!bCore ? pEntityTable : NULL));

	printf("done.\n");

	//	Compress if this is NOT the main file. We can't compress the
	//	main file because we sometimes need to read it partially.

	bool bCompress = (retiModuleEntry == NULL);

	//	Write the module itself

	int iEntry;
	if (error = WriteGameFile(Ctx, sFilename, bCompress, Out, &iEntry))
		return error;

	//	If the caller doesn't want the module entry, then it means that this is
	//	a module (instead of the main file). If so, add it to the resources table

	if (retiModuleEntry == NULL)
		Ctx.AddResource(sFilename, iEntry, bCompress);

	//	Store all the image resources

	if (error = WriteModuleImages(Ctx, pModule, sFolder, Out))
		return error;

	//	Store all the sound resources

	if (error = WriteModuleSounds(Ctx, pModule, sFolder, Out))
		return error;

	//	Store all modules

	if (error = WriteSubModules(Ctx, pModule, sFolder, Out))
		return error;

	//	The root module may have a TranscendenceAdventure tag with modules in it

	for (i = 0; i < pModule->GetContentElementCount(); i++)
		{
		CXMLElement *pItem = pModule->GetContentElement(i);

		if (strEquals(pItem->GetTag(), TAG_CORE_LIBRARY)
				|| strEquals(pItem->GetTag(), TAG_TRANSCENDENCE_ADVENTURE) 
				|| strEquals(pItem->GetTag(), TAG_TRANSCENDENCE_LIBRARY))
			{
			//	If we have a filename, then we need to save the target as a
			//	module.

			CString sFilename;
			if (pItem->FindAttribute(ATTRIB_FILENAME, &sFilename))
				{
				//	Write out the module, making sure to set the core flag.

				if (error = WriteModule(Ctx, sFilename, sFolder, Out, NULL, true))
					return error;

				//	We ignore any other elements.

				continue;
				}

			//	Store all the image resources

			if (error = WriteModuleImages(Ctx, pItem, sFolder, Out))
				return error;

			//	Store all the sound resources

			if (error = WriteModuleSounds(Ctx, pItem, sFolder, Out))
				return error;

			//	Modules

			if (error = WriteSubModules(Ctx, pItem, sFolder, Out))
				return error;
			}
		}

	//	Done

	if (retiModuleEntry)
		*retiModuleEntry = iEntry;

	return NOERROR;
	}
Ejemplo n.º 13
0
ALERROR CGameSettings::Load (const CString &sFilespec, CString *retsError)

//	Load
//
//	Load game settings from a file. If the file does not exist, then we 
//	set settings to default values

	{
	ALERROR error;
	int i;

	//	Initialize from defaults

	for (i = 0; i < OPTIONS_COUNT; i++)
		SetValue(i, CString(g_OptionData[i].pszDefaultValue, -1, true), true);

	//	Look for a file in the current directory and see if it is writable. If
	//	not, then look in AppData. We remember the place where we found a valid
	//	file as our AppData root (and we base other directories off that).

	if (pathIsWritable(sFilespec))
		{
		//	AppData is current directory
		m_sAppData = NULL_STR;
		}
	else
		{
		m_sAppData = pathAddComponent(pathGetSpecialFolder(folderAppData), TRANSCENDENCE_APP_DATA);
		if (!pathCreate(m_sAppData)
				|| !pathIsWritable(m_sAppData))
			{
			*retsError = strPatternSubst(CONSTLIT("Unable to write to AppData folder: %s"), m_sAppData);
			return ERR_FAIL;
			}
		}

	//	Settings file

	CString sSettingsFilespec = pathAddComponent(m_sAppData, sFilespec);

	//	Load XML

	CFileReadBlock DataFile(sSettingsFilespec);
	CXMLElement *pData;
	CString sError;
	if (error = CXMLElement::ParseXML(&DataFile, &pData, retsError))
		{
		//	ERR_NOTFOUND means that we couldn't find the Settings.xml
		//	file. In that case, initialize from defaults

		if (error == ERR_NOTFOUND)
			{
			LoadFromRegistry();
			m_bModified = true;
			return NOERROR;
			}

		//	Otherwise, it means that we got an error parsing the file.
		//	Return the error, but leave the settings initialized to defaults
		//	(We should be OK to continue, even with an error).

		else
			{
			m_bModified = false;
			return error;
			}
		}

	//	Initialize to unmodified (as we load settings we might change this)

	m_bModified = false;

	//	Loop over all elements

	for (i = 0; i < pData->GetContentElementCount(); i++)
		{
		CXMLElement *pItem = pData->GetContentElement(i);

		if (strEquals(pItem->GetTag(), OPTION_TAG))
			{
			int iOption = FindOptionData(pItem->GetAttribute(NAME_ATTRIB));
			if (iOption == -1)
				{
				kernelDebugLogMessage("Unknown option: %s", pItem->GetAttribute(NAME_ATTRIB));
				continue;
				}

			SetValue(iOption, pItem->GetAttribute(VALUE_ATTRIB), true);
			}
		else if (strEquals(pItem->GetTag(), KEY_MAP_TAG))
			{
			if (error = m_KeyMap.ReadFromXML(pItem))
				return error;
			}
		else if (strEquals(pItem->GetTag(), EXTENSION_FOLDER_TAG))
			{
			CString sFolder;
			if (pItem->FindAttribute(PATH_ATTRIB, &sFolder))
				m_ExtensionFolders.Insert(sFolder);
			}
		else if (strEquals(pItem->GetTag(), EXTENSIONS_TAG))
			{
			if (error = m_Extensions.ReadFromXML(pItem))
				return error;
			}
		else if (m_pExtra)
			{
			bool bModified;
			if (error = m_pExtra->OnLoadSettings(pItem, &bModified))
				return error;

			if (bModified)
				m_bModified = true;
			}
		}

	//	Done

	delete pData;

	return NOERROR;
	}
Ejemplo n.º 14
0
void GenerateEntitiesTable (const CString &sDataFile, CXMLElement *pCmdLine)
	{
	int i;
	ALERROR error;

	CString sSourceFile;
	if (!pCmdLine->FindAttribute(FILE_ATTRIB, &sSourceFile))
		{
		printf("Specify file\n");
		return;
		}

	//	Open the data file and parse all entities

	CSymbolTable Entities(FALSE, TRUE);
	CFileReadBlock DataFile(CONSTLIT("Transcendence.xml"));

	if (error = DataFile.Open())
		{
		printf("Unable to open Transcendence.xml\n");
		return;
		}

	char *pPos = DataFile.GetPointer(0, -1);
	char *pEnd = pPos + DataFile.GetLength();

	//	Look for "<!ENTITY"

	CString sName;
	DWORD dwValue;
	while (NextEntity(&pPos, pEnd, &sName, &dwValue))
		Entities.AddEntry(sName, (CObject *)dwValue);

	DataFile.Close();

	//	Open the source file and look for all entity references

	CFileReadBlock SourceFile(sSourceFile);
	if (error = SourceFile.Open())
		{
		printf("Unable to open %s\n", sSourceFile.GetASCIIZPointer());
		return;
		}

	pPos = SourceFile.GetPointer(0, -1);
	pEnd = pPos + SourceFile.GetLength();

	//	Look for entity references

	CSymbolTable Output(TRUE, TRUE);
	while (NextEntityReference(&pPos, pEnd, &sName))
		{
		//	Look for this entity

		DWORD dwValue;
		if (Entities.Lookup(sName, (CObject **)&dwValue) == NOERROR)
			{
			//	Start with the entity keyword

			CString sOutput = strPatternSubst(CONSTLIT("\t<!ENTITY %s"), sName);

			//	Add tabs

			int iTabs = (40 - (sOutput.GetLength() + 3) + 3) / 4;
			if (iTabs)
				sOutput.Append(strRepeat(CONSTLIT("\t"), iTabs));
			else
				sOutput.Append(CONSTLIT(" "));

			//	Add the value

			char szBuffer[1024];
			wsprintf(szBuffer, "\"0x%08X\">\n", dwValue);
			sOutput.Append(CString(szBuffer));

			//	Output to the table (in UNID order)

			Output.AddEntry(CString(szBuffer), new CString(sOutput));
			}
		}

	SourceFile.Close();

	//	Output table

	for (i = 0; i < Output.GetCount(); i++)
		{
		CString *pLine = (CString *)Output.GetValue(i);
		printf(pLine->GetASCIIZPointer());
		}
	}
Ejemplo n.º 15
0
ALERROR CGameSettings::Load (const CString &sFilespec, CString *retsError)

//	Load
//
//	Load game settings from a file. If the file does not exist, then we 
//	set settings to default values

	{
	ALERROR error;
	int i;

	//	Initialize from defaults

	for (i = 0; i < OPTIONS_COUNT; i++)
		SetValue(i, CString(g_OptionData[i].pszDefaultValue, -1, true), true);

	//	Load XML

	CFileReadBlock DataFile(sFilespec);
	CXMLElement *pData;
	CString sError;
	if (error = CXMLElement::ParseXML(&DataFile, &pData, retsError))
		{
		//	ERR_NOTFOUND means that we couldn't find the Settings.xml
		//	file. In that case, initialize from defaults

		if (error == ERR_NOTFOUND)
			{
			LoadFromRegistry();
			m_bModified = true;
			return NOERROR;
			}

		//	Otherwise, it means that we got an error parsing the file.
		//	Return the error, but leave the settings initialized to defaults
		//	(We should be OK to continue, even with an error).

		else
			{
			m_bModified = false;
			return error;
			}
		}

	//	Initialize to unmodified (as we load settings we might change this)

	m_bModified = false;

	//	Loop over all elements

	for (i = 0; i < pData->GetContentElementCount(); i++)
		{
		CXMLElement *pItem = pData->GetContentElement(i);

		if (strEquals(pItem->GetTag(), OPTION_TAG))
			{
			int iOption = FindOptionData(pItem->GetAttribute(NAME_ATTRIB));
			if (iOption == -1)
				{
				kernelDebugLogMessage("Unknown option: %s", pItem->GetAttribute(NAME_ATTRIB).GetASCIIZPointer());
				continue;
				}

			SetValue(iOption, pItem->GetAttribute(VALUE_ATTRIB), true);
			}
		else if (strEquals(pItem->GetTag(), KEY_MAP_TAG))
			{
			if (error = m_KeyMap.ReadFromXML(pItem))
				return error;
			}
		else if (m_pExtra)
			{
			bool bModified;
			if (error = m_pExtra->OnLoadSettings(pItem, &bModified))
				return error;

			if (bModified)
				m_bModified = true;
			}
		}

	//	Done

	delete pData;

	return NOERROR;
	}
Ejemplo n.º 16
0
ALERROR CGameSettings::Save (const CString &sFilespec)

//	Save
//
//	Save game settings to a file (if necessary)

	{
	ALERROR error;

	if (!m_bModified)
		return NOERROR;

	//	Create the file

	CFileWriteStream DataFile(sFilespec, FALSE);
	if (error = DataFile.Create())
		return error;

	//	Write the XML header

	CString sData = CONSTLIT("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n\r\n<TranscendenceSettings>\r\n\r\n");
	if (error = DataFile.Write(sData.GetPointer(), sData.GetLength(), NULL))
		return error;

	//	Loop over options

	for (int i = 0; i < OPTIONS_COUNT; i++)
		{
		//	Don't bother saving if our current value is the same 
		//	as the default value

		if (strEquals(m_Options[i].sSettingsValue, CString(g_OptionData[i].pszDefaultValue, -1, true)))
			continue;

		//	Compose option element and write

		sData = strPatternSubst(CONSTLIT("\t<Option name=\"%s\"\tvalue=\"%s\"/>\r\n"),
				CString(g_OptionData[i].pszName, -1, true),
				m_Options[i].sSettingsValue);

		if (error = DataFile.Write(sData.GetPointer(), sData.GetLength(), NULL))
			return error;
		}

	//	Write the key map

	if (error = DataFile.Write("\r\n", 2, NULL))
		return error;

	if (error = m_KeyMap.WriteAsXML(&DataFile))
		return error;

	//	Write additional settings

	if (m_pExtra)
		{
		if (error = DataFile.Write("\r\n", 2, NULL))
			return error;

		if (error = m_pExtra->OnSaveSettings(&DataFile))
			return error;
		}

	//	Done

	sData = CONSTLIT("\r\n</TranscendenceSettings>\r\n");
	if (error = DataFile.Write(sData.GetPointer(), sData.GetLength(), NULL))
		return error;

	if (error = DataFile.Close())
		return error;

	return NOERROR;
	}
Ejemplo n.º 17
0
/*
ALERROR CResourceDb::LoadImage (const CString &sFolder, const CString &sFilename, HBITMAP *rethImage)

//	LoadImage
//
//	Loads an image and returns it

	{
	assert(0);
	}
*/
ALERROR CResourceDb::LoadModule (const CString &sFolder, const CString &sFilename, CXMLElement **retpData, CString *retsError)

//	LoadModule
//
//	Loads a module

	{
	ALERROR error;

	if (m_bGameFileInDb && m_pDb)
		{
		ASSERT(m_pResourceMap);

		CString sFilespec;
		if (m_iVersion >= 11)
			sFilespec = pathAddComponent(sFolder, sFilename);
		else
			sFilespec = sFilename;

		//	Look up the file in the map

		int iEntry;
		TRY(m_pResourceMap->Lookup(sFilespec, (CObject **)&iEntry));
		if (error)
			{
			*retsError = strPatternSubst(CONSTLIT("%s: Resource map corrupt."), m_sGameFile.GetASCIIZPointer());
			return error;
			}

		CString sGameFile;
		TRY(m_pDb->ReadEntry(iEntry, &sGameFile));
		if (error)
			{
			*retsError = strPatternSubst(CONSTLIT("%s: Unable to read entry: %d"), m_sGameFile.GetASCIIZPointer(), iEntry);
			return error;
			}

		//	Parse the XML file from the buffer

		CBufferReadBlock GameFile(sGameFile);
		CString sError;
		TRY(CXMLElement::ParseXML(&GameFile, &m_Entities, retpData, &sError));
		if (error)
			{
			*retsError = strPatternSubst(CONSTLIT("%s: %s"), m_sGameFile.GetASCIIZPointer(), sError.GetASCIIZPointer());
			return error;
			}
		}
	else
		{
		//	Parse the XML file on disk

		CFileReadBlock DataFile(pathAddComponent(m_sRoot, pathAddComponent(sFolder, sFilename)));
		CString sError;
		if ((error = CXMLElement::ParseXML(&DataFile, &m_Entities, retpData, &sError)))
			{
			*retsError = strPatternSubst(CONSTLIT("Unable to parse %s: %s"), sFilename.GetASCIIZPointer(), sError.GetASCIIZPointer());
			return error;
			}
		}

	return NOERROR;
	}
Ejemplo n.º 18
0
ALERROR CGameSettings::Save (const CString &sFilespec)

//	Save
//
//	Save game settings to a file (if necessary)

	{
	int i;
	ALERROR error;

	if (!m_bModified)
		return NOERROR;

	//	Settings file

	CString sSettingsFilespec = pathAddComponent(m_sAppData, sFilespec);

	//	Create the file

	CFileWriteStream DataFile(sSettingsFilespec, FALSE);
	if (error = DataFile.Create())
		return error;

	//	Write the XML header

	CString sData = CONSTLIT("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n\r\n<TranscendenceSettings>\r\n\r\n");
	if (error = DataFile.Write(sData.GetPointer(), sData.GetLength(), NULL))
		return error;

	//	Write extension folders

	if (m_ExtensionFolders.GetCount() > 0)
		{
		for (i = 0; i < m_ExtensionFolders.GetCount(); i++)
			{
			sData = strPatternSubst(CONSTLIT("\t<ExtensionFolder path=\"%s\"/>\r\n"), m_ExtensionFolders[i]);
			if (error = DataFile.Write(sData.GetPointer(), sData.GetLength()))
				return error;
			}

		if (error = DataFile.Write("\r\n", 2, NULL))
			return error;
		}

	//	Loop over options

	for (i = 0; i < OPTIONS_COUNT; i++)
		{
		//	Compose option element and write

		sData = strPatternSubst(CONSTLIT("\t<Option name=\"%s\"\tvalue=\"%s\"/>\r\n"),
				CString(g_OptionData[i].pszName, -1, true),
				strToXMLText(m_Options[i].sSettingsValue));

		if (error = DataFile.Write(sData.GetPointer(), sData.GetLength(), NULL))
			return error;
		}

	//	Write the key map

	if (error = DataFile.Write("\r\n", 2, NULL))
		return error;

	if (error = m_KeyMap.WriteAsXML(&DataFile))
		return error;

	//	Write the extensions list

	if (error = DataFile.Write("\r\n", 2))
		return error;

	if (error = m_Extensions.WriteAsXML(&DataFile))
		return error;

	//	Write additional settings

	if (m_pExtra)
		{
		if (error = DataFile.Write("\r\n", 2, NULL))
			return error;

		if (error = m_pExtra->OnSaveSettings(&DataFile))
			return error;
		}

	//	Done

	sData = CONSTLIT("\r\n</TranscendenceSettings>\r\n");
	if (error = DataFile.Write(sData.GetPointer(), sData.GetLength(), NULL))
		return error;

	if (error = DataFile.Close())
		return error;

	return NOERROR;
	}
Ejemplo n.º 19
0
int main( int argc, char* argv[] ) {


  if( argc > 1 ) {
    energy = atoi(argv[1]);
  }

  setStyle();

  std::string dataDir(Form("../data_%dGeV", energy));
  if( cef3_thickness==3. ) 
    dataDir = std::string(Form("../data_3mm_%dGeV", energy));

  std::vector<DataFile> dataFiles; 

  dataFiles.push_back(DataFile("EEShash_LYSO_tung25_nLayers28.root", dataDir) );

  if( cef3_thickness==5. ) {
    dataFiles.push_back(DataFile("EEShash_CeF3_tung15_nLayers34.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung20_nLayers28.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung25_nLayers24.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung30_nLayers21.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung35_nLayers19.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung40_nLayers17.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung45_nLayers16.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung50_nLayers14.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung55_nLayers13.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung60_nLayers12.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung65_nLayers12.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung70_nLayers11.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung75_nLayers10.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung80_nLayers10.root", dataDir) );
  } else if( cef3_thickness==3. ) {
    dataFiles.push_back(DataFile("EEShash_CeF3_tung30_nLayers24.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung35_nLayers21.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung40_nLayers19.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung45_nLayers17.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung50_nLayers15.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung55_nLayers14.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung60_nLayers13.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung65_nLayers12.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung70_nLayers12.root", dataDir) );
    dataFiles.push_back(DataFile("EEShash_CeF3_tung75_nLayers11.root", dataDir) );
    //dataFiles.push_back(DataFile("EEShash_CeF3_tung80_nLayers10.root", dataDir) );
  }


  std::string outputdir(Form("Plots_CeF3_vs_LYSO_%dGeV", energy));
  if( cef3_thickness!=5. )
    outputdir = std::string(Form("Plots_CeF3_vs_LYSO_%dGeV_%.0fmm", energy, cef3_thickness));
  system( Form("mkdir -p %s", outputdir.c_str()) );


  TGraphErrors* gr_mol = getMoliereGraph( dataFiles );
  TGraphErrors* gr_vol = getVolumeGraph( dataFiles );
  std::pair<TGraphErrors*, TGraphErrors*> gr_resp_reso = getResponseGraphs( outputdir, dataFiles );

  std::vector< TGraphErrors* > graphs;
  graphs.push_back( gr_mol );
  graphs.push_back( gr_vol );
  graphs.push_back( gr_resp_reso.first );
  graphs.push_back( gr_resp_reso.second );


  for( unsigned i=0; i<graphs.size(); ++i ) 
    drawSingleGraph( outputdir, graphs[i] ); 

  drawCompareAll( outputdir, graphs );



  return 0;

}