Compare commits
7 Commits
7adcd780b0
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 38d9805150 | |||
| d760bc2f83 | |||
| 0ebf7e07a7 | |||
| 52ef710cd7 | |||
| 4b2026e96b | |||
| 4c0c566ff9 | |||
| 6cfadfc4b6 |
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"inheritEnvironments": [
|
|
||||||
"msvc_x86"
|
|
||||||
],
|
|
||||||
"name": "x86-Debug",
|
|
||||||
"includePath": [
|
|
||||||
"${env.INCLUDE}",
|
|
||||||
"${workspaceRoot}\\**"
|
|
||||||
],
|
|
||||||
"defines": [
|
|
||||||
"WIN32",
|
|
||||||
"_DEBUG",
|
|
||||||
"UNICODE",
|
|
||||||
"_UNICODE"
|
|
||||||
],
|
|
||||||
"intelliSenseMode": "windows-msvc-x86"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
#include "LauncherWindow.h"
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QStandardPaths>
|
|
||||||
#include <QDesktopServices>
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QFile>
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#ifndef LAUNCHERWINDOW_H
|
|
||||||
#define LAUNCHERWINDOW_H
|
|
||||||
|
|
||||||
#include <QMainWindow>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
|
|
||||||
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
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
# minecraft-launcher
|
# minecraft-launcher
|
||||||
|
|
||||||
Первая итерация самописного лаунчера для запуска сборок Minecraft
|
Первая итерация самописного лаунчера для запуска сборок Minecraft
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user