MCPcopy Create free account
hub / github.com/TASEmulators/fceux / SaveINESFile

Method SaveINESFile

src/drivers/Qt/iNesHeaderEditor.cpp:731–773  ·  view source on GitHub ↗

----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

729}
730//----------------------------------------------------------------------------
731bool iNesHeaderEditor_t::SaveINESFile(const char* path, iNES_HEADER* header)
732{
733 char buf[4096];
734 const char* ext[] = { "nes", 0 };
735
736 // Source file
737 FCEUFILE* source = FCEU_fopen(LoadedRomFName, NULL, "rb", 0, -1, ext);
738 if (!source)
739 {
740 char msg[5120];
741 snprintf(msg, sizeof(msg), "Opening source file %s failed.", LoadedRomFName);
742 showErrorMsgWindow(msg);
743 return false;
744 }
745
746 // Destination file
747 FILE* target = FCEUD_UTF8fopen(path, "wb");
748 if (!target)
749 {
750 char msg[5120];
751 snprintf(msg, sizeof(msg), "Creating target file %s failed.", path);
752 showErrorMsgWindow(msg);
753 return false;
754 }
755
756 memset(buf, 0, sizeof(buf));
757
758 // Write the header first
759 fwrite(header, 1, sizeof(iNES_HEADER), target);
760 // Skip the original header
761 FCEU_fseek(source, sizeof(iNES_HEADER), SEEK_SET);
762 int len;
763 while (len = FCEU_fread(buf, 1, sizeof(buf), source))
764 {
765 fwrite(buf, len, 1, target);
766 }
767
768 FCEU_fclose(source);
769 fclose(target);
770
771 return true;
772
773}
774
775//----------------------------------------------------------------------------
776bool iNesHeaderEditor_t::openFile(void)

Callers

nothing calls this directly

Calls 5

FCEU_fopenFunction · 0.85
FCEU_fseekFunction · 0.85
FCEU_freadFunction · 0.85
FCEU_fcloseFunction · 0.85
FCEUD_UTF8fopenFunction · 0.70

Tested by

no test coverage detected