fix more bugs in the DLDI machine

This commit is contained in:
Arisotura
2021-10-29 01:33:37 +02:00
parent cca5615748
commit 635a47014f
2 changed files with 10 additions and 11 deletions

View File

@ -497,11 +497,15 @@ bool FATStorage::DeleteHostDirectory(std::string path, std::string outbase, int
{ {
if (level >= 32) return false; if (level >= 32) return false;
fs::path dirpath = fs::u8path(outbase + "/" + path);
if (!fs::is_directory(dirpath))
return true; // already deleted? oh well
std::vector<std::string> filedeletelist; std::vector<std::string> filedeletelist;
std::vector<std::string> dirdeletelist; std::vector<std::string> dirdeletelist;
int outlen = outbase.length(); int outlen = outbase.length();
for (auto& entry : fs::directory_iterator(outbase + "/" + path)) for (auto& entry : fs::directory_iterator(dirpath))
{ {
std::string fullpath = entry.path().string(); std::string fullpath = entry.path().string();
std::string innerpath = fullpath.substr(outlen); std::string innerpath = fullpath.substr(outlen);
@ -697,12 +701,8 @@ bool FATStorage::DeleteDirectory(std::string path, int level)
for (auto& entry : subdirlist) for (auto& entry : subdirlist)
{ {
if (!DeleteDirectory(entry+"/", level+1)) return false; if (!DeleteDirectory(entry+"/", level+1))
return false;
std::string fullpath = "0:/" + entry;
f_chmod(fullpath.c_str(), 0, AM_RDO);
res = f_unlink(fullpath.c_str());
if (res != FR_OK) return false;
} }
res = f_unlink(fullpath.c_str()); res = f_unlink(fullpath.c_str());
@ -916,7 +916,7 @@ bool FATStorage::ImportDirectory(std::string sourcedir)
return true; return true;
} }
u64 FATStorage::GetDirectorySize(std::string sourcedir) u64 FATStorage::GetDirectorySize(fs::path sourcedir)
{ {
u64 ret = 0; u64 ret = 0;
u32 csize = 0x1000; // this is an estimate u32 csize = 0x1000; // this is an estimate
@ -987,7 +987,6 @@ bool FATStorage::Load(std::string filename, u64 size, std::string sourcedir)
{ {
melon_fseek(FF_File, 0, SEEK_END); melon_fseek(FF_File, 0, SEEK_END);
FileSize = melon_ftell(FF_File); FileSize = melon_ftell(FF_File);
printf("FILESIZE DETERMINED TO BE %016llX (%d) (%d)\n", FileSize, sizeof(long), errno);
} }
} }
@ -1022,7 +1021,7 @@ bool FATStorage::Load(std::string filename, u64 size, std::string sourcedir)
{ {
if (hasdir) if (hasdir)
{ {
FileSize = GetDirectorySize(sourcedir); FileSize = GetDirectorySize(fs::u8path(sourcedir));
FileSize += 0x8000000ULL; // 128MB leeway FileSize += 0x8000000ULL; // 128MB leeway
// make it a power of two // make it a power of two

View File

@ -72,7 +72,7 @@ private:
void CleanupDirectory(std::string sourcedir, std::string path, int level); void CleanupDirectory(std::string sourcedir, std::string path, int level);
bool ImportFile(std::string path, std::filesystem::path in); bool ImportFile(std::string path, std::filesystem::path in);
bool ImportDirectory(std::string sourcedir); bool ImportDirectory(std::string sourcedir);
u64 GetDirectorySize(std::string sourcedir); u64 GetDirectorySize(std::filesystem::path sourcedir);
bool Load(std::string filename, u64 size, std::string sourcedir); bool Load(std::string filename, u64 size, std::string sourcedir);
bool Save(); bool Save();