Skip to content

Commit

Permalink
fixed overwriting with smaller files, implemented sort by name
Browse files Browse the repository at this point in the history
  • Loading branch information
meladroit committed Sep 10, 2015
1 parent 4269b38 commit 8b4bb94
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 11 deletions.
58 changes: 52 additions & 6 deletions source/main.c
Expand Up @@ -19,6 +19,7 @@
#define HELD_THRESHOLD 10

int canHasConsole = 0;
int alphabetSort = 0;
lsTitle* firstTitle = NULL;

u8 mediatype = 2;
Expand All @@ -37,7 +38,8 @@ enum state
CONFIRM_OVERWRITE,
SVDT_IS_KILL,
SET_TARGET_TITLE,
CONFIRM_SAVE_ROOT
CONFIRM_SAVE_ROOT,
CONFIRM_SECURE_VALUE
};
enum state machine_state;
enum state previous_state;
Expand Down Expand Up @@ -105,6 +107,19 @@ void copyFile(lsDir* dir, char* path, u64 size, lsDir* destDir)
break;
}

char* deletePath = (char*)malloc(strlen(dir->thisDir)+strlen(path)+1);
strcpy(deletePath,dir->thisDir);
strcat(deletePath,path);
if(canHasConsole)
{
debugOut("about to overwrite file");
printf(" deletePath %s",deletePath);
}
if (curArchive==&sdmcArchive)
deleteFile(deletePath,&saveGameArchive,&saveGameFsHandle);
if (curArchive==&saveGameArchive)
deleteFile(deletePath,&sdmcArchive,&sdmcFsHandle);

char origpath[MAX_PATH_LENGTH] = {0};
char destpath[MAX_PATH_LENGTH] = {0};
strncpy(origpath,dir->thisDir,MAX_PATH_LENGTH);
Expand Down Expand Up @@ -533,6 +548,7 @@ int main()
break;
default:
debugOut("successful startup, I guess. Huh.");
canHasConsole = 1;
break;
}
if (mediatype!=2)
Expand All @@ -551,7 +567,7 @@ int main()

