bool C4DefGraphics::LoadSkeleton(C4Group &hGroup, const char* szFileName, StdMeshSkeletonLoader& loader) { char* buf = NULL; size_t size; try { if (!hGroup.LoadEntry(szFileName, &buf, &size, 1)) return false; // delete skeleton from the map for reloading, or else if you delete or rename // a skeleton file in the folder the old skeleton will still exist in the map loader.RemoveSkeleton(hGroup.GetName(), szFileName); if (SEqualNoCase(GetExtension(szFileName), "xml")) { loader.LoadSkeletonXml(hGroup.GetName(), szFileName, buf, size); } else { loader.LoadSkeletonBinary(hGroup.GetName(), szFileName, buf, size); } delete[] buf; } catch (const std::runtime_error& ex) { DebugLogF("Failed to load skeleton in definition %s: %s", hGroup.GetName(), ex.what()); delete[] buf; return false; } return true; }
void C4Language::LoadInfos(C4Group &hGroup) { char strEntry[_MAX_FNAME + 1]; char *strTable; // Look for language string tables hGroup.ResetSearch(); while (hGroup.FindNextEntry(C4CFN_Language, strEntry)) // For now, we will only load info on the first string table found for a given // language code as there is currently no handling for selecting different string tables // of the same code - the system always loads the first string table found for a given code if (!FindInfo(GetFilenameOnly(strEntry) + SLen(GetFilenameOnly(strEntry)) - 2)) // Load language string table if (hGroup.LoadEntry(strEntry, &strTable, 0, 1)) { // New language info C4LanguageInfo *pInfo = new C4LanguageInfo; // Get language code by entry name SCopy(GetFilenameOnly(strEntry) + SLen(GetFilenameOnly(strEntry)) - 2, pInfo->Code, 2); SCapitalize(pInfo->Code); // Get language name, info, fallback from table CopyResStr("IDS_LANG_NAME", strTable, pInfo->Name); CopyResStr("IDS_LANG_INFO", strTable, pInfo->Info); CopyResStr("IDS_LANG_FALLBACK", strTable, pInfo->Fallback); // Safety: pipe character is not allowed in any language info string SReplaceChar(pInfo->Name, '|', ' '); SReplaceChar(pInfo->Info, '|', ' '); SReplaceChar(pInfo->Fallback, '|', ' '); // Delete table delete [] strTable; // Add info to list pInfo->Next = Infos; Infos = pInfo; } }
bool C4DefGraphics::LoadSkeleton(C4Group &hGroup, const char* szFileName, StdMeshSkeletonLoader& loader) { char* buf = NULL; size_t size; try { if (!hGroup.LoadEntry(szFileName, &buf, &size, 1)) return false; StdCopyStrBuf filename = StdCopyStrBuf(); StdMeshSkeletonLoader::MakeFullSkeletonPath(filename, hGroup.GetName(), szFileName); if (SEqualNoCase(GetExtension(szFileName), "xml")) { loader.LoadSkeletonXml(filename, buf, size); } else { loader.LoadSkeletonBinary(filename, buf, size); } delete[] buf; } catch (const std::runtime_error& ex) { DebugLogF("Failed to load skeleton in definition %s: %s", hGroup.GetName(), ex.what()); delete[] buf; return false; } return true; }
void C4Def::LoadMeshMaterials(C4Group &hGroup, C4DefGraphicsPtrBackup *gfx_backup) { // Load all mesh materials from this folder C4DefAdditionalResourcesLoader loader(hGroup); hGroup.ResetSearch(); char MaterialFilename[_MAX_PATH + 1]; *MaterialFilename = 0; for (const auto &mat : mesh_materials) { ::MeshMaterialManager.Remove(mat, &gfx_backup->GetUpdater()); } mesh_materials.clear(); while (hGroup.FindNextEntry(C4CFN_DefMaterials, MaterialFilename, NULL, !!*MaterialFilename)) { StdStrBuf material; if (hGroup.LoadEntryString(MaterialFilename, &material)) { try { StdStrBuf buf; buf.Copy(hGroup.GetName()); buf.Append("/"); buf.Append(MaterialFilename); auto new_materials = ::MeshMaterialManager.Parse(material.getData(), buf.getData(), loader); mesh_materials.insert(new_materials.begin(), new_materials.end()); } catch (const StdMeshMaterialError& ex) { DebugLogF("Failed to read material script: %s", ex.what()); } } } }
bool C4DefGraphics::LoadMesh(C4Group &hGroup, const char* szFileName, StdMeshSkeletonLoader& loader) { char* buf = NULL; size_t size; try { if(!hGroup.LoadEntry(szFileName, &buf, &size, 1)) return false; if (SEqualNoCase(GetExtension(szFileName), "xml")) { Mesh = StdMeshLoader::LoadMeshXml(buf, size, ::MeshMaterialManager, loader, hGroup.GetName()); } else { Mesh = StdMeshLoader::LoadMeshBinary(buf, size, ::MeshMaterialManager, loader, hGroup.GetName()); } delete[] buf; Mesh->SetLabel(pDef->id.ToString()); // order submeshes Mesh->PostInit(); } catch (const std::runtime_error& ex) { DebugLogF("Failed to load mesh in definition %s: %s", hGroup.GetName(), ex.what()); delete[] buf; return false; } Type = TYPE_Mesh; return true; }
bool C4Network2Res::OptimizeStandalone(bool fSilent) { CStdLock FileLock(&FileCSec); // for now: player files only if (Core.getType() == NRT_Player) { // log - this may take a few seconds if (!fSilent) LogF(LoadResStr("IDS_PRC_NETPREPARING"), GetFilename(szFile)); // copy to temp file, if needed if (!fTempFile && SEqual(szFile, szStandalone)) { char szNewStandalone[_MAX_PATH + 1]; if (!pParent->FindTempResFileName(szStandalone, szNewStandalone)) { if (!fSilent) Log("OptimizeStandalone: could not find free name for temporary file!"); return false; } if (!C4Group_CopyItem(szStandalone, szNewStandalone)) { if (!fSilent) Log("OptimizeStandalone: could not copy to temporary file!"); return false; } /* TODO: Test failure */ SCopy(szNewStandalone, szStandalone, sizeof(szStandalone) - 1); } // open as group C4Group Grp; if (!Grp.Open(szStandalone)) { if (!fSilent) Log("OptimizeStandalone: could not open player file!"); return false; } // remove bigicon, if the file size is too large size_t iBigIconSize=0; if (Grp.FindEntry(C4CFN_BigIcon, NULL, &iBigIconSize)) if (iBigIconSize > C4NetResMaxBigicon*1024) Grp.Delete(C4CFN_BigIcon); Grp.Close(); } return true; }
bool C4PlayerInfoCore::Load(C4Group &hGroup) { // New version StdStrBuf Source; if (hGroup.LoadEntryString(C4CFN_PlayerInfoCore,&Source)) { // Compile StdStrBuf GrpName = hGroup.GetFullName(); GrpName.Append(DirSep C4CFN_PlayerInfoCore); if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(*this, Source, GrpName.getData())) return false; // Pref for AutoContextMenus is still undecided: default by player's control style if (OldPrefAutoContextMenu == -1) OldPrefAutoContextMenu = OldPrefControlStyle; // Determine true color from indexed pref color if (!PrefColorDw) PrefColorDw = GetPrefColorValue(PrefColor); // Validate colors PrefColorDw &= 0xffffff; PrefColor2Dw &= 0xffffff; // Validate name C4Markup::StripMarkup(PrefName); // Success return true; } // Old version no longer supported - sorry return false; }
bool C4PlayerList::Save(C4Group &hGroup, bool fStoreTiny, const C4PlayerInfoList &rStoreList) { StdStrBuf sTempFilename; bool fSuccess = true; // Save to external player files and add to group for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next) { // save only those in the list, and only those with a filename C4PlayerInfo *pNfo = rStoreList.GetPlayerInfoByID(pPlr->ID); if (!pNfo) continue; if (!pNfo->GetFilename() || !*pNfo->GetFilename()) continue;; // save over original file? bool fStoreOnOriginal = (!fStoreTiny && pNfo->GetType() == C4PT_User); // Create temporary file sTempFilename.Copy(Config.AtTempPath(pNfo->GetFilename())); if (fStoreOnOriginal) if (!C4Group_CopyItem(pPlr->Filename, sTempFilename.getData())) return false; // Open group C4Group PlrGroup; if (!PlrGroup.Open(sTempFilename.getData(), !fStoreOnOriginal)) return false; // Save player if (!pPlr->Save(PlrGroup, true, fStoreOnOriginal)) return false; PlrGroup.Close(); // Add temp file to group if (!hGroup.Move(sTempFilename.getData(), pNfo->GetFilename())) return false; } return fSuccess; }
int32_t C4SoundSystem::LoadEffects(C4Group &hGroup, BOOL fStatic) { int32_t iNum = 0; char szFilename[_MAX_FNAME + 1]; char szFileType[_MAX_FNAME + 1]; C4SoundEffect *nsfx; // Process segmented list of file types for (int32_t i = 0; SCopySegment(C4CFN_SoundFiles, i, szFileType, '|', _MAX_FNAME); i++) { // Search all sound files in group hGroup.ResetSearch(); while (hGroup.FindNextEntry(szFileType, szFilename)) // Create and load effect if (nsfx = new C4SoundEffect) if (nsfx->Load(szFilename, hGroup, fStatic)) { // Overload same name effects RemoveEffect(szFilename); // Add effect nsfx->Next = FirstSound; FirstSound = nsfx; iNum++; } else delete nsfx; } return iNum; }
bool C4GroupSet::RegisterGroups(const C4GroupSet &rCopy, int32_t Contents, const char *szFilename, int32_t iMaxSkipID) { // get all groups of rCopy int32_t Contents2; for (C4GroupSetNode *pNode=rCopy.pFirst; pNode; pNode=pNode->pNext) if ((Contents2 = pNode->Contents & Contents)) if (pNode->id > iMaxSkipID) { if (!szFilename) // add group but don't check the content again! RegisterGroup(*pNode->pGroup, false, pNode->Priority, Contents2, false); else { // if a filename is given, open the child group C4Group *pGroup = new C4Group(); if (!pGroup->OpenAsChild(pNode->pGroup, szFilename)) { delete pGroup; continue; } // add the child group to the local list; contents equal Contents2 // but this flag is not likely to be used if (!RegisterGroup(*pGroup, true, pNode->Priority, Contents2, false)) delete pGroup; } } // done, success return true; }
int32_t C4FontLoader::LoadDefs(C4Group &hGroup, C4Config &rCfg) { // load vector fonts char fn[_MAX_PATH+1], fnDef[32]; int32_t i=0; while (SCopySegment(C4CFN_FontFiles, i++, fnDef, '|', 31)) { hGroup.ResetSearch(); while (hGroup.FindNextEntry(fnDef, fn)) { C4VectorFont *pVecFon = new C4VectorFont(); if (pVecFon->Init(hGroup, fn, rCfg)) { pVecFon->pNext = pVectorFonts; pVectorFonts = pVecFon; } else delete pVecFon; } } // load definition file StdStrBuf DefFileContent; if (!hGroup.LoadEntryString(C4CFN_FontDefs, DefFileContent)) return 0; std::vector<C4FontDef> NewFontDefs; if (!CompileFromBuf_LogWarn<StdCompilerINIRead>( mkNamingAdapt(mkSTLContainerAdapt(NewFontDefs), "Font"), DefFileContent, C4CFN_FontDefs)) return 0; // Copy the new FontDefs into the list FontDefs.insert(FontDefs.end(), NewFontDefs.begin(), NewFontDefs.end()); // done return NewFontDefs.size(); }
bool C4GraphicsResource::RegisterGlobalGraphics() { // Create main gfx group - register with fixed ID 1, to prevent unnecessary font reloading. // FontLoader-initializations always check whether the font has already been initialized // with the same parameters. If the game is simply reloaded in console-mode, this means // that fonts are not reinitialized. This will also apply for InGame-scenario switches yet // to be implemented. // Bitmap fonts from other groups are always reloaded, because the group indices of the gfx // group set are not reset, and will then differ for subsequent group registrations. // Resetting the group index of the gfx group set at game reset would cause problems if a // scenario with its own font face is being closed, and then another scenario with another, // overloaded font face is opened. The group indices could match and the old font would // then be kept. // The cleanest alternative would be to reinit all the fonts whenever a scenario is reloaded // FIXME: Test whether vector fonts from a scenario are correctly reloaded C4Group *pMainGfxGrp = new C4Group(); if (!Reloc.Open(*pMainGfxGrp, C4CFN_Graphics) || !Files.RegisterGroup(*pMainGfxGrp, true, C4GSPrio_Base, C4GSCnt_Graphics, 1)) { // error LogFatal(FormatString(LoadResStr("IDS_PRC_NOGFXFILE"),C4CFN_Graphics,pMainGfxGrp->GetError()).getData()); delete pMainGfxGrp; return false; } return true; }
BOOL C4UpdatePackage::Optimize(C4Group *pGrpFrom, C4GroupEx *pGrpTo, const char *strFileName) { // group file? C4Group ItemGroupFrom; if (!ItemGroupFrom.OpenAsChild(pGrpFrom, strFileName)) return TRUE; // try to open target group C4GroupEx ItemGroupTo; char strTempGroup[_MAX_PATH + 1]; strTempGroup[0] = 0; if (!ItemGroupTo.OpenAsChild(pGrpTo, strFileName)) return TRUE; // update children char ItemFileName[_MAX_PATH]; ItemGroupFrom.ResetSearch(); while (ItemGroupFrom.FindNextEntry("*", ItemFileName)) Optimize(&ItemGroupFrom, &ItemGroupTo, ItemFileName); // set head if (ItemGroupTo.HeadIdentical(ItemGroupFrom, true)) ItemGroupTo.SetHead(ItemGroupFrom); // write group (do not change any headers set by DoGrpUpdate!) ItemGroupTo.Close(FALSE); // set core (C4Group::Save overwrites it) pGrpTo->SaveEntryCore(*pGrpFrom, strFileName); pGrpTo->SetSavedEntryCore(strFileName); return TRUE; }
int C4UpdatePackage::Check(C4Group *pGroup) { // Version requirement is set if (RequireVersion[0]) { // Engine and game version must match (rest ignored) if ((C4XVER1 != RequireVersion[0]) || (C4XVER2 != RequireVersion[1])) return C4UPD_CHK_BAD_VERSION; } // only group updates have any special needs if (!GrpUpdate) return C4UPD_CHK_OK; // check source file C4Group TargetGrp; if (!TargetGrp.Open(DestPath)) return C4UPD_CHK_NO_SOURCE; if (!TargetGrp.IsPacked()) return C4UPD_CHK_BAD_SOURCE; TargetGrp.Close(); // check source crc uint32_t iCRC32; if (!C4Group_GetFileCRC(DestPath, &iCRC32)) return C4UPD_CHK_BAD_SOURCE; // equal to destination group? if (iCRC32 == GrpChks2) // so there's nothing to do return C4UPD_CHK_ALREADY_UPDATED; // check if it's one of our registered sources int i = 0; for (; i < UpGrpCnt; i++) if (iCRC32 == GrpChks1[i]) break; if (i >= UpGrpCnt) return C4UPD_CHK_BAD_SOURCE; // ok return C4UPD_CHK_OK; }
bool C4Language::Init() { // Clear (to allow clean re-init) Clear(); // Make sure Language.ocg is unpacked (TODO: This won't work properly if Language.ocg is in system data path) // Assume for now that Language.ocg is either at a writable location or unpacked already. // TODO: Use all Language.c4gs that we find, and merge them. // TODO: Use gettext instead? StdStrBuf langPath; C4Reloc::iterator iter; for(iter = Reloc.begin(); iter != Reloc.end(); ++iter) { langPath.Copy((*iter).strBuf + DirSep + C4CFN_Languages); if(ItemExists(langPath.getData())) { if(DirectoryExists(langPath.getData())) break; if(C4Group_UnpackDirectory(langPath.getData())) break; } } // Break if no language.ocg found if(iter != Reloc.end()) { // Look for available language packs in Language.ocg C4Group *pPack; char strPackFilename[_MAX_FNAME + 1], strEntry[_MAX_FNAME + 1]; if (PackDirectory.Open(langPath.getData())) { while (PackDirectory.FindNextEntry("*.ocg", strEntry)) { sprintf(strPackFilename, "%s" DirSep "%s", C4CFN_Languages, strEntry); pPack = new C4Group(); if (pPack->Open(strPackFilename)) { Packs.RegisterGroup(*pPack, true, C4GSCnt_Language, false); } else { delete pPack; } } } // Now create a pack group for each language pack (these pack groups are child groups // that browse along each pack to access requested data) for (int iPack = 0; (pPack = Packs.GetGroup(iPack)); iPack++) PackGroups.RegisterGroup(*(new C4Group), true, C4GSPrio_Base, C4GSCnt_Language); } // Load language infos by scanning string tables (the engine doesn't really need this at the moment) InitInfos(); // Done return true; }
bool C4GroupSet::LoadEntry(const char *szEntryName, char **lpbpBuf, size_t *ipSize, int32_t iAppendZeros) { // Load the entry from the first group that has it C4Group *pGroup; if ((pGroup = FindEntry(szEntryName))) return pGroup->LoadEntry(szEntryName, lpbpBuf, ipSize, iAppendZeros); // Didn't find it return false; }
bool C4GroupSet::LoadEntryString(const char *szEntryName, StdStrBuf * rBuf) { // Load the entry from the first group that has it C4Group *pGroup; if ((pGroup = FindEntry(szEntryName))) return pGroup->LoadEntryString(szEntryName, rBuf); // Didn't find it return false; }
bool C4PlayerInfoCore::Save(C4Group &hGroup) { StdStrBuf Source, Name = hGroup.GetFullName(); Name.Append(DirSep C4CFN_PlayerInfoCore); if (!DecompileToBuf_Log<StdCompilerINIWrite>(*this, &Source, Name.getData())) return false; if (!hGroup.Add(C4CFN_PlayerInfoCore,Source,false,true)) return false; hGroup.Delete("C4Player.ocb"); return true; }
BOOL C4PlayerInfoCore::Save(C4Group &hGroup) { StdStrBuf Source, Name = hGroup.GetFullName(); Name.Append(DirSep C4CFN_PlayerInfoCore); if(!DecompileToBuf_Log<StdCompilerINIWrite>(*this, &Source, Name.getData())) return FALSE; if (!hGroup.Add(C4CFN_PlayerInfoCore,Source,FALSE,TRUE)) return FALSE; hGroup.Delete("C4Player.c4b"); return TRUE; }
C4Group *C4Network2Res::OpenAsGrp() const { C4Group *pnGrp = new C4Group(); if (!pnGrp->Open(szFile)) { delete pnGrp; return NULL; } return pnGrp; }
bool C4Reloc::Open(C4Group& hGroup, const char* filename) const { if(IsGlobalPath(filename)) return hGroup.Open(filename); for(iterator iter = begin(); iter != end(); ++iter) if(hGroup.Open(((*iter).strBuf + DirSep + filename).getData())) return true; return false; }
int32_t C4SoundSystem::LoadEffects(C4Group &hGroup, const char *namespace_prefix, bool group_is_root) { // Local definition sounds: If there is a Sound.ocg in the group, load the sound from there if(group_is_root && hGroup.FindEntry(C4CFN_Sound)) { C4Group g; g.OpenAsChild(&hGroup, C4CFN_Sound, false, false); return LoadEffects(g, namespace_prefix, false); } int32_t iNum=0; char szFilename[_MAX_FNAME+1]; char szFileType[_MAX_FNAME+1]; C4SoundEffect *nsfx; // Process segmented list of file types for (int32_t i = 0; SCopySegment(C4CFN_SoundFiles, i, szFileType, '|', _MAX_FNAME); i++) { // Search all sound files in group hGroup.ResetSearch(); while (hGroup.FindNextEntry(szFileType, szFilename)) // Create and load effect if ((nsfx = new C4SoundEffect)) { if (nsfx->Load(szFilename, hGroup, namespace_prefix)) { // Overload same name effects RemoveEffect(nsfx->Name); // Add effect nsfx->Next=FirstSound; FirstSound=nsfx; iNum++; } else delete nsfx; } } // Load subgroups from Sound.ocg and other subgroups if (!group_is_root) { hGroup.ResetSearch(); while (hGroup.FindNextEntry(C4CFN_SoundSubgroups, szFilename)) { // Load from subgroup as a sub-namespace // get namespace name StdStrBuf sub_namespace; if (namespace_prefix) { sub_namespace.Copy(namespace_prefix); sub_namespace.Append("::"); } sub_namespace.Append(szFilename, strlen(szFilename) - strlen(C4CFN_SoundSubgroups) + 1); // load from child group C4Group subgroup; if (subgroup.OpenAsChild(&hGroup, szFilename, false, false)) { iNum += LoadEffects(subgroup, sub_namespace.getData(), false); } } } return iNum; }
bool C4UpdatePackage::DoUpdate(C4Group *pGrpFrom, C4GroupEx *pGrpTo, const char *strFileName) { // group file? C4Group ItemGroupFrom; if (ItemGroupFrom.OpenAsChild(pGrpFrom, strFileName)) { // try to open target group C4GroupEx ItemGroupTo; char strTempGroup[_MAX_PATH+1]; strTempGroup[0] = 0; if (!ItemGroupTo.OpenAsChild(pGrpTo, strFileName, false, true)) return false; // update children char ItemFileName[_MAX_PATH]; ItemGroupFrom.ResetSearch(); while (ItemGroupFrom.FindNextEntry("*", ItemFileName)) if (!SEqual(ItemFileName, C4CFN_UpdateCore) && !SEqual(ItemFileName, C4CFN_UpdateEntries)) DoUpdate(&ItemGroupFrom, &ItemGroupTo, ItemFileName); if (GrpUpdate) { DoGrpUpdate(&ItemGroupFrom, &ItemGroupTo); // write group (do not change any headers set by DoGrpUpdate!) ItemGroupTo.Close(false); // set core (C4Group::Save overwrites it) pGrpTo->SaveEntryCore(*pGrpFrom, strFileName); pGrpTo->SetSavedEntryCore(strFileName); // flag as no-resort pGrpTo->SetNoSort(strFileName); } else { // write group ItemGroupTo.Close(true); // temporary group? if (strTempGroup[0]) if (!pGrpTo->Move(strTempGroup, strFileName)) return false; } } else { #ifdef _WIN32 OutputDebugString(FormatString("updating %s\\%s\n", pGrpTo->GetFullName().getData(), strFileName).GetWideChar()); #elif defined(_DEBUG) printf("updating %s\\%s\n", pGrpTo->GetFullName().getData(), strFileName); #endif if (!C4Group_CopyEntry(pGrpFrom, pGrpTo, strFileName)) return false; // set core pGrpTo->SaveEntryCore(*pGrpFrom, strFileName); pGrpTo->SetSavedEntryCore(strFileName); } // ok return true; }
bool C4ParticleDef::Reload() { // no file? if (!Filename[0]) return false; // open group C4Group group; if (!group.Open(Filename.getData())) return false; // reset class Clear(); // load return Load(group); }
bool C4MassMoverSet::Load(C4Group &hGroup) { // clear previous Clear(); Default(); size_t iBinSize,iMoverSize=sizeof(C4MassMover); if (!hGroup.AccessEntry(C4CFN_MassMover,&iBinSize)) return false; if ((iBinSize % iMoverSize)!=0) return false; // load new Count = iBinSize / iMoverSize; if (!hGroup.Read(Set,iBinSize)) return false; return true; }
bool C4VectorFont::Init(C4Group &hGrp, const char *szFilename, C4Config &rCfg) { // name by file Name.Copy(GetFilenameOnly(szFilename)); #if defined(_WIN32) && !defined(HAVE_FREETYPE) // check whether group is directory or packed if (!hGrp.IsPacked()) { // it's open: use the file directly SCopy(hGrp.GetFullName().getData(), FileName, _MAX_PATH); AppendBackslash(FileName); SAppend(szFilename, FileName); if (!FileExists(FileName)) { *FileName=0; return false; } fIsTempFile = false; } else { // it's packed: extract to temp path SCopy(rCfg.AtTempPath(szFilename), FileName, _MAX_PATH); // make sure the filename is not in use, in case multiple instances of the engine are run if (FileExists(FileName)) { RemoveExtension(FileName); StdStrBuf sNewFilename; for (int i=0; i<1000; ++i) { sNewFilename.Format("%s%x", FileName, (int)rand()); if (*GetExtension(szFilename)) { sNewFilename.AppendChar('.'); sNewFilename.Append(GetExtension(szFilename)); } if (!FileExists(sNewFilename.getData())) break; } SCopy(sNewFilename.getData(), FileName, _MAX_PATH); } if (!hGrp.ExtractEntry(szFilename, FileName)) { *FileName=0; return false; } fIsTempFile = true; } // add the font resource //if (!AddFontResourceEx(FileName, FR_PRIVATE, NULL)) requires win2k if (!AddFontResource(FileName)) { if (fIsTempFile) EraseFile(FileName); *FileName='\0'; return false; } #else if (!hGrp.LoadEntry(szFilename, Data)) return false; #endif // success return true; }
bool C4Language::CloseGroup(const char *strPath) { // Check all open language packs C4Group *pPack; for (int iPack = 0; (pPack = Packs.GetGroup(iPack)); iPack++) if (ItemIdentical(strPath, pPack->GetFullName().getData())) { Packs.UnregisterGroup(iPack); return true; } // No pack of that path return false; }
bool C4MusicSystem::GrpContainsMusic(C4Group &rGrp) { // search for known file extensions return rGrp.FindEntry("*.mid") #ifdef USE_MP3 || rGrp.FindEntry("*.mp3") #endif || rGrp.FindEntry("*.xm") || rGrp.FindEntry("*.it") || rGrp.FindEntry("*.s3m") || rGrp.FindEntry("*.mod") || rGrp.FindEntry("*.ogg"); }
bool C4KeyboardInput::LoadCustomConfig() { // load from INI file (2do: load from registry) C4Group GrpExtra; if (!GrpExtra.Open(C4CFN_Extra)) return false; StdBuf sFileContents; if (!GrpExtra.LoadEntry(C4CFN_KeyConfig, &sFileContents)) return false; StdStrBuf sFileContentsString((const char *) sFileContents.getData()); if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(*this, sFileContentsString, "Custom keys from" C4CFN_Extra DirSep C4CFN_KeyConfig)) return false; LogF(LoadResStr("IDS_PRC_LOADEDKEYCONF"), C4CFN_Extra DirSep C4CFN_KeyConfig); return true; }
bool C4Extra::LoadDef(C4Group &hGroup, const char *szName) { // check if file exists if (!hGroup.FindEntry(szName)) return false; // log that extra group is loaded LogF(LoadResStr("IDS_PRC_LOADEXTRA"), hGroup.GetName(), szName); // open and add group to set C4Group *pGrp = new C4Group; if (!pGrp->OpenAsChild(&hGroup, szName)) { Log(LoadResStr("IDS_ERR_FAILURE")); delete pGrp; return false; } Game.GroupSet.RegisterGroup(*pGrp, true, C4GSPrio_Extra, C4GSCnt_Extra); // done, success return true; }