mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-29 21:58:58 +02:00
[desktop] Add mod importer from folder and zip (#3472)
Closes #3125 Adds buttons to the addons page that imports a mod (or mods) from zip or folder. Currently known to work with mods that provide proper romfs/exefs things, unsure about cheats and such. Also works on mods that just stuff things into the root of the zip. TODO: - [ ] test folder more thoroughly - [ ] cheats - [ ] test all sorts of mod pack types Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3472 Reviewed-by: Lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
08232ce642
commit
e07e269bd7
18 changed files with 570 additions and 14 deletions
|
|
@ -22,6 +22,8 @@ add_library(qt_common STATIC
|
|||
util/rom.h util/rom.cpp
|
||||
util/applet.h util/applet.cpp
|
||||
util/compress.h util/compress.cpp
|
||||
util/fs.h util/fs.cpp
|
||||
util/mod.h util/mod.cpp
|
||||
|
||||
abstract/frontend.h abstract/frontend.cpp
|
||||
abstract/qt_progress_dialog.h abstract/qt_progress_dialog.cpp
|
||||
|
|
@ -29,9 +31,7 @@ add_library(qt_common STATIC
|
|||
qt_string_lookup.h
|
||||
qt_compat.h
|
||||
|
||||
discord/discord.h
|
||||
util/fs.h util/fs.cpp
|
||||
)
|
||||
discord/discord.h)
|
||||
|
||||
if (UNIX)
|
||||
target_sources(qt_common PRIVATE gui_settings.cpp gui_settings.h)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <QLineEdit>
|
||||
#include "frontend.h"
|
||||
#include "qt_common/qt_common.h"
|
||||
|
||||
|
|
@ -8,6 +9,9 @@
|
|||
#include <QFileDialog>
|
||||
#endif
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QInputDialog>
|
||||
|
||||
namespace QtCommon::Frontend {
|
||||
|
||||
StandardButton ShowMessage(
|
||||
|
|
@ -50,4 +54,25 @@ const QString GetExistingDirectory(const QString& caption, const QString& dir,
|
|||
#endif
|
||||
}
|
||||
|
||||
int Choice(const QString& title, const QString& caption, const QStringList& options) {
|
||||
QMessageBox box(rootObject);
|
||||
box.setText(caption);
|
||||
box.setWindowTitle(title);
|
||||
|
||||
for (const QString &opt : options) {
|
||||
box.addButton(opt, QMessageBox::AcceptRole);
|
||||
}
|
||||
|
||||
box.addButton(QMessageBox::Cancel);
|
||||
|
||||
box.exec();
|
||||
auto button = box.clickedButton();
|
||||
return options.indexOf(button->text());
|
||||
}
|
||||
|
||||
const QString GetTextInput(const QString& title, const QString& caption,
|
||||
const QString& defaultText) {
|
||||
return QInputDialog::getText(rootObject, title, caption, QLineEdit::Normal, defaultText);
|
||||
}
|
||||
|
||||
} // namespace QtCommon::Frontend
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#ifndef FRONTEND_H
|
||||
|
|
@ -139,5 +139,11 @@ const QString GetExistingDirectory(const QString &caption = QString(),
|
|||
const QString &dir = QString(),
|
||||
Options options = Option::ShowDirsOnly);
|
||||
|
||||
int Choice(const QString& title = QString(), const QString& caption = QString(),
|
||||
const QStringList& options = {});
|
||||
|
||||
const QString GetTextInput(const QString& title = QString(), const QString& caption = QString(),
|
||||
const QString& defaultText = QString());
|
||||
|
||||
} // namespace QtCommon::Frontend
|
||||
#endif // FRONTEND_H
|
||||
|
|
|
|||
137
src/qt_common/util/mod.cpp
Normal file
137
src/qt_common/util/mod.cpp
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <filesystem>
|
||||
#include <JlCompress.h>
|
||||
#include "frontend_common/mod_manager.h"
|
||||
#include "mod.h"
|
||||
#include "qt_common/abstract/frontend.h"
|
||||
|
||||
namespace QtCommon::Mod {
|
||||
QStringList GetModFolders(const QString& root, const QString& fallbackName) {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
const auto std_root = root.toStdString();
|
||||
|
||||
auto paths = FrontendCommon::GetModFolder(std_root);
|
||||
|
||||
// multi mod zip
|
||||
if (paths.size() > 1) {
|
||||
// We just have to assume it's properly formed here.
|
||||
// If not, you're out of luck.
|
||||
QStringList qpaths;
|
||||
for (const fs::path& path : paths) {
|
||||
qpaths << QString::fromStdString(path.string());
|
||||
}
|
||||
|
||||
return qpaths;
|
||||
}
|
||||
// either frontend didn't detect any romfs/exefs, or is a single-mod zip
|
||||
else {
|
||||
fs::path std_path;
|
||||
if (!paths.empty())
|
||||
std_path = paths[0];
|
||||
|
||||
QString default_name;
|
||||
if (!fallbackName.isEmpty())
|
||||
default_name = fallbackName;
|
||||
else if (!paths.empty())
|
||||
default_name = QString::fromStdString(std_path.filename().string());
|
||||
else
|
||||
default_name = root.split(QLatin1Char('/')).last();
|
||||
|
||||
QString name = QtCommon::Frontend::GetTextInput(
|
||||
tr("Mod Name"), tr("What should this mod be called?"), default_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
|
||||
if (paths.empty()) {
|
||||
// TODO: Carboxyl impl.
|
||||
const QStringList choices = {
|
||||
tr("RomFS"),
|
||||
tr("ExeFS/Patch"),
|
||||
tr("Cheat"),
|
||||
};
|
||||
|
||||
int choice = QtCommon::Frontend::Choice(
|
||||
tr("Mod Type"),
|
||||
tr("Could not detect mod type automatically. Please manually "
|
||||
"specify the type of mod you downloaded.\n\nMost mods are RomFS mods, but "
|
||||
"patches "
|
||||
"(.pchtxt) are typically ExeFS mods."),
|
||||
choices);
|
||||
|
||||
std::string to_make;
|
||||
|
||||
switch (choice) {
|
||||
case 0:
|
||||
to_make = "romfs";
|
||||
break;
|
||||
case 1:
|
||||
to_make = "exefs";
|
||||
break;
|
||||
case 2:
|
||||
to_make = "cheats";
|
||||
break;
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
|
||||
// now make a temp directory...
|
||||
const auto mod_dir = fs::temp_directory_path() / "eden" / "mod" / name.toStdString();
|
||||
const auto tmp = mod_dir / to_make;
|
||||
fs::remove_all(mod_dir);
|
||||
if (!fs::create_directories(tmp)) {
|
||||
LOG_ERROR(Frontend, "Failed to create temporary directory {}", tmp.string());
|
||||
return {};
|
||||
}
|
||||
|
||||
std_path = mod_dir;
|
||||
|
||||
// ... and copy everything from the root to the temp dir
|
||||
for (const auto& entry : fs::directory_iterator(root.toStdString())) {
|
||||
const auto target = tmp / entry.path().filename();
|
||||
|
||||
fs::copy(entry.path(), target,
|
||||
fs::copy_options::recursive | fs::copy_options::overwrite_existing);
|
||||
}
|
||||
} else {
|
||||
// Rename the existing mod folder.
|
||||
const auto new_path = std_path.parent_path() / name.toStdString();
|
||||
fs::rename(std_path, new_path);
|
||||
std_path = new_path;
|
||||
}
|
||||
|
||||
return {QString::fromStdString(std_path.string())};
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(crueter): Make this a common extract_to_tmp func
|
||||
const QString ExtractMod(const QString& path) {
|
||||
namespace fs = std::filesystem;
|
||||
fs::path tmp{fs::temp_directory_path() / "eden" / "unzip_mod"};
|
||||
|
||||
fs::remove_all(tmp);
|
||||
if (!fs::create_directories(tmp)) {
|
||||
QtCommon::Frontend::Critical(tr("Mod Extract Failed"),
|
||||
tr("Failed to create temporary directory %1")
|
||||
.arg(QString::fromStdString(tmp.string())));
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString qCacheDir = QString::fromStdString(tmp.string());
|
||||
|
||||
QFile zip{path};
|
||||
|
||||
// TODO(crueter): use QtCompress
|
||||
QStringList result = JlCompress::extractDir(&zip, qCacheDir);
|
||||
if (result.isEmpty()) {
|
||||
QtCommon::Frontend::Critical(tr("Mod Extract Failed"),
|
||||
tr("Zip file %1 is empty").arg(path));
|
||||
return QString();
|
||||
}
|
||||
|
||||
return qCacheDir;
|
||||
}
|
||||
|
||||
} // namespace QtCommon::Mod
|
||||
16
src/qt_common/util/mod.h
Normal file
16
src/qt_common/util/mod.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include "common/common_types.h"
|
||||
#include "frontend_common/mod_manager.h"
|
||||
|
||||
namespace QtCommon::Mod {
|
||||
|
||||
QStringList GetModFolders(const QString &root, const QString &fallbackName);
|
||||
|
||||
const QString ExtractMod(const QString &path);
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue