Qt: unify package installation logic

This commit is contained in:
Megamouse 2020-08-04 19:03:13 +02:00
parent fab1f7d939
commit 17557df9f4
2 changed files with 53 additions and 48 deletions

View file

@ -491,21 +491,25 @@ bool main_window::InstallRapFile(const QString& path, const std::string& filenam
return fs::copy_file(sstr(path), Emulator::GetHddDir() + "/home/" + Emu.GetUsr() + "/exdata/" + filename, true); return fs::copy_file(sstr(path), Emulator::GetHddDir() + "/home/" + Emu.GetUsr() + "/exdata/" + filename, true);
} }
void main_window::InstallPackages(QStringList file_paths, bool show_confirm) void main_window::InstallPackages(QStringList file_paths)
{ {
if (file_paths.isEmpty()) if (file_paths.isEmpty())
{ {
// If this function was called without a path, ask the user for files to install.
const QString path_last_pkg = m_gui_settings->GetValue(gui::fd_install_pkg).toString(); const QString path_last_pkg = m_gui_settings->GetValue(gui::fd_install_pkg).toString();
const QStringList file_path = QFileDialog::getOpenFileNames(this, tr("Select packages and/or rap files to install"), const QStringList paths = QFileDialog::getOpenFileNames(this, tr("Select packages and/or rap files to install"),
path_last_pkg, tr("All relevant (*.pkg *.rap);;Package files (*.pkg);;Rap files (*.rap);;All files (*.*)")); path_last_pkg, tr("All relevant (*.pkg *.rap);;Package files (*.pkg);;Rap files (*.rap);;All files (*.*)"));
if (!file_path.isEmpty()) if (paths.isEmpty())
{ {
file_paths.append(file_path); return;
} }
file_paths.append(paths);
} }
else if (show_confirm) else if (file_paths.count() == 1)
{ {
// This can currently only happen by drag and drop.
if (QMessageBox::question(this, tr("PKG Decrypter / Installer"), tr("Install package: %1?").arg(file_paths.front()), if (QMessageBox::question(this, tr("PKG Decrypter / Installer"), tr("Install package: %1?").arg(file_paths.front()),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
{ {
@ -514,8 +518,7 @@ void main_window::InstallPackages(QStringList file_paths, bool show_confirm)
} }
} }
if (!file_paths.isEmpty()) // Install rap files if available
{
for (const auto& rap : file_paths.filter(QRegExp(".*\\.rap"))) for (const auto& rap : file_paths.filter(QRegExp(".*\\.rap")))
{ {
const QFileInfo file_info(rap); const QFileInfo file_info(rap);
@ -527,24 +530,42 @@ void main_window::InstallPackages(QStringList file_paths, bool show_confirm)
} }
else else
{ {
gui_log.warning("Could not copy rap file: %s", rapname); gui_log.error("Could not copy rap file: %s", rapname);
} }
m_gui_settings->SetValue(gui::fd_install_pkg, file_info.path()); m_gui_settings->SetValue(gui::fd_install_pkg, file_info.path());
} }
// Find remaining package files
file_paths = file_paths.filter(QRegExp(".*\\.pkg")); file_paths = file_paths.filter(QRegExp(".*\\.pkg"));
if (!file_paths.isEmpty()) if (file_paths.isEmpty())
{ {
return;
}
// Let the user choose the packages to install and select the order in which they shall be installed.
if (file_paths.size() > 1)
{
pkg_install_dialog dlg(file_paths, this);
connect(&dlg, &QDialog::accepted, [&file_paths, &dlg]()
{
file_paths = dlg.GetPathsToInstall();
});
dlg.exec();
}
if (file_paths.empty())
{
return;
}
// Handle the actual installations with a timeout. Otherwise the source explorer instance is not usable during the following file processing. // Handle the actual installations with a timeout. Otherwise the source explorer instance is not usable during the following file processing.
QTimer::singleShot(0, [this, file_paths]() QTimer::singleShot(0, [this, file_paths]()
{ {
HandlePackageInstallation(file_paths); HandlePackageInstallation(file_paths);
}); });
} }
}
}
void main_window::HandlePackageInstallation(QStringList file_paths) void main_window::HandlePackageInstallation(QStringList file_paths)
{ {
@ -2321,23 +2342,7 @@ void main_window::dropEvent(QDropEvent* event)
} }
case drop_type::drop_pkg: // install the packages case drop_type::drop_pkg: // install the packages
{ {
if (drop_paths.count() > 1) InstallPackages(drop_paths);
{
pkg_install_dialog dlg(drop_paths, this);
connect(&dlg, &QDialog::accepted, [this, &dlg]()
{
const QStringList paths = dlg.GetPathsToInstall();
if (!paths.isEmpty())
{
InstallPackages(paths, false);
}
});
dlg.exec();
}
else
{
InstallPackages(drop_paths, true);
}
break; break;
} }
case drop_type::drop_pup: // install the firmware case drop_type::drop_pup: // install the firmware

View file

@ -133,7 +133,7 @@ private:
static bool InstallRapFile(const QString& path, const std::string& filename); static bool InstallRapFile(const QString& path, const std::string& filename);
void InstallPackages(QStringList file_paths = QStringList(), bool show_confirm = true); void InstallPackages(QStringList file_paths = QStringList());
void HandlePackageInstallation(QStringList file_paths = QStringList()); void HandlePackageInstallation(QStringList file_paths = QStringList());
void InstallPup(QString filePath = ""); void InstallPup(QString filePath = "");