Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 8cf88ff

Browse files
committed
MultiMCGH-1314 add UI for custom minecraft jar addition
Also changes the text of the jar mod addition button. It should be clearer what it does and hopefully will not confuse as many people.
1 parent 117bfef commit 8cf88ff

16 files changed

+147
-52
lines changed

Diff for: api/logic/minecraft/MinecraftProfile.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,12 @@ void MinecraftProfile::installJarMods(QStringList selectedFiles)
664664
m_strategy->installJarMods(selectedFiles);
665665
}
666666

667+
void MinecraftProfile::installCustomJar(QString selectedFile)
668+
{
669+
m_strategy->installCustomJar(selectedFile);
670+
}
671+
672+
667673
/*
668674
* TODO: get rid of this. Get rid of all order numbers.
669675
*/

Diff for: api/logic/minecraft/MinecraftProfile.h

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class MULTIMC_LOGIC_EXPORT MinecraftProfile : public QAbstractListModel
5858
/// install more jar mods
5959
void installJarMods(QStringList selectedFiles);
6060

61+
/// install more jar mods
62+
void installCustomJar(QString selectedFile);
63+
6164
/// DEPRECATED, remove ASAP
6265
int getFreeOrderNumber();
6366

Diff for: api/logic/minecraft/ProfileStrategy.h

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class ProfileStrategy
2323
/// install a list of jar mods into the instance
2424
virtual bool installJarMods(QStringList filepaths) = 0;
2525

26+
/// install a custom jar (replaces the one from the Minecraft component)
27+
virtual bool installCustomJar(QString filepath) = 0;
28+
2629
/// remove any files or records that constitute the version patch
2730
virtual bool removePatch(ProfilePatchPtr jarMod) = 0;
2831

Diff for: api/logic/minecraft/ftb/FTBProfileStrategy.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ bool FTBProfileStrategy::installJarMods(QStringList filepaths)
118118
return false;
119119
}
120120

121+
bool FTBProfileStrategy::installCustomJar(QString filepath)
122+
{
123+
return false;
124+
}
125+
121126
bool FTBProfileStrategy::customizePatch(ProfilePatchPtr patch)
122127
{
123128
return false;

Diff for: api/logic/minecraft/ftb/FTBProfileStrategy.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ class FTBProfileStrategy : public OneSixProfileStrategy
99
public:
1010
FTBProfileStrategy(OneSixFTBInstance * instance);
1111
virtual ~FTBProfileStrategy() {};
12-
virtual void load() override;
13-
virtual bool resetOrder() override;
14-
virtual bool saveOrder(ProfileUtils::PatchOrder order) override;
15-
virtual bool installJarMods(QStringList filepaths) override;
16-
virtual bool customizePatch (ProfilePatchPtr patch) override;
17-
virtual bool revertPatch (ProfilePatchPtr patch) override;
12+
void load() override;
13+
bool resetOrder() override;
14+
bool saveOrder(ProfileUtils::PatchOrder order) override;
15+
bool installJarMods(QStringList filepaths) override;
16+
bool installCustomJar(QString filepath) override;
17+
bool customizePatch (ProfilePatchPtr patch) override;
18+
bool revertPatch (ProfilePatchPtr patch) override;
1819

1920
protected:
20-
virtual void loadDefaultBuiltinPatches() override;
21+
void loadDefaultBuiltinPatches() override;
2122
};

Diff for: api/logic/minecraft/onesix/OneSixInstance.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -637,11 +637,16 @@ QString OneSixInstance::jarModsDir() const
637637
return FS::PathCombine(instanceRoot(), "jarmods");
638638
}
639639

640-
QString OneSixInstance::libDir() const
640+
QString OneSixInstance::FMLlibDir() const
641641
{
642642
return FS::PathCombine(minecraftRoot(), "lib");
643643
}
644644

