CitraQt: Simplify the game list loader code
This commit is contained in:
parent
9a35d1fb4a
commit
314ce5e505
@ -114,7 +114,7 @@ int main(int argc, char **argv) {
|
||||
System::Init(emu_window.get());
|
||||
SCOPE_EXIT({ System::Shutdown(); });
|
||||
|
||||
std::unique_ptr<Loader::AppLoader> loader = Loader::GetFileLoader(boot_filename);
|
||||
std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(boot_filename);
|
||||
if (!loader) {
|
||||
LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", boot_filename.c_str());
|
||||
return -1;
|
||||
|
@ -132,30 +132,16 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, bool d
|
||||
if (deep_scan && FileUtil::IsDirectory(physical_name)) {
|
||||
AddFstEntriesToGameList(physical_name, true);
|
||||
} else {
|
||||
std::string filename_filename, filename_extension;
|
||||
Common::SplitPath(physical_name, nullptr, &filename_filename, &filename_extension);
|
||||
|
||||
Loader::FileType guessed_filetype = Loader::GuessFromExtension(filename_extension);
|
||||
if (guessed_filetype == Loader::FileType::Unknown)
|
||||
std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(physical_name);
|
||||
if (!loader)
|
||||
return true;
|
||||
Loader::FileType filetype = Loader::IdentifyFile(physical_name);
|
||||
if (filetype == Loader::FileType::Unknown) {
|
||||
LOG_WARNING(Frontend, "File %s is of indeterminate type and is possibly corrupted.", physical_name.c_str());
|
||||
return true;
|
||||
}
|
||||
if (guessed_filetype != filetype) {
|
||||
LOG_WARNING(Frontend, "Filetype and extension of file %s do not match.", physical_name.c_str());
|
||||
}
|
||||
|
||||
std::vector<u8> smdh;
|
||||
std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(FileUtil::IOFile(physical_name, "rb"), filetype, filename_filename, physical_name);
|
||||
|
||||
if (loader)
|
||||
loader->ReadIcon(smdh);
|
||||
|
||||
emit EntryReady({
|
||||
new GameListItemPath(QString::fromStdString(physical_name), smdh),
|
||||
new GameListItem(QString::fromStdString(Loader::GetFileTypeString(filetype))),
|
||||
new GameListItem(QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))),
|
||||
new GameListItemSize(FileUtil::GetSize(physical_name)),
|
||||
});
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ bool GMainWindow::InitializeSystem() {
|
||||
}
|
||||
|
||||
bool GMainWindow::LoadROM(const std::string& filename) {
|
||||
std::unique_ptr<Loader::AppLoader> app_loader = Loader::GetFileLoader(filename);
|
||||
std::unique_ptr<Loader::AppLoader> app_loader = Loader::GetLoader(filename);
|
||||
if (!app_loader) {
|
||||
LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filename.c_str());
|
||||
QMessageBox::critical(this, tr("Error while loading ROM!"),
|
||||
|
@ -91,7 +91,15 @@ const char* GetFileTypeString(FileType type) {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type,
|
||||
/**
|
||||
* Get a loader for a file with a specific type
|
||||
* @param file The file to load
|
||||
* @param type The type of the file
|
||||
* @param filename the file name (without path)
|
||||
* @param filepath the file full path (with name)
|
||||
* @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type
|
||||
*/
|
||||
static std::unique_ptr<AppLoader> GetFileLoader(FileUtil::IOFile&& file, FileType type,
|
||||
const std::string& filename, const std::string& filepath) {
|
||||
switch (type) {
|
||||
|
||||
@ -113,7 +121,7 @@ std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type,
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<AppLoader> GetFileLoader(const std::string& filename) {
|
||||
std::unique_ptr<AppLoader> GetLoader(const std::string& filename) {
|
||||
FileUtil::IOFile file(filename, "rb");
|
||||
if (!file.IsOpen()) {
|
||||
LOG_ERROR(Loader, "Failed to load file %s", filename.c_str());
|
||||
@ -134,7 +142,7 @@ std::unique_ptr<AppLoader> GetFileLoader(const std::string& filename) {
|
||||
|
||||
LOG_INFO(Loader, "Loading file %s as %s...", filename.c_str(), GetFileTypeString(type));
|
||||
|
||||
return GetLoader(std::move(file), type, filename_filename, filename);
|
||||
return GetFileLoader(std::move(file), type, filename_filename, filename);
|
||||
}
|
||||
|
||||
} // namespace Loader
|
||||
|
@ -202,21 +202,11 @@ protected:
|
||||
*/
|
||||
extern const std::initializer_list<Kernel::AddressMapping> default_address_mappings;
|
||||
|
||||
/**
|
||||
* Get a loader for a file with a specific type
|
||||
* @param file The file to load
|
||||
* @param type The type of the file
|
||||
* @param filename the file name (without path)
|
||||
* @param filepath the file full path (with name)
|
||||
* @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type
|
||||
*/
|
||||
std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type, const std::string& filename, const std::string& filepath);
|
||||
|
||||
/**
|
||||
* Identifies a bootable file and return a suitable loader
|
||||
* @param filename String filename of bootable file
|
||||
* @return best loader for this file
|
||||
*/
|
||||
std::unique_ptr<AppLoader> GetFileLoader(const std::string& filename);
|
||||
std::unique_ptr<AppLoader> GetLoader(const std::string& filename);
|
||||
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user