2018-09-19 16:45:57 +00:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
2018-09-09 23:09:37 +00:00
|
|
|
#include "citra_qt/compatibility_list.h"
|
2018-09-19 16:45:57 +00:00
|
|
|
#include "citra_qt/game_list.h"
|
|
|
|
#include "citra_qt/game_list_p.h"
|
|
|
|
#include "citra_qt/game_list_worker.h"
|
2019-08-15 04:38:54 +00:00
|
|
|
#include "citra_qt/uisettings.h"
|
2018-09-19 16:45:57 +00:00
|
|
|
#include "common/common_paths.h"
|
|
|
|
#include "common/file_util.h"
|
|
|
|
#include "core/hle/service/am/am.h"
|
|
|
|
#include "core/hle/service/fs/archive.h"
|
|
|
|
#include "core/loader/loader.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
bool HasSupportedFileExtension(const std::string& file_name) {
|
|
|
|
const QFileInfo file = QFileInfo(QString::fromStdString(file_name));
|
|
|
|
return GameList::supported_file_extensions.contains(file.suffix(), Qt::CaseInsensitive);
|
|
|
|
}
|
|
|
|
} // Anonymous namespace
|
|
|
|
|
2019-09-22 15:27:01 +00:00
|
|
|
GameListWorker::GameListWorker(QVector<UISettings::GameDir>& game_dirs,
|
2018-09-09 23:09:37 +00:00
|
|
|
const CompatibilityList& compatibility_list)
|
2018-09-19 16:45:57 +00:00
|
|
|
: game_dirs(game_dirs), compatibility_list(compatibility_list) {}
|
|
|
|
|
|
|
|
GameListWorker::~GameListWorker() = default;
|
|
|
|
|
|
|
|
void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion,
|
|
|
|
GameListDir* parent_dir) {
|
|
|
|
const auto callback = [this, recursion, parent_dir](u64* num_entries_out,
|
|
|
|
const std::string& directory,
|
|
|
|
const std::string& virtual_name) -> bool {
|
2018-12-07 15:53:15 +00:00
|
|
|
if (stop_processing) {
|
|
|
|
// Breaks the callback loop.
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-19 16:45:57 +00:00
|
|
|
|
2018-12-07 15:53:15 +00:00
|
|
|
const std::string physical_name = directory + DIR_SEP + virtual_name;
|
|
|
|
const bool is_dir = FileUtil::IsDirectory(physical_name);
|
2018-09-19 16:45:57 +00:00
|
|
|
if (!is_dir && HasSupportedFileExtension(physical_name)) {
|
|
|
|
std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(physical_name);
|
2020-03-15 17:42:53 +00:00
|
|
|
if (!loader) {
|
2018-09-19 16:45:57 +00:00
|
|
|
return true;
|
2020-03-15 16:54:13 +00:00
|
|
|
}
|
2018-09-19 16:45:57 +00:00
|
|
|
|
2019-09-07 08:52:18 +00:00
|
|
|
bool executable = false;
|
2020-03-15 17:42:53 +00:00
|
|
|
auto res = loader->IsExecutable(executable);
|
|
|
|
if (!executable && res != Loader::ResultStatus::ErrorEncrypted) {
|
2019-09-07 08:52:18 +00:00
|
|
|
return true;
|
2020-03-15 16:54:13 +00:00
|
|
|
}
|
2019-09-07 08:52:18 +00:00
|
|
|
|
2018-09-19 16:45:57 +00:00
|
|
|
u64 program_id = 0;
|
|
|
|
loader->ReadProgramId(program_id);
|
|
|
|
|
|
|
|
u64 extdata_id = 0;
|
|
|
|
loader->ReadExtdataId(extdata_id);
|
|
|
|
|
2019-12-19 03:51:06 +00:00
|
|
|
std::vector<u8> smdh;
|
|
|
|
// Look for an update icon if available
|
|
|
|
if (!(program_id & ~0x00040000FFFFFFFF)) {
|
2018-09-19 16:45:57 +00:00
|
|
|
std::string update_path = Service::AM::GetTitleContentPath(
|
2019-12-19 03:51:06 +00:00
|
|
|
Service::FS::MediaType::SDMC, program_id | 0x0000000E00000000);
|
|
|
|
if (FileUtil::Exists(update_path)) {
|
|
|
|
std::unique_ptr<Loader::AppLoader> update_loader =
|
|
|
|
Loader::GetLoader(update_path);
|
|
|
|
if (update_loader) {
|
|
|
|
update_loader->ReadIcon(smdh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-19 16:45:57 +00:00
|
|
|
|
2019-12-19 03:51:06 +00:00
|
|
|
if (!Loader::IsValidSMDH(smdh)) {
|
|
|
|
// Read the original smdh if there is no valid update smdh
|
|
|
|
loader->ReadIcon(smdh);
|
|
|
|
}
|
2018-09-19 16:45:57 +00:00
|
|
|
|
|
|
|
if (!Loader::IsValidSMDH(smdh) && UISettings::values.game_list_hide_no_icon) {
|
|
|
|
// Skip this invalid entry
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto it = FindMatchingCompatibilityEntry(compatibility_list, program_id);
|
|
|
|
|
|
|
|
// The game list uses this as compatibility number for untested games
|
2019-11-09 01:46:23 +00:00
|
|
|
QString compatibility(QStringLiteral("99"));
|
2018-09-19 16:45:57 +00:00
|
|
|
if (it != compatibility_list.end())
|
|
|
|
compatibility = it->second.first;
|
|
|
|
|
|
|
|
emit EntryReady(
|
|
|
|
{
|
|
|
|
new GameListItemPath(QString::fromStdString(physical_name), smdh, program_id,
|
|
|
|
extdata_id),
|
|
|
|
new GameListItemCompat(compatibility),
|
|
|
|
new GameListItemRegion(smdh),
|
|
|
|
new GameListItem(
|
|
|
|
QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))),
|
|
|
|
new GameListItemSize(FileUtil::GetSize(physical_name)),
|
|
|
|
},
|
|
|
|
parent_dir);
|
|
|
|
|
|
|
|
} else if (is_dir && recursion > 0) {
|
|
|
|
watch_list.append(QString::fromStdString(physical_name));
|
|
|
|
AddFstEntriesToGameList(physical_name, recursion - 1, parent_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
FileUtil::ForeachDirectoryEntry(nullptr, dir_path, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameListWorker::run() {
|
|
|
|
stop_processing = false;
|
|
|
|
for (UISettings::GameDir& game_dir : game_dirs) {
|
2019-11-09 01:46:23 +00:00
|
|
|
if (game_dir.path == QStringLiteral("INSTALLED")) {
|
2019-02-09 00:04:05 +00:00
|
|
|
QString games_path =
|
2018-09-19 16:45:57 +00:00
|
|
|
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)) +
|
2020-02-11 12:12:09 +00:00
|
|
|
QStringLiteral("Nintendo "
|
|
|
|
"3DS/00000000000000000000000000000000/"
|
|
|
|
"00000000000000000000000000000000/title/00040000");
|
2019-02-09 00:04:05 +00:00
|
|
|
QString demos_path =
|
|
|
|
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)) +
|
2020-02-11 12:12:09 +00:00
|
|
|
QStringLiteral(
|
|
|
|
"Nintendo "
|
|
|
|
"3DS/00000000000000000000000000000000/00000000000000000000000000000000/title/"
|
|
|
|
"00040002");
|
2019-02-09 00:04:05 +00:00
|
|
|
watch_list.append(games_path);
|
|
|
|
watch_list.append(demos_path);
|
2019-09-22 15:27:01 +00:00
|
|
|
auto* const game_list_dir = new GameListDir(game_dir, GameListItemType::InstalledDir);
|
2019-11-02 17:55:08 +00:00
|
|
|
emit DirEntryReady(game_list_dir);
|
2019-02-09 00:04:05 +00:00
|
|
|
AddFstEntriesToGameList(games_path.toStdString(), 2, game_list_dir);
|
|
|
|
AddFstEntriesToGameList(demos_path.toStdString(), 2, game_list_dir);
|
2019-11-09 01:46:23 +00:00
|
|
|
} else if (game_dir.path == QStringLiteral("SYSTEM")) {
|
2018-09-19 16:45:57 +00:00
|
|
|
QString path =
|
|
|
|
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)) +
|
2020-02-11 12:12:09 +00:00
|
|
|
QStringLiteral("00000000000000000000000000000000/title/00040010");
|
2018-09-19 16:45:57 +00:00
|
|
|
watch_list.append(path);
|
2019-09-22 15:27:01 +00:00
|
|
|
auto* const game_list_dir = new GameListDir(game_dir, GameListItemType::SystemDir);
|
2019-11-02 17:55:08 +00:00
|
|
|
emit DirEntryReady(game_list_dir);
|
2018-09-19 16:45:57 +00:00
|
|
|
AddFstEntriesToGameList(path.toStdString(), 2, game_list_dir);
|
|
|
|
} else {
|
|
|
|
watch_list.append(game_dir.path);
|
2019-09-22 15:27:01 +00:00
|
|
|
auto* const game_list_dir = new GameListDir(game_dir);
|
2019-11-02 17:55:08 +00:00
|
|
|
emit DirEntryReady(game_list_dir);
|
2018-09-19 16:45:57 +00:00
|
|
|
AddFstEntriesToGameList(game_dir.path.toStdString(), game_dir.deep_scan ? 256 : 0,
|
|
|
|
game_list_dir);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
emit Finished(watch_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameListWorker::Cancel() {
|
|
|
|
this->disconnect();
|
|
|
|
stop_processing = true;
|
|
|
|
}
|