-fixed sd only the correct way. now it really does work.

-shrunk the list cache code.
This commit is contained in:
fledge68 2018-07-15 20:23:32 +00:00
parent 66c17c023c
commit db2abf7669
6 changed files with 16 additions and 112 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 MiB

After

Width:  |  Height:  |  Size: 3.3 MiB

View File

@ -48,7 +48,6 @@ void DeviceHandler::Init()
OGC_Device.Init();// used for Devolution gamecube iso launcher OGC_Device.Init();// used for Devolution gamecube iso launcher
} }
bool mount_usb = false;
void DeviceHandler::SetMountUSB(bool using_usb) void DeviceHandler::SetMountUSB(bool using_usb)
{ {
mount_usb = using_usb; mount_usb = using_usb;
@ -57,8 +56,7 @@ void DeviceHandler::SetMountUSB(bool using_usb)
void DeviceHandler::MountAll() void DeviceHandler::MountAll()
{ {
MountSD(); MountSD();
if(!Sys_DolphinMode() && mount_usb) MountAllUSB();
MountAllUSB();
} }
void DeviceHandler::UnMountAll() void DeviceHandler::UnMountAll()
@ -147,6 +145,9 @@ bool DeviceHandler::MountUSB(int pos)
bool DeviceHandler::MountAllUSB() bool DeviceHandler::MountAllUSB()
{ {
if(!mount_usb)
return false;
/* Kill possible USB thread */ /* Kill possible USB thread */
KillUSBKeepAliveThread(); KillUSBKeepAliveThread();
/* Wait for our slowass HDD */ /* Wait for our slowass HDD */

View File

@ -104,6 +104,7 @@ public:
void UnMountDevolution(); void UnMountDevolution();
private: private:
bool MountUSB(int part); bool MountUSB(int part);
bool mount_usb;
PartitionHandle sd; PartitionHandle sd;
PartitionHandle usb; PartitionHandle usb;

View File

@ -1,27 +1,6 @@
#include "cache.hpp" #include "cache.hpp"
CCache::CCache(dir_discHdr &tmp, string path, u32 index, CMode mode) /* Load/Save One */ CCache::CCache(vector<dir_discHdr> &list, string path, CMode mode)
{
filename = path;
//gprintf("Openning DB: %s\n", filename.c_str());
cache = fopen(filename.c_str(), io[mode]);
if(!cache) return;
switch(mode)
{
case LOAD:
LoadOne(tmp, index);
break;
case SAVE:
SaveOne(tmp, index);
break;
default:
return;
}
}
CCache::CCache(vector<dir_discHdr> &list, string path , CMode mode) /* Load/Save All */
{ {
filename = path; filename = path;
//gprintf("Opening DB: %s\n", filename.c_str()); //gprintf("Opening DB: %s\n", filename.c_str());
@ -42,42 +21,6 @@ CCache::CCache(vector<dir_discHdr> &list, string path , CMode mode) /* Load/Save
} }
} }
CCache::CCache(vector<dir_discHdr> &list, string path, dir_discHdr tmp, CMode mode) /* Add One */
{
filename = path;
//gprintf("Openning DB: %s\n", filename.c_str());
cache = fopen(filename.c_str(), io[mode]);
if(!cache) return;
switch(mode)
{
case ADD:
AddOne(list, tmp);
break;
default:
return;
}
}
CCache::CCache(vector<dir_discHdr> &list, string path, u32 index, CMode mode) /* Remove One */
{
filename = path;
//gprintf("Openning DB: %s\n", filename.c_str());
cache = fopen(filename.c_str(), io[mode]);
if(!cache) return;
switch(mode)
{
case REMOVE:
RemoveOne(list, index);
break;
default:
return;
}
}
CCache::~CCache() CCache::~CCache()
{ {
//gprintf("Closing DB: %s\n", filename.c_str()); //gprintf("Closing DB: %s\n", filename.c_str());
@ -92,14 +35,6 @@ void CCache::SaveAll(vector<dir_discHdr> list)
fwrite((void *)&list[0], 1, list.size() * sizeof(dir_discHdr), cache); fwrite((void *)&list[0], 1, list.size() * sizeof(dir_discHdr), cache);
} }
void CCache::SaveOne(dir_discHdr tmp, u32 index)
{
//gprintf("Updating Item number %u in DB: %s\n", index, filename.c_str());
if(!cache) return;
fseek(cache, index * sizeof(dir_discHdr), SEEK_SET);
fwrite((void *)&tmp, 1, sizeof(dir_discHdr), cache);
}
void CCache::LoadAll(vector<dir_discHdr> &list) void CCache::LoadAll(vector<dir_discHdr> &list)
{ {
if(!cache) return; if(!cache) return;
@ -116,33 +51,10 @@ void CCache::LoadAll(vector<dir_discHdr> &list)
list.reserve(count + list.size()); list.reserve(count + list.size());
for(u32 i = 0; i < count; i++) for(u32 i = 0; i < count; i++)
{ {
LoadOne(tmp, i); //gprintf("Fetching Item number %u in DB: %s\n", index, filename.c_str());
fseek(cache, i * sizeof(dir_discHdr), SEEK_SET);
fread((void *)&tmp, 1, sizeof(dir_discHdr), cache);
//gprintf("Path %s\n", tmp.path);
list.push_back(tmp); list.push_back(tmp);
} }
} }
void CCache::LoadOne(dir_discHdr &tmp, u32 index)
{
if(!cache) return;
//gprintf("Fetching Item number %u in DB: %s\n", index, filename.c_str());
fseek(cache, index * sizeof(dir_discHdr), SEEK_SET);
fread((void *)&tmp, 1, sizeof(dir_discHdr), cache);
//gprintf("Path %s\n", tmp.path);
}
void CCache::AddOne(vector<dir_discHdr> &list, dir_discHdr tmp)
{
//gprintf("Adding Item number %u in DB: %s\n", list.size()+1, filename.c_str());
list.push_back(tmp);
if(!cache) return;
fwrite((void *)&tmp, 1, sizeof(dir_discHdr), cache); // FILE* is opened as "ab+" so its always written to the EOF.
}
void CCache::RemoveOne(vector<dir_discHdr> &list, u32 index)
{
//gprintf("Removing Item number %u in DB: %s\n", index, filename.c_str());
list.erase(list.begin() + index);
SaveAll(list);
}

View File

@ -10,37 +10,25 @@
//#include "gecko.hpp" //#include "gecko.hpp"
using namespace std; using namespace std;
const char io[4][5] = { const char io[2][3] = {
"wb", "wb",
"rb", "rb",
"ab",
"wb",
}; };
enum CMode enum CMode
{ {
SAVE, SAVE,
LOAD, LOAD,
ADD,
REMOVE
}; };
class CCache class CCache
{ {
public: public:
CCache(dir_discHdr &tmp, string path, u32 index, CMode mode); /* Load/Save One */ CCache(vector<dir_discHdr> &list, string path, CMode mode);
CCache(vector<dir_discHdr> &list, string path, CMode mode); /* Load/Save All */
CCache(vector<dir_discHdr> &list, string path, dir_discHdr tmp, CMode mode); /* Add One */
CCache(vector<dir_discHdr> &list, string path, u32 index, CMode mode); /* Remove One */
~CCache(); ~CCache();
private: private:
void SaveAll(vector<dir_discHdr> list); void SaveAll(vector<dir_discHdr> list);
void SaveOne(dir_discHdr tmp, u32 index);
void LoadAll(vector<dir_discHdr> &list); void LoadAll(vector<dir_discHdr> &list);
void LoadOne(dir_discHdr &tmp, u32 index);
void AddOne(vector<dir_discHdr> &list, dir_discHdr tmp);
void RemoveOne(vector<dir_discHdr> &list, u32 index);
FILE *cache; FILE *cache;
string filename; string filename;

View File

@ -1,6 +1,7 @@
#include <ogc/system.h> #include <ogc/system.h>
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h>
#include "const_str.hpp" #include "const_str.hpp"
#include "booter/external_booter.hpp" #include "booter/external_booter.hpp"
@ -157,8 +158,9 @@ int main(int argc, char **argv)
Sys_ExitTo(EXIT_TO_HBC);// set exit to in case of failed launch Sys_ExitTo(EXIT_TO_HBC);// set exit to in case of failed launch
/* mount Devices */ /* mount Devices */
DeviceHandle.SetMountUSB(isUsingUSB()); DeviceHandle.MountSD();// mount SD before calling isUsingUSB() duh!
DeviceHandle.MountAll(); DeviceHandle.SetMountUSB(isUsingUSB() && !Sys_DolphinMode());
DeviceHandle.MountAllUSB();// only mounts any USB if isUsingUSB()
/* init wait images and show wait animation */ /* init wait images and show wait animation */
m_vid.setCustomWaitImgs(wait_dir, wait_loop); m_vid.setCustomWaitImgs(wait_dir, wait_loop);