Example #1
0
char *GetResStr(const char *id, const char *strTable)
{
	const char *pos;
	// Default
	sprintf(strResult, "[Undefined:%s]", id);
	// Compose identifier with operator
	char idExt[256 + 1 + 1]; SCopy(id, idExt, 256); SAppendChar('=', idExt);
	// String table present and id not empty
	if (strTable && id && id[0])
		// Search for identifier with operator
		if ((pos = SSearch(strTable, idExt)))
			// Get string until end of line
			SCopyUntil(pos, strResult, "\r\n", ResStrMaxLen);
	// Compile line feeds ("\n" -> 0D0A)
	pos = strResult;
	while ((pos = SSearch(pos, "\\n")))
		{ ((char*)pos)[-2] = 0x0D; ((char*)pos)[-1] = 0x0A; }
#ifdef _DEBUG
#ifdef _MSC_VER
	if (SEqual2(strResult, "[Undefined:"))
		if (!SEqual(id, "IDS_LANG_CHARSET"))
			{
			/* __asm int 3 */
			}
#endif
#endif
	// Return string
	return strResult;
}
void SetClientPrefix(char *szFilename, const char *szClient)
{
	char szTemp[1024+1];
	// Compose prefix
	char szPrefix[1024+1];
	SCopy(szClient,szPrefix); SAppendChar('-',szPrefix);
	// Prefix already set?
	SCopy(GetFilename(szFilename),szTemp,SLen(szPrefix));
	if (SEqualNoCase(szTemp,szPrefix)) return;
	// Insert prefix
	SCopy(GetFilename(szFilename),szTemp);
	SCopy(szPrefix,GetFilename(szFilename));
	SAppend(szTemp,szFilename);
}
Example #3
0
BOOL C4UpdatePackage::DoGrpUpdate(C4Group *pUpdateData, C4GroupEx *pGrpTo) {
    char *pData;
    // sort entries
    if (pUpdateData->LoadEntry(C4CFN_UpdateEntries, &pData, NULL, 1)) {
        // delete all entries that do not appear in the entries list
        char strItemName[_MAX_FNAME + 1], strItemName2[_MAX_FNAME + 1];
        pGrpTo->ResetSearch();
        while (pGrpTo->FindNextEntry("*", strItemName)) {
            BOOL fGotIt = FALSE;
            for (int i = 0;
                    fGotIt = SCopySegment(pData, i, strItemName2, '|', _MAX_FNAME);
                    i++) {
                // remove seperator
                char *pSep = strchr(strItemName2, '=');
                if (pSep) *pSep = '\0';
                // in list?
                if (SEqual(strItemName, strItemName2)) break;
            }
            if (!fGotIt) pGrpTo->DeleteEntry(strItemName);
        }
        // set entry times, set sort list
        char strSortList[32767] = "";
        for (int i = 0; SCopySegment(pData, i, strItemName, '|', _MAX_FNAME); i++) {
            // get time (if given)
            char *pTime = strchr(strItemName, '=');
            if (pTime) *pTime++ = '\0';
            // set
            if (pTime) pGrpTo->SetEntryTime(strItemName, atoi(pTime));
            // update EntryCRC32. This will make updates to old groups invalid
            // however, it's needed so updates will update the EntryCRC of *unchanged*
            // files correctly
            pGrpTo->EntryCRC32(strItemName);
            // copy to sort list
            SAppend(strItemName, strSortList);
            SAppendChar('|', strSortList);
        }
        // sort by list
        pGrpTo->Sort(strSortList);
        delete[] pData;
    }
    // copy header from update group
    pGrpTo->SetHead(*pUpdateData);
    // ok
    return TRUE;
}
Example #4
0
bool C4UpdatePackage::DoGrpUpdate(C4Group *pUpdateData, C4GroupEx *pGrpTo)
{
	char *pData;
	// sort entries
	if (pUpdateData->LoadEntry(C4CFN_UpdateEntries, &pData, nullptr, 1))
	{
		// delete all entries that do not appear in the entries list
		char strItemName[_MAX_FNAME+1], strItemName2[_MAX_FNAME+1];
		pGrpTo->ResetSearch();
		while (pGrpTo->FindNextEntry("*", strItemName))
		{
			bool fGotIt = false;
			for (int i = 0; (fGotIt = SCopySegment(pData, i, strItemName2, '|', _MAX_FNAME)); i++)
			{
				// remove separator
				char *pSep = strchr(strItemName2, '=');
				if (pSep) *pSep = '\0';
				// in list?
				if (SEqual(strItemName, strItemName2))
					break;
			}
			if (!fGotIt)
				pGrpTo->DeleteEntry(strItemName);
		}
		// set entry times, set sort list
		char strSortList[32767] = "";
		for (int i = 0; SCopySegment(pData, i, strItemName, '|', _MAX_FNAME); i++)
		{
			// strip checksum/time (if given)
			char *pTime = strchr(strItemName, '=');
			if (pTime) *pTime = '\0';
			// copy to sort list
			SAppend(strItemName, strSortList);
			SAppendChar('|', strSortList);
		}
		// sort by list
		pGrpTo->Sort(strSortList);
		delete[] pData;
	}
	// copy header from update group
	pGrpTo->SetHead(*pUpdateData);
	// ok
	return true;
}
Example #5
0
// Construct full path
void C4ComponentHost::CopyFilePathFromGroup(const C4Group &hGroup) {
  SCopy(pConfig->AtExeRelativePath(hGroup.GetFullName().getData()), FilePath,
        _MAX_PATH - 1);
  SAppendChar(DirectorySeparator, FilePath);
  SAppend(Filename, FilePath, _MAX_PATH);
}
Example #6
0
C4GroupSet C4Language::GetPackGroups(C4Group & hGroup)
{
	// Build a group set containing the provided group and
	// alternative groups for cross-loading from a language pack
	char strRelativePath[_MAX_PATH + 1];
	char strTargetLocation[_MAX_PATH + 1];
	char strPackPath[_MAX_PATH + 1];
	char strPackGroupLocation[_MAX_PATH + 1];
	char strAdvance[_MAX_PATH + 1];

	// Store wanted target location
	SCopy(Config.AtRelativePath(hGroup.GetFullName().getData()), strRelativePath, _MAX_PATH);
	SCopy(strRelativePath, strTargetLocation, _MAX_PATH);

	// Adjust location by scenario origin
	if (Game.C4S.Head.Origin.getLength() && SEqualNoCase(GetExtension(Game.C4S.Head.Origin.getData()), "ocs"))
	{
		const char *szScenarioRelativePath = GetRelativePathS(strRelativePath, Config.AtRelativePath(Game.ScenarioFilename));
		if (szScenarioRelativePath != strRelativePath)
		{
			// this is a path within the scenario! Change to origin.
			size_t iRestPathLen = SLen(szScenarioRelativePath);
			if (Game.C4S.Head.Origin.getLength() + 1 + iRestPathLen <= _MAX_PATH)
			{
				SCopy(Game.C4S.Head.Origin.getData(), strTargetLocation);
				if (iRestPathLen)
				{
					SAppendChar(DirectorySeparator, strTargetLocation);
					SAppend(szScenarioRelativePath, strTargetLocation);
				}
			}
		}
	}

	// Process all language packs (and their respective pack groups)
	C4Group *pPack, *pPackGroup;
	for (int iPack = 0; (pPack = Packs.GetGroup(iPack)) && (pPackGroup = PackGroups.GetGroup(iPack)); iPack++)
	{
		// Get current pack group position within pack
		SCopy(pPack->GetFullName().getData(), strPackPath, _MAX_PATH);
		GetRelativePath(pPackGroup->GetFullName().getData(), strPackPath, strPackGroupLocation);

		// Pack group is at correct position within pack: continue with next pack
		if (SEqualNoCase(strPackGroupLocation, strTargetLocation))
			continue;

		// Try to backtrack until we can reach the target location as a relative child
		while ( strPackGroupLocation[0]
		        && !GetRelativePath(strTargetLocation, strPackGroupLocation, strAdvance)
		        && pPackGroup->OpenMother() )
		{
			// Update pack group location
			GetRelativePath(pPackGroup->GetFullName().getData(), strPackPath, strPackGroupLocation);
		}

		// We can reach the target location as a relative child
		if (strPackGroupLocation[0] && GetRelativePath(strTargetLocation, strPackGroupLocation, strAdvance))
		{
			// Advance pack group to relative child
			pPackGroup->OpenChild(strAdvance);
		}

		// Cannot reach by advancing: need to close and reopen (rewinding group file)
		else
		{
			// Close pack group (if it is open at all)
			pPackGroup->Close();
			// Reopen pack group to relative position in language pack if possible
			pPackGroup->OpenAsChild(pPack, strTargetLocation);
		}

	}

	// Store new target location
	SCopy(strTargetLocation, PackGroupLocation, _MAX_FNAME);

	C4GroupSet r;
	// Provided group gets highest priority
	r.RegisterGroup(hGroup, false, 1000, C4GSCnt_Component);
	// register currently open pack groups
	r.RegisterGroups(PackGroups, C4GSCnt_Language);
	return r;
}