WIP: Working on the installation of addons

loadfix
pvdk 11 years ago
parent 691e007524
commit 0f7f3391f7

@ -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())
dir.remove(info.absoluteFilePath());
if (file.copy(source, destination)) { 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,127 +179,217 @@ 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;
} }
if (!keepSource)
return result && removeDirectory(sourceDir.absolutePath()); return result && removeDirectory(sourceDir.absolutePath());
return result;
} }
void Wizard::UnshieldWorker::extract() bool Wizard::UnshieldWorker::moveFile(const QString &source, const QString &destination)
{ {
emit textChanged(QLatin1String("Starting installation")); return copyFile(source, destination, false);
emit textChanged(QLatin1String("Installation target: ") + mPath); }
QStringList components; bool Wizard::UnshieldWorker::moveDirectory(const QString &source, const QString &destination)
if (mInstallMorrowind) {
components << QLatin1String("Morrowind"); return copyDirectory(source, destination, false);
}
if (mInstallTribunal) void Wizard::UnshieldWorker::installDirectories(const QString &source)
components << QLatin1String("Tribunal"); {
QDir dir(source);
if (mInstallBloodmoon) if (!dir.exists())
components << QLatin1String("Bloodmoon"); return;
emit textChanged(QLatin1String("Components: ") + components.join(QLatin1String(", "))); 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;
emit textChanged(QLatin1String("Updating Morrowind.ini: ") + mIniPath); 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());
}
}
}
//emit progressChanged(45); void Wizard::UnshieldWorker::extract()
{
emit textChanged(QLatin1String("Starting installation"));
emit textChanged(QLatin1String("Installation target: ") + mPath);
/// QString diskPath("/mnt/cdrom/");
// bfs::path outputDataFilesDir = mOutputPath; QDir disk(diskPath);
// 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"));
moveFile(info.absoluteFilePath(), mPath + QDir::separator() + QLatin1String("Morrowind.ini"));
} else {
qDebug() << "Could not find ini file!";
}
if (directories.contains(info.fileName())) mMorrowindDone = true;
qDebug() << "found " << info.fileName();
// copyDirectory(info.absoluteFilePath(), mPath); }
temp.setPath(tempPath);
disk.setPath(diskPath);
if (mInstallTribunal)
{
emit textChanged(QLatin1String("Installing Tribunal\n"));
if (!temp.mkdir(QLatin1String("tribunal"))) {
qDebug() << "Can't make dir";
return;
}
if (!temp.cd(QLatin1String("tribunal"))) {
qDebug() << "Can't cd to dir";
return;
}
if (!disk.cd(QLatin1String("Tribunal")))
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());
mTribunalDone = true;
} }
// if(!mMorrowindDone && mMorrowindPath.string().length() > 0) temp.setPath(tempPath);
// { disk.setPath(diskPath);
// mMorrowindDone = true;
if (mInstallBloodmoon)
{
emit textChanged(QLatin1String("Installing Bloodmoon\n"));
if (!temp.mkdir(QLatin1String("bloodmoon"))) {
qDebug() << "Can't make dir";
return;
}
// bfs::path mwExtractPath = extractPath / "morrowind"; if (!temp.cd(QLatin1String("bloodmoon"))) {
// extract_cab(mMorrowindPath, mwExtractPath, true); qDebug() << "Can't cd to dir";
return;
}
// bfs::path dFilesDir = findFile(mwExtractPath, "morrowind.esm").parent_path(); if (!disk.cd(QLatin1String("Bloodmoon")))
qDebug() << "Show file selector";
// installToPath(dFilesDir, outputDataFilesDir); if (!disk.exists(QLatin1String("data1.hdr"))) {
qDebug() << "No data found!";
return;
}
// install_dfiles_outside(mwExtractPath, outputDataFilesDir); // Extract the installation files
extractCab(disk.absoluteFilePath(QLatin1String("data1.hdr")), temp.absolutePath());
// // Videos are often kept uncompressed on the cd if (!moveDirectory(temp.absoluteFilePath(QLatin1String("Data Files")), mPath))
// bfs::path videosPath = findFile(mMorrowindPath.parent_path(), "video", false); qDebug() << "failed!";
// if(videosPath.string() != "")
// {
// emit signalGUI(QString("Installing Videos..."));
// installToPath(videosPath, outputDataFilesDir / "Video", true);
// }
// bfs::path cdDFiles = findFile(mMorrowindPath.parent_path(), "data files", false); // Install files outside of cab archives
// if(cdDFiles.string() != "") installDirectories(disk.absolutePath());
// {
// emit signalGUI(QString("Installing Uncompressed Data files from CD..."));
// installToPath(cdDFiles, outputDataFilesDir, true);
// }
mBloodmoonDone = true;
}
// bfs::rename(findFile(mwExtractPath, "morrowind.ini"), outputDataFilesDir / "Morrowind.ini");
// mTribunalDone = contains(outputDataFilesDir, "tribunal.esm"); int total = 0;
// mBloodmoonDone = contains(outputDataFilesDir, "bloodmoon.esm");
// } if (mInstallMorrowind)
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…
Cancel
Save