-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
278 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
#include "installfromswg.h" | ||
#include "ui_installfromswg.h" | ||
#include <QSettings> | ||
#include <QDir> | ||
#include "mainwindow.h" | ||
#include <QTimer> | ||
#include <QFutureWatcher> | ||
#include <QPalette> | ||
#include <QMessageBox> | ||
#include <QFileDialog> | ||
|
||
#if QT_VERSION >= 0x050000 | ||
#include <QtConcurrent/QtConcurrentRun> | ||
#endif | ||
|
||
InstallFromSWG::InstallFromSWG(QWidget *parent) : | ||
QDialog(parent), | ||
ui(new Ui::InstallFromSWG) { | ||
ui->setupUi(this); | ||
|
||
cancelThreads = false; | ||
|
||
connect(©Watcher, SIGNAL(finished()), this, SLOT(copyFinished())); | ||
|
||
ui->progressBar->setValue(0); | ||
ui->progressBar->setMaximum(0); | ||
//connect(this, SIGNAL()) | ||
|
||
connect(this, SIGNAL(fileCopiedSignal(QString,bool)), this, SLOT(fileCopied(QString,bool))); | ||
} | ||
|
||
InstallFromSWG::~InstallFromSWG() { | ||
delete ui; | ||
} | ||
|
||
void InstallFromSWG::copyFinished() { | ||
int result = copyWatcher.result(); | ||
|
||
ui->progressBar->setValue(ui->progressBar->maximum()); | ||
|
||
if (result == 0) | ||
ui->label->setText("Installation finished."); | ||
else | ||
ui->label->setText("Installation failed."); | ||
|
||
qDebug() << "copy finished with result " << result; | ||
|
||
done(result); | ||
} | ||
|
||
void InstallFromSWG::closeEvent(QCloseEvent* event) { | ||
cancelThreads = true; | ||
|
||
if (copyWatcher.isRunning()) { | ||
copyWatcher.cancel(); | ||
copyWatcher.waitForFinished(); | ||
} | ||
|
||
QDialog::closeEvent(event); | ||
} | ||
|
||
int InstallFromSWG::copyFiles() { | ||
QVector<QPair<QString, qint64> > requiredFiles = MainWindow::getRequiredFiles(); | ||
|
||
for (int i = 0; i < requiredFiles.size() && !cancelThreads; ++i) { | ||
const QPair<QString, qint64> file = requiredFiles.at(i); | ||
|
||
//if (QDir(file)) | ||
|
||
if (file.first.contains("/")) { | ||
QString dir = emuFolder + "\\" + file.first.mid(0, file.first.lastIndexOf("/")); | ||
|
||
QDir(dir).mkpath("."); | ||
} | ||
|
||
bool result = QFile::copy(swgfolder + "\\" + file.first, emuFolder + "\\" + file.first); | ||
|
||
//bool result = true; | ||
//QTimer::singleShot(0, this, SLOT(fileCopied(file.first, result))); | ||
emit fileCopiedSignal(file.first, result); | ||
/* | ||
if (!result) | ||
return 1;*/ | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
void InstallFromSWG::fileCopied(const QString& file, bool success) { | ||
if (success) { | ||
ui->label->setText(file + " successfully installed"); | ||
|
||
ui->progressBar->setValue(ui->progressBar->value()+ 1); | ||
} else { | ||
//ui->label->setPalette(QPalette(Qt::red)); | ||
ui->label->setText("Unable to copy file: " + file); | ||
|
||
ui->progressBar->setValue(ui->progressBar->maximum()); | ||
} | ||
|
||
} | ||
|
||
int InstallFromSWG::checkSWGFolder() { | ||
QDir dir(swgfolder); | ||
|
||
if (!dir.exists()) | ||
return 1; | ||
|
||
QStringList filesToCheck; | ||
filesToCheck << "bottom.tre" << "data_animation_00.tre" << "data_texture_04.tre"; | ||
|
||
for (int i = 0; i < filesToCheck.size(); ++i) { | ||
if (!QFile(swgfolder + "\\" + filesToCheck.at(i)).exists()) | ||
return 2; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int InstallFromSWG::installFiles() { | ||
QSettings settings; | ||
|
||
QMessageBox::information(this, "SWGEmu", "Please choose a valid Star Wars Galaxies installation"); | ||
|
||
swgfolder = QFileDialog::getExistingDirectory(this, tr("Open Directory"), | ||
"/home", | ||
QFileDialog::ShowDirsOnly | ||
| QFileDialog::DontResolveSymlinks); | ||
|
||
int validFolder = checkSWGFolder(); | ||
|
||
if (validFolder != 0) { | ||
QMessageBox::warning(this, "Folder", "The folder you selected isnt a valid Star Wars Galaxies installation!"); | ||
|
||
return 1; | ||
} | ||
|
||
QMessageBox::information(this, "SWGEmu", "Please choose where you want to install SWGEmu"); | ||
|
||
emuFolder = QFileDialog::getExistingDirectory(this, tr("Open Directory"), | ||
"/home", | ||
QFileDialog::ShowDirsOnly | ||
| QFileDialog::DontResolveSymlinks); | ||
|
||
if (!QDir(emuFolder).exists()) { | ||
QMessageBox::warning(this, "Folder", "The swgemu folder you selected isnt a valid directory"); | ||
|
||
return 1; | ||
} | ||
|
||
QVector<QPair<QString, qint64> > requiredFiles = MainWindow::getRequiredFiles(); | ||
|
||
ui->progressBar->setValue(0); | ||
ui->progressBar->setMaximum(requiredFiles.size()); | ||
|
||
QFuture<int> future = QtConcurrent::run(this, &InstallFromSWG::copyFiles); | ||
copyWatcher.setFuture(future); | ||
|
||
return exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef INSTALLFROMSWG_H | ||
#define INSTALLFROMSWG_H | ||
|
||
#include <QDialog> | ||
#include <QString> | ||
#include <QFutureWatcher> | ||
|
||
namespace Ui { | ||
class InstallFromSWG; | ||
} | ||
|
||
class InstallFromSWG : public QDialog { | ||
Q_OBJECT | ||
|
||
public: | ||
explicit InstallFromSWG(QWidget *parent = 0); | ||
~InstallFromSWG(); | ||
|
||
public slots: | ||
int installFiles(); | ||
int checkSWGFolder(); | ||
int copyFiles(); | ||
void fileCopied(const QString& file, bool success); | ||
void copyFinished(); | ||
|
||
public: | ||
void closeEvent(QCloseEvent *event); | ||
QString getEmuFolder() { | ||
return emuFolder; | ||
} | ||
|
||
signals: | ||
void fileCopiedSignal(QString, bool); | ||
|
||
private: | ||
Ui::InstallFromSWG* ui; | ||
QFutureWatcher<int> copyWatcher; | ||
QString swgfolder; | ||
QString emuFolder; | ||
|
||
volatile bool cancelThreads; | ||
}; | ||
|
||
#endif // INSTALLFROMSWG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>InstallFromSWG</class> | ||
<widget class="QDialog" name="InstallFromSWG"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>320</width> | ||
<height>66</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Installation</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<item row="0" column="0"> | ||
<widget class="QLabel" name="label"> | ||
<property name="text"> | ||
<string>Installation Status</string> | ||
</property> | ||
<property name="alignment"> | ||
<set>Qt::AlignCenter</set> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QProgressBar" name="progressBar"> | ||
<property name="value"> | ||
<number>24</number> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters