MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / cf_CopyFile

Function cf_CopyFile

cfile/cfile.cpp:832–868  ·  view source on GitHub ↗

Copies a file. Returns TRUE if copied ok. Returns FALSE if error opening either file. Throws an exception of type (cfile_error *) if the OS returns an error on read or write

Source from the content-addressed store, hash-verified

830// Copies a file. Returns TRUE if copied ok. Returns FALSE if error opening either file.
831// Throws an exception of type (cfile_error *) if the OS returns an error on read or write
832bool cf_CopyFile(const std::filesystem::path &dest, const std::filesystem::path &src, int copytime) {
833 CFILE *infile, *outfile;
834 if (!stricmp(dest.u8string().c_str(), src.u8string().c_str()))
835 return true; // don't copy files if they are the same
836 infile = (CFILE *)cfopen(src, "rb");
837 if (!infile)
838 return false;
839 outfile = (CFILE *)cfopen(dest, "wb");
840 if (!outfile) {
841 cfclose(infile);
842 return false;
843 }
844 int progress = 0;
845 int readcount = 0;
846#define COPY_CHUNK_SIZE 5000
847 uint8_t copybuf[COPY_CHUNK_SIZE];
848 while (!cfeof(infile)) {
849 // uint8_t c;
850
851 if (progress + COPY_CHUNK_SIZE <= infile->size) {
852 readcount = COPY_CHUNK_SIZE;
853 } else {
854 readcount = infile->size - progress;
855 }
856 cf_ReadBytes(copybuf, readcount, infile);
857 cf_WriteBytes(copybuf, readcount, outfile);
858 progress += readcount;
859 // c=cf_ReadByte (infile);
860 // cf_WriteByte (outfile,c);
861 }
862 cfclose(infile);
863 cfclose(outfile);
864 if (!infile->lib_offset && copytime) {
865 cf_CopyFileTime(dest, src);
866 }
867 return true;
868}
869
870// Checks to see if two files are different.
871// Returns TRUE if the files are different, or FALSE if they are the same.

Callers 15

mng_BackupTableFileFunction · 0.85
UpdatePrimitiveFunction · 0.85
OnAddSoundMethod · 0.85
OnCheckinSoundMethod · 0.85
OnLoadSoundMethod · 0.85
CopyScriptFileFunction · 0.85
OnAddNewRobotMethod · 0.85
OnCheckinRobotMethod · 0.85
OnRobotModelMethod · 0.85
AddNewGameFileFunction · 0.85
CheckInGamefileFunction · 0.85
OnAddWeaponMethod · 0.85

Calls 6

cfopenFunction · 0.85
cfcloseFunction · 0.85
cfeofFunction · 0.85
cf_ReadBytesFunction · 0.85
cf_WriteBytesFunction · 0.85
cf_CopyFileTimeFunction · 0.85

Tested by

no test coverage detected