Skip to content

Commit 11e1df7

Browse files
committed
create new folder per dump
use tabs for indent. use better(?) folder naming and fix directory creation after inserting a new storage device. also check if game dump directory has been previously created, in case the user reuses a storage device when dumping in smaller chunks.
1 parent 332e043 commit 11e1df7

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

source/datel.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ void datel_addSkip(uint64_t start, u32 length) {
274274
}
275275
}
276276

277-
void dump_skips(char *mountPath, u32 crc100000) {
278-
sprintf(txtbuffer, "%s%s.skp", mountPath, get_game_name());
277+
void dump_skips(char *pathToCurrentGameDir, u32 crc100000) {
278+
sprintf(txtbuffer, "%s%s.skp", pathToCurrentGameDir, get_game_name());
279279
FILE *fp = fopen(txtbuffer, "wb");
280280
if (fp) {
281281
int sk=0;

source/main.c

+46-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
#include <stdio.h>
2424
#include <stdlib.h>
2525
#include <string.h>
26+
#include <time.h>
2627
#include <gccore.h>
2728
#include <errno.h>
2829
#include <math.h>
2930
#include <unistd.h>
3031
#include <malloc.h>
3132
#include <stdarg.h>
33+
#include <sys/stat.h>
34+
#include <sys/types.h>
3235
#include <ogc/lwp_watchdog.h>
3336
#include <ogc/machine/processor.h>
3437
#include "FrameBufferMagic.h"
@@ -70,6 +73,7 @@ static int dumpCounter = 0;
7073
static char gameName[32];
7174
static char internalName[512];
7275
static char mountPath[512];
76+
static char currentGameDirName[520];
7377
static char wpadNeedScan = 0;
7478
static char padNeedScan = 0;
7579
int print_usb = 0;
@@ -707,6 +711,34 @@ int filesystem_type() {
707711
return type;
708712
}
709713

714+
/* create folder structure on the mounted device "/cleanrip-dumps/gamename" */
715+
int create_folder_structure(int generateGameDirName) {
716+
char folderPath[1050];
717+
struct stat st = {0};
718+
// when we dump a new game we want to generate a new name for the folder
719+
if (generateGameDirName) {
720+
int rnd = rand()%1000;
721+
sprintf(currentGameDirName, "%s-%d", &internalName[0], rnd);
722+
}
723+
724+
sprintf(folderPath, "%scleanrip-dumps", &mountPath[0]);
725+
strcat(folderPath, "/");
726+
strcat(folderPath, currentGameDirName);
727+
if (stat(folderPath, &st) == -1) {
728+
if (mkdir(folderPath, 0755) != 0) {
729+
DrawFrameStart();
730+
DrawEmptyBox(30, 180, vmode->fbWidth - 38, 350, COLOR_BLACK);
731+
WriteCentre(230, "Failed to create folder:");
732+
WriteCentre(255, folderPath);
733+
WriteCentre(315, "Exiting in 5 seconds");
734+
DrawFrameFinish();
735+
sleep(5);
736+
exit(0);
737+
}
738+
}
739+
return 0;
740+
}
741+
710742
char *getShrinkOption() {
711743
int opt = options_map[NGC_SHRINK_ISO];
712744
if (opt == SHRINK_ALL)
@@ -927,8 +959,10 @@ void prompt_new_file(FILE **fp, int chunk, int type, int fs, int silent) {
927959
} while (ret != 1);
928960
}
929961

962+
create_folder_structure(0);
963+
930964
*fp = NULL;
931-
sprintf(txtbuffer, "%s%s.part%i.iso", &mountPath[0], &gameName[0], chunk);
965+
sprintf(txtbuffer, "%scleanrip-dumps/%s/%s.part%i.iso", &mountPath[0], &currentGameDirName[0], &gameName[0], chunk);
932966
remove(&txtbuffer[0]);
933967
*fp = fopen(&txtbuffer[0], "wb");
934968
if (*fp == NULL) {
@@ -947,7 +981,7 @@ void prompt_new_file(FILE **fp, int chunk, int type, int fs, int silent) {
947981
}
948982

949983
void dump_bca() {
950-
sprintf(txtbuffer, "%s%s.bca", &mountPath[0], &gameName[0]);
984+
sprintf(txtbuffer, "%scleanrip-dumps/%s/%s.bca", &mountPath[0], &currentGameDirName[0], &gameName[0]);
951985
remove(&txtbuffer[0]);
952986
FILE *fp = fopen(txtbuffer, "wb");
953987
if (fp) {
@@ -976,7 +1010,7 @@ void dump_info(char *md5, char *sha1, u32 crc32, int verified, u32 seconds) {
9761010
"Version: 1.0%i\r\nChecksum calculations disabled\r\nDuration: %u min. %u sec.\r\n",
9771011
V_MAJOR,V_MID,V_MINOR,&gameName[0],&internalName[0], *(u8*)0x80000007, seconds/60, seconds%60);
9781012
}
979-
sprintf(txtbuffer, "%s%s-dumpinfo.txt", &mountPath[0], &gameName[0]);
1013+
sprintf(txtbuffer, "%scleanrip-dumps/%s/%s-dumpinfo.txt", &mountPath[0], &currentGameDirName[0], &gameName[0]);
9801014
remove(&txtbuffer[0]);
9811015
FILE *fp = fopen(txtbuffer, "wb");
9821016
if (fp) {
@@ -1058,9 +1092,9 @@ int dump_game(int disc_type, int type, int fs) {
10581092

10591093
// There will be chunks, name accordingly
10601094
if (opt_chunk_size < endLBA) {
1061-
sprintf(txtbuffer, "%s%s.part0.iso", &mountPath[0], &gameName[0]);
1095+
sprintf(txtbuffer, "%scleanrip-dumps/%s/%s.part0.iso", &mountPath[0], &currentGameDirName[0], &gameName[0]);
10621096
} else {
1063-
sprintf(txtbuffer, "%s%s.iso", &mountPath[0], &gameName[0]);
1097+
sprintf(txtbuffer, "%scleanrip-dumps/%s/%s.iso", &mountPath[0], &currentGameDirName[0], &gameName[0]);
10641098
}
10651099
remove(&txtbuffer[0]);
10661100
FILE *fp = fopen(&txtbuffer[0], "wb");
@@ -1245,7 +1279,9 @@ int dump_game(int disc_type, int type, int fs) {
12451279
dump_info(NULL, NULL, 0, 0, diff_sec(startTime, gettime()));
12461280
}
12471281
if((disc_type == IS_DATEL_DISC)) {
1248-
dump_skips(&mountPath[0], crc100000);
1282+
char pathToGameDir[1050];
1283+
sprintf(pathToGameDir, "%scleanrip-dumps/%s/", &mountPath[0], &currentGameDirName[0]);
1284+
dump_skips(&pathToGameDir[0], crc100000);
12491285
}
12501286
WriteCentre(315,"Press A to continue B to Exit");
12511287
dvd_motor_off();
@@ -1278,6 +1314,8 @@ int main(int argc, char **argv) {
12781314
// Ask the user if they want checksum calculations enabled this time?
12791315
calcChecksums = DrawYesNoDialog("Enable checksum calculations?",
12801316
"(Enabling will add about 3 minutes)");
1317+
// Intialize RNG
1318+
srand(time(NULL));
12811319

12821320
int reuseSettings = NOT_ASKED;
12831321
while (1) {
@@ -1343,6 +1381,8 @@ int main(int argc, char **argv) {
13431381
}
13441382
}
13451383
}
1384+
1385+
create_folder_structure(1);
13461386

13471387
if(reuseSettings == NOT_ASKED) {
13481388
if(DrawYesNoDialog("Remember settings?",

0 commit comments

Comments
 (0)