Skip to content

Commit 988d07e

Browse files
authored
Merge branch 'PrismLauncher:develop' into develop
2 parents aa5c022 + f4f1d5f commit 988d07e

16 files changed

+127
-128
lines changed

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

launcher/Application.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
616616
m_settings->registerSetting("IconsDir", "icons");
617617
m_settings->registerSetting("DownloadsDir", QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
618618
m_settings->registerSetting("DownloadsDirWatchRecursive", false);
619+
m_settings->registerSetting("MoveModsFromDownloadsDir", false);
619620
m_settings->registerSetting("SkinsDir", "skins");
620621
m_settings->registerSetting("JavaDir", "java");
621622

launcher/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,6 @@ SET(LAUNCHER_SOURCES
10851085
ui/widgets/CustomCommands.h
10861086
ui/widgets/EnvironmentVariables.cpp
10871087
ui/widgets/EnvironmentVariables.h
1088-
ui/widgets/DropLabel.cpp
1089-
ui/widgets/DropLabel.h
10901088
ui/widgets/FocusLineEdit.cpp
10911089
ui/widgets/FocusLineEdit.h
10921090
ui/widgets/IconLabel.cpp

launcher/icons/IconList.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ void IconList::directoryChanged(const QString& path)
196196
qDebug() << "Adding icon " << addedPath;
197197

198198
QFileInfo addfile(addedPath);
199-
QString key = m_dir.relativeFilePath(addfile.absoluteFilePath());
199+
QString relativePath = m_dir.relativeFilePath(addfile.absoluteFilePath());
200+
QString key = QFileInfo(relativePath).completeBaseName();
200201
QString name = formatName(m_dir, addfile);
201202

202203
if (addIcon(key, name, addfile.filePath(), IconType::FileBased)) {

launcher/minecraft/MinecraftLoadAndCheck.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ void MinecraftLoadAndCheck::executeTask()
88
{
99
// add offline metadata load task
1010
auto components = m_inst->getPackProfile();
11-
components->reload(m_netmode);
11+
if (auto result = components->reload(m_netmode); !result) {
12+
emitFailed(result.error);
13+
return;
14+
}
1215
m_task = components->getCurrentTask();
1316

1417
if (!m_task) {

launcher/minecraft/PackProfile.cpp

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -173,29 +173,32 @@ static bool savePackProfile(const QString& filename, const ComponentContainer& c
173173
}
174174

175175
// Read the given file into component containers
176-
static bool loadPackProfile(PackProfile* parent,
177-
const QString& filename,
178-
const QString& componentJsonPattern,
179-
ComponentContainer& container)
176+
static PackProfile::Result loadPackProfile(PackProfile* parent,
177+
const QString& filename,
178+
const QString& componentJsonPattern,
179+
ComponentContainer& container)
180180
{
181181
QFile componentsFile(filename);
182182
if (!componentsFile.exists()) {
183-
qCWarning(instanceProfileC) << "Components file" << filename << "doesn't exist. This should never happen.";
184-
return false;
183+
auto message = QObject::tr("Components file %1 doesn't exist. This should never happen.").arg(filename);
184+
qCWarning(instanceProfileC) << message;
185+
return PackProfile::Result::Error(message);
185186
}
186187
if (!componentsFile.open(QFile::ReadOnly)) {
187-
qCCritical(instanceProfileC) << "Couldn't open" << componentsFile.fileName() << " for reading:" << componentsFile.errorString();
188+
auto message = QObject::tr("Couldn't open %1 for reading: %2").arg(componentsFile.fileName(), componentsFile.errorString());
189+
qCCritical(instanceProfileC) << message;
188190
qCWarning(instanceProfileC) << "Ignoring overridden order";
189-
return false;
191+
return PackProfile::Result::Error(message);
190192
}
191193

192194
// and it's valid JSON
193195
QJsonParseError error;
194196
QJsonDocument doc = QJsonDocument::fromJson(componentsFile.readAll(), &error);
195197
if (error.error != QJsonParseError::NoError) {
196-
qCCritical(instanceProfileC) << "Couldn't parse" << componentsFile.fileName() << ":" << error.errorString();
198+
auto message = QObject::tr("Couldn't parse %1 as json: %2").arg(componentsFile.fileName(), error.errorString());
199+
qCCritical(instanceProfileC) << message;
197200
qCWarning(instanceProfileC) << "Ignoring overridden order";
198-
return false;
201+
return PackProfile::Result::Error(message);
199202
}
200203

201204
// and then read it and process it if all above is true.
@@ -212,11 +215,13 @@ static bool loadPackProfile(PackProfile* parent,
212215
container.append(componentFromJsonV1(parent, componentJsonPattern, comp_obj));
213216
}
214217
} catch ([[maybe_unused]] const JSONValidationError& err) {
215-
qCCritical(instanceProfileC) << "Couldn't parse" << componentsFile.fileName() << ": bad file format";
218+
auto message = QObject::tr("Couldn't parse %1 : bad file format").arg(componentsFile.fileName());
219+
qCCritical(instanceProfileC) << message;
220+
qCWarning(instanceProfileC) << "error:" << err.what();
216221
container.clear();
217-
return false;
222+
return PackProfile::Result::Error(message);
218223
}
219-
return true;
224+
return PackProfile::Result::Success();
220225
}
221226

222227
// END: component file format
@@ -283,44 +288,43 @@ void PackProfile::save_internal()
283288
d->dirty = false;
284289
}
285290

286-
bool PackProfile::load()
291+
PackProfile::Result PackProfile::load()
287292
{
288293
auto filename = componentsFilePath();
289294

290295
// load the new component list and swap it with the current one...
291296
ComponentContainer newComponents;
292-
if (!loadPackProfile(this, filename, patchesPattern(), newComponents)) {
297+
if (auto result = loadPackProfile(this, filename, patchesPattern(), newComponents); !result) {
293298
qCritical() << d->m_instance->name() << "|" << "Failed to load the component config";
294-
return false;
295-
} else {
296-
// FIXME: actually use fine-grained updates, not this...
297-
beginResetModel();
298-
// disconnect all the old components
299-
for (auto component : d->components) {
300-
disconnect(component.get(), &Component::dataChanged, this, &PackProfile::componentDataChanged);
301-
}
302-
d->components.clear();
303-
d->componentIndex.clear();
304-
for (auto component : newComponents) {
305-
if (d->componentIndex.contains(component->m_uid)) {
306-
qWarning() << d->m_instance->name() << "|" << "Ignoring duplicate component entry" << component->m_uid;
307-
continue;
308-
}
309-
connect(component.get(), &Component::dataChanged, this, &PackProfile::componentDataChanged);
310-
d->components.append(component);
311-
d->componentIndex[component->m_uid] = component;
299+
return result;
300+
}
301+
// FIXME: actually use fine-grained updates, not this...
302+
beginResetModel();
303+
// disconnect all the old components
304+
for (auto component : d->components) {
305+
disconnect(component.get(), &Component::dataChanged, this, &PackProfile::componentDataChanged);
306+
}
307+
d->components.clear();
308+
d->componentIndex.clear();
309+
for (auto component : newComponents) {
310+
if (d->componentIndex.contains(component->m_uid)) {
311+
qWarning() << d->m_instance->name() << "|" << "Ignoring duplicate component entry" << component->m_uid;
312+
continue;
312313
}
313-
endResetModel();
314-
d->loaded = true;
315-
return true;
314+
connect(component.get(), &Component::dataChanged, this, &PackProfile::componentDataChanged);
315+
d->components.append(component);
316+
d->componentIndex[component->m_uid] = component;
316317
}
318+
endResetModel();
319+
d->loaded = true;
320+
return Result::Success();
317321
}
318322

319-
void PackProfile::reload(Net::Mode netmode)
323+
PackProfile::Result PackProfile::reload(Net::Mode netmode)
320324
{
321325
// Do not reload when the update/resolve task is running. It is in control.
322326
if (d->m_updateTask) {
323-
return;
327+
return Result::Success();
324328
}
325329

326330
// flush any scheduled saves to not lose state
@@ -329,9 +333,11 @@ void PackProfile::reload(Net::Mode netmode)
329333
// FIXME: differentiate when a reapply is required by propagating state from components
330334
invalidateLaunchProfile();
331335

332-
if (load()) {
333-
resolve(netmode);
336+
if (auto result = load(); !result) {
337+
return result;
334338
}
339+
resolve(netmode);
340+
return Result::Success();
335341
}
336342

337343
Task::Ptr PackProfile::getCurrentTask()

launcher/minecraft/PackProfile.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ class PackProfile : public QAbstractListModel {
6262
public:
6363
enum Columns { NameColumn = 0, VersionColumn, NUM_COLUMNS };
6464

65+
struct Result {
66+
bool success;
67+
QString error;
68+
69+
// Implicit conversion to bool
70+
operator bool() const { return success; }
71+
72+
// Factory methods for convenience
73+
static Result Success() { return { true, "" }; }
74+
75+
static Result Error(const QString& errorMessage) { return { false, errorMessage }; }
76+
};
77+
6578
explicit PackProfile(MinecraftInstance* instance);
6679
virtual ~PackProfile();
6780

@@ -102,7 +115,7 @@ class PackProfile : public QAbstractListModel {
102115
bool revertToBase(int index);
103116

104117
/// reload the list, reload all components, resolve dependencies
105-
void reload(Net::Mode netmode);
118+
Result reload(Net::Mode netmode);
106119

107120
// reload all components, resolve dependencies
108121
void resolve(Net::Mode netmode);
@@ -169,7 +182,7 @@ class PackProfile : public QAbstractListModel {
169182
void disableInteraction(bool disable);
170183

171184
private:
172-
bool load();
185+
Result load();
173186
bool installJarMods_internal(QStringList filepaths);
174187
bool installCustomJar_internal(QString filepath);
175188
bool installAgents_internal(QStringList filepaths);

launcher/modplatform/flame/FlameInstanceCreationTask.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,14 @@ void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods)
597597

598598
qDebug() << "Will try to copy" << mod.localPath << "to" << destPath;
599599

600-
if (!FS::copy(mod.localPath, destPath)()) {
601-
qDebug() << "Copy of" << mod.localPath << "to" << destPath << "Failed";
600+
if (mod.move) {
601+
if (!FS::move(mod.localPath, destPath)) {
602+
qDebug() << "Move of" << mod.localPath << "to" << destPath << "Failed";
603+
}
604+
} else {
605+
if (!FS::copy(mod.localPath, destPath)()) {
606+
qDebug() << "Copy of" << mod.localPath << "to" << destPath << "Failed";
607+
}
602608
}
603609

604610
i++;

launcher/ui/dialogs/BlockedModsDialog.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,18 @@ void BlockedModsDialog::checkMatchHash(QString hash, QString path)
288288

289289
qDebug() << "[Blocked Mods Dialog] Checking for match on hash: " << hash << "| From path:" << path;
290290

291+
auto downloadDir = QFileInfo(APPLICATION->settings()->get("DownloadsDir").toString()).absoluteFilePath();
292+
auto moveFiles = APPLICATION->settings()->get("MoveModsFromDownloadsDir").toBool();
291293
for (auto& mod : m_mods) {
292294
if (mod.matched) {
293295
continue;
294296
}
295297
if (mod.hash.compare(hash, Qt::CaseInsensitive) == 0) {
296298
mod.matched = true;
297299
mod.localPath = path;
300+
if (moveFiles) {
301+
mod.move = QFileInfo(path).absoluteFilePath().startsWith(downloadDir);
302+
}
298303
match = true;
299304

300305
qDebug() << "[Blocked Mods Dialog] Hash match found:" << mod.name << hash << "| From path:" << path;
@@ -346,13 +351,18 @@ bool BlockedModsDialog::checkValidPath(QString path)
346351
return fsName.compare(metaName) == 0;
347352
};
348353

354+
auto downloadDir = QFileInfo(APPLICATION->settings()->get("DownloadsDir").toString()).absoluteFilePath();
355+
auto moveFiles = APPLICATION->settings()->get("MoveModsFromDownloadsDir").toBool();
349356
for (auto& mod : m_mods) {
350357
if (compare(filename, mod.name)) {
351358
// if the mod is not yet matched and doesn't have a hash then
352359
// just match it with the file that has the exact same name
353360
if (!mod.matched && mod.hash.isEmpty()) {
354361
mod.matched = true;
355362
mod.localPath = path;
363+
if (moveFiles) {
364+
mod.move = QFileInfo(path).absoluteFilePath().startsWith(downloadDir);
365+
}
356366
return false;
357367
}
358368
qDebug() << "[Blocked Mods Dialog] Name match found:" << mod.name << "| From path:" << path;

launcher/ui/dialogs/BlockedModsDialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct BlockedMod {
4242
bool matched;
4343
QString localPath;
4444
QString targetFolder;
45+
bool move = false;
4546
};
4647

4748
QT_BEGIN_NAMESPACE

launcher/ui/pages/global/LauncherPage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ void LauncherPage::applySettings()
235235
s->set("SkinsDir", ui->skinsDirTextBox->text());
236236
s->set("JavaDir", ui->javaDirTextBox->text());
237237
s->set("DownloadsDirWatchRecursive", ui->downloadsDirWatchRecursiveCheckBox->isChecked());
238+
s->set("MoveModsFromDownloadsDir", ui->downloadsDirMoveCheckBox->isChecked());
238239

239240
auto sortMode = (InstSortMode)ui->sortingModeGroup->checkedId();
240241
switch (sortMode) {
@@ -302,6 +303,7 @@ void LauncherPage::loadSettings()
302303
ui->skinsDirTextBox->setText(s->get("SkinsDir").toString());
303304
ui->javaDirTextBox->setText(s->get("JavaDir").toString());
304305
ui->downloadsDirWatchRecursiveCheckBox->setChecked(s->get("DownloadsDirWatchRecursive").toBool());
306+
ui->downloadsDirMoveCheckBox->setChecked(s->get("MoveModsFromDownloadsDir").toBool());
305307

306308
QString sortMode = s->get("InstSortMode").toString();
307309

0 commit comments

Comments
 (0)