Skip to content

Commit

Permalink
[added] install from swg option
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAnswer committed Nov 13, 2013
1 parent 7512ae7 commit 1e0e5ba
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 8 deletions.
9 changes: 6 additions & 3 deletions SWGEmuLaunchpad.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ SOURCES += main.cpp\
configparser.cpp \
gameprocess.cpp \
windebugmonitor.cpp \
selfupdater.cpp
selfupdater.cpp \
installfromswg.cpp

HEADERS += mainwindow.h \
settings.h \
Expand All @@ -33,14 +34,16 @@ HEADERS += mainwindow.h \
gameprocess.h \
windebugmonitor.h \
selfupdater.h \
singleinstance.h
singleinstance.h \
installfromswg.h

FORMS += mainwindow.ui \
settings.ui \
loginservers.ui \
addloginserver.ui \
gameprocess.ui \
selfupdater.ui
selfupdater.ui \
installfromswg.ui

OTHER_FILES += \
logo_yellow.png \
Expand Down
160 changes: 160 additions & 0 deletions installfromswg.cpp
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(&copyWatcher, 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();
}
44 changes: 44 additions & 0 deletions installfromswg.h
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
38 changes: 38 additions & 0 deletions installfromswg.ui
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>
25 changes: 21 additions & 4 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "windebugmonitor.h"
#include "selfupdater.h"
#include <QCloseEvent>
#include "installfromswg.h"

#if QT_VERSION >= 0x050000
#include <QtConcurrent/QtConcurrentRun>
Expand All @@ -23,7 +24,7 @@ QString MainWindow::patchUrl = "http://www.launchpad2.net/SWGEmu/";
QString MainWindow::newsUrl = "http://www.swgemu.com/forums/index.php#bd";
QString MainWindow::gameExecutable = "SWGEmu.exe";
QString MainWindow::selfUpdateUrl = "http://launchpad2.net/setup.cfg";
const QString MainWindow::version = "0.11";
const QString MainWindow::version = "0.12";

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
Expand Down Expand Up @@ -74,6 +75,8 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
connect(ui->actionDelete_Profiles, SIGNAL(triggered()), this, SLOT(deleteProfiles()));
connect(this, SIGNAL(addFileToDownload(QString)), this, SLOT(addFileToDownloadSlot(QString)));
connect(ui->actionInstall_from_SWG, SIGNAL(triggered()), this, SLOT(installSWGEmu()));

ui->groupBox_browser->hide();

QTabBar* tabBar = ui->tabWidget->tabBar();
Expand Down Expand Up @@ -104,7 +107,7 @@ MainWindow::MainWindow(QWidget *parent) :
if (!swgFolder.isEmpty())
startLoadBasicCheck();
else
QMessageBox::warning(this, "Error", "Please set the swg folder in Settings->Options");
QMessageBox::warning(this, "Error", "Please set the swgemu folder in Settings->Options or install using Settings->Install From SWG");

requiredFilesNetworkManager.get(QNetworkRequest(QUrl(patchUrl + "required2.txt")));
}
Expand Down Expand Up @@ -616,7 +619,7 @@ void MainWindow::updateFullScanProgress(QString successFile, bool success) {
}
}

void MainWindow::startFullScan() {
void MainWindow::startFullScan(bool forceConfigRestore) {
requiredFilesCount = getRequiredFiles().size();
currentReadFiles = 0;

Expand All @@ -628,7 +631,7 @@ void MainWindow::startFullScan() {
return;
}

bool restoreConfigFiles = QMessageBox::question(this, "Config files", "Do you want to restore the config files too?") == QMessageBox::Yes;
bool restoreConfigFiles = forceConfigRestore ? true : QMessageBox::question(this, "Config files", "Do you want to restore the config files too?") == QMessageBox::Yes;

if (requiredFilesCount == 0 && !restoreConfigFiles)
return;
Expand Down Expand Up @@ -1296,3 +1299,17 @@ void MainWindow::closeTab(int index) {
//delete widget;
}
}

void MainWindow::installSWGEmu() {
InstallFromSWG installation(this);
int result = installation.installFiles();

if (result == 0) {
QSettings settingsVals;
settingsVals.setValue("swg_folder", installation.getEmuFolder());

settings->restoreFolder();

startFullScan(true);
}
}
4 changes: 3 additions & 1 deletion mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public slots:
void loadFinished();
//void fullScanFinished();
void startLoadBasicCheck();
void startFullScan();
void startFullScan(bool forceConfigRestore = false);
static QVector<QPair<QString, qint64> > getRequiredFiles();
void downloadFinished();
void downloadFileFinished(QNetworkReply *reply);
Expand Down Expand Up @@ -75,6 +75,8 @@ public slots:
int fullScanSingleThreaded(bool restoreConfigFiles);
void fullScanMultiThreaded(bool restoreConfigFiles);

void installSWGEmu();


signals:
void startDownload();
Expand Down
6 changes: 6 additions & 0 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ p, li { white-space: pre-wrap; }
</property>
<addaction name="actionFolders"/>
<addaction name="actionLogin_Servers"/>
<addaction name="actionInstall_from_SWG"/>
</widget>
<widget class="QMenu" name="menuAbout">
<property name="title">
Expand Down Expand Up @@ -486,6 +487,11 @@ p, li { white-space: pre-wrap; }
<string>Delete Profiles</string>
</property>
</action>
<action name="actionInstall_from_SWG">
<property name="text">
<string>Install from SWG</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down

0 comments on commit 1e0e5ba

Please sign in to comment.