mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Mod from GitHub (#785)
* Make new dialog for checking updates * update on startup * Implemented auto-update
This commit is contained in:
parent
23bbb69eb9
commit
5862c192b0
@ -363,12 +363,12 @@
|
||||
"type" : "object",
|
||||
"default": {},
|
||||
"additionalProperties" : false,
|
||||
"required" : [ "repositoryURL", "enableInstalledMods", "autoCheckRepositories" ],
|
||||
"required" : [ "repositoryURL", "enableInstalledMods", "autoCheckRepositories", "updateOnStartup", "updateConfigUrl" ],
|
||||
"properties" : {
|
||||
"repositoryURL" : {
|
||||
"type" : "array",
|
||||
"default" : [
|
||||
"http://download.vcmi.eu/mods/repository/repository.json"
|
||||
"https://raw.githubusercontent.com/vcmi/vcmi-mods-repository/develop/github.json"
|
||||
],
|
||||
"items" : {
|
||||
"type" : "string"
|
||||
@ -381,6 +381,14 @@
|
||||
"autoCheckRepositories" : {
|
||||
"type" : "boolean",
|
||||
"default" : true
|
||||
},
|
||||
"updateOnStartup" : {
|
||||
"type" : "boolean",
|
||||
"default" : true
|
||||
},
|
||||
"updateConfigUrl" : {
|
||||
"type" : "string",
|
||||
"default" : "https://raw.githubusercontent.com/vcmi/vcmi-updates/master/vcmi-updates.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ set(launcher_SRCS
|
||||
mainwindow_moc.cpp
|
||||
launcherdirs.cpp
|
||||
jsonutils.cpp
|
||||
updatedialog_moc.cpp
|
||||
)
|
||||
|
||||
set(launcher_HEADERS
|
||||
@ -41,6 +42,7 @@ set(launcher_HEADERS
|
||||
mainwindow_moc.h
|
||||
launcherdirs.h
|
||||
jsonutils.h
|
||||
updatedialog_moc.h
|
||||
)
|
||||
|
||||
set(launcher_FORMS
|
||||
@ -48,6 +50,7 @@ set(launcher_FORMS
|
||||
modManager/imageviewer_moc.ui
|
||||
settingsView/csettingsview_moc.ui
|
||||
mainwindow_moc.ui
|
||||
updatedialog_moc.ui
|
||||
)
|
||||
|
||||
assign_source_group(${launcher_SRCS} ${launcher_HEADERS} VCMI_launcher.rc)
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "../lib/filesystem/Filesystem.h"
|
||||
#include "../lib/logging/CBasicLogConfigurator.h"
|
||||
|
||||
#include "updatedialog_moc.h"
|
||||
|
||||
void MainWindow::load()
|
||||
{
|
||||
// Set current working dir to executable folder.
|
||||
@ -80,6 +82,9 @@ MainWindow::MainWindow(QWidget * parent)
|
||||
|
||||
connect(ui->tabSelectList, SIGNAL(currentRowChanged(int)),
|
||||
ui->tabListWidget, SLOT(setCurrentIndex(int)));
|
||||
|
||||
if(settings["launcher"]["updateOnStartup"].Bool())
|
||||
UpdateDialog::showUpdateDialog(false);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -20,6 +20,7 @@ CDownloadManager::CDownloadManager()
|
||||
|
||||
void CDownloadManager::downloadFile(const QUrl & url, const QString & file)
|
||||
{
|
||||
filename = file;
|
||||
QNetworkRequest request(url);
|
||||
FileEntry entry;
|
||||
entry.file.reset(new QFile(CLauncherDirs::get().downloadsPath() + '/' + file));
|
||||
@ -61,6 +62,23 @@ CDownloadManager::FileEntry & CDownloadManager::getEntry(QNetworkReply * reply)
|
||||
void CDownloadManager::downloadFinished(QNetworkReply * reply)
|
||||
{
|
||||
FileEntry & file = getEntry(reply);
|
||||
|
||||
QVariant possibleRedirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
|
||||
QUrl qurl = possibleRedirectUrl.toUrl();
|
||||
|
||||
if(possibleRedirectUrl.isValid())
|
||||
{
|
||||
for(int i = 0; i< currentDownloads.size(); ++i)
|
||||
{
|
||||
if(currentDownloads[i].file == file.file)
|
||||
{
|
||||
currentDownloads.removeAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
downloadFile(qurl, filename);
|
||||
return;
|
||||
}
|
||||
|
||||
if(file.reply->error())
|
||||
{
|
||||
|
@ -35,6 +35,8 @@ class CDownloadManager : public QObject
|
||||
};
|
||||
|
||||
QStringList encounteredErrors;
|
||||
|
||||
QString filename;
|
||||
|
||||
QNetworkAccessManager manager;
|
||||
|
||||
|
@ -24,21 +24,21 @@ static QString detectModArchive(QString path, QString modName)
|
||||
|
||||
QString modDirName;
|
||||
|
||||
for(auto file : files)
|
||||
for(int folderLevel : {0, 1}) //search in subfolder if there is no mod.json in the root
|
||||
{
|
||||
QString filename = QString::fromUtf8(file.c_str());
|
||||
if(filename.toLower().startsWith(modName))
|
||||
for(auto file : files)
|
||||
{
|
||||
// archive must contain mod.json file
|
||||
if(filename.toLower() == modName + "/mod.json")
|
||||
modDirName = filename.section('/', 0, 0);
|
||||
}
|
||||
else // all files must be in <modname> directory
|
||||
{
|
||||
return "";
|
||||
QString filename = QString::fromUtf8(file.c_str());
|
||||
modDirName = filename.section('/', 0, folderLevel);
|
||||
|
||||
if(filename == modDirName + "/mod.json")
|
||||
{
|
||||
return modDirName;
|
||||
}
|
||||
}
|
||||
}
|
||||
return modDirName;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
CModManager::CModManager(CModList * modList)
|
||||
@ -259,7 +259,18 @@ bool CModManager::doInstallMod(QString modname, QString archivePath)
|
||||
return addError(modname, "Failed to extract mod data");
|
||||
}
|
||||
|
||||
QVariantMap json = JsonUtils::JsonFromFile(destDir + modDirName + "/mod.json").toMap();
|
||||
//rename folder and fix the path
|
||||
QDir extractedDir(destDir + modDirName);
|
||||
auto rc = QFile::rename(destDir + modDirName, destDir + modname);
|
||||
if (rc)
|
||||
extractedDir.setPath(destDir + modname);
|
||||
|
||||
//there are possible excessive files - remove them
|
||||
QString upperLevel = modDirName.section('/', 0, 0);
|
||||
if(upperLevel != modDirName)
|
||||
removeModDir(destDir + upperLevel);
|
||||
|
||||
QVariantMap json = JsonUtils::JsonFromFile(destDir + modname + "/mod.json").toMap();
|
||||
|
||||
localMods.insert(modname, json);
|
||||
modList->setLocalModList(localMods);
|
||||
@ -280,8 +291,9 @@ bool CModManager::doUninstallMod(QString modname)
|
||||
if(!localMods.contains(modname))
|
||||
return addError(modname, "Data with this mod was not found");
|
||||
|
||||
QDir modFullDir(modDir);
|
||||
if(!removeModDir(modDir))
|
||||
return addError(modname, "Failed to delete mod data");
|
||||
return addError(modname, "Mod is located in protected directory, plase remove it manually:\n" + modFullDir.absolutePath());
|
||||
|
||||
localMods.remove(modname);
|
||||
modList->setLocalModList(localMods);
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include "csettingsview_moc.h"
|
||||
#include "ui_csettingsview_moc.h"
|
||||
|
||||
#include "../updatedialog_moc.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QGuiApplication>
|
||||
|
||||
@ -232,3 +234,9 @@ void CSettingsView::on_comboBoxAutoSave_currentIndexChanged(int index)
|
||||
Settings node = settings.write["general"]["saveFrequency"];
|
||||
node->Integer() = index;
|
||||
}
|
||||
|
||||
void CSettingsView::on_updatesButton_clicked()
|
||||
{
|
||||
UpdateDialog::showUpdateDialog(true);
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,8 @@ private slots:
|
||||
|
||||
void on_comboBoxAutoSave_currentIndexChanged(int index);
|
||||
|
||||
void on_updatesButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::CSettingsView * ui;
|
||||
};
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>738</width>
|
||||
<height>471</height>
|
||||
<width>779</width>
|
||||
<height>619</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -26,40 +26,15 @@
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="3" column="6">
|
||||
<widget class="QLabel" name="labelTempDir">
|
||||
<property name="text">
|
||||
<string>Log files directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="17" column="6">
|
||||
<widget class="QComboBox" name="comboBoxAutoCheck">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Off</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>On</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="6" colspan="4">
|
||||
<widget class="QLabel" name="labelDataDirs">
|
||||
<item row="8" column="1" colspan="4">
|
||||
<widget class="QLabel" name="labelAIMovingOnTheMap">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Data Directories</string>
|
||||
<string>AI on the map</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -67,7 +42,6 @@
|
||||
<widget class="QLabel" name="labelVideo">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
@ -76,68 +50,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="labelResolution">
|
||||
<property name="text">
|
||||
<string>Resolution</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="9">
|
||||
<widget class="QPushButton" name="openTempDir">
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="4">
|
||||
<widget class="QComboBox" name="comboBoxNeutralAI">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>BattleAI</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>StupidAI</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="6">
|
||||
<widget class="QLabel" name="labelUserDataDir">
|
||||
<property name="text">
|
||||
<string>User data directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="14" column="1">
|
||||
<widget class="QLabel" name="labelEnemyAI">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Enemy AI</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="17" column="1" colspan="4">
|
||||
<widget class="QLabel" name="labelAutoCheck">
|
||||
<property name="text">
|
||||
<string>Check repositories on startup</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="labelDisplayIndex">
|
||||
<property name="text">
|
||||
<string>Display index</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="labelShowIntro">
|
||||
<property name="text">
|
||||
@ -145,91 +57,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="6" colspan="4">
|
||||
<widget class="QLabel" name="labelGeneral">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>General</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="4">
|
||||
<widget class="QComboBox" name="comboBoxDisplayIndex">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="8">
|
||||
<widget class="QPushButton" name="changeGameDataDir">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Change</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="4">
|
||||
<widget class="QComboBox" name="comboBoxPlayerAI">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>VCAI</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Nullkiller</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="7" colspan="2">
|
||||
<widget class="QLineEdit" name="lineEditTempDir">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>/home/user/.vcmi</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="18" column="1" colspan="4">
|
||||
<widget class="QLabel" name="labelRepositories">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Repositories</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="9">
|
||||
<widget class="QPushButton" name="openGameDataDir">
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="7" colspan="3">
|
||||
<widget class="QSpinBox" name="spinBoxNetworkPort">
|
||||
<property name="minimum">
|
||||
@ -243,86 +70,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="20" column="1" colspan="9">
|
||||
<widget class="QPlainTextEdit" name="plainTextEditRepos">
|
||||
<property name="lineWrapMode">
|
||||
<enum>QPlainTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="plainText">
|
||||
<string>http://downloads.vcmi.eu/Mods/repository.json</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="9">
|
||||
<widget class="QPushButton" name="openUserDataDir">
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="13" column="1">
|
||||
<widget class="QLabel" name="labelFriendlyAI">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Friendly AI</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<widget class="QLabel" name="labelPlayerAI">
|
||||
<property name="text">
|
||||
<string>Player AI</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="14" column="4">
|
||||
<widget class="QComboBox" name="comboBoxEnemyAI">
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="currentText">
|
||||
<string>BattleAI</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>BattleAI</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>StupidAI</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="labelFullScreen">
|
||||
<property name="text">
|
||||
<string>Fullscreen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1" colspan="4">
|
||||
<spacer name="spacerSections">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>56</width>
|
||||
<height>8</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="7">
|
||||
<widget class="QLineEdit" name="lineEditGameDir">
|
||||
<property name="minimumSize">
|
||||
@ -336,10 +83,31 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="6">
|
||||
<widget class="QLabel" name="labelGameDir">
|
||||
<item row="10" column="6">
|
||||
<widget class="QLabel" name="labelEncoding">
|
||||
<property name="text">
|
||||
<string>Extra data directory</string>
|
||||
<string>Heroes III character set</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QCheckBox" name="checkBoxFullScreen">
|
||||
<property name="text">
|
||||
<string>Real fullscreen mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="labelResolution">
|
||||
<property name="text">
|
||||
<string>Resolution</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="labelFullScreen">
|
||||
<property name="text">
|
||||
<string>Fullscreen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -379,16 +147,72 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1" colspan="4">
|
||||
<widget class="QLabel" name="labelAIMovingOnTheMap">
|
||||
<item row="8" column="6" colspan="4">
|
||||
<widget class="QLabel" name="labelGeneral">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>AI on the map</string>
|
||||
<string>General</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="20" column="1" colspan="9">
|
||||
<widget class="QPlainTextEdit" name="plainTextEditRepos">
|
||||
<property name="lineWrapMode">
|
||||
<enum>QPlainTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="plainText">
|
||||
<string>http://downloads.vcmi.eu/Mods/repository.json</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="9">
|
||||
<widget class="QPushButton" name="openGameDataDir">
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<widget class="QLabel" name="labelPlayerAI">
|
||||
<property name="text">
|
||||
<string>Player AI</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="18" column="1" colspan="4">
|
||||
<widget class="QLabel" name="labelRepositories">
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Repositories</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="4">
|
||||
<widget class="QComboBox" name="comboBoxPlayerAI">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>VCAI</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Nullkiller</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="labelDisplayIndex">
|
||||
<property name="text">
|
||||
<string>Display index</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -409,11 +233,67 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="4">
|
||||
<widget class="QComboBox" name="comboBoxNeutralAI">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>BattleAI</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>StupidAI</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="13" column="4">
|
||||
<widget class="QComboBox" name="comboBoxFriendlyAI">
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="currentText">
|
||||
<string>BattleAI</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>BattleAI</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>StupidAI</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="5">
|
||||
<spacer name="spacerColumns">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>8</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="9">
|
||||
<widget class="QPushButton" name="openTempDir">
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="16" column="1" colspan="4">
|
||||
<widget class="QLabel" name="LauncherSettings">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
@ -422,10 +302,33 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="6">
|
||||
<widget class="QLabel" name="labelNetworkPort">
|
||||
<item row="1" column="6">
|
||||
<widget class="QLabel" name="labelGameDir">
|
||||
<property name="text">
|
||||
<string>Network port</string>
|
||||
<string>Extra data directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="14" column="1">
|
||||
<widget class="QLabel" name="labelEnemyAI">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Enemy AI</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="8">
|
||||
<widget class="QPushButton" name="changeGameDataDir">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Change</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -449,7 +352,7 @@
|
||||
<string>1024x768</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>1181x664</string>
|
||||
</property>
|
||||
@ -506,8 +409,24 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="15" column="1" colspan="4">
|
||||
<spacer name="spacerRepos">
|
||||
<item row="11" column="1">
|
||||
<widget class="QLabel" name="labelNeutralAI">
|
||||
<property name="text">
|
||||
<string>Neutral AI</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="4">
|
||||
<widget class="QComboBox" name="comboBoxDisplayIndex">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1" colspan="4">
|
||||
<spacer name="spacerSections">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
@ -516,14 +435,67 @@
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<width>56</width>
|
||||
<height>8</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="13" column="4">
|
||||
<widget class="QComboBox" name="comboBoxFriendlyAI">
|
||||
<item row="3" column="7" colspan="2">
|
||||
<widget class="QLineEdit" name="lineEditTempDir">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>/home/user/.vcmi</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="17" column="6">
|
||||
<widget class="QComboBox" name="comboBoxAutoCheck">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Off</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>On</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="7">
|
||||
<widget class="QComboBox" name="comboBoxAutoSave">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Off</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>On</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="14" column="4">
|
||||
<widget class="QComboBox" name="comboBoxEnemyAI">
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
@ -542,6 +514,96 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="15" column="1" colspan="4">
|
||||
<spacer name="spacerRepos">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>8</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="10" column="1">
|
||||
<widget class="QLabel" name="labelAIInTheBattlefield">
|
||||
<property name="font">
|
||||
<font>
|
||||
<italic>true</italic>
|
||||
<bold>true</bold>
|
||||
<underline>false</underline>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>AI in the battlefield</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="17" column="1" colspan="4">
|
||||
<widget class="QLabel" name="labelAutoCheck">
|
||||
<property name="text">
|
||||
<string>Check repositories on startup</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="13" column="1">
|
||||
<widget class="QLabel" name="labelFriendlyAI">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Friendly AI</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="6">
|
||||
<widget class="QLabel" name="labelTempDir">
|
||||
<property name="text">
|
||||
<string>Log files directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="6" colspan="4">
|
||||
<widget class="QLabel" name="labelDataDirs">
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Data Directories</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="6">
|
||||
<widget class="QLabel" name="labelUserDataDir">
|
||||
<property name="text">
|
||||
<string>User data directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="9">
|
||||
<widget class="QPushButton" name="openUserDataDir">
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="6">
|
||||
<widget class="QLabel" name="labelNetworkPort">
|
||||
<property name="text">
|
||||
<string>Network port</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="7" colspan="3">
|
||||
<widget class="QComboBox" name="comboBoxEncoding">
|
||||
<item>
|
||||
@ -576,58 +638,6 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="1">
|
||||
<widget class="QLabel" name="labelAIInTheBattlefield">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<italic>true</italic>
|
||||
<bold>true</bold>
|
||||
<underline>false</underline>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>AI in the battlefield</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="5">
|
||||
<spacer name="spacerColumns">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>8</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="10" column="6">
|
||||
<widget class="QLabel" name="labelEncoding">
|
||||
<property name="text">
|
||||
<string>Heroes III character set</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="1">
|
||||
<widget class="QLabel" name="labelNeutralAI">
|
||||
<property name="text">
|
||||
<string>Neutral AI</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QCheckBox" name="checkBoxFullScreen">
|
||||
<property name="text">
|
||||
<string>Real fullscreen mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="6">
|
||||
<widget class="QLabel" name="labelAutoSave">
|
||||
<property name="text">
|
||||
@ -635,21 +645,11 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="7">
|
||||
<widget class="QComboBox" name="comboBoxAutoSave">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<item row="17" column="7">
|
||||
<widget class="QPushButton" name="updatesButton">
|
||||
<property name="text">
|
||||
<string>Check for updates</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Off</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>On</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
147
launcher/updatedialog_moc.cpp
Normal file
147
launcher/updatedialog_moc.cpp
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* updatedialog_moc.cpp, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
* License: GNU General Public License v2.0 or later
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
#include "StdInc.h"
|
||||
#include "updatedialog_moc.h"
|
||||
#include "ui_updatedialog_moc.h"
|
||||
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "../lib/GameConstants.h"
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
UpdateDialog::UpdateDialog(bool calledManually, QWidget *parent):
|
||||
QDialog(parent),
|
||||
ui(new Ui::UpdateDialog),
|
||||
calledManually(calledManually)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
if(calledManually)
|
||||
{
|
||||
setWindowModality(Qt::ApplicationModal);
|
||||
show();
|
||||
}
|
||||
|
||||
connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close()));
|
||||
|
||||
if(settings["launcher"]["updateOnStartup"].Bool())
|
||||
ui->checkOnStartup->setCheckState(Qt::CheckState::Checked);
|
||||
|
||||
currentVersion = GameConstants::VCMI_VERSION;
|
||||
|
||||
setWindowTitle(QString::fromStdString(currentVersion));
|
||||
|
||||
#ifdef VCMI_WINDOWS
|
||||
platformParameter = "windows";
|
||||
#elif defined(VCMI_MAC)
|
||||
platformParameter = "macos";
|
||||
#elif defined(VCMI_IOS)
|
||||
platformParameter = "ios";
|
||||
#elif defined(VCMI_ANDROID)
|
||||
platformParameter = "android";
|
||||
#elif defined(VCMI_UNIX)
|
||||
platformParameter = "linux";
|
||||
#endif
|
||||
|
||||
QString url = QString::fromStdString(settings["launcher"]["updateConfigUrl"].String());
|
||||
|
||||
QNetworkReply *response = networkManager.get(QNetworkRequest(QUrl(url)));
|
||||
|
||||
connect(response, &QNetworkReply::finished, [&, response]{
|
||||
response->deleteLater();
|
||||
|
||||
if(response->error() != QNetworkReply::NoError)
|
||||
{
|
||||
ui->versionLabel->setStyleSheet("QLabel { background-color : red; color : black; }");
|
||||
ui->versionLabel->setText("Network error");
|
||||
ui->plainTextEdit->setPlainText(response->errorString());
|
||||
return;
|
||||
}
|
||||
|
||||
auto byteArray = response->readAll();
|
||||
JsonNode node(byteArray.constData(), byteArray.size());
|
||||
loadFromJson(node);
|
||||
});
|
||||
}
|
||||
|
||||
UpdateDialog::~UpdateDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void UpdateDialog::showUpdateDialog(bool isManually)
|
||||
{
|
||||
UpdateDialog * dialog = new UpdateDialog(isManually);
|
||||
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
}
|
||||
|
||||
void UpdateDialog::on_checkOnStartup_stateChanged(int state)
|
||||
{
|
||||
Settings node = settings.write["launcher"]["updateOnStartup"];
|
||||
node->Bool() = ui->checkOnStartup->isChecked();
|
||||
}
|
||||
|
||||
void UpdateDialog::loadFromJson(const JsonNode & node)
|
||||
{
|
||||
if(node.getType() != JsonNode::JsonType::DATA_STRUCT ||
|
||||
node["updateType"].getType() != JsonNode::JsonType::DATA_STRING ||
|
||||
node["version"].getType() != JsonNode::JsonType::DATA_STRING ||
|
||||
node["changeLog"].getType() != JsonNode::JsonType::DATA_STRING ||
|
||||
node.getType() != JsonNode::JsonType::DATA_STRUCT) //we need at least one link - other are optional
|
||||
{
|
||||
ui->plainTextEdit->setPlainText("Cannot read JSON from url or incorrect JSON data");
|
||||
return;
|
||||
}
|
||||
|
||||
//check whether update is needed
|
||||
bool isFutureVersion = true;
|
||||
std::string newVersion = node["version"].String();
|
||||
for(auto & prevVersion : node["history"].Vector())
|
||||
{
|
||||
if(prevVersion.String() == currentVersion)
|
||||
isFutureVersion = false;
|
||||
}
|
||||
|
||||
if(isFutureVersion || currentVersion == newVersion)
|
||||
{
|
||||
if(!calledManually)
|
||||
close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!calledManually)
|
||||
{
|
||||
setWindowModality(Qt::ApplicationModal);
|
||||
show();
|
||||
}
|
||||
|
||||
const auto updateType = node["updateType"].String();
|
||||
|
||||
QString bgColor;
|
||||
if(updateType == "minor")
|
||||
bgColor = "gray";
|
||||
else if(updateType == "major")
|
||||
bgColor = "orange";
|
||||
else if(updateType == "critical")
|
||||
bgColor = "red";
|
||||
|
||||
ui->versionLabel->setStyleSheet(QString("QLabel { background-color : %1; color : black; }").arg(bgColor));
|
||||
ui->versionLabel->setText(QString::fromStdString(newVersion));
|
||||
ui->plainTextEdit->setPlainText(QString::fromStdString(node["changeLog"].String()));
|
||||
|
||||
QString downloadLink = QString::fromStdString(node["downloadLinks"]["other"].String());
|
||||
if(node["downloadLinks"][platformParameter].getType() == JsonNode::JsonType::DATA_STRING)
|
||||
downloadLink = QString::fromStdString(node["downloadLinks"][platformParameter].String());
|
||||
|
||||
ui->downloadLink->setText(QString{"<a href=\"%1\">Download page</a>"}.arg(downloadLink));
|
||||
}
|
44
launcher/updatedialog_moc.h
Normal file
44
launcher/updatedialog_moc.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* updatedialog_moc.h, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
* License: GNU General Public License v2.0 or later
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include <QDialog>
|
||||
#include <QNetworkAccessManager>
|
||||
|
||||
class JsonNode;
|
||||
|
||||
namespace Ui {
|
||||
class UpdateDialog;
|
||||
}
|
||||
|
||||
class UpdateDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UpdateDialog(bool calledManually, QWidget *parent = nullptr);
|
||||
~UpdateDialog();
|
||||
|
||||
static void showUpdateDialog(bool isManually);
|
||||
|
||||
private slots:
|
||||
void on_checkOnStartup_stateChanged(int state);
|
||||
|
||||
private:
|
||||
Ui::UpdateDialog *ui;
|
||||
|
||||
std::string currentVersion;
|
||||
std::string platformParameter = "other";
|
||||
|
||||
QNetworkAccessManager networkManager;
|
||||
|
||||
bool calledManually;
|
||||
|
||||
void loadFromJson(const JsonNode & node);
|
||||
};
|
128
launcher/updatedialog_moc.ui
Normal file
128
launcher/updatedialog_moc.ui
Normal file
@ -0,0 +1,128 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>UpdateDialog</class>
|
||||
<widget class="QDialog" name="UpdateDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>371</width>
|
||||
<height>247</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>371</width>
|
||||
<height>247</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>12</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>12</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>12</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>12</number>
|
||||
</property>
|
||||
<item row="0" column="0" colspan="5">
|
||||
<widget class="QLabel" name="versionLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>48</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>18</pointsize>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QLabel {background-color: green; color : black} </string>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>You have latest version</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="5">
|
||||
<widget class="QPlainTextEdit" name="plainTextEdit">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="plainText">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3" colspan="2">
|
||||
<widget class="QPushButton" name="closeButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="checkOnStartup">
|
||||
<property name="text">
|
||||
<string>Check updates on startup</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="downloadLink">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::TextBrowserInteraction</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user