NOISSUE redo new instance dialog
This commit is contained in:
@ -8,14 +8,10 @@ set(CORE_SOURCES
|
||||
BaseInstaller.cpp
|
||||
BaseVersionList.h
|
||||
BaseVersionList.cpp
|
||||
InstanceCreationTask.h
|
||||
InstanceCreationTask.cpp
|
||||
InstanceCopyTask.h
|
||||
InstanceCopyTask.cpp
|
||||
InstanceImportTask.h
|
||||
InstanceImportTask.cpp
|
||||
InstanceList.h
|
||||
InstanceList.cpp
|
||||
InstanceTask.h
|
||||
InstanceTask.cpp
|
||||
LoggedProcess.h
|
||||
LoggedProcess.cpp
|
||||
MessageLevel.cpp
|
||||
@ -32,6 +28,14 @@ set(CORE_SOURCES
|
||||
MMCStrings.h
|
||||
MMCStrings.cpp
|
||||
|
||||
# Basic instance manipulation tasks (derived from InstanceTask)
|
||||
InstanceCreationTask.h
|
||||
InstanceCreationTask.cpp
|
||||
InstanceCopyTask.h
|
||||
InstanceCopyTask.cpp
|
||||
InstanceImportTask.h
|
||||
InstanceImportTask.cpp
|
||||
|
||||
# Use tracking separate from memory management
|
||||
Usable.h
|
||||
|
||||
@ -42,6 +46,10 @@ set(CORE_SOURCES
|
||||
Env.h
|
||||
Env.cpp
|
||||
|
||||
# String filters
|
||||
Filter.h
|
||||
Filter.cpp
|
||||
|
||||
# JSON parsing helpers
|
||||
Json.h
|
||||
Json.cpp
|
||||
|
31
api/logic/Filter.cpp
Normal file
31
api/logic/Filter.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include "Filter.h"
|
||||
|
||||
Filter::~Filter(){}
|
||||
|
||||
ContainsFilter::ContainsFilter(const QString& pattern) : pattern(pattern){}
|
||||
ContainsFilter::~ContainsFilter(){}
|
||||
bool ContainsFilter::accepts(const QString& value)
|
||||
{
|
||||
return value.contains(pattern);
|
||||
}
|
||||
|
||||
ExactFilter::ExactFilter(const QString& pattern) : pattern(pattern){}
|
||||
ExactFilter::~ExactFilter(){}
|
||||
bool ExactFilter::accepts(const QString& value)
|
||||
{
|
||||
return value.contains(pattern);
|
||||
}
|
||||
|
||||
RegexpFilter::RegexpFilter(const QString& regexp, bool invert)
|
||||
:invert(invert)
|
||||
{
|
||||
pattern.setPattern(regexp);
|
||||
pattern.optimize();
|
||||
}
|
||||
RegexpFilter::~RegexpFilter(){}
|
||||
bool RegexpFilter::accepts(const QString& value)
|
||||
{
|
||||
auto match = pattern.match(value);
|
||||
bool matched = match.hasMatch();
|
||||
return invert ? (!matched) : (matched);
|
||||
}
|
44
api/logic/Filter.h
Normal file
44
api/logic/Filter.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "multimc_logic_export.h"
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT Filter
|
||||
{
|
||||
public:
|
||||
virtual ~Filter();
|
||||
virtual bool accepts(const QString & value) = 0;
|
||||
};
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT ContainsFilter: public Filter
|
||||
{
|
||||
public:
|
||||
ContainsFilter(const QString &pattern);
|
||||
virtual ~ContainsFilter();
|
||||
bool accepts(const QString & value) override;
|
||||
private:
|
||||
QString pattern;
|
||||
};
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT ExactFilter: public Filter
|
||||
{
|
||||
public:
|
||||
ExactFilter(const QString &pattern);
|
||||
virtual ~ExactFilter();
|
||||
bool accepts(const QString & value) override;
|
||||
private:
|
||||
QString pattern;
|
||||
};
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT RegexpFilter: public Filter
|
||||
{
|
||||
public:
|
||||
RegexpFilter(const QString ®exp, bool invert);
|
||||
virtual ~RegexpFilter();
|
||||
bool accepts(const QString & value) override;
|
||||
private:
|
||||
QRegularExpression pattern;
|
||||
bool invert = false;
|
||||
};
|
@ -412,46 +412,13 @@ private:
|
||||
QTimer m_backoffTimer;
|
||||
};
|
||||
|
||||
#include "InstanceImportTask.h"
|
||||
Task * FolderInstanceProvider::zipImportTask(const QUrl sourceUrl, const QString& instName, const QString& instGroup, const QString& instIcon)
|
||||
#include "InstanceTask.h"
|
||||
Task * FolderInstanceProvider::wrapInstanceTask(InstanceTask * task)
|
||||
{
|
||||
auto stagingPath = getStagedInstancePath();
|
||||
auto task = new InstanceImportTask(m_globalSettings, sourceUrl, stagingPath, instName, instIcon, instGroup);
|
||||
return new FolderInstanceStaging(this, task, stagingPath, instName, instGroup);
|
||||
}
|
||||
|
||||
#include "InstanceCreationTask.h"
|
||||
Task * FolderInstanceProvider::creationTask(BaseVersionPtr version, const QString& instName, const QString& instGroup, const QString& instIcon)
|
||||
{
|
||||
auto stagingPath = getStagedInstancePath();
|
||||
auto task = new InstanceCreationTask(m_globalSettings, stagingPath, version, instName, instIcon, instGroup);
|
||||
return new FolderInstanceStaging(this, task, stagingPath, instName, instGroup);
|
||||
}
|
||||
|
||||
#include <modplatform/ftb/FtbPackInstallTask.h>
|
||||
Task * FolderInstanceProvider::ftbCreationTask(FtbPackDownloader *downloader, const QString& instName, const QString& instGroup, const QString& instIcon)
|
||||
{
|
||||
auto stagingPath = getStagedInstancePath();
|
||||
auto task = new FtbPackInstallTask(downloader, m_globalSettings, stagingPath, instName, instIcon, instGroup);
|
||||
return new FolderInstanceStaging(this, task, stagingPath, instName, instGroup);
|
||||
}
|
||||
|
||||
#include "InstanceCopyTask.h"
|
||||
Task * FolderInstanceProvider::copyTask(const InstancePtr& oldInstance, const QString& instName, const QString& instGroup, const QString& instIcon, bool copySaves)
|
||||
{
|
||||
auto stagingPath = getStagedInstancePath();
|
||||
auto task = new InstanceCopyTask(m_globalSettings, stagingPath, oldInstance, instName, instIcon, instGroup, copySaves);
|
||||
return new FolderInstanceStaging(this, task, stagingPath, instName, instGroup);
|
||||
}
|
||||
|
||||
// FIXME: find a better place for this
|
||||
#include "minecraft/legacy/LegacyUpgradeTask.h"
|
||||
Task * FolderInstanceProvider::legacyUpgradeTask(const InstancePtr& oldInstance)
|
||||
{
|
||||
auto stagingPath = getStagedInstancePath();
|
||||
QString newName = tr("%1 (Migrated)").arg(oldInstance->name());
|
||||
auto task = new LegacyUpgradeTask(m_globalSettings, stagingPath, oldInstance, newName);
|
||||
return new FolderInstanceStaging(this, task, stagingPath, newName, oldInstance->group());
|
||||
task->setStagingPath(stagingPath);
|
||||
task->setParentSettings(m_globalSettings);
|
||||
return new FolderInstanceStaging(this, task, stagingPath, task->name(), task->group());
|
||||
}
|
||||
|
||||
QString FolderInstanceProvider::getStagedInstancePath()
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
#include "BaseInstanceProvider.h"
|
||||
#include <QMap>
|
||||
#include <modplatform/ftb/FtbPackDownloader.h>
|
||||
|
||||
class QFileSystemWatcher;
|
||||
class InstanceTask;
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT FolderInstanceProvider : public BaseInstanceProvider
|
||||
{
|
||||
@ -20,6 +20,7 @@ public:
|
||||
InstancePtr loadInstance(const InstanceId& id) override;
|
||||
|
||||
|
||||
/*
|
||||
// create instance in this provider
|
||||
Task * creationTask(BaseVersionPtr version, const QString &instName, const QString &instGroup, const QString &instIcon);
|
||||
|
||||
@ -34,6 +35,10 @@ public:
|
||||
|
||||
// migrate an instance to the current format
|
||||
Task * legacyUpgradeTask(const InstancePtr& oldInstance);
|
||||
*/
|
||||
|
||||
// Wrap an instance creation task in some more task machinery and make it ready to be used
|
||||
Task * wrapInstanceTask(InstanceTask * task);
|
||||
|
||||
/**
|
||||
* Create a new empty staging area for instance creation and @return a path/key top commit it later.
|
||||
|
@ -6,14 +6,9 @@
|
||||
#include "pathmatcher/RegexpMatcher.h"
|
||||
#include <QtConcurrentRun>
|
||||
|
||||
InstanceCopyTask::InstanceCopyTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString& instName, const QString& instIcon, const QString& instGroup, bool copySaves)
|
||||
InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, bool copySaves)
|
||||
{
|
||||
m_globalSettings = settings;
|
||||
m_stagingPath = stagingPath;
|
||||
m_origInstance = origInstance;
|
||||
m_instName = instName;
|
||||
m_instIcon = instIcon;
|
||||
m_instGroup = instGroup;
|
||||
|
||||
if(!copySaves)
|
||||
{
|
||||
|
@ -9,16 +9,15 @@
|
||||
#include "settings/SettingsObject.h"
|
||||
#include "BaseVersion.h"
|
||||
#include "BaseInstance.h"
|
||||
|
||||
#include "InstanceTask.h"
|
||||
|
||||
class BaseInstanceProvider;
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT InstanceCopyTask : public Task
|
||||
class MULTIMC_LOGIC_EXPORT InstanceCopyTask : public InstanceTask
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InstanceCopyTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString &instName,
|
||||
const QString &instIcon, const QString &instGroup, bool copySaves);
|
||||
explicit InstanceCopyTask(InstancePtr origInstance, bool copySaves);
|
||||
|
||||
protected:
|
||||
//! Entry point for tasks.
|
||||
@ -27,15 +26,8 @@ protected:
|
||||
void copyAborted();
|
||||
|
||||
private: /* data */
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
InstancePtr m_origInstance;
|
||||
QString m_instName;
|
||||
QString m_instIcon;
|
||||
QString m_instGroup;
|
||||
QString m_stagingPath;
|
||||
QFuture<bool> m_copyFuture;
|
||||
QFutureWatcher<bool> m_copyFutureWatcher;
|
||||
std::unique_ptr<IPathMatcher> m_matcher;
|
||||
};
|
||||
|
||||
|
||||
|
@ -7,14 +7,8 @@
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/ComponentList.h"
|
||||
|
||||
InstanceCreationTask::InstanceCreationTask(SettingsObjectPtr settings, const QString & stagingPath, BaseVersionPtr version,
|
||||
const QString& instName, const QString& instIcon, const QString& instGroup)
|
||||
InstanceCreationTask::InstanceCreationTask(BaseVersionPtr version)
|
||||
{
|
||||
m_globalSettings = settings;
|
||||
m_stagingPath = stagingPath;
|
||||
m_instName = instName;
|
||||
m_instIcon = instIcon;
|
||||
m_instGroup = instGroup;
|
||||
m_version = version;
|
||||
}
|
||||
|
||||
|
@ -6,24 +6,18 @@
|
||||
#include <QUrl>
|
||||
#include "settings/SettingsObject.h"
|
||||
#include "BaseVersion.h"
|
||||
#include "InstanceTask.h"
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT InstanceCreationTask : public Task
|
||||
class MULTIMC_LOGIC_EXPORT InstanceCreationTask : public InstanceTask
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InstanceCreationTask(SettingsObjectPtr settings, const QString & stagingPath, BaseVersionPtr version, const QString &instName,
|
||||
const QString &instIcon, const QString &instGroup);
|
||||
explicit InstanceCreationTask(BaseVersionPtr version);
|
||||
|
||||
protected:
|
||||
//! Entry point for tasks.
|
||||
virtual void executeTask() override;
|
||||
|
||||
private: /* data */
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
QString m_stagingPath;
|
||||
BaseVersionPtr m_version;
|
||||
QString m_instName;
|
||||
QString m_instIcon;
|
||||
QString m_instGroup;
|
||||
};
|
||||
|
||||
|
@ -16,15 +16,9 @@
|
||||
#include "modplatform/flame/PackManifest.h"
|
||||
#include "Json.h"
|
||||
|
||||
InstanceImportTask::InstanceImportTask(SettingsObjectPtr settings, const QUrl sourceUrl, const QString & stagingPath,
|
||||
const QString &instName, const QString &instIcon, const QString &instGroup)
|
||||
InstanceImportTask::InstanceImportTask(const QUrl sourceUrl)
|
||||
{
|
||||
m_globalSettings = settings;
|
||||
m_sourceUrl = sourceUrl;
|
||||
m_stagingPath = stagingPath;
|
||||
m_instName = instName;
|
||||
m_instIcon = instIcon;
|
||||
m_instGroup = instGroup;
|
||||
}
|
||||
|
||||
void InstanceImportTask::executeTask()
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "tasks/Task.h"
|
||||
#include "InstanceTask.h"
|
||||
#include "multimc_logic_export.h"
|
||||
#include "net/NetJob.h"
|
||||
#include <QUrl>
|
||||
@ -16,12 +16,11 @@ namespace Flame
|
||||
class FileResolvingTask;
|
||||
}
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT InstanceImportTask : public Task
|
||||
class MULTIMC_LOGIC_EXPORT InstanceImportTask : public InstanceTask
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InstanceImportTask(SettingsObjectPtr settings, const QUrl sourceUrl, const QString & stagingPath, const QString &instName,
|
||||
const QString &instIcon, const QString &instGroup);
|
||||
explicit InstanceImportTask(const QUrl sourceUrl);
|
||||
|
||||
protected:
|
||||
//! Entry point for tasks.
|
||||
@ -40,16 +39,11 @@ private slots:
|
||||
void extractAborted();
|
||||
|
||||
private: /* data */
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
NetJobPtr m_filesNetJob;
|
||||
shared_qobject_ptr<Flame::FileResolvingTask> m_modIdResolver;
|
||||
QUrl m_sourceUrl;
|
||||
QString m_archivePath;
|
||||
bool m_downloadRequired = false;
|
||||
QString m_instName;
|
||||
QString m_instIcon;
|
||||
QString m_instGroup;
|
||||
QString m_stagingPath;
|
||||
std::unique_ptr<QuaZip> m_packZip;
|
||||
QFuture<QStringList> m_extractFuture;
|
||||
QFutureWatcher<QStringList> m_extractFutureWatcher;
|
||||
|
9
api/logic/InstanceTask.cpp
Normal file
9
api/logic/InstanceTask.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "InstanceTask.h"
|
||||
|
||||
InstanceTask::InstanceTask()
|
||||
{
|
||||
}
|
||||
|
||||
InstanceTask::~InstanceTask()
|
||||
{
|
||||
}
|
55
api/logic/InstanceTask.h
Normal file
55
api/logic/InstanceTask.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "tasks/Task.h"
|
||||
#include "multimc_logic_export.h"
|
||||
#include "settings/SettingsObject.h"
|
||||
|
||||
class BaseInstanceProvider;
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT InstanceTask : public Task
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InstanceTask();
|
||||
virtual ~InstanceTask();
|
||||
|
||||
void setParentSettings(SettingsObjectPtr settings)
|
||||
{
|
||||
m_globalSettings = settings;
|
||||
}
|
||||
|
||||
void setStagingPath(const QString &stagingPath)
|
||||
{
|
||||
m_stagingPath = stagingPath;
|
||||
}
|
||||
|
||||
void setName(const QString &name)
|
||||
{
|
||||
m_instName = name;
|
||||
}
|
||||
QString name() const
|
||||
{
|
||||
return m_instName;
|
||||
}
|
||||
|
||||
void setIcon(const QString &icon)
|
||||
{
|
||||
m_instIcon = icon;
|
||||
}
|
||||
|
||||
void setGroup(const QString &group)
|
||||
{
|
||||
m_instGroup = group;
|
||||
}
|
||||
QString group() const
|
||||
{
|
||||
return m_instGroup;
|
||||
}
|
||||
|
||||
protected: /* data */
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
QString m_instName;
|
||||
QString m_instIcon;
|
||||
QString m_instGroup;
|
||||
QString m_stagingPath;
|
||||
};
|
@ -10,12 +10,9 @@
|
||||
#include "minecraft/ComponentList.h"
|
||||
#include "classparser.h"
|
||||
|
||||
LegacyUpgradeTask::LegacyUpgradeTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString & newName)
|
||||
LegacyUpgradeTask::LegacyUpgradeTask(InstancePtr origInstance)
|
||||
{
|
||||
m_globalSettings = settings;
|
||||
m_stagingPath = stagingPath;
|
||||
m_origInstance = origInstance;
|
||||
m_newName = newName;
|
||||
}
|
||||
|
||||
void LegacyUpgradeTask::executeTask()
|
||||
@ -70,7 +67,7 @@ void LegacyUpgradeTask::copyFinished()
|
||||
// NOTE: this scope ensures the instance is fully saved before we emitSucceeded
|
||||
{
|
||||
MinecraftInstance inst(m_globalSettings, instanceSettings, m_stagingPath);
|
||||
inst.setName(m_newName);
|
||||
inst.setName(m_instName);
|
||||
inst.init();
|
||||
|
||||
QString preferredVersionNumber = decideVersion(legacyInst->currentVersionId(), legacyInst->intendedVersionId());
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "tasks/Task.h"
|
||||
#include "InstanceTask.h"
|
||||
#include "multimc_logic_export.h"
|
||||
#include "net/NetJob.h"
|
||||
#include <QUrl>
|
||||
@ -13,11 +13,11 @@
|
||||
|
||||
class BaseInstanceProvider;
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT LegacyUpgradeTask : public Task
|
||||
class MULTIMC_LOGIC_EXPORT LegacyUpgradeTask : public InstanceTask
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LegacyUpgradeTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString & newName);
|
||||
explicit LegacyUpgradeTask(InstancePtr origInstance);
|
||||
|
||||
protected:
|
||||
//! Entry point for tasks.
|
||||
@ -26,13 +26,7 @@ protected:
|
||||
void copyAborted();
|
||||
|
||||
private: /* data */
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
InstancePtr m_origInstance;
|
||||
QString m_stagingPath;
|
||||
QString m_newName;
|
||||
QFuture<bool> m_copyFuture;
|
||||
QFutureWatcher<bool> m_copyFutureWatcher;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
@ -3,36 +3,25 @@
|
||||
#include "FtbPackFetchTask.h"
|
||||
#include "Env.h"
|
||||
|
||||
FtbPackDownloader::FtbPackDownloader() {
|
||||
FtbPackDownloader::FtbPackDownloader()
|
||||
{
|
||||
done = false;
|
||||
fetching = false;
|
||||
}
|
||||
|
||||
FtbPackDownloader::~FtbPackDownloader(){
|
||||
FtbPackDownloader::~FtbPackDownloader()
|
||||
{
|
||||
}
|
||||
|
||||
bool FtbPackDownloader::isValidPackSelected(){
|
||||
FtbModpack dummy;
|
||||
dummy.name = "__INVALID__";
|
||||
|
||||
FtbModpack other = fetchedPacks.value(selected.name, dummy);
|
||||
if(other.name == "__INVALID__") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return other.oldVersions.contains(selectedVersion) && !other.broken;
|
||||
}
|
||||
|
||||
QString FtbPackDownloader::getSuggestedInstanceName() {
|
||||
return selected.name;
|
||||
}
|
||||
|
||||
FtbModpackList FtbPackDownloader::getModpacks() {
|
||||
FtbModpackList FtbPackDownloader::getModpacks()
|
||||
{
|
||||
return static_cast<FtbModpackList>(fetchedPacks.values());
|
||||
}
|
||||
|
||||
void FtbPackDownloader::fetchModpacks(bool force = false){
|
||||
if(fetching || (!force && done)) {
|
||||
void FtbPackDownloader::fetchModpacks(bool force = false)
|
||||
{
|
||||
if(fetching || (!force && done))
|
||||
{
|
||||
qDebug() << "Skipping modpack refetch because done or already fetching [done =>" << done << "| fetching =>" << fetching << "]";
|
||||
return;
|
||||
}
|
||||
@ -46,8 +35,10 @@ void FtbPackDownloader::fetchModpacks(bool force = false){
|
||||
}
|
||||
|
||||
|
||||
void FtbPackDownloader::fetchSuccess(FtbModpackList modpacks) {
|
||||
for(int i = 0; i < modpacks.size(); i++) {
|
||||
void FtbPackDownloader::fetchSuccess(FtbModpackList modpacks)
|
||||
{
|
||||
for(int i = 0; i < modpacks.size(); i++)
|
||||
{
|
||||
fetchedPacks.insert(modpacks.at(i).name, modpacks.at(i));
|
||||
}
|
||||
|
||||
@ -57,53 +48,10 @@ void FtbPackDownloader::fetchSuccess(FtbModpackList modpacks) {
|
||||
fetchTask->deleteLater();
|
||||
}
|
||||
|
||||
void FtbPackDownloader::fetchFailed(QString reason) {
|
||||
void FtbPackDownloader::fetchFailed(QString reason)
|
||||
{
|
||||
qWarning() << "Failed to fetch FtbData" << reason;
|
||||
fetching = false;
|
||||
emit packFetchFailed();
|
||||
fetchTask->deleteLater();
|
||||
}
|
||||
|
||||
void FtbPackDownloader::selectPack(FtbModpack modpack, QString version) {
|
||||
selected = modpack;
|
||||
selectedVersion = version;
|
||||
}
|
||||
|
||||
FtbModpack FtbPackDownloader::getSelectedPack() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
void FtbPackDownloader::downloadSelected(MetaEntryPtr cache) {
|
||||
NetJob *job = new NetJob("Downlad FTB Pack");
|
||||
|
||||
cache->setStale(true);
|
||||
QString url = QString("http://ftb.cursecdn.com/FTB2/modpacks/%1/%2/%3").arg(selected.dir, selectedVersion.replace(".", "_"), selected.file);
|
||||
job->addNetAction(Net::Download::makeCached(url, cache));
|
||||
downloadPath = cache->getFullPath();
|
||||
|
||||
netJobContainer.reset(job);
|
||||
|
||||
connect(job, &NetJob::succeeded, this, &FtbPackDownloader::_downloadSucceeded);
|
||||
connect(job, &NetJob::failed, this, &FtbPackDownloader::_downloadFailed);
|
||||
connect(job, &NetJob::progress, this, &FtbPackDownloader::_downloadProgress);
|
||||
job->start();
|
||||
}
|
||||
|
||||
void FtbPackDownloader::_downloadSucceeded() {
|
||||
netJobContainer.reset();
|
||||
emit downloadSucceded(downloadPath);
|
||||
}
|
||||
|
||||
void FtbPackDownloader::_downloadProgress(qint64 current, qint64 total) {
|
||||
emit downloadProgress(current, total);
|
||||
}
|
||||
|
||||
void FtbPackDownloader::_downloadFailed(QString reason) {
|
||||
netJobContainer.reset();
|
||||
emit downloadFailed(reason);
|
||||
}
|
||||
|
||||
NetJobPtr FtbPackDownloader::getNetJob()
|
||||
{
|
||||
return netJobContainer;
|
||||
}
|
||||
|
@ -11,54 +11,29 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
class FtbPackDownloader;
|
||||
class MULTIMC_LOGIC_EXPORT FtbPackDownloader : public QObject {
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT FtbPackDownloader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FtbPackDownloader();
|
||||
virtual ~FtbPackDownloader();
|
||||
|
||||
void fetchModpacks(bool force);
|
||||
FtbModpackList getModpacks();
|
||||
|
||||
signals:
|
||||
void ready();
|
||||
void packFetchFailed();
|
||||
|
||||
private slots:
|
||||
void fetchSuccess(FtbModpackList modlist);
|
||||
void fetchFailed(QString reason);
|
||||
|
||||
private:
|
||||
QMap<QString, FtbModpack> fetchedPacks;
|
||||
bool fetching = false;
|
||||
bool done = false;
|
||||
|
||||
FtbModpack selected;
|
||||
QString selectedVersion;
|
||||
QString downloadPath;
|
||||
|
||||
FtbPackFetchTask *fetchTask = 0;
|
||||
NetJobPtr netJobContainer;
|
||||
|
||||
void _downloadSucceeded();
|
||||
void _downloadFailed(QString reason);
|
||||
void _downloadProgress(qint64 current, qint64 total);
|
||||
|
||||
private slots:
|
||||
void fetchSuccess(FtbModpackList modlist);
|
||||
void fetchFailed(QString reason);
|
||||
|
||||
public:
|
||||
FtbPackDownloader();
|
||||
~FtbPackDownloader();
|
||||
|
||||
bool isValidPackSelected();
|
||||
void selectPack(FtbModpack modpack, QString version);
|
||||
|
||||
FtbModpack getSelectedPack();
|
||||
|
||||
void fetchModpacks(bool force);
|
||||
void downloadSelected(MetaEntryPtr cache);
|
||||
|
||||
QString getSuggestedInstanceName();
|
||||
|
||||
FtbModpackList getModpacks();
|
||||
NetJobPtr getNetJob();
|
||||
|
||||
signals:
|
||||
void ready();
|
||||
void packFetchFailed();
|
||||
|
||||
void downloadSucceded(QString archivePath);
|
||||
void downloadFailed(QString reason);
|
||||
void downloadProgress(qint64 current, qint64 total);
|
||||
|
||||
};
|
||||
|
@ -58,6 +58,8 @@ void FtbPackFetchTask::fileDownloadFinished(){
|
||||
modpack.mods = element.attribute("mods");
|
||||
modpack.image = element.attribute("image");
|
||||
modpack.oldVersions = element.attribute("oldVersions").split(";");
|
||||
modpack.broken = false;
|
||||
modpack.bugged = false;
|
||||
|
||||
//remove empty if the xml is bugged
|
||||
for(QString curr : modpack.oldVersions) {
|
||||
|
@ -12,7 +12,7 @@ class MULTIMC_LOGIC_EXPORT FtbPackFetchTask : public QObject {
|
||||
|
||||
public:
|
||||
FtbPackFetchTask();
|
||||
~FtbPackFetchTask();
|
||||
virtual ~FtbPackFetchTask();
|
||||
|
||||
void fetch();
|
||||
|
||||
|
@ -9,52 +9,65 @@
|
||||
#include "minecraft/ComponentList.h"
|
||||
#include "minecraft/GradleSpecifier.h"
|
||||
|
||||
FtbPackInstallTask::FtbPackInstallTask(FtbPackDownloader *downloader, SettingsObjectPtr settings,
|
||||
const QString &stagingPath, const QString &instName, const QString &instIcon, const QString &instGroup) :
|
||||
m_globalSettings(settings), m_stagingPath(stagingPath), m_instName(instName), m_instIcon(instIcon), m_instGroup(instGroup)
|
||||
FtbPackInstallTask::FtbPackInstallTask(FtbModpack pack, QString version)
|
||||
{
|
||||
m_downloader = downloader;
|
||||
m_pack = pack;
|
||||
m_version = version;
|
||||
}
|
||||
|
||||
void FtbPackInstallTask::executeTask() {
|
||||
void FtbPackInstallTask::executeTask()
|
||||
{
|
||||
downloadPack();
|
||||
}
|
||||
|
||||
void FtbPackInstallTask::downloadPack(){
|
||||
FtbModpack toInstall = m_downloader->getSelectedPack();
|
||||
setStatus(tr("Downloading zip for %1").arg(toInstall.name));
|
||||
void FtbPackInstallTask::downloadPack()
|
||||
{
|
||||
setStatus(tr("Downloading zip for %1").arg(m_pack.name));
|
||||
|
||||
auto entry = ENV.metacache()->resolveEntry("general", "FTBPacks/" + toInstall.name);
|
||||
m_downloader->downloadSelected(entry);
|
||||
auto entry = ENV.metacache()->resolveEntry("general", "FTBPacks/" + m_pack.name);
|
||||
NetJob *job = new NetJob("Downlad FTB Pack");
|
||||
|
||||
entry->setStale(true);
|
||||
QString url = QString("http://ftb.cursecdn.com/FTB2/modpacks/%1/%2/%3").arg(m_pack.dir, m_version.replace(".", "_"), m_pack.file);
|
||||
job->addNetAction(Net::Download::makeCached(url, entry));
|
||||
archivePath = entry->getFullPath();
|
||||
|
||||
netJobContainer.reset(job);
|
||||
connect(job, &NetJob::succeeded, this, &FtbPackInstallTask::onDownloadSucceeded);
|
||||
connect(job, &NetJob::failed, this, &FtbPackInstallTask::onDownloadFailed);
|
||||
connect(job, &NetJob::progress, this, &FtbPackInstallTask::onDownloadProgress);
|
||||
job->start();
|
||||
|
||||
connect(m_downloader, &FtbPackDownloader::downloadSucceded, this, &FtbPackInstallTask::onDownloadSucceeded);
|
||||
connect(m_downloader, &FtbPackDownloader::downloadProgress, this, &FtbPackInstallTask::onDownloadProgress);
|
||||
connect(m_downloader, &FtbPackDownloader::downloadFailed, this,&FtbPackInstallTask::onDownloadFailed);
|
||||
progress(1, 4);
|
||||
}
|
||||
|
||||
void FtbPackInstallTask::onDownloadSucceeded(QString archivePath){
|
||||
void FtbPackInstallTask::onDownloadSucceeded()
|
||||
{
|
||||
abortable = false;
|
||||
unzip(archivePath);
|
||||
unzip();
|
||||
}
|
||||
|
||||
void FtbPackInstallTask::onDownloadFailed(QString reason) {
|
||||
void FtbPackInstallTask::onDownloadFailed(QString reason)
|
||||
{
|
||||
emitFailed(reason);
|
||||
}
|
||||
|
||||
void FtbPackInstallTask::onDownloadProgress(qint64 current, qint64 total){
|
||||
void FtbPackInstallTask::onDownloadProgress(qint64 current, qint64 total)
|
||||
{
|
||||
abortable = true;
|
||||
progress(current, total * 4);
|
||||
setStatus(tr("Downloading zip for %1 (%2\%)").arg(m_downloader->getSelectedPack().name).arg(current / 10));
|
||||
setStatus(tr("Downloading zip for %1 (%2\%)").arg(m_pack.name).arg(current / 10));
|
||||
}
|
||||
|
||||
void FtbPackInstallTask::unzip(QString archivePath) {
|
||||
void FtbPackInstallTask::unzip()
|
||||
{
|
||||
progress(2, 4);
|
||||
setStatus(tr("Extracting modpack"));
|
||||
QDir extractDir(m_stagingPath);
|
||||
|
||||
m_packZip.reset(new QuaZip(archivePath));
|
||||
if(!m_packZip->open(QuaZip::mdUnzip)) {
|
||||
if(!m_packZip->open(QuaZip::mdUnzip))
|
||||
{
|
||||
emitFailed(tr("Failed to open modpack file %1!").arg(archivePath));
|
||||
return;
|
||||
}
|
||||
@ -65,22 +78,26 @@ void FtbPackInstallTask::unzip(QString archivePath) {
|
||||
m_extractFutureWatcher.setFuture(m_extractFuture);
|
||||
}
|
||||
|
||||
void FtbPackInstallTask::onUnzipFinished() {
|
||||
void FtbPackInstallTask::onUnzipFinished()
|
||||
{
|
||||
install();
|
||||
}
|
||||
|
||||
void FtbPackInstallTask::onUnzipCanceled() {
|
||||
void FtbPackInstallTask::onUnzipCanceled()
|
||||
{
|
||||
emitAborted();
|
||||
}
|
||||
|
||||
void FtbPackInstallTask::install() {
|
||||
void FtbPackInstallTask::install()
|
||||
{
|
||||
progress(3, 4);
|
||||
FtbModpack toInstall = m_downloader->getSelectedPack();
|
||||
setStatus(tr("Installing modpack"));
|
||||
QDir unzipMcDir(m_stagingPath + "/unzip/minecraft");
|
||||
if(unzipMcDir.exists()) {
|
||||
if(unzipMcDir.exists())
|
||||
{
|
||||
//ok, found minecraft dir, move contents to instance dir
|
||||
if(!QDir().rename(m_stagingPath + "/unzip/minecraft", m_stagingPath + "/.minecraft")) {
|
||||
if(!QDir().rename(m_stagingPath + "/unzip/minecraft", m_stagingPath + "/.minecraft"))
|
||||
{
|
||||
emitFailed(tr("Failed to move unzipped minecraft!"));
|
||||
return;
|
||||
}
|
||||
@ -94,14 +111,15 @@ void FtbPackInstallTask::install() {
|
||||
MinecraftInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
|
||||
auto components = instance.getComponentList();
|
||||
components->buildingFromScratch();
|
||||
components->setComponentVersion("net.minecraft", toInstall.mcVersion, true);
|
||||
components->setComponentVersion("net.minecraft", m_pack.mcVersion, true);
|
||||
|
||||
bool fallback = true;
|
||||
|
||||
//handle different versions
|
||||
QFile packJson(m_stagingPath + "/.minecraft/pack.json");
|
||||
QDir jarmodDir = QDir(m_stagingPath + "/unzip/instMods");
|
||||
if(packJson.exists()) {
|
||||
if(packJson.exists())
|
||||
{
|
||||
packJson.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
QJsonDocument doc = QJsonDocument::fromJson(packJson.readAll());
|
||||
packJson.close();
|
||||
@ -109,15 +127,17 @@ void FtbPackInstallTask::install() {
|
||||
//we only care about the libs
|
||||
QJsonArray libs = doc.object().value("libraries").toArray();
|
||||
|
||||
foreach (const QJsonValue &value, libs) {
|
||||
foreach (const QJsonValue &value, libs)
|
||||
{
|
||||
QString nameValue = value.toObject().value("name").toString();
|
||||
if(!nameValue.startsWith("net.minecraftforge")) {
|
||||
if(!nameValue.startsWith("net.minecraftforge"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
GradleSpecifier forgeVersion(nameValue);
|
||||
|
||||
components->setComponentVersion("net.minecraftforge", forgeVersion.version().replace(toInstall.mcVersion, "").replace("-", ""));
|
||||
components->setComponentVersion("net.minecraftforge", forgeVersion.version().replace(m_pack.mcVersion, "").replace("-", ""));
|
||||
packJson.remove();
|
||||
fallback = false;
|
||||
break;
|
||||
@ -125,7 +145,8 @@ void FtbPackInstallTask::install() {
|
||||
|
||||
}
|
||||
|
||||
if(jarmodDir.exists()) {
|
||||
if(jarmodDir.exists())
|
||||
{
|
||||
qDebug() << "Found jarmods, installing...";
|
||||
|
||||
QStringList jarmods;
|
||||
@ -142,7 +163,8 @@ void FtbPackInstallTask::install() {
|
||||
//just nuke unzip directory, it s not needed anymore
|
||||
FS::deletePath(m_stagingPath + "/unzip");
|
||||
|
||||
if(fallback) {
|
||||
if(fallback)
|
||||
{
|
||||
//TODO: Some fallback mechanism... or just keep failing!
|
||||
emitFailed(tr("No installation method found!"));
|
||||
return;
|
||||
@ -154,7 +176,8 @@ void FtbPackInstallTask::install() {
|
||||
|
||||
instance.init();
|
||||
instance.setName(m_instName);
|
||||
if(m_instIcon == "default") {
|
||||
if(m_instIcon == "default")
|
||||
{
|
||||
m_instIcon = "ftb_logo";
|
||||
}
|
||||
instance.setIconKey(m_instIcon);
|
||||
@ -166,8 +189,9 @@ void FtbPackInstallTask::install() {
|
||||
|
||||
bool FtbPackInstallTask::abort()
|
||||
{
|
||||
if(abortable) {
|
||||
return m_downloader->getNetJob()->abort();
|
||||
if(abortable)
|
||||
{
|
||||
return netJobContainer->abort();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "tasks/Task.h"
|
||||
#include "InstanceTask.h"
|
||||
#include "modplatform/ftb/FtbPackDownloader.h"
|
||||
#include "BaseInstanceProvider.h"
|
||||
#include "net/NetJob.h"
|
||||
@ -9,47 +9,41 @@
|
||||
#include "meta/Version.h"
|
||||
#include "meta/VersionList.h"
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT FtbPackInstallTask : public Task {
|
||||
class MULTIMC_LOGIC_EXPORT FtbPackInstallTask : public InstanceTask {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FtbPackInstallTask(FtbPackDownloader *downloader, SettingsObjectPtr settings, const QString &stagingPath, const QString &instName,
|
||||
const QString &instIcon, const QString &instGroup);
|
||||
explicit FtbPackInstallTask(FtbModpack pack, QString version);
|
||||
virtual ~FtbPackInstallTask(){}
|
||||
|
||||
bool abort() override;
|
||||
|
||||
protected:
|
||||
//! Entry point for tasks.
|
||||
virtual void executeTask() override;
|
||||
|
||||
private: /* data */
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
QString m_stagingPath;
|
||||
QString m_instName;
|
||||
QString m_instIcon;
|
||||
QString m_instGroup;
|
||||
NetJobPtr m_netJobPtr;
|
||||
|
||||
FtbPackDownloader *m_downloader;
|
||||
|
||||
std::unique_ptr<QuaZip> m_packZip;
|
||||
QFuture<QStringList> m_extractFuture;
|
||||
QFutureWatcher<QStringList> m_extractFutureWatcher;
|
||||
|
||||
private:
|
||||
void downloadPack();
|
||||
void unzip(QString archivePath);
|
||||
void unzip();
|
||||
void install();
|
||||
|
||||
bool moveRecursively(QString source, QString dest);
|
||||
|
||||
bool abortable = false;
|
||||
|
||||
private slots:
|
||||
void onDownloadSucceeded(QString archivePath);
|
||||
void onDownloadSucceeded();
|
||||
void onDownloadFailed(QString reason);
|
||||
void onDownloadProgress(qint64 current, qint64 total);
|
||||
|
||||
void onUnzipFinished();
|
||||
void onUnzipCanceled();
|
||||
|
||||
private: /* data */
|
||||
bool abortable = false;
|
||||
std::unique_ptr<QuaZip> m_packZip;
|
||||
QFuture<QStringList> m_extractFuture;
|
||||
QFutureWatcher<QStringList> m_extractFutureWatcher;
|
||||
NetJobPtr netJobContainer;
|
||||
QString archivePath;
|
||||
|
||||
FtbModpack m_pack;
|
||||
QString m_version;
|
||||
};
|
||||
|
@ -17,8 +17,8 @@ struct FtbModpack {
|
||||
QString dir;
|
||||
QString file; //<- Url in the xml, but doesn't make much sense
|
||||
|
||||
bool bugged = false;
|
||||
bool broken = false;
|
||||
bool bugged = true;
|
||||
bool broken = true;
|
||||
};
|
||||
//We need it for the proxy model
|
||||
Q_DECLARE_METATYPE(FtbModpack)
|
||||
|
Reference in New Issue
Block a user