Guest User

Untitled

a guest
May 24th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.54 KB | None | 0 0
  1. // SD Card Directory Listing Demo
  2. // Updated 12/19/2008 by PunMaster
  3.  
  4. #include <gccore.h>
  5. #include <wiiuse/wpad.h>
  6. #include <sdcard/wiisd_io.h>
  7.  
  8. #include <fat.h>
  9. #include <ogc/usbstorage.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <dirent.h>
  14.  
  15.  
  16. static void *xfb = NULL;
  17. static GXRModeObj *rmode = NULL;
  18.  
  19. char * device;
  20. char * selected = "SD Card";
  21.  
  22. void InitSD(){
  23.  
  24. fatUnmount("sd:/");
  25. __io_wiisd.shutdown();
  26. fatMountSimple("sd", &__io_wiisd);
  27. }
  28.  
  29. void InitUSB(){
  30. fatUnmount("usb:/");  
  31. fatMountSimple("usb", &__io_usbstorage);
  32. }
  33.  
  34. void dirlist(char* path)
  35. {
  36.     DIR* pdir = opendir(path);
  37.  
  38.     if (pdir != NULL)
  39.     {
  40.         while(true)
  41.         {
  42.             struct dirent* pent = readdir(pdir);
  43.             if(pent == NULL) break;
  44.            
  45.             if(strcmp(".", pent->d_name) != 0 && strcmp("..", pent->d_name) != 0)
  46.             {
  47.                 char dnbuf[260];
  48.                 sprintf(dnbuf, "%s/%s", path, pent->d_name);
  49.                
  50.                 struct stat statbuf;
  51.                 stat(dnbuf, &statbuf);
  52.                
  53.                 if(S_ISDIR(statbuf.st_mode))
  54.                 {
  55.                     printf("%s <DIR>\n", dnbuf);
  56.                     dirlist(dnbuf);
  57.                 }
  58.                 else
  59.                 {
  60.                     printf("%s (%d)\n", dnbuf, (int)statbuf.st_size);
  61.                 }
  62.                
  63.             }
  64.         }
  65.        
  66.         closedir(pdir);
  67.     }
  68.     else
  69.     {
  70.         printf("opendir() failure.\n");
  71.     }
  72. }
  73.  
  74. void main_menu(void) {
  75.  
  76.     printf("\x1b[7;7H[++] Source selector:");
  77.     printf("\x1b[9;9H[>] Press [A] to browse SD CARD");
  78.     printf("\x1b[10;9H[>] Press [B] to browse USB DRIVE");
  79.     printf("\x1b[7;7H[>] Press [B] to exit.");
  80.  
  81.  
  82.  
  83.     while(1) {
  84.  
  85.     printf("\x1b[7;7H[>] Browsing device: <%s>", selected);
  86.  
  87.         WPAD_ScanPads();
  88.         u32 pressed = WPAD_ButtonsDown(0);
  89.  
  90.     if (pressed & WPAD_BUTTON_HOME)exit(0);
  91.  
  92.     if (((pressed & WPAD_BUTTON_RIGHT) || (pressed & WPAD_BUTTON_RIGHT))) {
  93.  
  94.     if (selected = ("SD Card")){
  95.  
  96.     selected = ((char *)"USB Drive");
  97.  
  98.         }else{
  99.    
  100.     selected = ((char *)"SD Card");
  101.     }
  102.     }
  103.  
  104.     }
  105. }
  106.  
  107. int main(int argc, char **argv)
  108. {
  109.     VIDEO_Init();
  110.    
  111.     WPAD_Init();
  112.  
  113.     rmode = VIDEO_GetPreferredMode(NULL);
  114.  
  115.     xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  116.    
  117.     console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
  118.    
  119.     VIDEO_Configure(rmode);
  120.    
  121.     VIDEO_SetNextFramebuffer(xfb);
  122.    
  123.     VIDEO_SetBlack(FALSE);
  124.  
  125.     VIDEO_Flush();
  126.  
  127.     VIDEO_WaitVSync();
  128.     if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
  129.  
  130.     printf("\x1b[2;0H");
  131.  
  132. main_menu();
  133.  
  134.     while(1)
  135.     {
  136.         WPAD_ScanPads();
  137.  
  138.         u32 pressed = WPAD_ButtonsDown(0);
  139.  
  140.         if ( pressed & WPAD_BUTTON_HOME ) exit(0);
  141.  
  142.         VIDEO_WaitVSync();
  143.     }
  144.  
  145.     return 0;
  146. }
Add Comment
Please, Sign In to add comment