23
23
#include <stdio.h>
24
24
#include <stdlib.h>
25
25
#include <string.h>
26
+ #include <time.h>
26
27
#include <gccore.h>
27
28
#include <errno.h>
28
29
#include <math.h>
29
30
#include <unistd.h>
30
31
#include <malloc.h>
31
32
#include <stdarg.h>
33
+ #include <sys/stat.h>
34
+ #include <sys/types.h>
32
35
#include <ogc/lwp_watchdog.h>
33
36
#include <ogc/machine/processor.h>
34
37
#include "FrameBufferMagic.h"
@@ -70,6 +73,7 @@ static int dumpCounter = 0;
70
73
static char gameName [32 ];
71
74
static char internalName [512 ];
72
75
static char mountPath [512 ];
76
+ static char currentGameDirName [520 ];
73
77
static char wpadNeedScan = 0 ;
74
78
static char padNeedScan = 0 ;
75
79
int print_usb = 0 ;
@@ -707,6 +711,34 @@ int filesystem_type() {
707
711
return type ;
708
712
}
709
713
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
+
710
742
char * getShrinkOption () {
711
743
int opt = options_map [NGC_SHRINK_ISO ];
712
744
if (opt == SHRINK_ALL )
@@ -927,8 +959,10 @@ void prompt_new_file(FILE **fp, int chunk, int type, int fs, int silent) {
927
959
} while (ret != 1 );
928
960
}
929
961
962
+ create_folder_structure (0 );
963
+
930
964
* 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 );
932
966
remove (& txtbuffer [0 ]);
933
967
* fp = fopen (& txtbuffer [0 ], "wb" );
934
968
if (* fp == NULL ) {
@@ -947,7 +981,7 @@ void prompt_new_file(FILE **fp, int chunk, int type, int fs, int silent) {
947
981
}
948
982
949
983
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 ]);
951
985
remove (& txtbuffer [0 ]);
952
986
FILE * fp = fopen (txtbuffer , "wb" );
953
987
if (fp ) {
@@ -976,7 +1010,7 @@ void dump_info(char *md5, char *sha1, u32 crc32, int verified, u32 seconds) {
976
1010
"Version: 1.0%i\r\nChecksum calculations disabled\r\nDuration: %u min. %u sec.\r\n" ,
977
1011
V_MAJOR ,V_MID ,V_MINOR ,& gameName [0 ],& internalName [0 ], * (u8 * )0x80000007 , seconds /60 , seconds %60 );
978
1012
}
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 ]);
980
1014
remove (& txtbuffer [0 ]);
981
1015
FILE * fp = fopen (txtbuffer , "wb" );
982
1016
if (fp ) {
@@ -1058,9 +1092,9 @@ int dump_game(int disc_type, int type, int fs) {
1058
1092
1059
1093
// There will be chunks, name accordingly
1060
1094
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 ]);
1062
1096
} 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 ]);
1064
1098
}
1065
1099
remove (& txtbuffer [0 ]);
1066
1100
FILE * fp = fopen (& txtbuffer [0 ], "wb" );
@@ -1245,7 +1279,9 @@ int dump_game(int disc_type, int type, int fs) {
1245
1279
dump_info (NULL , NULL , 0 , 0 , diff_sec (startTime , gettime ()));
1246
1280
}
1247
1281
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 );
1249
1285
}
1250
1286
WriteCentre (315 ,"Press A to continue B to Exit" );
1251
1287
dvd_motor_off ();
@@ -1278,6 +1314,8 @@ int main(int argc, char **argv) {
1278
1314
// Ask the user if they want checksum calculations enabled this time?
1279
1315
calcChecksums = DrawYesNoDialog ("Enable checksum calculations?" ,
1280
1316
"(Enabling will add about 3 minutes)" );
1317
+ // Intialize RNG
1318
+ srand (time (NULL ));
1281
1319
1282
1320
int reuseSettings = NOT_ASKED ;
1283
1321
while (1 ) {
@@ -1343,6 +1381,8 @@ int main(int argc, char **argv) {
1343
1381
}
1344
1382
}
1345
1383
}
1384
+
1385
+ create_folder_structure (1 );
1346
1386
1347
1387
if (reuseSettings == NOT_ASKED ) {
1348
1388
if (DrawYesNoDialog ("Remember settings?" ,
0 commit comments