consoleSelect(&titleBar);
textcolour(SALMON);
printf("svdt 0.3, meladroit/willidleaway\n");
printf("svdt 0.3a, meladroit/willidleaway\n");
printf("a hacked-together save data explorer/manager\n");
gotoxy(CURSOR_WIDTH,2);
textcolour(GREY);
Expand Down Expand Up @@ -687,7 +703,11 @@ int main()
for(i=0;i<8;i++)
printf("%02x ",secureValue[i]);
putchar('\n');
wordwrap("Enable automatic secure value rewriting on restore? Press A to enable, B to disable.\n",BOTTOM_WIDTH);
previous_state = machine_state;
machine_state = CONFIRM_SECURE_VALUE;
}
continue;
}
if(hidKeysDown() & KEY_B)
{
Expand All @@ -705,6 +725,31 @@ int main()
gfxSwapBuffers();
continue;
}
if(machine_state == CONFIRM_SECURE_VALUE)
{
if(hidKeysDown() & KEY_A)
{
printInstructions();
printf("Target app:\n %s\n",titleTitle);
debugOut("Anti-anti savegame restore enabled.");
previous_state = machine_state;
machine_state = SELECT_SDMC;
}
if(hidKeysDown() & KEY_B)
{
whichSecureGame = SECURE_UNKNOWN;
printInstructions();
printf("Target app:\n %s\n",titleTitle);
debugOut("Anti-anti savegame restore disabled.");
previous_state = machine_state;
machine_state = SELECT_SDMC;
}
gspWaitForVBlank();
// Flush and swap framebuffers
gfxFlushBuffers();
gfxSwapBuffers();
continue;
}
if(machine_state == SVDT_IS_KILL)
{
if(previous_state != SVDT_IS_KILL)
Expand Down Expand Up @@ -733,6 +778,7 @@ int main()
{
previous_state = CONFIRM_SAVE_ROOT;
consoleSelect(&statusBar);
putchar('\n');
wordwrap("You are about to extract all target save data to the SD card. To extract into a folder in the current SD working directory, press Y. To extract into a folder in /svdt/, press A. Press B to cancel.\n",BOTTOM_WIDTH);
}
if(hidKeysDown() & KEY_B)
Expand Down Expand Up @@ -811,6 +857,10 @@ int main()
if(hidKeysDown() & KEY_SELECT)
{
printInstructions();
debugOut("changing sort order");
alphabetSort = !alphabetSort;
cwd_needs_update = 1;
notccwd_needs_update = 1;
}
if(hidKeysDown() & KEY_X)
{
Expand Down Expand Up @@ -872,10 +922,6 @@ int main()
{
machine_state = previous_state;
previous_state = CONFIRM_OVERWRITE;
if (curArchive==&sdmcArchive)
deleteFile(deletePath,&saveGameArchive,&saveGameFsHandle);
if (curArchive==&saveGameArchive)
deleteFile(deletePath,&sdmcArchive,&sdmcFsHandle);

copyFile(ccwd,overwritePath,overwriteSize,notccwd);
notccwd_needs_update = 1;
Expand Down
2 changes: 1 addition & 1 deletion source/secure_values.c
Expand Up @@ -298,9 +298,9 @@ Result getSecureValue2(const char* productCode)
while (ret!=EOF)
{
ret = fscanf(config,"%s %s %08x ",productCodeBuffer,filenameBuffer,&offset);
printf("%s %s %08x\n",productCodeBuffer,filenameBuffer,offset);
if (!strncmp(productCode,productCodeBuffer,9))
{
printf("%s %s %08x\n",productCodeBuffer,filenameBuffer,offset);
Result res = readBytesFromSaveFile(filenameBuffer,offset,secureValue,SECURE_VALUE_SIZE);
if(res) return res;
secureValueSet = 1;
Expand Down
40 changes: 36 additions & 4 deletions source/svdt.c
Expand Up @@ -62,6 +62,18 @@ char* lsDirBasename(lsDir* dir)
return ret;
}

int lsLine_cmp(lsLine* line1, lsLine* line2)
{
if (!line1)
return 1;
if (!line2)
return -1;
int isDir_cmp = (line2->isDirectory) - (line1->isDirectory);
if(isDir_cmp)
return isDir_cmp;
return strcmp(line1->thisLine,line2->thisLine);
}

void scanDir(lsDir* dir, FS_archive* archive, Handle* fsHandle)
{
if (!dir) return;
Expand Down Expand Up @@ -98,13 +110,33 @@ void scanDir(lsDir* dir, FS_archive* archive, Handle* fsHandle)
tempLine->isDirectory = entry.isDirectory;
tempLine->fileSize = entry.fileSize;
tempLine->nextLine = NULL;
if(dir->firstLine)
if (!alphabetSort)
{
lastLine->nextLine = tempLine;
if(dir->firstLine)
{
lastLine->nextLine = tempLine;
} else {
dir->firstLine = tempLine;
}
lastLine = tempLine;
} else {
dir->firstLine = tempLine;
if(dir->firstLine == NULL) {
dir->firstLine = tempLine;
} else {
lastLine = dir->firstLine;
if(lsLine_cmp(tempLine,lastLine)<0) {
tempLine->nextLine = lastLine;
dir->firstLine = tempLine;
} else {
while(lsLine_cmp(lastLine->nextLine,tempLine)<0)
{
lastLine = lastLine->nextLine;
}
tempLine->nextLine = lastLine->nextLine;
lastLine->nextLine = tempLine;
}
}
}
lastLine = tempLine;
dir->dirEntryCount++;
}
}while (entriesRead);
Expand Down
1 change: 1 addition & 0 deletions source/svdt.h
Expand Up @@ -23,6 +23,7 @@ typedef struct lsTitle {
} lsTitle;

extern int canHasConsole;
extern int alphabetSort;
extern lsTitle* firstTitle;

void freeDir(lsDir* dir);
Expand Down
Binary file modified svdt.3dsx
Binary file not shown.

0 comments on commit 8b4bb94

Please sign in to comment.