mirror of
https://github.com/rvtr/GodMode9i.git
synced 2025-06-18 10:55:31 -04:00
70 lines
1.3 KiB
C++
70 lines
1.3 KiB
C++
#include <nds.h>
|
|
#include <stdio.h>
|
|
|
|
u32 copyBuf[0x8000];
|
|
|
|
off_t getFileSize(const char *fileName)
|
|
{
|
|
FILE* fp = fopen(fileName, "rb");
|
|
off_t fsize = 0;
|
|
if (fp) {
|
|
fseek(fp, 0, SEEK_END);
|
|
fsize = ftell(fp); // Get source file's size
|
|
fseek(fp, 0, SEEK_SET);
|
|
}
|
|
fclose(fp);
|
|
|
|
return fsize;
|
|
}
|
|
|
|
int fcopy(const char *sourcePath, const char *destinationPath)
|
|
{
|
|
FILE* sourceFile = fopen(sourcePath, "rb");
|
|
off_t fsize = 0;
|
|
if (sourceFile) {
|
|
fseek(sourceFile, 0, SEEK_END);
|
|
fsize = ftell(sourceFile); // Get source file's size
|
|
fseek(sourceFile, 0, SEEK_SET);
|
|
} else {
|
|
fclose(sourceFile);
|
|
return -1;
|
|
}
|
|
|
|
FILE* destinationFile = fopen(destinationPath, "wb");
|
|
//if (destinationFile) {
|
|
fseek(destinationFile, 0, SEEK_SET);
|
|
/*} else {
|
|
fclose(sourceFile);
|
|
fclose(destinationFile);
|
|
return -1;
|
|
}*/
|
|
|
|
off_t offset = 0;
|
|
int numr;
|
|
while (1)
|
|
{
|
|
/* scanKeys();
|
|
if (keysHeld() & KEY_A) {
|
|
// Cancel copying
|
|
fclose(sourceFile);
|
|
fclose(destinationFile);
|
|
return -1;
|
|
break;
|
|
} */
|
|
|
|
// Copy file to destination path
|
|
numr = fread(copyBuf, 2, 0x8000, sourceFile);
|
|
fwrite(copyBuf, 2, numr, destinationFile);
|
|
offset += 0x8000;
|
|
|
|
if (offset > fsize) {
|
|
fclose(sourceFile);
|
|
fclose(destinationFile);
|
|
return 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|