mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-09-26 22:45:15 -04:00
Fixed openmw.cfg handling: file should not be cleared anymore
This commit is contained in:
parent
fb59112b74
commit
36d4287da4
@ -41,9 +41,36 @@ Wizard::MainWizard::MainWizard(QWidget *parent) :
|
|||||||
|
|
||||||
void Wizard::MainWizard::setupInstallations()
|
void Wizard::MainWizard::setupInstallations()
|
||||||
{
|
{
|
||||||
QString userPath(QFile::decodeName(mCfgMgr.getUserConfigPath().string().c_str()));
|
QString userPath(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()));
|
||||||
QString globalPath(QFile::decodeName(mCfgMgr.getGlobalPath().string().c_str()));
|
QString globalPath(QString::fromUtf8(mCfgMgr.getGlobalPath().string().c_str()));
|
||||||
|
QString message(tr("<html><head/><body><p><b>Could not open %1 for reading</b></p> \
|
||||||
|
<p>Please make sure you have the right permissions \
|
||||||
|
and try again.</p></body></html>"));
|
||||||
|
|
||||||
|
// 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;
|
QStringList paths;
|
||||||
paths.append(userPath + QLatin1String("openmw.cfg"));
|
paths.append(userPath + QLatin1String("openmw.cfg"));
|
||||||
paths.append(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.setWindowTitle(tr("Error opening OpenMW configuration file"));
|
||||||
msgBox.setIcon(QMessageBox::Critical);
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \
|
msgBox.setText(message.arg(file.fileName()));
|
||||||
Please make sure you have the right permissions \
|
|
||||||
and try again.<br>").arg(file.fileName()));
|
|
||||||
msgBox.exec();
|
|
||||||
return qApp->quit();
|
return qApp->quit();
|
||||||
}
|
}
|
||||||
QTextStream stream(&file);
|
QTextStream stream(&file);
|
||||||
@ -73,7 +98,7 @@ void Wizard::MainWizard::setupInstallations()
|
|||||||
file.close();
|
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()) {
|
foreach (const QString path, mGameSettings.getDataDirs()) {
|
||||||
|
|
||||||
if (findFiles(QLatin1String("Morrowind"), path))
|
if (findFiles(QLatin1String("Morrowind"), path))
|
||||||
@ -136,7 +161,24 @@ void Wizard::MainWizard::accept()
|
|||||||
|
|
||||||
void Wizard::MainWizard::writeSettings()
|
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("<html><head/><body><p><b>Could not create %1</b></p> \
|
||||||
|
<p>Please make sure you have the right permissions \
|
||||||
|
and try again.</p></body></html>").arg(userPath));
|
||||||
|
msgBox.exec();
|
||||||
|
return qApp->quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Game settings
|
||||||
QFile file(userPath + QLatin1String("openmw.cfg"));
|
QFile file(userPath + QLatin1String("openmw.cfg"));
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) {
|
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.setWindowTitle(tr("Error writing OpenMW configuration file"));
|
||||||
msgBox.setIcon(QMessageBox::Critical);
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
msgBox.setText(tr("<br><b>Could not open or create %0 for writing</b><br><br> \
|
msgBox.setText(tr("<html><head/><body><p><b>Could not open %1 for writing</b></p> \
|
||||||
Please make sure you have the right permissions \
|
<p>Please make sure you have the right permissions \
|
||||||
and try again.<br>").arg(file.fileName()));
|
and try again.</p></body></html>").arg(file.fileName()));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return qApp->quit();
|
return qApp->quit();
|
||||||
}
|
}
|
||||||
|
@ -656,7 +656,7 @@ bool Wizard::UnshieldWorker::extractFile(Unshield *unshield, const QString &outp
|
|||||||
path.append(prefix + QDir::separator());
|
path.append(prefix + QDir::separator());
|
||||||
|
|
||||||
if (directory >= 0)
|
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
|
// Ensure the path has the right separators
|
||||||
path.replace(QLatin1Char('\\'), QDir::separator());
|
path.replace(QLatin1Char('\\'), QDir::separator());
|
||||||
@ -667,7 +667,7 @@ bool Wizard::UnshieldWorker::extractFile(Unshield *unshield, const QString &outp
|
|||||||
dir.mkpath(path);
|
dir.mkpath(path);
|
||||||
|
|
||||||
QString fileName(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
|
// Calculate the percentage done
|
||||||
int progress = (((float) counter / (float) unshield_file_count(unshield)) * 100);
|
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))
|
if (getComponentDone(Wizard::Component_Tribunal))
|
||||||
progress = progress + 100;
|
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);
|
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) {
|
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);
|
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)
|
bool Wizard::UnshieldWorker::findFile(const QString &cabFile, const QString &fileName)
|
||||||
{
|
{
|
||||||
|
QByteArray array(cabFile.toUtf8());
|
||||||
|
|
||||||
Unshield *unshield;
|
Unshield *unshield;
|
||||||
unshield = unshield_open(cabFile.toLatin1().constData());
|
unshield = unshield_open(array.constData());
|
||||||
|
|
||||||
if (!unshield) {
|
if (!unshield) {
|
||||||
emit error(tr("Failed to open InstallShield Cabinet File."), tr("Opening %1 failed.").arg(cabFile));
|
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)
|
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;
|
qDebug() << "File is: " << current;
|
||||||
if (current == fileName)
|
if (current == fileName)
|
||||||
@ -723,8 +726,10 @@ bool Wizard::UnshieldWorker::extractCab(const QString &cabFile, const QString &o
|
|||||||
{
|
{
|
||||||
bool success;
|
bool success;
|
||||||
|
|
||||||
|
QByteArray array(cabFile.toUtf8());
|
||||||
|
|
||||||
Unshield *unshield;
|
Unshield *unshield;
|
||||||
unshield = unshield_open(cabFile.toLatin1().constData());
|
unshield = unshield_open(array.constData());
|
||||||
|
|
||||||
if (!unshield) {
|
if (!unshield) {
|
||||||
emit error(tr("Failed to open InstallShield Cabinet File."), tr("Opening %1 failed.").arg(cabFile));
|
emit error(tr("Failed to open InstallShield Cabinet File."), tr("Opening %1 failed.").arg(cabFile));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user