MCPcopy Create free account
hub / github.com/0ldsk00l/nestopia / LoadFileData

Method LoadFileData

source/win32/NstManagerEmulator.cpp:661–813  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

659 }
660
661 void Emulator::LoadFileData(Nes::User::File& context,const bool loadSamples,Path path,wcstring const filename) const
662 {
663 NST_VERIFY( filename && *filename );
664
665 if (!filename || !*filename)
666 return;
667
668 cstring errReason = NULL;
669
670 try
671 {
672 if (path.Length())
673 {
674 Io::File file( path, Io::File::COLLECT );
675 Io::Archive archive( file );
676
677 uint index = archive.Find( filename );
678
679 if (index && index-- != Io::Archive::NO_FILES)
680 {
681 Collection::Buffer buffer( archive[index].Size() );
682
683 if (buffer.Size())
684 {
685 archive[index].Uncompress( buffer.Ptr() );
686
687 archive.Close();
688 file.Close();
689
690 if (loadSamples)
691 {
692 WAVEFORMATEX format;
693 Io::Wave wave( Io::Wave::MODE_READ );
694
695 if (const uint size = wave.Open( buffer.Ptr(), buffer.Size(), format ))
696 {
697 buffer.Resize( size );
698 wave.Read( buffer.Ptr() );
699 wave.Close();
700
701 const Nes::Result result = context.SetSampleContent
702 (
703 buffer.Ptr(),
704 buffer.Size() / format.nBlockAlign,
705 format.nChannels == 2,
706 format.wBitsPerSample,
707 format.nSamplesPerSec
708 );
709
710 if (NES_FAILED(result))
711 throw result;
712 }
713 else
714 {
715 throw Nes::RESULT_ERR_INVALID_FILE;
716 }
717 }
718 else

Callers 1

DoFileIOMethod · 0.80

Calls 15

DirectoryMethod · 0.80
FileExistsMethod · 0.80
LogClass · 0.70
LengthMethod · 0.45
FindMethod · 0.45
SizeMethod · 0.45
UncompressMethod · 0.45
PtrMethod · 0.45
CloseMethod · 0.45
OpenMethod · 0.45
ResizeMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected