Bladeren bron

Added legacy forward launcher & fixed bugs

Ivan Arkhipov 3 jaren geleden
bovenliggende
commit
0af72c65bb

+ 3 - 8
Legacy_v2.pro

@@ -4,16 +4,11 @@
 #
 #-------------------------------------------------
 
-QT       += core gui network
-
- QMAKE_LFLAGS_RELEASE += -static -static-libgcc -static-libstdc++
-
-greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
-
 TARGET = Legacy_v2
 TEMPLATE = subdirs
 
 SUBDIRS += \
-    src/Legacy \ 
+    src/Legacy \
 #    src/Legacy-advanced \
-    src/LegacyLauncher
+    src/LegacyLauncher \
+    src/LegacyForwardHelper

+ 17 - 0
src/Legacy/main.cpp

@@ -12,6 +12,23 @@ int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);
 
+    if (argc <= 1 || (argc > 1 && std::string(argv[1]) != "-prelaunched")) {
+        QMessageBox msgBox;
+        msgBox.setIcon(QMessageBox::Warning);
+
+        #ifdef DEBUG
+            msgBox.setText("ЭТО ТЕСТОВАЯ ВЕРСИЯ ЛАУНЧЕРА! НЕ ДЛЯ РАСПРОСТРАНЕНИЯ!");
+            msgBox.exec();
+            long long cur_time = time(0);
+            if (cur_time >= DEBUG_EXPIRE)
+                return 0;
+        #else
+            msgBox.setText("Запуск Наследия невозможен без лаунчера. Используйте лаунчер Наследия для запуска приложения!");
+            msgBox.exec();
+            return 0;
+        #endif
+    }
+
     QLockFile lockFile(QDir::temp().absoluteFilePath("rulotro.lock"));
     if(!lockFile.tryLock(100)){
         qDebug() << "Lock file already exists! Some other application is already running...";

+ 9 - 6
src/Legacy/widgets/serverstatuswidget.cpp

@@ -89,6 +89,7 @@ void ServerStatusWidget::updateStatus()
         return;
     }
 
+    disabled_servers_count = 0;
     servers_disabled = false;
     QStringList servers = QString(status_data).split("|||");
     foreach (QString server, servers) {
@@ -96,10 +97,12 @@ void ServerStatusWidget::updateStatus()
         QWidget* widget = findChild<QWidget*>(QString(data[0]).toLower());
         if (!widget)
             continue;
-        if (data.size() > 1 && data[1] == "on")
+        if (data.size() > 1 && data[1] == "on") {
             widget->setStyleSheet(open_color);
-        else
+        } else {
             widget->setStyleSheet(closed_color);
+            disabled_servers_count++;
+        }
     }
     status_data = "";
     tech_work_message_downloader.start();
@@ -108,10 +111,10 @@ void ServerStatusWidget::updateStatus()
 void ServerStatusWidget::updateTechWorksMessage()
 {
     if (tech_work_message_data.isEmpty()) {
-        if (!servers_disabled) {
+        if (disabled_servers_count <= 3) {
             server_status_tooltip_ = "Серверы игры работают в штатном режиме.";
         } else {
-            server_status_tooltip_ = "<p style =\"color:#ff0000\">Серверы игры отключены.</p>";
+            server_status_tooltip_ = "Серверы игры частично или полностью отключены.\nСообщений о профилактике не поступало.";
         }
         tech_work_message_data = "";
         return;
@@ -129,9 +132,9 @@ void ServerStatusWidget::updateTechWorksMessage()
     QString month = QString(" " + list[3]).toUpper();
 
     if (!servers_disabled) {
-        server_status_tooltip_ = "<p style=\"color:#ffff7f\">Планируется отключение серверов игры " + day + month + " с " + time_beginning + " до " + time_end+ " (мск).</p>";
+        server_status_tooltip_ = "Планируется отключение серверов игры " + day + month + " с " + time_beginning + " до " + time_end+ " (мск).";
     } else {
-        server_status_tooltip_ = "<p style=\"color:#ff0000\">Серверы игры отключены на профилактику<br>Время проф. работ: " + day + month + " с " + time_beginning + " до " + time_end + " (мск).</p>";
+        server_status_tooltip_ = "Серверы игры отключены на профилактику<br>Время проф. работ: " + day + month + " с " + time_beginning + " до " + time_end + " (мск).";
     }
 
     tech_work_message_data = "";

+ 1 - 0
src/Legacy/widgets/serverstatuswidget.h

@@ -67,6 +67,7 @@ private:
 
     Ui::ServerStatusWidget *ui;
     bool servers_disabled;
+    int disabled_servers_count = 0;
 
 };
 

+ 26 - 0
src/LegacyForwardHelper/LegacyForwardHelper.pro

@@ -0,0 +1,26 @@
+include( ../../common.pri )
+include( ../../app.pri )
+
+QT += core widgets
+QMAKE_LFLAGS += -static -static-libgcc -static-libstdc++
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+        main.cpp
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
+
+win32:RC_ICONS = $${PROJECT_ROOT_PATH}/resources/appicon.ico

+ 13 - 0
src/LegacyForwardHelper/legacyforwardhelper_plugin_import.cpp

@@ -0,0 +1,13 @@
+// This file is autogenerated by qmake. It imports static plugin classes for
+// static plugins specified using QTPLUGIN and QT_PLUGIN_CLASS.<plugin> variables.
+#include <QtPlugin>
+Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin)
+Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
+Q_IMPORT_PLUGIN(QGifPlugin)
+Q_IMPORT_PLUGIN(QICNSPlugin)
+Q_IMPORT_PLUGIN(QICOPlugin)
+Q_IMPORT_PLUGIN(QJpegPlugin)
+Q_IMPORT_PLUGIN(QTgaPlugin)
+Q_IMPORT_PLUGIN(QTiffPlugin)
+Q_IMPORT_PLUGIN(QWbmpPlugin)
+Q_IMPORT_PLUGIN(QWebpPlugin)

+ 111 - 0
src/LegacyForwardHelper/main.cpp

@@ -0,0 +1,111 @@
+#include <QFile>
+#include <QDir>
+#include <QDirIterator>
+#include <QCoreApplication>
+#include <QDebug>
+#include <QThread>
+#include <QProcess>
+#include <QApplication>
+#include <QMessageBox>
+
+void logMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
+{
+    QString message_type;
+
+    switch (type) {
+    case QtDebugMsg:
+        message_type = "[LEGACY_FORWARD_HELPER][DEBG]";
+        break;
+    case QtInfoMsg:
+        message_type = "[LEGACY_FORWARD_HELPER][INFO]";
+        break;
+    case QtWarningMsg:
+        message_type = "[LEGACY_FORWARD_HELPER][WARN]";
+        break;
+    case QtCriticalMsg:
+        message_type = "[LEGACY_FORWARD_HELPER][CRIT]";
+        break;
+    case QtFatalMsg:
+        message_type = "[LEGACY_FORWARD_HELPER][FATL]";
+        break;
+    default:
+        message_type = "[LEGACY_FORWARD_HELPER][UNKN]";
+        break;
+    }
+
+    QString filename = context.category;
+    QString function = context.function;
+    QString line_number = QString::number(context.line);
+
+    QString s = QString("%1: %2 ||| %3:%4 %5\n")
+                .arg(message_type)
+                .arg(msg)
+                .arg(filename)
+                .arg(line_number)
+                .arg(function);
+
+#ifndef QT_DEBUG
+    QFile log_file("legacy_log.txt");
+    QFileInfo log_file_info(log_file);
+    if (log_file_info.size() >= 10 * 1024 * 1024) {
+        QFile::remove("legacy_log.old.txt");
+        QFile::copy("legacy_log.txt", "legacy_log.old.txt");
+        QFile::remove("legacy_log.txt");
+    }
+    log_file.open(QIODevice::ReadWrite | QIODevice::Append);
+    QTextStream stream(&log_file);
+    stream << s;
+    log_file.close();
+#endif
+
+    fprintf(stderr, "%s", qUtf8Printable(s));
+    fflush(stderr);
+}
+
+int main(int argc, char** argv) {
+    if (argc <= 1 || (argc > 1 && std::string(argv[1]) != "-prelaunched")) {
+        QApplication a(argc, argv);
+        QMessageBox msgBox;
+        msgBox.setIcon(QMessageBox::Warning);
+
+        #ifdef DEBUG
+            msgBox.setText("ЭТО ТЕСТОВАЯ ВЕРСИЯ ЛАУНЧЕРА! НЕ ДЛЯ РАСПРОСТРАНЕНИЯ!");
+            msgBox.exec();
+            long long cur_time = time(0);
+            if (cur_time >= DEBUG_EXPIRE)
+                return 0;
+        #else
+            msgBox.setText("Запуск Наследия невозможен без лаунчера. Используйте лаунчер Наследия для запуска приложения!");
+            msgBox.exec();
+            a.exit(0);
+            return 0;
+        #endif
+    }
+
+    QCoreApplication a(argc, argv);
+    qInstallMessageHandler(logMessageHandler);
+    QThread::currentThread()->sleep(1); // Sleep 2 seconds to ensure that application-caller finished its work
+    const QString app_path = QCoreApplication::applicationDirPath();
+    const QDir::Filters filters = (QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
+    QDirIterator it(app_path, filters, QDirIterator::Subdirectories);
+
+    while (it.hasNext()) {
+        QString path = it.next();
+
+        if (QFileInfo(path).isFile() && path.endsWith(".forward")) {
+            QString path_stripped = path.left(path.length() - QString(".forward").length());
+            QFile::remove(path_stripped);
+            if (QFile::copy(path, path_stripped)) {
+                QFile::remove(path);
+            }
+            qInfo() << "Renaming file " << path << " to file " << path_stripped;
+        }
+    }
+
+    QProcess process;
+    process.setProgram("./Legacy.exe");
+    process.setArguments({"-prelaunched"});
+    process.startDetached();
+    process.waitForFinished(-1);
+    return 0;
+}

+ 1 - 1
src/LegacyLauncher/LegacyLauncher.pro

@@ -34,7 +34,7 @@ qnx: target.path = /tmp/$${TARGET}/bin
 else: unix:!android: target.path = /opt/$${TARGET}/bin
 !isEmpty(target.path): INSTALLS += target
 
-win32:RC_ICONS = $${PROJECT_ROOT_PATH}/resources/icon.ico
+win32:RC_ICONS = $${PROJECT_ROOT_PATH}/resources/appicon.ico
 
 RESOURCES += \
     ../../resources/prelauncher_resources.qrc

+ 11 - 2
src/LegacyLauncher/launcher.cpp

@@ -97,6 +97,11 @@ void GIFAnimationDemoWidget::downloadNextEnqueuedFile()
     data_downloader->setUrl(QUrl(base_url + file_path));
     data_downloader->targetFile = new QFile(target_file_path);
     data_downloader->targetFile->open(QIODevice::WriteOnly);
+    if (!data_downloader->targetFile->isOpen() || !data_downloader->targetFile->isWritable()) {
+        QFile::remove(target_file_path + ".forward");
+        data_downloader->targetFile->setFileName(target_file_path + ".forward");
+        data_downloader->targetFile->open(QIODevice::WriteOnly);
+    }
     data_downloader->disconnect();
     connect(data_downloader, &Downloader::progressChanged, this, &GIFAnimationDemoWidget::onDownloadProgressChanged);
     connect(data_downloader, &Downloader::downloadFinished, this, &GIFAnimationDemoWidget::onDownloadNextEnqueuedFileFinished);
@@ -106,8 +111,12 @@ void GIFAnimationDemoWidget::downloadNextEnqueuedFile()
 void GIFAnimationDemoWidget::startApplication()
 {
     QProcess process;
-    process.setProgram(target_folder + "Legacy.exe");
-    process.setArguments({"launcherpath=" + QString(QApplication::applicationFilePath().toUtf8().toBase64())});
+    if (FileSystem::fileExists(target_folder + "LegacyForwardHelper.exe")) {
+        process.setProgram(target_folder + "LegacyForwardHelper.exe");
+    } else {
+        process.setProgram(target_folder + "Legacy.exe");
+    }
+    process.setArguments({"-prelaunched"});
     process.startDetached();
     process.waitForFinished(-1);
     QMetaObject::invokeMethod(this, &GIFAnimationDemoWidget::close, Qt::QueuedConnection);

+ 1 - 1
src/LegacyLauncher/launcher.h

@@ -39,7 +39,7 @@ private slots:
 
 private:
     const QString base_url = "http://translate.lotros.ru/upload/launcher_v2/";
-    const QString target_folder = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/";
+    const QString target_folder = "./";
 
     Downloader* data_downloader;
     QByteArray downloaded_data;