Browse Source

fix mod naming and live update

Signed-off-by: crueter <crueter@eden-emu.dev>
pull/3472/head
crueter 7 days ago
parent
commit
e0134678cd
No known key found for this signature in database GPG Key ID: 425ACD2D4830EBC6
  1. 6
      src/frontend_common/mod_manager.cpp
  2. 8
      src/frontend_common/mod_manager.h
  3. 29
      src/qt_common/util/mod.cpp
  4. 6
      src/qt_common/util/mod.h
  5. 47
      src/yuzu/configuration/configure_per_game_addons.cpp

6
src/frontend_common/mod_manager.cpp

@ -38,7 +38,7 @@ std::optional<std::filesystem::path> GetModFolder(const std::string& root) {
return std::nullopt; return std::nullopt;
} }
bool InstallMod(const std::filesystem::path& path, const u64 program_id, const bool copy) {
ModInstallResult InstallMod(const std::filesystem::path& path, const u64 program_id, const bool copy) {
const auto program_id_string = fmt::format("{:016X}", program_id); const auto program_id_string = fmt::format("{:016X}", program_id);
const auto mod_name = path.filename(); const auto mod_name = path.filename();
const auto mod_dir = const auto mod_dir =
@ -54,12 +54,12 @@ bool InstallMod(const std::filesystem::path& path, const u64 program_id, const b
std::filesystem::remove_all(path); std::filesystem::remove_all(path);
} catch (std::exception& e) { } catch (std::exception& e) {
LOG_ERROR(Frontend, "Mod install failed with message {}", e.what()); LOG_ERROR(Frontend, "Mod install failed with message {}", e.what());
return false;
return Failed;
} }
LOG_INFO(Frontend, "Copied mod from {} to {}", path.string(), mod_dir.string()); LOG_INFO(Frontend, "Copied mod from {} to {}", path.string(), mod_dir.string());
return true;
return Success;
} }
} // namespace FrontendCommon } // namespace FrontendCommon

8
src/frontend_common/mod_manager.h

@ -6,7 +6,13 @@
namespace FrontendCommon { namespace FrontendCommon {
enum ModInstallResult {
Cancelled,
Failed,
Success,
};
std::optional<std::filesystem::path> GetModFolder(const std::string& root); std::optional<std::filesystem::path> GetModFolder(const std::string& root);
bool InstallMod(const std::filesystem::path &path, const u64 program_id, const bool copy = true);
ModInstallResult InstallMod(const std::filesystem::path &path, const u64 program_id, const bool copy = true);
} }

29
src/qt_common/util/mod.cpp

