@@ -115,7 +115,7 @@ u64 getShortcut(char *filename)
115
115
if (sscanf (p1 , "%08x" , & lowpath ) != 1 ) return shortcut ;
116
116
117
117
shortcut = 0x0004001000000000 + lowpath ;
118
- DEBUG ("Shortcut %08llx found for %s\n" , shortcut , filename );
118
+ DEBUG ("Shortcut %16llx found for %s\n" , shortcut , filename );
119
119
return shortcut ;
120
120
}
121
121
@@ -480,12 +480,89 @@ Result extract_badges(void)
480
480
return res ;
481
481
}
482
482
483
+ Result backup_badges_fast (void )
484
+ {
485
+ char * badgeMng = NULL ;
486
+
487
+ DEBUG ("writing badge data: making files...\n" );
488
+ char mng_path [128 ] = "/3ds/" APP_TITLE "/BadgeMngFile.dat" ;
489
+ char data_path [128 ] = "/3ds/" APP_TITLE "/BadgeData.dat" ;
490
+ DEBUG ("mng_path: %s, data_path: %s\n" , mng_path , data_path );
491
+
492
+ Handle dataHandle = 0 ;
493
+ Handle sdHandle = 0 ;
494
+
495
+ DEBUG ("loading existing badge mng file...\n" );
496
+ u32 mngRead = file_to_buf (fsMakePath (PATH_ASCII , "/BadgeMngFile.dat" ), ArchiveBadgeExt , & badgeMng );
497
+ DEBUG ("loading existing badge data file\n" );
498
+ Result res = FSUSER_OpenFile (& dataHandle , ArchiveBadgeExt , fsMakePath (PATH_ASCII , "/BadgeData.dat" ), FS_OPEN_READ , 0 );
499
+ if (mngRead != BADGE_MNG_SIZE || R_FAILED (res ))
500
+ {
501
+ char err_string [128 ] = {0 };
502
+ sprintf (err_string , language .badges .extdata_locked , res );
503
+ throw_error (err_string , ERROR_LEVEL_WARNING );
504
+ if (badgeMng ) free (badgeMng );
505
+ if (dataHandle ) FSFILE_Close (dataHandle );
506
+ FSFILE_Close (sdHandle );
507
+ return -1 ;
508
+ }
509
+ remake_file (fsMakePath (PATH_ASCII , mng_path ), ArchiveSD , BADGE_MNG_SIZE );
510
+
511
+ FSUSER_CreateFile (ArchiveSD , fsMakePath (PATH_ASCII , data_path ), 0 , BADGE_DATA_SIZE );
512
+ FSUSER_OpenFile (& sdHandle , ArchiveSD , fsMakePath (PATH_ASCII , data_path ), FS_OPEN_WRITE , 0 );
513
+
514
+ DEBUG ("writing badge data: writing BadgeMngFile...\n" );
515
+ res = buf_to_file (mngRead , fsMakePath (PATH_ASCII , mng_path ), ArchiveSD , badgeMng );
516
+ if (R_FAILED (res ))
517
+ {
518
+ DEBUG ("Failed to write badgemngfile: 0x%08lx\n" , res );
519
+ free (badgeMng );
520
+ FSFILE_Close (dataHandle );
521
+ FSFILE_Close (sdHandle );
522
+ return -1 ;
523
+ }
524
+ DEBUG ("writing badge data: writing badgedata...\n" );
525
+ char * buf = malloc (0x10000 );
526
+ u64 size = BADGE_DATA_SIZE ;
527
+ u64 cur = 0 ;
528
+ while (size > 0 )
529
+ {
530
+ u32 read = 0 ;
531
+ res = FSFILE_Read (dataHandle , & read , cur , buf , min (0x10000 , size ));
532
+ res = FSFILE_Write (sdHandle , NULL , cur , buf , read , FS_WRITE_FLUSH );
533
+ size -= read ;
534
+ cur += read ;
535
+ }
536
+
537
+ free (badgeMng );
538
+ free (buf );
539
+ FSFILE_Close (dataHandle );
540
+ FSFILE_Close (sdHandle );
541
+ return 0 ;
542
+ }
543
+
483
544
Result install_badges (void )
484
545
{
485
546
Handle handle = 0 ;
486
547
Handle folder = 0 ;
487
548
Result res = 0 ;
488
549
draw_loading_bar (0 , 1 , INSTALL_BADGES );
550
+ {
551
+ char testpath [128 ] = "/3ds/" APP_TITLE "/BadgeData.dat" ;
552
+ if (R_FAILED (res = FSUSER_OpenFile (& handle , ArchiveSD , fsMakePath (PATH_ASCII , testpath ), FS_OPEN_READ , 0 )))
553
+ {
554
+ if (R_SUMMARY (res ) == RS_NOTFOUND )
555
+ {
556
+ res = backup_badges_fast ();
557
+ if (R_FAILED (res )) return res ;
558
+ } else
559
+ {
560
+ DEBUG ("????: 0x%08lx\n" , res );
561
+ }
562
+ }
563
+ }
564
+
565
+ if (handle ) FSFILE_Close (handle );
489
566
490
567
DEBUG ("Initializing ACT\n" );
491
568
res = actInit ();
0 commit comments