Browse Source

Initial commit

Ivan Arkhipov 6 years ago
commit
61cf8b2434
11 changed files with 443 additions and 0 deletions
  1. 30 0
      .gitignore
  2. 36 0
      LegacyLauncher.pro
  3. 37 0
      LegacyLauncher_resource.rc
  4. 130 0
      launcher.cpp
  5. 58 0
      launcher.h
  6. 87 0
      launcher.ui
  7. 22 0
      main.cpp
  8. 37 0
      resources.rc
  9. BIN
      resources/appicon.ico
  10. 6 0
      resources/resources.qrc
  11. BIN
      resources/second.gif

+ 30 - 0
.gitignore

@@ -0,0 +1,30 @@
+# cmake build directory
+cmake-build-debug 
+# ide project directory
+.idea
+
+# Compiled Object files
+*.slo
+*.lo
+*.o
+
+# Compiled Dynamic libraries
+*.so
+*.dylib
+
+# Build and stuff dirs
+build*/*
+debug/*
+release/*
+stuff/*
+debug_build/*
+release_build/*
+bin/*
+install/*
+
+ui_*
+qzip*
+.qmake*
+qmake*
+*.user*
+Makefile*

+ 36 - 0
LegacyLauncher.pro

@@ -0,0 +1,36 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2016-08-08T08:08:19
+#
+#-------------------------------------------------
+
+QT       += core gui
+QT       += core network
+QT       += concurrent widgets
+QT       += multimedia
+QT       += multimediawidgets
+
+INCLUDEPATH += $$[QT_INSTALL_PREFIX]/src/3rdparty/zlib
+CONFIG += resources_big
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = LegacyLauncher
+TEMPLATE = app
+
+
+SOURCES += main.cpp \
+    launcher.cpp
+
+HEADERS  += \
+    launcher.h
+
+FORMS    += \
+    launcher.ui
+
+RESOURCES += \
+    resources/resources.qrc
+
+RC_FILE    = resources.rc
+
+DISTFILES += \
+    resources.rc

+ 37 - 0
LegacyLauncher_resource.rc

@@ -0,0 +1,37 @@
+#include <windows.h>
+
+IDI_ICON1	ICON	DISCARDABLE	"D:\\Programming\\SourceRepos\\LegacyLauncher\\resources\\appicon.ico"
+
+VS_VERSION_INFO VERSIONINFO
+	FILEVERSION 0,0,0,0
+	PRODUCTVERSION 0,0,0,0
+	FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+	FILEFLAGS VS_FF_DEBUG
+#else
+	FILEFLAGS 0x0L
+#endif
+	FILEOS VOS__WINDOWS32
+	FILETYPE VFT_DLL
+	FILESUBTYPE 0x0L
+	BEGIN
+		BLOCK "StringFileInfo"
+		BEGIN
+			BLOCK "040904b0"
+			BEGIN
+				VALUE "CompanyName", "\0"
+				VALUE "FileDescription", "\0"
+				VALUE "FileVersion", "0.0.0.0\0"
+				VALUE "LegalCopyright", "\0"
+				VALUE "OriginalFilename", "LegacyLauncher.exe\0"
+				VALUE "ProductName", "LegacyLauncher\0"
+				VALUE "ProductVersion", "0.0.0.0\0"
+			END
+		END
+		BLOCK "VarFileInfo"
+		BEGIN
+			VALUE "Translation", 0x0409, 1200
+		END
+	END
+/* End of Version info */
+

+ 130 - 0
launcher.cpp

@@ -0,0 +1,130 @@
+#include "launcher.h"
+#include "ui_launcher.h"
+
+GIFAnimationDemoWidget::GIFAnimationDemoWidget( QWidget* parent ) :
+    QWidget( parent, Qt::Window | Qt::FramelessWindowHint  ), ui( new Ui::GIFAnimationDemoWidget ) {
+
+    ui->setupUi(this);
+    setWindowTitle("ВКО: Наследие - система обновлений");
+    ui->lbHint->setText("Получение списка файлов...");
+    movie = new QMovie(":/second.gif");
+    ui->lbMovie->setMovie(movie);
+    movie->setScaledSize(QSize(ui->lbMovie->width(), ui->lbMovie->height()));
+    movie->start();
+
+    QString response = getFilelist("http://translate.lotros.ru/upload/launcher/filelist.txt");
+
+    QFuture<void> future = QtConcurrent::run([=]() {
+        start(response);
+    });
+}
+
+GIFAnimationDemoWidget::~GIFAnimationDemoWidget() {
+    delete ui;
+}
+
+void GIFAnimationDemoWidget::start(QString filelist) {
+    ui->lbHint->setText("Проверка и скачивание файлов...");
+
+    QStringList templist = filelist.split("\r\n");
+
+    foreach(const QString &str, templist){
+        QString path = str;
+        QStringList list = path.replace("release/", "").split("|");
+
+        path = list[0];
+        if (path.size() == 0)
+            continue;
+
+        qDebug() << path;
+
+        if (fileExists(path)) {
+            QString hash = fileHash(list[0], QCryptographicHash::Md5); // Hashes match - file is ok. Passing it;
+            qDebug() << path << " " << hash << " " << list[1];
+            if (hash == list[1])
+                continue;
+        }
+
+        QFileInfo fileInfo(path);
+        QString folder = fileInfo.dir().path();
+        if (folder == ".") folder = "";
+        makeFolder(folder);
+        ui->lbHint->setText("Загрузка " + path);
+        downloadFile ("http://translate.lotros.ru/upload/launcher/release/" + path, QApplication::applicationDirPath() + "/" + folder);
+    }
+
+    ui->lbHint->setText("Подготовка к запуску ...");
+    QProcess process;
+    process.startDetached("Legacy.exe -prelaunched");
+    process.waitForFinished(-1);
+    exit(0);
+}
+
+QString GIFAnimationDemoWidget::fileHash(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm) {
+    QFile file(fileName);
+    if (file.open(QIODevice::ReadOnly)) {
+        QByteArray fileData = file.readAll();
+        QByteArray hashData = QCryptographicHash::hash(fileData, hashAlgorithm);
+        return hashData.toHex();
+    }
+    return QByteArray();
+}
+
+bool GIFAnimationDemoWidget::fileExists(QString path) {
+    QFileInfo check_file(path);
+    return check_file.exists() && check_file.isFile();
+}
+
+void GIFAnimationDemoWidget::makeFolder(QString path) {
+    QString folder = QApplication::applicationDirPath();
+    QStringList p = path.split("/");
+
+    foreach(const QString &str, p){
+        folder = folder + "/" + str;
+        if (!(QDir(folder).exists() == true) ){
+            QDir().mkdir(folder);
+            qDebug() << "Создана папка " + folder;
+        }
+    }
+}
+
+void GIFAnimationDemoWidget::startNewAnimation() {
+    delete movie;
+    movie = new QMovie(":/second.gif");
+    ui->lbMovie->setMovie(movie);
+    movie->setScaledSize(QSize(ui->lbMovie->width(), ui->lbMovie->height()));
+    movie->start();
+}
+
+QString GIFAnimationDemoWidget::getFilelist(const QString &url) {
+    QNetworkAccessManager manager;
+    QNetworkReply* reply = manager.get(QNetworkRequest(url));
+    QEventLoop loop;
+    QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
+    loop.exec();
+    QString content;
+    if (reply->error() != QNetworkReply::NoError){
+        content = "error";
+        // пишем в лог
+        qDebug() << reply->errorString();
+    }
+    reply->deleteLater();
+    content = reply->readAll();
+    return content;
+}
+
+
+
+void GIFAnimationDemoWidget::downloadFile(const QString &url, const QString &aPathInClient) {
+    QNetworkAccessManager m_NetworkMngr;
+    QNetworkReply *reply= m_NetworkMngr.get(QNetworkRequest(url));
+    QEventLoop loop;
+    QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
+    loop.exec();
+    QUrl aUrl(url);
+    QFileInfo fileInfo=aUrl.path();
+    QFile file(aPathInClient+ "/" + fileInfo.fileName());
+    file.remove();
+    file.open(QIODevice::WriteOnly);
+    file.write(reply->readAll());
+}

+ 58 - 0
launcher.h

@@ -0,0 +1,58 @@
+#ifndef GIFANIMATIONDEMOWIDGET_H
+#define GIFANIMATIONDEMOWIDGET_H
+#include <QApplication>
+#include <QWidget>
+#include <QLabel>
+#include <QFile>
+#include <QFileInfo>
+#include <QStandardPaths>
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkReply>
+#include <QMovie>
+#include <QUrl>
+#include <QDir>
+#include <QThread>
+#include <QtConcurrent/QtConcurrent>
+#include <QMediaPlayer>
+#include <QMediaPlaylist>
+#include <QVideoWidget>
+
+namespace Ui {
+class GIFAnimationDemoWidget;
+}
+
+class GIFAnimationDemoWidget : public QWidget {
+    Q_OBJECT
+
+public:
+    explicit GIFAnimationDemoWidget( QWidget* parent = 0 );
+    ~GIFAnimationDemoWidget();
+
+    QString df_url;
+    QString df_path;
+    QNetworkAccessManager *m_NetworkMngr;
+    QNetworkReply *reply;
+
+    void downloadFile(const QString &url, const QString &aPathInClient);
+    QString getFilelist(const QString &url);
+    void makeFolder(QString path);
+    bool fileExists(QString path);
+    QString fileHash(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm);
+    void start(QString filelist);
+
+
+public slots:
+
+private slots:
+    void startNewAnimation();
+
+private:
+    Ui::GIFAnimationDemoWidget* ui;
+
+    QMovie * movie;
+    QMediaPlayer *player;
+    QMediaPlaylist *playlist;
+    QVideoWidget *videoWidget;
+};
+
+#endif // GIFANIMATIONDEMOWIDGET_H

