From 3420882624ad52a4a9a18e970a99500009f00fb4 Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Sat, 22 Sep 2012 13:47:52 +0000 Subject: [PATCH] -general code cleanup --- source/devicemounter/DeviceHandler.cpp | 144 ++++++------------ source/devicemounter/DeviceHandler.hpp | 52 +++---- source/devicemounter/PartitionHandle.cpp | 12 +- source/devicemounter/PartitionHandle.h | 88 ++++++----- source/gc/gc.cpp | 4 +- source/list/cachedlist.cpp | 4 +- source/list/list.cpp | 12 +- source/loader/alt_ios.cpp | 6 +- source/loader/external_booter.cpp | 2 +- source/loader/wbfs.c | 2 +- source/main.cpp | 9 +- source/menu/menu.cpp | 92 ++++++------ source/menu/menu.hpp | 2 +- source/menu/menu_configsnd.cpp | 4 +- source/menu/menu_game.cpp | 33 +++-- source/menu/menu_main.cpp | 22 +-- source/menu/menu_nandemu.cpp | 22 +-- source/menu/menu_wbfs.cpp | 11 +- source/music/MusicPlayer.cpp | 171 ++++++++++++++++++++++ source/music/MusicPlayer.hpp | 68 +++++++++ source/music/gui_sound.cpp | 2 +- source/music/musicplayer.cpp | 179 ----------------------- source/music/musicplayer.h | 54 ------- source/plugin/plugin.cpp | 2 +- wiiflow.pnproj | 2 +- wiiflow.pnps | 2 +- 26 files changed, 470 insertions(+), 531 deletions(-) create mode 100644 source/music/MusicPlayer.cpp create mode 100644 source/music/MusicPlayer.hpp delete mode 100644 source/music/musicplayer.cpp delete mode 100644 source/music/musicplayer.h diff --git a/source/devicemounter/DeviceHandler.cpp b/source/devicemounter/DeviceHandler.cpp index 4d3b57c0..ab50cac6 100644 --- a/source/devicemounter/DeviceHandler.cpp +++ b/source/devicemounter/DeviceHandler.cpp @@ -1,6 +1,6 @@ /**************************************************************************** - * Copyright (C) 2010 - * by Dimok + * Copyright (C) 2010 by Dimok + * (C) 2012 by FIX94 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any @@ -20,8 +20,6 @@ * * 3. This notice may not be removed or altered from any source * distribution. - * - * for WiiXplorer 2010 ***************************************************************************/ #include #include @@ -40,25 +38,17 @@ #include "loader/sys.h" #include "loader/wbfs.h" -DeviceHandler * DeviceHandler::instance = NULL; +DeviceHandler DeviceHandle; -DeviceHandler::~DeviceHandler() +void DeviceHandler::Init() { - UnMountAll(); -} - -DeviceHandler * DeviceHandler::Instance() -{ - if(instance == NULL) - instance = new DeviceHandler(); - return instance; -} - -void DeviceHandler::DestroyInstance() -{ - if(instance) - delete instance; - instance = NULL; + sd = NULL; + gca = NULL; + gcb = NULL; + usb0 = NULL; + usb1 = NULL; + OGC_Device = NULL; + DolphinSD = false; } void DeviceHandler::MountAll() @@ -121,7 +111,7 @@ bool DeviceHandler::IsInserted(int dev) else if(dev >= USB1 && dev <= USB8) { int portPart = PartitionToPortPartition(dev-USB1); - PartitionHandle *usb = instance->GetUSBHandleFromPartition(dev-USB1); + PartitionHandle *usb = GetUSBHandleFromPartition(dev-USB1); if(usb) return usb->IsMounted(portPart); } @@ -211,35 +201,6 @@ bool DeviceHandler::MountAllUSB() return result; } -/* -bool DeviceHandler::MountUSBPort1() -{ - if(!usb1)// && (Settings.USBPort == 1 || Settings.USBPort == 2)) - usb1 = new PartitionHandle(GetUSB1Interface()); - - if(usb1 && usb1->GetPartitionCount() < 1) - { - delete usb1; - usb1 = NULL; - return false; - } - - bool result = false; - int partCount = GetUSBPartitionCount(); - int partCount0 = 0; - if(usb0) - partCount0 = usb0->GetPartitionCount(); - - for(int i = partCount0; i < partCount; i++) - { - if(MountUSB(i)) - result = true; - } - - return result; -} -*/ - void DeviceHandler::UnMountUSB(int pos) { if(pos >= GetUSBPartitionCount()) @@ -266,7 +227,7 @@ void DeviceHandler::UnMountAllUSB() usb1 = NULL; } -int DeviceHandler::PathToDriveType(const char * path) +int DeviceHandler::PathToDriveType(const char *path) { if(!path) return -1; @@ -280,25 +241,23 @@ int DeviceHandler::PathToDriveType(const char * path) return -1; } -const char * DeviceHandler::GetFSName(int dev) +const char *DeviceHandler::GetFSName(int dev) { - if(dev == SD && DeviceHandler::instance->sd) - { - return DeviceHandler::instance->sd->GetFSName(0); - } + if(dev == SD && sd) + return sd->GetFSName(0); else if(dev >= USB1 && dev <= USB8) { int partCount0 = 0; int partCount1 = 0; - if(DeviceHandler::instance->usb0) - partCount0 += DeviceHandler::instance->usb0->GetPartitionCount(); - if(DeviceHandler::instance->usb1) - partCount1 += DeviceHandler::instance->usb1->GetPartitionCount(); + if(usb0) + partCount0 += usb0->GetPartitionCount(); + if(usb1) + partCount1 += usb1->GetPartitionCount(); - if(dev-USB1 < partCount0 && DeviceHandler::instance->usb0) - return DeviceHandler::instance->usb0->GetFSName(dev-USB1); - else if(DeviceHandler::instance->usb1) - return DeviceHandler::instance->usb1->GetFSName(dev-USB1-partCount0); + if(dev-USB1 < partCount0 && usb0) + return usb0->GetFSName(dev-USB1); + else if(usb1) + return usb1->GetFSName(dev-USB1-partCount0); } return ""; @@ -306,9 +265,6 @@ const char * DeviceHandler::GetFSName(int dev) int DeviceHandler::GetFSType(int dev) { - if(!instance) - return -1; - const char *FSName = GetFSName(dev); if(!FSName) return -1; @@ -326,43 +282,39 @@ int DeviceHandler::GetFSType(int dev) u16 DeviceHandler::GetUSBPartitionCount() { - if(!instance) - return 0; - u16 partCount0 = 0; u16 partCount1 = 0; - if(instance->usb0) - partCount0 = instance->usb0->GetPartitionCount(); - if(instance->usb1) - partCount1 = instance->usb1->GetPartitionCount(); + if(usb0) + partCount0 = usb0->GetPartitionCount(); + if(usb1) + partCount1 = usb1->GetPartitionCount(); return partCount0+partCount1; } wbfs_t * DeviceHandler::GetWbfsHandle(int dev) { - if(dev == SD && DeviceHandler::instance->sd) - return DeviceHandler::instance->sd->GetWbfsHandle(0); - else if(dev >= USB1 && dev <= USB8 && DeviceHandler::instance->usb0) - return DeviceHandler::instance->usb0->GetWbfsHandle(dev-USB1); - else if(dev >= USB1 && dev <= USB8 && DeviceHandler::instance->usb1) - return DeviceHandler::instance->usb1->GetWbfsHandle(dev-USB1); - - return NULL; + if(dev == SD && sd) + return sd->GetWbfsHandle(0); + else if(dev >= USB1 && dev <= USB8 && usb0) + return usb0->GetWbfsHandle(dev-USB1); + else if(dev >= USB1 && dev <= USB8 && usb1) + return usb1->GetWbfsHandle(dev-USB1); + return NULL; } -s32 DeviceHandler::Open_WBFS(int dev) +s32 DeviceHandler::OpenWBFS(int dev) { u32 part_lba, part_idx = 1; u32 part_fs = GetFSType(dev); char *partition = (char *)DeviceName[dev]; if(dev == SD && IsInserted(dev)) - part_lba = Instance()->sd->GetLBAStart(dev); + part_lba = sd->GetLBAStart(dev); else if(dev >= USB1 && dev <= USB8 && IsInserted(dev)) { part_idx = dev; - part_lba = Instance()->usb0->GetLBAStart(dev - USB1); + part_lba = usb0->GetLBAStart(dev - USB1); } else return -1; @@ -372,14 +324,11 @@ s32 DeviceHandler::Open_WBFS(int dev) int DeviceHandler::PartitionToUSBPort(int part) { - if(!DeviceHandler::instance) - return 0; - u16 partCount0 = 0; - if(DeviceHandler::instance->usb0) - partCount0 = instance->usb0->GetPartitionCount(); + if(usb0) + partCount0 = usb0->GetPartitionCount(); - if(!instance->usb0 || part >= partCount0) + if(!usb0 || part >= partCount0) return 1; else return 0; @@ -387,20 +336,17 @@ int DeviceHandler::PartitionToUSBPort(int part) int DeviceHandler::PartitionToPortPartition(int part) { - if(!DeviceHandler::instance) - return 0; - u16 partCount0 = 0; - if(instance->usb0) - partCount0 = instance->usb0->GetPartitionCount(); + if(usb0) + partCount0 = usb0->GetPartitionCount(); - if(!instance->usb0 || part >= partCount0) + if(!usb0 || part >= partCount0) return part-partCount0; else return part; } -PartitionHandle *DeviceHandler::GetUSBHandleFromPartition(int part) const +PartitionHandle *DeviceHandler::GetUSBHandleFromPartition(int part) { if(PartitionToUSBPort(part) == 0) return usb0; diff --git a/source/devicemounter/DeviceHandler.hpp b/source/devicemounter/DeviceHandler.hpp index 37ecf859..a8c1a8fd 100644 --- a/source/devicemounter/DeviceHandler.hpp +++ b/source/devicemounter/DeviceHandler.hpp @@ -1,6 +1,6 @@ /**************************************************************************** - * Copyright (C) 2010 - * by Dimok + * Copyright (C) 2010 by Dimok + * (C) 2012 by FIX94 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any @@ -20,8 +20,6 @@ * * 3. This notice may not be removed or altered from any source * distribution. - * - * for WiiXplorer 2010 ***************************************************************************/ #ifndef DEVICE_HANDLER_HPP_ #define DEVICE_HANDLER_HPP_ @@ -66,11 +64,8 @@ const char DeviceName[MAXDEVICES][8] = class DeviceHandler { public: - static DeviceHandler * Instance(); - static void DestroyInstance(); - + void Init(); void SetModes(); - void MountAll(); void UnMountAll(); bool Mount(int dev); @@ -97,40 +92,37 @@ public: PartitionHandle * GetUSB0Handle() const { return usb0; } PartitionHandle * GetUSB1Handle() const { return usb1; } - PartitionHandle * GetUSBHandleFromPartition(int part) const; - static const DISC_INTERFACE *GetUSB0Interface() { return &__io_usbstorage2_port0; } - static const DISC_INTERFACE *GetUSB1Interface() { return &__io_usbstorage2_port1; } + PartitionHandle * GetUSBHandleFromPartition(int part); + const DISC_INTERFACE *GetUSB0Interface() { return &__io_usbstorage2_port0; } + const DISC_INTERFACE *GetUSB1Interface() { return &__io_usbstorage2_port1; } - static int PathToDriveType(const char * path); - static const char * GetFSName(int dev); - static int GetFSType(int dev); - static u16 GetUSBPartitionCount(); - static const char * PathToFSName(const char * path) { return GetFSName(PathToDriveType(path)); } - static wbfs_t *GetWbfsHandle(int dev); - s32 Open_WBFS(int dev); - static int PartitionToUSBPort(int part); - static int PartitionToPortPartition(int part); + int PathToDriveType(const char *path); + const char * GetFSName(int dev); + int GetFSType(int dev); + u16 GetUSBPartitionCount(); + const char *PathToFSName(const char *path) { return GetFSName(PathToDriveType(path)); } + wbfs_t *GetWbfsHandle(int dev); + s32 OpenWBFS(int dev); + int PartitionToUSBPort(int part); + int PartitionToPortPartition(int part); /* Special Devolution Stuff */ bool MountDevolution(int CurrentPartition); void UnMountDevolution(int CurrentPartition); private: - DeviceHandler() : sd(0), gca(0), gcb(0), usb0(0), usb1(0), OGC_Device(0), DolphinSD(false) { } - ~DeviceHandler(); bool MountUSB(int part); - static DeviceHandler *instance; - - PartitionHandle * sd; - PartitionHandle * gca; - PartitionHandle * gcb; - PartitionHandle * usb0; - PartitionHandle * usb1; - + PartitionHandle *sd; + PartitionHandle *gca; + PartitionHandle *gcb; + PartitionHandle *usb0; + PartitionHandle *usb1; /* Special Devolution Stuff */ PartitionHandle *OGC_Device; /* Dolphin Stuff */ bool DolphinSD; }; +extern DeviceHandler DeviceHandle; + #endif diff --git a/source/devicemounter/PartitionHandle.cpp b/source/devicemounter/PartitionHandle.cpp index 2e63893f..409695fb 100644 --- a/source/devicemounter/PartitionHandle.cpp +++ b/source/devicemounter/PartitionHandle.cpp @@ -1,6 +1,6 @@ /**************************************************************************** - * Copyright (C) 2010 - * by Dimok + * Copyright (C) 2010 by Dimok + * (C) 2012 by FIX94 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any @@ -20,8 +20,6 @@ * * 3. This notice may not be removed or altered from any source * distribution. - * - * for WiiXplorer 2010 ***************************************************************************/ #include #include @@ -265,8 +263,7 @@ int PartitionHandle::FindPartitions() if(le32(partition->block_count) > 0 && !IsExisting(le32(partition->lba_start))) { AddPartition(PartFromType(partition->type), le32(partition->lba_start), - le32(partition->block_count), (partition->status == PARTITION_BOOTABLE), - partition->type, i); + le32(partition->block_count), (partition->status == PARTITION_BOOTABLE), partition->type, i); } } @@ -299,8 +296,7 @@ void PartitionHandle::CheckEBR(u8 PartNum, sec_t ebr_lba) if(le32(ebr->partition.block_count) > 0 && !IsExisting(ebr_lba + next_erb_lba + le32(ebr->partition.lba_start))) { AddPartition(PartFromType(ebr->partition.type), ebr_lba + next_erb_lba + le32(ebr->partition.lba_start), - le32(ebr->partition.block_count), (ebr->partition.status == PARTITION_BOOTABLE), - ebr->partition.type, PartNum); + le32(ebr->partition.block_count), (ebr->partition.status == PARTITION_BOOTABLE), ebr->partition.type, PartNum); } // Get the start sector of the current partition // and the next extended boot record in the chain diff --git a/source/devicemounter/PartitionHandle.h b/source/devicemounter/PartitionHandle.h index d21fa9f0..f42da34c 100644 --- a/source/devicemounter/PartitionHandle.h +++ b/source/devicemounter/PartitionHandle.h @@ -1,6 +1,6 @@ /**************************************************************************** - * Copyright (C) 2010 - * by Dimok + * Copyright (C) 2010 by Dimok + * (C) 2012 by FIX94 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any @@ -20,8 +20,6 @@ * * 3. This notice may not be removed or altered from any source * distribution. - * - * for WiiXplorer 2010 ***************************************************************************/ #ifndef PARTITION_HANDLE_H #define PARTITION_HANDLE_H @@ -33,80 +31,80 @@ using namespace std; -#define MAX_PARTITIONS 32 /* Maximum number of partitions that can be found */ -#define MAX_MOUNTS 10 /* Maximum number of mounts available at one time */ -#define MAX_SYMLINK_DEPTH 10 /* Maximum search depth when resolving symbolic links */ +#define MAX_PARTITIONS 32 /* Maximum number of partitions that can be found */ +#define MAX_MOUNTS 10 /* Maximum number of mounts available at one time */ +#define MAX_SYMLINK_DEPTH 10 /* Maximum search depth when resolving symbolic links */ -#define MBR_SIGNATURE 0x55AA -#define EBR_SIGNATURE MBR_SIGNATURE +#define MBR_SIGNATURE 0x55AA +#define EBR_SIGNATURE MBR_SIGNATURE -#define PARTITION_BOOTABLE 0x80 /* Bootable (active) */ -#define PARTITION_NONBOOTABLE 0x00 /* Non-bootable */ -#define PARTITION_TYPE_GPT 0xEE /* Indicates that a GPT header is available */ +#define PARTITION_BOOTABLE 0x80 /* Bootable (active) */ +#define PARTITION_NONBOOTABLE 0x00 /* Non-bootable */ +#define PARTITION_TYPE_GPT 0xEE /* Indicates that a GPT header is available */ -#define GUID_SYSTEM_PARTITION 0x0000000000000001LL /* System partition (disk partitioning utilities must reserve the partition as is) */ +#define GUID_SYSTEM_PARTITION 0x0000000000000001LL /* System partition (disk partitioning utilities must reserve the partition as is) */ #define GUID_READ_ONLY_PARTITION 0x0800000000000000LL /* Read-only partition */ -#define GUID_HIDDEN_PARTITION 0x2000000000000000LL /* Hidden partition */ -#define GUID_NO_AUTOMOUNT_PARTITION 0x4000000000000000LL /* Do not automount (e.g., do not assign drive letter) */ +#define GUID_HIDDEN_PARTITION 0x2000000000000000LL /* Hidden partition */ +#define GUID_NO_AUTOMOUNT_PARTITION 0x4000000000000000LL /* Do not automount (e.g., do not assign drive letter) */ #define BYTES_PER_SECTOR 512 /* Default in libogc */ #define MAX_BYTES_PER_SECTOR 4096 /* Max bytes per sector */ typedef struct _PARTITION_RECORD { - u8 status; /* Partition status; see above */ - u8 chs_start[3]; /* Cylinder-head-sector address to first block of partition */ - u8 type; /* Partition type; see above */ - u8 chs_end[3]; /* Cylinder-head-sector address to last block of partition */ - u32 lba_start; /* Local block address to first sector of partition */ - u32 block_count; /* Number of blocks in partition */ + u8 status; /* Partition status; see above */ + u8 chs_start[3]; /* Cylinder-head-sector address to first block of partition */ + u8 type; /* Partition type; see above */ + u8 chs_end[3]; /* Cylinder-head-sector address to last block of partition */ + u32 lba_start; /* Local block address to first sector of partition */ + u32 block_count; /* Number of blocks in partition */ } __attribute__((__packed__)) PARTITION_RECORD; typedef struct _MASTER_BOOT_RECORD { - u8 code_area[446]; /* Code area; normally empty */ - PARTITION_RECORD partitions[4]; /* 4 primary partitions */ - u16 signature; /* MBR signature; 0xAA55 */ + u8 code_area[446]; /* Code area; normally empty */ + PARTITION_RECORD partitions[4]; /* 4 primary partitions */ + u16 signature; /* MBR signature; 0xAA55 */ } __attribute__((__packed__)) MASTER_BOOT_RECORD; typedef struct _EXTENDED_BOOT_RECORD { - u8 code_area[446]; /* Code area; normally empty */ - PARTITION_RECORD partition; /* Primary partition */ - PARTITION_RECORD next_ebr; /* Next extended boot record in the chain */ - u8 reserved[32]; /* Normally empty */ - u16 signature; /* EBR signature; 0xAA55 */ + u8 code_area[446]; /* Code area; normally empty */ + PARTITION_RECORD partition; /* Primary partition */ + PARTITION_RECORD next_ebr; /* Next extended boot record in the chain */ + u8 reserved[32]; /* Normally empty */ + u16 signature; /* EBR signature; 0xAA55 */ } __attribute__((__packed__)) EXTENDED_BOOT_RECORD; typedef struct _GUID_PART_ENTRY { - u8 part_type_guid[16]; /* Partition type GUID */ - u8 uniq_part_guid[16]; /* Unique partition GUID */ - u64 part_first_lba; /* First LBA (little-endian) */ - u64 part_last_lba; /* Last LBA (inclusive, usually odd) */ + u8 part_type_guid[16]; /* Partition type GUID */ + u8 uniq_part_guid[16]; /* Unique partition GUID */ + u64 part_first_lba; /* First LBA (little-endian) */ + u64 part_last_lba; /* Last LBA (inclusive, usually odd) */ u64 attribute_flags; /* GUID Attribute flags (e.g. bit 60 denotes read-only) */ char partition_name[72]; /* Partition name (36 UTF-16LE code units) */ } __attribute__((__packed__)) GUID_PART_ENTRY; typedef struct _GPT_HEADER { - char magic[8]; /* "EFI PART" */ - u32 revision; /* For version 1.0 */ + char magic[8]; /* "EFI PART" */ + u32 revision; /* For version 1.0 */ u32 header_size; /* Header size in bytes */ - u32 checksum; /* CRC32 of header (0 to header size), with this field zeroed during calculation */ - u32 reserved; /* must be 0 */ - u64 header_lba; /* Current LBA (location of this header copy) */ - u64 backup_lba; /* Backup LBA (location of the other header copy) */ - u64 first_part_lba; /* First usable LBA for partitions (primary partition table last LBA + 1) */ - u64 last_part_lba; /* Last usable LBA (secondary partition table first LBA - 1) */ - u8 disk_guid[16]; /* Disk GUID (also referred as UUID on UNIXes) */ - u64 part_table_lba; /* Partition entries starting LBA (always 2 in primary copy) */ - u32 part_entries; /* Number of partition entries */ + u32 checksum; /* CRC32 of header (0 to header size), with this field zeroed during calculation */ + u32 reserved; /* must be 0 */ + u64 header_lba; /* Current LBA (location of this header copy) */ + u64 backup_lba; /* Backup LBA (location of the other header copy) */ + u64 first_part_lba; /* First usable LBA for partitions (primary partition table last LBA + 1) */ + u64 last_part_lba; /* Last usable LBA (secondary partition table first LBA - 1) */ + u8 disk_guid[16]; /* Disk GUID (also referred as UUID on UNIXes) */ + u64 part_table_lba; /* Partition entries starting LBA (always 2 in primary copy) */ + u32 part_entries; /* Number of partition entries */ u32 part_entry_size; /* Size of a partition entry (usually 128) */ u32 part_entry_checksum; /* CRC32 of partition array */ u8 zeros[420]; } __attribute__((__packed__)) GPT_HEADER; typedef struct _PartitionFS { - const char * FSName; + const char *FSName; u64 LBA_Start; u64 SecCount; bool Bootable; diff --git a/source/gc/gc.cpp b/source/gc/gc.cpp index 3fb3ab6a..e92efa4d 100644 --- a/source/gc/gc.cpp +++ b/source/gc/gc.cpp @@ -211,7 +211,7 @@ void DEVO_GetLoader(const char *loader) void DEVO_SetOptions(const char *isopath, int CurrentPartition, const char *gameID, bool memcard_emu) { // re-mount device we need - DeviceHandler::Instance()->MountDevolution(CurrentPartition); + DeviceHandle.MountDevolution(CurrentPartition); //start writing cfg to mem struct stat st; @@ -298,7 +298,7 @@ void DEVO_SetOptions(const char *isopath, int CurrentPartition, const char *game // flush disc ID and Devolution config out to memory DCFlushRange((void*)0x80000000, 64); - DeviceHandler::Instance()->UnMountDevolution(CurrentPartition); + DeviceHandle.UnMountDevolution(CurrentPartition); } void DEVO_Boot() diff --git a/source/list/cachedlist.cpp b/source/list/cachedlist.cpp index 048b84b7..85ee58e4 100644 --- a/source/list/cachedlist.cpp +++ b/source/list/cachedlist.cpp @@ -7,7 +7,7 @@ void CachedList::Load(string path, string containing, string m_lastLanguage, Con m_loaded = false; m_database = sfmt("%s/%s.db", m_cacheDir.c_str(), (make_db_name(path)).c_str()); - m_wbfsFS = strncasecmp(DeviceHandler::Instance()->PathToFSName(path.c_str()), "WBFS", 4) == 0; + m_wbfsFS = strncasecmp(DeviceHandle.PathToFSName(path.c_str()), "WBFS", 4) == 0; bool update_games = false; bool update_homebrew = false; @@ -23,7 +23,7 @@ void CachedList::Load(string path, string containing, string m_lastLanguage, Con update_homebrew = strcasestr(path.c_str(), "apps") != NULL && force_update[COVERFLOW_HOMEBREW]; update_emu = strcasestr(path.c_str(), m_plugin.getString("PLUGIN","romDir","").c_str()) != NULL && force_update[COVERFLOW_EMU]; - const char* partition = DeviceName[DeviceHandler::Instance()->PathToDriveType(path.c_str())]; + const char* partition = DeviceName[DeviceHandle.PathToDriveType(path.c_str())]; update_dml = strcasestr(path.c_str(), fmt(strncmp(partition, "sd", 2) != 0 ? m_DMLgameDir.c_str() : "%s:/games", partition)) != NULL && force_update[COVERFLOW_DML]; gprintf("update_games=%d update_homebrew=%d update_dml=%d, update_emu=%d\n", update_games, update_homebrew, update_dml, update_emu); diff --git a/source/list/list.cpp b/source/list/list.cpp index 9fd34127..9c920835 100644 --- a/source/list/list.cpp +++ b/source/list/list.cpp @@ -87,8 +87,8 @@ void CList::GetPaths(vector &pathlist, string containing, string dire if(strcasestr(containing.c_str(), ".dol") != 0) return; - int partition = DeviceHandler::Instance()->PathToDriveType(directory.c_str()); - wbfs_t* handle = DeviceHandler::Instance()->GetWbfsHandle(partition); + int partition = DeviceHandle.PathToDriveType(directory.c_str()); + wbfs_t* handle = DeviceHandle.GetWbfsHandle(partition); if(!handle) return; @@ -177,7 +177,7 @@ void CList::GetHeaders(vector pathlist, vector || (*itr).rfind(".bin") != string::npos || (*itr).rfind(".BIN") != string::npos) { char* filename = &(*itr)[(*itr).find_last_of('/')+1]; - const char* dml_partition = DeviceName[DeviceHandler::Instance()->PathToDriveType((*itr).c_str())]; + const char* dml_partition = DeviceName[DeviceHandle.PathToDriveType((*itr).c_str())]; if(strcasecmp(filename, "game.iso") == 0 || strcasecmp(filename, "gam1.iso") == 0 || strcasecmp(filename, "boot.bin") == 0) { FILE *fp = fopen((*itr).c_str(), "rb"); @@ -312,10 +312,10 @@ void CList::GetHeaders(vector pathlist, vector continue; } } - else if(strncasecmp(DeviceHandler::Instance()->PathToFSName((*itr).c_str()), "WBFS", 4) == 0) + else if(strncasecmp(DeviceHandle.PathToFSName((*itr).c_str()), "WBFS", 4) == 0) { - u8 partition = DeviceHandler::Instance()->PathToDriveType((*itr).c_str()); - wbfs_t* handle = DeviceHandler::Instance()->GetWbfsHandle(partition); + u8 partition = DeviceHandle.PathToDriveType((*itr).c_str()); + wbfs_t* handle = DeviceHandle.GetWbfsHandle(partition); if(!handle) return; diff --git a/source/loader/alt_ios.cpp b/source/loader/alt_ios.cpp index 2f035110..589f0e9c 100644 --- a/source/loader/alt_ios.cpp +++ b/source/loader/alt_ios.cpp @@ -16,7 +16,6 @@ #include "gecko/gecko.h" #include "memory/mem2.hpp" #include "memory/memory.h" -#include "music/musicplayer.h" #include "types.h" // mload from uloader by Hermes @@ -90,7 +89,6 @@ bool loadIOS(int ios, bool MountDevices) { WDVD_Close(); Close_Inputs(); - m_music.StopAndSetPos(); gprintf("Reloading into IOS %i from %i...\n", ios, CurIOS); ShutdownBeforeExit(); ret = IOS_ReloadIOS(ios) == 0; @@ -104,9 +102,9 @@ bool loadIOS(int ios, bool MountDevices) load_ehc_module_ex(); else if(CurrentIOS.Type == IOS_TYPE_WANIN && CurrentIOS.Revision >= 18) load_dip_249(); - DeviceHandler::Instance()->SetModes(); + DeviceHandle.SetModes(); if(MountDevices && ios != CurIOS) - DeviceHandler::Instance()->MountAll(); + DeviceHandle.MountAll(); return ret; } diff --git a/source/loader/external_booter.cpp b/source/loader/external_booter.cpp index f1ccdf10..d17d39d3 100644 --- a/source/loader/external_booter.cpp +++ b/source/loader/external_booter.cpp @@ -102,7 +102,7 @@ void ExternalBooter_ChannelSetup(u64 title) void ShutdownBeforeExit(bool KeepPatches) { - DeviceHandler::Instance()->UnMountAll(); + DeviceHandle.UnMountAll(); Nand::Instance()->DeInit_ISFS(KeepPatches); WDVD_Close(); } diff --git a/source/loader/wbfs.c b/source/loader/wbfs.c index 593b7030..96279e52 100644 --- a/source/loader/wbfs.c +++ b/source/loader/wbfs.c @@ -197,7 +197,7 @@ bool WBFS_Close() wbfs_part_fs = 0; wbfs_part_lba = 0; wbfs_part_idx = 0; - strcpy(wbfs_fs_drive, ""); + memset(wbfs_fs_drive, 0, sizeof(wbfs_fs_drive)); wbfs_mounted = 0; return 0; diff --git a/source/main.cpp b/source/main.cpp index 0e143c34..ffc19b12 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -34,6 +34,7 @@ int main(int argc, char **argv) CVideo vid; vid.init(); + DeviceHandle.Init(); Nand::Instance()->Init_ISFS(); MEM_init(); //Inits both mem1lo and mem2 gprintf(" \nWelcome to %s (%s-r%s)!\nThis is the debug output.\n", APP_NAME, APP_VERSION, SVN_REV); @@ -73,7 +74,7 @@ int main(int argc, char **argv) CurrentIOS.Base = 254; CurrentIOS.Revision = 999; DCFlushRange(&CurrentIOS, sizeof(IOS_Info)); - DeviceHandler::Instance()->SetModes(); + DeviceHandle.SetModes(); } else if(AHBRPOT_Patched() && IOS_GetVersion() == 58) { @@ -89,7 +90,7 @@ int main(int argc, char **argv) Sys_Init(); Sys_ExitTo(EXIT_TO_HBC); - DeviceHandler::Instance()->MountAll(); + DeviceHandle.MountAll(); vid.waitMessage(0.15f); mainMenu = new CMenu(vid); @@ -97,7 +98,7 @@ int main(int argc, char **argv) mainMenu->init(); if(CurrentIOS.Version != mainIOS && !neek2o() && !Sys_DolphinMode()) { - if(useMainIOS || !DeviceHandler::Instance()->UsablePartitionMounted()) + if(useMainIOS || !DeviceHandle.UsablePartitionMounted()) { iosOK = loadIOS(mainIOS, true) && CustomIOS(CurrentIOS.Type); Open_Inputs(); @@ -109,7 +110,7 @@ int main(int argc, char **argv) if(!iosOK) mainMenu->terror("errboot1", L"No cIOS found!\ncIOS d2x 249 base 56 and 250 base 57 are enough for all your games."); - else if(!DeviceHandler::Instance()->UsablePartitionMounted()) + else if(!DeviceHandle.UsablePartitionMounted()) mainMenu->terror("errboot2", L"Could not find a device to save configuration files on!"); else if(WDVD_Init() < 0) mainMenu->terror("errboot3", L"Could not initialize the DIP module!"); diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index 0476318d..fa53dab5 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -158,7 +158,7 @@ void CMenu::init(void) Playlog_Delete(); for(int i = SD; i <= USB8; i++) //Find the first partition with a wiiflow.ini - if (DeviceHandler::Instance()->IsInserted(i) && DeviceHandler::Instance()->GetFSType(i) != PART_FS_WBFS && stat(fmt("%s:/%s/" CFG_FILENAME, DeviceName[i], APPDATA_DIR2), &dummy) == 0) + if (DeviceHandle.IsInserted(i) && DeviceHandle.GetFSType(i) != PART_FS_WBFS && stat(fmt("%s:/%s/" CFG_FILENAME, DeviceName[i], APPDATA_DIR2), &dummy) == 0) { drive = DeviceName[i]; break; @@ -166,7 +166,7 @@ void CMenu::init(void) if(drive == check) //No wiiflow.ini found for(int i = SD; i <= USB8; i++) //Find the first partition with a boot.dol - if (DeviceHandler::Instance()->IsInserted(i) && DeviceHandler::Instance()->GetFSType(i) != PART_FS_WBFS && stat(fmt("%s:/%s/boot.dol", DeviceName[i], APPDATA_DIR2), &dummy) == 0) + if (DeviceHandle.IsInserted(i) && DeviceHandle.GetFSType(i) != PART_FS_WBFS && stat(fmt("%s:/%s/boot.dol", DeviceName[i], APPDATA_DIR2), &dummy) == 0) { drive = DeviceName[i]; break; @@ -174,7 +174,7 @@ void CMenu::init(void) if(drive == check) //No boot.dol found for(int i = SD; i <= USB8; i++) //Find the first partition with apps/wiiflow folder - if (DeviceHandler::Instance()->IsInserted(i) && DeviceHandler::Instance()->GetFSType(i) != PART_FS_WBFS && stat(fmt("%s:/%s", DeviceName[i], APPDATA_DIR2), &dummy) == 0) + if (DeviceHandle.IsInserted(i) && DeviceHandle.GetFSType(i) != PART_FS_WBFS && stat(fmt("%s:/%s", DeviceName[i], APPDATA_DIR2), &dummy) == 0) { drive = DeviceName[i]; break; @@ -182,7 +182,7 @@ void CMenu::init(void) if(drive == check) //No apps/wiiflow folder found for(int i = SD; i <= USB8; i++) // Find the first writable partition - if (DeviceHandler::Instance()->IsInserted(i) && DeviceHandler::Instance()->GetFSType(i) != PART_FS_WBFS) + if (DeviceHandle.IsInserted(i) && DeviceHandle.GetFSType(i) != PART_FS_WBFS) { drive = DeviceName[i]; fsop_MakeFolder((char *)fmt("%s:/%s", DeviceName[i], APPDATA_DIR2)); //Make the apps dir, so saving wiiflow.ini does not fail. @@ -221,17 +221,17 @@ void CMenu::init(void) if (onUSB) { for(int i = USB1; i <= USB8; i++) //Look for first partition with a wiiflow folder in root - if (DeviceHandler::Instance()->IsInserted(i) && DeviceHandler::Instance()->GetFSType(i) != PART_FS_WBFS && stat(fmt("%s:/%s", DeviceName[i], APPDATA_DIR), &dummy) == 0) + if (DeviceHandle.IsInserted(i) && DeviceHandle.GetFSType(i) != PART_FS_WBFS && stat(fmt("%s:/%s", DeviceName[i], APPDATA_DIR), &dummy) == 0) { drive = DeviceName[i]; break; } } - else if(DeviceHandler::Instance()->IsInserted(SD)) drive = DeviceName[SD]; + else if(DeviceHandle.IsInserted(SD)) drive = DeviceName[SD]; if(drive == check && onUSB) //No wiiflow folder found in root of any usb partition, and data_on_usb=yes for(int i = USB1; i <= USB8; i++) // Try first USB partition with wbfs folder. - if (DeviceHandler::Instance()->IsInserted(i) && DeviceHandler::Instance()->GetFSType(i) != PART_FS_WBFS && stat(fmt(GAMES_DIR, DeviceName[i]), &dummy) == 0) + if (DeviceHandle.IsInserted(i) && DeviceHandle.GetFSType(i) != PART_FS_WBFS && stat(fmt(GAMES_DIR, DeviceName[i]), &dummy) == 0) { drive = DeviceName[i]; break; @@ -239,7 +239,7 @@ void CMenu::init(void) if(drive == check && onUSB) // No wbfs folder found and data_on_usb=yes for(int i = USB1; i <= USB8; i++) // Try first available USB partition. - if (DeviceHandler::Instance()->IsInserted(i) && DeviceHandler::Instance()->GetFSType(i) != PART_FS_WBFS) + if (DeviceHandle.IsInserted(i) && DeviceHandle.GetFSType(i) != PART_FS_WBFS) { drive = DeviceName[i]; break; @@ -248,7 +248,7 @@ void CMenu::init(void) if(drive == check) { _buildMenus(); - if(DeviceHandler::Instance()->IsInserted(SD)) + if(DeviceHandle.IsInserted(SD)) { error(_fmt("errboot5", L"data_on_usb=yes and No available usb partitions for data!\nUsing SD.")); drive = DeviceName[SD]; @@ -320,7 +320,7 @@ void CMenu::init(void) const char *checkDir = m_current_view == COVERFLOW_HOMEBREW ? HOMEBREW_DIR : GAMES_DIR; u8 partition = m_cfg.getInt(domain, "partition", 0); //Auto find a valid partition and fix old ini partition settings. - if(m_current_view != COVERFLOW_CHANNEL && (partition > USB8 || !DeviceHandler::Instance()->IsInserted(partition))) + if(m_current_view != COVERFLOW_CHANNEL && (partition > USB8 || !DeviceHandle.IsInserted(partition))) { m_cfg.remove(domain, "partition"); for(int i = SD; i <= USB8+1; i++) // Find a usb partition with the wbfs folder or wbfs file system, else leave it blank (defaults to 1 later) @@ -330,8 +330,8 @@ void CMenu::init(void) m_current_view = COVERFLOW_CHANNEL; break; } - if (DeviceHandler::Instance()->IsInserted(i) - && ((m_current_view == COVERFLOW_USB && DeviceHandler::Instance()->GetFSType(i) == PART_FS_WBFS) + if (DeviceHandle.IsInserted(i) + && ((m_current_view == COVERFLOW_USB && DeviceHandle.GetFSType(i) == PART_FS_WBFS) || stat(fmt(checkDir, DeviceName[i]), &dummy) == 0)) { gprintf("Setting Emu NAND to Partition: %i\n",currentPartition); @@ -437,7 +437,7 @@ void CMenu::init(void) } m_btnMgr.init(m_vid); - m_music.Init(m_cfg, m_musicDir, sfmt("%s/music", m_themeDataDir.c_str())); + MusicPlayer.Init(m_cfg, m_musicDir, sfmt("%s/music", m_themeDataDir.c_str())); _buildMenus(); @@ -445,7 +445,7 @@ void CMenu::init(void) m_btnMgr.setRumble(m_cfg.getBool("GENERAL", "rumble", true)); int exit_to = m_cfg.getInt("GENERAL", "exit_to", 0); - if(exit_to == EXIT_TO_BOOTMII && (!DeviceHandler::Instance()->IsInserted(SD) || + if(exit_to == EXIT_TO_BOOTMII && (!DeviceHandle.IsInserted(SD) || stat(fmt("%s:/bootmii/armboot.bin",DeviceName[SD]), &dummy) != 0 || stat(fmt("%s:/bootmii/ppcboot.elf", DeviceName[SD]), &dummy) != 0)) exit_to = EXIT_TO_HBC; @@ -496,7 +496,7 @@ void CMenu::cleanup() m_plugin.Cleanup(); _stopSounds(); - m_music.cleanup(); + MusicPlayer.Cleanup(); m_cameraSound.release(); ClearGameSoundThreadStack(); SoundHandler::DestroyInstance(); @@ -1894,7 +1894,7 @@ void CMenu::_mainLoopCommon(bool withCF, bool adjusting) if(Sys_Exiting()) exitHandler(BUTTON_CALLBACK); - if(withCF && m_gameSelected && m_gamesound_changed && (m_gameSoundHdr == NULL) && !m_gameSound.IsPlaying() && m_music.GetVolume() == 0) + if(withCF && m_gameSelected && m_gamesound_changed && (m_gameSoundHdr == NULL) && !m_gameSound.IsPlaying() && MusicPlayer.GetVolume() == 0) { CheckGameSoundThread(); m_gameSound.Play(m_bnrSndVol); @@ -1903,18 +1903,18 @@ void CMenu::_mainLoopCommon(bool withCF, bool adjusting) else if(!m_gameSelected) m_gameSound.Stop(); - m_music.Tick(m_video_playing || (m_gameSelected && + MusicPlayer.Tick(m_video_playing || (m_gameSelected && m_gameSound.IsLoaded()) || m_gameSound.IsPlaying()); - if(m_music.SongChanged()) + if(MusicPlayer.SongChanged()) { - m_btnMgr.setText(m_mainLblCurMusic, m_music.GetFileName(), true); + m_btnMgr.setText(m_mainLblCurMusic, MusicPlayer.GetFileName(), true); m_btnMgr.show(m_mainLblCurMusic); - m_music.DisplayTime = time(NULL); + MusicPlayer.DisplayTime = time(NULL); } - else if(m_music.DisplayTime > 0 && time(NULL) - m_music.DisplayTime > 3) + else if(MusicPlayer.DisplayTime > 0 && time(NULL) - MusicPlayer.DisplayTime > 3) { - m_music.DisplayTime = 0; + MusicPlayer.DisplayTime = 0; m_btnMgr.hide(m_mainLblCurMusic); } @@ -2153,14 +2153,12 @@ bool CMenu::_loadChannelList(void) Nand::Instance()->Disable_Emu(); if(!disable_emu) { - if(useMainIOS) - m_music.StopAndSetPos(); - else - _TempLoadIOS(); - if(!DeviceHandler::Instance()->IsInserted(lastPartition)) - DeviceHandler::Instance()->Mount(lastPartition); + MusicPlayer.Stop(); + _TempLoadIOS(); + if(!DeviceHandle.IsInserted(lastPartition)) + DeviceHandle.Mount(lastPartition); - DeviceHandler::Instance()->UnMount(currentPartition); + DeviceHandle.UnMount(currentPartition); Nand::Instance()->Init(emuPath.c_str(), currentPartition, disable_emu); if(Nand::Instance()->Enable_Emu() < 0) @@ -2169,8 +2167,8 @@ bool CMenu::_loadChannelList(void) gprintf("Using path: \"%s\" for NAND emulation\n", nandpath.c_str()); } - if(!DeviceHandler::Instance()->IsInserted(currentPartition)) - DeviceHandler::Instance()->Mount(currentPartition); + if(!DeviceHandle.IsInserted(currentPartition)) + DeviceHandle.Mount(currentPartition); if(Nand::Instance()->EmulationEnabled() || disable_emu) { @@ -2189,14 +2187,15 @@ bool CMenu::_loadList(void) { m_cf.clear(); m_gameList.clear(); - if((m_current_view == COVERFLOW_CHANNEL && m_cfg.getBool("NAND", "disable", true)) || m_current_view != COVERFLOW_CHANNEL) + if((m_current_view == COVERFLOW_CHANNEL && m_cfg.getBool("NAND", "disable", true)) + || (m_current_view != COVERFLOW_CHANNEL && Nand::Instance()->EmulationEnabled())) + { + MusicPlayer.Stop(); Nand::Instance()->Disable_Emu(); - + _TempLoadIOS(IOS_TYPE_NORMAL_IOS); + } if(m_cfg.getBool(_domainFromView(), "update_cache")) m_gameList.Update(m_current_view); - - /* Make sure if coming from Emu NAND the IOS is set back */ - _TempLoadIOS(IOS_TYPE_NORMAL_IOS); gprintf("Loading items of "); bool retval; @@ -2232,22 +2231,23 @@ bool CMenu::_loadList(void) bool CMenu::_loadGameList(void) { currentPartition = m_cfg.getInt("GAMES", "partition", 1); - if(!DeviceHandler::Instance()->IsInserted(currentPartition)) + if(!DeviceHandle.IsInserted(currentPartition)) return false; Config tmpcfg; gprintf("%s\n", DeviceName[currentPartition]); - DeviceHandler::Instance()->Open_WBFS(currentPartition); + DeviceHandle.OpenWBFS(currentPartition); m_gameList.Load(sfmt(GAMES_DIR, DeviceName[currentPartition]), ".wbfs|.iso", m_cfg.getString("GAMES", "lastlanguage", "EN").c_str(), tmpcfg); m_cfg.setString("GAMES", "lastlanguage", m_loc.getString(m_curLanguage, "gametdb_code", "EN")); m_cfg.save(); + WBFS_Close(); return m_gameList.size() > 0 ? true : false; } bool CMenu::_loadHomebrewList() { - currentPartition = m_cfg.getInt("HOMEBREW", "partition", DeviceHandler::Instance()->PathToDriveType(m_appDir.c_str())); - if(!DeviceHandler::Instance()->IsInserted(currentPartition)) + currentPartition = m_cfg.getInt("HOMEBREW", "partition", DeviceHandle.PathToDriveType(m_appDir.c_str())); + if(!DeviceHandle.IsInserted(currentPartition)) return false; Config tmpcfg; @@ -2261,7 +2261,7 @@ bool CMenu::_loadHomebrewList() bool CMenu::_loadDmlList() { currentPartition = m_cfg.getInt("DML", "partition", 0); - if(!DeviceHandler::Instance()->IsInserted(currentPartition)) + if(!DeviceHandle.IsInserted(currentPartition)) return false; Config tmpcfg; @@ -2278,7 +2278,7 @@ bool CMenu::_loadDmlList() bool CMenu::_loadEmuList() { currentPartition = m_cfg.getInt("EMULATOR", "partition", 0); - if(!DeviceHandler::Instance()->IsInserted(currentPartition)) + if(!DeviceHandle.IsInserted(currentPartition)) return false; gprintf("%s\n", DeviceName[currentPartition]); @@ -2340,11 +2340,11 @@ void CMenu::_stopSounds(void) // Fade out sounds int fade_rate = m_cfg.getInt("GENERAL", "music_fade_rate", 8); - if(!m_music.IsStopped()) + if(!MusicPlayer.IsStopped()) { - while(m_music.GetVolume() > 0 || m_gameSound.GetVolume() > 0) + while(MusicPlayer.GetVolume() > 0 || m_gameSound.GetVolume() > 0) { - m_music.Tick(true); + MusicPlayer.Tick(true); if(m_gameSound.GetVolume() > 0) m_gameSound.SetVolume(m_gameSound.GetVolume() < fade_rate ? 0 : m_gameSound.GetVolume() - fade_rate); VIDEO_WaitVSync(); @@ -2653,7 +2653,6 @@ void CMenu::RemoveCover( char * id ) void CMenu::_TempLoadIOS(int IOS) { -#ifndef DOLPHIN /* Only temp reload in IOS58 mode */ if(useMainIOS || neek2o() || Sys_DolphinMode()) return; @@ -2670,5 +2669,4 @@ void CMenu::_TempLoadIOS(int IOS) for(int chan = WPAD_MAX_WIIMOTES-2; chan >= 0; chan--) WPAD_SetVRes(chan, m_vid.width() + m_cursor[chan].width(), m_vid.height() + m_cursor[chan].height()); } -#endif } diff --git a/source/menu/menu.hpp b/source/menu/menu.hpp index 46e5527a..168b9531 100644 --- a/source/menu/menu.hpp +++ b/source/menu/menu.hpp @@ -22,7 +22,7 @@ #include "loader/gc_disc_dump.hpp" #include "loader/wbfs.h" #include "music/gui_sound.h" -#include "music/musicplayer.h" +#include "music/MusicPlayer.hpp" #include "plugin/plugin.hpp" #include "wiiuse/wpad.h" diff --git a/source/menu/menu_configsnd.cpp b/source/menu/menu_configsnd.cpp index eb89119e..d7199202 100644 --- a/source/menu/menu_configsnd.cpp +++ b/source/menu/menu_configsnd.cpp @@ -101,14 +101,14 @@ int CMenu::_configSnd(void) int musicVol = min(m_cfg.getInt("GENERAL", "sound_volume_music", 255) + step, 255); m_cfg.setInt("GENERAL", "sound_volume_music", musicVol); _showConfigSnd(); - m_music.SetMaxVolume(musicVol); + MusicPlayer.SetMaxVolume(musicVol); } else if (m_btnMgr.selected(m_configSndBtnMusicVolM)) { int musicVol = max(m_cfg.getInt("GENERAL", "sound_volume_music", 255) - step, 0); m_cfg.setInt("GENERAL", "sound_volume_music", musicVol); _showConfigSnd(); - m_music.SetMaxVolume(musicVol); + MusicPlayer.SetMaxVolume(musicVol); } else if (m_btnMgr.selected(m_configSndBtnCFVolP)) { diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index 002d8863..ea7d574b 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -265,6 +265,7 @@ static Banner *_extractBnr(dir_discHdr *hdr) { u32 size = 0; Banner *banner = NULL; + DeviceHandle.OpenWBFS(currentPartition); wbfs_disc_t *disc = WBFS_OpenDisc((u8 *) &hdr->id, (char *) hdr->path); if (disc != NULL) { @@ -274,6 +275,7 @@ static Banner *_extractBnr(dir_discHdr *hdr) banner = new Banner((u8 *)bnr, size); WBFS_CloseDisc(disc); } + WBFS_Close(); return banner; } @@ -449,7 +451,7 @@ void CMenu::_game(bool launch) FILE *file = fopen(videoPath.c_str(), "rb"); if(file) { - m_music.StopAndSetPos(); + MusicPlayer.Stop(); m_gameSound.Stop(); m_banner->SetShowBanner(false); fclose(file); @@ -544,6 +546,7 @@ void CMenu::_game(bool launch) else if(launch || m_btnMgr.selected(m_gameBtnPlay) || m_btnMgr.selected(m_gameBtnPlayFull) || !ShowPointer()) { _hideGame(); + MusicPlayer.Stop(); m_gameSound.FreeMemory(); CheckGameSoundThread(); ClearGameSoundThreadStack(); @@ -738,15 +741,13 @@ void CMenu::directlaunch(const string &id) for (int i = USB1; i < USB8; i++) { - if(!DeviceHandler::Instance()->IsInserted(i)) continue; + if(!DeviceHandle.IsInserted(i)) continue; - DeviceHandler::Instance()->Open_WBFS(i); + DeviceHandle.OpenWBFS(i); CList list; string path = sfmt(GAMES_DIR, DeviceName[i]); vector pathlist; - list.GetPaths(pathlist, id.c_str(), path, - strncasecmp(DeviceHandler::Instance()->PathToFSName(path.c_str()), "WBFS", 4) == 0); - + list.GetPaths(pathlist, id.c_str(), path, strncasecmp(DeviceHandle.PathToFSName(path.c_str()), "WBFS", 4) == 0); m_gameList.clear(); Config nullCfg; list.GetHeaders(pathlist, m_gameList, m_settingsDir, m_curLanguage, m_DMLgameDir, nullCfg); @@ -755,6 +756,7 @@ void CMenu::directlaunch(const string &id) gprintf("Game found on partition #%i\n", i); _launch(&m_gameList[0]); // Launch will exit wiiflow } + WBFS_Close(); } error(sfmt("errgame1", L"Cannot find the game with ID: %s", id.c_str())); } @@ -1109,7 +1111,7 @@ void CMenu::_launchChannel(dir_discHdr *hdr) { if(!emu_disabled) { - DeviceHandler::Instance()->UnMount(emuPartition); + DeviceHandle.UnMount(emuPartition); Nand::Instance()->Init(emuPath.c_str(), emuPartition, false); Nand::Instance()->Enable_Emu(); } @@ -1360,10 +1362,6 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) if(_loadIOS(gameIOS, userIOS, id) == LOAD_IOS_FAILED) Sys_Exit(); } - DeviceHandler::Instance()->Open_WBFS(currentPartition); - bool wbfs_partition = (DeviceHandler::Instance()->GetFSType(currentPartition) == PART_FS_WBFS); - if(!dvd && !wbfs_partition && get_frag_list((u8 *)id.c_str(), (char*)path.c_str(), currentPartition == 0 ? 0x200 : USBStorage2_GetSectorSize()) < 0) - Sys_Exit(); if(CurrentIOS.Type == IOS_TYPE_D2X) { /* Open ES Module */ @@ -1395,7 +1393,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) if(emulate_mode && !neek2o()) { Nand::Instance()->Init(emuPath.c_str(), emuPartition, false); - DeviceHandler::Instance()->UnMount(emuPartition); + DeviceHandle.UnMount(emuPartition); if(emulate_mode == 3) Nand::Instance()->Set_RCMode(true); @@ -1409,12 +1407,16 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) error(_t("errgame6", L"Enabling emu after reload failed!")); Sys_Exit(); } - if(!DeviceHandler::Instance()->IsInserted(currentPartition)) - DeviceHandler::Instance()->Mount(currentPartition); - DeviceHandler::Instance()->Mount(emuPartition); + if(!DeviceHandle.IsInserted(currentPartition)) + DeviceHandle.Mount(currentPartition); + DeviceHandle.Mount(emuPartition); } if(!dvd) { + DeviceHandle.OpenWBFS(currentPartition); + bool wbfs_partition = (DeviceHandle.GetFSType(currentPartition) == PART_FS_WBFS); + if(!wbfs_partition && get_frag_list((u8 *)id.c_str(), (char*)path.c_str(), currentPartition == 0 ? 0x200 : USBStorage2_GetSectorSize()) < 0) + Sys_Exit(); s32 ret = Disc_SetUSB((u8*)id.c_str(), !wbfs_partition); if(ret < 0) { @@ -1427,6 +1429,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) error(_t("wbfsoperr2", L"Disc_Open failed")); Sys_Exit(); } + WBFS_Close(); } if(gameconfig.get() != NULL) { diff --git a/source/menu/menu_main.cpp b/source/menu/menu_main.cpp index 28bf10f1..ecea1c27 100644 --- a/source/menu/menu_main.cpp +++ b/source/menu/menu_main.cpp @@ -154,7 +154,7 @@ void CMenu::_showMain(void) if(!m_cfg.getBool("NAND", "disable", true)) { Nand::Instance()->Disable_Emu(); - DeviceHandler::Instance()->MountAll(); + DeviceHandle.MountAll(); _hideMain(); if(!_AutoCreateNand()) m_cfg.setBool("NAND", "disable", true); @@ -217,7 +217,7 @@ void CMenu::exitHandler(int ExitTo) if(ExitTo == EXIT_TO_BOOTMII) //Bootmii, check that the files are there, or ios will hang. { struct stat dummy; - if(!DeviceHandler::Instance()->IsInserted(SD) || + if(!DeviceHandle.IsInserted(SD) || stat("sd:/bootmii/armboot.bin", &dummy) != 0 || stat("sd:/bootmii/ppcboot.elf", &dummy) != 0) ExitTo = EXIT_TO_HBC; @@ -545,14 +545,14 @@ int CMenu::main(void) else if(BTN_MINUS_PRESSED) { if(b_lr_mode) - m_music.Previous(); + MusicPlayer.Previous(); else m_cf.pageUp(); } else if(BTN_PLUS_PRESSED) { if(b_lr_mode) - m_music.Next(); + MusicPlayer.Next(); else m_cf.pageDown(); } @@ -596,7 +596,7 @@ int CMenu::main(void) if(b_lr_mode) m_cf.pageUp(); else - m_music.Previous(); + MusicPlayer.Previous(); } else if(BTN_RIGHT_PRESSED) { @@ -604,7 +604,7 @@ int CMenu::main(void) if(b_lr_mode) m_cf.pageDown(); else - m_music.Next(); + MusicPlayer.Next(); } else if(BTN_PLUS_PRESSED && !m_locked) { @@ -650,11 +650,11 @@ int CMenu::main(void) Nand::Instance()->Enable_Emu(); u8 limiter = 0; currentPartition = loopNum(currentPartition + 1, (int)USB8); - while(!DeviceHandler::Instance()->IsInserted(currentPartition) || - ((m_current_view == COVERFLOW_CHANNEL || m_current_view == COVERFLOW_EMU) && (DeviceHandler::Instance()->GetFSType(currentPartition) != PART_FS_FAT || - (!isD2XnewerThanV6 && DeviceHandler::Instance()->PathToDriveType(m_appDir.c_str()) == currentPartition) || - (!isD2XnewerThanV6 && DeviceHandler::Instance()->PathToDriveType(m_dataDir.c_str()) == currentPartition))) || - ((m_current_view == COVERFLOW_HOMEBREW || m_current_view == COVERFLOW_DML) && DeviceHandler::Instance()->GetFSType(currentPartition) == PART_FS_WBFS)) + while(!DeviceHandle.IsInserted(currentPartition) || + ((m_current_view == COVERFLOW_CHANNEL || m_current_view == COVERFLOW_EMU) && (DeviceHandle.GetFSType(currentPartition) != PART_FS_FAT || + (!isD2XnewerThanV6 && DeviceHandle.PathToDriveType(m_appDir.c_str()) == currentPartition) || + (!isD2XnewerThanV6 && DeviceHandle.PathToDriveType(m_dataDir.c_str()) == currentPartition))) || + ((m_current_view == COVERFLOW_HOMEBREW || m_current_view == COVERFLOW_DML) && DeviceHandle.GetFSType(currentPartition) == PART_FS_WBFS)) { currentPartition = loopNum(currentPartition + 1, (int)USB8); if(limiter > 10) break; diff --git a/source/menu/menu_nandemu.cpp b/source/menu/menu_nandemu.cpp index f1514639..022a7601 100644 --- a/source/menu/menu_nandemu.cpp +++ b/source/menu/menu_nandemu.cpp @@ -118,10 +118,10 @@ int CMenu::_FindEmuPart(string *emuPath, int part, bool searchvalid) } } - if(!DeviceHandler::Instance()->IsInserted(emuPartition)) - DeviceHandler::Instance()->Mount(emuPartition); + if(!DeviceHandle.IsInserted(emuPartition)) + DeviceHandle.Mount(emuPartition); - if(_TestEmuNand(emuPartition, tmpPath.c_str(), true) && DeviceHandler::Instance()->PartitionUsableForNandEmu(emuPartition)) + if(_TestEmuNand(emuPartition, tmpPath.c_str(), true) && DeviceHandle.PartitionUsableForNandEmu(emuPartition)) { *emuPath = tmpPath; return emuPartition; @@ -131,10 +131,10 @@ int CMenu::_FindEmuPart(string *emuPath, int part, bool searchvalid) bool fllscn = emuPartition == -1; for(u8 i = part; i <= USB8; ++i) { - if(!DeviceHandler::Instance()->IsInserted(i)) - DeviceHandler::Instance()->Mount(i); + if(!DeviceHandle.IsInserted(i)) + DeviceHandle.Mount(i); - if(!DeviceHandler::Instance()->PartitionUsableForNandEmu(i)) + if(!DeviceHandle.PartitionUsableForNandEmu(i)) continue; if(_TestEmuNand(i, tmpPath.c_str(), true) || searchvalid) @@ -203,11 +203,11 @@ void CMenu::_enableNandEmu(bool fromconfig) if (!fromconfig) direction = 0; currentPartition = loopNum(currentPartition + direction, (int)USB8); - while(!DeviceHandler::Instance()->IsInserted(currentPartition) || - (m_current_view == COVERFLOW_CHANNEL && (DeviceHandler::Instance()->GetFSType(currentPartition) != PART_FS_FAT || - (!isD2XnewerThanV6 && DeviceHandler::Instance()->PathToDriveType(m_appDir.c_str()) == currentPartition) || - (!isD2XnewerThanV6 && DeviceHandler::Instance()->PathToDriveType(m_dataDir.c_str()) == currentPartition))) || - ((m_current_view == COVERFLOW_HOMEBREW || m_current_view == COVERFLOW_DML) && DeviceHandler::Instance()->GetFSType(currentPartition) == PART_FS_WBFS)) + while(!DeviceHandle.IsInserted(currentPartition) || + (m_current_view == COVERFLOW_CHANNEL && (DeviceHandle.GetFSType(currentPartition) != PART_FS_FAT || + (!isD2XnewerThanV6 && DeviceHandle.PathToDriveType(m_appDir.c_str()) == currentPartition) || + (!isD2XnewerThanV6 && DeviceHandle.PathToDriveType(m_dataDir.c_str()) == currentPartition))) || + ((m_current_view == COVERFLOW_HOMEBREW || m_current_view == COVERFLOW_DML) && DeviceHandle.GetFSType(currentPartition) == PART_FS_WBFS)) { currentPartition = loopNum(currentPartition + direction, (int)USB8); if (limiter > 10) break; diff --git a/source/menu/menu_wbfs.cpp b/source/menu/menu_wbfs.cpp index 3ca427e6..331e4b2b 100644 --- a/source/menu/menu_wbfs.cpp +++ b/source/menu/menu_wbfs.cpp @@ -115,18 +115,16 @@ int CMenu::_gameInstaller(void *obj) CMenu &m = *(CMenu *)obj; int ret; - DeviceHandler::Instance()->Open_WBFS(currentPartition); + DeviceHandle.OpenWBFS(currentPartition); if(!WBFS_Mounted()) { m.m_thrdWorking = false; return -1; } - u64 comp_size = 0, real_size = 0; f32 free, used; WBFS_DiskSpace(&used, &free); WBFS_DVD_Size(&comp_size, &real_size); - if((f32)comp_size + (f32)128*1024 >= free * GB_SIZE) { LWP_MutexLock(m.m_mutex); @@ -149,6 +147,7 @@ int CMenu::_gameInstaller(void *obj) LWP_MutexUnlock(m.m_mutex); slotLight(true); } + WBFS_Close(); m.m_thrdWorking = false; return ret; } @@ -173,7 +172,7 @@ int CMenu::_GCgameInstaller(void *obj) int ret; m.m_progress = 0.f; - if (!DeviceHandler::Instance()->IsInserted(currentPartition)) + if (!DeviceHandle.IsInserted(currentPartition)) { m.m_thrdWorking = false; return -1; @@ -307,6 +306,7 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) switch(op) { case CMenu::WO_ADD_GAME: + MusicPlayer.Stop(); _TempLoadIOS(); m_btnMgr.show(m_wbfsPBar); m_btnMgr.setProgress(m_wbfsPBar, 0.f); @@ -436,7 +436,7 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) m_thrdMessageAdded = false; m_cf.stopCoverLoader(); _stopSounds(); - m_music.cleanup(); + MusicPlayer.Cleanup(); SoundHandler::DestroyInstance(); soundDeinit(); Nand::Instance()->Disable_Emu(); @@ -461,6 +461,7 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) if(op == CMenu::WO_ADD_GAME) { WDVD_StopMotor(); + MusicPlayer.Stop(); _TempLoadIOS(IOS_TYPE_NORMAL_IOS); } m_btnMgr.show(m_wbfsBtnBack); diff --git a/source/music/MusicPlayer.cpp b/source/music/MusicPlayer.cpp new file mode 100644 index 00000000..57d0acc6 --- /dev/null +++ b/source/music/MusicPlayer.cpp @@ -0,0 +1,171 @@ +/**************************************************************************** + * Copyright (C) 2012 FIX94 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ +#include +#include + +#include "MusicPlayer.hpp" +#include "SoundHandler.hpp" +#include "fileOps/fileOps.h" +#include "gui/text.hpp" +#include "gecko/gecko.h" + +Musicplayer MusicPlayer; + +void Musicplayer::Cleanup() +{ + Stop(); + DisplayTime = 0; + CurrentPosition = 0; + MusicChanged = false; + MusicStopped = true; + FileNames.clear(); +} + +void Musicplayer::Init(Config &cfg, string musicDir, string themeMusicDir) +{ + Cleanup(); + FadeRate = cfg.getInt("GENERAL", "music_fade_rate", 8); + Volume = cfg.getInt("GENERAL", "sound_volume_music", 255); + + SetVolume(0); + MusicFile.SetVoice(0); + + ScanDirectories(themeMusicDir.c_str()); + ScanDirectories(musicDir.c_str()); + if(cfg.getBool("GENERAL", "randomize_music", true) && FileNames.size() > 0) + { + srand(unsigned(time(NULL))); + random_shuffle(FileNames.begin(), FileNames.end()); + } + CurrentFileName = FileNames.begin(); +} + +void Musicplayer::ScanDirectories(const char *directory) +{ + struct dirent *pent = NULL; + DIR *pdir = opendir(directory); + while((pent = readdir(pdir)) != NULL) + { + if(strcmp(pent->d_name, ".") == 0 || strcmp(pent->d_name, "..") == 0) + continue; + string CurrentItem = sfmt("%s/%s", directory, pent->d_name); + if(fsop_DirExist(CurrentItem.c_str())) + ScanDirectories(CurrentItem.c_str()); + else if(strcasestr(pent->d_name, ".mp3") != NULL || strcasestr(pent->d_name, ".ogg") != NULL) + FileNames.push_back(CurrentItem); + } + closedir(pdir); +} + +void Musicplayer::SetMaxVolume(u8 volume) +{ + Volume = volume; + SetVolume(volume); +} + +void Musicplayer::SetVolume(u8 volume) +{ + CurrentVolume = volume; + MusicFile.SetVolume(CurrentVolume); +} + +void Musicplayer::Previous() +{ + if(FileNames.empty() || PosFromPrevFile()) + return; + + if(CurrentFileName == FileNames.begin()) + CurrentFileName = FileNames.end(); + CurrentFileName--; + LoadCurrentFile(); +} + +void Musicplayer::Next() +{ + if(FileNames.empty() || PosFromPrevFile()) + return; + + CurrentFileName++; + if(CurrentFileName == FileNames.end()) + CurrentFileName = FileNames.begin(); + LoadCurrentFile(); +} + +bool Musicplayer::PosFromPrevFile() +{ + if(!CurrentPosition) + return false; + + MusicFile.Load((*CurrentFileName).c_str()); + SoundHandler::Instance()->Decoder(MusicFile.GetVoice())->Seek(CurrentPosition); + SetVolume(CurrentVolume); + MusicFile.Play(); + CurrentPosition = 0; + MusicStopped = false; + MusicChanged = false; + return true; +} + +void Musicplayer::Stop() +{ + if(!MusicFile.IsPlaying()) + return; + MusicFile.Pause(); + CurrentPosition = SoundHandler::Instance()->Decoder(MusicFile.GetVoice())->Tell(); + MusicFile.FreeMemory(); + MusicStopped = true; +} + +void Musicplayer::Tick(bool attenuate) +{ + if(FileNames.empty()) + return; + if(!attenuate && CurrentVolume < Volume) + SetVolume(CurrentVolume + FadeRate > Volume ? Volume : CurrentVolume + FadeRate); + else if(attenuate && CurrentVolume > 0) + SetVolume(CurrentVolume - FadeRate < 0 ? 0 : CurrentVolume - FadeRate); + if(!attenuate && !MusicFile.IsPlaying()) + Next(); +} + +void Musicplayer::LoadCurrentFile() +{ + MusicFile.Load((*CurrentFileName).c_str()); + SetVolume(CurrentVolume); + MusicFile.Play(); + CurrentPosition = 0; + MusicStopped = false; + MusicChanged = true; +} + +/* For our GUI */ +wstringEx Musicplayer::GetFileName() +{ + wstringEx CurrentFile; + string CurrentFileStr((*CurrentFileName).begin()+(*CurrentFileName).find_last_of('/')+1, + (*CurrentFileName).begin()+(*CurrentFileName).find_last_of('.')); + CurrentFile.fromUTF8(CurrentFileStr.c_str()); + return CurrentFile; +} + +bool Musicplayer::SongChanged() +{ + if(!MusicChanged) + return false; + MusicChanged = false; + return true; +} diff --git a/source/music/MusicPlayer.hpp b/source/music/MusicPlayer.hpp new file mode 100644 index 00000000..5073d276 --- /dev/null +++ b/source/music/MusicPlayer.hpp @@ -0,0 +1,68 @@ +/**************************************************************************** + * Copyright (C) 2012 FIX94 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ +#ifndef _MUSICPLAYER_HPP_ +#define _MUSICPLAYER_HPP_ + +#include +#include "gui_sound.h" +#include "config/config.hpp" +#include "wstringEx/wstringEx.hpp" + +using namespace std; + +class Musicplayer +{ +public: + void Cleanup(); + void Init(Config &cfg, string musicDir, string themeMusicDir); + void Tick(bool attenuate); + + void SetVolume(u8 volume); + void SetMaxVolume(u8 volume); + u8 GetVolume() { return CurrentVolume; }; + u8 GetMaxVolume() { return Volume; }; + + void Previous(); + void Next(); + void Stop(); + + bool IsStopped() { return MusicStopped; }; + + /* For our GUI */ + wstringEx GetFileName(); + bool SongChanged(); + time_t DisplayTime; +protected: + bool PosFromPrevFile(); + void LoadCurrentFile(); + void ScanDirectories(const char *directory); + + u8 Volume; + u8 CurrentVolume; + u8 FadeRate; + int CurrentPosition; + bool MusicStopped; + bool MusicChanged; + + GuiSound MusicFile; + vector FileNames; + vector::iterator CurrentFileName; +}; + +extern Musicplayer MusicPlayer; + +#endif /* _MUSICPLAYER_HPP_ */ diff --git a/source/music/gui_sound.cpp b/source/music/gui_sound.cpp index b7ffcc19..669fa9ad 100644 --- a/source/music/gui_sound.cpp +++ b/source/music/gui_sound.cpp @@ -28,7 +28,7 @@ #include "gui_sound.h" #include "SoundHandler.hpp" -#include "musicplayer.h" +#include "MusicPlayer.hpp" #include "WavDecoder.hpp" #include "loader/sys.h" #include "banner/AnimatedBanner.h" diff --git a/source/music/musicplayer.cpp b/source/music/musicplayer.cpp deleted file mode 100644 index c4177934..00000000 --- a/source/music/musicplayer.cpp +++ /dev/null @@ -1,179 +0,0 @@ - -#include -#include - -#include "musicplayer.h" -#include "SoundHandler.hpp" -#include "fileOps/fileOps.h" -#include "gui/text.hpp" - -MusicPlayer m_music; - -void MusicPlayer::cleanup() -{ - if(m_music_files.empty()) - return; - MusicFile.Pause(); - MusicFile.Stop(); - MusicFile.FreeMemory(); - m_music_files.clear(); - DisplayTime = 0; - m_changed = false; - m_stopped = true; -} - -void MusicPlayer::Init(Config &cfg, string musicDir, string themeMusicDir) -{ - DisplayTime = 0; - m_changed = false; - m_stopped = true; - CurrentPosition = 0; - m_fade_rate = cfg.getInt("GENERAL", "music_fade_rate", 8); - m_music_volume = cfg.getInt("GENERAL", "sound_volume_music", 255); - - SetVolume(0); - MusicFile.SetVoice(0); - m_music_files.clear(); - ScanDirectories(themeMusicDir.c_str()); - ScanDirectories(musicDir.c_str()); - - if(cfg.getBool("GENERAL", "randomize_music", true) && m_music_files.size() > 0) - { - srand(unsigned(time(NULL))); - random_shuffle(m_music_files.begin(), m_music_files.end()); - } - m_current_music = m_music_files.begin(); -} - -void MusicPlayer::ScanDirectories(const char *directory) -{ - struct dirent *pent = NULL; - DIR *pdir = opendir(directory); - while((pent = readdir(pdir)) != NULL) - { - if(strcmp(pent->d_name, ".") == 0 || strcmp(pent->d_name, "..") == 0) - continue; - string CurrentItem = sfmt("%s/%s", directory, pent->d_name); - if(fsop_DirExist(CurrentItem.c_str())) - ScanDirectories(CurrentItem.c_str()); - else if(strcasestr(pent->d_name, ".mp3") != NULL || strcasestr(pent->d_name, ".ogg") != NULL) - m_music_files.push_back(CurrentItem); - } - closedir(pdir); -} - -void MusicPlayer::SetMaxVolume(u8 volume) -{ - m_music_volume = volume; - SetVolume(volume); -} - -void MusicPlayer::SetVolume(u8 volume) -{ - m_music_current_volume = volume; - MusicFile.SetVolume(m_music_current_volume); -} - -void MusicPlayer::Previous() -{ - if(m_music_files.empty()) - return; - if(PosFromPrevFile()) - return; - if(m_current_music == m_music_files.begin()) - m_current_music = m_music_files.end(); - - m_current_music--; - - LoadCurrentFile(); -} - -void MusicPlayer::Next() -{ - if(m_music_files.empty()) - return; - if(PosFromPrevFile()) - return; - m_current_music++; - if (m_current_music == m_music_files.end()) - m_current_music = m_music_files.begin(); - - LoadCurrentFile(); -} - -void MusicPlayer::StopAndSetPos() -{ - if(m_music_files.empty()) - return; - CurrentPosition = SoundHandler::Instance()->Decoder(MusicFile.GetVoice())->Tell(); - Stop(); -} - -bool MusicPlayer::PosFromPrevFile() -{ - if(!CurrentPosition) - return false; - LoadCurrentFile(); - MusicFile.Pause(); - SoundHandler::Instance()->Decoder(MusicFile.GetVoice())->Seek(CurrentPosition); - CurrentPosition = 0; - MusicFile.Resume(); - return true; -} - -void MusicPlayer::Play() -{ - SetVolume(m_music_current_volume); - MusicFile.Play(); - m_stopped = false; -} - -void MusicPlayer::Stop() -{ - MusicFile.Pause(); - MusicFile.Stop(); - m_stopped = true; -} - -void MusicPlayer::Tick(bool attenuate) -{ - if(m_music_files.empty()) - return; - if(!attenuate && m_music_current_volume < m_music_volume) - { - SetVolume(m_music_current_volume + m_fade_rate > m_music_volume ? m_music_volume - : m_music_current_volume + m_fade_rate); - } - else if(attenuate && m_music_current_volume > 0) - { - SetVolume(m_music_current_volume - m_fade_rate < 0 ? 0 - : m_music_current_volume - m_fade_rate); - } - if(!attenuate && !MusicFile.IsPlaying()) - Next(); -} - -void MusicPlayer::LoadCurrentFile() -{ - m_changed = true; - MusicFile.Load((*m_current_music).c_str()); - Play(); -} - -/* For our GUI */ -wstringEx MusicPlayer::GetFileName() -{ - wstringEx CurrentFile; - string CurrentFileStr((*m_current_music).begin()+(*m_current_music).find_last_of('/')+1, - (*m_current_music).begin()+(*m_current_music).find_last_of('.')); - CurrentFile.fromUTF8(CurrentFileStr.c_str()); - return CurrentFile; -} - -bool MusicPlayer::SongChanged() -{ - if(!m_changed) - return false; - m_changed = false; - return true; -} diff --git a/source/music/musicplayer.h b/source/music/musicplayer.h deleted file mode 100644 index d6d52b12..00000000 --- a/source/music/musicplayer.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _MUSICPLAYER_H -#define _MUSICPLAYER_H - -#include -#include "gui_sound.h" -#include "config/config.hpp" -#include "wstringEx/wstringEx.hpp" - -using namespace std; - -class MusicPlayer -{ -public: - void cleanup(); - void Init(Config &cfg, string musicDir, string themeMusicDir); - void Tick(bool attenuate); - - void SetVolume(u8 volume); - void SetMaxVolume(u8 volume); - u8 GetVolume() { return m_music_current_volume; }; - u8 GetMaxVolume() { return m_music_volume; }; - - void Previous(); - void Next(); - void StopAndSetPos(); - - bool IsStopped() { return m_stopped; }; - - /* For our GUI */ - wstringEx GetFileName(); - bool SongChanged(); - time_t DisplayTime; -protected: - void Play(); - void Stop(); - bool PosFromPrevFile(); - void LoadCurrentFile(); - void ScanDirectories(const char *directory); - - u8 m_music_volume; - u8 m_music_current_volume; - u8 m_fade_rate; - int CurrentPosition; - bool m_stopped; - bool m_changed; - - GuiSound MusicFile; - vector m_music_files; - vector::iterator m_current_music; -}; - -extern MusicPlayer m_music; - -#endif \ No newline at end of file diff --git a/source/plugin/plugin.cpp b/source/plugin/plugin.cpp index d54cbaca..6afa005a 100644 --- a/source/plugin/plugin.cpp +++ b/source/plugin/plugin.cpp @@ -261,7 +261,7 @@ vector Plugin::CreateMplayerCEArguments(const char *filepath) while(ptr[0] != '/' || ptr[1] == '/') ptr++; - if(strncmp(DeviceHandler::PathToFSName(filepath), "NTF", 3) == 0) + if(strncmp(DeviceHandle.PathToFSName(filepath), "NTF", 3) == 0) { sprintf(dst, "ntfs:%s", ptr); } diff --git a/wiiflow.pnproj b/wiiflow.pnproj index 9d2d0721..8b6ef7ef 100644 --- a/wiiflow.pnproj +++ b/wiiflow.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/wiiflow.pnps b/wiiflow.pnps index f3871f27..eba498cf 100644 --- a/wiiflow.pnps +++ b/wiiflow.pnps @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file