s32 WBFS_OpenPart(u32 part_fs, u32 part_idx, u32 part_lba, u32 part_size, char *partition) { // close WBFS_Close(); dbg_printf("openpart(%d %d %d %d)\n", part_fs, part_idx, part_lba, part_size); if (part_fs == PART_FS_UNK) return -1; if (part_fs == PART_FS_WBFS) { if (WBFS_OpenLBA(part_lba, part_size)) return -1; } else { MountPoint *mp = mount_find_part(wbfsDev, part_lba); if (mp) { mount_name2drive(mp->name, wbfs_fs_drive); } else { if (MountFS(GAME_MOUNT, wbfsDev, part_lba, part_fs, 1)) return -1; mount_name2drive(GAME_MOUNT, wbfs_fs_drive); } } // success wbfs_part_fs = part_fs; wbfs_part_idx = part_idx; wbfs_part_lba = part_lba; sprintf(partition, "%s%d", get_fs_name(part_fs), wbfs_part_idx); dbg_printf("game part=%s\n", partition); return 0; }
s32 WBFS_Open(void) { WBFS_Close(); current = new Wbfs_Wbfs(WBFS_DEVICE_USB, 0, 0); // Fix me! wbfs_part_fs = wbfs_part_idx = wbfs_part_lba = 0; wbfs_part_idx = 1; return current->Open(); }
s32 WBFS_OpenLBA(u32 lba, u32 size) { Wbfs *part = new Wbfs_Wbfs(wbfsDev, lba, size); if (part->Open() != 0) { delete part; return -1; } WBFS_Close(); current = part; return 0; }
s32 WBFS_OpenPart(u32 part_fs, u32 part_idx, u32 part_lba, u32 part_size, char *partition) { // close WBFS_Close(); if (part_fs == PART_FS_FAT) { current = new Wbfs_Fat(wbfsDev, part_lba, part_size); strcpy(wbfs_fs_drive, "USB:"); #ifdef DEBUG_WBFS gprintf("\n\tCreated WBFS_Fat instance at lba: %d of size %d", part_lba, part_size); #endif } else if (part_fs == PART_FS_NTFS) { current = new Wbfs_Ntfs(wbfsDev, part_lba, part_size); strcpy(wbfs_fs_drive, "NTFS:"); #ifdef DEBUG_WBFS gprintf("\n\tCreated WBFS_Ntfs instance at lba: %d of size %d", part_lba, part_size); #endif } else { current = new Wbfs_Wbfs(wbfsDev, part_lba, part_size); #ifdef DEBUG_WBFS gprintf("\n\tCreated WBFS_Wbfs instance at lba: %d of size %d", part_lba, part_size); #endif } if (current->Open()) { delete current; current = NULL; return -1; } // success wbfs_part_fs = part_fs; wbfs_part_idx = part_idx; wbfs_part_lba = part_lba; const char *fs = "WBFS"; if (wbfs_part_fs == PART_FS_FAT) fs = "FAT"; if (wbfs_part_fs == PART_FS_NTFS) fs = "NTFS"; sprintf(partition, "%s%d", fs, wbfs_part_idx); return 0; }
void PartitionHandle::UnMount(int pos) { if(!interface || (pos >= (int)MountNameList.size()) || (MountNameList[pos].size() == 0)) return; WBFS_Close(); char DeviceSyn[10]; memcpy(DeviceSyn, MountName(pos), 8); strcat(DeviceSyn, ":"); DeviceSyn[9] = '\0'; if(strncmp(GetFSName(pos), "WBFS", 4) == 0) { wbfs_t *wbfshandle = GetWbfsHandle(pos); if(wbfshandle) wbfs_close(wbfshandle); gprintf("WBFS Partition at %s unmounted.\n", DeviceSyn); } else if(strncmp(GetFSName(pos), "FAT", 3) == 0) { fatUnmount(DeviceSyn); gprintf("FAT Partition at %s unmounted.\n", DeviceSyn); } else if(strncmp(GetFSName(pos), "NTFS", 4) == 0) { ntfsUnmount(DeviceSyn, true); gprintf("NTFS Partition at %s unmounted.\n", DeviceSyn); } else if(strncmp(GetFSName(pos), "LINUX", 5) == 0) { ext2Unmount(DeviceSyn); gprintf("EXT Partition at %s unmounted.\n", DeviceSyn); } /* Remove name from list */ MountNameList[pos].clear(); SetWbfsHandle(pos, NULL); }
s32 WBFS_OpenNamed(char *partition) { u32 i; u32 part_fs = PART_FS_WBFS; u32 part_idx = 0; u32 part_lba = 0; s32 ret = 0; PartList plist; // close WBFS_Close(); // parse partition option if (strncasecmp(partition, "WBFS", 4) == 0) { i = atoi(partition+4); if (i < 1 || i > 4) goto err; part_fs = PART_FS_WBFS; part_idx = i; } else if (strncasecmp(partition, "FAT", 3) == 0) { if (wbfsDev != WBFS_DEVICE_USB) goto err; i = atoi(partition+3); if (i < 1 || i > 9) goto err; part_fs = PART_FS_FAT; part_idx = i; } else if (strncasecmp(partition, "NTFS", 4) == 0) { i = atoi(partition+4); if (i < 1 || i > 9) goto err; part_fs = PART_FS_NTFS; part_idx = i; } else { goto err; } // Get partition entries ret = Partition_GetList(wbfsDev, &plist); if (ret || plist.num == 0) return -1; if (part_fs == PART_FS_WBFS) { if (part_idx > plist.wbfs_n) goto err; for (i=0; i<plist.num; i++) { if (plist.pinfo[i].wbfs_i == part_idx) break; } } else if (part_fs == PART_FS_FAT) { if (part_idx > plist.fat_n) goto err; for (i=0; i<plist.num; i++) { if (plist.pinfo[i].fat_i == part_idx) break; } } else if (part_fs == PART_FS_NTFS) { if (part_idx > plist.ntfs_n) goto err; for (i=0; i<plist.num; i++) { if (plist.pinfo[i].ntfs_i == part_idx) break; } } if (i >= plist.num) goto err; // set partition lba sector part_lba = plist.pentry[i].sector; if (WBFS_OpenPart(part_fs, part_idx, part_lba, plist.pentry[i].size, partition)) { goto err; } // success return 0; err: return -1; }
void Menu_Boot() { struct discHdr *header; bool gc = false; header = &gameList[gameSelected]; s32 ret; struct Game_CFG_2 *game_cfg = NULL; /* Clear console */ if (!CFG.direct_launch) { Con_Clear(); } FgColor(CFG.color_header); printf_x(gt("Start this game?")); printf("\n\n"); DefaultColor(); game_cfg = CFG_find_game(header->id); // Get game size gc = header->magic == GC_MAGIC; bool do_skip = !CFG.confirm_start; /* SoundInfo snd; u8 banner_title[84]; memset(banner_title, 0, 84); memset(&snd, 0, sizeof(snd)); WBFS_Banner(header->id, &snd, banner_title, !do_skip, CFG_read_active_game_setting(header->id).write_playlog); */ if (do_skip) { goto skip_confirm; } printf("\n"); /* Show game info */ printf_("%s\n", get_title(header)); printf_("(%.6s)\n\n", header->id); __Menu_ShowGameInfo(true, header->id); /* load game info from XML */ printf("\n"); //Does DL warning apply to launching discs too? Not sure printf_h(gt("Press %s button to continue."), (button_names[CFG.button_confirm.num])); printf("\n"); printf_h(gt("Press %s button to go back."), (button_names[CFG.button_cancel.num])); if (!gc) { printf("\n"); printf_h(gt("Press %s button for options."), (button_names[CFG.button_other.num])); } printf("\n\n"); __console_flush(0); // play banner sound /* if (snd.dsp_data) { SND_PauseVoice(0, 1); // pause mp3 int fmt = (snd.channels == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT; SND_SetVoice(1, fmt, snd.rate, 0, snd.dsp_data, snd.size, 255,255, //volume,volume, NULL); //DataTransferCallback } */ /* Wait for user answer */ u32 buttons; for (;;) { buttons = Wpad_WaitButtons(); if (buttons & CFG.button_confirm.mask) break; if (buttons & CFG.button_cancel.mask) break; if (!gc && (buttons & CFG.button_other.mask)) break; if (buttons & CFG.button_exit.mask) break; } /* // stop banner sound, resume mp3 if (snd.dsp_data) { SND_StopVoice(1); SAFE_FREE(snd.dsp_data); if (buttons & CFG.button_confirm.mask) { SND_ChangeVolumeVoice(0, 0, 0); } SND_PauseVoice(0, 0); } */ if (buttons & CFG.button_cancel.mask) goto close; if (buttons & CFG.button_exit.mask) { Handle_Home(0); return; } if (!gc && (buttons & CFG.button_other.mask)) { Menu_Boot_Options(header); return; } // A button: continue to boot skip_confirm: if (game_cfg) { CFG.game = game_cfg->curr; } if (CFG.game.write_playlog && set_playrec(header->id, (u8 *) header->title) < 0) { // banner_title) < 0) { printf_(gt("Error storing playlog file.\nStart from the Wii Menu to fix.")); printf("\n"); printf_h(gt("Press %s button to exit."), (button_names[CFG.button_exit.num])); printf("\n"); if (!Menu_Confirm(0)) return; } WBFS_OpenDisc(header->id, header->game_idx); printf("\n"); printf_x(gt("Booting Wii game, please wait...")); printf("\n\n"); // load stuff before ios reloads & services close ocarina_load_code(header->id); load_wip_patches(header->id); // Close the wode stuff WBFS_Close(); use_dvdx = 0; Disc_Init(); ret = Disc_Wait(); if (ret < 0) { printf("Cannot mount newly selected image: %d\n", ret); } Disc_Open(); // stop services (music, gui) Services_Close(); setPlayStat(header->id); //I'd rather do this after the check, but now you unmount fat before that ;) Fat_UnmountAll(); if (gc) { WII_Initialize(); ret = WII_LaunchTitle(0x0000000100000100ULL); } else { switch(CFG.game.language) { // 0 = CFG_LANG_CONSOLE case 0: configbytes[0] = 0xCD; break; case 1: configbytes[0] = 0x00; break; case 2: configbytes[0] = 0x01; break; case 3: configbytes[0] = 0x02; break; case 4: configbytes[0] = 0x03; break; case 5: configbytes[0] = 0x04; break; case 6: configbytes[0] = 0x05; break; case 7: configbytes[0] = 0x06; break; case 8: configbytes[0] = 0x07; break; case 9: configbytes[0] = 0x08; break; case 10: configbytes[0] = 0x09; break; } /* Boot Wii disc */ ret = Disc_WiiBoot(); } printf_(gt("Returned! (ret = %d)"), ret); printf("\n"); printf("\n"); printf_(gt("Press any button to exit...")); printf("\n"); /* Wait for button */ Wpad_WaitButtonsCommon(); exit(0); close: WDVD_StopMotor(); header = &gameList[gameSelected]; Gui_DrawCover(header->id); // Reopen the wode WBFS_Init(); return; }
s32 WBFS_OpenNamed(char *partition) { int i = 0; u32 part_fs = PART_FS_WBFS; u32 part_idx = 0; u32 part_lba = 0; s32 ret = 0; PartList plist; int x, fs; // close WBFS_Close(); dbg_printf("open_part(%s)\n", partition); // Get partition entries ret = Partition_GetList(wbfsDev, &plist); if (ret || plist.num == 0) return -1; // parse partition option if (strcasecmp(partition, "auto") == 0) { int fs_list[] = { PART_FS_WBFS, PART_FS_FAT, PART_FS_NTFS }; // PART_FS_EXT int n = sizeof(fs_list) / sizeof(int); for (x=0; x<n; x++) { fs = fs_list[x]; i = PartList_FindFS(&plist, fs, 1, NULL); if (i < 0) continue; if ((fs == PART_FS_WBFS) || is_game_fs(wbfsDev, plist.pentry[i].sector)) { part_fs = fs; part_idx = 1; goto found; } } } else { for (x=0; x<PART_FS_NUM; x++) { fs = PART_FS_FIRST + x; char *fsname = get_fs_name(fs); int len = strlen(fsname); if (strncasecmp(partition, fsname, len) == 0) { int idx = atoi(partition + len); if (idx < 1 || idx > 9) goto err; i = PartList_FindFS(&plist, fs, idx, NULL); if (i >= 0) { part_fs = fs; part_idx = idx; goto found; } } } } // nothing found goto err; found: if (i >= plist.num) goto err; // set partition lba sector part_lba = plist.pentry[i].sector; if (WBFS_OpenPart(part_fs, part_idx, part_lba, plist.pentry[i].size, partition)) { goto err; } // success dbg_printf("OK! partition=%s\n", partition); return 0; err: Gui_Console_Enable(); printf(gt("Invalid partition: '%s'"), partition); printf("\n"); __console_flush(0); sleep(2); return -1; }