Example #1
0
bool CvXMLLoadUtilityModTools::isExcludedFile(const char* szLocationName)
{
	CvString szLocationNameStripDot = szLocationName;
	CvString szLocationNameStripTemp = szLocationName;	

	string::size_type posDot = szLocationNameStripDot.find_last_of('.');

	if(posDot != string::npos) 
	{		
		//force lowercase for comparison
		int length = szLocationNameStripDot.size();
		for (int i = 0; i < length; ++i)
		{
			szLocationNameStripTemp[length - (i + 1)] = tolower(szLocationNameStripDot[i]);
		}
		string::size_type posDot = szLocationNameStripTemp.find_last_of('.');
		//delete everything after first dir
		szLocationNameStripTemp.erase(posDot);
		//compare
		if ( szLocationNameStripTemp == "mht" )  //if its a thema file, force static linking
		{
#ifdef _DEBUG
		CvXMLLoadUtility* p_szLogWrite = new CvXMLLoadUtility;
		p_szLogWrite->XmlArtTagVerification("You are now loading an alternative theme: %s", szLocationName);
		SAFE_DELETE(p_szLogWrite);
#endif
			return true;
		}
	}
	return false;
}
Example #2
0
void CvXMLLoadUtilityModTools::writeThm(const char* szTextVal)
{	
	CvString tszTextVal = szTextVal;
	int posCut;
	string::size_type posBackSlash = tszTextVal.find_last_of('\\');
	string::size_type posSlashForw = tszTextVal.find_last_of('/');

	if (posBackSlash > posSlashForw)
	{
		posCut = posBackSlash;
	}
	else
	{
		posCut = posSlashForw;
	}

	if(posCut != string::npos) 
	{
		tszTextVal.erase(posCut);
	}
	else
	{
		FAssertMsg(false, "Something went wrong with the Theme file");
	}
	
	FILE *pFile = fopen(szTextVal, "w");

	if (pFile == NULL) 
	{
/*
#ifdef _DEBUG
		CvString szPrint = GetProgramDir();
		szPrint.append(szTextVal);
		CvXMLLoadUtility* p_szLogWrite = new CvXMLLoadUtility;
		p_szLogWrite->XmlArtTagVerification("Your Theme file: %s seems to be corrupted", szPrint.GetCString());
		SAFE_DELETE(p_szLogWrite);
#endif
*/
	}
	
	//set the proper string to write to the Theme file	
	CvString szOutput = "resource_path\t";	
	szOutput.append("\"");
	szOutput.append(tszTextVal);
	szOutput.append("\";\n");
	szOutput.append("\n");
	szOutput.append("include\t");
	szOutput.append("\"");
	szOutput.append(tszTextVal);
	szOutput.append("\\Themes\\Civ4\\Civ4Theme.thm");	
	szOutput.append("\";\n");

	//write the file
	fputs(szOutput, pFile);
	fclose(pFile);
}
Example #3
0
CvString CvXMLLoadUtilityModTools::deleteFileName(const char* szDirName, const char szLocateChar)
{	
	CvString szDirNameStrip = szDirName;
	string::size_type pos = szDirNameStrip.find_last_of(szLocateChar);
	if(pos != string::npos) 
	{
		szDirNameStrip.erase(pos + 1);
	}
	else
	{
		FAssertMsg(false, "Couldn't find the directory slash")
	}

	return szDirNameStrip;
}
Example #4
0
// Fully based on CString
CvString CvXMLLoadUtilityModTools::GetProgramDir()
{
	CvString szExeLocation = _pgmptr;
	if ( szExeLocation == NULL)
	{
		FAssertMsg(false, "Not running Stdlib Compatible Operating System?");
	}
	
	string::size_type posDot = szExeLocation.find_last_of('\\');

	if(posDot != string::npos) 
	{
		szExeLocation.erase(posDot + 1);
	}

	return szExeLocation;
}
Example #5
0
bool CvXMLLoadUtilityModTools::isCommaFile(CvString *pszTextVal, const char* szDirName)
{
#if (DEBUG_IS_MODULAR_ART == 1)
	CvString szDebugBuffer;
	szDebugBuffer.Format("=== isCommaFile BEGIN ===");
	gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());

	szDebugBuffer.Format(" Text value: %s,  Directory name: '%s'", pszTextVal->c_str(), szDirName);
	gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());
#endif

	string::size_type posComma = (*pszTextVal).find_first_of(',');

	if(posComma != string::npos) //if no comma found at all, return false
	{

#if (DEBUG_IS_MODULAR_ART == 1)
		szDebugBuffer.Format(" Found a ',' at position %i (total length %i)", (int)posComma, (*pszTextVal).GetLength());
		gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());
#endif
		CvString szTempLocation;
		CvString szAppend = " ";
		int iCountComma = 0;
		CvString szLocationNameStripComma;
		// Check how many comma's we have in the string and how many Button Files		

#if (DEBUG_IS_MODULAR_ART == 1)
		std::vector<CvString> asTagParts;
		pszTextVal->getTokens(CvString(","), asTagParts);
		iCountComma = asTagParts.size();

		szDebugBuffer.Format(" Total number of ',' in pszTextVal: %i", iCountComma);
		gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());
		for (std::vector<CvString>::iterator it = asTagParts.begin(); it != asTagParts.end(); it++)
		{
			szDebugBuffer.Format("  - Token %s", (*it).c_str());
			gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());
		}
