diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index b7fd754eb..f1fc0b509 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -5,29 +5,29 @@ include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}) set(launcher_modmanager_SRCS - modManager/cdownloadmanager.cpp + modManager/cdownloadmanager_moc.cpp modManager/cmodlist.cpp - modManager/cmodlistmodel.cpp - modManager/cmodlistview.cpp + modManager/cmodlistmodel_moc.cpp + modManager/cmodlistview_moc.cpp modManager/cmodmanager.cpp ) set(launcher_settingsview_SRCS - settingsView/csettingsview.cpp + settingsView/csettingsview_moc.cpp ) set(launcher_SRCS ${launcher_modmanager_SRCS} ${launcher_settingsview_SRCS} main.cpp - mainwindow.cpp + mainwindow_moc.cpp launcherdirs.cpp ) set(launcher_FORMS - modManager/cmodlistview.ui - settingsView/csettingsview.ui - mainwindow.ui + modManager/cmodlistview_moc.ui + settingsView/csettingsview_moc.ui + mainwindow_moc.ui ) # Tell CMake to run moc when necessary: diff --git a/launcher/main.cpp b/launcher/main.cpp index 5d88094d4..e9fd317b5 100644 --- a/launcher/main.cpp +++ b/launcher/main.cpp @@ -1,5 +1,5 @@ #include "StdInc.h" -#include "mainwindow.h" +#include "mainwindow_moc.h" #include int main(int argc, char *argv[]) diff --git a/launcher/mainwindow.cpp b/launcher/mainwindow_moc.cpp similarity index 81% rename from launcher/mainwindow.cpp rename to launcher/mainwindow_moc.cpp index d02393877..804aab9f2 100644 --- a/launcher/mainwindow.cpp +++ b/launcher/mainwindow_moc.cpp @@ -1,6 +1,6 @@ #include "StdInc.h" -#include "mainwindow.h" -#include "ui_mainwindow.h" +#include "mainwindow_moc.h" +#include "ui_mainwindow_moc.h" #include #include @@ -46,13 +46,7 @@ MainWindow::~MainWindow() void MainWindow::on_startGameButon_clicked() { -#if defined(Q_OS_WIN) - QString clientName = "VCMI_Client.exe"; -#else - // TODO: Right now launcher will only start vcmi from system-default locations - QString clientName = "vcmiclient"; -#endif - startExecutable(clientName); + startExecutable(QString::fromUtf8(VCMIDirs::get().clientPath().c_str())); } void MainWindow::startExecutable(QString name) @@ -68,7 +62,8 @@ void MainWindow::startExecutable(QString name) { QMessageBox::critical(this, "Error starting executable", - "Failed to start " + name + ": " + process.errorString(), + "Failed to start " + name + "\n" + "Reason: " + process.errorString(), QMessageBox::Ok, QMessageBox::Ok); return; diff --git a/launcher/mainwindow.h b/launcher/mainwindow_moc.h similarity index 100% rename from launcher/mainwindow.h rename to launcher/mainwindow_moc.h diff --git a/launcher/mainwindow.ui b/launcher/mainwindow_moc.ui similarity index 98% rename from launcher/mainwindow.ui rename to launcher/mainwindow_moc.ui index f2d65c8c9..7f746adcc 100644 --- a/launcher/mainwindow.ui +++ b/launcher/mainwindow_moc.ui @@ -187,13 +187,13 @@ CModListView QWidget -
modManager/cmodlistview.h
+
modManager/cmodlistview_moc.h
1
CSettingsView QWidget -
settingsView/csettingsview.h
+
settingsView/csettingsview_moc.h
1
diff --git a/launcher/modManager/cdownloadmanager.cpp b/launcher/modManager/cdownloadmanager_moc.cpp similarity index 98% rename from launcher/modManager/cdownloadmanager.cpp rename to launcher/modManager/cdownloadmanager_moc.cpp index 0d98dfc46..4c963b7f8 100644 --- a/launcher/modManager/cdownloadmanager.cpp +++ b/launcher/modManager/cdownloadmanager_moc.cpp @@ -1,5 +1,5 @@ #include "StdInc.h" -#include "cdownloadmanager.h" +#include "cdownloadmanager_moc.h" #include "launcherdirs.h" diff --git a/launcher/modManager/cdownloadmanager.h b/launcher/modManager/cdownloadmanager_moc.h similarity index 100% rename from launcher/modManager/cdownloadmanager.h rename to launcher/modManager/cdownloadmanager_moc.h diff --git a/launcher/modManager/cmodlist.cpp b/launcher/modManager/cmodlist.cpp index 3c503fe8b..a33e68e60 100644 --- a/launcher/modManager/cmodlist.cpp +++ b/launcher/modManager/cmodlist.cpp @@ -111,9 +111,14 @@ QJsonObject CModList::copyField(QJsonObject data, QString from, QString to) return renamed; } +void CModList::resetRepositories() +{ + repositories.clear(); +} + void CModList::addRepository(QJsonObject data) { - repositores.push_back(copyField(data, "version", "latestVersion")); + repositories.push_back(copyField(data, "version", "latestVersion")); } void CModList::setLocalModList(QJsonObject data) @@ -134,7 +139,7 @@ CModEntry CModList::getMod(QString modname) const QJsonObject local = localModList[modname].toObject(); QJsonValue settings = modSettings[modname]; - for (auto entry : repositores) + for (auto entry : repositories) { if (entry.contains(modname)) { @@ -157,7 +162,7 @@ bool CModList::hasMod(QString modname) const if (localModList.contains(modname)) return true; - for (auto entry : repositores) + for (auto entry : repositories) if (entry.contains(modname)) return true; @@ -184,7 +189,7 @@ QVector CModList::getModList() const { QSet knownMods; QVector modList; - for (auto repo : repositores) + for (auto repo : repositories) { for (auto it = repo.begin(); it != repo.end(); it++) { diff --git a/launcher/modManager/cmodlist.h b/launcher/modManager/cmodlist.h index 6e2bdf12c..766421608 100644 --- a/launcher/modManager/cmodlist.h +++ b/launcher/modManager/cmodlist.h @@ -52,12 +52,13 @@ public: class CModList { - QVector repositores; + QVector repositories; QJsonObject localModList; QJsonObject modSettings; QJsonObject copyField(QJsonObject data, QString from, QString to); public: + virtual void resetRepositories(); virtual void addRepository(QJsonObject data); virtual void setLocalModList(QJsonObject data); virtual void setModSettings(QJsonObject data); diff --git a/launcher/modManager/cmodlistmodel.cpp b/launcher/modManager/cmodlistmodel_moc.cpp similarity index 96% rename from launcher/modManager/cmodlistmodel.cpp rename to launcher/modManager/cmodlistmodel_moc.cpp index 141f42c26..1e3969b2b 100644 --- a/launcher/modManager/cmodlistmodel.cpp +++ b/launcher/modManager/cmodlistmodel_moc.cpp @@ -1,5 +1,5 @@ #include "StdInc.h" -#include "cmodlistmodel.h" +#include "cmodlistmodel_moc.h" #include @@ -110,6 +110,13 @@ QVariant CModListModel::headerData(int section, Qt::Orientation orientation, int return QVariant(); } +void CModListModel::resetRepositories() +{ + beginResetModel(); + CModList::resetRepositories(); + endResetModel(); +} + void CModListModel::addRepository(QJsonObject data) { beginResetModel(); diff --git a/launcher/modManager/cmodlistmodel.h b/launcher/modManager/cmodlistmodel_moc.h similarity index 98% rename from launcher/modManager/cmodlistmodel.h rename to launcher/modManager/cmodlistmodel_moc.h index 5dc705806..01ef3145a 100644 --- a/launcher/modManager/cmodlistmodel.h +++ b/launcher/modManager/cmodlistmodel_moc.h @@ -29,6 +29,7 @@ class CModListModel : public QAbstractTableModel, public CModList void endResetModel(); public: /// CModListContainer overrides + void resetRepositories(); void addRepository(QJsonObject data); void setLocalModList(QJsonObject data); void setModSettings(QJsonObject data); diff --git a/launcher/modManager/cmodlistview.cpp b/launcher/modManager/cmodlistview_moc.cpp similarity index 95% rename from launcher/modManager/cmodlistview.cpp rename to launcher/modManager/cmodlistview_moc.cpp index 20f7925a0..9bd9648f6 100644 --- a/launcher/modManager/cmodlistview.cpp +++ b/launcher/modManager/cmodlistview_moc.cpp @@ -1,13 +1,13 @@ #include "StdInc.h" -#include "cmodlistview.h" -#include "ui_cmodlistview.h" +#include "cmodlistview_moc.h" +#include "ui_cmodlistview_moc.h" #include #include -#include "cmodlistmodel.h" +#include "cmodlistmodel_moc.h" #include "cmodmanager.h" -#include "cdownloadmanager.h" +#include "cdownloadmanager_moc.h" #include "launcherdirs.h" #include "../lib/CConfigHandler.h" @@ -42,12 +42,16 @@ void CModListView::setupModsView() connect( filterModel, SIGNAL( modelReset()), this, SLOT( modelReset())); + + selectMod(filterModel->rowCount() > 0 ? 0 : -1); } CModListView::CModListView(QWidget *parent) : QWidget(parent), + settingsListener(settings.listen["launcher"]["repositoryURL"]), ui(new Ui::CModListView) { + settingsListener([&](const JsonNode &){ repositoriesChanged = true; }); ui->setupUi(this); setupModModel(); @@ -56,10 +60,12 @@ CModListView::CModListView(QWidget *parent) : ui->progressWidget->setVisible(false); dlManager = nullptr; + loadRepositories(); +} - // hide mod description on start. looks better this way - hideModInfo(); - +void CModListView::loadRepositories() +{ + manager->resetRepositories(); for (auto entry : settings["launcher"]["repositoryURL"].Vector()) { QString str = QString::fromUtf8(entry.String().c_str()); @@ -77,6 +83,16 @@ CModListView::~CModListView() delete ui; } +void CModListView::showEvent(QShowEvent * event) +{ + QWidget::showEvent(event); + if (repositoriesChanged) + { + repositoriesChanged = false; + loadRepositories(); + } +} + void CModListView::showModInfo() { ui->modInfoWidget->show(); @@ -174,6 +190,7 @@ QString CModListView::genModInfoText(CModEntry &mod) void CModListView::enableModInfo() { + showModInfo(); ui->hideModInfoButton->setEnabled(true); } @@ -514,5 +531,6 @@ void CModListView::on_pushButton_clicked() void CModListView::modelReset() { - selectMod(filterModel->mapToSource(ui->allModsView->currentIndex()).row()); -} \ No newline at end of file + //selectMod(filterModel->mapToSource(ui->allModsView->currentIndex()).row()); + selectMod(filterModel->rowCount() > 0 ? 0 : -1); +} diff --git a/launcher/modManager/cmodlistview.h b/launcher/modManager/cmodlistview_moc.h similarity index 91% rename from launcher/modManager/cmodlistview.h rename to launcher/modManager/cmodlistview_moc.h index 1fab2f4d4..97230ae66 100644 --- a/launcher/modManager/cmodlistview.h +++ b/launcher/modManager/cmodlistview_moc.h @@ -1,5 +1,8 @@ #pragma once +#include "Global.h" +#include "../../lib/CConfigHandler.h" + namespace Ui { class CModListView; } @@ -21,11 +24,17 @@ class CModListView : public QWidget CModFilterModel * filterModel; CDownloadManager * dlManager; + SettingsListener settingsListener; + bool repositoriesChanged; + + void showEvent(QShowEvent * event); + void keyPressEvent(QKeyEvent * event); void setupModModel(); void setupFilterModel(); void setupModsView(); + void loadRepositories(); // find mods unknown to mod list (not present in repo and not installed) QStringList findInvalidDependencies(QString mod); diff --git a/launcher/modManager/cmodlistview.ui b/launcher/modManager/cmodlistview_moc.ui similarity index 100% rename from launcher/modManager/cmodlistview.ui rename to launcher/modManager/cmodlistview_moc.ui diff --git a/launcher/modManager/cmodmanager.cpp b/launcher/modManager/cmodmanager.cpp index 7c4d18fb5..15bcf8c61 100644 --- a/launcher/modManager/cmodmanager.cpp +++ b/launcher/modManager/cmodmanager.cpp @@ -61,6 +61,11 @@ void CModManager::loadModSettings() modList->setModSettings(modSettings["activeMods"].toObject()); } +void CModManager::resetRepositories() +{ + modList->resetRepositories(); +} + void CModManager::loadRepository(QString file) { modList->addRepository(JsonFromFile(file)); @@ -182,7 +187,7 @@ bool CModManager::canDisableMod(QString modname) auto current = modList->getMod(modEntry); if (current.getValue("depends").toStringList().contains(modname) && - !current.isDisabled()) + current.isEnabled()) return false; // this mod must be disabled first } return true; diff --git a/launcher/modManager/cmodmanager.h b/launcher/modManager/cmodmanager.h index bb787a84d..acfc837dc 100644 --- a/launcher/modManager/cmodmanager.h +++ b/launcher/modManager/cmodmanager.h @@ -19,6 +19,7 @@ class CModManager public: CModManager(CModList * modList); + void resetRepositories(); void loadRepository(QString filename); void loadModSettings(); void loadMods(); diff --git a/launcher/settingsView/csettingsview.cpp b/launcher/settingsView/csettingsview_moc.cpp similarity index 98% rename from launcher/settingsView/csettingsview.cpp rename to launcher/settingsView/csettingsview_moc.cpp index 1dce1f976..9dfbdc2b3 100644 --- a/launcher/settingsView/csettingsview.cpp +++ b/launcher/settingsView/csettingsview_moc.cpp @@ -1,6 +1,6 @@ #include "StdInc.h" -#include "csettingsview.h" -#include "ui_csettingsview.h" +#include "csettingsview_moc.h" +#include "ui_csettingsview_moc.h" #include "../lib/CConfigHandler.h" #include "../lib/VCMIDirs.h" diff --git a/launcher/settingsView/csettingsview.h b/launcher/settingsView/csettingsview_moc.h similarity index 100% rename from launcher/settingsView/csettingsview.h rename to launcher/settingsView/csettingsview_moc.h diff --git a/launcher/settingsView/csettingsview.ui b/launcher/settingsView/csettingsview_moc.ui similarity index 100% rename from launcher/settingsView/csettingsview.ui rename to launcher/settingsView/csettingsview_moc.ui diff --git a/lib/VCMIDirs.cpp b/lib/VCMIDirs.cpp index 645527cf4..be0032301 100644 --- a/lib/VCMIDirs.cpp +++ b/lib/VCMIDirs.cpp @@ -60,6 +60,11 @@ std::string VCMIDirs::libraryPath() const return userDataPath(); } +std::string VCMIDirs::clientPath() const +{ + return userDataPath() + "\\" + "VCMI_client.exe"; +} + std::string VCMIDirs::serverPath() const { return userDataPath() + "\\" + "VCMI_server.exe"; @@ -96,9 +101,14 @@ std::string VCMIDirs::libraryPath() const return "."; } +std::string VCMIDirs::clientPath() const +{ + return userDataPath() + "\\" + "VCMI_client.exe"; +} + std::string VCMIDirs::serverPath() const { - return "./vcmiserver"; + return userDataPath() + "\\" + "VCMI_server.exe"; } std::vector VCMIDirs::dataPaths() const @@ -125,6 +135,11 @@ std::string VCMIDirs::libraryPath() const return M_LIB_DIR; } +std::string VCMIDirs::clientPath() const +{ + return std::string(M_BIN_DIR) + "/" + "vcmiclient"; +} + std::string VCMIDirs::serverPath() const { return std::string(M_BIN_DIR) + "/" + "vcmiserver"; diff --git a/lib/VCMIDirs.h b/lib/VCMIDirs.h index 7fd756a06..1aab57f76 100644 --- a/lib/VCMIDirs.h +++ b/lib/VCMIDirs.h @@ -39,7 +39,10 @@ public: /// Paths to global system-wide data directories. First items have higher priority std::vector dataPaths() const; - /// Full path to vcmiserver executable, including server name (e.g. /usr/bin/vcmiserver) + /// Full path to client executable, including server name (e.g. /usr/bin/vcmiclient) + std::string clientPath() const; + + /// Full path to server executable, including server name (e.g. /usr/bin/vcmiserver) std::string serverPath() const; /// Path where vcmi libraries can be found (in AI and Scripting subdirectories)