diff options
-rw-r--r-- | backend/BaseInstance.cpp | 15 | ||||
-rw-r--r-- | backend/BaseInstance.h | 5 | ||||
-rw-r--r-- | backend/LegacyInstance.cpp | 46 | ||||
-rw-r--r-- | backend/LegacyInstance.h | 3 | ||||
-rw-r--r-- | backend/LegacyUpdate.cpp | 67 | ||||
-rw-r--r-- | backend/LegacyUpdate.h | 11 | ||||
-rw-r--r-- | backend/MinecraftProcess.cpp | 2 | ||||
-rw-r--r-- | backend/OneSixInstance.cpp | 11 | ||||
-rw-r--r-- | backend/OneSixUpdate.cpp | 11 | ||||
-rw-r--r-- | backend/OneSixUpdate.h | 1 | ||||
-rw-r--r-- | backend/lists/MinecraftVersionList.cpp | 3 | ||||
-rw-r--r-- | gui/instancemodel.cpp | 2 | ||||
-rw-r--r-- | gui/mainwindow.cpp | 36 | ||||
-rw-r--r-- | gui/mainwindow.h | 3 |
14 files changed, 173 insertions, 43 deletions
diff --git a/backend/BaseInstance.cpp b/backend/BaseInstance.cpp index d94f3de9..951b403a 100644 --- a/backend/BaseInstance.cpp +++ b/backend/BaseInstance.cpp @@ -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")) diff --git a/backend/BaseInstance.h b/backend/BaseInstance.h index 3a344cea..05f3ce00 100644 --- a/backend/BaseInstance.h +++ b/backend/BaseInstance.h @@ -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); diff --git a/backend/LegacyInstance.cpp b/backend/LegacyInstance.cpp index bf5c674b..9102c9c7 100644 --- a/backend/LegacyInstance.cpp +++ b/backend/LegacyInstance.cpp @@ -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 ); +} diff --git a/backend/LegacyInstance.h b/backend/LegacyInstance.h index e7cf347c..6c9a295f 100644 --- a/backend/LegacyInstance.h +++ b/backend/LegacyInstance.h @@ -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; diff --git a/backend/LegacyUpdate.cpp b/backend/LegacyUpdate.cpp index 630f7f29..8580a2f2 100644 --- a/backend/LegacyUpdate.cpp +++ b/backend/LegacyUpdate.cpp @@ -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."); +} diff --git a/backend/LegacyUpdate.h b/backend/LegacyUpdate.h index cc1f5efd..ad58fc85 100644 --- a/backend/LegacyUpdate.h +++ b/backend/LegacyUpdate.h @@ -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; }; diff --git a/backend/MinecraftProcess.cpp b/backend/MinecraftProcess.cpp index d4d1da3c..d34be835 100644 --- a/backend/MinecraftProcess.cpp +++ b/backend/MinecraftProcess.cpp @@ -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); diff --git a/backend/OneSixInstance.cpp b/backend/OneSixInstance.cpp index bf8fd84e..46866b0e 100644 --- a/backend/OneSixInstance.cpp +++ b/backend/OneSixInstance.cpp @@ -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)) { diff --git a/backend/OneSixUpdate.cpp b/backend/OneSixUpdate.cpp index 5506d9aa..5cd2c78c 100644 --- a/backend/OneSixUpdate.cpp +++ b/backend/OneSixUpdate.cpp @@ -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"); diff --git a/backend/OneSixUpdate.h b/backend/OneSixUpdate.h index bab2d335..75575166 100644 --- a/backend/OneSixUpdate.h +++ b/backend/OneSixUpdate.h @@ -44,7 +44,6 @@ private slots: void jarlibFailed(); private: - JobListPtr legacyDownloadJob; JobListPtr specificVersionDownloadJob; JobListPtr jarlibDownloadJob; JobListQueue download_queue; diff --git a/backend/lists/MinecraftVersionList.cpp b/backend/lists/MinecraftVersionList.cpp index bf0406dc..2e5f0cd7 100644 --- a/backend/lists/MinecraftVersionList.cpp +++ b/backend/lists/MinecraftVersionList.cpp @@ -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() diff --git a/gui/instancemodel.cpp b/gui/instancemodel.cpp index dbeba0da..3cbb0fb9 100644 --- a/gui/instancemodel.cpp +++ b/gui/instancemodel.cpp @@ -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: { diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 6187de93..6176c079 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -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() ); } } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index efcbc80c..62115e1d 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -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; |