645+
QString OneSixInstance::customLibrariesDir() const
646+
{
647+
return FS::PathCombine(instanceRoot(), "libraries");
648+
}
649+
645650
QString OneSixInstance::worldDir() const
646651
{
647652
return FS::PathCombine(minecraftRoot(), "saves");

Diff for: api/logic/minecraft/onesix/OneSixInstance.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class MULTIMC_LOGIC_EXPORT OneSixInstance : public MinecraftInstance
4848
QString texturePacksDir() const;
4949
QString loaderModsDir() const;
5050
QString coreModsDir() const;
51-
QString libDir() const;
51+
QString FMLlibDir() const;
52+
QString customLibrariesDir() const;
5253
QString worldDir() const;
5354
virtual QString instanceConfigFolder() const override;
5455

Diff for: api/logic/minecraft/onesix/OneSixProfileStrategy.cpp

+64
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,67 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths)
405405
return true;
406406
}
407407

408+
bool OneSixProfileStrategy::installCustomJar(QString filepath)
409+
{
410+
QString patchDir = FS::PathCombine(m_instance->instanceRoot(), "patches");
411+
if(!FS::ensureFolderPathExists(patchDir))
412+
{
413+
return false;
414+
}
415+
416+
QString libDir = m_instance->customLibrariesDir();
417+
if (!FS::ensureFolderPathExists(libDir))
418+
{
419+
return false;
420+
}
421+
422+
auto specifier = GradleSpecifier("org.multimc:customjar:1");
423+
QFileInfo sourceInfo(filepath);
424+
QString target_filename = specifier.getFileName();
425+
QString target_id = specifier.artifactId();
426+
QString target_name = sourceInfo.completeBaseName() + " (custom jar)";
427+
QString finalPath = FS::PathCombine(libDir, target_filename);
428+
429+
QFileInfo jarInfo(finalPath);
430+
if (jarInfo.exists())
431+
{
432+
if(!QFile::remove(finalPath))
433+
{
434+
return false;
435+
}
436+
}
437+
if (!QFile::copy(filepath, finalPath))
438+
{
439+
return false;
440+
}
441+
442+
auto f = std::make_shared<VersionFile>();
443+
auto jarMod = std::make_shared<Library>();
444+
jarMod->setRawName(specifier);
445+
jarMod->setDisplayName(sourceInfo.completeBaseName());
446+
jarMod->setHint("local");
447+
f->mainJar = jarMod;
448+
f->name = target_name;
449+
f->uid = target_id;
450+
f->order = profile->getFreeOrderNumber();
451+
QString patchFileName = FS::PathCombine(patchDir, target_id + ".json");
452+
453+
QFile file(patchFileName);
454+
if (!file.open(QFile::WriteOnly))
455+
{
456+
qCritical() << "Error opening" << file.fileName()
457+
<< "for reading:" << file.errorString();
458+
return false;
459+
}
460+
file.write(OneSixVersionFormat::versionFileToJson(f, true).toJson());
461+
file.close();
462+
463+
auto patch = std::make_shared<ProfilePatch>(f, patchFileName);
464+
patch->setMovable(true);
465+
patch->setRemovable(true);
466+
profile->appendPatch(patch);
467+
468+
profile->saveCurrentOrder();
469+
profile->reapplyPatches();
470+
return true;
471+
}

Diff for: api/logic/minecraft/onesix/OneSixProfileStrategy.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ class OneSixProfileStrategy : public ProfileStrategy
88
public:
99
OneSixProfileStrategy(OneSixInstance * instance);
1010
virtual ~OneSixProfileStrategy() {};
11-
virtual void load() override;
12-
virtual bool resetOrder() override;
13-
virtual bool saveOrder(ProfileUtils::PatchOrder order) override;
14-
virtual bool installJarMods(QStringList filepaths) override;
15-
virtual bool removePatch(ProfilePatchPtr patch) override;
16-
virtual bool customizePatch(ProfilePatchPtr patch) override;
17-
virtual bool revertPatch(ProfilePatchPtr patch) override;
11+
void load() override;
12+
bool resetOrder() override;
13+
bool saveOrder(ProfileUtils::PatchOrder order) override;
14+
bool installJarMods(QStringList filepaths) override;
15+
bool installCustomJar(QString filepath) override;
16+
bool removePatch(ProfilePatchPtr patch) override;
17+
bool customizePatch(ProfilePatchPtr patch) override;
18+
bool revertPatch(ProfilePatchPtr patch) override;
1819

