Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Core/GameEngine/Include/GameNetwork/FileTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class GameInfo;

// Convenience functions
AsciiString GetBasePathFromPath( AsciiString path );
AsciiString GetFileFromPath( AsciiString path );
AsciiString GetExtensionFromFile( AsciiString fname );
AsciiString GetBaseFileFromFile( AsciiString fname );
AsciiString GetPreviewFromMap( AsciiString path );
AsciiString GetINIFromMap( AsciiString path );
Expand Down
7 changes: 1 addition & 6 deletions Core/GameEngine/Source/Common/Audio/AudioEventRTS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,12 +796,7 @@ AsciiString AudioEventRTS::generateFilenameExtension( AudioType audioTypeToPlay
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::adjustForLocalization(AsciiString &strToAdjust)
{
const char *filename = strToAdjust.reverseFind('\\');
if (filename) {
filename += 1;
} else {
filename = strToAdjust.str();
}
const char *filename = getFileName(strToAdjust.str());

// try the localized version first so that we're guaranteed to get it
// even if the generic data directory holds a version of the file
Expand Down
21 changes: 8 additions & 13 deletions Core/GameEngine/Source/Common/CRCDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,6 @@ void outputCRCDumpLines()
*/
}

static AsciiString getFname(AsciiString path)
{
return path.reverseFind('\\') + 1;
}

static void addCRCDebugLineInternal(bool count, const char *fmt, va_list args)
{
if (TheGameLogic == nullptr || !(IS_FRAME_OK_TO_LOG))
Expand Down Expand Up @@ -278,30 +273,30 @@ void dumpVector3(const Vector3 *v, AsciiString name, AsciiString fname, Int line
{
if (!(IS_FRAME_OK_TO_LOG)) return;
fname.toLower();
fname = getFname(fname);
const char* fileName = getFileName(fname.str());
addCRCDebugLine("dumpVector3() %s:%d %s %8.8X %8.8X %8.8X",
fname.str(), line, name.str(),
fileName, line, name.str(),
AS_INT(v->X), AS_INT(v->Y), AS_INT(v->Z));
}

void dumpCoord3D(const Coord3D *c, AsciiString name, AsciiString fname, Int line)
{
if (!(IS_FRAME_OK_TO_LOG)) return;
fname.toLower();
fname = getFname(fname);
const char* fileName = getFileName(fname.str());
addCRCDebugLine("dumpCoord3D() %s:%d %s %8.8X %8.8X %8.8X",
fname.str(), line, name.str(),
fileName, line, name.str(),
AS_INT(c->x), AS_INT(c->y), AS_INT(c->z));
}

void dumpMatrix3D(const Matrix3D *m, AsciiString name, AsciiString fname, Int line)
{
if (!(IS_FRAME_OK_TO_LOG)) return;
fname.toLower();
fname = getFname(fname);
const char* fileName = getFileName(fname.str());
const Real *matrix = (const Real *)m;
addCRCDebugLine("dumpMatrix3D() %s:%d %s",
fname.str(), line, name.str());
fileName, line, name.str());
for (Int i=0; i<3; ++i)
addCRCDebugLine(" 0x%08X 0x%08X 0x%08X 0x%08X",
AS_INT(matrix[(i<<2)+0]), AS_INT(matrix[(i<<2)+1]), AS_INT(matrix[(i<<2)+2]), AS_INT(matrix[(i<<2)+3]));
Expand All @@ -311,9 +306,9 @@ void dumpReal(Real r, AsciiString name, AsciiString fname, Int line)
{
if (!(IS_FRAME_OK_TO_LOG)) return;
fname.toLower();
fname = getFname(fname);
const char* fileName = getFileName(fname.str());
addCRCDebugLine("dumpReal() %s:%d %s %8.8X (%f)",
fname.str(), line, name.str(), AS_INT(r), r);
fileName, line, name.str(), AS_INT(r), r);
}

#endif // DEBUG_CRC
2 changes: 1 addition & 1 deletion Core/GameEngine/Source/Common/INI/INIMapCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void INI::parseMapCacheDefinition( INI* ini )
{
// maps without localized name tags
AsciiString tempdisplayname;
tempdisplayname = name.reverseFind('\\') + 1;
tempdisplayname = getFileName(name.str());
md.m_displayName.translate(tempdisplayname);
if (md.m_numPlayers >= 2)
{
Expand Down
1 change: 0 additions & 1 deletion Core/GameEngine/Source/Common/System/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#include "Common/LocalFileSystem.h"
#include "Common/PerfTimer.h"

#include "Lib/PathUtil.h"


DECLARE_PERF_TIMER(FileSystem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2714,16 +2714,16 @@ GameWindow *GameWindowManager::winCreateFromScript( AsciiString filenameString,
resetWindowDefaults();

//
// get the filename from the parameter, if it doesn't contain a '\' it is
// a it is assumed to be a filename only, which we will prefix a "window\"
// directory to, otherwise it is assumed to be an absolute path. When using
// a filename only make sure the current directory is set to the right
// place for the window files subdirectory
// Prefix bare filenames with the window directory. Keep supplied paths unchanged.
//
if( strchr( filename, '\\' ) == nullptr )
if( getLastPathSeparator( filename ) == nullptr )

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Relative layouts lose Window prefix

Existing callers pass relative layout names such as Menus/SinglePlayerLoadScreen.wnd and Menus/MessageBox.wnd. The new check treats their / as a supplied path, so openFile receives Menus/... instead of Window\Menus/.... If those layouts are stored under the Window directory, load screens and message boxes will fail to open.

Knowledge Base Used: Game client runtime

{
snprintf( filepath, ARRAY_SIZE(filepath), "Window\\%s", filename );
}
else
{
strlcpy(filepath, filename, ARRAY_SIZE(filepath));
}

// Open the input file
inFile = TheFileSystem->openFile(filepath, File::READ);
Expand Down
6 changes: 3 additions & 3 deletions Core/GameEngine/Source/GameClient/MapUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ Bool MapCache::loadMapsFromDisk( const AsciiString &mapDir, Bool isOfficial, Boo
AsciiString filepathLower = *filepathIt;
filepathLower.toLower();

const char *szFilenameLower = filepathLower.reverseFind('\\');
const char *szFilenameLower = getLastPathSeparator(filepathLower.str());
if (!szFilenameLower)
{
DEBUG_CRASH(("Couldn't find \\ in map name!"));
Expand Down Expand Up @@ -592,7 +592,7 @@ Bool MapCache::addMap(
{
// unofficial maps or maps without names
AsciiString tempdisplayname;
tempdisplayname = fname.reverseFind('\\') + 1;
tempdisplayname = getFileName(fname.str());
(*this)[lowerFname].m_displayName.translate(tempdisplayname);
if (md.m_numPlayers >= 2)
{
Expand Down Expand Up @@ -654,7 +654,7 @@ Bool MapCache::addMap(
{
DEBUG_LOG(("Missing TheKey_mapName!"));
AsciiString tempdisplayname;
tempdisplayname = fname.reverseFind('\\') + 1;
tempdisplayname = getFileName(fname.str());
md.m_displayName.translate(tempdisplayname);
if (md.m_numPlayers >= 2)
{
Expand Down
21 changes: 3 additions & 18 deletions Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,26 +1140,11 @@ void TerrainLogic::enableWaterGrid( Bool enable )
// the fact that the map Data\CHI01\CHI01.map will turn into Save\CHI01.map when
// loading the map from a save game file
//
AsciiString strippedMapNameOnly;
AsciiString strippedCompareMapNameOnly;
const char *c;

// create stripped map name
c = strrchr( TheGlobalData->m_mapName.str(), '\\' );
if( c )
strippedMapNameOnly.set( c );
else
strippedMapNameOnly = TheGlobalData->m_mapName;

// create stripped compare name
c = strrchr( TheGlobalData->m_vertexWaterAvailableMaps[ i ].str(), '\\' );
if( c )
strippedCompareMapNameOnly.set( c );
else
strippedCompareMapNameOnly = TheGlobalData->m_vertexWaterAvailableMaps[ i ];
const char* strippedMapNameOnly = getFileName( TheGlobalData->m_mapName.str() );
const char* strippedCompareMapNameOnly = getFileName( TheGlobalData->m_vertexWaterAvailableMaps[ i ].str() );

// now try this compare
if( strippedMapNameOnly.compareNoCase( strippedCompareMapNameOnly.str() ) == 0 )
if( stricmp( strippedMapNameOnly, strippedCompareMapNameOnly ) == 0 )
{

waterSettingIndex = i;
Expand Down
38 changes: 5 additions & 33 deletions Core/GameEngine/Source/GameNetwork/FileTransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,55 +137,27 @@ static Bool doFileTransfer( AsciiString filename, MapTransferLoadScreen *ls, Int

AsciiString GetBasePathFromPath( AsciiString path )
{
const char *s = path.reverseFind('\\');
const char *s = getLastPathSeparator(path.str());
if (s)
{
Int len = s - path.str();

AsciiString base;
char *buf = base.getBufferForRead(len + 1);
memcpy(buf, path.str(), len);
buf[len] = 0;
return buf;
return AsciiString(path.str(), s - path.str());
}
return AsciiString::TheEmptyString;
}

AsciiString GetFileFromPath( AsciiString path )
{
const char *s = path.reverseFind('\\');
if (s)
return s+1;
return path;
}

AsciiString GetExtensionFromFile( AsciiString fname )
{
const char *s = fname.reverseFind('.');
if (s)
return s+1;
return fname;
}

AsciiString GetBaseFileFromFile( AsciiString fname )
{
const char *s = fname.reverseFind('.');
const char *s = getExtension(fname.str());
if (s)
{
Int len = s - fname.str();

AsciiString base;
char *buf = base.getBufferForRead(len + 1);
memcpy(buf, fname.str(), len);
buf[len] = 0;
return buf;
return AsciiString(fname.str(), s - fname.str());
}
return AsciiString::TheEmptyString;
}

AsciiString GetPreviewFromMap( AsciiString path )
{
AsciiString fname = GetBaseFileFromFile(GetFileFromPath(path));
AsciiString fname = GetBaseFileFromFile(getFileName(path.str()));
AsciiString base = GetBasePathFromPath(path);

AsciiString out;
Expand Down
4 changes: 2 additions & 2 deletions Core/GameEngine/Source/GameNetwork/GameInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ void GameInfo::setMap( AsciiString mapName )
// directory name, we can do this since the filename
// is just the directory name with the file extention
// added onto it.
while (mapName.find('\\') != nullptr)
while (getLastPathSeparator(mapName.str()) != nullptr)
{
if (!newMapName.isEmpty())
{
Expand Down Expand Up @@ -973,7 +973,7 @@ static AsciiString buildGameInfoAsciiString(const GameInfo& game, const AsciiStr
// directory name, we can do this since the filename
// is just the directory name with the file extention
// added onto it.
while (mapName.find('\\') != nullptr)
while (getLastPathSeparator(mapName.str()) != nullptr)
{
if (!newMapName.isEmpty())
{
Expand Down
22 changes: 2 additions & 20 deletions Core/GameEngine/Source/GameNetwork/GameSpy/LobbyUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,7 @@ static void gameTooltip(GameWindow *window,
}
else
{
const char *start = room->getMap().reverseFind('\\');
if (start)
{
++start;
}
else
{
start = room->getMap().str();
}
mapName.translate( start );
mapName.translate( getFileName(room->getMap().str()) );
}
UnicodeString tmp;
tooltip.format(TheGameText->fetch("TOOLTIP:GameInfoGameName"), room->getGameName().str());
Expand Down Expand Up @@ -584,16 +575,7 @@ static Int insertGame( GameWindow *win, GameSpyStagingRoom *game, Bool showMap )
}
else
{
const char *start = game->getMap().reverseFind('\\');
if (start)
{
++start;
}
else
{
start = game->getMap().str();
}
mapName.translate( start );
mapName.translate( getFileName(game->getMap().str()) );
}
GadgetListBoxAddEntryText(win, mapName, gameColor, index, COLUMN_MAP);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void MilesAudioManager::audioDebugDisplay(DebugDisplayInterface *dd, void *, FIL

AudioEventRTS *event = playing->m_audioEventRTS.Peek();
filenameNoSlashes = event->getFilename();
filenameNoSlashes = filenameNoSlashes.reverseFind('\\') + 1;
filenameNoSlashes = getFileName(filenameNoSlashes.str());

// Calculate Sample volume
volume = 100.0f;
Expand All @@ -265,7 +265,7 @@ void MilesAudioManager::audioDebugDisplay(DebugDisplayInterface *dd, void *, FIL
playing = *it;
AudioEventRTS *event = playing->m_audioEventRTS.Peek();
filenameNoSlashes = event->getFilename();
filenameNoSlashes = filenameNoSlashes.reverseFind( '\\' ) + 1;
filenameNoSlashes = getFileName(filenameNoSlashes.str());

// Calculate Sample volume
volume = 100.0f;
Expand Down Expand Up @@ -302,7 +302,7 @@ void MilesAudioManager::audioDebugDisplay(DebugDisplayInterface *dd, void *, FIL

AudioEventRTS *event = playing->m_audioEventRTS.Peek();
filenameNoSlashes = event->getFilename();
filenameNoSlashes = filenameNoSlashes.reverseFind('\\') + 1;
filenameNoSlashes = getFileName(filenameNoSlashes.str());

// Calculate Sample volume
volume = 100.0f;
Expand Down Expand Up @@ -354,7 +354,7 @@ void MilesAudioManager::audioDebugDisplay(DebugDisplayInterface *dd, void *, FIL
playing = *it;
AudioEventRTS *event = playing->m_audioEventRTS.Peek();
filenameNoSlashes = event->getFilename();
filenameNoSlashes = filenameNoSlashes.reverseFind('\\') + 1;
filenameNoSlashes = getFileName(filenameNoSlashes.str());

// Calculate Sample volume
volume = 100.0f;
Expand All @@ -378,7 +378,7 @@ void MilesAudioManager::audioDebugDisplay(DebugDisplayInterface *dd, void *, FIL
playing = *it;
AudioEventRTS *event = playing->m_audioEventRTS.Peek();
filenameNoSlashes = event->getFilename();
filenameNoSlashes = filenameNoSlashes.reverseFind('\\') + 1;
filenameNoSlashes = getFileName(filenameNoSlashes.str());

// Calculate Sample volume
volume = 100.0f;
Expand All @@ -402,7 +402,7 @@ void MilesAudioManager::audioDebugDisplay(DebugDisplayInterface *dd, void *, FIL
playing = *it;
AudioEventRTS *event = playing->m_audioEventRTS.Peek();
filenameNoSlashes = event->getFilename();
filenameNoSlashes = filenameNoSlashes.reverseFind('\\') + 1;
filenameNoSlashes = getFileName(filenameNoSlashes.str());

// Calculate Sample volume
volume = 100.0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void LogClass::log(const char *fmt, ...)
void LogClass::dumpMatrix3D(const Matrix3D *m, AsciiString name, AsciiString fname, Int line)
{
fname.toLower();
fname = fname.reverseFind('\\') + 1;
fname = getFileName(fname.str());
const Real *matrix = (const Real *)m;
log("dumpMatrix3D() %s:%d %s",
fname.str(), line, name.str());
Expand All @@ -166,7 +166,7 @@ void LogClass::dumpReal(Real r, AsciiString name, AsciiString fname, Int line)
if (!m_fp || !isValidTimeToCalcLogicStuff())
return;
fname.toLower();
fname = fname.reverseFind('\\') + 1;
fname = getFileName(fname.str());
log("dumpReal() %s:%d %s %8.8X (%f)",
fname.str(), line, name.str(), AS_INT(r), r);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3260,11 +3260,7 @@ void W3DDisplay::dumpAssetUsage(const char* mapname)
DynamicVectorClass<StringClass> names(8000);
m_assetManager->Create_Asset_List(names);

const char* leafname = strrchr(mapname, '\\');
if (leafname)
++leafname; // point to first character after the last backslash
else
leafname = mapname; // point to the start of the filename
const char* leafname = getFileName(mapname);

char buf[256];
int idx = 1;
Expand Down
1 change: 1 addition & 0 deletions Core/Libraries/Source/WWVegas/WWLib/WWCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#pragma once

#include "Lib/PathUtil.h"
#include "ref_ptr.h"
#include "refcount.h"
#include "Utility/STLUtils.h"
Expand Down
Loading
Loading