+ 87 - 0
launcher.ui

@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>GIFAnimationDemoWidget</class>
+ <widget class="QWidget" name="GIFAnimationDemoWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>372</width>
+    <height>247</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>GIFAnimationDemoWidget</string>
+  </property>
+  <property name="windowOpacity">
+   <double>1.000000000000000</double>
+  </property>
+  <property name="autoFillBackground">
+   <bool>false</bool>
+  </property>
+  <property name="styleSheet">
+   <string notr="true">background-color: rgb(255, 255, 255);</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <property name="sizeConstraint">
+    <enum>QLayout::SetNoConstraint</enum>
+   </property>
+   <property name="leftMargin">
+    <number>0</number>
+   </property>
+   <property name="topMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <property name="bottomMargin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="QGroupBox" name="groupBox">
+     <property name="styleSheet">
+      <string notr="true">background-color: #262626;
+border: none;</string>
+     </property>
+     <property name="title">
+      <string/>
+     </property>
+     <widget class="QLabel" name="lbHint">
+      <property name="geometry">
+       <rect>
+        <x>10</x>
+        <y>223</y>
+        <width>341</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="styleSheet">
+       <string notr="true">background-color: #262626;
+color: rgb(255, 255, 255);</string>
+      </property>
+      <property name="text">
+       <string>TextLabel</string>
+      </property>
+     </widget>
+     <widget class="QLabel" name="lbMovie">
+      <property name="geometry">
+       <rect>
+        <x>5</x>
+        <y>5</y>
+        <width>365</width>
+        <height>221</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string/>
+      </property>
+     </widget>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>

+ 22 - 0
main.cpp

@@ -0,0 +1,22 @@
+#include "launcher.h"
+#include <QApplication>
+#include <QLockFile>
+#include <QMessageBox>
+
+int main( int argc, char* argv[] ) {
+    QApplication a( argc, argv );
+    GIFAnimationDemoWidget w;
+
+    QLockFile lockFile(QDir::temp().absoluteFilePath("rulotro_launcher.lock"));
+    if(!lockFile.tryLock(100)){
+        QMessageBox msgBox;
+        msgBox.setIcon(QMessageBox::Warning);
+        msgBox.setText("Приложение уже запущено.\nРазрешено запускать только один экземпляр приложения.");
+        msgBox.exec();
+        return 1;
+    }
+
+    w.show();
+
+    return a.exec();
+}

+ 37 - 0
resources.rc

@@ -0,0 +1,37 @@
+IDI_ICON1 ICON "resources/appicon.ico"
+
+#include <windows.h>
+
+#define VER_FILEVERSION             2,0,0
+#define VER_FILEVERSION_STR         "2.0.0\0"
+#define VER_PRODUCTVERSION          2,0,0
+#define VER_PRODUCTVERSION_STR      "2.0.0\0"
+#define VER_FILEDESCRIPTION_STR     "LotRO: Legacy Updater"
+#define VER_INTERNALNAME_STR        "LegacyUpdater"
+#define VER_LEGALCOPYRIGHT_STR      "LotRO Rusification project (translate.lotros.ru)"
+#define VER_ORIGINALFILENAME_STR    "LegacyLauncher.exe"
+#define VER_PRODUCTNAME_STR         "LotRO: Legacy"
+
+VS_VERSION_INFO VERSIONINFO
+FILEVERSION     VER_FILEVERSION
+PRODUCTVERSION  VER_PRODUCTVERSION
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904E4"
+        BEGIN
+            VALUE "FileDescription",    VER_FILEDESCRIPTION_STR
+            VALUE "FileVersion",        VER_FILEVERSION_STR
+            VALUE "InternalName",       VER_INTERNALNAME_STR
+            VALUE "LegalCopyright",     VER_LEGALCOPYRIGHT_STR
+            VALUE "OriginalFilename",   VER_ORIGINALFILENAME_STR
+            VALUE "ProductName",        VER_PRODUCTNAME_STR
+            VALUE "ProductVersion",     VER_PRODUCTVERSION_STR
+        END
+    END
+
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 1252
+    END
+END

BIN
resources/appicon.ico


+ 6 - 0
resources/resources.qrc

@@ -0,0 +1,6 @@
+<RCC>
+    <qresource prefix="/">
+        <file>appicon.ico</file>
+        <file>second.gif</file>
+    </qresource>
+</RCC>

BIN
resources/second.gif