Skip to content

Commit

Permalink
Improve backup speeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpl0itU committed Mar 9, 2022
1 parent a2a1f61 commit d238d24
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 69 deletions.
4 changes: 2 additions & 2 deletions meta/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<app version="1">
<name>SaveMii Mod</name>
<coder>Ryuzaki_MrL original (GabyPCgeeK mod)</coder>
<version>1.2.0.mod4</version>
<release_date>20170716000000</release_date>
<version>1.3.1</version>
<release_date>20220306000000</release_date>
<short_description>WiiU/vWii Save Manager</short_description>
<long_description>WiiU/vWii Save Manager

Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define VERSION_MAJOR 1
#define VERSION_MINOR 3
#define VERSION_MICRO 0
#define VERSION_MICRO 1
#define M_OFF 1

u8 slot = 0;
Expand Down
101 changes: 35 additions & 66 deletions src/savemng.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <nn/act/client_cpp.h>
#include <sys/stat.h>
extern "C" {
#include "common/fs_defs.h"
#include "savemng.h"
}
using namespace std;

#define BUFFER_SIZE 0x8020
#define BUFFER_SIZE_STEPS 0x20
Expand All @@ -19,23 +21,6 @@ void setFSAFD(int fd) {
fsaFd = fd;
}

void replace_str(char *str, char *orig, char *rep, int start, char *out) {
static char temp[PATH_SIZE];
static char buffer[PATH_SIZE];
char *p;

strcpy(temp, str + start);

if (!(p = strstr(temp, orig))) // Is 'orig' even in 'temp'?
return;

strncpy(buffer, temp, p-temp); // Copy characters from 'temp' start to 'orig' str
buffer[p-temp] = '\0';

sprintf(buffer + (p - temp), "%s%s", rep, p + strlen(orig));
sprintf(out, "%s", buffer);
}

void show_file_operation(const char* file_name, const char* file_src, const char* file_dest) {
char dev_s[100], dev_d[100];

Expand Down Expand Up @@ -398,67 +383,51 @@ void getAccountsSD(Title* title, u8 slot) {
}
}

int DumpFile(char* pPath, const char* oPath) {
int srcFd = -1, destFd = -1;
int ret = 0;
int DumpFile(char *pPath, const char * oPath)
{
int buf_size = BUFFER_SIZE;
uint8_t * pBuffer;
uint8_t * pBuffer;

do{
buf_size -= BUFFER_SIZE_STEPS;
if (buf_size < 0) {
promptError("Error allocating Buffer.");
return -1;
return;
}
pBuffer = (uint8_t *)memalign(0x40, buf_size);
if (pBuffer) memset(pBuffer, 0x00, buf_size);
}while(!pBuffer);

ret = IOSUHAX_FSA_OpenFile(fsaFd, pPath, "rb", &srcFd);
if (ret >= 0) {
fileStat_s fStat;
IOSUHAX_FSA_StatFile(fsaFd, srcFd, &fStat);
if ((ret = IOSUHAX_FSA_OpenFile(fsaFd, oPath, "wb", &destFd)) >= 0) {
int result, sizew = 0, sizef = fStat.size;
int fwrite = 0;
u32 passedMs = 1;
u64 startTime = OSGetTime();

while ((result = IOSUHAX_FSA_ReadFile(fsaFd, pBuffer, 0x01, buf_size, srcFd, 0)) > 0) {
if ((fwrite = IOSUHAX_FSA_WriteFile(fsaFd, pBuffer, 0x01, result, destFd, 0)) < 0) {
promptError("Write %d,%s", fwrite, oPath);
IOSUHAX_FSA_CloseFile(fsaFd, destFd);
IOSUHAX_FSA_CloseFile(fsaFd, srcFd);
free(pBuffer);
return -1;
}
sizew += fwrite;
passedMs = (OSGetTime() - startTime) * 4000ULL / BUS_SPEED;
if(passedMs == 0)
passedMs = 1;

OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);
show_file_operation(p1, pPath, oPath);
console_print_pos(-2, 15, "Bytes Copied: %d of %d (%i kB/s)", sizew, sizef, (u32)(((u64)sizew * 1000) / ((u64)1024 * passedMs)));
flipBuffers();
}
} else {
promptError("Open File W %d,%s", ret, oPath);
IOSUHAX_FSA_CloseFile(fsaFd, srcFd);
free(pBuffer);
return -1;
}
IOSUHAX_FSA_CloseFile(fsaFd, destFd);
IOSUHAX_FSA_CloseFile(fsaFd, srcFd);
IOSUHAX_FSA_ChangeMode(fsaFd, oPath, 0x666);
free(pBuffer);
} else {
promptError("Open File R %d,%s", ret, pPath);
free(pBuffer);
return -1;
FILE* source = fopen(pPath, "rb");
FILE* dest = fopen(oPath, "wb");
if ((dest && source) == NULL) {
return -1;
}
struct stat st;
stat(pPath, &st);
int sizef = st.st_size;
int sizew = 0, size;
u32 passedMs = 1;
u64 startTime = OSGetTime();

while ((size = fread(pBuffer, 1, buf_size, source)) > 0) {
fwrite(pBuffer, 1, size, dest);
passedMs = (uint32_t)OSTicksToMilliseconds(OSGetTime() - startTime);
if(passedMs == 0)
passedMs = 1; // avoid 0 div
OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);
sizew += size;
show_file_operation("file", pPath, oPath);
console_print_pos(-2, 15, "Bytes Copied: %d of %d (%i kB/s)", sizew, sizef, (u32)(((u64)sizew * 1000) / ((u64)1024 * passedMs)));
flipBuffers();
}
return 0;

fclose(source);
fclose(dest);
free(pBuffer);

return 0;
}

int DumpDir(char* pPath, const char* tPath) { // Source: ft2sd
Expand Down

0 comments on commit d238d24

Please sign in to comment.