From 5004c5addefdbdc0397b11dcbc84b9da2053cc9f Mon Sep 17 00:00:00 2001 From: OpexHunter Date: Wed, 12 Feb 2025 14:04:51 +0300 Subject: [PATCH] VCS Linux --- src/app/launcher/launcher.cpp | 109 ++++++++++++++++++++++++++++------ src/app/launcher/launcher.h | 23 ++++--- src/app/vcs/cwrsync.cpp | 6 ++ src/app/vcs/cwrsync.h | 14 +++++ src/app/vcs/rsync.cpp | 6 ++ src/app/vcs/rsync.h | 14 +++++ src/resources/mainwindow.ui | 31 +++++++++- 7 files changed, 174 insertions(+), 29 deletions(-) create mode 100644 src/app/vcs/cwrsync.cpp create mode 100644 src/app/vcs/cwrsync.h create mode 100644 src/app/vcs/rsync.cpp create mode 100644 src/app/vcs/rsync.h diff --git a/src/app/launcher/launcher.cpp b/src/app/launcher/launcher.cpp index d360846..5484896 100644 --- a/src/app/launcher/launcher.cpp +++ b/src/app/launcher/launcher.cpp @@ -8,13 +8,14 @@ #include #include #include +#include #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,43 +24,115 @@ Launcher::~Launcher() { } -void Launcher::startProcess(QString &username, QString &uuid, QString &access_token) { - // Подготовка параметров запуска +void Launcher::update() { MainWindow *mainWindow = qobject_cast(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::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); + 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(); garbarge_collector = json_settings["garbarge_collector"].toString(); - // - // Выбор профиля - // - if (selected_profile == "CyberExtrieme") { - arguments = get_args->getCrossPlatformArgs(RAM, username, uuid, access_token, garbarge_collector); + // + // Выбор профиля + // + 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; } - // Запуск процесса + // Запуск процесса process->setWorkingDirectory(client_dir); process->start(java_path, arguments); if (!process->waitForStarted()) { qDebug() << "Failed to start process"; qDebug() << process->errorString(); + run_status = false; // Сбрасываем статус, если процесс не запустился return; } - - // Скрытие лаунчера - connect(process, - QOverload::of(&QProcess::finished), - [mainWindow](int, QProcess::ExitStatus) { mainWindow->show(); }); - mainWindow->hide(); + // Скрытие лаунчера + connect(process, + QOverload::of(&QProcess::finished), + [mainWindow, this](int, QProcess::ExitStatus) { + mainWindow->show(); + run_status = false; // Сбрасываем статус после завершения процесса + }); + mainWindow->hide(); qDebug() << "Process started successfully"; } diff --git a/src/app/launcher/launcher.h b/src/app/launcher/launcher.h index dddfedd..07e39d4 100644 --- a/src/app/launcher/launcher.h +++ b/src/app/launcher/launcher.h @@ -17,19 +17,24 @@ 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; + QObject *mainwindow; + forge1_12_2 *get_args; + bool run_status; - // Переменные для запуска клиента - QString client_dir; - QString RAM; - QString java_path; - QString garbarge_collector; - QJsonObject json_settings; - QStringList arguments; + // Переменные для запуска клиента + QString client_dir; + QString RAM; + QString java_path; + QString garbarge_collector; + QJsonObject json_settings; + QStringList arguments; }; #endif diff --git a/src/app/vcs/cwrsync.cpp b/src/app/vcs/cwrsync.cpp new file mode 100644 index 0000000..3ce65de --- /dev/null +++ b/src/app/vcs/cwrsync.cpp @@ -0,0 +1,6 @@ +#include "rsync.h" + + + +Rsync::Rsync() {} + diff --git a/src/app/vcs/cwrsync.h b/src/app/vcs/cwrsync.h new file mode 100644 index 0000000..56faacc --- /dev/null +++ b/src/app/vcs/cwrsync.h @@ -0,0 +1,14 @@ +#ifndef RSYNC_H +#define RSYNC_H + + + +class Rsync { +public: + Rsync(); + + +private: +}; + +#endif diff --git a/src/app/vcs/rsync.cpp b/src/app/vcs/rsync.cpp new file mode 100644 index 0000000..3ce65de --- /dev/null +++ b/src/app/vcs/rsync.cpp @@ -0,0 +1,6 @@ +#include "rsync.h" + + + +Rsync::Rsync() {} + diff --git a/src/app/vcs/rsync.h b/src/app/vcs/rsync.h new file mode 100644 index 0000000..56faacc --- /dev/null +++ b/src/app/vcs/rsync.h @@ -0,0 +1,14 @@ +#ifndef RSYNC_H +#define RSYNC_H + + + +class Rsync { +public: + Rsync(); + + +private: +}; + +#endif diff --git a/src/resources/mainwindow.ui b/src/resources/mainwindow.ui index ce03c1f..9bcaec6 100644 --- a/src/resources/mainwindow.ui +++ b/src/resources/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 1009 - 631 + 658 @@ -688,6 +688,9 @@ QLineEdit::placeholder { true + + Qt::LeftToRight + 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 { - CyberExtrieme + ZombieExtrieme @@ -781,6 +786,28 @@ QComboBox:hover { + + + + + 14 + 75 + true + + + + background-color: rgba(255, 255, 255, 0); +color: rgba(255, 255, 255, 0.7); +margin-bottom: 1px; + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + +