MCPcopy Create free account
hub / github.com/CytopiaTeam/Cytopia / CopyFile

Method CopyFile

external/as_add_on/scriptfile/scriptfilesystem.cpp:424–468  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

422}
423
424int CScriptFileSystem::CopyFile(const string &source, const string &target)
425{
426 string search1;
427 if (source.find(":") != string::npos || source.find("/") == 0 || source.find("\\") == 0)
428 search1 = source;
429 else
430 search1 = currentPath + "/" + source;
431
432 string search2;
433 if (target.find(":") != string::npos || target.find("/") == 0 || target.find("\\") == 0)
434 search2 = target;
435 else
436 search2 = currentPath + "/" + target;
437
438#if defined(_WIN32)
439 // Windows uses UTF16 so it is necessary to convert the string
440 wchar_t bufUTF16_1[10000];
441 MultiByteToWideChar(CP_UTF8, 0, search1.c_str(), -1, bufUTF16_1, 10000);
442
443 wchar_t bufUTF16_2[10000];
444 MultiByteToWideChar(CP_UTF8, 0, search2.c_str(), -1, bufUTF16_2, 10000);
445
446 // Copy the file
447 BOOL success = CopyFileW(bufUTF16_1, bufUTF16_2, TRUE);
448 return success ? 0 : -1;
449#else
450 // Copy the file manually as there is no posix function for this
451 bool failure = false;
452 FILE *src = 0, *tgt = 0;
453 src = fopen(search1.c_str(), "r");
454 if (src == 0) failure = true;
455 if( !failure ) tgt = fopen(search2.c_str(), "w");
456 if (tgt == 0) failure = true;
457 char buf[1024];
458 size_t n;
459 while (!failure && (n = fread(buf, sizeof(char), sizeof(buf), src)) > 0)
460 {
461 if (fwrite(buf, sizeof(char), n, tgt) != n)
462 failure = true;
463 }
464 if (src) fclose(src);
465 if (tgt) fclose(tgt);
466 return !failure ? 0 : -1;
467#endif
468}
469
470int CScriptFileSystem::Move(const string &source, const string &target)
471{

Callers

nothing calls this directly

Calls 1

findMethod · 0.80

Tested by

no test coverage detected