GH-1927 Add more specific task status logging

* Tasks are now described by class name and object name (or memory address).
* Tasks starts are logged.
* Aborted tasks are now treated just as the other cases.
This commit is contained in:
Petr Mrázek
2017-07-07 19:46:56 +02:00
parent fbeceaa98c
commit e5b4b5d295
13 changed files with 194 additions and 122 deletions

View File

@ -9,9 +9,9 @@
typedef std::shared_ptr<class SkinUpload> SkinUploadPtr;
class MULTIMC_LOGIC_EXPORT SkinUpload : public Task\
class MULTIMC_LOGIC_EXPORT SkinUpload : public Task
{
Q_OBJECT
Q_OBJECT
public:
enum Model
{

View File

@ -95,85 +95,87 @@ shared_qobject_ptr<Task> LegacyInstance::createUpdateTask()
return shared_qobject_ptr<Task>(new LegacyUpdate(this, this));
}
std::shared_ptr<Task> LegacyInstance::createJarModdingTask()
class LegacyJarModTask : public Task
{
class JarModTask : public Task
Q_OBJECT
public:
explicit LegacyJarModTask(std::shared_ptr<LegacyInstance> inst) : Task(nullptr), m_inst(inst)
{
public:
explicit JarModTask(std::shared_ptr<LegacyInstance> inst) : Task(nullptr), m_inst(inst)
}
virtual void executeTask()
{
if (!m_inst->shouldRebuild())
{
emitSucceeded();
return;
}
virtual void executeTask()
// Get the mod list
auto modList = m_inst->getJarMods();
QFileInfo runnableJar(m_inst->runnableJar());
QFileInfo baseJar(m_inst->baseJar());
bool base_is_custom = m_inst->shouldUseCustomBaseJar();
// Nothing to do if there are no jar mods to install, no backup and just the mc jar
if (base_is_custom)
{
if (!m_inst->shouldRebuild())
// yes, this can happen if the instance only has the runnable jar and not the base jar
// it *could* be assumed that such an instance is vanilla, but that wouldn't be safe
// because that's not something mmc4 guarantees
if (runnableJar.isFile() && !baseJar.exists() && modList.empty())
{
m_inst->setShouldRebuild(false);
emitSucceeded();
return;
}
// Get the mod list
auto modList = m_inst->getJarMods();
QFileInfo runnableJar(m_inst->runnableJar());
QFileInfo baseJar(m_inst->baseJar());
bool base_is_custom = m_inst->shouldUseCustomBaseJar();
// Nothing to do if there are no jar mods to install, no backup and just the mc jar
if (base_is_custom)
setStatus(tr("Installing mods: Backing up minecraft.jar ..."));
if (!baseJar.exists() && !QFile::copy(runnableJar.filePath(), baseJar.filePath()))
{
// yes, this can happen if the instance only has the runnable jar and not the base jar
// it *could* be assumed that such an instance is vanilla, but that wouldn't be safe
// because that's not something mmc4 guarantees
if (runnableJar.isFile() && !baseJar.exists() && modList.empty())
{
m_inst->setShouldRebuild(false);
emitSucceeded();
return;
}
setStatus(tr("Installing mods: Backing up minecraft.jar ..."));
if (!baseJar.exists() && !QFile::copy(runnableJar.filePath(), baseJar.filePath()))
{
emitFailed("It seems both the active and base jar are gone. A fresh base jar will "
"be used on next run.");
m_inst->setShouldRebuild(true);
m_inst->setShouldUpdate(true);
m_inst->setShouldUseCustomBaseJar(false);
return;
}
}
if (!baseJar.exists())
{
emitFailed("The base jar " + baseJar.filePath() + " does not exist");
emitFailed("It seems both the active and base jar are gone. A fresh base jar will "
"be used on next run.");
m_inst->setShouldRebuild(true);
m_inst->setShouldUpdate(true);
m_inst->setShouldUseCustomBaseJar(false);
return;
}
if (runnableJar.exists() && !QFile::remove(runnableJar.filePath()))
{
emitFailed("Failed to delete old minecraft.jar");
return;
}
setStatus(tr("Installing mods: Opening minecraft.jar ..."));
QString outputJarPath = runnableJar.filePath();
QString inputJarPath = baseJar.filePath();
if(!MMCZip::createModdedJar(inputJarPath, outputJarPath, modList))
{
emitFailed(tr("Failed to create the custom Minecraft jar file."));
return;
}
m_inst->setShouldRebuild(false);
// inst->UpdateVersion(true);
emitSucceeded();
return;
}
std::shared_ptr<LegacyInstance> m_inst;
};
return std::make_shared<JarModTask>(std::dynamic_pointer_cast<LegacyInstance>(shared_from_this()));
if (!baseJar.exists())
{
emitFailed("The base jar " + baseJar.filePath() + " does not exist");
return;
}
if (runnableJar.exists() && !QFile::remove(runnableJar.filePath()))
{
emitFailed("Failed to delete old minecraft.jar");
return;
}
setStatus(tr("Installing mods: Opening minecraft.jar ..."));
QString outputJarPath = runnableJar.filePath();
QString inputJarPath = baseJar.filePath();
if(!MMCZip::createModdedJar(inputJarPath, outputJarPath, modList))
{
emitFailed(tr("Failed to create the custom Minecraft jar file."));
return;
}
m_inst->setShouldRebuild(false);
// inst->UpdateVersion(true);
emitSucceeded();
return;
}
std::shared_ptr<LegacyInstance> m_inst;
};
std::shared_ptr<Task> LegacyInstance::createJarModdingTask()
{
return std::make_shared<LegacyJarModTask>(std::dynamic_pointer_cast<LegacyInstance>(shared_from_this()));
}
QString LegacyInstance::createLaunchScript(AuthSessionPtr session)
@ -515,3 +517,5 @@ QStringList LegacyInstance::processMinecraftArgs(AuthSessionPtr account) const
out.append(account->session);
return out;
}
#include "LegacyInstance.moc"

