1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00

Merge pull request #2786 from vcmi/lobby

Minor improvements for launcher
This commit is contained in:
Nordsoft91 2023-09-12 23:37:22 +02:00 committed by GitHub
commit 2db6a75028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 6 deletions

View File

@ -189,10 +189,14 @@ void Lobby::serverCommand(const ServerCommand & command) try
case CLIENTMODS: {
protocolAssert(args.size() >= 1);
auto & clientModsMap = clientsModsMap[args[0]];
amount = args[1].toInt();
protocolAssert(amount * 2 == (args.size() - 2));
tagPoint = 2;
for(int i = 0; i < amount; ++i, tagPoint += 2)
clientModsMap[args[tagPoint]] = args[tagPoint + 1];
break;
}
@ -342,6 +346,7 @@ void Lobby::onDisconnected()
authentificationStatus = AuthStatus::AUTH_NONE;
session = "";
ui->chatWidget->setSession(session);
ui->chatWidget->setChannel("global");
ui->stackedWidget->setCurrentWidget(ui->sessionsPage);
ui->connectButton->setChecked(false);
ui->serverEdit->setEnabled(true);
@ -517,7 +522,14 @@ void Lobby::on_kickButton_clicked()
void Lobby::on_buttonResolve_clicked()
{
QStringList toEnableList, toDisableList;
for(auto * item : ui->modsList->selectedItems())
auto items = ui->modsList->selectedItems();
if(items.empty())
{
for(int i = 0; i < ui->modsList->count(); ++i)
items.push_back(ui->modsList->item(i));
}
for(auto * item : items)
{
auto modName = item->data(ModResolutionRoles::ModNameRole);
if(modName.isNull())

View File

@ -74,6 +74,7 @@ private:
QString username;
QStringList gameArgs;
QMap<QString, QString> hostModsMap;
QMap<QString, QMap<QString, QString>> clientsModsMap;
enum AuthStatus
{

View File

@ -22,15 +22,15 @@
namespace
{
QString detectModArchive(QString path, QString modName)
QString detectModArchive(QString path, QString modName, std::vector<std::string> & filesToExtract)
{
auto files = ZipArchive::listFiles(qstringToPath(path));
filesToExtract = ZipArchive::listFiles(qstringToPath(path));
QString modDirName;
for(int folderLevel : {0, 1}) //search in subfolder if there is no mod.json in the root
{
for(auto file : files)
for(auto file : filesToExtract)
{
QString filename = QString::fromUtf8(file.c_str());
modDirName = filename.section('/', 0, folderLevel);
@ -275,11 +275,12 @@ bool CModManager::doInstallMod(QString modname, QString archivePath)
if(localMods.contains(modname))
return addError(modname, "Mod with such name is already installed");
QString modDirName = ::detectModArchive(archivePath, modname);
std::vector<std::string> filesToExtract;
QString modDirName = ::detectModArchive(archivePath, modname, filesToExtract);
if(!modDirName.size())
return addError(modname, "Mod archive is invalid or corrupted");
if(!ZipArchive::extract(qstringToPath(archivePath), qstringToPath(destDir)))
if(!ZipArchive::extract(qstringToPath(archivePath), qstringToPath(destDir), filesToExtract))
{
removeModDir(destDir + modDirName);
return addError(modname, "Failed to extract mod data");