Improvements from linux side. Built standalone linux executable and included in source

This commit is contained in:
Jkibbels 2025-02-08 18:29:54 -05:00
parent 429e93d9dc
commit ca327be658
3 changed files with 18 additions and 16 deletions

BIN
linux_installer.zip Normal file

Binary file not shown.

View File

@ -31,18 +31,18 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete ui;
delete net; delete net;
delete reply; delete reply;
delete ui;
} }
// Kick off the installation
void MainWindow::on_install_update_button_clicked() void MainWindow::on_install_update_button_clicked()
{ {
if (ConfirmationPopup()) { if (ConfirmationPopup()) {
QNetworkRequest request(downloadUrl); QNetworkRequest request(downloadUrl);
reply = net->get(request); reply = net->get(request);
// connect(reply, SIGNAL(&QNetworkReply::errorOccurred), this, SLOT(Error(QNetworkReply::NetworkError)));
connect(reply, &QNetworkReply::errorOccurred, this, [this](QNetworkReply::NetworkError) { connect(reply, &QNetworkReply::errorOccurred, this, [this](QNetworkReply::NetworkError) {
reply->deleteLater(); reply->deleteLater();
QMessageBox::warning(nullptr, "Error", reply->errorString()); QMessageBox::warning(nullptr, "Error", reply->errorString());
@ -53,11 +53,13 @@ void MainWindow::on_install_update_button_clicked()
} }
} }
// Callback from network manager on download. Update the progress bar as we download
void MainWindow::UpdateProgress(qint64 read, qint64 total) { void MainWindow::UpdateProgress(qint64 read, qint64 total) {
ui->mf_progress_bar->setMaximum(total); ui->mf_progress_bar->setMaximum(total);
ui->mf_progress_bar->setValue(read); ui->mf_progress_bar->setValue(read);
} }
// This is a callback to when the download is completed by the network manager
void MainWindow::FinishedDownloading() { void MainWindow::FinishedDownloading() {
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
@ -86,11 +88,13 @@ void MainWindow::FinishedDownloading() {
} }
} }
// Build the unzip command depending on the users operating system
std::string MainWindow::BuildUnzipCmd() { std::string MainWindow::BuildUnzipCmd() {
std::stringstream ss; std::stringstream ss;
#ifdef WIN64 #ifdef WIN64
ss << "tar -xf " << downloadLocation.toStdString() << " -C " << modsDir.toStdString(); ss << "tar -xf " << downloadLocation.toStdString() << " -C " << modsDir.toStdString();
#elif __unix__ #elif __unix__
qDebug() << "DL Loc: " << downloadLocation << " modsDir: " << modsDir;
ss << "unzip " << downloadLocation.toStdString() << " -d " << modsDir.toStdString(); ss << "unzip " << downloadLocation.toStdString() << " -d " << modsDir.toStdString();
#endif #endif
return ss.str(); return ss.str();
@ -134,11 +138,13 @@ void MainWindow::Install() {
PostInstallMode(); PostInstallMode();
} }
// Callback for downloading
void MainWindow::Error(QNetworkReply::NetworkError code) { void MainWindow::Error(QNetworkReply::NetworkError code) {
reply->deleteLater(); reply->deleteLater();
QMessageBox::warning(nullptr, "Error", reply->errorString()); QMessageBox::warning(nullptr, "Error", reply->errorString());
} }
// Setup the window to be ready to update/install the mods folder
void MainWindow::PreInstallMode() { void MainWindow::PreInstallMode() {
ui->mf_progress_bar->setEnabled(false); ui->mf_progress_bar->setEnabled(false);
ui->install_update_button->setText("Update / Install"); ui->install_update_button->setText("Update / Install");
@ -147,6 +153,7 @@ void MainWindow::PreInstallMode() {
ui->close_launcher->setVisible(false); ui->close_launcher->setVisible(false);
} }
// Set window variables after installation and unzipping
void MainWindow::PostInstallMode() { void MainWindow::PostInstallMode() {
ui->mf_progress_bar->setEnabled(false); ui->mf_progress_bar->setEnabled(false);
ui->install_update_button->setEnabled(false); ui->install_update_button->setEnabled(false);
@ -155,19 +162,22 @@ void MainWindow::PostInstallMode() {
ui->close_launcher->setVisible(true); ui->close_launcher->setVisible(true);
} }
// Make sure the user is sure they are OK with the current configuration
bool MainWindow::ConfirmationPopup() { bool MainWindow::ConfirmationPopup() {
// This is the preinstall pop up box // This is the preinstall pop up box
QString tInstallFabric = "YOU MUST HAVE FABRIC INSTALLED PRIOR TO USING THIS INSTALLER";
QString tempInstallPath = "Install to: " + modsDir; QString tempInstallPath = "Install to: " + modsDir;
QString tempDlSrvr = "Grab mods.zip from: " + downloadUrl.toString(); QString tempDlSrvr = "Grab mods.zip from: " + downloadUrl.toString();
QString formatted = tempInstallPath.append("\n").append(tempDlSrvr); QString deleteAll = "This installer will DELETE YOUR EXISTING MODS DIRECTORY. Back it up if you care about it beforehand!";
QString formatted = tInstallFabric.append(tempInstallPath).append("\n").append("\n").append(tempDlSrvr).append("\n").append(deleteAll);
QMessageBox::StandardButton reply = QMessageBox::question(nullptr, "Confirm install options...", formatted); QMessageBox::StandardButton reply = QMessageBox::question(nullptr, "Confirm install options...", formatted);
return reply == QMessageBox::Yes; return reply == QMessageBox::Yes;
} }
// This handles setting data prior to the install period dependent on the users operating system.
void MainWindow::UpdateOSAgnosticInformation() { void MainWindow::UpdateOSAgnosticInformation() {
#ifdef _WIN64 #ifdef _WIN64
isLinux = false;
char* appDataLoc = std::getenv("APPDATA"); char* appDataLoc = std::getenv("APPDATA");
if (appDataLoc) { if (appDataLoc) {
std::filesystem::path execPath(appDataLoc); std::filesystem::path execPath(appDataLoc);
@ -179,9 +189,9 @@ void MainWindow::UpdateOSAgnosticInformation() {
QMessageBox::warning(nullptr, "Warning", "Unable to resolve APPDATA environment variable. You must manually set the .minecraft folder location"); QMessageBox::warning(nullptr, "Warning", "Unable to resolve APPDATA environment variable. You must manually set the .minecraft folder location");
} }
#elif __unix__ #elif __unix__
isLinux = true;
downloadLocation = getenv("HOME"); downloadLocation = getenv("HOME");
modsDir = downloadLocation + "/.minecraft/"; // Default value modsDir = downloadLocation + "/.minecraft/"; // Default value
downloadLocation.append("/mods.zip");
#endif #endif
// Update the UI to reflect the default values correctly // Update the UI to reflect the default values correctly
@ -189,18 +199,14 @@ void MainWindow::UpdateOSAgnosticInformation() {
ui->mcInstallDir->setText(modsDir); ui->mcInstallDir->setText(modsDir);
} }
// This just closes the application but DOES call the destructor.
// It technically segfaults on the way out for some odd reason; but the pointers are cleaned up. Who knows!
void MainWindow::on_close_launcher_clicked() void MainWindow::on_close_launcher_clicked()
{ {
delete reply;
delete net;
QApplication::quit(); QApplication::quit();
} }
// unused // This is called if the users default .minecraft path cannot be found (by a user pressing the button of course)
void MainWindow::on_changeInstallPathButton_triggered(QAction *arg1){}
void MainWindow::on_changeInstallPathButton_clicked() void MainWindow::on_changeInstallPathButton_clicked()
{ {
QString directory = QFileDialog::getExistingDirectory(this, tr("Find Files"), QDir::currentPath()); QString directory = QFileDialog::getExistingDirectory(this, tr("Find Files"), QDir::currentPath());

View File

@ -35,8 +35,6 @@ private slots:
void on_close_launcher_clicked(); void on_close_launcher_clicked();
void on_changeInstallPathButton_triggered(QAction *arg1);
void on_changeInstallPathButton_clicked(); void on_changeInstallPathButton_clicked();
void on_sf_dl_server_textChanged(); void on_sf_dl_server_textChanged();
@ -48,7 +46,5 @@ private:
QString modsDir = "Set .minecraft path here..."; QString modsDir = "Set .minecraft path here...";
QString downloadLocation; QString downloadLocation;
QNetworkReply* reply = nullptr; QNetworkReply* reply = nullptr;
bool isLinux = true;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H