MCPcopy Create free account
hub / github.com/dborth/vbagx / LoadFile

Function LoadFile

source/fileop.cpp:846–934  ·  view source on GitHub ↗

* LoadFile ***************************************************************************/

Source from the content-addressed store, hash-verified

844 * LoadFile
845 ***************************************************************************/
846size_t
847LoadFile (char * rbuffer, char *filepath, size_t length, size_t buffersize, bool silent)
848{
849 char zipbuffer[2048];
850 size_t size = 0, offset = 0, readsize = 0;
851 int retry = 1;
852 int device;
853
854 if(!FindDevice(filepath, &device))
855 return 0;
856
857 // stop checking if devices were removed/inserted
858 // since we're loading a file
859 HaltDeviceThread();
860
861 // halt parsing
862 HaltParseThread();
863
864 // open the file
865 while(retry)
866 {
867 if(!ChangeInterface(device, silent))
868 break;
869
870 file = fopen (filepath, "rb");
871
872 if(!file)
873 {
874 if(silent)
875 break;
876
877 retry = ErrorPromptRetry("Error opening file!");
878 continue;
879 }
880
881 if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
882 {
883 size = fread (rbuffer, 1, length, file);
884 }
885 else // load whole file
886 {
887 readsize = fread (zipbuffer, 1, 32, file);
888
889 if(!readsize)
890 {
891 unmountRequired[device] = true;
892 retry = ErrorPromptRetry("Error reading file!");
893 fclose (file);
894 continue;
895 }
896
897 if (IsZipFile (zipbuffer))
898 {
899 size = UnZipBuffer ((unsigned char *)rbuffer, buffersize); // unzip
900 }
901 else
902 {
903 fseeko(file,0,SEEK_END);

Callers 10

GetFirstZipFilenameFunction · 0.85
LoadBatteryOrStateFunction · 0.85
SaveBatteryOrStateFunction · 0.85
LoadPatchFunction · 0.85
LoadPNGBorderFunction · 0.85
LoadGBROMFunction · 0.85
LoadPrefsFromMethodFunction · 0.85
LoadPalettesFunction · 0.85
MenuGameSavesFunction · 0.85
VMCPULoadROMFunction · 0.85

Calls 10

FindDeviceFunction · 0.85
HaltDeviceThreadFunction · 0.85
HaltParseThreadFunction · 0.85
ChangeInterfaceFunction · 0.85
ErrorPromptRetryFunction · 0.85
IsZipFileFunction · 0.85
UnZipBufferFunction · 0.85
ShowProgressFunction · 0.85
CancelActionFunction · 0.85
ResumeDeviceThreadFunction · 0.85

Tested by

no test coverage detected