Fixes #22, #16, and possibly 7: Rewrite file read function to actually pull proper files from filesystem of iso volume

This commit is contained in:
R2DLiu 2020-07-08 22:08:44 -04:00
commit e9507c7d8c
6 changed files with 27 additions and 23 deletions

View file

@ -969,6 +969,7 @@ bool SConfig::SetPathsAndGameMetadata(const BootParameters& boot)
const std::string region_dir = GetDirectoryForRegion(ToGameCubeRegion(m_region)); const std::string region_dir = GetDirectoryForRegion(ToGameCubeRegion(m_region));
m_strSRAM = File::GetUserPath(F_GCSRAM_IDX); m_strSRAM = File::GetUserPath(F_GCSRAM_IDX);
m_strBootROM = GetBootROMPath(region_dir); m_strBootROM = GetBootROMPath(region_dir);
m_strIsoPath = (boot.parameters.index() == 0) ? std::get<BootParameters::Disc>(boot.parameters).path : "";
return true; return true;
} }

View file

@ -196,6 +196,7 @@ struct SConfig
// files // files
std::string m_strBootROM; std::string m_strBootROM;
std::string m_strIsoPath;
std::string m_strSRAM; std::string m_strSRAM;
std::string m_perfDir; std::string m_perfDir;

View file

@ -32,7 +32,9 @@
#include "Core/HW/SystemTimers.h" #include "Core/HW/SystemTimers.h"
#include "Core/IOS/ES/Formats.h" #include "Core/IOS/ES/Formats.h"
#include "DiscIO/DiscExtractor.h"
#include "DiscIO/Enums.h" #include "DiscIO/Enums.h"
#include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h" #include "DiscIO/Volume.h"
namespace DVDThread namespace DVDThread
@ -393,4 +395,18 @@ static void DVDThread()
} }
} }
} }
void ReadFile(std::string& fileName, std::vector<u8>& buf) {
if (HasDisc()) {
const DiscIO::FileSystem* filesystem = s_disc->GetFileSystem(DiscIO::PARTITION_NONE);
auto fileInfo = filesystem->FindFileInfo(fileName);
auto fileSize = fileInfo->GetSize();
WaitUntilIdle();
buf.resize(fileSize);
DiscIO::ReadFile(*s_disc, DiscIO::PARTITION_NONE, fileInfo.get(), buf.data(), fileSize);
}
else {
INFO_LOG(SLIPPI, "Failed to open file: %s", fileName.c_str());
}
}
} // namespace DVDThread } // namespace DVDThread

View file

@ -7,7 +7,7 @@
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <vector> #include <vector>
#include <string>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
class PointerWrap; class PointerWrap;
@ -60,4 +60,6 @@ void StartRead(u64 dvd_offset, u32 length, const DiscIO::Partition& partition,
void StartReadToEmulatedRAM(u32 output_address, u64 dvd_offset, u32 length, void StartReadToEmulatedRAM(u32 output_address, u64 dvd_offset, u32 length,
const DiscIO::Partition& partition, DVDInterface::ReplyType reply_type, const DiscIO::Partition& partition, DVDInterface::ReplyType reply_type,
s64 ticks_until_completion); s64 ticks_until_completion);
void ReadFile(std::string& fileName, std::vector<u8>& buf);
} // namespace DVDThread } // namespace DVDThread

View file

@ -3,6 +3,7 @@
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/File.h" #include "Common/File.h"
#include "Core/HW/DVD/DVDThread.h"
#include "Core/Boot/Boot.h" #include "Core/Boot/Boot.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
@ -10,6 +11,7 @@
std::string getFilePath(std::string fileName) std::string getFilePath(std::string fileName)
{ {
std::string dirPath = File::GetSysDirectory(); std::string dirPath = File::GetSysDirectory();
std::string filePath = dirPath + "GameFiles/GALE01/" + fileName; // TODO: Handle other games? std::string filePath = dirPath + "GameFiles/GALE01/" + fileName; // TODO: Handle other games?
if (File::Exists(filePath)) if (File::Exists(filePath))
@ -26,23 +28,6 @@ std::string getFilePath(std::string fileName)
return ""; return "";
} }
// SLIPPITODO: Revisit. Modified this function a bit, unsure of functionality
void ReadFileToBuffer(std::string& fileName, std::vector<u8>& buf)
{
// Clear anything that was in the buffer
buf.clear();
// Don't do anything if a game is not running
if (Core::GetState() != Core::State::Running)
return;
File::IOFile file(fileName, "rb");
auto fileSize = file.GetSize();
buf.resize(fileSize);
size_t bytes_read;
file.ReadArray<u8>(buf.data(), std::min<u64>(file.GetSize(), buf.size()), &bytes_read);
}
u32 SlippiGameFileLoader::LoadFile(std::string fileName, std::string& data) u32 SlippiGameFileLoader::LoadFile(std::string fileName, std::string& data)
{ {
if (fileCache.count(fileName)) if (fileCache.count(fileName))
@ -64,14 +49,13 @@ u32 SlippiGameFileLoader::LoadFile(std::string fileName, std::string& data)
std::string fileContents; std::string fileContents;
File::ReadFileToString(gameFilePath, fileContents); File::ReadFileToString(gameFilePath, fileContents);
if (gameFilePath.substr(gameFilePath.length() - 5) == ".diff") // If the file was a diff file and the game is running, load the main file from ISO and apply patch
if (gameFilePath.substr(gameFilePath.length() - 5) == ".diff" && Core::GetState() == Core::State::Running)
{ {
// If the file was a diff file, load the main file from ISO and apply patch
std::vector<u8> buf; std::vector<u8> buf;
INFO_LOG(SLIPPI, "Will process diff"); INFO_LOG(SLIPPI, "Will process diff");
ReadFileToBuffer(fileName, buf); DVDThread::ReadFile(fileName, buf);
std::string diffContents = fileContents; std::string diffContents = fileContents;
decoder.Decode((char*)buf.data(), buf.size(), diffContents, &fileContents); decoder.Decode((char*)buf.data(), buf.size(), diffContents, &fileContents);
} }

View file

@ -149,7 +149,7 @@ void SlippiUser::UpdateFile()
void SlippiUser::UpdateApp() void SlippiUser::UpdateApp()
{ {
#ifdef _WIN32 #ifdef _WIN32
auto isoPath = SConfig::GetInstance().m_strBootROM; auto isoPath = SConfig::GetInstance().m_strIsoPath;
std::string path = File::GetExeDirectory() + "/dolphin-slippi-tools.exe"; std::string path = File::GetExeDirectory() + "/dolphin-slippi-tools.exe";
std::string echoMsg = "echo Starting update process. If nothing happen after a few " std::string echoMsg = "echo Starting update process. If nothing happen after a few "