diff --git a/apps/wizard/mainwizard.cpp b/apps/wizard/mainwizard.cpp index d9b2c3ba8..eb1e3b304 100644 --- a/apps/wizard/mainwizard.cpp +++ b/apps/wizard/mainwizard.cpp @@ -41,9 +41,36 @@ Wizard::MainWizard::MainWizard(QWidget *parent) : void Wizard::MainWizard::setupInstallations() { - QString userPath(QFile::decodeName(mCfgMgr.getUserConfigPath().string().c_str())); - QString globalPath(QFile::decodeName(mCfgMgr.getGlobalPath().string().c_str())); + QString userPath(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str())); + QString globalPath(QString::fromUtf8(mCfgMgr.getGlobalPath().string().c_str())); + QString message(tr("

Could not open %1 for reading

\ +

Please make sure you have the right permissions \ + and try again.

")); + + // Load the user config file first, separately + // So we can write it properly, uncontaminated + QString path(userPath + QLatin1String("openmw.cfg")); + QFile file(path); + + qDebug() << "Loading config file:" << qPrintable(path); + + if (file.exists()) { + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error opening OpenMW configuration file")); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(message.arg(file.fileName())); + msgBox.exec(); + return qApp->quit(); + } + QTextStream stream(&file); + stream.setCodec(QTextCodec::codecForName("UTF-8")); + + mGameSettings.readUserFile(stream); + } + // Now the rest QStringList paths; paths.append(userPath + QLatin1String("openmw.cfg")); paths.append(QLatin1String("openmw.cfg")); @@ -59,10 +86,8 @@ void Wizard::MainWizard::setupInstallations() msgBox.setWindowTitle(tr("Error opening OpenMW configuration file")); msgBox.setIcon(QMessageBox::Critical); msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(QObject::tr("
Could not open %0 for reading

\ - Please make sure you have the right permissions \ - and try again.
").arg(file.fileName())); - msgBox.exec(); + msgBox.setText(message.arg(file.fileName())); + return qApp->quit(); } QTextStream stream(&file); @@ -73,7 +98,7 @@ void Wizard::MainWizard::setupInstallations() file.close(); } - // Check if the paths actually contains a Morrowind installation + // Check if the paths actually contain a Morrowind installation foreach (const QString path, mGameSettings.getDataDirs()) { if (findFiles(QLatin1String("Morrowind"), path)) @@ -136,7 +161,24 @@ void Wizard::MainWizard::accept() void Wizard::MainWizard::writeSettings() { - QString userPath(QFile::decodeName(mCfgMgr.getUserConfigPath().string().c_str())); + QString userPath(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str())); + QDir dir(userPath); + + if (!dir.exists()) { + if (!dir.mkpath(userPath)) { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error creating OpenMW configuration directory")); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(tr("

Could not create %1

\ +

Please make sure you have the right permissions \ + and try again.

").arg(userPath)); + msgBox.exec(); + return qApp->quit(); + } + } + + // Game settings QFile file(userPath + QLatin1String("openmw.cfg")); if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) { @@ -145,9 +187,9 @@ void Wizard::MainWizard::writeSettings() msgBox.setWindowTitle(tr("Error writing OpenMW configuration file")); msgBox.setIcon(QMessageBox::Critical); msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not open or create %0 for writing

\ - Please make sure you have the right permissions \ - and try again.
").arg(file.fileName())); + msgBox.setText(tr("

Could not open %1 for writing

\ +

Please make sure you have the right permissions \ + and try again.

").arg(file.fileName())); msgBox.exec(); return qApp->quit(); } diff --git a/apps/wizard/unshield/unshieldworker.cpp b/apps/wizard/unshield/unshieldworker.cpp index 47d3c1be7..6a19673f3 100644 --- a/apps/wizard/unshield/unshieldworker.cpp +++ b/apps/wizard/unshield/unshieldworker.cpp @@ -656,7 +656,7 @@ bool Wizard::UnshieldWorker::extractFile(Unshield *unshield, const QString &outp path.append(prefix + QDir::separator()); if (directory >= 0) - path.append(QString::fromLatin1(unshield_directory_name(unshield, directory)) + QDir::separator()); + path.append(QString::fromUtf8(unshield_directory_name(unshield, directory)) + QDir::separator()); // Ensure the path has the right separators path.replace(QLatin1Char('\\'), QDir::separator()); @@ -667,7 +667,7 @@ bool Wizard::UnshieldWorker::extractFile(Unshield *unshield, const QString &outp dir.mkpath(path); QString fileName(path); - fileName.append(QString::fromLatin1(unshield_file_name(unshield, index))); + fileName.append(QString::fromUtf8(unshield_file_name(unshield, index))); // Calculate the percentage done int progress = (((float) counter / (float) unshield_file_count(unshield)) * 100); @@ -678,13 +678,14 @@ bool Wizard::UnshieldWorker::extractFile(Unshield *unshield, const QString &outp if (getComponentDone(Wizard::Component_Tribunal)) progress = progress + 100; - emit textChanged(tr("Extracting: %1").arg(QString::fromLatin1(unshield_file_name(unshield, index)))); + emit textChanged(tr("Extracting: %1").arg(QString::fromUtf8(unshield_file_name(unshield, index)))); emit progressChanged(progress); - success = unshield_file_save(unshield, index, fileName.toLatin1().constData()); + QByteArray array(fileName.toUtf8()); + success = unshield_file_save(unshield, index, array.constData()); if (!success) { - emit error(tr("Failed to extract %1.").arg(QString::fromLatin1(unshield_file_name(unshield, index))), tr("Complete path: %1.").arg(fileName)); + emit error(tr("Failed to extract %1.").arg(QString::fromUtf8(unshield_file_name(unshield, index))), tr("Complete path: %1.").arg(fileName)); dir.remove(fileName); } @@ -693,8 +694,10 @@ bool Wizard::UnshieldWorker::extractFile(Unshield *unshield, const QString &outp bool Wizard::UnshieldWorker::findFile(const QString &cabFile, const QString &fileName) { + QByteArray array(cabFile.toUtf8()); + Unshield *unshield; - unshield = unshield_open(cabFile.toLatin1().constData()); + unshield = unshield_open(array.constData()); if (!unshield) { emit error(tr("Failed to open InstallShield Cabinet File."), tr("Opening %1 failed.").arg(cabFile)); @@ -707,7 +710,7 @@ bool Wizard::UnshieldWorker::findFile(const QString &cabFile, const QString &fil for (size_t j=group->first_file; j<=group->last_file; ++j) { - QString current(QString::fromLatin1(unshield_file_name(unshield, j))); + QString current(QString::fromUtf8(unshield_file_name(unshield, j))); qDebug() << "File is: " << current; if (current == fileName) @@ -723,8 +726,10 @@ bool Wizard::UnshieldWorker::extractCab(const QString &cabFile, const QString &o { bool success; + QByteArray array(cabFile.toUtf8()); + Unshield *unshield; - unshield = unshield_open(cabFile.toLatin1().constData()); + unshield = unshield_open(array.constData()); if (!unshield) { emit error(tr("Failed to open InstallShield Cabinet File."), tr("Opening %1 failed.").arg(cabFile));