mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-30 21:32:42 +00:00
Made install functions use file finding methods and improved error handling
This commit is contained in:
parent
ef16b46148
commit
254fe0a424
@ -22,7 +22,7 @@ void Wizard::ConclusionPage::initializePage()
|
|||||||
if (!mWizard->mError)
|
if (!mWizard->mError)
|
||||||
{
|
{
|
||||||
if ((field(QLatin1String("installation.new")).toBool() == true)
|
if ((field(QLatin1String("installation.new")).toBool() == true)
|
||||||
| (field(QLatin1String("installation.import-settings")).toBool() == true))
|
|| (field(QLatin1String("installation.import-settings")).toBool() == true))
|
||||||
{
|
{
|
||||||
qDebug() << "IMPORT SETTINGS";
|
qDebug() << "IMPORT SETTINGS";
|
||||||
mWizard->runSettingsImporter();
|
mWizard->runSettingsImporter();
|
||||||
|
@ -44,8 +44,6 @@ void Wizard::InstallationPage::initializePage()
|
|||||||
installProgressBar->setMaximum(installProgressBar->maximum() + 100);
|
installProgressBar->setMaximum(installProgressBar->maximum() + 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle when cancel is clicked
|
|
||||||
|
|
||||||
startInstallation();
|
startInstallation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,21 +52,21 @@ void Wizard::InstallationPage::startInstallation()
|
|||||||
QStringList components(field(QLatin1String("installation.components")).toStringList());
|
QStringList components(field(QLatin1String("installation.components")).toStringList());
|
||||||
QString path(field(QLatin1String("installation.path")).toString());
|
QString path(field(QLatin1String("installation.path")).toString());
|
||||||
|
|
||||||
QThread *thread = new QThread();
|
mThread = new QThread();
|
||||||
mUnshield = new UnshieldWorker();
|
mUnshield = new UnshieldWorker();
|
||||||
mUnshield->moveToThread(thread);
|
mUnshield->moveToThread(mThread);
|
||||||
|
|
||||||
connect(thread, SIGNAL(started()),
|
connect(mThread, SIGNAL(started()),
|
||||||
mUnshield, SLOT(extract()));
|
mUnshield, SLOT(extract()));
|
||||||
|
|
||||||
connect(mUnshield, SIGNAL(finished()),
|
connect(mUnshield, SIGNAL(finished()),
|
||||||
thread, SLOT(quit()));
|
mThread, SLOT(quit()));
|
||||||
|
|
||||||
connect(mUnshield, SIGNAL(finished()),
|
connect(mUnshield, SIGNAL(finished()),
|
||||||
mUnshield, SLOT(deleteLater()));
|
mUnshield, SLOT(deleteLater()));
|
||||||
|
|
||||||
connect(mUnshield, SIGNAL(finished()),
|
connect(mUnshield, SIGNAL(finished()),
|
||||||
thread, SLOT(deleteLater()));
|
mThread, SLOT(deleteLater()));;
|
||||||
|
|
||||||
connect(mUnshield, SIGNAL(finished()),
|
connect(mUnshield, SIGNAL(finished()),
|
||||||
this, SLOT(installationFinished()), Qt::QueuedConnection);
|
this, SLOT(installationFinished()), Qt::QueuedConnection);
|
||||||
@ -129,7 +127,7 @@ void Wizard::InstallationPage::startInstallation()
|
|||||||
mUnshield->setIniCodec(QTextCodec::codecForName("windows-1252"));
|
mUnshield->setIniCodec(QTextCodec::codecForName("windows-1252"));
|
||||||
}
|
}
|
||||||
|
|
||||||
thread->start();
|
mThread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wizard::InstallationPage::showFileDialog(Wizard::Component component)
|
void Wizard::InstallationPage::showFileDialog(Wizard::Component component)
|
||||||
@ -148,23 +146,15 @@ void Wizard::InstallationPage::showFileDialog(Wizard::Component component)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// QString fileName = QFileDialog::getOpenFileName(
|
|
||||||
// this,
|
|
||||||
// tr("Select %1 installation file").arg(name),
|
|
||||||
// QDir::rootPath(),
|
|
||||||
// tr("InstallShield header files (*.hdr)"));
|
|
||||||
|
|
||||||
|
|
||||||
QString path = QFileDialog::getExistingDirectory(this,
|
QString path = QFileDialog::getExistingDirectory(this,
|
||||||
tr("Select %1 installation media").arg(name),
|
tr("Select %1 installation media").arg(name),
|
||||||
QDir::rootPath());
|
QDir::rootPath());
|
||||||
|
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
qDebug() << "Cancel was clicked!";
|
|
||||||
|
|
||||||
logTextEdit->appendHtml(tr("<p><br/><span style=\"color:red;\"> \
|
logTextEdit->appendHtml(tr("<p><br/><span style=\"color:red;\"> \
|
||||||
<b>Error: The installation was aborted by the user</b></p>"));
|
<b>Error: The installation was aborted by the user</b></p>"));
|
||||||
mWizard->mError = true;
|
mWizard->mError = true;
|
||||||
|
|
||||||
emit completeChanged();
|
emit completeChanged();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -174,8 +164,6 @@ void Wizard::InstallationPage::showFileDialog(Wizard::Component component)
|
|||||||
|
|
||||||
void Wizard::InstallationPage::installationFinished()
|
void Wizard::InstallationPage::installationFinished()
|
||||||
{
|
{
|
||||||
qDebug() << "finished!";
|
|
||||||
|
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
msgBox.setWindowTitle(tr("Installation finished"));
|
msgBox.setWindowTitle(tr("Installation finished"));
|
||||||
msgBox.setIcon(QMessageBox::Information);
|
msgBox.setIcon(QMessageBox::Information);
|
||||||
@ -186,13 +174,10 @@ void Wizard::InstallationPage::installationFinished()
|
|||||||
|
|
||||||
mFinished = true;
|
mFinished = true;
|
||||||
emit completeChanged();
|
emit completeChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wizard::InstallationPage::installationError(const QString &text, const QString &details)
|
void Wizard::InstallationPage::installationError(const QString &text, const QString &details)
|
||||||
{
|
{
|
||||||
qDebug() << "error: " << text;
|
|
||||||
|
|
||||||
installProgressLabel->setText(tr("Installation failed!"));
|
installProgressLabel->setText(tr("Installation failed!"));
|
||||||
|
|
||||||
logTextEdit->appendHtml(tr("<p><br/><span style=\"color:red;\"> \
|
logTextEdit->appendHtml(tr("<p><br/><span style=\"color:red;\"> \
|
||||||
@ -213,7 +198,6 @@ void Wizard::InstallationPage::installationError(const QString &text, const QStr
|
|||||||
|
|
||||||
mWizard->mError = true;
|
mWizard->mError = true;
|
||||||
emit completeChanged();
|
emit completeChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wizard::InstallationPage::isComplete() const
|
bool Wizard::InstallationPage::isComplete() const
|
||||||
|
@ -143,7 +143,8 @@ void Wizard::MainWizard::runSettingsImporter()
|
|||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
|
|
||||||
// Import plugin selection?
|
// Import plugin selection?
|
||||||
if (field(QLatin1String("installation.import-addons")).toBool() == true)
|
if (field(QLatin1String("installation.new")).toBool() == true
|
||||||
|
|| field(QLatin1String("installation.import-addons")).toBool() == true)
|
||||||
arguments.append(QLatin1String("--game-files"));
|
arguments.append(QLatin1String("--game-files"));
|
||||||
|
|
||||||
arguments.append(QLatin1String("--encoding"));
|
arguments.append(QLatin1String("--encoding"));
|
||||||
|
@ -162,8 +162,8 @@ void Wizard::UnshieldWorker::setupSettings()
|
|||||||
QFile file(getIniPath());
|
QFile file(getIniPath());
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
qDebug() << "Error opening .ini file!";
|
emit error(tr("Failed to open Morrowind configuration file!"),
|
||||||
emit error(tr("Failed to open Morrowind configuration file!"), tr("Opening %1 failed: %2.").arg(getIniPath(), file.errorString()));
|
tr("Opening %1 failed: %2.").arg(getIniPath(), file.errorString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +181,6 @@ void Wizard::UnshieldWorker::writeSettings()
|
|||||||
QFile file(getIniPath());
|
QFile file(getIniPath());
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
||||||
qDebug() << "Error opening .ini file!";
|
|
||||||
emit error(tr("Failed to open Morrowind configuration file!"),
|
emit error(tr("Failed to open Morrowind configuration file!"),
|
||||||
tr("Opening %1 failed: %2.").arg(getIniPath(), file.errorString()));
|
tr("Opening %1 failed: %2.").arg(getIniPath(), file.errorString()));
|
||||||
return;
|
return;
|
||||||
@ -198,7 +197,7 @@ void Wizard::UnshieldWorker::writeSettings()
|
|||||||
|
|
||||||
bool Wizard::UnshieldWorker::removeDirectory(const QString &dirName)
|
bool Wizard::UnshieldWorker::removeDirectory(const QString &dirName)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = false;
|
||||||
QDir dir(dirName);
|
QDir dir(dirName);
|
||||||
|
|
||||||
if (dir.exists(dirName))
|
if (dir.exists(dirName))
|
||||||
@ -229,38 +228,42 @@ bool Wizard::UnshieldWorker::copyFile(const QString &source, const QString &dest
|
|||||||
|
|
||||||
QFileInfo info(destination);
|
QFileInfo info(destination);
|
||||||
|
|
||||||
if (info.exists())
|
if (info.exists()) {
|
||||||
dir.remove(info.absoluteFilePath());
|
if (!dir.remove(info.absoluteFilePath()))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (file.copy(source, destination)) {
|
if (file.copy(source, destination)) {
|
||||||
if (!keepSource) {
|
if (!keepSource) {
|
||||||
return file.remove(source);
|
if (!file.remove(source))
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "copy failed! " << file.errorString();
|
return false;
|
||||||
emit error(tr("Failed to copy file!"), tr("Copying %1 to %2 failed: %3.").arg(source, destination, file.errorString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wizard::UnshieldWorker::copyDirectory(const QString &source, const QString &destination, bool keepSource)
|
bool Wizard::UnshieldWorker::copyDirectory(const QString &source, const QString &destination, bool keepSource)
|
||||||
{
|
{
|
||||||
QDir sourceDir(source);
|
QDir sourceDir(source);
|
||||||
QDir destDir(destination);
|
QDir destDir(destination);
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
if (!destDir.exists()) {
|
if (!destDir.exists()) {
|
||||||
sourceDir.mkpath(destination);
|
if (!sourceDir.mkpath(destination)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
destDir.refresh();
|
destDir.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!destDir.exists())
|
if (!destDir.exists())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool result = true;
|
|
||||||
|
|
||||||
QFileInfoList list(sourceDir.entryInfoList(QDir::NoDotAndDotDot |
|
QFileInfoList list(sourceDir.entryInfoList(QDir::NoDotAndDotDot |
|
||||||
QDir::System | QDir::Hidden |
|
QDir::System | QDir::Hidden |
|
||||||
QDir::AllDirs | QDir::Files, QDir::DirsFirst));
|
QDir::AllDirs | QDir::Files, QDir::DirsFirst));
|
||||||
@ -269,13 +272,15 @@ bool Wizard::UnshieldWorker::copyDirectory(const QString &source, const QString
|
|||||||
QString relativePath(info.absoluteFilePath());
|
QString relativePath(info.absoluteFilePath());
|
||||||
relativePath.remove(source);
|
relativePath.remove(source);
|
||||||
|
|
||||||
|
QString destinationPath(destDir.absolutePath() + relativePath);
|
||||||
|
|
||||||
if (info.isSymLink())
|
if (info.isSymLink())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (info.isDir()) {
|
if (info.isDir()) {
|
||||||
result = moveDirectory(info.absoluteFilePath(), destDir.absolutePath() + relativePath);
|
result = copyDirectory(info.absoluteFilePath(), destinationPath);
|
||||||
} else {
|
} else {
|
||||||
result = moveFile(info.absoluteFilePath(), destDir.absolutePath() + relativePath);
|
result = copyFile(info.absoluteFilePath(), destinationPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,80 +290,56 @@ bool Wizard::UnshieldWorker::copyDirectory(const QString &source, const QString
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wizard::UnshieldWorker::moveFile(const QString &source, const QString &destination)
|
bool Wizard::UnshieldWorker::installFile(const QString &fileName, const QString &path, Qt::MatchFlags flags, bool keepSource)
|
||||||
{
|
{
|
||||||
return copyFile(source, destination, false);
|
return installFiles(fileName, path, flags, true, keepSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wizard::UnshieldWorker::moveDirectory(const QString &source, const QString &destination)
|
bool Wizard::UnshieldWorker::installFiles(const QString &fileName, const QString &path, Qt::MatchFlags flags, bool keepSource, bool single)
|
||||||
{
|
{
|
||||||
return copyDirectory(source, destination, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Wizard::UnshieldWorker::installFile(const QString &fileName, const QString &path)
|
|
||||||
{
|
|
||||||
qDebug() << "Attempting to find file: " << fileName << " in: " << path;
|
|
||||||
|
|
||||||
bool result = true;
|
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
|
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QFileInfoList list(dir.entryInfoList(QDir::NoDotAndDotDot |
|
QStringList files(findFiles(fileName, path, flags));
|
||||||
QDir::System | QDir::Hidden |
|
|
||||||
QDir::AllDirs | QDir::Files, QDir::DirsFirst));
|
|
||||||
foreach(const QFileInfo &info, list) {
|
|
||||||
if (info.isDir()) {
|
|
||||||
result = installFile(fileName, info.absoluteFilePath());
|
|
||||||
} else {
|
|
||||||
if (info.fileName() == fileName) {
|
|
||||||
qDebug() << "File found at: " << info.absoluteFilePath();
|
|
||||||
|
|
||||||
|
foreach (const QString &file, files) {
|
||||||
|
QFileInfo info(file);
|
||||||
emit textChanged(tr("Installing: %1").arg(info.fileName()));
|
emit textChanged(tr("Installing: %1").arg(info.fileName()));
|
||||||
return moveFile(info.absoluteFilePath(), getPath() + QDir::separator() + info.fileName());
|
|
||||||
}
|
if (single) {
|
||||||
|
return copyFile(info.absoluteFilePath(), getPath() + QDir::separator() + info.fileName(), keepSource);
|
||||||
|
} else {
|
||||||
|
if (!copyFile(info.absoluteFilePath(), getPath() + QDir::separator() + info.fileName(), keepSource))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wizard::UnshieldWorker::installDirectory(const QString &dirName, const QString &path, bool recursive)
|
bool Wizard::UnshieldWorker::installDirectories(const QString &dirName, const QString &path, bool recursive, bool keepSource)
|
||||||
{
|
{
|
||||||
qDebug() << "Attempting to find: " << dirName << " in: " << path;
|
|
||||||
bool result = true;
|
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
|
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QFileInfoList list(dir.entryInfoList(QDir::NoDotAndDotDot |
|
QStringList directories(findDirectories(dirName, path, recursive));
|
||||||
QDir::System | QDir::Hidden |
|
|
||||||
QDir::AllDirs));
|
|
||||||
foreach(const QFileInfo &info, list) {
|
|
||||||
if (info.isSymLink())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (info.isDir()) {
|
foreach (const QString &dir, directories) {
|
||||||
if (info.fileName() == dirName) {
|
QFileInfo info(dir);
|
||||||
qDebug() << "Directory found at: " << info.absoluteFilePath();
|
|
||||||
emit textChanged(tr("Installing: %1 directory").arg(info.fileName()));
|
emit textChanged(tr("Installing: %1 directory").arg(info.fileName()));
|
||||||
return copyDirectory(info.absoluteFilePath(), getPath() + QDir::separator() + info.fileName());
|
if (!copyDirectory(info.absoluteFilePath(), getPath() + QDir::separator() + info.fileName(), keepSource))
|
||||||
} else {
|
return false;
|
||||||
if (recursive)
|
|
||||||
result = installDirectory(dirName, info.absoluteFilePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wizard::UnshieldWorker::extract()
|
void Wizard::UnshieldWorker::extract()
|
||||||
{
|
{
|
||||||
qDebug() << "extract!";
|
|
||||||
|
|
||||||
if (getInstallComponent(Wizard::Component_Morrowind))
|
if (getInstallComponent(Wizard::Component_Morrowind))
|
||||||
{
|
{
|
||||||
if (!getComponentDone(Wizard::Component_Morrowind))
|
if (!getComponentDone(Wizard::Component_Morrowind))
|
||||||
@ -423,8 +404,6 @@ void Wizard::UnshieldWorker::extract()
|
|||||||
emit textChanged(tr("Installation finished!"));
|
emit textChanged(tr("Installation finished!"));
|
||||||
emit progressChanged(total);
|
emit progressChanged(total);
|
||||||
emit finished();
|
emit finished();
|
||||||
|
|
||||||
qDebug() << "installation finished!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wizard::UnshieldWorker::setupComponent(Component component)
|
bool Wizard::UnshieldWorker::setupComponent(Component component)
|
||||||
@ -466,12 +445,28 @@ bool Wizard::UnshieldWorker::setupComponent(Component component)
|
|||||||
QStringList list(findFiles(QLatin1String("data1.hdr"), disk.absolutePath()));
|
QStringList list(findFiles(QLatin1String("data1.hdr"), disk.absolutePath()));
|
||||||
|
|
||||||
foreach (const QString &file, list) {
|
foreach (const QString &file, list) {
|
||||||
qDebug() << "current cab file is: " << file;
|
|
||||||
|
if (component == Wizard::Component_Morrowind)
|
||||||
|
{
|
||||||
|
bool morrowindFound = findInCab(file, QLatin1String("Morrowind.bsa"));
|
||||||
|
bool tribunalFound = findInCab(file, QLatin1String("Tribunal.bsa"));
|
||||||
|
bool bloodmoonFound = findInCab(file, QLatin1String("Bloodmoon.bsa"));
|
||||||
|
|
||||||
|
if (morrowindFound) {
|
||||||
|
// Check if we have correct archive, other archives have Morrowind.bsa too
|
||||||
|
if ((tribunalFound && bloodmoonFound)
|
||||||
|
|| (!tribunalFound && !bloodmoonFound)) {
|
||||||
|
cabFile = file;
|
||||||
|
found = true; // We have a GoTY disk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (findInCab(file, name + QLatin1String(".bsa"))) {
|
if (findInCab(file, name + QLatin1String(".bsa"))) {
|
||||||
cabFile = file;
|
cabFile = file;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
QReadLocker readLock(&mLock);
|
QReadLocker readLock(&mLock);
|
||||||
@ -484,7 +479,6 @@ bool Wizard::UnshieldWorker::setupComponent(Component component)
|
|||||||
setComponentDone(component, true);
|
setComponentDone(component, true);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Erorr installing " << name;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,9 +506,6 @@ bool Wizard::UnshieldWorker::installComponent(Component component, const QString
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Install " << name << " from " << path;
|
|
||||||
|
|
||||||
|
|
||||||
emit textChanged(tr("Installing %1").arg(name));
|
emit textChanged(tr("Installing %1").arg(name));
|
||||||
|
|
||||||
QFileInfo info(path);
|
QFileInfo info(path);
|
||||||
@ -569,19 +560,34 @@ bool Wizard::UnshieldWorker::installComponent(Component component, const QString
|
|||||||
<< QLatin1String("Video");
|
<< QLatin1String("Video");
|
||||||
|
|
||||||
foreach (const QString &dir, directories) {
|
foreach (const QString &dir, directories) {
|
||||||
installDirectory(dir, temp.absolutePath());
|
if (!installDirectories(dir, temp.absolutePath())) {
|
||||||
|
emit error(tr("Could not install directory!"),
|
||||||
|
tr("Installing %1 to %2 failed.").arg(dir, temp.absolutePath()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install directories from disk
|
// Install directories from disk
|
||||||
foreach (const QString &dir, directories) {
|
foreach (const QString &dir, directories) {
|
||||||
qDebug() << "\n\nDISK DIRS!";
|
if (!installDirectories(dir, info.absolutePath(), false, true)) {
|
||||||
installDirectory(dir, info.absolutePath(), false);
|
emit error(tr("Could not install directory!"),
|
||||||
|
tr("Installing %1 to %2 failed.").arg(dir, info.absolutePath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo datafiles(info.absolutePath() + QDir::separator() + QLatin1String("Data Files"));
|
}
|
||||||
if (datafiles.exists()) {
|
|
||||||
emit textChanged(tr("Installing: Data Files directory"));
|
// Install translation files
|
||||||
copyDirectory(datafiles.absoluteFilePath(), getPath());
|
QStringList extensions;
|
||||||
|
extensions << QLatin1String(".cel")
|
||||||
|
<< QLatin1String(".top")
|
||||||
|
<< QLatin1String(".mrk");
|
||||||
|
|
||||||
|
foreach (const QString &extension, extensions) {
|
||||||
|
if (!installFiles(extension, info.absolutePath(), Qt::MatchEndsWith)) {
|
||||||
|
emit error(tr("Could not install translation file!"),
|
||||||
|
tr("Failed to install *%1 files.").arg(extension));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component == Wizard::Component_Morrowind)
|
if (component == Wizard::Component_Morrowind)
|
||||||
@ -592,14 +598,16 @@ bool Wizard::UnshieldWorker::installComponent(Component component, const QString
|
|||||||
|
|
||||||
foreach (const QString &file, files) {
|
foreach (const QString &file, files) {
|
||||||
if (!installFile(file, temp.absolutePath())) {
|
if (!installFile(file, temp.absolutePath())) {
|
||||||
emit error(tr("Could not find Morrowind data file!"), tr("Failed to find %1.").arg(file));
|
emit error(tr("Could not install Morrowind data file!"),
|
||||||
|
tr("Failed to install %1.").arg(file));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy Morrowind configuration file
|
// Copy Morrowind configuration file
|
||||||
if (!installFile(QLatin1String("Morrowind.ini"), temp.absolutePath())) {
|
if (!installFile(QLatin1String("Morrowind.ini"), temp.absolutePath())) {
|
||||||
emit error(tr("Could not find Morrowind configuration file!"), tr("Failed to find %1.").arg(QLatin1String("Morrowind.ini")));
|
emit error(tr("Could not install Morrowind configuration file!"),
|
||||||
|
tr("Failed to install %1.").arg(QLatin1String("Morrowind.ini")));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,21 +619,25 @@ bool Wizard::UnshieldWorker::installComponent(Component component, const QString
|
|||||||
if (component == Wizard::Component_Tribunal)
|
if (component == Wizard::Component_Tribunal)
|
||||||
{
|
{
|
||||||
QFileInfo sounds(temp.absoluteFilePath(QLatin1String("Sounds")));
|
QFileInfo sounds(temp.absoluteFilePath(QLatin1String("Sounds")));
|
||||||
|
QString dest(getPath() + QDir::separator() + QLatin1String("Sound"));
|
||||||
|
|
||||||
if (sounds.exists()) {
|
if (sounds.exists()) {
|
||||||
emit textChanged(tr("Installing: Sound directory"));
|
emit textChanged(tr("Installing: Sound directory"));
|
||||||
copyDirectory(sounds.absoluteFilePath(), getPath() + QDir::separator() + QLatin1String("Sound"));
|
if (!copyDirectory(sounds.absoluteFilePath(), dest)) {
|
||||||
|
emit error(tr("Could not install directory!"),
|
||||||
|
tr("Installing %1 to %2 failed.").arg(sounds.absoluteFilePath(), dest));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList files;
|
QStringList files;
|
||||||
files << QLatin1String("Tribunal.esm")
|
files << QLatin1String("Tribunal.esm")
|
||||||
<< QLatin1String("Tribunal.bsa")
|
<< QLatin1String("Tribunal.bsa");
|
||||||
<< QLatin1String("Morrowind.esm")
|
|
||||||
<< QLatin1String("Morrowind.bsa");
|
|
||||||
|
|
||||||
foreach (const QString &file, files) {
|
foreach (const QString &file, files) {
|
||||||
if (!installFile(file, temp.absolutePath())) {
|
if (!installFile(file, temp.absolutePath())) {
|
||||||
emit error(tr("Could not find Tribunal data file!"), tr("Failed to find %1.").arg(file));
|
emit error(tr("Could not find Tribunal data file!"),
|
||||||
|
tr("Failed to find %1.").arg(file));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -637,20 +649,20 @@ bool Wizard::UnshieldWorker::installComponent(Component component, const QString
|
|||||||
|
|
||||||
if (original.exists()) {
|
if (original.exists()) {
|
||||||
if (!installFile(QLatin1String("Tribunal.esm"), temp.absolutePath())) {
|
if (!installFile(QLatin1String("Tribunal.esm"), temp.absolutePath())) {
|
||||||
emit error(tr("Could not find Tribunal patch file!"), tr("Failed to find %1.").arg(QLatin1String("Tribunal.esm")));
|
emit error(tr("Could not find Tribunal patch file!"),
|
||||||
|
tr("Failed to find %1.").arg(QLatin1String("Tribunal.esm")));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList files;
|
QStringList files;
|
||||||
files << QLatin1String("Bloodmoon.esm")
|
files << QLatin1String("Bloodmoon.esm")
|
||||||
<< QLatin1String("Bloodmoon.bsa")
|
<< QLatin1String("Bloodmoon.bsa");
|
||||||
<< QLatin1String("Morrowind.esm")
|
|
||||||
<< QLatin1String("Morrowind.bsa");
|
|
||||||
|
|
||||||
foreach (const QString &file, files) {
|
foreach (const QString &file, files) {
|
||||||
if (!installFile(file, temp.absolutePath())) {
|
if (!installFile(file, temp.absolutePath())) {
|
||||||
emit error(tr("Could not find Bloodmoon data file!"), tr("Failed to find %1.").arg(file));
|
emit error(tr("Could not find Bloodmoon data file!"),
|
||||||
|
tr("Failed to find %1.").arg(file));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -665,6 +677,21 @@ bool Wizard::UnshieldWorker::installComponent(Component component, const QString
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finally, install Data Files directories from temp and disk
|
||||||
|
QStringList datafiles(findDirectories(QLatin1String("Data Files"), temp.absolutePath()));
|
||||||
|
datafiles.append(findDirectories(QLatin1String("Data Files"), info.absolutePath()));
|
||||||
|
|
||||||
|
foreach (const QString &dir, datafiles) {
|
||||||
|
QFileInfo info(dir);
|
||||||
|
emit textChanged(tr("Installing: %1 directory").arg(info.fileName()));
|
||||||
|
|
||||||
|
if (!copyDirectory(info.absoluteFilePath(), getPath())) {
|
||||||
|
emit error(tr("Could not install directory!"),
|
||||||
|
tr("Installing %1 to %2 failed.").arg(info.absoluteFilePath(), getPath()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit textChanged(tr("%1 installation finished!").arg(name));
|
emit textChanged(tr("%1 installation finished!").arg(name));
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -718,15 +745,15 @@ bool Wizard::UnshieldWorker::extractFile(Unshield *unshield, const QString &dest
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Wizard::UnshieldWorker::findFile(const QString &fileName, const QString &path, int depth)
|
QString Wizard::UnshieldWorker::findFile(const QString &fileName, const QString &path)
|
||||||
{
|
{
|
||||||
return findFiles(fileName, path, depth).first();
|
return findFiles(fileName, path).first();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Wizard::UnshieldWorker::findFiles(const QString &fileName, const QString &path, int depth)
|
QStringList Wizard::UnshieldWorker::findFiles(const QString &fileName, const QString &path, int depth, bool recursive,
|
||||||
|
bool directories, Qt::MatchFlags flags)
|
||||||
{
|
{
|
||||||
qDebug() << "Searching path: " << path << " for: " << fileName;
|
static const int MAXIMUM_DEPTH = 10;
|
||||||
static const int MAXIMUM_DEPTH = 5;
|
|
||||||
|
|
||||||
if (depth >= MAXIMUM_DEPTH) {
|
if (depth >= MAXIMUM_DEPTH) {
|
||||||
qWarning("Maximum directory depth limit reached.");
|
qWarning("Maximum directory depth limit reached.");
|
||||||
@ -748,11 +775,31 @@ QStringList Wizard::UnshieldWorker::findFiles(const QString &fileName, const QSt
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (info.isDir()) {
|
if (info.isDir()) {
|
||||||
result.append(findFiles(fileName, info.absoluteFilePath(), depth + 1));
|
if (directories)
|
||||||
} else {
|
{
|
||||||
if (info.fileName() == fileName) {
|
if (info.fileName() == fileName) {
|
||||||
qDebug() << "File found at: " << info.absoluteFilePath();
|
|
||||||
result.append(info.absoluteFilePath());
|
result.append(info.absoluteFilePath());
|
||||||
|
} else {
|
||||||
|
if (recursive)
|
||||||
|
result.append(findFiles(fileName, info.absoluteFilePath(), depth + 1, recursive, true));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (recursive)
|
||||||
|
result.append(findFiles(fileName, info.absoluteFilePath(), depth + 1));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (directories)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (flags) {
|
||||||
|
case Qt::MatchExactly:
|
||||||
|
if (info.fileName() == fileName)
|
||||||
|
result.append(info.absoluteFilePath());
|
||||||
|
break;
|
||||||
|
case Qt::MatchEndsWith:
|
||||||
|
if (info.fileName().endsWith(fileName))
|
||||||
|
result.append(info.absoluteFilePath());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -760,6 +807,11 @@ QStringList Wizard::UnshieldWorker::findFiles(const QString &fileName, const QSt
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList Wizard::UnshieldWorker::findDirectories(const QString &dirName, const QString &path, bool recursive)
|
||||||
|
{
|
||||||
|
return findFiles(dirName, path, 0, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
bool Wizard::UnshieldWorker::findInCab(const QString &cabFile, const QString &fileName)
|
bool Wizard::UnshieldWorker::findInCab(const QString &cabFile, const QString &fileName)
|
||||||
{
|
{
|
||||||
QByteArray array(cabFile.toUtf8());
|
QByteArray array(cabFile.toUtf8());
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
#include <QReadWriteLock>
|
#include <QReadWriteLock>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
#include <libunshield.h>
|
#include <libunshield.h>
|
||||||
|
|
||||||
@ -31,7 +32,6 @@ namespace Wizard
|
|||||||
|
|
||||||
void setInstallComponent(Wizard::Component component, bool install);
|
void setInstallComponent(Wizard::Component component, bool install);
|
||||||
|
|
||||||
// void setComponentPath(Wizard::Component component, const QString &path);
|
|
||||||
void setDiskPath(const QString &path);
|
void setDiskPath(const QString &path);
|
||||||
|
|
||||||
void setPath(const QString &path);
|
void setPath(const QString &path);
|
||||||
@ -50,7 +50,6 @@ namespace Wizard
|
|||||||
|
|
||||||
bool getInstallComponent(Component component);
|
bool getInstallComponent(Component component);
|
||||||
|
|
||||||
//QString getComponentPath(Component component);
|
|
||||||
QString getDiskPath();
|
QString getDiskPath();
|
||||||
|
|
||||||
void setComponentDone(Component component, bool done = true);
|
void setComponentDone(Component component, bool done = true);
|
||||||
@ -61,18 +60,25 @@ namespace Wizard
|
|||||||
bool copyFile(const QString &source, const QString &destination, bool keepSource = true);
|
bool copyFile(const QString &source, const QString &destination, bool keepSource = true);
|
||||||
bool copyDirectory(const QString &source, const QString &destination, bool keepSource = true);
|
bool copyDirectory(const QString &source, const QString &destination, bool keepSource = true);
|
||||||
|
|
||||||
bool moveFile(const QString &source, const QString &destination);
|
|
||||||
bool moveDirectory(const QString &source, const QString &destination);
|
|
||||||
|
|
||||||
bool extractCab(const QString &cabFile, const QString &destination);
|
bool extractCab(const QString &cabFile, const QString &destination);
|
||||||
bool extractFile(Unshield *unshield, const QString &destination, const QString &prefix, int index, int counter);
|
bool extractFile(Unshield *unshield, const QString &destination, const QString &prefix, int index, int counter);
|
||||||
bool findInCab(const QString &cabFile, const QString &fileName);
|
bool findInCab(const QString &cabFile, const QString &fileName);
|
||||||
|
|
||||||
QString findFile(const QString &fileName, const QString &path, int depth = 0);
|
QString findFile(const QString &fileName, const QString &path);
|
||||||
QStringList findFiles(const QString &fileName, const QString &path, int depth = 0);
|
|
||||||
|
|
||||||
bool installFile(const QString &fileName, const QString &path);
|
QStringList findFiles(const QString &fileName, const QString &path, int depth = 0, bool recursive = true,
|
||||||
bool installDirectory(const QString &dirName, const QString &path, bool recursive = true);
|
bool directories = false, Qt::MatchFlags flags = Qt::MatchExactly);
|
||||||
|
|
||||||
|
QStringList findDirectories(const QString &dirName, const QString &path, bool recursive = true);
|
||||||
|
|
||||||
|
bool installFile(const QString &fileName, const QString &path, Qt::MatchFlags flags = Qt::MatchExactly,
|
||||||
|
bool keepSource = false);
|
||||||
|
|
||||||
|
bool installFiles(const QString &fileName, const QString &path, Qt::MatchFlags flags = Qt::MatchExactly,
|
||||||
|
bool keepSource = false, bool single = false);
|
||||||
|
|
||||||
|
bool installDirectories(const QString &dirName, const QString &path,
|
||||||
|
bool recursive = true, bool keepSource = false);
|
||||||
|
|
||||||
bool installComponent(Component component, const QString &path);
|
bool installComponent(Component component, const QString &path);
|
||||||
bool setupComponent(Component component);
|
bool setupComponent(Component component);
|
||||||
@ -111,7 +117,6 @@ namespace Wizard
|
|||||||
void error(const QString &text, const QString &details);
|
void error(const QString &text, const QString &details);
|
||||||
void progressChanged(int progress);
|
void progressChanged(int progress);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user