diff options
| author | 2016-05-18 22:06:50 +0100 | |
|---|---|---|
| committer | 2016-05-21 17:09:59 +0100 | |
| commit | 314ce5e505aca066ad4d0385be46d7e8de9f6dfb (patch) | |
| tree | e71b47815cf82006ea78b9820b5df5f99f8380b9 /src | |
| parent | Loader: Add a GetFileType method to get the type of a loaded file (diff) | |
| download | yuzu-314ce5e505aca066ad4d0385be46d7e8de9f6dfb.tar.gz yuzu-314ce5e505aca066ad4d0385be46d7e8de9f6dfb.tar.xz yuzu-314ce5e505aca066ad4d0385be46d7e8de9f6dfb.zip | |
CitraQt: Simplify the game list loader code
Diffstat (limited to 'src')
| -rw-r--r-- | src/citra/citra.cpp | 2 | ||||
| -rw-r--r-- | src/citra_qt/game_list.cpp | 22 | ||||
| -rw-r--r-- | src/citra_qt/main.cpp | 2 | ||||
| -rw-r--r-- | src/core/loader/loader.cpp | 14 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 12 |
5 files changed, 18 insertions, 34 deletions
diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp index aa3bf94ca..e01216734 100644 --- a/src/citra/citra.cpp +++ b/src/citra/citra.cpp | |||
| @@ -114,7 +114,7 @@ int main(int argc, char **argv) { | |||
| 114 | System::Init(emu_window.get()); | 114 | System::Init(emu_window.get()); |
| 115 | SCOPE_EXIT({ System::Shutdown(); }); | 115 | SCOPE_EXIT({ System::Shutdown(); }); |
| 116 | 116 | ||
| 117 | std::unique_ptr<Loader::AppLoader> loader = Loader::GetFileLoader(boot_filename); | 117 | std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(boot_filename); |
| 118 | if (!loader) { | 118 | if (!loader) { |
| 119 | LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", boot_filename.c_str()); | 119 | LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", boot_filename.c_str()); |
| 120 | return -1; | 120 | return -1; |
diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index d4ac9c96e..570647539 100644 --- a/src/citra_qt/game_list.cpp +++ b/src/citra_qt/game_list.cpp | |||
| @@ -132,30 +132,16 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, bool d | |||
| 132 | if (deep_scan && FileUtil::IsDirectory(physical_name)) { | 132 | if (deep_scan && FileUtil::IsDirectory(physical_name)) { |
| 133 | AddFstEntriesToGameList(physical_name, true); | 133 | AddFstEntriesToGameList(physical_name, true); |
| 134 | } else { | 134 | } else { |
| 135 | std::string filename_filename, filename_extension; | 135 | std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(physical_name); |
| 136 | Common::SplitPath(physical_name, nullptr, &filename_filename, &filename_extension); | 136 | if (!loader) |
| 137 | |||
| 138 | Loader::FileType guessed_filetype = Loader::GuessFromExtension(filename_extension); | ||
| 139 | if (guessed_filetype == Loader::FileType::Unknown) | ||
| 140 | return true; | ||
| 141 | Loader::FileType filetype = Loader::IdentifyFile(physical_name); | ||
| 142 | if (filetype == Loader::FileType::Unknown) { | ||
| 143 | LOG_WARNING(Frontend, "File %s is of indeterminate type and is possibly corrupted.", physical_name.c_str()); | ||
| 144 | return true; | 137 | return true; |
| 145 | } | ||
| 146 | if (guessed_filetype != filetype) { | ||
| 147 | LOG_WARNING(Frontend, "Filetype and extension of file %s do not match.", physical_name.c_str()); | ||
| 148 | } | ||
| 149 | 138 | ||
| 150 | std::vector<u8> smdh; | 139 | std::vector<u8> smdh; |
| 151 | std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(FileUtil::IOFile(physical_name, "rb"), filetype, filename_filename, physical_name); | 140 | loader->ReadIcon(smdh); |
| 152 | |||
| 153 | if (loader) | ||
| 154 | loader->ReadIcon(smdh); | ||
| 155 | 141 | ||
| 156 | emit EntryReady({ | 142 | emit EntryReady({ |
| 157 | new GameListItemPath(QString::fromStdString(physical_name), smdh), | 143 | new GameListItemPath(QString::fromStdString(physical_name), smdh), |
| 158 | new GameListItem(QString::fromStdString(Loader::GetFileTypeString(filetype))), | 144 | new GameListItem(QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))), |
| 159 | new GameListItemSize(FileUtil::GetSize(physical_name)), | 145 | new GameListItemSize(FileUtil::GetSize(physical_name)), |
| 160 | }); | 146 | }); |
| 161 | } | 147 | } |
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 9d47014aa..6239160bc 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp | |||
| @@ -272,7 +272,7 @@ bool GMainWindow::InitializeSystem() { | |||
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | bool GMainWindow::LoadROM(const std::string& filename) { | 274 | bool GMainWindow::LoadROM(const std::string& filename) { |
| 275 | std::unique_ptr<Loader::AppLoader> app_loader = Loader::GetFileLoader(filename); | 275 | std::unique_ptr<Loader::AppLoader> app_loader = Loader::GetLoader(filename); |
| 276 | if (!app_loader) { | 276 | if (!app_loader) { |
| 277 | LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filename.c_str()); | 277 | LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filename.c_str()); |
| 278 | QMessageBox::critical(this, tr("Error while loading ROM!"), | 278 | QMessageBox::critical(this, tr("Error while loading ROM!"), |
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index c82688026..9719d30d5 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -91,7 +91,15 @@ const char* GetFileTypeString(FileType type) { | |||
| 91 | return "unknown"; | 91 | return "unknown"; |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type, | 94 | /** |
| 95 | * Get a loader for a file with a specific type | ||
| 96 | * @param file The file to load | ||
| 97 | * @param type The type of the file | ||
| 98 | * @param filename the file name (without path) | ||
| 99 | * @param filepath the file full path (with name) | ||
| 100 | * @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type | ||
| 101 | */ | ||
| 102 | static std::unique_ptr<AppLoader> GetFileLoader(FileUtil::IOFile&& file, FileType type, | ||
| 95 | const std::string& filename, const std::string& filepath) { | 103 | const std::string& filename, const std::string& filepath) { |
| 96 | switch (type) { | 104 | switch (type) { |
| 97 | 105 | ||
| @@ -113,7 +121,7 @@ std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type, | |||
| 113 | } | 121 | } |
| 114 | } | 122 | } |
| 115 | 123 | ||
| 116 | std::unique_ptr<AppLoader> GetFileLoader(const std::string& filename) { | 124 | std::unique_ptr<AppLoader> GetLoader(const std::string& filename) { |
| 117 | FileUtil::IOFile file(filename, "rb"); | 125 | FileUtil::IOFile file(filename, "rb"); |
| 118 | if (!file.IsOpen()) { | 126 | if (!file.IsOpen()) { |
| 119 | LOG_ERROR(Loader, "Failed to load file %s", filename.c_str()); | 127 | LOG_ERROR(Loader, "Failed to load file %s", filename.c_str()); |
| @@ -134,7 +142,7 @@ std::unique_ptr<AppLoader> GetFileLoader(const std::string& filename) { | |||
| 134 | 142 | ||
| 135 | LOG_INFO(Loader, "Loading file %s as %s...", filename.c_str(), GetFileTypeString(type)); | 143 | LOG_INFO(Loader, "Loading file %s as %s...", filename.c_str(), GetFileTypeString(type)); |
| 136 | 144 | ||
| 137 | return GetLoader(std::move(file), type, filename_filename, filename); | 145 | return GetFileLoader(std::move(file), type, filename_filename, filename); |
| 138 | } | 146 | } |
| 139 | 147 | ||
| 140 | } // namespace Loader | 148 | } // namespace Loader |
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 08bab84e5..39aedfeeb 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -203,20 +203,10 @@ protected: | |||
| 203 | extern const std::initializer_list<Kernel::AddressMapping> default_address_mappings; | 203 | extern const std::initializer_list<Kernel::AddressMapping> default_address_mappings; |
| 204 | 204 | ||
| 205 | /** | 205 | /** |
| 206 | * Get a loader for a file with a specific type | ||
| 207 | * @param file The file to load | ||
| 208 | * @param type The type of the file | ||
| 209 | * @param filename the file name (without path) | ||
| 210 | * @param filepath the file full path (with name) | ||
| 211 | * @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type | ||
| 212 | */ | ||
| 213 | std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type, const std::string& filename, const std::string& filepath); | ||
| 214 | |||
| 215 | /** | ||
| 216 | * Identifies a bootable file and return a suitable loader | 206 | * Identifies a bootable file and return a suitable loader |
| 217 | * @param filename String filename of bootable file | 207 | * @param filename String filename of bootable file |
| 218 | * @return best loader for this file | 208 | * @return best loader for this file |
| 219 | */ | 209 | */ |
| 220 | std::unique_ptr<AppLoader> GetFileLoader(const std::string& filename); | 210 | std::unique_ptr<AppLoader> GetLoader(const std::string& filename); |
| 221 | 211 | ||
| 222 | } // namespace | 212 | } // namespace |