Skip to content

Commit

Permalink
Qt: Cleanup game-install assistant pull request
Browse files Browse the repository at this point in the history
Use paths instead of IDs,  disable typemap.
  • Loading branch information
elad335 committed Dec 12, 2023
1 parent 60baa49 commit 7549406
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
20 changes: 9 additions & 11 deletions rpcs3/rpcs3qt/game_list_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,24 @@ private Q_SLOTS:
void Refreshed();

public:

template <typename KeyType>
struct GameIdsTable
{
// List of Game IDS an operation has been done on for the use of the slot function
std::set<QString> m_done_ids;
// List of game paths an operation has been done on for the use of the slot function
std::set<std::string> m_done_paths;
};

template <typename KeySlot, typename Func>
// Enqueue slot for refreshed signal
// Allowing for an individual container for each distinct use case (currently disabled and contains only one such entry)
template <typename KeySlot = void, typename Func>
void AddRefreshedSlot(Func&& func)
{
if (!m_refresh_funcs_manage_type.has_value())
{
m_refresh_funcs_manage_type.emplace();
}
// NOTE: Remove assert when the need for individual containers arises
static_assert(std::is_void_v<KeySlot>);

connect(this, &game_list_frame::Refreshed, this, [this, func = std::move(func)]() mutable
{
func(m_refresh_funcs_manage_type->get<GameIdsTable<KeySlot>>().m_done_ids);
func(m_refresh_funcs_manage_type->get<GameIdsTable<KeySlot>>().m_done_paths);
}, Qt::SingleShotConnection);
}

Expand Down Expand Up @@ -195,7 +194,6 @@ private Q_SLOTS:
const std::array<int, 1> m_parsing_threads{0};
QFutureWatcher<void> m_parsing_watcher;
QFutureWatcher<void> m_refresh_watcher;
usz m_refresh_counter = 0;
QSet<QString> m_hidden_list;
bool m_show_hidden{false};

Expand All @@ -213,5 +211,5 @@ private Q_SLOTS:
bool m_draw_compat_status_to_grid = false;
bool m_show_custom_icons = true;
bool m_play_hover_movies = true;
std::optional<auto_typemap<game_list_frame>> m_refresh_funcs_manage_type;
std::optional<auto_typemap<game_list_frame>> m_refresh_funcs_manage_type{std::in_place};
};
40 changes: 19 additions & 21 deletions rpcs3/rpcs3qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,27 +1095,30 @@ bool main_window::HandlePackageInstallation(QStringList file_paths, bool from_bo
bootable_paths_installed[bootable_paths[index]] = packages[index].title_id;
}

// Need to test here due to potential std::move later
const bool installed_a_whole_package_without_new_software = bootable_paths_installed.empty() && !cancelled;

if (!bootable_paths_installed.empty())
{
m_game_list_frame->AddRefreshedSlot<class KeyType>([this, paths = std::move(bootable_paths_installed)](std::set<QString>& IDs) mutable
m_game_list_frame->AddRefreshedSlot([this, paths = std::move(bootable_paths_installed)](std::set<std::string>& claimed_paths) mutable
{
// Try to claim operaions on ID
for (auto it = paths.begin(); it != paths.end();)
{
if (IDs.count(it->second))
std::string resolved_path = Emu.GetCallbacks().resolve_path(it->first);

if (resolved_path.empty() || claimed_paths.count(resolved_path))
{
it = paths.erase(it);
}
else
{
IDs.emplace(it->second);
claimed_paths.emplace(std::move(resolved_path));
it++;
}
}

ShowOptionalGamePreparations(tr("Success!"), tr("Successfully installed software from package(s)!"), std::move(paths));
ShowOptionalGamePreparations(tr("Success!"), tr("Successfully installed software from package(s)!"), paths);
});
}

Expand All @@ -1127,12 +1130,6 @@ bool main_window::HandlePackageInstallation(QStringList file_paths, bool from_bo
if (installed_a_whole_package_without_new_software)
{
m_gui_settings->ShowInfoBox(tr("Success!"), tr("Successfully installed software from package(s)!"), gui::ib_pkg_success, this);
return true;
}

if (!cancelled)
{
return true;
}
}
else
Expand Down Expand Up @@ -2406,7 +2403,7 @@ void main_window::CreateConnects()

// Only select one folder for now
paths << QFileDialog::getExistingDirectory(this, tr("Select a folder containing one or more games"), qstr(fs::get_config_dir()), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
AddGamesFromDirs(paths);
AddGamesFromDirs(std::move(paths));
});