#else
		szLocationNameStripComma = *pszTextVal;
		for ( int i = 0; i < szLocationNameStripComma.GetLength(); i++)
		{
			if (szLocationNameStripComma[i] == 44) // "," = 44 (ASCII)
			{
			  iCountComma++;
			}
		}		
#endif

		

#if (DEBUG_IS_MODULAR_ART == 1)
		CvString szButtonsString;
		for (std::vector<CvString>::iterator it = asTagParts.begin(); it != asTagParts.end(); it++)
		{
			bool bDigitsOnly = true;
			for (int i = 0; i < (*it).GetLength(); i++)
			{
				if (!isdigit((*it)[i]))
					bDigitsOnly = false;
			}
			if (!bDigitsOnly)
				szButtonsString += ((*it) + ",");
		}
		// Eliminate comma at end of string, if there is one
		if (szButtonsString.GetLength() > 0 && szButtonsString[szButtonsString.GetLength()] == ',')
			szButtonsString = szButtonsString.substr(0, szButtonsString.GetLength() - 1);

		szDebugBuffer.Format(" Button art string after eliminating numerical indices: %s", szButtonsString.c_str());
		gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());

#else
		// determine the append string at the end of the tag
		bool bContinue = true;
		szTempLocation = *pszTextVal;
		while ( bContinue)
		{
			posComma = szTempLocation.find_first_of(',');
			if(posComma != string::npos) //Prevent Null pointer deletion
			{
				szTempLocation = szTempLocation.substr(szTempLocation.find(",")+1);
				if (isdigit(szTempLocation[0]))  //We found the Append
				{					
					bContinue = false;
				}
			}
			else break;			
		}
		if (!bContinue )
		{
			szAppend = "," + szTempLocation;
		}
#endif

std::vector<CvString> vecButtonArtFile;
#if (DEBUG_IS_MODULAR_ART == 1)
	szButtonsString.getTokens(CvString(","), vecButtonArtFile);
	szDebugBuffer.Format(" Button art vector size after tokenizing by ',': %i", vecButtonArtFile.size());
	gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());
#else
		// set Button Array
		// Array to hold the Button art files
		CvString szTempLocationSubstr;
		szTempLocation = *pszTextVal;
		while (true)
		{
			posComma = szTempLocation.find_first_of(',');
			if(posComma != string::npos) //Prevent Null pointer deletion
			{
				if (szTempLocation[0] == 44) // "," = 44 (ASCII)
				{
					szTempLocation = szTempLocation.substr(szTempLocation.find(",")+1);
				}
				szTempLocationSubstr = szTempLocation;
				posComma = szTempLocationSubstr.find_first_of(',');
				if(posComma != string::npos) //Prevent Null pointer deletion
				{
					szTempLocationSubstr.erase(posComma);
					if (!isdigit(szTempLocationSubstr[0]))
					{
						vecButtonArtFile.push_back(szTempLocationSubstr);
					}
					else break;
				}
				szTempLocation = szTempLocation.substr(szTempLocation.find(",")+1);
			}
			else if (szTempLocation.GetLength() >= 1)
			{
				if (!isdigit(szTempLocationSubstr[0]))
				{
					vecButtonArtFile.push_back(szTempLocationSubstr);
				}
				break;
			}
			else break;
		}		
#endif

		//Check if we need to modularize the files
		bool bNeedChange = false;
/************************************************************************************************/
/* Afforess	                  Start		 06/15/10                                               */
/*                                                                                              */
/*                                                                                              */
/************************************************************************************************/
		CvString m_szFolderPath = GC.getInitCore().getDLLPath() + "//";
/************************************************************************************************/
/* Afforess	                     END                                                            */
/************************************************************************************************/

		m_szFolderPath += szDirName;			// "Modules\Modules\ModuleXXX" 
		for ( unsigned int i = 0; i < vecButtonArtFile.size(); i++)
		{
			szTempLocation = m_szFolderPath;
			szTempLocation += vecButtonArtFile[i];
			//set the Slash properly
			for ( int j = 0; j < szTempLocation.GetLength(); j++)
			{
				if ( szTempLocation[j] == 47)  // 47 = "/"
				{
					szTempLocation[j] = 92;  //92 = "\\", actually 1 backslash of course
				}
			}

			FILE *file = fopen(szTempLocation , "rb");
			if (file != NULL)
			{
				vecButtonArtFile[i] = szDirName + vecButtonArtFile[i];
				fclose(file);
				bNeedChange = true;
			}
		}

		// Now set the new tag string properly
		if (bNeedChange)
		{
			if (szLocationNameStripComma[0] == 44)
			{
				szTempLocation = ",";
			}
			else
			{
				szTempLocation = 0;
			}
			for ( unsigned int i = 0; i < vecButtonArtFile.size(); i++)
			{
				if (i != 0) szTempLocation += ",";
				szTempLocation += vecButtonArtFile[i];
			}
			if (szAppend[0] == 44)   // "," = 44 (ASCII)
			{
				szTempLocation += szAppend;
			}
			*pszTextVal = szTempLocation;
			return true;
		}	
	} 
	return false;
}