Cleaning up and adding confirmation stuff to not blow everything up
This commit is contained in:
parent
e2725e00a1
commit
429e93d9dc
@ -38,17 +38,19 @@ MainWindow::~MainWindow()
|
|||||||
|
|
||||||
void MainWindow::on_install_update_button_clicked()
|
void MainWindow::on_install_update_button_clicked()
|
||||||
{
|
{
|
||||||
QNetworkRequest request(downloadUrl);
|
if (ConfirmationPopup()) {
|
||||||
reply = net->get(request);
|
QNetworkRequest request(downloadUrl);
|
||||||
|
reply = net->get(request);
|
||||||
|
|
||||||
// connect(reply, SIGNAL(&QNetworkReply::errorOccurred), this, SLOT(Error(QNetworkReply::NetworkError)));
|
// 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());
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(UpdateProgress(qint64, qint64)));
|
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(UpdateProgress(qint64, qint64)));
|
||||||
connect(reply, SIGNAL(finished()), this, SLOT(FinishedDownloading()));
|
connect(reply, SIGNAL(finished()), this, SLOT(FinishedDownloading()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::UpdateProgress(qint64 read, qint64 total) {
|
void MainWindow::UpdateProgress(qint64 read, qint64 total) {
|
||||||
@ -74,8 +76,14 @@ void MainWindow::FinishedDownloading() {
|
|||||||
ui->install_update_button->show();
|
ui->install_update_button->show();
|
||||||
ui->install_update_button->setText(QString("Unzipping..."));
|
ui->install_update_button->setText(QString("Unzipping..."));
|
||||||
|
|
||||||
// Unzip
|
// Unzip the file - this version isn't really checking if the file is really us so at the very least the name needs to match.
|
||||||
Install();
|
// Otherwise we could end up damaging the ecosystem more than necessary.
|
||||||
|
if (std::filesystem::exists(downloadLocation.toStdString())) {
|
||||||
|
Install();
|
||||||
|
} else {
|
||||||
|
QMessageBox::critical(nullptr, "Wrong format", "The downloaded file appears to not exist - or is more likely just not named mods.zip -> you either downloaded a bad file or Jesse named his file wrong. Tell him to fix it!!");
|
||||||
|
PostInstallMode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MainWindow::BuildUnzipCmd() {
|
std::string MainWindow::BuildUnzipCmd() {
|
||||||
@ -93,11 +101,17 @@ void MainWindow::Install() {
|
|||||||
uint8_t installStage = 1;
|
uint8_t installStage = 1;
|
||||||
ui->mf_progress_bar->setValue(installStage++);
|
ui->mf_progress_bar->setValue(installStage++);
|
||||||
ui->mf_progress_bar->setMaximum(MAX_INSTALL_STAGES);
|
ui->mf_progress_bar->setMaximum(MAX_INSTALL_STAGES);
|
||||||
|
|
||||||
|
modsDir.append("mods");
|
||||||
|
|
||||||
// COND 1: If mods dir exists we need to nuke it
|
// COND 1: If mods dir exists we need to nuke it
|
||||||
// COND 2: If mods dir exists & it was our install location do NOT nuke it!
|
// COND 2: If mods dir exists & it was our install location do NOT nuke it!
|
||||||
if (std::filesystem::is_directory(modsDir.toStdString().append("mods")) && modsDir != downloadLocation) {
|
if (std::filesystem::is_directory(modsDir.toStdString()) && modsDir != downloadLocation) {
|
||||||
modsDir.append("mods");
|
std::filesystem::remove_all(modsDir.toStdString()); // Force empty the mods folder inside the .minecraft dir
|
||||||
std::filesystem::remove_all(modsDir.toStdString());
|
}
|
||||||
|
|
||||||
|
if (!std::filesystem::exists(modsDir.toStdString())) {
|
||||||
|
std::filesystem::create_directory(modsDir.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->mf_progress_bar->setValue(installStage++);
|
ui->mf_progress_bar->setValue(installStage++);
|
||||||
@ -106,6 +120,16 @@ void MainWindow::Install() {
|
|||||||
|
|
||||||
ui->mf_progress_bar->setValue(installStage++);
|
ui->mf_progress_bar->setValue(installStage++);
|
||||||
|
|
||||||
|
// Clean up after ourselves; remove the file if possible
|
||||||
|
try {
|
||||||
|
if (std::filesystem::exists(downloadLocation.toStdString())) {
|
||||||
|
std::filesystem::remove(downloadLocation.toStdString());
|
||||||
|
}
|
||||||
|
} catch (std::exception e) {
|
||||||
|
QString errorMsg = QString("Slight error - unable to cleanup after ourselves and could not remove leftover downloaded zip file located at %1").arg(downloadLocation);
|
||||||
|
QMessageBox::information(nullptr, "Failed to cleanup!", errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
QMessageBox::information(nullptr, "Completed", "The installer has successfully finished. You may now close the installer and launch Minecraft!");
|
QMessageBox::information(nullptr, "Completed", "The installer has successfully finished. You may now close the installer and launch Minecraft!");
|
||||||
PostInstallMode();
|
PostInstallMode();
|
||||||
}
|
}
|
||||||
@ -131,6 +155,16 @@ void MainWindow::PostInstallMode() {
|
|||||||
ui->close_launcher->setVisible(true);
|
ui->close_launcher->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MainWindow::ConfirmationPopup() {
|
||||||
|
// This is the preinstall pop up box
|
||||||
|
QString tempInstallPath = "Install to: " + modsDir;
|
||||||
|
QString tempDlSrvr = "Grab mods.zip from: " + downloadUrl.toString();
|
||||||
|
QString formatted = tempInstallPath.append("\n").append(tempDlSrvr);
|
||||||
|
QMessageBox::StandardButton reply = QMessageBox::question(nullptr, "Confirm install options...", formatted);
|
||||||
|
|
||||||
|
return reply == QMessageBox::Yes;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::UpdateOSAgnosticInformation() {
|
void MainWindow::UpdateOSAgnosticInformation() {
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
isLinux = false;
|
isLinux = false;
|
||||||
@ -140,17 +174,19 @@ void MainWindow::UpdateOSAgnosticInformation() {
|
|||||||
downloadLocation = QString::fromStdString(execPath.string()); // Stick the mods inside the roaming directory; but not the .minecraft directory itself.
|
downloadLocation = QString::fromStdString(execPath.string()); // Stick the mods inside the roaming directory; but not the .minecraft directory itself.
|
||||||
modsDir = downloadLocation + "\\.minecraft\\";
|
modsDir = downloadLocation + "\\.minecraft\\";
|
||||||
downloadLocation.append("\\mods.zip"); // Should point to %APPDATA%\mods.zip
|
downloadLocation.append("\\mods.zip"); // Should point to %APPDATA%\mods.zip
|
||||||
|
|
||||||
|
} else {
|
||||||
|
QMessageBox::warning(nullptr, "Warning", "Unable to resolve APPDATA environment variable. You must manually set the .minecraft folder location");
|
||||||
}
|
}
|
||||||
#elif __unix__
|
#elif __unix__
|
||||||
isLinux = true;
|
isLinux = true;
|
||||||
downloadLocation = getenv("HOME");
|
downloadLocation = getenv("HOME");
|
||||||
modsDir = downloadLocation + "/.minecraft/"; // Default value
|
modsDir = downloadLocation + "/.minecraft/"; // Default value
|
||||||
|
|
||||||
ui->mcInstallDir->setText(modsDir); // Tell the user the default location for their .minecraft folder.
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Update the UI to reflect the default values correctly
|
// Update the UI to reflect the default values correctly
|
||||||
ui->sf_dl_server->setPlainText(downloadUrl.toString());
|
ui->sf_dl_server->setPlainText(downloadUrl.toString());
|
||||||
|
ui->mcInstallDir->setText(modsDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -177,3 +213,9 @@ void MainWindow::on_changeInstallPathButton_clicked()
|
|||||||
ui->mcInstallDir->setText(modsDir);
|
ui->mcInstallDir->setText(modsDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::on_sf_dl_server_textChanged()
|
||||||
|
{
|
||||||
|
downloadUrl = ui->sf_dl_server->toPlainText();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ public:
|
|||||||
std::string BuildUnzipCmd();
|
std::string BuildUnzipCmd();
|
||||||
void PreInstallMode();
|
void PreInstallMode();
|
||||||
void PostInstallMode();
|
void PostInstallMode();
|
||||||
|
bool ConfirmationPopup();
|
||||||
private slots:
|
private slots:
|
||||||
void UpdateProgress(qint64, qint64);
|
void UpdateProgress(qint64, qint64);
|
||||||
void FinishedDownloading();
|
void FinishedDownloading();
|
||||||
@ -38,11 +39,13 @@ private slots:
|
|||||||
|
|
||||||
void on_changeInstallPathButton_clicked();
|
void on_changeInstallPathButton_clicked();
|
||||||
|
|
||||||
|
void on_sf_dl_server_textChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QNetworkAccessManager* net = nullptr;
|
QNetworkAccessManager* net = nullptr;
|
||||||
QUrl downloadUrl {"https://www.techyjessy.tech/downloads/mods.zip"};
|
QUrl downloadUrl {"https://www.techyjessy.tech/downloads/mods.zip"};
|
||||||
QString modsDir;
|
QString modsDir = "Set .minecraft path here...";
|
||||||
QString downloadLocation;
|
QString downloadLocation;
|
||||||
QNetworkReply* reply = nullptr;
|
QNetworkReply* reply = nullptr;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user