mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-27 19:11:34 +00:00
WIP: Working on the installation of addons
This commit is contained in:
parent
691e007524
commit
0f7f3391f7
5 changed files with 220 additions and 94 deletions
|
@ -45,8 +45,6 @@ void Wizard::InstallationPage::initializePage()
|
||||||
installProgressBar->setMaximum(installProgressBar->maximum() + 100);
|
installProgressBar->setMaximum(installProgressBar->maximum() + 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
installProgressBar->setValue(100);
|
|
||||||
|
|
||||||
startInstallation();
|
startInstallation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +73,9 @@ void Wizard::InstallationPage::startInstallation()
|
||||||
connect(unshield, SIGNAL(finished()),
|
connect(unshield, SIGNAL(finished()),
|
||||||
this, SLOT(installationFinished()));
|
this, SLOT(installationFinished()));
|
||||||
|
|
||||||
|
connect(unshield, SIGNAL(error(QString)),
|
||||||
|
this, SLOT(installationError(QString)));
|
||||||
|
|
||||||
connect(unshield, SIGNAL(textChanged(QString)),
|
connect(unshield, SIGNAL(textChanged(QString)),
|
||||||
installProgressLabel, SLOT(setText(QString)));
|
installProgressLabel, SLOT(setText(QString)));
|
||||||
|
|
||||||
|
@ -135,6 +136,12 @@ void Wizard::InstallationPage::installationFinished()
|
||||||
qDebug() << "finished!";
|
qDebug() << "finished!";
|
||||||
mFinished = true;
|
mFinished = true;
|
||||||
emit completeChanged();
|
emit completeChanged();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wizard::InstallationPage::installationError(const QString &text)
|
||||||
|
{
|
||||||
|
qDebug() << "error: " << text;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wizard::InstallationPage::isComplete() const
|
bool Wizard::InstallationPage::isComplete() const
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace Wizard
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void installationFinished();
|
void installationFinished();
|
||||||
|
void installationError(const QString &text);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initializePage();
|
void initializePage();
|
||||||
|
|
|
@ -29,6 +29,10 @@ Wizard::UnshieldWorker::UnshieldWorker(QObject *parent) :
|
||||||
mInstallMorrowind = false;
|
mInstallMorrowind = false;
|
||||||
mInstallTribunal = false;
|
mInstallTribunal = false;
|
||||||
mInstallBloodmoon = false;
|
mInstallBloodmoon = false;
|
||||||
|
|
||||||
|
mMorrowindDone = false;
|
||||||
|
mTribunalDone = false;
|
||||||
|
mBloodmoonDone = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Wizard::UnshieldWorker::~UnshieldWorker()
|
Wizard::UnshieldWorker::~UnshieldWorker()
|
||||||
|
@ -119,25 +123,30 @@ bool Wizard::UnshieldWorker::removeDirectory(const QString &dirName)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wizard::UnshieldWorker::moveFile(const QString &source, const QString &destination)
|
bool Wizard::UnshieldWorker::copyFile(const QString &source, const QString &destination, bool keepSource)
|
||||||
{
|
{
|
||||||
QDir dir;
|
QDir dir;
|
||||||
QFile file;
|
QFile file;
|
||||||
|
|
||||||
if (dir.rename(source, destination)) {
|
QFileInfo info(destination);
|
||||||
return true;
|
|
||||||
} else {
|
if (info.exists())
|
||||||
if (file.copy(source, destination)) {
|
dir.remove(info.absoluteFilePath());
|
||||||
|
|
||||||
|
if (file.copy(source, destination)) {
|
||||||
|
if (!keepSource) {
|
||||||
return file.remove(source);
|
return file.remove(source);
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "copy failed! " << file.errorString();
|
return true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "copy failed! " << file.errorString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wizard::UnshieldWorker::moveDirectory(const QString &source, const QString &destination)
|
bool Wizard::UnshieldWorker::copyDirectory(const QString &source, const QString &destination, bool keepSource)
|
||||||
{
|
{
|
||||||
QDir sourceDir(source);
|
QDir sourceDir(source);
|
||||||
QDir destDir(destination);
|
QDir destDir(destination);
|
||||||
|
@ -170,12 +179,51 @@ bool Wizard::UnshieldWorker::moveDirectory(const QString &source, const QString
|
||||||
|
|
||||||
result = moveFile(info.absoluteFilePath(), destDir.absolutePath() + relativePath);
|
result = moveFile(info.absoluteFilePath(), destDir.absolutePath() + relativePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (!result)
|
|
||||||
// return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result && removeDirectory(sourceDir.absolutePath());
|
if (!keepSource)
|
||||||
|
return result && removeDirectory(sourceDir.absolutePath());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Wizard::UnshieldWorker::moveFile(const QString &source, const QString &destination)
|
||||||
|
{
|
||||||
|
return copyFile(source, destination, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Wizard::UnshieldWorker::moveDirectory(const QString &source, const QString &destination)
|
||||||
|
{
|
||||||
|
return copyDirectory(source, destination, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wizard::UnshieldWorker::installDirectories(const QString &source)
|
||||||
|
{
|
||||||
|
QDir dir(source);
|
||||||
|
|
||||||
|
if (!dir.exists())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QStringList directories;
|
||||||
|
directories << QLatin1String("Fonts")
|
||||||
|
<< QLatin1String("Music")
|
||||||
|
<< QLatin1String("Sound")
|
||||||
|
<< QLatin1String("Splash")
|
||||||
|
<< QLatin1String("Video");
|
||||||
|
|
||||||
|
QFileInfoList list(dir.entryInfoList(QDir::NoDotAndDotDot |
|
||||||
|
QDir::System | QDir::Hidden |
|
||||||
|
QDir::AllDirs));
|
||||||
|
foreach(QFileInfo info, list) {
|
||||||
|
if (info.isSymLink())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (directories.contains(info.fileName())) {
|
||||||
|
qDebug() << "found " << info.fileName();
|
||||||
|
emit textChanged(tr("Extracting: %1 directory").arg(info.fileName()));
|
||||||
|
copyDirectory(info.absoluteFilePath(), mPath + QDir::separator() + info.fileName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wizard::UnshieldWorker::extract()
|
void Wizard::UnshieldWorker::extract()
|
||||||
|
@ -183,114 +231,165 @@ void Wizard::UnshieldWorker::extract()
|
||||||
emit textChanged(QLatin1String("Starting installation"));
|
emit textChanged(QLatin1String("Starting installation"));
|
||||||
emit textChanged(QLatin1String("Installation target: ") + mPath);
|
emit textChanged(QLatin1String("Installation target: ") + mPath);
|
||||||
|
|
||||||
QStringList components;
|
QString diskPath("/mnt/cdrom/");
|
||||||
if (mInstallMorrowind)
|
QDir disk(diskPath);
|
||||||
components << QLatin1String("Morrowind");
|
|
||||||
|
|
||||||
if (mInstallTribunal)
|
|
||||||
components << QLatin1String("Tribunal");
|
|
||||||
|
|
||||||
if (mInstallBloodmoon)
|
|
||||||
components << QLatin1String("Bloodmoon");
|
|
||||||
|
|
||||||
emit textChanged(QLatin1String("Components: ") + components.join(QLatin1String(", ")));
|
|
||||||
|
|
||||||
emit textChanged(QLatin1String("Updating Morrowind.ini: ") + mIniPath);
|
|
||||||
|
|
||||||
//emit progressChanged(45);
|
|
||||||
|
|
||||||
///
|
|
||||||
// bfs::path outputDataFilesDir = mOutputPath;
|
|
||||||
// outputDataFilesDir /= "Data Files";
|
|
||||||
// bfs::path extractPath = mOutputPath;
|
|
||||||
// extractPath /= "extract-temp";
|
|
||||||
|
|
||||||
// Create temporary extract directory
|
// Create temporary extract directory
|
||||||
// TODO: Use QTemporaryDir in Qt 5.0
|
// TODO: Use QTemporaryDir in Qt 5.0
|
||||||
QString tempPath(mPath + QLatin1String("/extract-temp"));
|
QString tempPath(mPath + QDir::separator() + QLatin1String("extract-temp"));
|
||||||
QDir dir;
|
QDir temp;
|
||||||
dir.mkpath(tempPath);
|
|
||||||
|
// Make sure the temporary folder is empty
|
||||||
|
removeDirectory(tempPath);
|
||||||
|
|
||||||
|
if (!temp.mkpath(tempPath)) {
|
||||||
|
qDebug() << "Can't make path";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp.setPath(tempPath);
|
||||||
|
disk.setPath(diskPath);
|
||||||
|
|
||||||
if (mInstallMorrowind)
|
if (mInstallMorrowind)
|
||||||
{
|
{
|
||||||
QString morrowindTempPath(tempPath + QLatin1String("/morrowind"));
|
emit textChanged(QLatin1String("Installing Morrowind\n"));
|
||||||
QString morrowindCab(QLatin1String("/mnt/cdrom/data1.hdr"));
|
|
||||||
|
|
||||||
//extractCab(morrowindCab, morrowindTempPath);
|
if (!temp.mkdir(QLatin1String("morrowind"))) {
|
||||||
|
qDebug() << "Can't make dir";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!temp.cd(QLatin1String("morrowind"))) {
|
||||||
|
qDebug() << "Can't cd to dir";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!disk.exists(QLatin1String("data1.hdr"))) {
|
||||||
|
qDebug() << "No data found!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the installation files
|
||||||
|
extractCab(disk.absoluteFilePath(QLatin1String("data1.hdr")), temp.absolutePath());
|
||||||
|
|
||||||
// TODO: Throw error;
|
// TODO: Throw error;
|
||||||
// Move the files from the temporary path to the destination folder
|
// Move the files from the temporary path to the destination folder
|
||||||
|
|
||||||
//qDebug() << "rename: " << morrowindTempPath << " to: " << mPath;
|
//qDebug() << "rename: " << morrowindTempPath << " to: " << mPath;
|
||||||
morrowindTempPath.append(QDir::separator() + QLatin1String("Data Files"));
|
if (!moveDirectory(temp.absoluteFilePath(QLatin1String("Data Files")), mPath))
|
||||||
// if (!moveDirectory(morrowindTempPath, mPath))
|
qDebug() << "failed!";
|
||||||
// qDebug() << "failed!";
|
|
||||||
|
|
||||||
QDir sourceDir(QLatin1String("/mnt/cdrom/"));
|
// Install files outside of cab archives
|
||||||
QStringList directories;
|
qDebug() << temp.absolutePath() << disk.absolutePath();
|
||||||
directories << QLatin1String("Fonts")
|
installDirectories(disk.absolutePath());
|
||||||
<< QLatin1String("Music")
|
|
||||||
<< QLatin1String("Sound")
|
|
||||||
<< QLatin1String("Splash")
|
|
||||||
<< QLatin1String("Video");
|
|
||||||
|
|
||||||
QFileInfoList list(sourceDir.entryInfoList(QDir::NoDotAndDotDot |
|
// Copy Morrowind configuration file
|
||||||
QDir::System | QDir::Hidden |
|
QString iniPath(temp.absoluteFilePath(QLatin1String("App Executables")));
|
||||||
QDir::AllDirs));
|
iniPath.append(QDir::separator() + QLatin1String("Morrowind.ini"));
|
||||||
|
|
||||||
|
QFileInfo info(iniPath);
|
||||||
|
|
||||||
foreach(QFileInfo info, list) {
|
qDebug() << info.absoluteFilePath() << mPath;
|
||||||
if (info.isSymLink())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
qDebug() << "not found " << info.fileName();
|
if (info.exists()) {
|
||||||
|
emit textChanged(tr("Extracting: Morrowind.ini"));
|
||||||
if (directories.contains(info.fileName()))
|
moveFile(info.absoluteFilePath(), mPath + QDir::separator() + QLatin1String("Morrowind.ini"));
|
||||||
qDebug() << "found " << info.fileName();
|
} else {
|
||||||
// copyDirectory(info.absoluteFilePath(), mPath);
|
qDebug() << "Could not find ini file!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mMorrowindDone = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(!mMorrowindDone && mMorrowindPath.string().length() > 0)
|
temp.setPath(tempPath);
|
||||||
// {
|
disk.setPath(diskPath);
|
||||||
// mMorrowindDone = true;
|
|
||||||
|
|
||||||
// bfs::path mwExtractPath = extractPath / "morrowind";
|
if (mInstallTribunal)
|
||||||
// extract_cab(mMorrowindPath, mwExtractPath, true);
|
{
|
||||||
|
emit textChanged(QLatin1String("Installing Tribunal\n"));
|
||||||
|
|
||||||
// bfs::path dFilesDir = findFile(mwExtractPath, "morrowind.esm").parent_path();
|
if (!temp.mkdir(QLatin1String("tribunal"))) {
|
||||||
|
qDebug() << "Can't make dir";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// installToPath(dFilesDir, outputDataFilesDir);
|
if (!temp.cd(QLatin1String("tribunal"))) {
|
||||||
|
qDebug() << "Can't cd to dir";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// install_dfiles_outside(mwExtractPath, outputDataFilesDir);
|
if (!disk.cd(QLatin1String("Tribunal")))
|
||||||
|
qDebug() << "Show file selector";
|
||||||
|
|
||||||
// // Videos are often kept uncompressed on the cd
|
if (!disk.exists(QLatin1String("data1.hdr"))) {
|
||||||
// bfs::path videosPath = findFile(mMorrowindPath.parent_path(), "video", false);
|
qDebug() << "No data found!";
|
||||||
// if(videosPath.string() != "")
|
return;
|
||||||
// {
|
}
|
||||||
// emit signalGUI(QString("Installing Videos..."));
|
|
||||||
// installToPath(videosPath, outputDataFilesDir / "Video", true);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// bfs::path cdDFiles = findFile(mMorrowindPath.parent_path(), "data files", false);
|
// Extract the installation files
|
||||||
// if(cdDFiles.string() != "")
|
extractCab(disk.absoluteFilePath(QLatin1String("data1.hdr")), temp.absolutePath());
|
||||||
// {
|
|
||||||
// emit signalGUI(QString("Installing Uncompressed Data files from CD..."));
|
if (!moveDirectory(temp.absoluteFilePath(QLatin1String("Data Files")), mPath))
|
||||||
// installToPath(cdDFiles, outputDataFilesDir, true);
|
qDebug() << "failed!";
|
||||||
// }
|
|
||||||
|
// Install files outside of cab archives
|
||||||
|
installDirectories(disk.absolutePath());
|
||||||
|
|
||||||
|
mTribunalDone = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp.setPath(tempPath);
|
||||||
|
disk.setPath(diskPath);
|
||||||
|
|
||||||
|
if (mInstallBloodmoon)
|
||||||
|
{
|
||||||
|
emit textChanged(QLatin1String("Installing Bloodmoon\n"));
|
||||||
|
|
||||||
|
if (!temp.mkdir(QLatin1String("bloodmoon"))) {
|
||||||
|
qDebug() << "Can't make dir";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!temp.cd(QLatin1String("bloodmoon"))) {
|
||||||
|
qDebug() << "Can't cd to dir";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!disk.cd(QLatin1String("Bloodmoon")))
|
||||||
|
qDebug() << "Show file selector";
|
||||||
|
|
||||||
|
if (!disk.exists(QLatin1String("data1.hdr"))) {
|
||||||
|
qDebug() << "No data found!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the installation files
|
||||||
|
extractCab(disk.absoluteFilePath(QLatin1String("data1.hdr")), temp.absolutePath());
|
||||||
|
|
||||||
|
if (!moveDirectory(temp.absoluteFilePath(QLatin1String("Data Files")), mPath))
|
||||||
|
qDebug() << "failed!";
|
||||||
|
|
||||||
|
// Install files outside of cab archives
|
||||||
|
installDirectories(disk.absolutePath());
|
||||||
|
|
||||||
|
mBloodmoonDone = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// bfs::rename(findFile(mwExtractPath, "morrowind.ini"), outputDataFilesDir / "Morrowind.ini");
|
int total = 0;
|
||||||
|
|
||||||
// mTribunalDone = contains(outputDataFilesDir, "tribunal.esm");
|
if (mInstallMorrowind)
|
||||||
// mBloodmoonDone = contains(outputDataFilesDir, "bloodmoon.esm");
|
total = 100;
|
||||||
|
|
||||||
// }
|
if (mInstallTribunal)
|
||||||
|
total = total + 100;
|
||||||
|
|
||||||
|
if (mInstallBloodmoon)
|
||||||
|
total = total + 100;
|
||||||
|
|
||||||
|
emit textChanged(tr("Installation finished!"));
|
||||||
///
|
emit progressChanged(total);
|
||||||
emit finished();
|
emit finished();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -322,17 +421,25 @@ bool Wizard::UnshieldWorker::extractFile(Unshield *unshield, const QString &outp
|
||||||
fileName.append(QString::fromLatin1(unshield_file_name(unshield, index)));
|
fileName.append(QString::fromLatin1(unshield_file_name(unshield, index)));
|
||||||
|
|
||||||
// Calculate the percentage done
|
// Calculate the percentage done
|
||||||
int progress = qCeil(((float) counter / (float) unshield_file_count(unshield)) * 100);
|
int progress = qFloor(((float) counter / (float) unshield_file_count(unshield)) * 100);
|
||||||
|
|
||||||
|
if (mMorrowindDone)
|
||||||
|
progress = progress + 100;
|
||||||
|
|
||||||
|
if (mTribunalDone)
|
||||||
|
progress = progress + 100;
|
||||||
|
|
||||||
qDebug() << progress << counter << unshield_file_count(unshield);
|
qDebug() << progress << counter << unshield_file_count(unshield);
|
||||||
|
|
||||||
emit textChanged(QLatin1String("Extracting: ") + QString::fromLatin1(unshield_file_name(unshield, index)));
|
emit textChanged(tr("Extracting: %1").arg(QString::fromLatin1(unshield_file_name(unshield, index))));
|
||||||
emit progressChanged(progress);
|
emit progressChanged(progress);
|
||||||
|
|
||||||
success = unshield_file_save(unshield, index, fileName.toLatin1().constData());
|
success = unshield_file_save(unshield, index, fileName.toLatin1().constData());
|
||||||
|
|
||||||
if (!success)
|
if (!success) {
|
||||||
|
emit error(tr("Failed to extract %1").arg(fileName));
|
||||||
dir.remove(fileName);
|
dir.remove(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@ namespace Wizard
|
||||||
|
|
||||||
bool removeDirectory(const QString &dirName);
|
bool removeDirectory(const QString &dirName);
|
||||||
|
|
||||||
|
bool copyFile(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 moveFile(const QString &source, const QString &destination);
|
||||||
bool moveDirectory(const QString &source, const QString &destination);
|
bool moveDirectory(const QString &source, const QString &destination);
|
||||||
|
|
||||||
|
@ -39,11 +42,17 @@ namespace Wizard
|
||||||
void extractCab(const QString &cabFile, const QString &outputDir);
|
void extractCab(const QString &cabFile, const QString &outputDir);
|
||||||
bool extractFile(Unshield *unshield, const QString &outputDir, const QString &prefix, int index, int counter);
|
bool extractFile(Unshield *unshield, const QString &outputDir, const QString &prefix, int index, int counter);
|
||||||
|
|
||||||
|
void installDirectories(const QString &source);
|
||||||
|
|
||||||
|
|
||||||
bool mInstallMorrowind;
|
bool mInstallMorrowind;
|
||||||
bool mInstallTribunal;
|
bool mInstallTribunal;
|
||||||
bool mInstallBloodmoon;
|
bool mInstallBloodmoon;
|
||||||
|
|
||||||
|
bool mMorrowindDone;
|
||||||
|
bool mTribunalDone;
|
||||||
|
bool mBloodmoonDone;
|
||||||
|
|
||||||
QString mPath;
|
QString mPath;
|
||||||
QString mIniPath;
|
QString mIniPath;
|
||||||
|
|
||||||
|
@ -58,6 +67,8 @@ namespace Wizard
|
||||||
signals:
|
signals:
|
||||||
void finished();
|
void finished();
|
||||||
void textChanged(const QString &text);
|
void textChanged(const QString &text);
|
||||||
|
void logTextChanged(const QString &text);
|
||||||
|
|
||||||
void error(const QString &text);
|
void error(const QString &text);
|
||||||
void progressChanged(int progress);
|
void progressChanged(int progress);
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>516</width>
|
<width>514</width>
|
||||||
<height>421</height>
|
<height>419</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QProgressBar" name="installProgressBar">
|
<widget class="QProgressBar" name="installProgressBar">
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>24</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Reference in a new issue