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:
Petr Mrázek 2013-08-12 00:39:19 +02:00
parent 7e78a422e8
commit ff33d4a1a4
14 changed files with 173 additions and 43 deletions

View File

@ -75,7 +75,7 @@ BaseInstance::BaseInstance( BaseInstancePrivate* d_in,
QString BaseInstance::id() const QString BaseInstance::id() const
{ {
return QFileInfo(rootDir()).fileName(); return QFileInfo(instanceRoot()).fileName();
} }
QString BaseInstance::instanceType() const QString BaseInstance::instanceType() const
@ -85,12 +85,23 @@ QString BaseInstance::instanceType() const
} }
QString BaseInstance::rootDir() const QString BaseInstance::instanceRoot() const
{ {
I_D(BaseInstance); I_D(BaseInstance);
return d->m_rootDir; 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 InstanceList *BaseInstance::instList() const
{ {
if (parent()->inherits("InstanceList")) if (parent()->inherits("InstanceList"))

View File

@ -56,7 +56,10 @@ public:
QString instanceType() const; QString instanceType() const;
/// Path to the instance's root directory. /// 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; QString name() const;
void setName(QString val); void setName(QString val);

View File

@ -21,17 +21,6 @@ LegacyInstance::LegacyInstance(const QString& rootDir, SettingsObject* settings,
settings->registerSetting(new Setting("IntendedJarVersion", "")); 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() BaseUpdate* LegacyInstance::doUpdate()
{ {
return new LegacyUpdate(this, this); return new LegacyUpdate(this, this);
@ -42,10 +31,10 @@ MinecraftProcess* LegacyInstance::prepareForLaunch(QString user, QString session
MinecraftProcess * proc = new MinecraftProcess(this); MinecraftProcess * proc = new MinecraftProcess(this);
// FIXME: extract the icon // 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 // 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 // set the process arguments
{ {
@ -88,7 +77,7 @@ MinecraftProcess* LegacyInstance::prepareForLaunch(QString user, QString session
} }
// set the process work path // set the process work path
proc->setMinecraftWorkdir(minecraftDir()); proc->setMinecraftWorkdir(minecraftRoot());
return proc; return proc;
} }
@ -101,32 +90,32 @@ void LegacyInstance::cleanupAfterRun()
QString LegacyInstance::instModsDir() const QString LegacyInstance::instModsDir() const
{ {
return PathCombine(rootDir(), "instMods"); return PathCombine(instanceRoot(), "instMods");
} }
QString LegacyInstance::binDir() const QString LegacyInstance::binDir() const
{ {
return PathCombine(minecraftDir(), "bin"); return PathCombine(minecraftRoot(), "bin");
} }
QString LegacyInstance::savesDir() const QString LegacyInstance::savesDir() const
{ {
return PathCombine(minecraftDir(), "saves"); return PathCombine(minecraftRoot(), "saves");
} }
QString LegacyInstance::mlModsDir() const QString LegacyInstance::mlModsDir() const
{ {
return PathCombine(minecraftDir(), "mods"); return PathCombine(minecraftRoot(), "mods");
} }
QString LegacyInstance::coreModsDir() const QString LegacyInstance::coreModsDir() const
{ {
return PathCombine(minecraftDir(), "coremods"); return PathCombine(minecraftRoot(), "coremods");
} }
QString LegacyInstance::resourceDir() const QString LegacyInstance::resourceDir() const
{ {
return PathCombine(minecraftDir(), "resources"); return PathCombine(minecraftRoot(), "resources");
} }
QString LegacyInstance::mcJar() const QString LegacyInstance::mcJar() const
@ -141,7 +130,7 @@ QString LegacyInstance::mcBackup() const
QString LegacyInstance::modListFile() const QString LegacyInstance::modListFile() const
{ {
return PathCombine(rootDir(), "modlist"); return PathCombine(instanceRoot(), "modlist");
} }
bool LegacyInstance::shouldUpdateCurrentVersion() const bool LegacyInstance::shouldUpdateCurrentVersion() const
@ -220,10 +209,21 @@ QString LegacyInstance::intendedVersionId() const
} }
bool LegacyInstance::setIntendedVersionId ( QString version ) bool LegacyInstance::setIntendedVersionId ( QString version )
{ {
return false; settings().set("IntendedJarVersion", version);
setShouldUpdate(true);
return true;
} }
bool LegacyInstance::shouldUpdate() const bool LegacyInstance::shouldUpdate() const
{ {
I_D(LegacyInstance);
QVariant var = settings().get ( "ShouldUpdate" );
if ( !var.isValid() || var.toBool() == false )
{
return intendedVersionId() != currentVersionId();
}
return true; return true;
} }
void LegacyInstance::setShouldUpdate ( bool val ) {} void LegacyInstance::setShouldUpdate ( bool val )
{
settings().set ( "ShouldUpdate", val );
}

View File

@ -21,10 +21,9 @@ public:
QString modListFile() const; QString modListFile() const;
////// Directories ////// ////// Directories //////
QString minecraftDir() const; QString savesDir() const;
QString instModsDir() const; QString instModsDir() const;
QString binDir() const; QString binDir() const;
QString savesDir() const;
QString mlModsDir() const; QString mlModsDir() const;
QString coreModsDir() const; QString coreModsDir() const;
QString resourceDir() const; QString resourceDir() const;

View File

@ -1,5 +1,6 @@
#include "LegacyUpdate.h" #include "LegacyUpdate.h"
#include "lists/LwjglVersionList.h" #include "lists/LwjglVersionList.h"
#include "lists/MinecraftVersionList.h"
#include "BaseInstance.h" #include "BaseInstance.h"
#include "LegacyInstance.h" #include "LegacyInstance.h"
#include "net/NetWorker.h" #include "net/NetWorker.h"
@ -27,7 +28,7 @@ void LegacyUpdate::lwjglStart()
QFileInfo doneFile(PathCombine(lwjglTargetPath, "done")); QFileInfo doneFile(PathCombine(lwjglTargetPath, "done"));
if(doneFile.exists()) if(doneFile.exists())
{ {
emitSucceeded(); jarStart();
return; return;
} }
@ -38,6 +39,7 @@ void LegacyUpdate::lwjglStart()
return; return;
} }
setStatus("Downloading new LWJGL.");
auto version = list.getVersion(lwjglVersion); auto version = list.getVersion(lwjglVersion);
if(!version) if(!version)
{ {
@ -104,6 +106,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply)
saveMe.close(); saveMe.close();
setStatus("Installing new LWJGL..."); setStatus("Installing new LWJGL...");
extractLwjgl(); extractLwjgl();
jarStart();
} }
void LegacyUpdate::extractLwjgl() void LegacyUpdate::extractLwjgl()
{ {
@ -189,7 +192,6 @@ void LegacyUpdate::extractLwjgl()
doneFile.open(QIODevice::WriteOnly); doneFile.open(QIODevice::WriteOnly);
doneFile.write("done."); doneFile.write("done.");
doneFile.close(); doneFile.close();
emitSucceeded();
} }
void LegacyUpdate::lwjglFailed() void LegacyUpdate::lwjglFailed()
@ -197,3 +199,64 @@ void LegacyUpdate::lwjglFailed()
emitFailed("Bad stuff happened while trying to get the lwjgl libs..."); 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.");
}

View File

@ -38,6 +38,11 @@ private slots:
void lwjglStart(); void lwjglStart();
void lwjglFinished( QNetworkReply* ); void lwjglFinished( QNetworkReply* );
void lwjglFailed(); void lwjglFailed();
void jarStart();
void jarFinished();
void jarFailed();
void extractLwjgl(); void extractLwjgl();
private: private:
@ -50,6 +55,12 @@ private:
QString lwjglTargetPath; QString lwjglTargetPath;
QString lwjglNativesPath; QString lwjglNativesPath;
private:
JobListPtr legacyDownloadJob;
JobListQueue download_queue;
// target version, determined during this task
QSharedPointer<MinecraftVersion> targetVersion;
}; };

