UI update + clean code

This commit is contained in:
OpexHunter 2025-03-04 17:12:00 +03:00
parent 47294fef88
commit 086702dc14
6 changed files with 25 additions and 42 deletions

View File

@ -23,10 +23,6 @@ Launcher::Launcher(QObject *parent) :
mainWindow(qobject_cast<MainWindow *>(parent)), mainWindow(qobject_cast<MainWindow *>(parent)),
app_dir(QDir(QCoreApplication::applicationDirPath())) app_dir(QDir(QCoreApplication::applicationDirPath()))
{ {
if (!mainWindow) {
qCritical() << "Failed to cast parent object to MainWindow";
}
OS_type = "linux"; OS_type = "linux";
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QString vcsBinPath = app_dir.absoluteFilePath(".vcs/bin"); QString vcsBinPath = app_dir.absoluteFilePath(".vcs/bin");
@ -46,11 +42,7 @@ Launcher::~Launcher() {
void Launcher::startProcess(QString &username, QString &uuid, QString &access_token) { void Launcher::startProcess(QString &username, QString &uuid, QString &access_token) {
if (run_status) { if (run_status) { return; } run_status = true;
qDebug() << "Process is already running";
return;
}
run_status = true;
selected_profile = this->mainWindow->ui->selected_profile->currentText(); selected_profile = this->mainWindow->ui->selected_profile->currentText();
client_dir = app_dir.absolutePath() + "/" + selected_profile; client_dir = app_dir.absolutePath() + "/" + selected_profile;
@ -65,20 +57,8 @@ void Launcher::startProcess(QString &username, QString &uuid, QString &access_to
garbarge_collector = garbarge_collector.isEmpty() ? "default_collector" : garbarge_collector; garbarge_collector = garbarge_collector.isEmpty() ? "default_collector" : garbarge_collector;
version = "1.12.2"; version = "1.12.2";
} }
arguments = get_args->getCrossPlatformArgs(RAM, username, uuid, access_token, garbarge_collector); arguments = get_args->getCrossPlatformArgs(RAM, username, uuid, access_token, garbarge_collector);
if (version == "1.12.2") {
sync_dirs
<< "java/zulu8"
<< "versions/1.12.2"
<< "libraries/1.12.2"
<< selected_profile;
sync_files
<< "PunkLauncher"
<< "PunkLauncher.exe";
}
QEventLoop loop; QEventLoop loop;
connect(this, &Launcher::updateFinished, &loop, &QEventLoop::quit); connect(this, &Launcher::updateFinished, &loop, &QEventLoop::quit);
update(); update();
@ -86,9 +66,8 @@ void Launcher::startProcess(QString &username, QString &uuid, QString &access_to
process->setWorkingDirectory(client_dir); process->setWorkingDirectory(client_dir);
process->start(java_path, arguments); process->start(java_path, arguments);
this->mainWindow->hide();
if (!process->waitForStarted()) { if (!process->waitForStarted()) {
qDebug() << "Failed to start process";
qDebug() << process->errorString(); qDebug() << process->errorString();
run_status = false; run_status = false;
return; return;
@ -98,8 +77,6 @@ void Launcher::startProcess(QString &username, QString &uuid, QString &access_to
this->mainWindow->show(); this->mainWindow->show();
run_status = false; run_status = false;
}); });
this->mainWindow->hide();
} }
@ -121,7 +98,6 @@ void Launcher::update() {
} }
} }
}); });
connect(rsyncProcess, &QProcess::readyReadStandardError, [this, rsyncProcess]() { connect(rsyncProcess, &QProcess::readyReadStandardError, [this, rsyncProcess]() {
QString errorOutput = rsyncProcess->readAllStandardError(); QString errorOutput = rsyncProcess->readAllStandardError();
this->mainWindow->ui->download_bar->setText(errorOutput); this->mainWindow->ui->download_bar->setText(errorOutput);
@ -130,23 +106,30 @@ void Launcher::update() {
QStringList rsyncArgs; QStringList rsyncArgs;
rsyncArgs << "-azH" << "--info=progress2" << "--no-perms" << "--no-owner" << "--no-group"; rsyncArgs << "-azH" << "--info=progress2" << "--no-perms" << "--no-owner" << "--no-group";
if (version == "1.12.2") {
sync_dirs
<< "java/zulu8"
<< "versions/1.12.2"
<< "libraries/1.12.2"
<< selected_profile;
sync_files
<< "PunkLauncher"
<< "PunkLauncher.exe";
}
for (const QString &dir : sync_dirs) { rsyncArgs << "--include=" + dir + "/**"; } for (const QString &dir : sync_dirs) { rsyncArgs << "--include=" + dir + "/**"; }
for (const QString &file : sync_files) { rsyncArgs << "--include=" + file; } for (const QString &file : sync_files) { rsyncArgs << "--include=" + file; }
QStringList exclude_exist_files = {
QStringList excludeFiles = {
"./" + selected_profile + "/options.txt", "./" + selected_profile + "/options.txt",
"./" + selected_profile + "/optionsof.txt", "./" + selected_profile + "/optionsof.txt",
"./" + selected_profile + "/optionsshaders.txt" "./" + selected_profile + "/optionsshaders.txt"
}; };
for (const QString &filePath : exclude_exist_files) {
for (const QString &filePath : excludeFiles) {
QFileInfo fileInfo(filePath); QFileInfo fileInfo(filePath);
if (fileInfo.exists() && fileInfo.isFile()) { if (fileInfo.exists() && fileInfo.isFile()) {
QString relativePath = QDir().relativeFilePath(fileInfo.absoluteFilePath()); QString relativePath = QDir().relativeFilePath(fileInfo.absoluteFilePath());
rsyncArgs << "--exclude=" + relativePath; rsyncArgs << "--exclude=" + relativePath;
} }
} }
rsyncArgs << "--exclude=./*"; rsyncArgs << "--exclude=./*";
rsyncArgs << "punkcraft.ru::PunkCraft/" + OS_type + "/uncompressed/" << "./"; rsyncArgs << "punkcraft.ru::PunkCraft/" + OS_type + "/uncompressed/" << "./";
@ -163,8 +146,8 @@ void Launcher::update() {
rsyncProcess->deleteLater(); rsyncProcess->deleteLater();
rsyncProcess2->setWorkingDirectory(app_dir.absolutePath()); rsyncProcess2->setWorkingDirectory(app_dir.absolutePath());
QStringList modsArgs; QStringList rsyncArgs2;
modsArgs rsyncArgs2
<< "-azH" << "--info=progress2" << "--no-perms" << "--no-owner" << "--no-group" << "--delete-after" << "-azH" << "--info=progress2" << "--no-perms" << "--no-owner" << "--no-group" << "--delete-after"
<< "--include=" + selected_profile << "--include=" + selected_profile
<< "--include=" + selected_profile + "/mods/" << "--include=" + selected_profile + "/mods/"
@ -175,7 +158,7 @@ void Launcher::update() {
<< "--exclude=" + selected_profile + "/*" << "--exclude=" + selected_profile + "/*"
<< "punkcraft.ru::PunkCraft/" + OS_type + "/uncompressed/" << "./"; << "punkcraft.ru::PunkCraft/" + OS_type + "/uncompressed/" << "./";
rsyncProcess2->start("rsync", modsArgs); rsyncProcess2->start("rsync", rsyncArgs2);
connect(rsyncProcess2, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [this, rsyncProcess2]() { connect(rsyncProcess2, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [this, rsyncProcess2]() {
rsyncProcess2->deleteLater(); rsyncProcess2->deleteLater();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 KiB

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1009</width> <width>1009</width>
<height>658</height> <height>657</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -176,7 +176,7 @@ QLineEdit::placeholder {
}</string> }</string>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="load"/> <widget class="QWidget" name="load"/>
<widget class="QWidget" name="auth"> <widget class="QWidget" name="auth">
@ -480,7 +480,7 @@ QPushButton:pressed {
<widget class="QStackedWidget" name="main_stackedWidget"> <widget class="QStackedWidget" name="main_stackedWidget">
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">QWidget#CyberExtrieme { <string notr="true">QWidget#CyberExtrieme {
border-image: url(:/main/banner.jpg) 0 0 0 0 stretch stretch; border-image: url(:/main/banner.png) 0 0 0 0 stretch stretch;
}</string> }</string>
</property> </property>
<widget class="QWidget" name="CyberExtrieme"> <widget class="QWidget" name="CyberExtrieme">
@ -525,8 +525,8 @@ QPushButton:pressed {
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>280</width> <width>320</width>
<height>32</height> <height>45</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
@ -566,7 +566,7 @@ QPushButton:pressed {
и styleSheet виджета, поэтому пользуемся :) и styleSheet виджета, поэтому пользуемся :)
Здесь padding-left как затычка чтобы в глаза не бросалось Здесь padding-left как затычка чтобы в глаза не бросалось
*/ */
padding-left: 60px; padding-left: 85px;
} }

View File

@ -1,11 +1,11 @@
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>main/banner.png</file>
<file>auth/logo.png</file> <file>auth/logo.png</file>
<file>app.ico</file> <file>app.ico</file>
<file>main/selected_profile.png</file> <file>main/selected_profile.png</file>
<file>main/settings_pressed_32x32.png</file> <file>main/settings_pressed_32x32.png</file>
<file>main/settings_hover_32x32.png</file> <file>main/settings_hover_32x32.png</file>
<file>main/settings_32x32.png</file> <file>main/settings_32x32.png</file>
<file>main/banner.jpg</file>
</qresource> </qresource>
</RCC> </RCC>