drag and dropperinno (#3037)

This commit is contained in:
Megamouse 2017-08-06 21:29:28 +02:00 committed by Ivan
parent 7b27a8e993
commit f3ad922a8f
6 changed files with 282 additions and 42 deletions

View File

@ -229,7 +229,7 @@ void Emulator::SetPath(const std::string& path, const std::string& elf_path)
m_elf_path = elf_path; m_elf_path = elf_path;
} }
bool Emulator::BootGame(const std::string& path, bool direct) bool Emulator::BootGame(const std::string& path, bool direct, bool add_only)
{ {
static const char* boot_list[] = static const char* boot_list[] =
{ {
@ -242,7 +242,7 @@ bool Emulator::BootGame(const std::string& path, bool direct)
if (direct && fs::is_file(path)) if (direct && fs::is_file(path))
{ {
SetPath(path); SetPath(path);
Load(); Load(add_only);
return true; return true;
} }
@ -254,7 +254,7 @@ bool Emulator::BootGame(const std::string& path, bool direct)
if (fs::is_file(elf)) if (fs::is_file(elf))
{ {
SetPath(elf); SetPath(elf);
Load(); Load(add_only);
return true; return true;
} }
@ -279,7 +279,7 @@ std::string Emulator::GetLibDir()
return fmt::replace_all(g_cfg.vfs.dev_flash, "$(EmulatorDir)", emu_dir) + "sys/external/"; return fmt::replace_all(g_cfg.vfs.dev_flash, "$(EmulatorDir)", emu_dir) + "sys/external/";
} }
void Emulator::Load() void Emulator::Load(bool add_only)
{ {
Stop(); Stop();
@ -442,6 +442,12 @@ void Emulator::Load()
return; return;
} }
if (add_only)
{
LOG_NOTICE(LOADER, "Finished to add data to games.yml by boot for: %s", m_path);
return;
}
// Check game updates // Check game updates
const std::string hdd0_boot = hdd0_game + m_title_id + "/USRDIR/EBOOT.BIN"; const std::string hdd0_boot = hdd0_game + m_title_id + "/USRDIR/EBOOT.BIN";

View File

@ -238,12 +238,12 @@ public:
return m_pause_amend_time; return m_pause_amend_time;
} }
bool BootGame(const std::string& path, bool direct = false); bool BootGame(const std::string& path, bool direct = false, bool add_only = false);
static std::string GetHddDir(); static std::string GetHddDir();
static std::string GetLibDir(); static std::string GetLibDir();
void Load(); void Load(bool add_only = false);
void Run(); void Run();
bool Pause(); bool Pause();
void Resume(); void Resume();

View File