View File

@ -49,7 +49,7 @@ MinecraftProcess::MinecraftProcess( BaseInstance* inst ) :
// export some infos // export some infos
env.insert("INST_NAME", inst->name()); env.insert("INST_NAME", inst->name());
env.insert("INST_ID", inst->id()); 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); this->setProcessEnvironment(env);
m_prepostlaunchprocess.setProcessEnvironment(env); m_prepostlaunchprocess.setProcessEnvironment(env);

View File

@ -70,7 +70,7 @@ QStringList OneSixInstance::processMinecraftArgs( QString user, QString session
token_mapping["profile_name"] = name(); token_mapping["profile_name"] = name();
token_mapping["version_name"] = version->id; token_mapping["version_name"] = version->id;
QString absRootDir = QDir(rootDir()).absolutePath(); QString absRootDir = QDir(minecraftRoot()).absolutePath();
token_mapping["game_directory"] = absRootDir; token_mapping["game_directory"] = absRootDir;
QString absAssetsDir = QDir("assets/").absolutePath(); QString absAssetsDir = QDir("assets/").absolutePath();
token_mapping["game_assets"] = absAssetsDir; token_mapping["game_assets"] = absAssetsDir;
@ -91,7 +91,7 @@ MinecraftProcess* OneSixInstance::prepareForLaunch ( QString user, QString sessi
if(!version) if(!version)
return nullptr; return nullptr;
auto libs_to_extract = version->getActiveNativeLibs(); 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); bool success = ensurePathExists(natives_dir_raw);
if(!success) if(!success)
{ {
@ -140,13 +140,13 @@ MinecraftProcess* OneSixInstance::prepareForLaunch ( QString user, QString sessi
// create the process and set its parameters // create the process and set its parameters
MinecraftProcess * proc = new MinecraftProcess(this); MinecraftProcess * proc = new MinecraftProcess(this);
proc->setMinecraftArguments(args); proc->setMinecraftArguments(args);
proc->setMinecraftWorkdir(rootDir()); proc->setMinecraftWorkdir(minecraftRoot());
return proc; return proc;
} }
void OneSixInstance::cleanupAfterRun() void OneSixInstance::cleanupAfterRun()
{ {
QString target_dir = PathCombine(rootDir(), "natives/"); QString target_dir = PathCombine(instanceRoot(), "natives/");
QDir dir(target_dir); QDir dir(target_dir);
dir.removeRecursively(); dir.removeRecursively();
} }
@ -155,6 +155,7 @@ bool OneSixInstance::setIntendedVersionId ( QString version )
{ {
settings().set("IntendedVersion", version); settings().set("IntendedVersion", version);
setShouldUpdate(true); setShouldUpdate(true);
return true;
} }
QString OneSixInstance::intendedVersionId() const QString OneSixInstance::intendedVersionId() const
@ -187,7 +188,7 @@ bool OneSixInstance::reloadFullVersion()
{ {
I_D(OneSixInstance); I_D(OneSixInstance);
QString verpath = PathCombine(rootDir(), "version.json"); QString verpath = PathCombine(instanceRoot(), "version.json");
QFile versionfile(verpath); QFile versionfile(verpath);
if(versionfile.exists() && versionfile.open(QIODevice::ReadOnly)) if(versionfile.exists() && versionfile.open(QIODevice::ReadOnly))
{ {

View File

@ -38,6 +38,15 @@ OneSixUpdate::OneSixUpdate(BaseInstance *inst, QObject *parent):BaseUpdate(inst,
void OneSixUpdate::executeTask() void OneSixUpdate::executeTask()
{ {
QString intendedVersion = m_inst->intendedVersionId(); 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. // Get a pointer to the version object that corresponds to the instance's version.
targetVersion = MinecraftVersionList::getMainList().findVersion(intendedVersion).dynamicCast<MinecraftVersion>(); targetVersion = MinecraftVersionList::getMainList().findVersion(intendedVersion).dynamicCast<MinecraftVersion>();
if(targetVersion == nullptr) if(targetVersion == nullptr)
@ -78,7 +87,7 @@ void OneSixUpdate::versionFileFinished()
auto DlJob = firstJob.dynamicCast<DownloadJob>(); auto DlJob = firstJob.dynamicCast<DownloadJob>();
QString version_id = targetVersion->descriptor; 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 // save the version file in $instanceId/version.json
{ {
QString version1 = PathCombine(inst_dir, "/version.json"); QString version1 = PathCombine(inst_dir, "/version.json");

View File

@ -44,7 +44,6 @@ private slots:
void jarlibFailed(); void jarlibFailed();
private: private:
JobListPtr legacyDownloadJob;
JobListPtr specificVersionDownloadJob; JobListPtr specificVersionDownloadJob;
JobListPtr jarlibDownloadJob; JobListPtr jarlibDownloadJob;
JobListQueue download_queue; JobListQueue download_queue;

View File

@ -141,8 +141,7 @@ MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
legacyWhitelist.insert("1.2.1"); legacyWhitelist.insert("1.2.1");
legacyWhitelist.insert("1.1"); legacyWhitelist.insert("1.1");
legacyWhitelist.insert("1.0.1"); legacyWhitelist.insert("1.0.1");
legacyWhitelist.insert("1.0.0"); legacyWhitelist.insert("1.0");
// TODO: consider adding betas here too (whatever the legacy launcher supports)
} }
MCVListLoadTask::~MCVListLoadTask() MCVListLoadTask::~MCVListLoadTask()

View File

@ -68,7 +68,7 @@ QVariant InstanceModel::data ( const QModelIndex& index, int role ) const
} }
case Qt::ToolTipRole: case Qt::ToolTipRole:
{ {
return pdata->rootDir(); return pdata->instanceRoot();
} }
case Qt::DecorationRole: case Qt::DecorationRole:
{ {

View File

@ -109,6 +109,7 @@ MainWindow::MainWindow ( QWidget *parent ) :
view->setItemDelegate(delegate); view->setItemDelegate(delegate);
view->setSpacing(10); view->setSpacing(10);
view->setUniformItemWidths(true); view->setUniformItemWidths(true);
view->installEventFilter(this);
model = new InstanceModel ( instList,this ); model = new InstanceModel ( instList,this );
proxymodel = new InstanceProxyModel ( this ); proxymodel = new InstanceProxyModel ( this );
@ -160,6 +161,37 @@ MainWindow::~MainWindow()
delete assets_downloader; 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 ) void MainWindow::instanceActivated ( QModelIndex index )
{ {
if(!index.isValid()) if(!index.isValid())
@ -306,7 +338,7 @@ void MainWindow::on_actionDeleteInstance_triggered()
QString("This is permanent! Are you sure?\nAbout to delete: ") + inst->name()); QString("This is permanent! Are you sure?\nAbout to delete: ") + inst->name());
if (response == QMessageBox::Yes) if (response == QMessageBox::Yes)
{ {
QDir(inst->rootDir()).removeRecursively(); QDir(inst->instanceRoot()).removeRecursively();
instList.loadList(); instList.loadList();
} }
} }
@ -335,7 +367,7 @@ void MainWindow::on_actionViewSelectedInstFolder_triggered()
BaseInstance* inst = selectedInstance(); BaseInstance* inst = selectedInstance();
if(inst) if(inst)
{ {
QString str = inst->rootDir(); QString str = inst->instanceRoot();
openDirInDefaultProgram ( QDir(str).absolutePath() ); openDirInDefaultProgram ( QDir(str).absolutePath() );
} }
} }

View File

@ -122,6 +122,9 @@ public slots:
void launchInstance(BaseInstance *inst, LoginResponse response); void launchInstance(BaseInstance *inst, LoginResponse response);
protected:
bool eventFilter(QObject *obj, QEvent *ev);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
KCategoryDrawer * drawer; KCategoryDrawer * drawer;