VCS Linux
This commit is contained in:
parent
6d62b85c10
commit
5004c5adde
@ -8,13 +8,14 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <qjsonobject.h>
|
#include <qjsonobject.h>
|
||||||
|
#include <QEventLoop>
|
||||||
|
|
||||||
#include "profile_handler/forge1_12_2.h"
|
#include "profile_handler/forge1_12_2.h"
|
||||||
#include "../ui/mainwindow.h"
|
#include "../ui/mainwindow.h"
|
||||||
#include "../../resources/ui_mainwindow.h"
|
#include "../../resources/ui_mainwindow.h"
|
||||||
|
|
||||||
|
|
||||||
Launcher::Launcher(QObject *mainwindow) : QObject(mainwindow), process(new QProcess(this)), mainwindow(mainwindow), get_args(new forge1_12_2()) {
|
Launcher::Launcher(QObject *mainwindow) : QObject(mainwindow), process(new QProcess(this)), mainwindow(mainwindow), get_args(new forge1_12_2()), run_status(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -23,43 +24,115 @@ Launcher::~Launcher() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Launcher::startProcess(QString &username, QString &uuid, QString &access_token) {
|
void Launcher::update() {
|
||||||
// Подготовка параметров запуска
|
|
||||||
MainWindow *mainWindow = qobject_cast<MainWindow *>(mainwindow);
|
MainWindow *mainWindow = qobject_cast<MainWindow *>(mainwindow);
|
||||||
|
QDir app_dir(QCoreApplication::applicationDirPath());
|
||||||
|
|
||||||
|
// Создаем процесс для выполнения команды rsync
|
||||||
|
QProcess *rsyncProcess = new QProcess(this);
|
||||||
|
rsyncProcess->setWorkingDirectory(app_dir.absolutePath());
|
||||||
|
|
||||||
|
|
||||||
|
// Подключаем вывод процесса к текстовому полю download_bar
|
||||||
|
connect(rsyncProcess, &QProcess::readyReadStandardOutput, [rsyncProcess, mainWindow]() {
|
||||||
|
QString output = rsyncProcess->readAllStandardOutput();
|
||||||
|
QStringList lines = output.split('\r', Qt::SkipEmptyParts);
|
||||||
|
QString lastLine = lines.isEmpty() ? "" : lines.last().trimmed();
|
||||||
|
if (!lastLine.isEmpty()) {
|
||||||
|
QRegularExpression regex(R"((\d+,\d+,\d+)\s+(\d+%)\s+(\d+\.\d+MB\/s)\s+(\d+:\d+:\d+))");
|
||||||
|
QRegularExpressionMatch match = regex.match(lastLine);
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
QString progress = match.captured(1);
|
||||||
|
QString percent = match.captured(2);
|
||||||
|
QString speed = match.captured(3);
|
||||||
|
QString time = match.captured(4);
|
||||||
|
QString displayText = QString("%1 %2 %3 %4").arg(progress, percent, speed, time);
|
||||||
|
mainWindow->ui->download_bar->setText(displayText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Подключаем вывод stderr к текстовому полю download_bar
|
||||||
|
connect(rsyncProcess, &QProcess::readyReadStandardError, [rsyncProcess, mainWindow]() {
|
||||||
|
QString errorOutput = rsyncProcess->readAllStandardError();
|
||||||
|
mainWindow->ui->download_bar->setText(errorOutput);
|
||||||
|
qDebug() << errorOutput;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Выполняем команду rsync
|
||||||
|
QStringList rsyncArgs;
|
||||||
|
rsyncArgs << "-az" << "--info=progress2" << "punkcraft.ru::PunkCraft" << "./";
|
||||||
|
rsyncProcess->start("rsync", rsyncArgs);
|
||||||
|
|
||||||
|
if (!rsyncProcess->waitForStarted()) {
|
||||||
|
qDebug() << "Failed to start rsync process";
|
||||||
|
qDebug() << rsyncProcess->errorString();
|
||||||
|
emit updateFinished(); // Сигнализируем о завершении (даже если произошла ошибка)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ожидаем завершения процесса rsync
|
||||||
|
connect(rsyncProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [this, rsyncProcess](int, QProcess::ExitStatus) {
|
||||||
|
qDebug() << "Rsync process finished";
|
||||||
|
rsyncProcess->deleteLater(); // Удаляем процесс после завершения
|
||||||
|
emit updateFinished(); // Сигнализируем о завершении
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Launcher::startProcess(QString &username, QString &uuid, QString &access_token) {
|
||||||
|
if (run_status) {
|
||||||
|
qDebug() << "Process is already running";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
run_status = true;
|
||||||
|
|
||||||
|
MainWindow *mainWindow = qobject_cast<MainWindow *>(mainwindow);
|
||||||
|
QDir app_dir(QCoreApplication::applicationDirPath());
|
||||||
|
|
||||||
|
// Обновление клиента
|
||||||
|
QEventLoop loop;
|
||||||
|
connect(this, &Launcher::updateFinished, &loop, &QEventLoop::quit); // Ожидаем сигнала updateFinished
|
||||||
|
update(); // Запускаем асинхронное обновление
|
||||||
|
loop.exec(); // Блокируем выполнение до завершения update
|
||||||
|
|
||||||
|
// Подготовка параметров запуска
|
||||||
QString selected_profile = mainWindow->ui->selected_profile->currentText();
|
QString selected_profile = mainWindow->ui->selected_profile->currentText();
|
||||||
QDir exe_dir(QCoreApplication::applicationDirPath());
|
client_dir = app_dir.absolutePath() + "/" + selected_profile;
|
||||||
client_dir = exe_dir.absolutePath() + "/" + selected_profile;
|
|
||||||
json_settings = mainWindow->settings->loadFromJson(selected_profile);
|
json_settings = mainWindow->settings->loadFromJson(selected_profile);
|
||||||
java_path = json_settings["java_path"].toString();
|
java_path = json_settings["java_path"].toString();
|
||||||
RAM = json_settings["RAM"].toString();
|
RAM = json_settings["RAM"].toString();
|
||||||
garbarge_collector = json_settings["garbarge_collector"].toString();
|
garbarge_collector = json_settings["garbarge_collector"].toString();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Выбор профиля
|
// Выбор профиля
|
||||||
//
|
//
|
||||||
if (selected_profile == "CyberExtrieme") {
|
if (selected_profile == "ZombieExtrieme") {
|
||||||
arguments = get_args->getCrossPlatformArgs(RAM, username, uuid, access_token, garbarge_collector);
|
arguments = get_args->getCrossPlatformArgs(RAM, username, uuid, access_token, garbarge_collector);
|
||||||
java_path = java_path.isEmpty() ?
|
java_path = java_path.isEmpty() ?
|
||||||
exe_dir.absolutePath() + "/java/zulu8.84.0.15-ca-jre8.0.442-linux_x64/bin/java" : java_path;
|
app_dir.absolutePath() + "/java/zulu8.84.0.15-ca-jre8.0.442-linux_x64/bin/java" : java_path;
|
||||||
RAM = RAM.isEmpty() ? "4096M" : RAM;
|
RAM = RAM.isEmpty() ? "4096M" : RAM;
|
||||||
garbarge_collector = garbarge_collector.isEmpty() ? "default_collector" : garbarge_collector;
|
garbarge_collector = garbarge_collector.isEmpty() ? "default_collector" : garbarge_collector;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Запуск процесса
|
// Запуск процесса
|
||||||
process->setWorkingDirectory(client_dir);
|
process->setWorkingDirectory(client_dir);
|
||||||
process->start(java_path, arguments);
|
process->start(java_path, arguments);
|
||||||
|
|
||||||
if (!process->waitForStarted()) {
|
if (!process->waitForStarted()) {
|
||||||
qDebug() << "Failed to start process";
|
qDebug() << "Failed to start process";
|
||||||
qDebug() << process->errorString();
|
qDebug() << process->errorString();
|
||||||
|
run_status = false; // Сбрасываем статус, если процесс не запустился
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Скрытие лаунчера
|
||||||
// Скрытие лаунчера
|
connect(process,
|
||||||
connect(process,
|
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||||
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
[mainWindow, this](int, QProcess::ExitStatus) {
|
||||||
[mainWindow](int, QProcess::ExitStatus) { mainWindow->show(); });
|
mainWindow->show();
|
||||||
mainWindow->hide();
|
run_status = false; // Сбрасываем статус после завершения процесса
|
||||||
|
});
|
||||||
|
mainWindow->hide();
|
||||||
qDebug() << "Process started successfully";
|
qDebug() << "Process started successfully";
|
||||||
}
|
}
|
||||||
|
@ -17,19 +17,24 @@ public:
|
|||||||
explicit Launcher(QObject *mainwindow = nullptr);
|
explicit Launcher(QObject *mainwindow = nullptr);
|
||||||
~Launcher();
|
~Launcher();
|
||||||
void startProcess(QString &username, QString &uuid, QString &access_token);
|
void startProcess(QString &username, QString &uuid, QString &access_token);
|
||||||
|
void update(); // Обновленный метод update
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void updateFinished(); // Сигнал, который будет испускаться после завершения update
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QProcess *process;
|
QProcess *process;
|
||||||
QObject *mainwindow;
|
QObject *mainwindow;
|
||||||
forge1_12_2 *get_args;
|
forge1_12_2 *get_args;
|
||||||
|
bool run_status;
|
||||||
|
|
||||||
// Переменные для запуска клиента
|
// Переменные для запуска клиента
|
||||||
QString client_dir;
|
QString client_dir;
|
||||||
QString RAM;
|
QString RAM;
|
||||||
QString java_path;
|
QString java_path;
|
||||||
QString garbarge_collector;
|
QString garbarge_collector;
|
||||||
QJsonObject json_settings;
|
QJsonObject json_settings;
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
6
src/app/vcs/cwrsync.cpp
Normal file
6
src/app/vcs/cwrsync.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "rsync.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Rsync::Rsync() {}
|
||||||
|
|
14
src/app/vcs/cwrsync.h
Normal file
14
src/app/vcs/cwrsync.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef RSYNC_H
|
||||||
|
#define RSYNC_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Rsync {
|
||||||
|
public:
|
||||||
|
Rsync();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
6
src/app/vcs/rsync.cpp
Normal file
6
src/app/vcs/rsync.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "rsync.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Rsync::Rsync() {}
|
||||||
|
|
14
src/app/vcs/rsync.h
Normal file
14
src/app/vcs/rsync.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef RSYNC_H
|
||||||
|
#define RSYNC_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Rsync {
|
||||||
|
public:
|
||||||
|
Rsync();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1009</width>
|
<width>1009</width>
|
||||||
<height>631</height>
|
<height>658</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -688,6 +688,9 @@ QLineEdit::placeholder {
|
|||||||
<bold>true</bold>
|
<bold>true</bold>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="layoutDirection">
|
||||||
|
<enum>Qt::LeftToRight</enum>
|
||||||
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">QComboBox {
|
<string notr="true">QComboBox {
|
||||||
color: rgba(255, 255, 255,0.9);
|
color: rgba(255, 255, 255,0.9);
|
||||||
@ -712,6 +715,7 @@ QLineEdit::placeholder {
|
|||||||
padding-left: 100px;
|
padding-left: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QFrame {
|
QFrame {
|
||||||
border-bottom-right-radius: 5px;
|
border-bottom-right-radius: 5px;
|
||||||
}
|
}
|
||||||
@ -731,6 +735,7 @@ QComboBox::drop-down {
|
|||||||
border-bottom-left-radius: 4px;
|
border-bottom-left-radius: 4px;
|
||||||
border-top-right-radius: 4px;
|
border-top-right-radius: 4px;
|
||||||
border-bottom-right-radius: 5px;
|
border-bottom-right-radius: 5px;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -748,7 +753,7 @@ QComboBox:hover {
|
|||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>CyberExtrieme</string>
|
<string>ZombieExtrieme</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
@ -781,6 +786,28 @@ QComboBox:hover {
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="download_bar">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>14</pointsize>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">background-color: rgba(255, 255, 255, 0);
|
||||||
|
color: rgba(255, 255, 255, 0.7);
|
||||||
|
margin-bottom: 1px;</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="ComingSoon"/>
|
<widget class="QWidget" name="ComingSoon"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user