VCS Linux
This commit is contained in:
parent
6d62b85c10
commit
5004c5adde
@ -8,13 +8,14 @@
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <qjsonobject.h>
|
||||
#include <QEventLoop>
|
||||
|
||||
#include "profile_handler/forge1_12_2.h"
|
||||
#include "../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,12 +24,81 @@ Launcher::~Launcher() {
|
||||
}
|
||||
|
||||
|
||||
void Launcher::startProcess(QString &username, QString &uuid, QString &access_token) {
|
||||
// Подготовка параметров запуска
|
||||
void Launcher::update() {
|
||||
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();
|
||||
QDir exe_dir(QCoreApplication::applicationDirPath());
|
||||
client_dir = exe_dir.absolutePath() + "/" + selected_profile;
|
||||
client_dir = app_dir.absolutePath() + "/" + selected_profile;
|
||||
json_settings = mainWindow->settings->loadFromJson(selected_profile);
|
||||
java_path = json_settings["java_path"].toString();
|
||||
RAM = json_settings["RAM"].toString();
|
||||
@ -37,10 +107,10 @@ void Launcher::startProcess(QString &username, QString &uuid, QString &access_to
|
||||
//
|
||||
// Выбор профиля
|
||||
//
|
||||
if (selected_profile == "CyberExtrieme") {
|
||||
if (selected_profile == "ZombieExtrieme") {
|
||||
arguments = get_args->getCrossPlatformArgs(RAM, username, uuid, access_token, garbarge_collector);
|
||||
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;
|
||||
garbarge_collector = garbarge_collector.isEmpty() ? "default_collector" : garbarge_collector;
|
||||
}
|
||||
@ -52,14 +122,17 @@ void Launcher::startProcess(QString &username, QString &uuid, QString &access_to
|
||||
if (!process->waitForStarted()) {
|
||||
qDebug() << "Failed to start process";
|
||||
qDebug() << process->errorString();
|
||||
run_status = false; // Сбрасываем статус, если процесс не запустился
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Скрытие лаунчера
|
||||
connect(process,
|
||||
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
[mainWindow](int, QProcess::ExitStatus) { mainWindow->show(); });
|
||||
[mainWindow, this](int, QProcess::ExitStatus) {
|
||||
mainWindow->show();
|
||||
run_status = false; // Сбрасываем статус после завершения процесса
|
||||
});
|
||||
mainWindow->hide();
|
||||
qDebug() << "Process started successfully";
|
||||
}
|
||||
|
@ -17,11 +17,16 @@ public:
|
||||
explicit Launcher(QObject *mainwindow = nullptr);
|
||||
~Launcher();
|
||||
void startProcess(QString &username, QString &uuid, QString &access_token);
|
||||
void update(); // Обновленный метод update
|
||||
|
||||
signals:
|
||||
void updateFinished(); // Сигнал, который будет испускаться после завершения update
|
||||
|
||||
private:
|
||||
QProcess *process;
|
||||
QObject *mainwindow;
|
||||
forge1_12_2 *get_args;
|
||||
bool run_status;
|
||||
|
||||
// Переменные для запуска клиента
|
||||
QString client_dir;
|
||||
|
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>
|
||||
<y>0</y>
|
||||
<width>1009</width>
|
||||
<height>631</height>
|
||||
<height>658</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -688,6 +688,9 @@ QLineEdit::placeholder {
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QComboBox {
|
||||
color: rgba(255, 255, 255,0.9);
|
||||
@ -712,6 +715,7 @@ QLineEdit::placeholder {
|
||||
padding-left: 100px;
|
||||
}
|
||||
|
||||
|
||||
QFrame {
|
||||
border-bottom-right-radius: 5px;
|
||||
}
|
||||
@ -731,6 +735,7 @@ QComboBox::drop-down {
|
||||
border-bottom-left-radius: 4px;
|
||||
border-top-right-radius: 4px;
|
||||
border-bottom-right-radius: 5px;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -748,7 +753,7 @@ QComboBox:hover {
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>CyberExtrieme</string>
|
||||
<string>ZombieExtrieme</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
@ -781,6 +786,28 @@ QComboBox:hover {
|
||||
</property>
|
||||
</spacer>
|
||||
</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>
|
||||
</widget>
|
||||
<widget class="QWidget" name="ComingSoon"/>
|
||||
|
Loading…
Reference in New Issue
Block a user