forked from Mirrors/openclonk
Store C4ComponentHost filenames in StdCopyStrBufs
parent
8ff6ae847c
commit
01e9dce9ce
|
@ -2255,7 +2255,7 @@ bool C4Game::InitScriptEngine()
|
|||
// get scripts
|
||||
char fn[_MAX_FNAME+1] = { 0 };
|
||||
File.ResetSearch();
|
||||
while (File.FindNextEntry(C4CFN_ScriptFiles, (char *) &fn, NULL, NULL, !!fn[0]))
|
||||
while (File.FindNextEntry(C4CFN_ScriptFiles, fn, NULL, !!fn[0]))
|
||||
{
|
||||
// host will be destroyed by script engine, so drop the references
|
||||
C4ScriptHost *scr = new C4ScriptHost();
|
||||
|
@ -2618,7 +2618,7 @@ bool C4Game::LoadScenarioComponents()
|
|||
// scenario sections
|
||||
char fn[_MAX_FNAME+1] = { 0 };
|
||||
ScenarioFile.ResetSearch(); *fn=0;
|
||||
while (ScenarioFile.FindNextEntry(C4CFN_ScenarioSections, (char *) &fn, NULL, NULL, !!*fn))
|
||||
while (ScenarioFile.FindNextEntry(C4CFN_ScenarioSections, fn, NULL, !!*fn))
|
||||
{
|
||||
// get section name
|
||||
char SctName[_MAX_FNAME+1];
|
||||
|
@ -2678,7 +2678,7 @@ bool C4Game::LoadAdditionalSystemGroup(C4Group &parent_group)
|
|||
}
|
||||
// load all scripts in there
|
||||
SysGroup.ResetSearch();
|
||||
while (SysGroup.FindNextEntry(C4CFN_ScriptFiles, (char *) &fn, NULL, NULL, !!fn[0]))
|
||||
while (SysGroup.FindNextEntry(C4CFN_ScriptFiles, fn, NULL, !!fn[0]))
|
||||
{
|
||||
// host will be destroyed by script engine, so drop the references
|
||||
C4ScriptHost *scr = new C4ScriptHost();
|
||||
|
|
|
@ -51,31 +51,21 @@ bool C4ComponentHost::Load(C4Group &hGroup,
|
|||
Clear();
|
||||
// Store filename
|
||||
if (fname)
|
||||
SCopy(fname, Filename);
|
||||
Filename.Copy(fname);
|
||||
// Load component - try all segmented filenames
|
||||
char strEntry[_MAX_FNAME+1], strEntryWithLanguage[_MAX_FNAME+1];
|
||||
for (int iFilename = 0; SCopySegment(Filename, iFilename, strEntry, '|'); iFilename++)
|
||||
char strEntry[_MAX_FNAME+1];
|
||||
StdStrBuf strEntryWithLanguage;
|
||||
for (int iFilename = 0; SCopySegment(Filename.getData(), iFilename, strEntry, '|'); iFilename++)
|
||||
{
|
||||
// Try to insert all language codes provided into the filename
|
||||
char strCode[3] = "";
|
||||
for (int iLang = 0; SCopySegment(szLanguage ? szLanguage : "", iLang, strCode, ',', 2); iLang++)
|
||||
{
|
||||
// Insert language code
|
||||
sprintf(strEntryWithLanguage, strEntry, strCode);
|
||||
strEntryWithLanguage.Format(strEntry, strCode);
|
||||
if (hGroup.LoadEntryString(strEntryWithLanguage, &Data))
|
||||
{
|
||||
Data.EnsureUnicode();
|
||||
// Skip those stupid "zero width no-break spaces" (also known as Byte Order Marks)
|
||||
if (Data[0] == '\xEF' && Data[1] == '\xBB' && Data[2] == '\xBF')
|
||||
{
|
||||
Data.Move(3,Data.getSize()-3);
|
||||
Data.Shrink(3);
|
||||
}
|
||||
// Store actual filename
|
||||
hGroup.FindEntry(strEntryWithLanguage, Filename);
|
||||
CopyFilePathFromGroup(hGroup);
|
||||
// Notify
|
||||
OnLoad();
|
||||
FinishLoad(strEntryWithLanguage, hGroup);
|
||||
// Got it
|
||||
return true;
|
||||
}
|
||||
|
@ -84,7 +74,7 @@ bool C4ComponentHost::Load(C4Group &hGroup,
|
|||
}
|
||||
}
|
||||
// Truncate any additional segments from stored filename
|
||||
SReplaceChar(Filename, '|', 0);
|
||||
SReplaceChar(Filename.getMData(), '|', 0);
|
||||
CopyFilePathFromGroup(hGroup);
|
||||
// Not loaded
|
||||
return false;
|
||||
|
@ -98,26 +88,22 @@ bool C4ComponentHost::Load(C4GroupSet &hGroupSet,
|
|||
Clear();
|
||||
// Store filename
|
||||
if (fname)
|
||||
SCopy(fname, Filename);
|
||||
Filename.Copy(fname);
|
||||
// Load component - try all segmented filenames
|
||||
char strEntry[_MAX_FNAME+1], strEntryWithLanguage[_MAX_FNAME+1];
|
||||
for (int iFilename = 0; SCopySegment(Filename, iFilename, strEntry, '|'); iFilename++)
|
||||
char strEntry[_MAX_FNAME+1];
|
||||
StdStrBuf strEntryWithLanguage;
|
||||
for (int iFilename = 0; SCopySegment(Filename.getData(), iFilename, strEntry, '|'); iFilename++)
|
||||
{
|
||||
// Try to insert all language codes provided into the filename
|
||||
char strCode[3] = "";
|
||||
for (int iLang = 0; SCopySegment(szLanguage ? szLanguage : "", iLang, strCode, ',', 2); iLang++)
|
||||
{
|
||||
// Insert language code
|
||||
sprintf(strEntryWithLanguage, strEntry, strCode);
|
||||
strEntryWithLanguage.Format(strEntry, strCode);
|
||||
if (hGroupSet.LoadEntryString(strEntryWithLanguage, &Data))
|
||||
{
|
||||
Data.EnsureUnicode();
|
||||
// Store actual filename
|
||||
C4Group *pGroup = hGroupSet.FindEntry(strEntryWithLanguage);
|
||||
pGroup->FindEntry(strEntryWithLanguage, Filename);
|
||||
CopyFilePathFromGroup(*pGroup);
|
||||
// Notify
|
||||
OnLoad();
|
||||
C4Group *pGroup = hGroupSet.FindEntry(strEntryWithLanguage.getData());
|
||||
FinishLoad(strEntryWithLanguage, *pGroup);
|
||||
// Got it
|
||||
return true;
|
||||
}
|
||||
|
@ -126,19 +112,35 @@ bool C4ComponentHost::Load(C4GroupSet &hGroupSet,
|
|||
}
|
||||
}
|
||||
// Truncate any additional segments from stored filename
|
||||
SReplaceChar(Filename, '|', 0);
|
||||
SReplaceChar(Filename.getMData(), '|', 0);
|
||||
// skip full path (unknown)
|
||||
FilePath[0] = 0;
|
||||
FilePath.Clear();
|
||||
// Not loaded
|
||||
return false;
|
||||
}
|
||||
|
||||
void C4ComponentHost::FinishLoad(const StdStrBuf & name, C4Group &hGroup)
|
||||
{
|
||||
Data.EnsureUnicode();
|
||||
// Skip those stupid "zero width no-break spaces" (also known as Byte Order Marks)
|
||||
if (Data[0] == '\xEF' && Data[1] == '\xBB' && Data[2] == '\xBF')
|
||||
{
|
||||
Data.Move(3,Data.getSize()-3);
|
||||
Data.Shrink(3);
|
||||
}
|
||||
// Store actual filename
|
||||
hGroup.FindEntry(name.getData(), &Filename);
|
||||
CopyFilePathFromGroup(hGroup);
|
||||
// Notify
|
||||
OnLoad();
|
||||
}
|
||||
|
||||
// Construct full path
|
||||
void C4ComponentHost::CopyFilePathFromGroup(const C4Group &hGroup)
|
||||
{
|
||||
SCopy(Config.AtRelativePath(hGroup.GetFullName().getData()), FilePath, _MAX_PATH - 1);
|
||||
SAppendChar(DirectorySeparator, FilePath);
|
||||
SAppend(Filename, FilePath, _MAX_PATH);
|
||||
FilePath.Copy(Config.AtRelativePath(hGroup.GetFullName().getData()));
|
||||
FilePath.AppendBackslash();
|
||||
FilePath.Append(Filename);
|
||||
}
|
||||
|
||||
bool C4ComponentHost::GetLanguageString(const char *szLanguage, StdStrBuf &rTarget)
|
||||
|
|
|
@ -30,7 +30,7 @@ class C4ComponentHost
|
|||
public:
|
||||
C4ComponentHost();
|
||||
virtual ~C4ComponentHost();
|
||||
const char *GetFilePath() const { return FilePath; }
|
||||
const char *GetFilePath() const { return FilePath.getData(); }
|
||||
void Clear();
|
||||
const char *GetData() const { return Data.getData(); }
|
||||
const StdStrBuf & GetDataBuf() const { return Data; }
|
||||
|
@ -49,9 +49,10 @@ protected:
|
|||
virtual void OnLoad() {}
|
||||
|
||||
StdCopyStrBuf Data;
|
||||
char Filename[_MAX_FNAME+1];
|
||||
char FilePath[_MAX_PATH+1];
|
||||
StdCopyStrBuf Filename;
|
||||
StdCopyStrBuf FilePath;
|
||||
void CopyFilePathFromGroup(const C4Group &hGroup);
|
||||
void FinishLoad(const StdStrBuf &, C4Group &hGroup);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1813,7 +1813,7 @@ bool C4Group::OpenAsChild(C4Group *pMother,
|
|||
|
||||
// Access entry in mother group
|
||||
size_t iSize;
|
||||
if ((!Mother->AccessEntry(FileName, &iSize, NULL, NULL, true)))
|
||||
if ((!Mother->AccessEntry(FileName, &iSize, NULL, true)))
|
||||
{
|
||||
if (!fCreate)
|
||||
{ CloseExclusiveMother(); Clear(); return Error("OpenAsChild: Entry not in mother group"); }
|
||||
|
@ -1874,23 +1874,23 @@ bool C4Group::OpenAsChild(C4Group *pMother,
|
|||
|
||||
bool C4Group::AccessEntry(const char *szWildCard,
|
||||
size_t *iSize, char *sFileName,
|
||||
bool *fChild, bool NeedsToBeAGroup)
|
||||
bool NeedsToBeAGroup)
|
||||
{
|
||||
#ifdef C4GROUP_DUMP_ACCESS
|
||||
LogF("Group access in %s: %s", GetFullName().getData(), szWildCard);
|
||||
#endif
|
||||
char fname[_MAX_FNAME+1];
|
||||
if (!FindEntry(szWildCard,fname,&iCurrFileSize,fChild))
|
||||
StdStrBuf fname;
|
||||
if (!FindEntry(szWildCard,&fname,&iCurrFileSize))
|
||||
return false;
|
||||
#ifdef _DEBUG
|
||||
szCurrAccessedEntry = fname;
|
||||
szCurrAccessedEntry = fname.getMData();
|
||||
#endif
|
||||
bool fResult = SetFilePtr2Entry(fname, NULL, NeedsToBeAGroup);
|
||||
bool fResult = SetFilePtr2Entry(fname.getData(), NULL, NeedsToBeAGroup);
|
||||
#ifdef _DEBUG
|
||||
szCurrAccessedEntry = NULL;
|
||||
#endif
|
||||
if (!fResult) return false;
|
||||
if (sFileName) SCopy(fname,sFileName);
|
||||
if (sFileName) SCopy(fname.getData(),sFileName);
|
||||
if (iSize) *iSize=iCurrFileSize;
|
||||
return true;
|
||||
}
|
||||
|
@ -1936,28 +1936,26 @@ bool C4Group::SetFilePtr2Entry(const char *szName, C4Group *pByChild, bool Needs
|
|||
return false;
|
||||
}
|
||||
|
||||
bool C4Group::FindEntry(const char *szWildCard, char *sFileName, size_t *iSize, bool *fChild)
|
||||
bool C4Group::FindEntry(const char *szWildCard, StdStrBuf *sFileName, size_t *iSize)
|
||||
{
|
||||
ResetSearch();
|
||||
return FindNextEntry(szWildCard,sFileName,iSize,fChild);
|
||||
return FindNextEntry(szWildCard,sFileName,iSize);
|
||||
}
|
||||
|
||||
bool C4Group::FindNextEntry(const char *szWildCard,
|
||||
char *sFileName,
|
||||
StdStrBuf *sFileName,
|
||||
size_t *iSize,
|
||||
bool *fChild,
|
||||
bool fStartAtFilename)
|
||||
{
|
||||
C4GroupEntry *centry;
|
||||
if (!szWildCard) return false;
|
||||
|
||||
// Reset search to specified position
|
||||
if (fStartAtFilename) FindEntry(sFileName);
|
||||
if (fStartAtFilename) FindEntry(sFileName->getData());
|
||||
|
||||
if (!(centry=SearchNextEntry(szWildCard))) return false;
|
||||
if (sFileName) SCopy(centry->FileName,sFileName);
|
||||
if (sFileName) sFileName->Copy(centry->FileName);
|
||||
if (iSize) *iSize=centry->Size;
|
||||
if (fChild) *fChild=!!centry->ChildGroup;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ public:
|
|||
bool View(const char *szFiles);
|
||||
bool AccessEntry(const char *szWildCard,
|
||||
size_t *iSize=NULL, char *sFileName=NULL,
|
||||
bool *fChild=NULL, bool NeedsToBeAGroup = false);
|
||||
bool NeedsToBeAGroup = false);
|
||||
bool AccessNextEntry(const char *szWildCard,
|
||||
size_t *iSize=NULL, char *sFileName=NULL,
|
||||
bool *fChild=NULL);
|
||||
|
@ -228,14 +228,30 @@ public:
|
|||
bool LoadEntryString(const char *szEntryName, StdStrBuf * Buf);
|
||||
bool LoadEntryString(const StdStrBuf & name, StdStrBuf * Buf) { return LoadEntryString(name.getData(), Buf); }
|
||||
bool FindEntry(const char *szWildCard,
|
||||
char *sFileName=NULL,
|
||||
size_t *iSize=NULL,
|
||||
bool *fChild=NULL);
|
||||
StdStrBuf *sFileName=NULL,
|
||||
size_t *iSize=NULL);
|
||||
bool FindEntry(const char *szWildCard,
|
||||
char *sFileName)
|
||||
{
|
||||
StdStrBuf name;
|
||||
bool r = FindEntry(szWildCard, &name);
|
||||
if(sFileName) SCopy(name.getData(),sFileName);
|
||||
return r;
|
||||
}
|
||||
bool FindNextEntry(const char *szWildCard,
|
||||
char *sFileName=NULL,
|
||||
StdStrBuf *sFileName=NULL,
|
||||
size_t *iSize=NULL,
|
||||
bool *fChild=NULL,
|
||||
bool fStartAtFilename=false);
|
||||
bool FindNextEntry(const char *szWildCard,
|
||||
char *sFileName,
|
||||
size_t *iSize=NULL,
|
||||
bool fStartAtFilename=false)
|
||||
{
|
||||
StdStrBuf name;
|
||||
bool r = FindNextEntry(szWildCard, &name, iSize, fStartAtFilename);
|
||||
if(sFileName) SCopy(name.getData(),sFileName);
|
||||
return r;
|
||||
}
|
||||
bool Read(void *pBuffer, size_t iSize);
|
||||
bool Advance(int iOffset);
|
||||
void SetStdOutput(bool fStatus);
|
||||
|
|
|
@ -736,7 +736,7 @@ bool C4UpdatePackage::MkUp(C4Group *pGrp1, C4Group *pGrp2, C4GroupEx *pUpGrp, bo
|
|||
strItemName[0] = strItemName2[0] = 0;
|
||||
pGrp2->ResetSearch(); if (!*fModified) pGrp1->ResetSearch();
|
||||
int iChangedEntries = 0;
|
||||
while (pGrp2->FindNextEntry("*", strItemName, NULL, NULL, !! strItemName[0]))
|
||||
while (pGrp2->FindNextEntry("*", strItemName, NULL, !! strItemName[0]))
|
||||
{
|
||||
// add to entry list
|
||||
if (!!EntryList) EntryList.AppendChar('|');
|
||||
|
@ -744,7 +744,7 @@ bool C4UpdatePackage::MkUp(C4Group *pGrp1, C4Group *pGrp2, C4GroupEx *pUpGrp, bo
|
|||
// no modification detected yet? then check order
|
||||
if (!*fModified)
|
||||
{
|
||||
if (!pGrp1->FindNextEntry("*", strItemName2, NULL, NULL, !! strItemName2[0]))
|
||||
if (!pGrp1->FindNextEntry("*", strItemName2, NULL, !! strItemName2[0]))
|
||||
*fModified = true;
|
||||
else if (!SEqual(strItemName, strItemName2))
|
||||
*fModified = true;
|
||||
|
|
|
@ -188,7 +188,7 @@ bool C4DefGraphics::Load(C4Group &hGroup, bool fColorByOwner)
|
|||
|
||||
// Load all materials for this definition:
|
||||
hGroup.ResetSearch();
|
||||
while (hGroup.FindNextEntry(C4CFN_DefMaterials, Filename, NULL, NULL, !!*Filename))
|
||||
while (hGroup.FindNextEntry(C4CFN_DefMaterials, Filename, NULL, !!*Filename))
|
||||
{
|
||||
StdStrBuf material;
|
||||
if (hGroup.LoadEntryString(Filename, &material))
|
||||
|
@ -215,7 +215,7 @@ bool C4DefGraphics::Load(C4Group &hGroup, bool fColorByOwner)
|
|||
iWildcardPos = SCharPos('*', C4CFN_DefGraphicsExPNG);
|
||||
int32_t iOverlayWildcardPos = SCharPos('*', C4CFN_ClrByOwnerExPNG);
|
||||
hGroup.ResetSearch();
|
||||
while (hGroup.FindNextEntry(C4CFN_DefGraphicsExPNG, Filename, NULL, NULL, !!*Filename))
|
||||
while (hGroup.FindNextEntry(C4CFN_DefGraphicsExPNG, Filename, NULL, !!*Filename))
|
||||
{
|
||||
// skip def graphics
|
||||
if (SEqualNoCase(Filename, C4CFN_DefGraphicsPNG)) continue;
|
||||
|
@ -253,7 +253,7 @@ bool C4DefGraphics::Load(C4Group &hGroup, bool fColorByOwner)
|
|||
iWildcardPos = SCharPos('*', C4CFN_Portraits);
|
||||
hGroup.ResetSearch();
|
||||
*Filename=0;
|
||||
while (hGroup.FindNextEntry(C4CFN_Portraits, Filename, NULL, NULL, !!*Filename))
|
||||
while (hGroup.FindNextEntry(C4CFN_Portraits, Filename, NULL, !!*Filename))
|
||||
{
|
||||
// get graphics name
|
||||
char GrpName[_MAX_PATH+1];
|
||||
|
|
|
@ -722,7 +722,7 @@ void C4StartupPlrSelDlg::UpdatePlayerList()
|
|||
SetTitle(FormatString("%s %s", LoadResStrNoAmp("IDS_CTL_CREW"), CurrPlayer.Core.PrefName).getData());
|
||||
// crew mode: Insert complete crew of player (2do: sort)
|
||||
bool fSucc; char szFn[_MAX_PATH+1];
|
||||
for (fSucc=CurrPlayer.Grp.FindEntry(C4CFN_ObjectInfoFiles, szFn); fSucc; fSucc=CurrPlayer.Grp.FindNextEntry(C4CFN_ObjectInfoFiles, szFn, NULL, NULL, true))
|
||||
for (fSucc=CurrPlayer.Grp.FindEntry(C4CFN_ObjectInfoFiles, szFn); fSucc; fSucc=CurrPlayer.Grp.FindNextEntry(C4CFN_ObjectInfoFiles, szFn, NULL, true))
|
||||
{
|
||||
CrewListItem *pCrewItem = new CrewListItem(this, pPlrListBox, CurrPlayer.Core.PrefColorDw);
|
||||
try
|
||||
|
|
|
@ -192,6 +192,12 @@ void StdStrBuf::AppendFormatV(const char *szFmt, va_list args)
|
|||
#endif
|
||||
}
|
||||
|
||||
void StdStrBuf::AppendBackslash()
|
||||
{
|
||||
if(getLength() && *getPtr(getLength() - 1) == DirectorySeparator) return;
|
||||
AppendChar(DirectorySeparator);
|
||||
}
|
||||
|
||||
void StdStrBuf::CompileFunc(StdCompiler *pComp, int iRawType)
|
||||
{
|
||||
if (pComp->isCompiler())
|
||||
|
|
|
@ -602,6 +602,7 @@ public:
|
|||
{
|
||||
AppendChars(cChar, 1);
|
||||
}
|
||||
void AppendBackslash();
|
||||
void InsertChar(char cChar, size_t insert_before)
|
||||
{
|
||||
assert(insert_before <= getLength());
|
||||
|
|
Loading…
Reference in New Issue