View File

@ -368,53 +368,54 @@ std::shared_ptr<LaunchStep> OneSixInstance::createMainLaunchStep(LaunchTask * pa
return nullptr;
}
class JarModTask : public Task
{
Q_OBJECT
public:
explicit JarModTask(std::shared_ptr<OneSixInstance> inst) : Task(nullptr), m_inst(inst)
{
}
virtual void executeTask()
{
auto profile = m_inst->getMinecraftProfile();
// nuke obsolete stripped jar(s) if needed
QString version_id = profile->getMinecraftVersion();
if(!FS::ensureFolderPathExists(m_inst->binRoot()))
{
emitFailed(tr("Couldn't create the bin folder for Minecraft.jar"));
}
auto finalJarPath = QDir(m_inst->binRoot()).absoluteFilePath("minecraft.jar");
QFile finalJar(finalJarPath);
if(finalJar.exists())
{
if(!finalJar.remove())
{
emitFailed(tr("Couldn't remove stale jar file: %1").arg(finalJarPath));
return;
}
}
// create temporary modded jar, if needed
auto jarMods = m_inst->getJarMods();
if(jarMods.size())
{
auto mainJar = profile->getMainJar();
QStringList jars, temp1, temp2, temp3, temp4;
mainJar->getApplicableFiles(currentSystem, jars, temp1, temp2, temp3, m_inst->getLocalLibraryPath());
auto sourceJarPath = jars[0];
if(!MMCZip::createModdedJar(sourceJarPath, finalJarPath, jarMods))
{
emitFailed(tr("Failed to create the custom Minecraft jar file."));
return;
}
}
emitSucceeded();
}
std::shared_ptr<OneSixInstance> m_inst;
};
std::shared_ptr<Task> OneSixInstance::createJarModdingTask()
{
class JarModTask : public Task
{
public:
explicit JarModTask(std::shared_ptr<OneSixInstance> inst) : Task(nullptr), m_inst(inst)
{
}
virtual void executeTask()
{
auto profile = m_inst->getMinecraftProfile();
// nuke obsolete stripped jar(s) if needed
QString version_id = profile->getMinecraftVersion();
if(!FS::ensureFolderPathExists(m_inst->binRoot()))
{
emitFailed(tr("Couldn't create the bin folder for Minecraft.jar"));
}
auto finalJarPath = QDir(m_inst->binRoot()).absoluteFilePath("minecraft.jar");
QFile finalJar(finalJarPath);
if(finalJar.exists())
{
if(!finalJar.remove())
{
emitFailed(tr("Couldn't remove stale jar file: %1").arg(finalJarPath));
return;
}
}
// create temporary modded jar, if needed
auto jarMods = m_inst->getJarMods();
if(jarMods.size())
{
auto mainJar = profile->getMainJar();
QStringList jars, temp1, temp2, temp3, temp4;
mainJar->getApplicableFiles(currentSystem, jars, temp1, temp2, temp3, m_inst->getLocalLibraryPath());
auto sourceJarPath = jars[0];
if(!MMCZip::createModdedJar(sourceJarPath, finalJarPath, jarMods))
{
emitFailed(tr("Failed to create the custom Minecraft jar file."));
return;
}
}
emitSucceeded();
}
std::shared_ptr<OneSixInstance> m_inst;
};
return std::make_shared<JarModTask>(std::dynamic_pointer_cast<OneSixInstance>(shared_from_this()));
}
@ -696,3 +697,5 @@ QStringList OneSixInstance::getNativeJars() const
m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot());
return nativeJars;
}
#include "OneSixInstance.moc"

View File

@ -142,11 +142,21 @@ void OneSixUpdate::next()
void OneSixUpdate::subtaskSucceeded()
{
if(isFinished())
{
qCritical() << "OneSixUpdate: Subtask" << sender() << "succeeded, but work was already done!";
return;
}
next();
}
void OneSixUpdate::subtaskFailed(QString error)
{
if(isFinished())
{
qCritical() << "OneSixUpdate: Subtask" << sender() << "failed, but work was already done!";
return;
}
emitFailed(error);
}

View File

@ -5,6 +5,7 @@ class OneSixInstance;
class AssetUpdateTask : public Task
{
Q_OBJECT
public:
AssetUpdateTask(OneSixInstance * inst);
void executeTask() override;

View File

@ -5,6 +5,7 @@ class OneSixInstance;
class FMLLibrariesTask : public Task
{
Q_OBJECT
public:
FMLLibrariesTask(OneSixInstance * inst);

View File

@ -3,6 +3,7 @@
#include <QDir>
FoldersTask::FoldersTask(OneSixInstance * inst)
:Task()
{
m_inst = inst;
}

View File

@ -5,6 +5,7 @@
class OneSixInstance;
class FoldersTask : public Task
{
Q_OBJECT
public:
FoldersTask(OneSixInstance * inst);
void executeTask() override;

View File

@ -5,6 +5,7 @@ class OneSixInstance;
class LibrariesTask : public Task
{
Q_OBJECT
public:
LibrariesTask(OneSixInstance * inst);