MCPcopy Create free account
hub / github.com/BSVino/DoubleAction / LoadFromFile

Method LoadFromFile

mp/src/tier1/KeyValues.cpp:633–667  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: Load keyValues from disk -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

631// Purpose: Load keyValues from disk
632//-----------------------------------------------------------------------------
633bool KeyValues::LoadFromFile( IBaseFileSystem *filesystem, const char *resourceName, const char *pathID )
634{
635 Assert(filesystem);
636#ifdef WIN32
637 Assert( IsX360() || ( IsPC() && _heapchk() == _HEAPOK ) );
638#endif
639 FileHandle_t f = filesystem->Open(resourceName, "rb", pathID);
640 if ( !f )
641 return false;
642
643 s_LastFileLoadingFrom = (char*)resourceName;
644
645 // load file into a null-terminated buffer
646 int fileSize = filesystem->Size( f );
647 unsigned bufSize = ((IFileSystem *)filesystem)->GetOptimalReadSize( f, fileSize + 2 );
648
649 char *buffer = (char*)((IFileSystem *)filesystem)->AllocOptimalReadBuffer( f, bufSize );
650 Assert( buffer );
651
652 // read into local buffer
653 bool bRetOK = ( ((IFileSystem *)filesystem)->ReadEx( buffer, bufSize, fileSize, f ) != 0 );
654
655 filesystem->Close( f ); // close file after reading
656
657 if ( bRetOK )
658 {
659 buffer[fileSize] = 0; // null terminate file as EOF
660 buffer[fileSize+1] = 0; // double NULL terminating in case this is a unicode file
661 bRetOK = LoadFromBuffer( resourceName, buffer, filesystem );
662 }
663
664 ((IFileSystem *)filesystem)->FreeOptimalReadBuffer( buffer );
665
666 return bRetOK;
667}
668
669//-----------------------------------------------------------------------------
670// Purpose: Save the keyvalues to disk

Callers 14

LoadCmdLineFromFileFunction · 0.45
AppendKeyValuesFileMethod · 0.45
CreateMaterialPatchFunction · 0.45
DoesMaterialHaveKeyFunction · 0.45
GetValueFromMaterialFunction · 0.45
LoadSurfacePropertiesFunction · 0.45
ReloadKeyBindingsMethod · 0.45

Calls 9

AssertFunction · 0.85
_heapchkFunction · 0.85
GetOptimalReadSizeMethod · 0.80
ReadExMethod · 0.80
FreeOptimalReadBufferMethod · 0.80
OpenMethod · 0.45
SizeMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected