Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "jarprogress.h"
- #include "ui_jarprogress.h"
- #include "minecraftmanager.h"
- #include "minemod.h"
- #include "syncmods.h"
- #include "extractasync.h"
- #include "simpledownloader.h"
- #include <QMessageBox>
- #include <QEventLoop>
- JarProgress::JarProgress(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::JarProgress)
- {
- ui->setupUi(this);
- }
- JarProgress::~JarProgress()
- {
- delete ui;
- }
- void JarProgress::ProgressUpdated(int min, int max, QString detail, QString subDetail) {
- ui->prgProgress->setMinimum(0);
- ui->prgProgress->setValue(min);
- ui->prgProgress->setMaximum(max);
- ui->txtStatus->setText(detail);
- ui->txtSubStatus->setText(subDetail);
- }
- void JarProgress::ExtractMinecraft(QString minecraftLocation, QString modLocation) {
- this->show();
- /*MinecraftManager *mgr = new MinecraftManager();
- connect(mgr, SIGNAL(ProgressUpdated(int,int,QString,QString)), this, SLOT(ProgressUpdated(int,int,QString,QString)), Qt::BlockingQueuedConnection);
- connect(mgr, SIGNAL(Completed()), this, SLOT(Completed()));
- mgr->UnzipMinecraft(minecraftLocation, modLocation, this);*/
- ExtractAsync *async = new ExtractAsync();
- connect(async, SIGNAL(ProgressUpdated(int,int,QString,QString)), this, SLOT(ProgressUpdated(int,int,QString,QString)));
- connect(async, SIGNAL(Completed()), this, SLOT(Completed()));
- async->start();
- }
- void JarProgress::Completed() {
- this->close();
- }
- void JarProgress::Sync(QString minecraftLocation, QString modLocation) {
- this->show();
- // ORDER: First, download the latest version of Minecraft, then
- // use the SyncM class to sync up the mods.
- this->ProgressUpdated(-1, 0, "Downloading Minecraft", "Connecting");
- SimpleDownloader *down = new SimpleDownloader();
- //QEventLoop loop(this);
- connect(down, SIGNAL(Progress(int,int,QString)), this, SLOT(DownloadProgress(int,int,QString)));
- connect(down, SIGNAL(Finished(QString,bool,QString)), this, SLOT(DownloadFinished(QString,bool,QString)));
- //loop.exec();
- down->InitDownload("http://minecraft.net/download/minecraft.jar", modLocation + "/tempDL");
- }
- void JarProgress::DownloadFinished(QString filename, bool success, QString message) {
- if (success) {
- SyncMods *syncM = new SyncMods(filename);
- connect(syncM, SIGNAL(Progress(int,int,QString,QString)), this, SLOT(SyncProgressUpdated(int,int,QString,QString)));
- connect(syncM, SIGNAL(Complete(bool,QString)), this, SLOT(SyncComplete(bool,QString)));
- syncM->start();
- } else {
- QMessageBox::critical(this, "Error", "There was an error downloading Minecraft.<p><b>Details:</b> " + message + "</p>",
- QMessageBox::Ok, QMessageBox::NoButton);
- this->reject();
- }
- }
- void JarProgress::DownloadProgress(int min, int max, QString message) {
- }
- void JarProgress::SyncComplete(bool successful, QString message) {
- if (successful)
- this->accept();
- else {
- QMessageBox::critical(this, "Error",
- "There was an error syncing with Minecraft.<p><b>Error Details:</b> " + message + "</p>",
- QMessageBox::Ok, QMessageBox::NoButton);
- this->reject();
- }
- }
- void JarProgress::SyncProgressUpdated(int val, int max, QString top, QString bottom) {
- ui->prgProgress->setMinimum(0);
- ui->prgProgress->setValue(val);
- ui->prgProgress->setMaximum(max);
- ui->txtStatus->setText(top);
- ui->txtSubStatus->setText(bottom);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement