Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SD Card Directory Listing Demo
- // Updated 12/19/2008 by PunMaster
- #include <gccore.h>
- #include <wiiuse/wpad.h>
- #include <sdcard/wiisd_io.h>
- #include <fat.h>
- #include <ogc/usbstorage.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <dirent.h>
- static void *xfb = NULL;
- static GXRModeObj *rmode = NULL;
- char * device;
- char * selected = "SD Card";
- void InitSD(){
- fatUnmount("sd:/");
- __io_wiisd.shutdown();
- fatMountSimple("sd", &__io_wiisd);
- }
- void InitUSB(){
- fatUnmount("usb:/");
- fatMountSimple("usb", &__io_usbstorage);
- }
- void dirlist(char* path)
- {
- DIR* pdir = opendir(path);
- if (pdir != NULL)
- {
- while(true)
- {
- struct dirent* pent = readdir(pdir);
- if(pent == NULL) break;
- if(strcmp(".", pent->d_name) != 0 && strcmp("..", pent->d_name) != 0)
- {
- char dnbuf[260];
- sprintf(dnbuf, "%s/%s", path, pent->d_name);
- struct stat statbuf;
- stat(dnbuf, &statbuf);
- if(S_ISDIR(statbuf.st_mode))
- {
- printf("%s <DIR>\n", dnbuf);
- dirlist(dnbuf);
- }
- else
- {
- printf("%s (%d)\n", dnbuf, (int)statbuf.st_size);
- }
- }
- }
- closedir(pdir);
- }
- else
- {
- printf("opendir() failure.\n");
- }
- }
- void main_menu(void) {
- printf("\x1b[7;7H[++] Source selector:");
- printf("\x1b[9;9H[>] Press [A] to browse SD CARD");
- printf("\x1b[10;9H[>] Press [B] to browse USB DRIVE");
- printf("\x1b[7;7H[>] Press [B] to exit.");
- while(1) {
- printf("\x1b[7;7H[>] Browsing device: <%s>", selected);
- WPAD_ScanPads();
- u32 pressed = WPAD_ButtonsDown(0);
- if (pressed & WPAD_BUTTON_HOME)exit(0);
- if (((pressed & WPAD_BUTTON_RIGHT) || (pressed & WPAD_BUTTON_RIGHT))) {
- if (selected = ("SD Card")){
- selected = ((char *)"USB Drive");
- }else{
- selected = ((char *)"SD Card");
- }
- }
- }
- }
- int main(int argc, char **argv)
- {
- VIDEO_Init();
- WPAD_Init();
- rmode = VIDEO_GetPreferredMode(NULL);
- xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
- console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
- VIDEO_Configure(rmode);
- VIDEO_SetNextFramebuffer(xfb);
- VIDEO_SetBlack(FALSE);
- VIDEO_Flush();
- VIDEO_WaitVSync();
- if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
- printf("\x1b[2;0H");
- main_menu();
- while(1)
- {
- WPAD_ScanPads();
- u32 pressed = WPAD_ButtonsDown(0);
- if ( pressed & WPAD_BUTTON_HOME ) exit(0);
- VIDEO_WaitVSync();
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment