diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index 7583e2479b9..f784e7ee709 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -725,6 +725,7 @@ reg_t kFileIOFindFirst(EngineState *s, int argc, reg_t *argv); reg_t kFileIOFindNext(EngineState *s, int argc, reg_t *argv); reg_t kFileIOExists(EngineState *s, int argc, reg_t *argv); reg_t kFileIORename(EngineState *s, int argc, reg_t *argv); +reg_t kFileIOCopy(EngineState *s, int argc, reg_t *argv); #ifdef ENABLE_SCI32 reg_t kFileIOReadByte(EngineState *s, int argc, reg_t *argv); reg_t kFileIOWriteByte(EngineState *s, int argc, reg_t *argv); diff --git a/engines/sci/engine/kernel_tables.h b/engines/sci/engine/kernel_tables.h index 8dab3263617..8275a36f9af 100644 --- a/engines/sci/engine/kernel_tables.h +++ b/engines/sci/engine/kernel_tables.h @@ -322,6 +322,7 @@ static const SciKernelMapSubEntry kFileIO_subops[] = { { SIG_SCIALL, 9, MAP_CALL(FileIOFindNext), "r", NULL }, { SIG_SCIALL, 10, MAP_CALL(FileIOExists), "r", NULL }, { SIG_SINCE_SCI11, 11, MAP_CALL(FileIORename), "rr", NULL }, + { SIG_SINCE_SCI11, 12, MAP_CALL(FileIOCopy), "rr", NULL }, #ifdef ENABLE_SCI32 { SIG_SINCE_SCI21MID, 13, MAP_CALL(FileIOReadByte), "i", NULL }, { SIG_SINCE_SCI21MID, 14, MAP_CALL(FileIOWriteByte), "ii", NULL }, diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp index 1e3f8bfd4c4..3256e20fffb 100644 --- a/engines/sci/engine/kfile.cpp +++ b/engines/sci/engine/kfile.cpp @@ -912,6 +912,25 @@ reg_t kFileIORename(EngineState *s, int argc, reg_t *argv) { return SIGNAL_REG; } +reg_t kFileIOCopy(EngineState *s, int argc, reg_t *argv) { + Common::String oldName = s->_segMan->getString(argv[0]); + Common::String newName = s->_segMan->getString(argv[1]); + + oldName = g_sci->wrapFilename(oldName); + newName = g_sci->wrapFilename(newName); + + // Phantasmagoria 1 files are small and interoperable with the + // original interpreter so they aren't compressed, see file_open(). + bool isCompressed = (g_sci->getGameId() != GID_PHANTASMAGORIA); + + // SCI1.1 returns 0 on success and a DOS error code on fail. SCI32 + // returns -1 on fail. We just return -1 for all versions. + if (g_sci->getSaveFileManager()->copySavefile(oldName, newName, isCompressed)) + return NULL_REG; + else + return SIGNAL_REG; +} + #ifdef ENABLE_SCI32 reg_t kFileIOReadByte(EngineState *s, int argc, reg_t *argv) { // Read the byte into the low byte of the accumulator