Skip to content
Merged
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
53 changes: 5 additions & 48 deletions Generals/Code/GameEngine/Source/GameClient/MapUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,12 @@ static Coord3DList m_techPositions;
static Int m_mapDX = 0;
static Int m_mapDY = 0;

static UnsignedInt calcCRC( AsciiString dirName, AsciiString fname )
static UnsignedInt calcCRC( AsciiString fname )
{
CRC theCRC;
theCRC.clear();

// Try the official map dir
AsciiString asciiFile;
char tempBuf[_MAX_PATH];
char filenameBuf[_MAX_PATH];
int length = 0;
strcpy(tempBuf, fname.str());
length = strlen( tempBuf );
if( length >= 4 )
{
strlcpy( filenameBuf, tempBuf, length - 4 + 1);
}

File *fp;
asciiFile = fname;
fp = TheFileSystem->openFile(asciiFile.str(), File::READ);
File *fp = TheFileSystem->openFile(fname.str(), File::READ);
Copy link

Choose a reason for hiding this comment

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

Is it correct that this does not use dirName? Does it work with User Maps?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, in the original code (main branch line 84), calcCRC declared dirName as a parameter but never used it. The function only used fname to open the file.

fname comes from getFileListInDirectory, which returns either relative (standard maps) or absolute path (user maps)

TheFileSystem->openFile() handles both eg MapCache::loadStandardMaps and MapCache::loadUserMaps

if( !fp )
{
DEBUG_CRASH(("Couldn't open '%s'", fname.str()));
Expand Down Expand Up @@ -231,23 +217,9 @@ static Bool ParseSizeOnlyInChunk(DataChunkInput &file, DataChunkInfo *info, void

static Bool loadMap( AsciiString filename )
{
char tempBuf[_MAX_PATH];
char filenameBuf[_MAX_PATH];
AsciiString asciiFile;
int length = 0;

strcpy(tempBuf, filename.str());

length = strlen( tempBuf );
if( length >= 4 )
{
strlcpy( filenameBuf, tempBuf, length - 4 + 1);
}

CachedFileInputStream fileStrm;

asciiFile = filename;
if( !fileStrm.open(asciiFile) )
if( !fileStrm.open(filename) )
{
return FALSE;
}
Expand Down Expand Up @@ -593,17 +565,6 @@ Bool MapCache::loadUserMaps()
else
{
if (TheFileSystem->getFileInfo(tempfilename, &fileInfo)) {
char funk[_MAX_PATH];
strcpy(funk, tempfilename.str());
char *filenameptr = funk;
char *tempchar = funk;
while (*tempchar != 0) {
if ((*tempchar == '\\') || (*tempchar == '/')) {
filenameptr = tempchar+1;
}
++tempchar;
}

m_seen[tempfilename] = TRUE;
parsedAMap |= addMap(mapDir, *iter, &fileInfo, TheGlobalData->m_buildMapCache);
} else {
Expand Down Expand Up @@ -672,7 +633,7 @@ Bool MapCache::addMap( AsciiString dirName, AsciiString fname, FileInfo *fileInf
md.m_timestamp.m_lowTimeStamp = fileInfo->timestampLow;
md.m_supplyPositions = m_supplyPositions;
md.m_techPositions = m_techPositions;
md.m_CRC = calcCRC(dirName, fname);
md.m_CRC = calcCRC(fname);

Bool exists = false;
AsciiString munkee = worldDict.getAsciiString(TheKey_mapName, &exists);
Expand Down Expand Up @@ -1053,12 +1014,8 @@ Image *getMapPreviewImage( AsciiString mapName )
AsciiString tgaName = mapName;
AsciiString name;
AsciiString tempName;
AsciiString filename;
tgaName.truncateBy(4); // ".map"
name = tgaName;//.reverseFind('\\') + 1;
filename = tgaName.reverseFind('\\') + 1;
//tgaName = name;
filename.concat(".tga");
name = tgaName;
tgaName.concat(".tga");

AsciiString portableName = TheGameState->realMapPathToPortableMapPath(name);
Expand Down
53 changes: 5 additions & 48 deletions GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,12 @@ static Coord3DList m_techPositions;
static Int m_mapDX = 0;
static Int m_mapDY = 0;

static UnsignedInt calcCRC( AsciiString dirName, AsciiString fname )
static UnsignedInt calcCRC( AsciiString fname )
{
CRC theCRC;
theCRC.clear();

// Try the official map dir
AsciiString asciiFile;
char tempBuf[_MAX_PATH];
char filenameBuf[_MAX_PATH];
int length = 0;
strcpy(tempBuf, fname.str());
length = strlen( tempBuf );
if( length >= 4 )
{
strlcpy( filenameBuf, tempBuf, length - 4 + 1);
}

File *fp;
asciiFile = fname;
fp = TheFileSystem->openFile(asciiFile.str(), File::READ);
File *fp = TheFileSystem->openFile(fname.str(), File::READ);
if( !fp )
{
DEBUG_CRASH(("Couldn't open '%s'", fname.str()));
Expand Down Expand Up @@ -231,23 +217,9 @@ static Bool ParseSizeOnlyInChunk(DataChunkInput &file, DataChunkInfo *info, void

static Bool loadMap( AsciiString filename )
{
char tempBuf[_MAX_PATH];
char filenameBuf[_MAX_PATH];
AsciiString asciiFile;
int length = 0;

strcpy(tempBuf, filename.str());

length = strlen( tempBuf );
if( length >= 4 )
{
strlcpy( filenameBuf, tempBuf, length - 4 + 1);
}

CachedFileInputStream fileStrm;

asciiFile = filename;
if( !fileStrm.open(asciiFile) )
if( !fileStrm.open(filename) )
{
return FALSE;
}
Expand Down Expand Up @@ -595,17 +567,6 @@ Bool MapCache::loadUserMaps()
else
{
if (TheFileSystem->getFileInfo(tempfilename, &fileInfo)) {
char funk[_MAX_PATH];
strcpy(funk, tempfilename.str());
char *filenameptr = funk;
char *tempchar = funk;
while (*tempchar != 0) {
if ((*tempchar == '\\') || (*tempchar == '/')) {
filenameptr = tempchar+1;
}
++tempchar;
}

m_seen[tempfilename] = TRUE;
parsedAMap |= addMap(mapDir, *iter, &fileInfo, TheGlobalData->m_buildMapCache);
} else {
Expand Down Expand Up @@ -699,7 +660,7 @@ Bool MapCache::addMap( AsciiString dirName, AsciiString fname, FileInfo *fileInf
md.m_timestamp.m_lowTimeStamp = fileInfo->timestampLow;
md.m_supplyPositions = m_supplyPositions;
md.m_techPositions = m_techPositions;
md.m_CRC = calcCRC(dirName, fname);
md.m_CRC = calcCRC(fname);

Bool exists = false;
AsciiString munkee = worldDict.getAsciiString(TheKey_mapName, &exists);
Expand Down Expand Up @@ -1133,12 +1094,8 @@ Image *getMapPreviewImage( AsciiString mapName )
AsciiString tgaName = mapName;
AsciiString name;
AsciiString tempName;
AsciiString filename;
tgaName.truncateBy(4); // ".map"
name = tgaName;//.reverseFind('\\') + 1;
filename = tgaName.reverseFind('\\') + 1;
//tgaName = name;
filename.concat(".tga");
name = tgaName;
tgaName.concat(".tga");

AsciiString portableName = TheGameState->realMapPathToPortableMapPath(name);
Expand Down
Loading