1920
protected:
2021
virtual void loadDefaultBuiltinPatches();

Diff for: api/logic/minecraft/onesix/update/FMLLibrariesTask.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void FMLLibrariesTask::executeTask()
4545
// now check the lib folder inside the instance for files.
4646
for (auto &lib : libList)
4747
{
48-
QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename));
48+
QFileInfo libInfo(FS::PathCombine(inst->FMLlibDir(), lib.filename));
4949
if (libInfo.exists())
5050
continue;
5151
fmlLibsToProcess.append(lib);
@@ -95,13 +95,13 @@ void FMLLibrariesTask::fmllibsFinished()
9595
{
9696
progress(index, fmlLibsToProcess.size());
9797
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
98-
auto path = FS::PathCombine(inst->libDir(), lib.filename);
98+
auto path = FS::PathCombine(inst->FMLlibDir(), lib.filename);
9999
if (!FS::ensureFilePathExists(path))
100100
{
101101
emitFailed(tr("Failed creating FML library folder inside the instance."));
102102
return;
103103
}
104-
if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->libDir(), lib.filename)))
104+
if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->FMLlibDir(), lib.filename)))
105105
{
106106
emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename));
107107
return;

Diff for: application/GuiUtil.cpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ void GuiUtil::setClipboardText(const QString &text)
5656
QApplication::clipboard()->setText(text);
5757
}
5858

59-
60-
QStringList GuiUtil::BrowseForFiles(QString context, QString caption, QString filter, QString defaultPath, QWidget *parentWidget)
59+
static QStringList BrowseForFileInternal(QString context, QString caption, QString filter, QString defaultPath, QWidget *parentWidget, bool single)
6160
{
6261
static QMap<QString, QString> savedPaths;
6362

@@ -82,7 +81,7 @@ QStringList GuiUtil::BrowseForFiles(QString context, QString caption, QString fi
8281
}
8382
urls.append(QUrl::fromLocalFile(defaultPath));
8483

85-
w.setFileMode(QFileDialog::ExistingFiles);
84+
w.setFileMode(single ? QFileDialog::ExistingFile : QFileDialog::ExistingFiles);
8685
w.setAcceptMode(QFileDialog::AcceptOpen);
8786
w.setNameFilter(filter);
8887

@@ -114,3 +113,19 @@ QStringList GuiUtil::BrowseForFiles(QString context, QString caption, QString fi
114113
savedPaths[context] = w.directory().absolutePath();
115114
return {};
116115
}
116+
117+
QString GuiUtil::BrowseForFile(QString context, QString caption, QString filter, QString defaultPath, QWidget *parentWidget)
118+
{
119+
auto resultList = BrowseForFileInternal(context, caption, filter, defaultPath, parentWidget, true);
120+
if(resultList.size())
121+
{
122+
return resultList[0];
123+
}
124+
return QString();
125+
}
126+
127+
128+
QStringList GuiUtil::BrowseForFiles(QString context, QString caption, QString filter, QString defaultPath, QWidget *parentWidget)
129+
{
130+
return BrowseForFileInternal(context, caption, filter, defaultPath, parentWidget, false);
131+
}

Diff for: application/GuiUtil.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ namespace GuiUtil
77
QString uploadPaste(const QString &text, QWidget *parentWidget);
88
void setClipboardText(const QString &text);
99
QStringList BrowseForFiles(QString context, QString caption, QString filter, QString defaultPath, QWidget *parentWidget);
10+
QString BrowseForFile(QString context, QString caption, QString filter, QString defaultPath, QWidget *parentWidget);
1011
}

