diff --git a/SWGEmuLaunchpad.pro b/SWGEmuLaunchpad.pro index d66e085..77cefe7 100644 --- a/SWGEmuLaunchpad.pro +++ b/SWGEmuLaunchpad.pro @@ -21,7 +21,8 @@ SOURCES += main.cpp\ configparser.cpp \ gameprocess.cpp \ windebugmonitor.cpp \ - selfupdater.cpp + selfupdater.cpp \ + installfromswg.cpp HEADERS += mainwindow.h \ settings.h \ @@ -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 \ diff --git a/installfromswg.cpp b/installfromswg.cpp new file mode 100644 index 0000000..db41185 --- /dev/null +++ b/installfromswg.cpp @@ -0,0 +1,160 @@ +#include "installfromswg.h" +#include "ui_installfromswg.h" +#include +#include +#include "mainwindow.h" +#include +#include +#include +#include +#include + +#if QT_VERSION >= 0x050000 +#include +#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 > requiredFiles = MainWindow::getRequiredFiles(); + + for (int i = 0; i < requiredFiles.size() && !cancelThreads; ++i) { + const QPair 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 > requiredFiles = MainWindow::getRequiredFiles(); + + ui->progressBar->setValue(0); + ui->progressBar->setMaximum(requiredFiles.size()); + + QFuture future = QtConcurrent::run(this, &InstallFromSWG::copyFiles); + copyWatcher.setFuture(future); + + return exec(); +} diff --git a/installfromswg.h b/installfromswg.h new file mode 100644 index 0000000..2a42839 --- /dev/null +++ b/installfromswg.h @@ -0,0 +1,44 @@ +#ifndef INSTALLFROMSWG_H +#define INSTALLFROMSWG_H + +#include +#include +#include + +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 copyWatcher; + QString swgfolder; + QString emuFolder; + + volatile bool cancelThreads; +}; + +#endif // INSTALLFROMSWG_H diff --git a/installfromswg.ui b/installfromswg.ui new file mode 100644 index 0000000..b30f12a --- /dev/null +++ b/installfromswg.ui @@ -0,0 +1,38 @@ + + + InstallFromSWG + + + + 0 + 0 + 320 + 66 + + + + Installation + + + + + + Installation Status + + + Qt::AlignCenter + + + + + + + 24 + + + + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index 5ea6293..13e9954 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -14,6 +14,7 @@ #include "windebugmonitor.h" #include "selfupdater.h" #include +#include "installfromswg.h" #if QT_VERSION >= 0x050000 #include @@ -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), @@ -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(); @@ -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"))); } @@ -616,7 +619,7 @@ void MainWindow::updateFullScanProgress(QString successFile, bool success) { } } -void MainWindow::startFullScan() { +void MainWindow::startFullScan(bool forceConfigRestore) { requiredFilesCount = getRequiredFiles().size(); currentReadFiles = 0; @@ -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; @@ -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); + } +} diff --git a/mainwindow.h b/mainwindow.h index a0dff83..ecebbb7 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -42,7 +42,7 @@ public slots: void loadFinished(); //void fullScanFinished(); void startLoadBasicCheck(); - void startFullScan(); + void startFullScan(bool forceConfigRestore = false); static QVector > getRequiredFiles(); void downloadFinished(); void downloadFileFinished(QNetworkReply *reply); @@ -75,6 +75,8 @@ public slots: int fullScanSingleThreaded(bool restoreConfigFiles); void fullScanMultiThreaded(bool restoreConfigFiles); + void installSWGEmu(); + signals: void startDownload(); diff --git a/mainwindow.ui b/mainwindow.ui index 5ceb3f9..63c2b57 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -402,6 +402,7 @@ p, li { white-space: pre-wrap; } + @@ -486,6 +487,11 @@ p, li { white-space: pre-wrap; } Delete Profiles + + + Install from SWG + +