diff options
Diffstat (limited to 'logic/OneSixInstance.cpp')
-rw-r--r-- | logic/OneSixInstance.cpp | 301 |
1 files changed, 205 insertions, 96 deletions
diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 6f3018cb..7bac3424 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -13,52 +13,84 @@ * limitations under the License. */ -#include "OneSixInstance.h" - #include <QIcon> - -#include "OneSixInstance_p.h" -#include "OneSixUpdate.h" -#include "VersionFinal.h" -#include "pathutils.h" +#include <pathutils.h> #include "logger/QsLog.h" -#include "assets/AssetsUtils.h" #include "MultiMC.h" -#include "icons/IconList.h" -#include "MinecraftProcess.h" -#include "gui/dialogs/OneSixModEditDialog.h" -#include <MMCError.h> +#include "MMCError.h" + +#include "logic/OneSixInstance.h" -OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) +#include "logic/OneSixInstance_p.h" +#include "logic/OneSixUpdate.h" +#include "logic/minecraft/InstanceVersion.h" +#include "minecraft/VersionBuildError.h" + +#include "logic/assets/AssetsUtils.h" +#include "icons/IconList.h" +#include "logic/MinecraftProcess.h" +#include "gui/pagedialog/PageDialog.h" +#include "gui/pages/VersionPage.h" +#include <gui/pages/ModFolderPage.h> +#include <gui/pages/ResourcePackPage.h> +#include <gui/pages/TexturePackPage.h> +#include <gui/pages/InstanceSettingsPage.h> +#include <gui/pages/NotesPage.h> +#include <gui/pages/ScreenshotsPage.h> + +OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings, + QObject *parent) : BaseInstance(new OneSixInstancePrivate(), rootDir, settings, parent) { I_D(OneSixInstance); d->m_settings->registerSetting("IntendedVersion", ""); - d->m_settings->registerSetting("ShouldUpdate", false); - d->version.reset(new VersionFinal(this, this)); - d->vanillaVersion.reset(new VersionFinal(this, this)); + d->version.reset(new InstanceVersion(this, this)); } void OneSixInstance::init() { - // FIXME: why is this decided here? what does this even mean? - if (QDir(instanceRoot()).exists("version.json")) + try { - try - { - reloadVersion(); - } - catch(MMCError & e) - { - // QLOG_ERROR() << "Caught exception on instance init: " << e.cause(); - } + reloadVersion(); } - else + catch (MMCError &e) { - clearVersion(); + QLOG_ERROR() << "Caught exception on instance init: " << e.cause(); } } +QList<BasePage *> OneSixInstance::getPages() +{ + QList<BasePage *> values; + values.append(new VersionPage(this)); + values.append(new ModFolderPage(this, loaderModList(), "mods", "plugin-blue", tr("Loader mods"), + "Loader-mods")); + values.append(new ModFolderPage(this, coreModList(), "coremods", "plugin-green", tr("Core mods"), + "Core-mods")); + values.append(new ResourcePackPage(this)); + values.append(new TexturePackPage(this)); + values.append(new NotesPage(this)); + values.append(new ScreenshotsPage(this)); + values.append(new InstanceSettingsPage(this)); + return values; +} + +QString OneSixInstance::dialogTitle() +{ + return tr("Edit Instance (%1)").arg(name()); +} + +QSet<QString> OneSixInstance::traits() +{ + auto version = getFullVersion(); + if (!version) + { + return {"version-incomplete"}; + } + else + return version->traits; +} + std::shared_ptr<Task> OneSixInstance::doUpdate() { return std::shared_ptr<Task>(new OneSixUpdate(this)); @@ -88,7 +120,7 @@ QString replaceTokensIn(QString text, QMap<QString, QString> with) return result; } -QDir OneSixInstance::reconstructAssets(std::shared_ptr<VersionFinal> version) +QDir OneSixInstance::reconstructAssets(std::shared_ptr<InstanceVersion> version) { QDir assetsDir = QDir("assets/"); QDir indexDir = QDir(PathCombine(assetsDir.path(), "indexes")); @@ -126,7 +158,7 @@ QDir OneSixInstance::reconstructAssets(std::shared_ptr<VersionFinal> version) QString original_path = PathCombine(PathCombine(objectDir.path(), tlk), asset_object.hash); QFile original(original_path); - if(!original.exists()) + if (!original.exists()) continue; if (!target.exists()) { @@ -138,7 +170,7 @@ QDir OneSixInstance::reconstructAssets(std::shared_ptr<VersionFinal> version) bool couldCopy = original.copy(target_path); QLOG_DEBUG() << " Copying" << original_path << "to" << target_path - << QString::number(couldCopy); // << original.errorString(); + << QString::number(couldCopy); // << original.errorString(); } } @@ -189,7 +221,7 @@ QStringList OneSixInstance::processMinecraftArgs(AuthSessionPtr session) return parts; } -bool OneSixInstance::prepareForLaunch(AuthSessionPtr account, QString &launchScript) +bool OneSixInstance::prepareForLaunch(AuthSessionPtr session, QString &launchScript) { I_D(OneSixInstance); @@ -200,44 +232,79 @@ bool OneSixInstance::prepareForLaunch(AuthSessionPtr account, QString &launchScr auto version = d->version; if (!version) return nullptr; + + // libraries and class path. { auto libs = version->getActiveNormalLibs(); for (auto lib : libs) { launchScript += "cp " + librariesPath().absoluteFilePath(lib->storagePath()) + "\n"; } - QString targetstr = version->id + "/" + version->id + ".jar"; - launchScript += "cp " + versionsPath().absoluteFilePath(targetstr) + "\n"; + QString minecraftjarpath; + if (version->hasJarMods()) + { + for (auto jarmod : version->jarMods) + { + launchScript += "cp " + jarmodsPath().absoluteFilePath(jarmod->name) + "\n"; + } + minecraftjarpath = version->id + "/" + version->id + "-stripped.jar"; + } + else + { + minecraftjarpath = version->id + "/" + version->id + ".jar"; + } + launchScript += "cp " + versionsPath().absoluteFilePath(minecraftjarpath) + "\n"; + } + if (!version->mainClass.isEmpty()) + { + launchScript += "mainClass " + version->mainClass + "\n"; + } + if (!version->appletClass.isEmpty()) + { + launchScript += "appletClass " + version->appletClass + "\n"; } - launchScript += "mainClass " + version->mainClass + "\n"; - for (auto param : processMinecraftArgs(account)) + // generic minecraft params + for (auto param : processMinecraftArgs(session)) { launchScript += "param " + param + "\n"; } - // Set the width and height for 1.6 instances - bool maximize = settings().get("LaunchMaximized").toBool(); - if (maximize) + // window size, title and state, legacy { - // this is probably a BAD idea - // launchScript += "param --fullscreen\n"; + QString windowParams; + if (settings().get("LaunchMaximized").toBool()) + windowParams = "max"; + else + windowParams = QString("%1x%2") + .arg(settings().get("MinecraftWinWidth").toInt()) + .arg(settings().get("MinecraftWinHeight").toInt()); + launchScript += "windowTitle " + windowTitle() + "\n"; + launchScript += "windowParams " + windowParams + "\n"; } - else + + // legacy auth + { + launchScript += "userName " + session->player_name + "\n"; + launchScript += "sessionId " + session->session + "\n"; + } + + // native libraries (mostly LWJGL) { - launchScript += - "param --width\nparam " + settings().get("MinecraftWinWidth").toString() + "\n"; - launchScript += - "param --height\nparam " + settings().get("MinecraftWinHeight").toString() + "\n"; + QDir natives_dir(PathCombine(instanceRoot(), "natives/")); + for (auto native : version->getActiveNativeLibs()) + { + QFileInfo finfo(PathCombine("libraries", native->storagePath())); + launchScript += "ext " + finfo.absoluteFilePath() + "\n"; + } + launchScript += "natives " + natives_dir.absolutePath() + "\n"; } - QDir natives_dir(PathCombine(instanceRoot(), "natives/")); - launchScript += "windowTitle " + windowTitle() + "\n"; - for(auto native: version->getActiveNativeLibs()) + + // traits. including legacyLaunch and others ;) + for (auto trait : version->traits) { - QFileInfo finfo(PathCombine("libraries", native->storagePath())); - launchScript += "ext " + finfo.absoluteFilePath() + "\n"; + launchScript += "traits " + trait + "\n"; } - launchScript += "natives " + natives_dir.absolutePath() + "\n"; launchScript += "launcher onesix\n"; return true; } @@ -260,6 +327,17 @@ std::shared_ptr<ModList> OneSixInstance::loaderModList() return d->loader_mod_list; } +std::shared_ptr<ModList> OneSixInstance::coreModList() +{ + I_D(OneSixInstance); + if (!d->core_mod_list) + { + d->core_mod_list.reset(new ModList(coreModsDir())); + } + d->core_mod_list->update(); + return d->core_mod_list; +} + std::shared_ptr<ModList> OneSixInstance::resourcePackList() { I_D(OneSixInstance); @@ -271,15 +349,20 @@ std::shared_ptr<ModList> OneSixInstance::resourcePackList() return d->resource_pack_list; } -QDialog *OneSixInstance::createModEditDialog(QWidget *parent) +std::shared_ptr<ModList> OneSixInstance::texturePackList() { - return new OneSixModEditDialog(this, parent); + I_D(OneSixInstance); + if (!d->texture_pack_list) + { + d->texture_pack_list.reset(new ModList(texturePacksDir())); + } + d->texture_pack_list->update(); + return d->texture_pack_list; } bool OneSixInstance::setIntendedVersionId(QString version) { settings().set("IntendedVersion", version); - setShouldUpdate(true); QFile::remove(PathCombine(instanceRoot(), "version.json")); clearVersion(); return true; @@ -290,34 +373,31 @@ QString OneSixInstance::intendedVersionId() const return settings().get("IntendedVersion").toString(); } -void OneSixInstance::setShouldUpdate(bool val) +void OneSixInstance::setShouldUpdate(bool) { - settings().set("ShouldUpdate", val); } bool OneSixInstance::shouldUpdate() const { - QVariant var = settings().get("ShouldUpdate"); - if (!var.isValid() || var.toBool() == false) - { - return intendedVersionId() != currentVersionId(); - } return true; } bool OneSixInstance::versionIsCustom() { - QDir patches(PathCombine(instanceRoot(), "patches/")); - return (patches.exists() && patches.count() >= 0) - || QFile::exists(PathCombine(instanceRoot(), "custom.json")) - || QFile::exists(PathCombine(instanceRoot(), "user.json")); + I_D(const OneSixInstance); + auto ver = d->version; + if (ver) + { + return !ver->isVanilla(); + } + return false; } bool OneSixInstance::versionIsFTBPack() { I_D(const OneSixInstance); auto ver = d->version; - if(ver) + if (ver) { return ver->hasFtbPack(); } @@ -335,17 +415,18 @@ void OneSixInstance::reloadVersion() try { - d->version->reload(false, externalPatches()); - d->vanillaVersion->reload(true, externalPatches()); + d->version->reload(externalPatches()); d->m_flags.remove(VersionBrokenFlag); emit versionReloaded(); } - catch(MMCError & error) + catch (VersionIncomplete &error) + { + } + catch (MMCError &error) { d->version->clear(); - d->vanillaVersion->clear(); d->m_flags.insert(VersionBrokenFlag); - //TODO: rethrow to show some error message(s)? + // TODO: rethrow to show some error message(s)? emit versionReloaded(); throw; } @@ -355,22 +436,15 @@ void OneSixInstance::clearVersion() { I_D(OneSixInstance); d->version->clear(); - d->vanillaVersion->clear(); emit versionReloaded(); } -std::shared_ptr<VersionFinal> OneSixInstance::getFullVersion() const +std::shared_ptr<InstanceVersion> OneSixInstance::getFullVersion() const { I_D(const OneSixInstance); return d->version; } -std::shared_ptr<VersionFinal> OneSixInstance::getVanillaVersion() const -{ - I_D(const OneSixInstance); - return d->vanillaVersion; -} - QString OneSixInstance::defaultBaseJar() const { return "versions/" + intendedVersionId() + "/" + intendedVersionId() + ".jar"; @@ -381,37 +455,38 @@ QString OneSixInstance::defaultCustomBaseJar() const return PathCombine(instanceRoot(), "custom.jar"); } -bool OneSixInstance::menuActionEnabled(QString action_name) const +QString OneSixInstance::getStatusbarDescription() { - if (flags().contains(VersionBrokenFlag)) + QStringList traits; + if (versionIsCustom()) { - return false; + traits.append(tr("custom")); } - if (action_name == "actionChangeInstLWJGLVersion") + if (flags().contains(VersionBrokenFlag)) { - return false; + traits.append(tr("broken")); } - return true; -} -QString OneSixInstance::getStatusbarDescription() -{ - QString descr = "OneSix : " + intendedVersionId(); - if (versionIsCustom()) + if (traits.size()) { - descr += " (custom)"; + return tr("Minecraft %1 (%2)").arg(intendedVersionId()).arg(traits.join(", ")); } - if (flags().contains(VersionBrokenFlag)) + else { - descr += " (broken)"; + return tr("Minecraft %1").arg(intendedVersionId()); } - return descr; } QDir OneSixInstance::librariesPath() const { return QDir::current().absoluteFilePath("libraries"); } + +QDir OneSixInstance::jarmodsPath() const +{ + return QDir(jarModsDir()); +} + QDir OneSixInstance::versionsPath() const { return QDir::current().absoluteFilePath("versions"); @@ -429,7 +504,7 @@ bool OneSixInstance::providesVersionFile() const bool OneSixInstance::reload() { - if(BaseInstance::reload()) + if (BaseInstance::reload()) { try { @@ -449,12 +524,46 @@ QString OneSixInstance::loaderModsDir() const return PathCombine(minecraftRoot(), "mods"); } +QString OneSixInstance::coreModsDir() const +{ + return PathCombine(minecraftRoot(), "coremods"); +} + QString OneSixInstance::resourcePacksDir() const { return PathCombine(minecraftRoot(), "resourcepacks"); } +QString OneSixInstance::texturePacksDir() const +{ + return PathCombine(minecraftRoot(), "texturepacks"); +} + QString OneSixInstance::instanceConfigFolder() const { return PathCombine(minecraftRoot(), "config"); } + +QString OneSixInstance::jarModsDir() const +{ + return PathCombine(instanceRoot(), "jarmods"); +} + +QString OneSixInstance::libDir() const +{ + return PathCombine(minecraftRoot(), "lib"); +} + +QStringList OneSixInstance::extraArguments() const +{ + auto list = BaseInstance::extraArguments(); + auto version = getFullVersion(); + if (!version) + return list; + if (version->hasJarMods()) + { + list.append({"-Dfml.ignoreInvalidMinecraftCertificates=true", + "-Dfml.ignorePatchDiscrepancies=true"}); + } + return list; +} |