-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
}
bool mount_usb = false;
void DeviceHandler::SetMountUSB(bool using_usb)
{
mount_usb = using_usb;
@ -57,7 +56,6 @@ void DeviceHandler::SetMountUSB(bool using_usb)
void DeviceHandler::MountAll()
{
MountSD();
if(!Sys_DolphinMode() && mount_usb)
MountAllUSB();
}
@ -147,6 +145,9 @@ bool DeviceHandler::MountUSB(int pos)
bool DeviceHandler::MountAllUSB()
{
if(!mount_usb)
return false;
/* Kill possible USB thread */
KillUSBKeepAliveThread();
/* Wait for our slowass HDD */

View File

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

View File

@ -1,27 +1,6 @@
#include "cache.hpp"
CCache::CCache(dir_discHdr &tmp, string path, u32 index, CMode mode) /* Load/Save One */
{
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 */
CCache::CCache(vector<dir_discHdr> &list, string path, CMode mode)
{
filename = path;
//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()
{
//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);
}
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)
{
if(!cache) return;
@ -116,33 +51,10 @@ void CCache::LoadAll(vector<dir_discHdr> &list)
list.reserve(count + list.size());
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);
}
}
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"
using namespace std;
const char io[4][5] = {
const char io[2][3] = {
"wb",
"rb",
"ab",
"wb",
};
enum CMode
{
SAVE,
LOAD,
ADD,
REMOVE
};
class CCache
{
public:
CCache(dir_discHdr &tmp, string path, u32 index, CMode mode); /* Load/Save One */
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(vector<dir_discHdr> &list, string path, CMode mode);
~CCache();
private:
void SaveAll(vector<dir_discHdr> list);
void SaveOne(dir_discHdr tmp, u32 index);
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;
string filename;

View File

@ -1,6 +1,7 @@
#include <ogc/system.h>
#include <unistd.h>
#include <sys/stat.h>
#include "const_str.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
/* mount Devices */
DeviceHandle.SetMountUSB(isUsingUSB());
DeviceHandle.MountAll();
DeviceHandle.MountSD();// mount SD before calling isUsingUSB() duh!
DeviceHandle.SetMountUSB(isUsingUSB() && !Sys_DolphinMode());
DeviceHandle.MountAllUSB();// only mounts any USB if isUsingUSB()
/* init wait images and show wait animation */
m_vid.setCustomWaitImgs(wait_dir, wait_loop);