mirror of
https://github.com/MultiMC/MultiMC5.git
synced 2024-09-03 21:49:13 +00:00
OneSix instances now have a minecraft folder inside.
Also, the main instance view was expanded with helpful key events: F2 for rename, F5 for refresh, Enter for start instance, Delete for...
This commit is contained in:
parent
7e78a422e8
commit
ff33d4a1a4
@ -75,7 +75,7 @@ BaseInstance::BaseInstance( BaseInstancePrivate* d_in,
|
||||
|
||||
QString BaseInstance::id() const
|
||||
{
|
||||
return QFileInfo(rootDir()).fileName();
|
||||
return QFileInfo(instanceRoot()).fileName();
|
||||
}
|
||||
|
||||
QString BaseInstance::instanceType() const
|
||||
@ -85,12 +85,23 @@ QString BaseInstance::instanceType() const
|
||||
}
|
||||
|
||||
|
||||
QString BaseInstance::rootDir() const
|
||||
QString BaseInstance::instanceRoot() const
|
||||
{
|
||||
I_D(BaseInstance);
|
||||
return d->m_rootDir;
|
||||
}
|
||||
|
||||
QString BaseInstance::minecraftRoot() const
|
||||
{
|
||||
QFileInfo mcDir(PathCombine(instanceRoot(), "minecraft"));
|
||||
QFileInfo dotMCDir(PathCombine(instanceRoot(), ".minecraft"));
|
||||
|
||||
if (dotMCDir.exists() && !mcDir.exists())
|
||||
return dotMCDir.filePath();
|
||||
else
|
||||
return mcDir.filePath();
|
||||
}
|
||||
|
||||
InstanceList *BaseInstance::instList() const
|
||||
{
|
||||
if (parent()->inherits("InstanceList"))
|
||||
|
@ -56,7 +56,10 @@ public:
|
||||
QString instanceType() const;
|
||||
|
||||
/// Path to the instance's root directory.
|
||||
QString rootDir() const;
|
||||
QString instanceRoot() const;
|
||||
|
||||
/// Path to the instance's minecraft directory.
|
||||
QString minecraftRoot() const;
|
||||
|
||||
QString name() const;
|
||||
void setName(QString val);
|
||||
|
@ -21,17 +21,6 @@ LegacyInstance::LegacyInstance(const QString& rootDir, SettingsObject* settings,
|
||||
settings->registerSetting(new Setting("IntendedJarVersion", ""));
|
||||
}
|
||||
|
||||
QString LegacyInstance::minecraftDir() const
|
||||
{
|
||||
QFileInfo mcDir(PathCombine(rootDir(), "minecraft"));
|
||||
QFileInfo dotMCDir(PathCombine(rootDir(), ".minecraft"));
|
||||
|
||||
if (dotMCDir.exists() && !mcDir.exists())
|
||||
return dotMCDir.filePath();
|
||||
else
|
||||
return mcDir.filePath();
|
||||
}
|
||||
|
||||
BaseUpdate* LegacyInstance::doUpdate()
|
||||
{
|
||||
return new LegacyUpdate(this, this);
|
||||
@ -42,10 +31,10 @@ MinecraftProcess* LegacyInstance::prepareForLaunch(QString user, QString session
|
||||
MinecraftProcess * proc = new MinecraftProcess(this);
|
||||
|
||||
// FIXME: extract the icon
|
||||
// QImage(":/icons/instances/" + iconKey()).save(PathCombine(minecraftDir(), "icon.png"));
|
||||
// QImage(":/icons/instances/" + iconKey()).save(PathCombine(minecraftRoot(), "icon.png"));
|
||||
|
||||
// extract the legacy launcher
|
||||
QFile(":/launcher/launcher.jar").copy(PathCombine(minecraftDir(), LAUNCHER_FILE));
|
||||
QFile(":/launcher/launcher.jar").copy(PathCombine(minecraftRoot(), LAUNCHER_FILE));
|
||||
|
||||
// set the process arguments
|
||||
{
|
||||
@ -88,7 +77,7 @@ MinecraftProcess* LegacyInstance::prepareForLaunch(QString user, QString session
|
||||
}
|
||||
|
||||
// set the process work path
|
||||
proc->setMinecraftWorkdir(minecraftDir());
|
||||
proc->setMinecraftWorkdir(minecraftRoot());
|
||||
|
||||
return proc;
|
||||
}
|
||||
@ -101,32 +90,32 @@ void LegacyInstance::cleanupAfterRun()
|
||||
|
||||
QString LegacyInstance::instModsDir() const
|
||||
{
|
||||
return PathCombine(rootDir(), "instMods");
|
||||
return PathCombine(instanceRoot(), "instMods");
|
||||
}
|
||||
|
||||
QString LegacyInstance::binDir() const
|
||||
{
|
||||
return PathCombine(minecraftDir(), "bin");
|
||||
return PathCombine(minecraftRoot(), "bin");
|
||||
}
|
||||
|
||||
QString LegacyInstance::savesDir() const
|
||||
{
|
||||
return PathCombine(minecraftDir(), "saves");
|
||||
return PathCombine(minecraftRoot(), "saves");
|
||||
}
|
||||
|
||||
QString LegacyInstance::mlModsDir() const
|
||||
{
|
||||
return PathCombine(minecraftDir(), "mods");
|
||||
return PathCombine(minecraftRoot(), "mods");
|
||||
}
|
||||
|
||||
QString LegacyInstance::coreModsDir() const
|
||||
{
|
||||
return PathCombine(minecraftDir(), "coremods");
|
||||
return PathCombine(minecraftRoot(), "coremods");
|
||||
}
|
||||
|
||||
QString LegacyInstance::resourceDir() const
|
||||
{
|
||||
return PathCombine(minecraftDir(), "resources");
|
||||
return PathCombine(minecraftRoot(), "resources");
|
||||
}
|
||||
|
||||
QString LegacyInstance::mcJar() const
|
||||
@ -141,7 +130,7 @@ QString LegacyInstance::mcBackup() const
|
||||
|
||||
QString LegacyInstance::modListFile() const
|
||||
{
|
||||
return PathCombine(rootDir(), "modlist");
|
||||
return PathCombine(instanceRoot(), "modlist");
|
||||
}
|
||||
|
||||
bool LegacyInstance::shouldUpdateCurrentVersion() const
|
||||
@ -220,10 +209,21 @@ QString LegacyInstance::intendedVersionId() const
|
||||
}
|
||||
bool LegacyInstance::setIntendedVersionId ( QString version )
|
||||
{
|
||||
return false;
|
||||
settings().set("IntendedJarVersion", version);
|
||||
setShouldUpdate(true);
|
||||
return true;
|
||||
}
|
||||
bool LegacyInstance::shouldUpdate() const
|
||||
{
|
||||
I_D(LegacyInstance);
|
||||
QVariant var = settings().get ( "ShouldUpdate" );
|
||||
if ( !var.isValid() || var.toBool() == false )
|
||||
{
|
||||
return intendedVersionId() != currentVersionId();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void LegacyInstance::setShouldUpdate ( bool val ) {}
|
||||
void LegacyInstance::setShouldUpdate ( bool val )
|
||||
{
|
||||
settings().set ( "ShouldUpdate", val );
|
||||
}
|
||||
|
@ -21,10 +21,9 @@ public:
|
||||
QString modListFile() const;
|
||||
|
||||
////// Directories //////
|
||||
QString minecraftDir() const;
|
||||
QString savesDir() const;
|
||||
QString instModsDir() const;
|
||||
QString binDir() const;
|
||||
QString savesDir() const;
|
||||
QString mlModsDir() const;
|
||||
QString coreModsDir() const;
|
||||
QString resourceDir() const;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "LegacyUpdate.h"
|
||||
#include "lists/LwjglVersionList.h"
|
||||
#include "lists/MinecraftVersionList.h"
|
||||
#include "BaseInstance.h"
|
||||
#include "LegacyInstance.h"
|
||||
#include "net/NetWorker.h"
|
||||
@ -27,7 +28,7 @@ void LegacyUpdate::lwjglStart()
|
||||
QFileInfo doneFile(PathCombine(lwjglTargetPath, "done"));
|
||||
if(doneFile.exists())
|
||||
{
|
||||
emitSucceeded();
|
||||
jarStart();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -38,6 +39,7 @@ void LegacyUpdate::lwjglStart()
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus("Downloading new LWJGL.");
|
||||
auto version = list.getVersion(lwjglVersion);
|
||||
if(!version)
|
||||
{
|
||||
@ -104,6 +106,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply)
|
||||
saveMe.close();
|
||||
setStatus("Installing new LWJGL...");
|
||||
extractLwjgl();
|
||||
jarStart();
|
||||
}
|
||||
void LegacyUpdate::extractLwjgl()
|
||||
{
|
||||
@ -189,7 +192,6 @@ void LegacyUpdate::extractLwjgl()
|
||||
doneFile.open(QIODevice::WriteOnly);
|
||||
doneFile.write("done.");
|
||||
doneFile.close();
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
void LegacyUpdate::lwjglFailed()
|
||||
@ -197,3 +199,64 @@ void LegacyUpdate::lwjglFailed()
|
||||
emitFailed("Bad stuff happened while trying to get the lwjgl libs...");
|
||||
}
|
||||
|
||||
void LegacyUpdate::jarStart()
|
||||
{
|
||||
setStatus("Checking ...");
|
||||
LegacyInstance * inst = (LegacyInstance *) m_inst;
|
||||
QString current_version_id = inst->currentVersionId();
|
||||
QString intended_version_id = inst->intendedVersionId();
|
||||
bool shouldUpdate = inst->shouldUpdate();
|
||||
if(!shouldUpdate)
|
||||
{
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a pointer to the version object that corresponds to the instance's version.
|
||||
auto targetVersion = MinecraftVersionList::getMainList().findVersion(intended_version_id);
|
||||
|
||||
if(!targetVersion)
|
||||
{
|
||||
emitFailed("Not a valid version:" + intended_version_id);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make directories
|
||||
QDir binDir(inst->binDir());
|
||||
if (!binDir.exists() && !binDir.mkpath("."))
|
||||
{
|
||||
emitFailed("Failed to create bin folder.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Build a list of URLs that will need to be downloaded.
|
||||
setStatus("Downloading new minecraft.jar");
|
||||
|
||||
// This will be either 'minecraft' or the version number, depending on where
|
||||
// we're downloading from.
|
||||
QString jarFilename = "minecraft";
|
||||
QString download_path = PathCombine(inst->minecraftRoot(), "bin/minecraft.jar");
|
||||
|
||||
QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/");
|
||||
urlstr += targetVersion->descriptor + "/" + targetVersion->descriptor + ".jar";
|
||||
auto dljob = DownloadJob::create(QUrl(urlstr), download_path);
|
||||
|
||||
legacyDownloadJob.reset(new JobList());
|
||||
legacyDownloadJob->add(dljob);
|
||||
connect(legacyDownloadJob.data(), SIGNAL(finished()), SLOT(jarFinished()));
|
||||
connect(legacyDownloadJob.data(), SIGNAL(failed()), SLOT(jarFailed()));
|
||||
connect(legacyDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
|
||||
download_queue.enqueue(legacyDownloadJob);
|
||||
}
|
||||
|
||||
void LegacyUpdate::jarFinished()
|
||||
{
|
||||
// process the jar
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
void LegacyUpdate::jarFailed()
|
||||
{
|
||||
// bad, bad
|
||||
emitFailed("Failed to download the minecraft jar. Try again later.");
|
||||
}
|
||||
|
@ -38,6 +38,11 @@ private slots:
|
||||
void lwjglStart();
|
||||
void lwjglFinished( QNetworkReply* );
|
||||
void lwjglFailed();
|
||||
|
||||
void jarStart();
|
||||
void jarFinished();
|
||||
void jarFailed();
|
||||
|
||||
void extractLwjgl();
|
||||
private:
|
||||
|
||||
@ -50,6 +55,12 @@ private:
|
||||
|
||||
QString lwjglTargetPath;
|
||||
QString lwjglNativesPath;
|
||||
private:
|
||||
JobListPtr legacyDownloadJob;
|
||||
JobListQueue download_queue;
|
||||
|
||||
// target version, determined during this task
|
||||
QSharedPointer<MinecraftVersion> targetVersion;
|
||||
};
|
||||
|
||||
|
||||
|
@ -49,7 +49,7 @@ MinecraftProcess::MinecraftProcess( BaseInstance* inst ) :
|
||||
// export some infos
|
||||
env.insert("INST_NAME", inst->name());
|
||||
env.insert("INST_ID", inst->id());
|
||||
env.insert("INST_DIR", QDir(inst->rootDir()).absolutePath());
|
||||
env.insert("INST_DIR", QDir(inst->instanceRoot()).absolutePath());
|
||||
|
||||
this->setProcessEnvironment(env);
|
||||
m_prepostlaunchprocess.setProcessEnvironment(env);
|
||||
|
@ -70,7 +70,7 @@ QStringList OneSixInstance::processMinecraftArgs( QString user, QString session
|
||||
token_mapping["profile_name"] = name();
|
||||
token_mapping["version_name"] = version->id;
|
||||
|
||||
QString absRootDir = QDir(rootDir()).absolutePath();
|
||||
QString absRootDir = QDir(minecraftRoot()).absolutePath();
|
||||
token_mapping["game_directory"] = absRootDir;
|
||||
QString absAssetsDir = QDir("assets/").absolutePath();
|
||||
token_mapping["game_assets"] = absAssetsDir;
|
||||
@ -91,7 +91,7 @@ MinecraftProcess* OneSixInstance::prepareForLaunch ( QString user, QString sessi
|
||||
if(!version)
|
||||
return nullptr;
|
||||
auto libs_to_extract = version->getActiveNativeLibs();
|
||||
QString natives_dir_raw = PathCombine(rootDir(), "natives/");
|
||||
QString natives_dir_raw = PathCombine(instanceRoot(), "natives/");
|
||||
bool success = ensurePathExists(natives_dir_raw);
|
||||
if(!success)
|
||||
{
|
||||
@ -140,13 +140,13 @@ MinecraftProcess* OneSixInstance::prepareForLaunch ( QString user, QString sessi
|
||||
// create the process and set its parameters
|
||||
MinecraftProcess * proc = new MinecraftProcess(this);
|
||||
proc->setMinecraftArguments(args);
|
||||
proc->setMinecraftWorkdir(rootDir());
|
||||
proc->setMinecraftWorkdir(minecraftRoot());
|
||||
return proc;
|
||||
}
|
||||
|
||||
void OneSixInstance::cleanupAfterRun()
|
||||
{
|
||||
QString target_dir = PathCombine(rootDir(), "natives/");
|
||||
QString target_dir = PathCombine(instanceRoot(), "natives/");
|
||||
QDir dir(target_dir);
|
||||
dir.removeRecursively();
|
||||
}
|
||||
@ -155,6 +155,7 @@ bool OneSixInstance::setIntendedVersionId ( QString version )
|
||||
{
|
||||
settings().set("IntendedVersion", version);
|
||||
setShouldUpdate(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
QString OneSixInstance::intendedVersionId() const
|
||||
@ -187,7 +188,7 @@ bool OneSixInstance::reloadFullVersion()
|
||||
{
|
||||
I_D(OneSixInstance);
|
||||
|
||||
QString verpath = PathCombine(rootDir(), "version.json");
|
||||
QString verpath = PathCombine(instanceRoot(), "version.json");
|
||||
QFile versionfile(verpath);
|
||||
if(versionfile.exists() && versionfile.open(QIODevice::ReadOnly))
|
||||
{
|
||||
|
@ -38,6 +38,15 @@ OneSixUpdate::OneSixUpdate(BaseInstance *inst, QObject *parent):BaseUpdate(inst,
|
||||
void OneSixUpdate::executeTask()
|
||||
{
|
||||
QString intendedVersion = m_inst->intendedVersionId();
|
||||
|
||||
// Make directories
|
||||
QDir mcDir(m_inst->minecraftRoot());
|
||||
if (!mcDir.exists() && !mcDir.mkpath("."))
|
||||
{
|
||||
emitFailed("Failed to create bin folder.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a pointer to the version object that corresponds to the instance's version.
|
||||
targetVersion = MinecraftVersionList::getMainList().findVersion(intendedVersion).dynamicCast<MinecraftVersion>();
|
||||
if(targetVersion == nullptr)
|
||||
@ -78,7 +87,7 @@ void OneSixUpdate::versionFileFinished()
|
||||
auto DlJob = firstJob.dynamicCast<DownloadJob>();
|
||||
|
||||
QString version_id = targetVersion->descriptor;
|
||||
QString inst_dir = m_inst->rootDir();
|
||||
QString inst_dir = m_inst->instanceRoot();
|
||||
// save the version file in $instanceId/version.json
|
||||
{
|
||||
QString version1 = PathCombine(inst_dir, "/version.json");
|
||||
|
@ -44,7 +44,6 @@ private slots:
|
||||
void jarlibFailed();
|
||||
|
||||
private:
|
||||
JobListPtr legacyDownloadJob;
|
||||
JobListPtr specificVersionDownloadJob;
|
||||
JobListPtr jarlibDownloadJob;
|
||||
JobListQueue download_queue;
|
||||
|
@ -141,8 +141,7 @@ MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
|
||||
legacyWhitelist.insert("1.2.1");
|
||||
legacyWhitelist.insert("1.1");
|
||||
legacyWhitelist.insert("1.0.1");
|
||||
legacyWhitelist.insert("1.0.0");
|
||||
// TODO: consider adding betas here too (whatever the legacy launcher supports)
|
||||
legacyWhitelist.insert("1.0");
|
||||
}
|
||||
|
||||
MCVListLoadTask::~MCVListLoadTask()
|
||||
|
@ -68,7 +68,7 @@ QVariant InstanceModel::data ( const QModelIndex& index, int role ) const
|
||||
}
|
||||
case Qt::ToolTipRole:
|
||||
{
|
||||
return pdata->rootDir();
|
||||
return pdata->instanceRoot();
|
||||
}
|
||||
case Qt::DecorationRole:
|
||||
{
|
||||
|
@ -109,6 +109,7 @@ MainWindow::MainWindow ( QWidget *parent ) :
|
||||
view->setItemDelegate(delegate);
|
||||
view->setSpacing(10);
|
||||
view->setUniformItemWidths(true);
|
||||
view->installEventFilter(this);
|
||||
|
||||
model = new InstanceModel ( instList,this );
|
||||
proxymodel = new InstanceProxyModel ( this );
|
||||
@ -160,6 +161,37 @@ MainWindow::~MainWindow()
|
||||
delete assets_downloader;
|
||||
}
|
||||
|
||||
bool MainWindow::eventFilter ( QObject* obj, QEvent* ev )
|
||||
{
|
||||
if(obj == view)
|
||||
{
|
||||
if (ev->type() == QEvent::KeyPress)
|
||||
{
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(ev);
|
||||
switch(keyEvent->key())
|
||||
{
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
on_actionLaunchInstance_triggered();
|
||||
return true;
|
||||
case Qt::Key_Delete:
|
||||
on_actionDeleteInstance_triggered();
|
||||
return true;
|
||||
case Qt::Key_F5:
|
||||
on_actionRefresh_triggered();
|
||||
return true;
|
||||
case Qt::Key_F2:
|
||||
on_actionRenameInstance_triggered();
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return QMainWindow::eventFilter ( obj, ev );
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::instanceActivated ( QModelIndex index )
|
||||
{
|
||||
if(!index.isValid())
|
||||
@ -306,7 +338,7 @@ void MainWindow::on_actionDeleteInstance_triggered()
|
||||
QString("This is permanent! Are you sure?\nAbout to delete: ") + inst->name());
|
||||
if (response == QMessageBox::Yes)
|
||||
{
|
||||
QDir(inst->rootDir()).removeRecursively();
|
||||
QDir(inst->instanceRoot()).removeRecursively();
|
||||
instList.loadList();
|
||||
}
|
||||
}
|
||||
@ -335,7 +367,7 @@ void MainWindow::on_actionViewSelectedInstFolder_triggered()
|
||||
BaseInstance* inst = selectedInstance();
|
||||
if(inst)
|
||||
{
|
||||
QString str = inst->rootDir();
|
||||
QString str = inst->instanceRoot();
|
||||
openDirInDefaultProgram ( QDir(str).absolutePath() );
|
||||
}
|
||||
}
|
||||
|
@ -122,6 +122,9 @@ public slots:
|
||||
|
||||
void launchInstance(BaseInstance *inst, LoginResponse response);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *ev);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
KCategoryDrawer * drawer;
|
||||
|
Loading…
Reference in New Issue
Block a user