Diff for: application/MultiMC.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,6 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
501501

502502
m_settings->registerSetting("UpdateDialogGeometry", "");
503503

504-
// Jar mod nag dialog in version page
505-
m_settings->registerSetting("JarModNagSeen", false);
506-
507504
// paste.ee API key
508505
m_settings->registerSetting("PasteEEAPIKey", "multimc");
509506

Diff for: application/pages/VersionPage.cpp

+10-24
Original file line numberDiff line numberDiff line change
@@ -250,34 +250,20 @@ void VersionPage::on_modBtn_clicked()
250250

251251
void VersionPage::on_jarmodBtn_clicked()
252252
{
253-
bool nagShown = false;
254-
if (!m_profile->hasTrait("legacyLaunch") && !m_profile->hasTrait("alphaLaunch"))
255-
{
256-
// not legacy launch... nag
257-
auto seenNag = MMC->settings()->get("JarModNagSeen").toBool();
258-
if(!seenNag)
259-
{
260-
auto result = QMessageBox::question(this,
261-
tr("Are you sure?"),
262-
tr("This will add mods directly to the Minecraft jar.\n"
263-
"Unless you KNOW that this is what NEEDS to be done, you should just use the mods folder (Loader mods).\n"
264-
"\n"
265-
"Do you want to continue?"),
266-
tr("I understand, continue."), tr("Cancel"), QString(), 1, 1
267-
);
268-
if(result != 0)
269-
return;
270-
nagShown = true;
271-
}
272-
}
273253
auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget());
274254
if(!list.empty())
275255
{
276256
m_profile->installJarMods(list);
277-
if(nagShown)
278-
{
279-
MMC->settings()->set("JarModNagSeen", QVariant(true));
280-
}
257+
}
258+
updateButtons();
259+
}
260+
261+
void VersionPage::on_jarBtn_clicked()
262+
{
263+
auto jarPath = GuiUtil::BrowseForFile("jar", tr("Select jar"), tr("Minecraft.jar replacement (*.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget());
264+
if(!jarPath.isEmpty())
265+
{
266+
m_profile->installCustomJar(jarPath);
281267
}
282268
updateButtons();
283269
}

Diff for: application/pages/VersionPage.h

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ private slots:
5858
void on_moveUpBtn_clicked();
5959
void on_moveDownBtn_clicked();
6060
void on_jarmodBtn_clicked();
61+
void on_jarBtn_clicked();
6162
void on_revertBtn_clicked();
6263
void on_editBtn_clicked();
6364
void on_modBtn_clicked();

Diff for: application/pages/VersionPage.ui

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>693</width>
10-
<height>750</height>
10+
<height>788</height>
1111
</rect>
1212
</property>
1313
<layout class="QVBoxLayout" name="verticalLayout">
@@ -206,7 +206,14 @@
206206
<string>Add a mod into the Minecraft jar file.</string>
207207
</property>
208208
<property name="text">
209-
<string>Add jar mod</string>
209+
<string>Add to Minecraft.jar</string>
210+
</property>
211+
</widget>
212+
</item>
213+
<item>
214+
<widget class="QPushButton" name="jarBtn">
215+
<property name="text">
216+
<string>Replace Minecraft.jar</string>
210217
</property>
211218
</widget>
212219
</item>
@@ -281,7 +288,6 @@
281288
</customwidget>
282289
</customwidgets>
283290
<tabstops>
284-
<tabstop>tabWidget</tabstop>
285291
<tabstop>packageView</tabstop>
286292
<tabstop>changeVersionBtn</tabstop>
287293
<tabstop>moveUpBtn</tabstop>

0 commit comments

Comments
 (0)