connect(ui->bootRecentMenu, &QMenu::aboutToShow, this, [this]()
Expand Down Expand Up @@ -3500,15 +3497,15 @@ void main_window::closeEvent(QCloseEvent* closeEvent)
Add valid disc games to gamelist (games.yml)
@param paths = dir paths to scan for game
*/
void main_window::AddGamesFromDirs(const QStringList& paths)
void main_window::AddGamesFromDirs(QStringList&& paths)
{
if (paths.isEmpty())
{
return;
}

// Obtain list of previously existing entries under the specificied parent paths for comparison
std::unordered_set<std::string_view> existing;
std::unordered_set<std::string> existing;

for (const game_info& game : m_game_list_frame->GetGameInfo())
{
Expand All @@ -3530,7 +3527,7 @@ void main_window::AddGamesFromDirs(const QStringList& paths)
Emu.AddGamesFromDir(sstr(path));
}

m_game_list_frame->AddRefreshedSlot<class KeyType>([this, paths = std::move(paths), existing = std::move(existing)](std::set<QString>& IDs)
m_game_list_frame->AddRefreshedSlot([this, paths = std::move(paths), existing = std::move(existing)](std::set<std::string>& claimed_paths)
{
// Execute followup operations only for newly added entries under the specified paths
std::map<std::string, QString> paths_added; // -> title id
Expand All @@ -3543,13 +3540,14 @@ void main_window::AddGamesFromDirs(const QStringList& paths)
{
if (Emu.IsPathInsideDir(game->info.path, sstr(dir_path)))
{
// Try to claim operaion on ID
const QString title_id = qstr(game->info.serial);
// Try to claim operaion on directory path

std::string resolved_path = Emu.GetCallbacks().resolve_path(game->info.path);

if (!IDs.count(title_id))
if (!resolved_path.empty() && !claimed_paths.count(resolved_path))
{
IDs.emplace(title_id);
paths_added.emplace(game->info.path, title_id);
claimed_paths.emplace(game->info.path);
paths_added.emplace(game->info.path, qstr(game->info.serial));
}

break;
Expand All @@ -3560,7 +3558,7 @@ void main_window::AddGamesFromDirs(const QStringList& paths)

if (!paths_added.empty())
{
ShowOptionalGamePreparations(tr("Success!"), tr("Successfully added software to game list from path(s)!"), std::move(paths_added));
ShowOptionalGamePreparations(tr("Success!"), tr("Successfully added software to game list from path(s)!"), paths_added);
}
});

Expand Down Expand Up @@ -3741,7 +3739,7 @@ void main_window::dropEvent(QDropEvent* event)
}
case drop_type::drop_dir: // import valid games to gamelist (games.yaml)
{
AddGamesFromDirs(drop_paths);
AddGamesFromDirs(std::move(drop_paths));
break;
}
case drop_type::drop_game: // import valid games to gamelist (games.yaml)
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/rpcs3qt/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private Q_SLOTS:
u64 m_drop_file_timestamp = umax;
drop_type m_drop_file_cached_drop_type = drop_type::drop_error;
drop_type IsValidFile(const QMimeData& md, QStringList* drop_paths = nullptr);
void AddGamesFromDirs(const QStringList& paths);
void AddGamesFromDirs(QStringList&& paths);

QAction* CreateRecentAction(const q_string_pair& entry, const uint& sc_idx);
void BootRecentAction(const QAction* act);
Expand Down

0 comments on commit 7549406

Please sign in to comment.