Skip to content
Open
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
58 changes: 17 additions & 41 deletions Core/GameEngine/Source/GameClient/MapUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,53 +1090,38 @@ const MapMetaData *MapCache::findMap(AsciiString mapName)
// ------------------------------------------------------------------------------------------------
/** Embed the pristine map into the xfer stream */
// ------------------------------------------------------------------------------------------------
static void copyFromBigToDir( const AsciiString& infile, const AsciiString& outfile )
static Bool copyFromBigToDir( const AsciiString& infile, const AsciiString& outfile )
{
// open the map file

File *file = TheFileSystem->openFile( infile.str(), File::READ | File::BINARY );
if( file == nullptr )
{
DEBUG_CRASH(( "copyFromBigToDir - Error opening source file '%s'", infile.str() ));
throw SC_INVALID_DATA;
return FALSE;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Might be good to have an assert here still to warn on failure of file opening

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

added the assert back

}

// how big is the map file
Int fileSize = file->seek( 0, File::END );


// rewind to beginning of file
const Int fileSize = file->seek( 0, File::END );
file->seek( 0, File::START );

// allocate buffer big enough to hold the entire map file
char *buffer = NEW char[ fileSize ];
if( buffer == nullptr )
{
DEBUG_CRASH(( "copyFromBigToDir - Unable to allocate buffer for file '%s'", infile.str() ));
throw SC_INVALID_DATA;
}

// copy the file to the buffer
if( file->read( buffer, fileSize ) < fileSize )
{
DEBUG_CRASH(( "copyFromBigToDir - Error reading from file '%s'", infile.str() ));
throw SC_INVALID_DATA;
}
// close the BIG file
const Bool readOk = file->read( buffer, fileSize ) == fileSize;
file->close();
DEBUG_ASSERTCRASH( readOk, ( "copyFromBigToDir - Error reading from file '%s'", infile.str() ) );

File *filenew = TheFileSystem->openFile( outfile.str(), File::WRITE | File::CREATE | File::BINARY );

if( !filenew || filenew->write(buffer, fileSize) < fileSize)
Bool writeOk = FALSE;
if( readOk )
{
DEBUG_CRASH(( "copyFromBigToDir - Error writing to file '%s'", outfile.str() ));
throw SC_INVALID_DATA;
File *filenew = TheFileSystem->openFile( outfile.str(), File::WRITE | File::CREATE | File::BINARY );
if( filenew != 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.

Would be good to assert on failure.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

added, the assert covers both opening and writing the output file

{
writeOk = filenew->write( buffer, fileSize ) == fileSize;
filenew->close();
}
DEBUG_ASSERTCRASH( writeOk, ( "copyFromBigToDir - Error writing to file '%s'", outfile.str() ) );
}

filenew->close();

// delete the buffer
delete [] buffer;

return writeOk;
}

Image *getMapPreviewImage( AsciiString mapName )
Expand Down Expand Up @@ -1181,16 +1166,7 @@ Image *getMapPreviewImage( AsciiString mapName )

mapPreviewDir.concat(name);

Bool success = false;
try
{
copyFromBigToDir(tgaName, mapPreviewDir);
success = true;
}
catch (...)
{
success = false; // no rethrow
}
const Bool success = copyFromBigToDir(tgaName, mapPreviewDir);
Comment thread
tintinhamans marked this conversation as resolved.
Comment thread
coderabbitai[bot] marked this conversation as resolved.

if (success)
{
Expand Down
Loading