@ -23,6 +23,7 @@
#include <QTimer> #include <QTimer>
#include <QUrl> #include <QUrl>
#include <QLabel> #include <QLabel>
#include <QMimeData>
static const std::string m_class_name = "GameViewer"; static const std::string m_class_name = "GameViewer";
inline std::string sstr(const QString& _in) { return _in.toUtf8().toStdString(); } inline std::string sstr(const QString& _in) { return _in.toUtf8().toStdString(); }
@ -31,6 +32,8 @@ inline QSize sizeFromSlider(const int& pos) { return GUI::gl_icon_size_min + (GU
game_list_frame::game_list_frame(std::shared_ptr<gui_settings> settings, const Render_Creator& r_Creator, QWidget *parent) game_list_frame::game_list_frame(std::shared_ptr<gui_settings> settings, const Render_Creator& r_Creator, QWidget *parent)
: QDockWidget(tr("Game List"), parent), xgui_settings(settings), m_Render_Creator(r_Creator) : QDockWidget(tr("Game List"), parent), xgui_settings(settings), m_Render_Creator(r_Creator)
{ {
setAcceptDrops(true);
m_isListLayout = xgui_settings->GetValue(GUI::gl_listMode).toBool(); m_isListLayout = xgui_settings->GetValue(GUI::gl_listMode).toBool();
m_icon_size_index = xgui_settings->GetValue(GUI::gl_iconSize).toInt(); m_icon_size_index = xgui_settings->GetValue(GUI::gl_iconSize).toInt();
m_Margin_Factor = xgui_settings->GetValue(GUI::gl_marginFactor).toReal(); m_Margin_Factor = xgui_settings->GetValue(GUI::gl_marginFactor).toReal();
@ -384,8 +387,8 @@ void game_list_frame::Refresh(bool fromDrive)
// std::set is used to remove duplicates from the list // std::set is used to remove duplicates from the list
for (const auto& dir : std::set<std::string>(std::make_move_iterator(path_list.begin()), std::make_move_iterator(path_list.end()))) for (const auto& dir : std::set<std::string>(std::make_move_iterator(path_list.begin()), std::make_move_iterator(path_list.end())))
{ {
const std::string& sfb = dir + "/PS3_DISC.SFB"; const std::string sfb = dir + "/PS3_DISC.SFB";
const std::string& sfo = dir + (fs::is_file(sfb) ? "/PS3_GAME/PARAM.SFO" : "/PARAM.SFO"); const std::string sfo = dir + (fs::is_file(sfb) ? "/PS3_GAME/PARAM.SFO" : "/PARAM.SFO");
const fs::file sfo_file(sfo); const fs::file sfo_file(sfo);
if (!sfo_file) if (!sfo_file)
@ -541,19 +544,9 @@ void game_list_frame::doubleClickedSlot(const QModelIndex& index)
if (1) if (1)
{ {
Q_EMIT RequestIconPathSet(m_game_data[i].info.path); if (Boot(m_game_data[i].info))
Emu.Stop();
if (!Emu.BootGame(m_game_data[i].info.path))
{
LOG_ERROR(LOADER, "Failed to boot %s", m_game_data[i].info.path);
}
else
{ {
LOG_SUCCESS(LOADER, "Boot from gamelist per doubleclick: done"); LOG_SUCCESS(LOADER, "Boot from gamelist per doubleclick: done");
Q_EMIT RequestAddRecentGame(q_string_pair(qstr(Emu.GetBoot()), qstr("[" + m_game_data[i].info.serial + "] " + m_game_data[i].info.name)));
Refresh(true);
} }
} }
else else
@ -622,7 +615,12 @@ void game_list_frame::ShowSpecifiedContextMenu(const QPoint &pos, int row)
myMenu.addSeparator(); myMenu.addSeparator();
QAction* checkCompat = myMenu.addAction(tr("&Check Game Compatibility")); QAction* checkCompat = myMenu.addAction(tr("&Check Game Compatibility"));
connect(boot, &QAction::triggered, [=]() {Boot(row); }); connect(boot, &QAction::triggered, [=]() {
if (Boot(m_game_data[row].info))
{
LOG_SUCCESS(LOADER, "Boot from gamelist per Boot: done");
}
});
connect(configure, &QAction::triggered, [=]() { connect(configure, &QAction::triggered, [=]() {
settings_dialog (xgui_settings, m_Render_Creator, 0, this, &currGame).exec(); settings_dialog (xgui_settings, m_Render_Creator, 0, this, &currGame).exec();
Refresh(true); Refresh(true);
@ -670,22 +668,23 @@ void game_list_frame::ShowSpecifiedContextMenu(const QPoint &pos, int row)
myMenu.exec(globalPos); myMenu.exec(globalPos);
} }
void game_list_frame::Boot(int row) bool game_list_frame::Boot(const GameInfo& game)
{ {
Q_EMIT RequestIconPathSet(m_game_data[row].info.path); Q_EMIT RequestIconPathSet(game.path);
Emu.Stop(); Emu.Stop();
if (!Emu.BootGame(m_game_data[row].info.path)) if (!Emu.BootGame(game.path))
{ {
QMessageBox::warning(this, tr("Warning!"), tr("Failed to boot ") + qstr(m_game_data[row].info.path)); QMessageBox::warning(this, tr("Warning!"), tr("Failed to boot ") + qstr(game.path));
LOG_ERROR(LOADER, "Failed to boot %s", m_game_data[row].info.path); LOG_ERROR(LOADER, "Failed to boot %s", game.path);
return false;
} }
else else
{ {
LOG_SUCCESS(LOADER, "Boot from gamelist per Boot: done"); Q_EMIT RequestAddRecentGame(q_string_pair(qstr(Emu.GetBoot()), qstr("[" + game.serial + "] " + game.name)));
Q_EMIT RequestAddRecentGame(q_string_pair(qstr(Emu.GetBoot()), qstr("[" + m_game_data[row].info.serial + "] " + m_game_data[row].info.name)));
Refresh(true); Refresh(true);
return true;
} }
} }
@ -1070,3 +1069,186 @@ std::string game_list_frame::GetStringFromU32(const u32& key, const std::map<u32
return sstr(string.join(", ")); return sstr(string.join(", "));
} }
/**
Add valid disc games to gamelist (games.yml)
@param path = dir path to scan for game
*/
void game_list_frame::AddGamesFromDir(const QString& path)
{
if (!QFileInfo(path).isDir()) return;
const std::string s_path = sstr(path);
// search dropped path first or else the direct parent to an elf is wrongly skipped
if (Emu.BootGame(s_path, false, true))
{
LOG_NOTICE(GENERAL, "Returned from game addition by drag and drop: %s", s_path);
}
// search direct subdirectories, that way we can drop one folder containing all games
for (const auto& entry : fs::dir(s_path))
{
if (entry.name == "." || entry.name == "..") continue;
const std::string pth = s_path + "/" + entry.name;
if (!QFileInfo(qstr(pth)).isDir()) continue;
if (Emu.BootGame(pth, false, true))
{
LOG_NOTICE(GENERAL, "Returned from game addition by drag and drop: %s", pth);
}
}
}
/**
Check data for valid file types and cache their paths if necessary
@param md = data containing file urls
@param savePaths = flag for path caching
@returns validity of file type
*/
int game_list_frame::IsValidFile(const QMimeData& md, QStringList* dropPaths)
{
int dropType = DROP_ERROR;
const QList<QUrl> list = md.urls(); // get list of all the dropped file urls
for (int i = 0; i < list.count(); i++) // check each file in url list for valid type
{
const QString path = list[i].toLocalFile(); // convert url to filepath
// check for directories first, only valid if all other paths led to directories until now.
if (QFileInfo(path).isDir())
{
if (i != 0 && dropType != DROP_DIR) return DROP_ERROR;
dropType = DROP_DIR;
if (dropPaths)
{
dropPaths->append(path);
}
continue;
}
// now that we know it has to be a file we get the file ending
QString suffix = QFileInfo(list[i].fileName()).suffix().toLower();
if (suffix.isEmpty()) return DROP_ERROR; // NANI the heck would you want such a file?
QString last_suffix;
if (i == 0) // the first item defines our file type
{
last_suffix = suffix;
}
else if (last_suffix == "pup" || last_suffix == "bin") // we only accept one firmware or eboot file
{
return list.count() != 1 ? dropType : DROP_ERROR;
}
else if (last_suffix != suffix) // we don't accept multiple file types
{
return DROP_ERROR;
}
// set drop type by file ending
if (suffix == "pkg")
{
dropType = DROP_PKG;
}
else if (suffix == "pup")
{
dropType = DROP_PUP;
}
else if (suffix == "rap")
{
dropType = DROP_RAP;
}
else if (suffix == "bin")
{
dropType = DROP_GAME;
}
else // if (suffix == "kuso")
{
return DROP_ERROR;
}
if (dropPaths) // we only need to know the paths on drop
{
dropPaths->append(path);
}
}
return dropType;
}
void game_list_frame::dropEvent(QDropEvent* event)
{
QStringList dropPaths;
switch (IsValidFile(*event->mimeData(), &dropPaths)) // get valid file paths and drop type
{
case DROP_ERROR:
break;
case DROP_PKG: // install the package
Q_EMIT RequestPackageInstall(dropPaths);
break;
case DROP_PUP: // install the firmware
Q_EMIT RequestFirmwareInstall(dropPaths.first());
break;
case DROP_RAP: // import rap files to exdata dir
for (const auto& rap : dropPaths)
{
const std::string rapname = sstr(QFileInfo(rap).fileName());
// TODO: use correct user ID once User Manager is implemented
if (!fs::copy_file(sstr(rap), fmt::format("%s/home/%s/exdata/%s", Emu.GetHddDir(), "00000001", rapname), false))
{
LOG_WARNING(GENERAL, "Could not copy rap file by drop: %s", rapname);
}
else
{
LOG_SUCCESS(GENERAL, "Successfully copied rap file by drop: %s", rapname);
}
}
break;
case DROP_DIR: // import valid games to gamelist (games.yaml)
for (const auto& path : dropPaths)
{
AddGamesFromDir(path);
}
Refresh(true);
break;
case DROP_GAME: // import valid games to gamelist (games.yaml)
if (Emu.BootGame(sstr(dropPaths.first()), true))
{
LOG_SUCCESS(GENERAL, "Elf Boot from drag and drop done: %s", sstr(dropPaths.first()));
}
Refresh(true);
break;
default:
LOG_WARNING(GENERAL, "Invalid dropType in gamelist dropEvent");
break;
}
}
void game_list_frame::dragEnterEvent(QDragEnterEvent* event)
{
if (IsValidFile(*event->mimeData()))
{
event->accept();
}
}
void game_list_frame::dragMoveEvent(QDragMoveEvent* event)
{
if (IsValidFile(*event->mimeData()))
{
event->accept();
}
}
void game_list_frame::dragLeaveEvent(QDragLeaveEvent* event)
{
event->accept();
}

View File

@ -13,6 +13,7 @@
#include <QToolBar> #include <QToolBar>
#include <QLineEdit> #include <QLineEdit>
#include <QStackedWidget> #include <QStackedWidget>
#include <QDropEvent>
#include <memory> #include <memory>
@ -167,6 +168,15 @@ struct Tool_Bar_Button
bool isActive; bool isActive;
}; };
enum {
DROP_ERROR,
DROP_PKG,
DROP_PUP,
DROP_RAP,
DROP_DIR,
DROP_GAME
};
class game_list_frame : public QDockWidget { class game_list_frame : public QDockWidget {
Q_OBJECT Q_OBJECT
@ -205,7 +215,6 @@ public Q_SLOTS:
void RepaintToolBarIcons(); void RepaintToolBarIcons();
private Q_SLOTS: private Q_SLOTS:
void Boot(int row);
void RemoveCustomConfiguration(int row); void RemoveCustomConfiguration(int row);
void OnColClicked(int col); void OnColClicked(int col);
void ShowContextMenu(const QPoint &pos); void ShowContextMenu(const QPoint &pos);
@ -213,24 +222,33 @@ private Q_SLOTS:
void doubleClickedSlot(const QModelIndex& index); void doubleClickedSlot(const QModelIndex& index);
Q_SIGNALS: Q_SIGNALS:
void GameListFrameClosed(); void GameListFrameClosed();
void RequestIconPathSet(const std::string path); void RequestIconPathSet(const std::string& path);
void RequestAddRecentGame(const q_string_pair& entry); void RequestAddRecentGame(const q_string_pair& entry);
void RequestIconSizeActSet(const int& idx); void RequestIconSizeActSet(const int& idx);
void RequestListModeActSet(const bool& isList); void RequestListModeActSet(const bool& isList);
void RequestCategoryActSet(const int& id); void RequestCategoryActSet(const int& id);
void RequestSaveSliderPos(const bool& save); void RequestSaveSliderPos(const bool& save);
void RequestPackageInstall(const QStringList& paths);
void RequestFirmwareInstall(const QString& path);
protected: protected:
/** Override inherited method from Qt to allow signalling when close happened.*/ /** Override inherited method from Qt to allow signalling when close happened.*/
void closeEvent(QCloseEvent* event) override; void closeEvent(QCloseEvent* event) override;
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
void dropEvent(QDropEvent* event) override;
void dragEnterEvent(QDragEnterEvent* event) override;
void dragMoveEvent(QDragMoveEvent* event) override;
void dragLeaveEvent(QDragLeaveEvent* event) override;
private: private:
QPixmap PaintedPixmap(const QImage& img, bool paintConfigIcon = false); QPixmap PaintedPixmap(const QImage& img, bool paintConfigIcon = false);
bool Boot(const GameInfo& info);
void PopulateGameGrid(uint maxCols, const QSize& image_size, const QColor& image_color); void PopulateGameGrid(uint maxCols, const QSize& image_size, const QColor& image_color);
void FilterData(); void FilterData();
void SortGameList(); void SortGameList();
int PopulateGameList(); int PopulateGameList();
bool SearchMatchesApp(const std::string& name, const std::string& serial); bool SearchMatchesApp(const std::string& name, const std::string& serial);
int IsValidFile(const QMimeData& md, QStringList* dropPaths = nullptr);
void AddGamesFromDir(const QString& path);
std::string CurrentSelectionIconPath(); std::string CurrentSelectionIconPath();
std::string GetStringFromU32(const u32& key, const std::map<u32, QString>& map, bool combined = false); std::string GetStringFromU32(const u32& key, const std::map<u32, QString>& map, bool combined = false);

View File

@ -285,10 +285,24 @@ void main_window::BootGame()
} }
} }
void main_window::InstallPkg() void main_window::InstallPkg(const QString& dropPath)
{ {
QString path_last_PKG = guiSettings->GetValue(GUI::fd_install_pkg).toString(); QString filePath = dropPath;
QString filePath = QFileDialog::getOpenFileName(this, tr("Select PKG To Install"), path_last_PKG, tr("PKG files (*.pkg);;All files (*.*)"));
if (filePath.isEmpty())
{
QString path_last_PKG = guiSettings->GetValue(GUI::fd_install_pkg).toString();
filePath = QFileDialog::getOpenFileName(this, tr("Select PKG To Install"), path_last_PKG, tr("PKG files (*.pkg);;All files (*.*)"));
}
else
{
if (QMessageBox::question(this, tr("PKG Decrypter / Installer"), tr("Install package: %1?").arg(filePath),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
{
LOG_NOTICE(LOADER, "PKG: Cancelled installation from drop. File: %s", sstr(filePath));
return;
}
}
if (filePath == NULL) if (filePath == NULL)
{ {
@ -418,10 +432,24 @@ void main_window::InstallPkg()
} }
} }
void main_window::InstallPup() void main_window::InstallPup(const QString& dropPath)
{ {
QString path_last_PUP = guiSettings->GetValue(GUI::fd_install_pup).toString(); QString filePath = dropPath;
QString filePath = QFileDialog::getOpenFileName(this, tr("Select PS3UPDAT.PUP To Install"), path_last_PUP, tr("PS3 update file (PS3UPDAT.PUP)"));
if (filePath.isEmpty())
{
QString path_last_PUP = guiSettings->GetValue(GUI::fd_install_pup).toString();
filePath = QFileDialog::getOpenFileName(this, tr("Select PS3UPDAT.PUP To Install"), path_last_PUP, tr("PS3 update file (PS3UPDAT.PUP)"));
}
else
{
if (QMessageBox::question(this, tr("RPCS3 Firmware Installer"), tr("Install firmware: %1?").arg(filePath),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
{
LOG_NOTICE(LOADER, "Firmware: Cancelled installation from drop. File: %s", sstr(filePath));
return;
}
}
if (filePath == NULL) if (filePath == NULL)
{ {
@ -1020,8 +1048,8 @@ void main_window::CreateConnects()
connect(ui->freezeRecentAct, &QAction::triggered, [=](bool checked) { connect(ui->freezeRecentAct, &QAction::triggered, [=](bool checked) {
guiSettings->SetValue(GUI::rg_freeze, checked); guiSettings->SetValue(GUI::rg_freeze, checked);
}); });
connect(ui->bootInstallPkgAct, &QAction::triggered, this, &main_window::InstallPkg); connect(ui->bootInstallPkgAct, &QAction::triggered, [this] {InstallPkg(); });
connect(ui->bootInstallPupAct, &QAction::triggered, this, &main_window::InstallPup); connect(ui->bootInstallPupAct, &QAction::triggered, [this] {InstallPup(); });
connect(ui->exitAct, &QAction::triggered, this, &QWidget::close); connect(ui->exitAct, &QAction::triggered, this, &QWidget::close);
connect(ui->sysPauseAct, &QAction::triggered, Pause); connect(ui->sysPauseAct, &QAction::triggered, Pause);
connect(ui->sysStopAct, &QAction::triggered, [=]() { Emu.Stop(); }); connect(ui->sysStopAct, &QAction::triggered, [=]() { Emu.Stop(); });
@ -1275,6 +1303,13 @@ void main_window::CreateDockWindows()
}); });
connect(gameListFrame, &game_list_frame::RequestIconPathSet, this, &main_window::SetAppIconFromPath); connect(gameListFrame, &game_list_frame::RequestIconPathSet, this, &main_window::SetAppIconFromPath);
connect(gameListFrame, &game_list_frame::RequestAddRecentGame, this, &main_window::AddRecentAction); connect(gameListFrame, &game_list_frame::RequestAddRecentGame, this, &main_window::AddRecentAction);
connect(gameListFrame, &game_list_frame::RequestPackageInstall, [this](const QStringList& paths){
for (const auto& path : paths)
{
InstallPkg(path);
}
});
connect(gameListFrame, &game_list_frame::RequestFirmwareInstall, this, &main_window::InstallPup);
} }
void main_window::ConfigureGuiFromSettings(bool configureAll) void main_window::ConfigureGuiFromSettings(bool configureAll)

View File

@ -76,8 +76,6 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void BootElf(); void BootElf();
void BootGame(); void BootGame();
void InstallPkg();
void InstallPup();
void DecryptSPRXLibraries(); void DecryptSPRXLibraries();
void SaveWindowState(); void SaveWindowState();
@ -85,6 +83,8 @@ private Q_SLOTS:
protected: protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
void keyPressEvent(QKeyEvent *keyEvent) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
void SetAppIconFromPath(const std::string path); void SetAppIconFromPath(const std::string path);
private: private:
void CreateActions(); void CreateActions();
@ -92,9 +92,8 @@ private:
void CreateDockWindows(); void CreateDockWindows();
void ConfigureGuiFromSettings(bool configureAll = false); void ConfigureGuiFromSettings(bool configureAll = false);
void EnableMenus(bool enabled); void EnableMenus(bool enabled);
void InstallPkg(const QString& dropPath = "");
void keyPressEvent(QKeyEvent *keyEvent) override; void InstallPup(const QString& dropPath = "");
void mouseDoubleClickEvent(QMouseEvent *event) override;
QAction* CreateRecentAction(const q_string_pair& entry, const uint& sc_idx); QAction* CreateRecentAction(const q_string_pair& entry, const uint& sc_idx);
void BootRecentAction(const QAction* act); void BootRecentAction(const QAction* act);