mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-27 00:00:07 -06:00
ensure the indexes are sane
This commit is contained in:
@ -177,8 +177,47 @@ void FATStorage::LoadIndex()
|
|||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
// TODO: ensure the indexes are sane
|
// ensure the indexes are sane
|
||||||
// ie. ensure that we don't have files existing in inexistant directories
|
|
||||||
|
std::vector<std::string> removelist;
|
||||||
|
|
||||||
|
for (const auto& [key, val] : DirIndex)
|
||||||
|
{
|
||||||
|
std::string path = val.Path;
|
||||||
|
int sep = path.rfind('/');
|
||||||
|
if (sep == std::string::npos) continue;
|
||||||
|
|
||||||
|
path = path.substr(0, sep);
|
||||||
|
if (DirIndex.count(path) < 1)
|
||||||
|
{
|
||||||
|
removelist.push_back(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& key : removelist)
|
||||||
|
{
|
||||||
|
DirIndex.erase(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
removelist.clear();
|
||||||
|
|
||||||
|
for (const auto& [key, val] : FileIndex)
|
||||||
|
{
|
||||||
|
std::string path = val.Path;
|
||||||
|
int sep = path.rfind('/');
|
||||||
|
if (sep == std::string::npos) continue;
|
||||||
|
|
||||||
|
path = path.substr(0, sep);
|
||||||
|
if (DirIndex.count(path) < 1)
|
||||||
|
{
|
||||||
|
removelist.push_back(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& key : removelist)
|
||||||
|
{
|
||||||
|
FileIndex.erase(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FATStorage::SaveIndex()
|
void FATStorage::SaveIndex()
|
||||||
@ -504,7 +543,8 @@ bool FATStorage::BuildSubdirectory(const char* sourcedir, const char* path, int
|
|||||||
ientry.IsReadOnly = readonly;
|
ientry.IsReadOnly = readonly;
|
||||||
|
|
||||||
innerpath = "0:/" + innerpath;
|
innerpath = "0:/" + innerpath;
|
||||||
if (f_mkdir(innerpath.c_str()) == FR_OK)
|
FRESULT res = f_mkdir(innerpath.c_str());
|
||||||
|
if (res == FR_OK)
|
||||||
{
|
{
|
||||||
DirIndex[ientry.Path] = ientry;
|
DirIndex[ientry.Path] = ientry;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user