@ -1,6 +1,5 @@
#include <filesystem> #include <filesystem>
#include <JlCompress.h> #include <JlCompress.h>
#include "frontend_common/mod_manager.h"
#include "mod.h" #include "mod.h"
#include "qt_common/abstract/frontend.h" #include "qt_common/abstract/frontend.h"
@ -22,8 +21,6 @@ QString GetModFolder(const QString& root, const QString& fallbackName) {
QString name = QtCommon::Frontend::GetTextInput( QString name = QtCommon::Frontend::GetTextInput(
tr("Mod Name"), tr("What should this mod be called?"), default_name); tr("Mod Name"), tr("What should this mod be called?"), default_name);
qDebug() << "Naming mod:" << name;
// if std_path is empty, frontend_common could not determine mod type and/or name. // if std_path is empty, frontend_common could not determine mod type and/or name.
// so we have to prompt the user and set up the structure ourselves // so we have to prompt the user and set up the structure ourselves
if (!std_path) { if (!std_path) {
@ -61,8 +58,10 @@ QString GetModFolder(const QString& root, const QString& fallbackName) {
const auto mod_dir = fs::temp_directory_path() / "eden" / "mod" / name.toStdString(); const auto mod_dir = fs::temp_directory_path() / "eden" / "mod" / name.toStdString();
const auto tmp = mod_dir / to_make; const auto tmp = mod_dir / to_make;
fs::remove_all(mod_dir); fs::remove_all(mod_dir);
if (!fs::create_directories(tmp))
if (!fs::create_directories(tmp)) {
LOG_ERROR(Frontend, "Failed to create temporary directory {}", tmp.string());
return QString(); return QString();
}
std_path = mod_dir; std_path = mod_dir;
@ -81,24 +80,28 @@ QString GetModFolder(const QString& root, const QString& fallbackName) {
std_path = new_path; std_path = new_path;
} }
qDebug() << "Mod path" << std_path->string();
return QString::fromStdString(std_path->string()); return QString::fromStdString(std_path->string());
} }
bool InstallMod(const QString& path, const QString& fallbackName, const u64 program_id,
FrontendCommon::ModInstallResult InstallMod(const QString& path, const QString& fallbackName, const u64 program_id,
const bool copy) { const bool copy) {
const auto target = GetModFolder(path, fallbackName); const auto target = GetModFolder(path, fallbackName);
if (target.isEmpty()) {
return FrontendCommon::Cancelled;
}
return FrontendCommon::InstallMod(target.toStdString(), program_id, copy); return FrontendCommon::InstallMod(target.toStdString(), program_id, copy);
} }
bool InstallModFromZip(const QString& path, const u64 program_id) {
FrontendCommon::ModInstallResult InstallModFromZip(const QString& path, const u64 program_id) {
namespace fs = std::filesystem; namespace fs = std::filesystem;
fs::path tmp{fs::temp_directory_path() / "eden" / "unzip_mod"}; fs::path tmp{fs::temp_directory_path() / "eden" / "unzip_mod"};
fs::remove_all(tmp); fs::remove_all(tmp);
if (!fs::create_directories(tmp))
return false;
if (!fs::create_directories(tmp)) {
LOG_ERROR(Frontend, "Failed to create temporary directory {}", tmp.string());
return FrontendCommon::Failed;
}
QString qCacheDir = QString::fromStdString(tmp.string()); QString qCacheDir = QString::fromStdString(tmp.string());
@ -106,8 +109,10 @@ bool InstallModFromZip(const QString& path, const u64 program_id) {
// TODO(crueter): use QtCompress // TODO(crueter): use QtCompress
QStringList result = JlCompress::extractDir(&zip, qCacheDir); QStringList result = JlCompress::extractDir(&zip, qCacheDir);
if (result.isEmpty())
return false;
if (result.isEmpty()) {
LOG_ERROR(Frontend, "Zip file {} is empty", path.toStdString());
return FrontendCommon::Failed;
}
const auto fallback = fs::path{path.toStdString()}.stem(); const auto fallback = fs::path{path.toStdString()}.stem();

6
src/qt_common/util/mod.h

@ -2,13 +2,15 @@
#include <QString> #include <QString>
#include "common/common_types.h" #include "common/common_types.h"
#include "frontend_common/mod_manager.h"
namespace QtCommon::Mod { namespace QtCommon::Mod {
QString GetModFolder(const QString &root, const QString &fallbackName); QString GetModFolder(const QString &root, const QString &fallbackName);
bool InstallMod(const QString &path, const QString &fallbackName, const u64 program_id, const bool copy = true);
FrontendCommon::ModInstallResult InstallMod(const QString& path, const QString& fallbackName,
const u64 program_id, const bool copy = true);
bool InstallModFromZip(const QString &path, const u64 program_id);
FrontendCommon::ModInstallResult InstallModFromZip(const QString &path, const u64 program_id);
} }

47
src/yuzu/configuration/configure_per_game_addons.cpp

@ -14,18 +14,20 @@
#include <QString> #include <QString>
#include <QTimer> #include <QTimer>
#include <QTreeView> #include <QTreeView>
#include <qstandardpaths.h>
#include "common/fs/fs.h" #include "common/fs/fs.h"
#include "common/fs/path_util.h" #include "common/fs/path_util.h"
#include "core/core.h" #include "core/core.h"
#include "core/file_sys/patch_manager.h" #include "core/file_sys/patch_manager.h"
#include "core/loader/loader.h" #include "core/loader/loader.h"
#include "frontend_common/mod_manager.h"
#include "qt_common/abstract/frontend.h" #include "qt_common/abstract/frontend.h"
#include "qt_common/config/uisettings.h"
#include "qt_common/util/mod.h" #include "qt_common/util/mod.h"
#include "ui_configure_per_game_addons.h" #include "ui_configure_per_game_addons.h"
#include "yuzu/configuration/configure_input.h" #include "yuzu/configuration/configure_input.h"
#include "yuzu/configuration/configure_per_game_addons.h" #include "yuzu/configuration/configure_per_game_addons.h"
#include "qt_common/config/uisettings.h"
ConfigurePerGameAddons::ConfigurePerGameAddons(Core::System& system_, QWidget* parent) ConfigurePerGameAddons::ConfigurePerGameAddons(Core::System& system_, QWidget* parent)
: QWidget(parent), ui{std::make_unique<Ui::ConfigurePerGameAddons>()}, system{system_} { : QWidget(parent), ui{std::make_unique<Ui::ConfigurePerGameAddons>()}, system{system_} {
@ -104,31 +106,58 @@ void ConfigurePerGameAddons::SetTitleId(u64 id) {
} }
void ConfigurePerGameAddons::InstallModFolder() { void ConfigurePerGameAddons::InstallModFolder() {
const auto path = QtCommon::Frontend::GetExistingDirectory(tr("Mod Folder"));
const auto path = QtCommon::Frontend::GetExistingDirectory(
tr("Mod Folder"), QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
if (path.isEmpty()) { if (path.isEmpty()) {
return; return;
} }
// TODO: Pending refresh game list // TODO: Pending refresh game list
if (QtCommon::Mod::InstallMod(path, {}, title_id)) {
auto ret = QtCommon::Mod::InstallMod(path, {}, title_id);
switch (ret) {
case FrontendCommon::Success:
QtCommon::Frontend::Information(tr("Mod Installed"), tr("Mod was successfully installed.")); QtCommon::Frontend::Information(tr("Mod Installed"), tr("Mod was successfully installed."));
item_model->removeRows(0, item_model->rowCount());
list_items.clear();
LoadConfiguration(); LoadConfiguration();
} else {
QtCommon::Frontend::Critical(tr("Mod Install Failed"), tr("Mod install was unsuccessful. Check the log for details."));
break;
case FrontendCommon::Failed:
QtCommon::Frontend::Critical(
tr("Mod Install Failed"),
tr("Mod install was unsuccessful. Check the log for details."));
break;
case FrontendCommon::Cancelled:
default:
break;
} }
} }
void ConfigurePerGameAddons::InstallModZip() { void ConfigurePerGameAddons::InstallModZip() {
const auto path = QtCommon::Frontend::GetOpenFileName(tr("Zipped Mod Location"), {}, tr("Zipped Archives (*.zip)"));
const auto path = QtCommon::Frontend::GetOpenFileName(
tr("Zipped Mod Location"),
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation),
tr("Zipped Archives (*.zip)"));
if (path.isEmpty()) { if (path.isEmpty()) {
return; return;
} }
if (QtCommon::Mod::InstallModFromZip(path, title_id)) {
auto ret = QtCommon::Mod::InstallModFromZip(path, title_id);
switch (ret) {
case FrontendCommon::Success:
QtCommon::Frontend::Information(tr("Mod Installed"), tr("Mod was successfully installed.")); QtCommon::Frontend::Information(tr("Mod Installed"), tr("Mod was successfully installed."));
item_model->removeRows(0, item_model->rowCount());
list_items.clear();
LoadConfiguration(); LoadConfiguration();
} else {
QtCommon::Frontend::Critical(tr("Mod Install Failed"), tr("Mod install was unsuccessful. Check the log for details."));
break;
case FrontendCommon::Failed:
QtCommon::Frontend::Critical(
tr("Mod Install Failed"),
tr("Mod install was unsuccessful. Check the log for details."));
break;
case FrontendCommon::Cancelled:
default:
break;
} }
} }

Loading…
Cancel
Save