mirror of
https://github.com/vcmi/vcmi.git
synced 2025-10-08 23:22:25 +02:00
basic error reporting for launcher.
This commit is contained in:
@@ -341,6 +341,7 @@ void CModListView::on_enableButton_clicked()
|
|||||||
for (auto & name : modModel->getRequirements(modName))
|
for (auto & name : modModel->getRequirements(modName))
|
||||||
if (modModel->getMod(name).isDisabled())
|
if (modModel->getMod(name).isDisabled())
|
||||||
manager->enableMod(name);
|
manager->enableMod(name);
|
||||||
|
checkManagerErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModListView::on_disableButton_clicked()
|
void CModListView::on_disableButton_clicked()
|
||||||
@@ -351,6 +352,7 @@ void CModListView::on_disableButton_clicked()
|
|||||||
if (modModel->hasMod(name) &&
|
if (modModel->hasMod(name) &&
|
||||||
modModel->getMod(name).isEnabled())
|
modModel->getMod(name).isEnabled())
|
||||||
manager->disableMod(name);
|
manager->disableMod(name);
|
||||||
|
checkManagerErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModListView::on_updateButton_clicked()
|
void CModListView::on_updateButton_clicked()
|
||||||
@@ -379,6 +381,7 @@ void CModListView::on_uninstallButton_clicked()
|
|||||||
manager->disableMod(modName);
|
manager->disableMod(modName);
|
||||||
manager->uninstallMod(modName);
|
manager->uninstallMod(modName);
|
||||||
}
|
}
|
||||||
|
checkManagerErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModListView::on_installButton_clicked()
|
void CModListView::on_installButton_clicked()
|
||||||
@@ -488,8 +491,6 @@ void CModListView::installFiles(QStringList files)
|
|||||||
|
|
||||||
void CModListView::installMods(QStringList archives)
|
void CModListView::installMods(QStringList archives)
|
||||||
{
|
{
|
||||||
//TODO: check return status of all calls to manager!!!
|
|
||||||
|
|
||||||
QStringList modNames;
|
QStringList modNames;
|
||||||
|
|
||||||
for (QString archive : archives)
|
for (QString archive : archives)
|
||||||
@@ -503,11 +504,17 @@ void CModListView::installMods(QStringList archives)
|
|||||||
|
|
||||||
// disable mod(s), to properly recalculate dependencies, if changed
|
// disable mod(s), to properly recalculate dependencies, if changed
|
||||||
for (QString mod : boost::adaptors::reverse(modNames))
|
for (QString mod : boost::adaptors::reverse(modNames))
|
||||||
manager->disableMod(mod);
|
{
|
||||||
|
if (modModel->getMod(mod).isInstalled())
|
||||||
|
manager->disableMod(mod);
|
||||||
|
}
|
||||||
|
|
||||||
// uninstall old version of mod, if installed
|
// uninstall old version of mod, if installed
|
||||||
for (QString mod : boost::adaptors::reverse(modNames))
|
for (QString mod : boost::adaptors::reverse(modNames))
|
||||||
manager->uninstallMod(mod);
|
{
|
||||||
|
if (modModel->getMod(mod).isInstalled())
|
||||||
|
manager->uninstallMod(mod);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i=0; i<modNames.size(); i++)
|
for (int i=0; i<modNames.size(); i++)
|
||||||
manager->installMod(modNames[i], archives[i]);
|
manager->installMod(modNames[i], archives[i]);
|
||||||
@@ -520,6 +527,8 @@ void CModListView::installMods(QStringList archives)
|
|||||||
|
|
||||||
for (QString archive : archives)
|
for (QString archive : archives)
|
||||||
QFile::remove(archive);
|
QFile::remove(archive);
|
||||||
|
|
||||||
|
checkManagerErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModListView::on_pushButton_clicked()
|
void CModListView::on_pushButton_clicked()
|
||||||
@@ -534,3 +543,14 @@ void CModListView::modelReset()
|
|||||||
//selectMod(filterModel->mapToSource(ui->allModsView->currentIndex()).row());
|
//selectMod(filterModel->mapToSource(ui->allModsView->currentIndex()).row());
|
||||||
selectMod(filterModel->rowCount() > 0 ? 0 : -1);
|
selectMod(filterModel->rowCount() > 0 ? 0 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CModListView::checkManagerErrors()
|
||||||
|
{
|
||||||
|
QString errors = manager->getErrors().join('\n');
|
||||||
|
if (errors.size() != 0)
|
||||||
|
{
|
||||||
|
QString title = "Operation failed";
|
||||||
|
QString description = "Encountered errors:\n" + errors;
|
||||||
|
QMessageBox::warning(this, title, description, QMessageBox::Ok, QMessageBox::Ok );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -36,6 +36,8 @@ class CModListView : public QWidget
|
|||||||
void setupModsView();
|
void setupModsView();
|
||||||
void loadRepositories();
|
void loadRepositories();
|
||||||
|
|
||||||
|
void checkManagerErrors();
|
||||||
|
|
||||||
// find mods unknown to mod list (not present in repo and not installed)
|
// find mods unknown to mod list (not present in repo and not installed)
|
||||||
QStringList findInvalidDependencies(QString mod);
|
QStringList findInvalidDependencies(QString mod);
|
||||||
// find mods that block enabling of this mod: conflicting with this mod or one of required mods
|
// find mods that block enabling of this mod: conflicting with this mod or one of required mods
|
||||||
|
@@ -93,6 +93,19 @@ void CModManager::loadMods()
|
|||||||
modList->setLocalModList(localMods);
|
modList->setLocalModList(localMods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CModManager::addError(QString modname, QString message)
|
||||||
|
{
|
||||||
|
recentErrors.push_back(QString("%1: %2").arg(modname).arg(message));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CModManager::getErrors()
|
||||||
|
{
|
||||||
|
QStringList ret = recentErrors;
|
||||||
|
recentErrors.clear();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool CModManager::installMod(QString modname, QString archivePath)
|
bool CModManager::installMod(QString modname, QString archivePath)
|
||||||
{
|
{
|
||||||
return canInstallMod(modname) && doInstallMod(modname, archivePath);
|
return canInstallMod(modname) && doInstallMod(modname, archivePath);
|
||||||
@@ -118,10 +131,10 @@ bool CModManager::canInstallMod(QString modname)
|
|||||||
auto mod = modList->getMod(modname);
|
auto mod = modList->getMod(modname);
|
||||||
|
|
||||||
if (mod.isInstalled())
|
if (mod.isInstalled())
|
||||||
return false;
|
return addError(modname, "Mod is already installed");
|
||||||
|
|
||||||
if (!mod.isAvailable())
|
if (!mod.isAvailable())
|
||||||
return false;
|
return addError(modname, "Mod is not available");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,10 +143,10 @@ bool CModManager::canUninstallMod(QString modname)
|
|||||||
auto mod = modList->getMod(modname);
|
auto mod = modList->getMod(modname);
|
||||||
|
|
||||||
if (!mod.isInstalled())
|
if (!mod.isInstalled())
|
||||||
return false;
|
return addError(modname, "Mod is not installed");
|
||||||
|
|
||||||
if (mod.isEnabled())
|
if (mod.isEnabled())
|
||||||
return false;
|
return addError(modname, "Mod must be disabled first");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,32 +155,33 @@ bool CModManager::canEnableMod(QString modname)
|
|||||||
auto mod = modList->getMod(modname);
|
auto mod = modList->getMod(modname);
|
||||||
|
|
||||||
if (mod.isEnabled())
|
if (mod.isEnabled())
|
||||||
return false;
|
return addError(modname, "Mod is already enabled");
|
||||||
|
|
||||||
if (!mod.isInstalled())
|
if (!mod.isInstalled())
|
||||||
return false;
|
return addError(modname, "Mod must be installed first");
|
||||||
|
|
||||||
for (auto modEntry : mod.getValue("depends").toStringList())
|
for (auto modEntry : mod.getValue("depends").toStringList())
|
||||||
{
|
{
|
||||||
if (!modList->hasMod(modEntry)) // required mod is not available
|
if (!modList->hasMod(modEntry)) // required mod is not available
|
||||||
return false;
|
return addError(modname, QString("Required mod %1 is missing").arg(modEntry));
|
||||||
if (!modList->getMod(modEntry).isEnabled())
|
if (!modList->getMod(modEntry).isEnabled())
|
||||||
return false;
|
return addError(modname, QString("Required mod %1 is not enabled").arg(modEntry));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (QString name : modList->getModList())
|
for (QString modEntry : modList->getModList())
|
||||||
{
|
{
|
||||||
auto mod = modList->getMod(name);
|
auto mod = modList->getMod(modEntry);
|
||||||
|
|
||||||
|
// "reverse conflict" - enabled mod has this one as conflict
|
||||||
if (mod.isEnabled() && mod.getValue("conflicts").toStringList().contains(modname))
|
if (mod.isEnabled() && mod.getValue("conflicts").toStringList().contains(modname))
|
||||||
return false; // "reverse conflict" - enabled mod has this one as conflict
|
return addError(modname, QString("This mod conflicts with %1").arg(modEntry));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto modEntry : mod.getValue("conflicts").toStringList())
|
for (auto modEntry : mod.getValue("conflicts").toStringList())
|
||||||
{
|
{
|
||||||
if (modList->hasMod(modEntry) &&
|
if (modList->hasMod(modEntry) &&
|
||||||
modList->getMod(modEntry).isEnabled()) // conflicting mod installed and enabled
|
modList->getMod(modEntry).isEnabled()) // conflicting mod installed and enabled
|
||||||
return false;
|
return addError(modname, QString("This mod conflicts with %1").arg(modEntry));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -177,10 +191,10 @@ bool CModManager::canDisableMod(QString modname)
|
|||||||
auto mod = modList->getMod(modname);
|
auto mod = modList->getMod(modname);
|
||||||
|
|
||||||
if (mod.isDisabled())
|
if (mod.isDisabled())
|
||||||
return false;
|
return addError(modname, "Mod is already disabled");
|
||||||
|
|
||||||
if (!mod.isInstalled())
|
if (!mod.isInstalled())
|
||||||
return false;
|
return addError(modname, "Mod must be installed first");
|
||||||
|
|
||||||
for (QString modEntry : modList->getModList())
|
for (QString modEntry : modList->getModList())
|
||||||
{
|
{
|
||||||
@@ -188,7 +202,7 @@ bool CModManager::canDisableMod(QString modname)
|
|||||||
|
|
||||||
if (current.getValue("depends").toStringList().contains(modname) &&
|
if (current.getValue("depends").toStringList().contains(modname) &&
|
||||||
current.isEnabled())
|
current.isEnabled())
|
||||||
return false; // this mod must be disabled first
|
return addError(modname, QString("This mod is needed to run %1").arg(modEntry));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -213,22 +227,22 @@ bool CModManager::doInstallMod(QString modname, QString archivePath)
|
|||||||
QString destDir = CLauncherDirs::get().modsPath() + "/";
|
QString destDir = CLauncherDirs::get().modsPath() + "/";
|
||||||
|
|
||||||
if (!QFile(archivePath).exists())
|
if (!QFile(archivePath).exists())
|
||||||
return false; // archive with mod data exists
|
return addError(modname, "Mod archive is missing");
|
||||||
|
|
||||||
if (QDir(destDir + modname).exists()) // FIXME: recheck wog/vcmi data behavior - they have bits of data in our trunk
|
if (QDir(destDir + modname).exists()) // FIXME: recheck wog/vcmi data behavior - they have bits of data in our trunk
|
||||||
return false; // no mod with such name installed
|
return addError(modname, "Mod with such name is already installed");
|
||||||
|
|
||||||
if (localMods.contains(modname))
|
if (localMods.contains(modname))
|
||||||
return false; // no installed data known
|
return addError(modname, "Mod with such name is already installed");
|
||||||
|
|
||||||
QString modDirName = detectModArchive(archivePath, modname);
|
QString modDirName = detectModArchive(archivePath, modname);
|
||||||
if (!modDirName.size())
|
if (!modDirName.size())
|
||||||
return false; // archive content looks like mod FS
|
return addError(modname, "Mod archive is invalid or corrupted");
|
||||||
|
|
||||||
if (!ZipArchive::extract(archivePath.toUtf8().data(), destDir.toUtf8().data()))
|
if (!ZipArchive::extract(archivePath.toUtf8().data(), destDir.toUtf8().data()))
|
||||||
{
|
{
|
||||||
QDir(destDir + modDirName).removeRecursively();
|
QDir(destDir + modDirName).removeRecursively();
|
||||||
return false; // extraction failed
|
return addError(modname, "Failed to extract mod data");
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject json = JsonFromFile(destDir + modDirName + "/mod.json");
|
QJsonObject json = JsonFromFile(destDir + modDirName + "/mod.json");
|
||||||
@@ -246,13 +260,13 @@ bool CModManager::doUninstallMod(QString modname)
|
|||||||
QString modDir = QString::fromUtf8(CResourceHandler::get()->getResourceName(resID)->c_str());
|
QString modDir = QString::fromUtf8(CResourceHandler::get()->getResourceName(resID)->c_str());
|
||||||
|
|
||||||
if (!QDir(modDir).exists())
|
if (!QDir(modDir).exists())
|
||||||
return false;
|
return addError(modname, "Data with this mod was not found");
|
||||||
|
|
||||||
if (!localMods.contains(modname))
|
if (!localMods.contains(modname))
|
||||||
return false;
|
return addError(modname, "Data with this mod was not found");
|
||||||
|
|
||||||
if (!QDir(modDir).removeRecursively())
|
if (!QDir(modDir).removeRecursively())
|
||||||
return false;
|
return addError(modname, "Failed to delete mod data");
|
||||||
|
|
||||||
localMods.remove(modname);
|
localMods.remove(modname);
|
||||||
modList->setLocalModList(localMods);
|
modList->setLocalModList(localMods);
|
||||||
|
@@ -16,6 +16,8 @@ class CModManager
|
|||||||
QJsonObject modSettings;
|
QJsonObject modSettings;
|
||||||
QJsonObject localMods;
|
QJsonObject localMods;
|
||||||
|
|
||||||
|
QStringList recentErrors;
|
||||||
|
bool addError(QString modname, QString message);
|
||||||
public:
|
public:
|
||||||
CModManager(CModList * modList);
|
CModManager(CModList * modList);
|
||||||
|
|
||||||
@@ -24,6 +26,8 @@ public:
|
|||||||
void loadModSettings();
|
void loadModSettings();
|
||||||
void loadMods();
|
void loadMods();
|
||||||
|
|
||||||
|
QStringList getErrors();
|
||||||
|
|
||||||
/// mod management functions. Return true if operation was successful
|
/// mod management functions. Return true if operation was successful
|
||||||
|
|
||||||
/// installs mod from zip archive located at archivePath
|
/// installs mod from zip archive located at archivePath
|
||||||
|
Reference in New Issue
Block a user