From 417fe5af820eab54ee8023e28bb9d02fd414ca3c Mon Sep 17 00:00:00 2001 From: galeon Date: Sat, 30 Aug 2025 19:46:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D0=B8=D1=80=D1=83?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=BF=D0=B5=D1=80=D0=B2=D1=83=D1=8E=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=81=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LauncherWindow.cpp | 114 +++++++++++++++++++++++++++++++++++++++++++++ LauncherWindow.h | 37 +++++++++++++++ main.cpp | 10 ++++ 3 files changed, 161 insertions(+) create mode 100644 LauncherWindow.cpp create mode 100644 LauncherWindow.h create mode 100644 main.cpp diff --git a/LauncherWindow.cpp b/LauncherWindow.cpp new file mode 100644 index 0000000..f195140 --- /dev/null +++ b/LauncherWindow.cpp @@ -0,0 +1,114 @@ +#include "LauncherWindow.h" +#include +#include +#include +#include +#include +#include +#include + +LauncherWindow::LauncherWindow(QWidget *parent) + : QMainWindow(parent) +{ + setupUI(); + networkManager = new QNetworkAccessManager(this); + connect(networkManager, &QNetworkAccessManager::finished, this, &LauncherWindow::onDownloadFinished); +} + +LauncherWindow::~LauncherWindow() +{ +} + +void LauncherWindow::setupUI() +{ + QWidget *centralWidget = new QWidget(this); + setCentralWidget(centralWidget); + + QVBoxLayout *layout = new QVBoxLayout(centralWidget); + + usernameLineEdit = new QLineEdit(this); + usernameLineEdit->setPlaceholderText("Введите ваш никнейм"); + layout->addWidget(usernameLineEdit); + + launchButton = new QPushButton("Запустить Minecraft", this); + connect(launchButton, &QPushButton::clicked, this, &LauncherWindow::launchMinecraft); + layout->addWidget(launchButton); + + modsFolderButton = new QPushButton("Открыть папку с модами", this); + connect(modsFolderButton, &QPushButton::clicked, this, &LauncherWindow::openModsFolder); + layout->addWidget(modsFolderButton); + + downloadModsButton = new QPushButton("Загрузить моды с GitHub", this); + connect(downloadModsButton, &QPushButton::clicked, this, &LauncherWindow::downloadMods); + layout->addWidget(downloadModsButton); + + setWindowTitle("Minecraft Launcher"); + resize(300, 200); +} + +QString LauncherWindow::getMinecraftPath() +{ +#ifdef Q_OS_WIN + return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/.minecraft"; +#elif defined(Q_OS_MAC) + return QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/Library/Application Support/minecraft"; +#else + return QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.minecraft"; +#endif +} + +void LauncherWindow::launchMinecraft() +{ + QString username = usernameLineEdit->text(); + if (username.isEmpty()) { + QMessageBox::warning(this, "Ошибка", "Пожалуйста, введите никнейм."); + return; + } + + // Это упрощенная команда запуска. Для современных версий Minecraft + // может потребоваться более сложная команда с указанием версии, + // аутентификацией и путями к библиотекам. + // Здесь мы используем гипотетическую команду для демонстрации. + QString command = "java -jar \"" + getMinecraftPath() + "/versions/1.19.2/1.19.2.jar\" --username " + username; + + QProcess *process = new QProcess(this); + process->startDetached(command); +} + +void LauncherWindow::openModsFolder() +{ + QString modsPath = getMinecraftPath() + "/mods"; + QDir modsDir(modsPath); + if (!modsDir.exists()) { + modsDir.mkpath("."); + } + QDesktopServices::openUrl(QUrl::fromLocalFile(modsPath)); +} + +void LauncherWindow::downloadMods() +{ + // URL для загрузки ZIP-архива с модами из репозитория GitHub + // Замените на URL вашего репозитория + QUrl url("https://github.com/user/repo/archive/refs/heads/main.zip"); + QNetworkRequest request(url); + networkManager->get(request); +} + +void LauncherWindow::onDownloadFinished(QNetworkReply *reply) +{ + if (reply->error()) { + QMessageBox::critical(this, "Ошибка загрузки", "Не удалось загрузить моды: " + reply->errorString()); + return; + } + + QFile *file = new QFile(getMinecraftPath() + "/mods/mods.zip"); + if (file->open(QIODevice::WriteOnly)) { + file->write(reply->readAll()); + file->close(); + QMessageBox::information(this, "Загрузка завершена", "Моды успешно загружены в папку mods. Распакуйте архив."); + } else { + QMessageBox::critical(this, "Ошибка", "Не удалось сохранить архив с модами."); + } + delete file; + reply->deleteLater(); +} \ No newline at end of file diff --git a/LauncherWindow.h b/LauncherWindow.h new file mode 100644 index 0000000..a0cd26b --- /dev/null +++ b/LauncherWindow.h @@ -0,0 +1,37 @@ +#ifndef LAUNCHERWINDOW_H +#define LAUNCHERWINDOW_H + +#include +#include +#include +#include +#include +#include + +class LauncherWindow : public QMainWindow +{ + Q_OBJECT + +public: + LauncherWindow(QWidget *parent = nullptr); + ~LauncherWindow(); + +private slots: + void launchMinecraft(); + void openModsFolder(); + void downloadMods(); + void onDownloadFinished(QNetworkReply *reply); + +private: + void setupUI(); + QString getMinecraftPath(); + + QPushButton *launchButton; + QPushButton *modsFolderButton; + QPushButton *downloadModsButton; + QLineEdit *usernameLineEdit; + + QNetworkAccessManager *networkManager; +}; + +#endif // LAUNCHERWINDOW_H \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..d7a2d6a --- /dev/null +++ b/main.cpp @@ -0,0 +1,10 @@ +#include "LauncherWindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + LauncherWindow w; + w.show(); + return a.exec(); +} \ No newline at end of file