1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-28 19:21:04 +00:00

Added dedicated functions for conversions between QString and std::filesystem::path.

This commit is contained in:
Project579 2022-08-19 22:33:51 +00:00
parent c226b35f1f
commit ca14fc00dc
16 changed files with 164 additions and 88 deletions

View File

@ -19,13 +19,15 @@
#include <components/config/gamesettings.hpp> #include <components/config/gamesettings.hpp>
#include <components/config/launchersettings.hpp> #include <components/config/launchersettings.hpp>
#include <components/settings/settings.hpp>
#include <components/bsa/compressedbsafile.hpp> #include <components/bsa/compressedbsafile.hpp>
#include <components/files/qtconversion.hpp>
#include <components/misc/strings/conversion.hpp>
#include <components/navmeshtool/protocol.hpp> #include <components/navmeshtool/protocol.hpp>
#include <components/settings/settings.hpp>
#include <components/vfs/bsaarchive.hpp> #include <components/vfs/bsaarchive.hpp>
#include "utils/textinputdialog.hpp"
#include "utils/profilescombobox.hpp" #include "utils/profilescombobox.hpp"
#include "utils/textinputdialog.hpp"
#include "ui_directorypicker.h" #include "ui_directorypicker.h"
@ -232,7 +234,7 @@ void Launcher::DataFilesPage::populateFileViews(const QString& contentModelName)
const auto& globalDataDir = mGameSettings.getGlobalDataDir(); const auto& globalDataDir = mGameSettings.getGlobalDataDir();
if (!globalDataDir.empty()) if (!globalDataDir.empty())
directories.insert(0, QString::fromStdU32String(globalDataDir.u32string())); directories.insert(0, Files::pathToQString(globalDataDir));
// normalize user supplied directories: resolve symlink, convert to native separator, make absolute // normalize user supplied directories: resolve symlink, convert to native separator, make absolute
for (auto& currentDir : directories) for (auto& currentDir : directories)
@ -264,7 +266,8 @@ void Launcher::DataFilesPage::populateFileViews(const QString& contentModelName)
} }
// deactivate data-local and global data directory: they are always included // deactivate data-local and global data directory: they are always included
if (currentDir == mDataLocal || std::filesystem::path(currentDir.toStdU32String()) == globalDataDir) const auto tmp = currentDir.toUtf8();
if (currentDir == mDataLocal || std::filesystem::path(Misc::StringUtils::stringToU8String(tmp)) == globalDataDir)
{ {
auto flags = item->flags(); auto flags = item->flags();
item->setFlags(flags & ~(Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled|Qt::ItemIsEnabled)); item->setFlags(flags & ~(Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled|Qt::ItemIsEnabled));

View File

@ -13,12 +13,13 @@
#include <boost/program_options/options_description.hpp> #include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
#include <components/files/conversion.hpp> #include <components/files/conversion.hpp>
#include <components/files/qtconversion.hpp>
#include "playpage.hpp"
#include "graphicspage.hpp"
#include "datafilespage.hpp"
#include "settingspage.hpp"
#include "advancedpage.hpp" #include "advancedpage.hpp"
#include "datafilespage.hpp"
#include "graphicspage.hpp"
#include "playpage.hpp"
#include "settingspage.hpp"
using namespace Process; using namespace Process;
@ -163,7 +164,7 @@ Launcher::FirstRunDialogResult Launcher::MainDialog::showFirstRunDialog()
cfgError(tr("Error opening OpenMW configuration file"), cfgError(tr("Error opening OpenMW configuration file"),
tr("<br><b>Could not create directory %0</b><br><br> \ tr("<br><b>Could not create directory %0</b><br><br> \
Please make sure you have the right permissions \ Please make sure you have the right permissions \
and try again.<br>").arg(QString::fromStdU32String(canonical(userConfigDir).u32string())) and try again.<br>").arg(Files::pathToQString(canonical(userConfigDir)))
); );
return FirstRunDialogResultFailure; return FirstRunDialogResultFailure;
} }
@ -296,7 +297,7 @@ bool Launcher::MainDialog::setupLauncherSettings()
mLauncherSettings.setMultiValueEnabled(true); mLauncherSettings.setMultiValueEnabled(true);
QString userPath = QString::fromStdU32String(mCfgMgr.getUserConfigPath().u32string()); const auto userPath = Files::pathToQString(mCfgMgr.getUserConfigPath());
QStringList paths; QStringList paths;
paths.append(QString(Config::LauncherSettings::sLauncherConfigFileName)); paths.append(QString(Config::LauncherSettings::sLauncherConfigFileName));
@ -329,9 +330,9 @@ bool Launcher::MainDialog::setupGameSettings()
{ {
mGameSettings.clear(); mGameSettings.clear();
QString localPath = QString::fromStdU32String(mCfgMgr.getLocalPath().u32string()); const auto localPath = Files::pathToQString(mCfgMgr.getLocalPath());
QString userPath = QString::fromStdU32String(mCfgMgr.getUserConfigPath().u32string()); const auto userPath = Files::pathToQString(mCfgMgr.getUserConfigPath());
QString globalPath = QString::fromStdU32String(mCfgMgr.getGlobalPath().u32string()); const auto globalPath = Files::pathToQString(mCfgMgr.getGlobalPath());
QFile file; QFile file;
@ -487,13 +488,17 @@ bool Launcher::MainDialog::writeSettings()
cfgError(tr("Error creating OpenMW configuration directory"), cfgError(tr("Error creating OpenMW configuration directory"),
tr("<br><b>Could not create %0</b><br><br> \ tr("<br><b>Could not create %0</b><br><br> \
Please make sure you have the right permissions \ Please make sure you have the right permissions \
and try again.<br>").arg(QString::fromStdU32String(userPath.u32string()))); and try again.<br>").arg(Files::pathToQString(userPath)));
return false; return false;
} }
} }
// Game settings // Game settings
QFile file(QString::fromStdU32String((userPath / "openmw.cfg").u32string())); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QFile file(userPath / "openmw.cfg");
#else
QFile file(Files::pathToQString(userPath / "openmw.cfg"));
#endif
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
// File cannot be opened or created // File cannot be opened or created
@ -521,7 +526,7 @@ bool Launcher::MainDialog::writeSettings()
} }
// Launcher settings // Launcher settings
file.setFileName(QString::fromStdU32String((userPath / Config::LauncherSettings::sLauncherConfigFileName).u32string())); file.setFileName(Files::pathToQString(userPath / Config::LauncherSettings::sLauncherConfigFileName));
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) { if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) {
// File cannot be opened or created // File cannot be opened or created

View File

@ -5,6 +5,9 @@
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <components/files/conversion.hpp>
#include <components/files/qtconversion.hpp>
#include "utils/textinputdialog.hpp" #include "utils/textinputdialog.hpp"
#include "datafilespage.hpp" #include "datafilespage.hpp"
@ -104,7 +107,11 @@ void Launcher::SettingsPage::on_importerButton_clicked()
// Create the file if it doesn't already exist, else the importer will fail // Create the file if it doesn't already exist, else the importer will fail
auto path = mCfgMgr.getUserConfigPath(); auto path = mCfgMgr.getUserConfigPath();
path /= "openmw.cfg"; path /= "openmw.cfg";
QFile file(QString::fromStdU32String(path.u32string())); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QFile file(path);
#else
QFile file(Files::pathToQString(path));
#endif
if (!file.exists()) { if (!file.exists()) {
if (!file.open(QIODevice::ReadWrite)) { if (!file.open(QIODevice::ReadWrite)) {
@ -137,7 +144,7 @@ void Launcher::SettingsPage::on_importerButton_clicked()
arguments.append(QString("--ini")); arguments.append(QString("--ini"));
arguments.append(settingsComboBox->currentText()); arguments.append(settingsComboBox->currentText());
arguments.append(QString("--cfg")); arguments.append(QString("--cfg"));
arguments.append(QString::fromStdU32String(path.u32string())); arguments.append(Files::pathToQString(path));
qDebug() << "arguments " << arguments; qDebug() << "arguments " << arguments;

View File

@ -10,7 +10,10 @@
#include <components/debug/debugging.hpp> #include <components/debug/debugging.hpp>
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/fallback/validate.hpp> #include <components/fallback/validate.hpp>
#include <components/files/conversion.hpp>
#include <components/files/qtconversion.hpp>
#include <components/misc/rng.hpp> #include <components/misc/rng.hpp>
#include <components/misc/strings/conversion.hpp>
#include <components/nifosg/nifloader.hpp> #include <components/nifosg/nifloader.hpp>
#include <components/settings/settings.hpp> #include <components/settings/settings.hpp>
@ -230,8 +233,9 @@ void CS::Editor::openFiles (const std::filesystem::path &savePath, const std::ve
if(discoveredFiles.empty()) if(discoveredFiles.empty())
{ {
for (const QString &path : mFileDialog.selectedFilePaths()) for (const QString &path : mFileDialog.selectedFilePaths()) {
files.emplace_back(path.toStdU32String()); files.emplace_back(Files::pathFromQString(path));
}
} }
else else
{ {
@ -248,7 +252,7 @@ void CS::Editor::createNewFile (const std::filesystem::path &savePath)
std::vector<std::filesystem::path> files; std::vector<std::filesystem::path> files;
for (const QString &path : mFileDialog.selectedFilePaths()) { for (const QString &path : mFileDialog.selectedFilePaths()) {
files.emplace_back(path.toStdU32String()); files.emplace_back(Files::pathFromQString(path));
} }
files.push_back (savePath); files.push_back (savePath);
@ -320,12 +324,13 @@ bool CS::Editor::makeIPCServer()
mServer->close(); mServer->close();
fullPath.remove(QRegExp("dummy$")); fullPath.remove(QRegExp("dummy$"));
fullPath += mIpcServerName; fullPath += mIpcServerName;
if(std::filesystem::exists(fullPath.toUtf8().constData())) const auto path = Files::pathFromQString(fullPath);
if(exists(path))
{ {
// TODO: compare pid of the current process with that in the file // TODO: compare pid of the current process with that in the file
Log(Debug::Info) << "Detected unclean shutdown."; Log(Debug::Info) << "Detected unclean shutdown.";
// delete the stale file // delete the stale file
if(remove(fullPath.toUtf8().constData())) if(remove(path))
Log(Debug::Error) << "Error: can not remove stale connection file."; Log(Debug::Error) << "Error: can not remove stale connection file.";
} }
} }
@ -390,7 +395,7 @@ int CS::Editor::run()
} }
discoveredFiles.push_back(mFileToLoad); discoveredFiles.push_back(mFileToLoad);
QString extension = QString::fromStdU32String(mFileToLoad.extension().u32string()).toLower(); const auto extension = Files::pathToQString(mFileToLoad.extension()).toLower();
if (extension == ".esm") if (extension == ".esm")
{ {
mFileToLoad.replace_extension(".omwgame"); mFileToLoad.replace_extension(".omwgame");

View File

@ -7,6 +7,9 @@
#include <QTextStream> #include <QTextStream>
#include <QCoreApplication> #include <QCoreApplication>
#include <components/files/conversion.hpp>
#include <components/files/qtconversion.hpp>
#include "operationholder.hpp" #include "operationholder.hpp"
CSMDoc::Runner::Runner (std::filesystem::path projectPath) CSMDoc::Runner::Runner (std::filesystem::path projectPath)
@ -80,22 +83,21 @@ void CSMDoc::Runner::start (bool delayed)
else else
arguments << "--new-game=1"; arguments << "--new-game=1";
arguments << ("--script-run="+mStartup->fileName()); arguments << ("--script-run=" + mStartup->fileName());
arguments << arguments << "--data=\"" + Files::pathToQString(mProjectPath.parent_path()) + "\"";
QString::fromStdU32String (U"--data=\""+mProjectPath.parent_path().u32string()+U"\"");
arguments << "--replace=content"; arguments << "--replace=content";
for (const auto & mContentFile : mContentFiles) for (const auto& mContentFile : mContentFiles)
{ {
arguments << QString::fromStdU32String (U"--content="+mContentFile.u32string()); arguments << "--content=" + Files::pathToQString(mContentFile);
} }
arguments arguments
<< QString::fromStdU32String (U"--content="+mProjectPath.filename().u32string()); << "--content=" + Files::pathToQString(mProjectPath.filename());
mProcess.start (path, arguments); mProcess.start(path, arguments);
} }
mRunning = true; mRunning = true;

View File

@ -1,12 +1,14 @@
#include "adjusterwidget.hpp" #include "adjusterwidget.hpp"
#include <filesystem> #include <filesystem>
#include <components/misc/strings/lower.hpp>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QStyle> #include <QStyle>
#include <components/files/qtconversion.hpp>
#include <components/misc/strings/conversion.hpp>
#include <components/misc/strings/lower.hpp>
CSVDoc::AdjusterWidget::AdjusterWidget (QWidget *parent) CSVDoc::AdjusterWidget::AdjusterWidget (QWidget *parent)
: QWidget (parent), mValid (false), mAction (ContentAction_Undefined) : QWidget (parent), mValid (false), mAction (ContentAction_Undefined)
{ {
@ -68,7 +70,7 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon)
} }
else else
{ {
std::filesystem::path path (name.toStdU32String()); auto path = Files::pathFromQString(name);
const auto extension = Misc::StringUtils::lowerCase(path.extension().u8string()); const auto extension = Misc::StringUtils::lowerCase(path.extension().u8string());
@ -85,7 +87,7 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon)
if (!isFilePathChanged && !isLegacyPath) if (!isFilePathChanged && !isLegacyPath)
{ {
// path already points to the local data directory // path already points to the local data directory
message = QString::fromStdU32String (U"Will be saved as: " + path.u32string()); message = "Will be saved as: " + Files::pathToQString(path);
mResultPath = path; mResultPath = path;
} }
//in all other cases, ensure the path points to data-local and do an existing file check //in all other cases, ensure the path points to data-local and do an existing file check
@ -95,7 +97,7 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon)
if (isFilePathChanged) if (isFilePathChanged)
path = mLocalData / path.filename(); path = mLocalData / path.filename();
message = QString::fromStdU32String (U"Will be saved as: " + path.u32string()); message = "Will be saved as: " + Files::pathToQString(path);
mResultPath = path; mResultPath = path;
if (std::filesystem::exists (path)) if (std::filesystem::exists (path))

View File

@ -8,6 +8,9 @@
#include <QCloseEvent> #include <QCloseEvent>
#include <QListWidget> #include <QListWidget>
#include <components/files/conversion.hpp>
#include <components/files/qtconversion.hpp>
#include "../../model/doc/document.hpp" #include "../../model/doc/document.hpp"
void CSVDoc::LoadingDocument::closeEvent (QCloseEvent *event) void CSVDoc::LoadingDocument::closeEvent (QCloseEvent *event)
@ -19,7 +22,7 @@ void CSVDoc::LoadingDocument::closeEvent (QCloseEvent *event)
CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document) CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
: mDocument (document), mTotalRecordsLabel (0), mRecordsLabel (0), mAborted (false), mMessages (nullptr), mRecords(0) : mDocument (document), mTotalRecordsLabel (0), mRecordsLabel (0), mAborted (false), mMessages (nullptr), mRecords(0)
{ {
setWindowTitle (QString::fromStdU32String(U"Opening " + document->getSavePath().filename().u32string())); setWindowTitle ("Opening " + Files::pathToQString(document->getSavePath().filename()));
setMinimumWidth (400); setMinimumWidth (400);
@ -89,16 +92,16 @@ void CSVDoc::LoadingDocument::nextStage (const std::string& name, int fileRecord
mRecords = fileRecords; mRecords = fileRecords;
} }
void CSVDoc::LoadingDocument::nextRecord (int records) void CSVDoc::LoadingDocument::nextRecord(int records)
{ {
if (records <= mRecords) if (records <= mRecords)
{ {
mTotalProgress->setValue (mTotalRecords+records); mTotalProgress->setValue(mTotalRecords + records);
mRecordProgress->setValue(records); mRecordProgress->setValue(records);
mRecordsLabel->setText(QString::fromStdString( mRecordsLabel->setText(
"Records: "+std::to_string(records)+" of "+std::to_string(mRecords))); "Records: " + QString::number(records) + " of " + QString::number(mRecords));
} }
} }

View File

@ -7,8 +7,10 @@
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include "../../model/doc/documentmanager.hpp" #include <components/files/qtconversion.hpp>
#include "../../model/doc/document.hpp" #include "../../model/doc/document.hpp"
#include "../../model/doc/documentmanager.hpp"
#include "../../model/doc/state.hpp" #include "../../model/doc/state.hpp"
#include "../../model/world/columns.hpp" #include "../../model/world/columns.hpp"
@ -261,7 +263,7 @@ bool CSVDoc::ViewManager::showModifiedDocumentMessageBox (CSVDoc::View *view)
QMessageBox messageBox(view); QMessageBox messageBox(view);
CSMDoc::Document *document = view->getDocument(); CSMDoc::Document *document = view->getDocument();
messageBox.setWindowTitle (QString::fromStdU32String(document->getSavePath().filename().u32string())); messageBox.setWindowTitle (Files::pathToQString(document->getSavePath().filename()));
messageBox.setText ("The document has been modified."); messageBox.setText ("The document has been modified.");
messageBox.setInformativeText ("Do you want to save your changes?"); messageBox.setInformativeText ("Do you want to save your changes?");
messageBox.setStandardButtons (QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); messageBox.setStandardButtons (QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);

View File

@ -1,13 +1,16 @@
#include "merge.hpp" #include "merge.hpp"
#include <QVBoxLayout>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QSplitter>
#include <QPushButton>
#include <QListWidget>
#include <QLabel>
#include <QKeyEvent> #include <QKeyEvent>
#include <QLabel>
#include <QListWidget>
#include <QPushButton>
#include <QSplitter>
#include <QVBoxLayout>
#include <components/files/conversion.hpp>
#include <components/files/qtconversion.hpp>
#include "../../model/doc/document.hpp" #include "../../model/doc/document.hpp"
#include "../../model/doc/documentmanager.hpp" #include "../../model/doc/documentmanager.hpp"
@ -102,7 +105,7 @@ void CSVTools::Merge::configure (CSMDoc::Document *document)
for (std::vector<std::filesystem::path>::const_iterator iter (files.begin()); for (std::vector<std::filesystem::path>::const_iterator iter (files.begin());
iter!=files.end(); ++iter) iter!=files.end(); ++iter)
mFiles->addItem (QString::fromStdU32String(iter->filename().u32string())); mFiles->addItem (Files::pathToQString(iter->filename()));
} }
void CSVTools::Merge::setLocalData (const std::filesystem::path& localData) void CSVTools::Merge::setLocalData (const std::filesystem::path& localData)

View File

@ -1,19 +1,22 @@
#include "mainwizard.hpp" #include "mainwizard.hpp"
#include <QDebug>
#include <QDateTime> #include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QMessageBox> #include <QMessageBox>
#include <QTextCodec> #include <QTextCodec>
#include <QDir>
#include "intropage.hpp" #include <components/files/conversion.hpp>
#include "methodselectionpage.hpp" #include <components/files/qtconversion.hpp>
#include "languageselectionpage.hpp"
#include "existinginstallationpage.hpp"
#include "installationtargetpage.hpp"
#include "componentselectionpage.hpp" #include "componentselectionpage.hpp"
#include "importpage.hpp"
#include "conclusionpage.hpp" #include "conclusionpage.hpp"
#include "existinginstallationpage.hpp"
#include "importpage.hpp"
#include "installationtargetpage.hpp"
#include "intropage.hpp"
#include "languageselectionpage.hpp"
#include "methodselectionpage.hpp"
#ifdef OPENMW_USE_UNSHIELD #ifdef OPENMW_USE_UNSHIELD
#include "installationpage.hpp" #include "installationpage.hpp"
@ -67,7 +70,7 @@ Wizard::MainWizard::MainWizard(QWidget *parent) :
if (!installationPath.empty()) if (!installationPath.empty())
{ {
const std::filesystem::path& dataPath = installationPath / "Data Files"; const std::filesystem::path& dataPath = installationPath / "Data Files";
addInstallation(toQString(dataPath)); addInstallation(Files::pathToQString(dataPath));
} }
} }
@ -78,7 +81,7 @@ Wizard::MainWizard::~MainWizard()
void Wizard::MainWizard::setupLog() void Wizard::MainWizard::setupLog()
{ {
QString logPath(toQString(mCfgMgr.getLogPath())); QString logPath(Files::pathToQString(mCfgMgr.getLogPath()));
logPath.append(QLatin1String("wizard.log")); logPath.append(QLatin1String("wizard.log"));
QFile file(logPath); QFile file(logPath);
@ -101,7 +104,7 @@ void Wizard::MainWizard::setupLog()
void Wizard::MainWizard::addLogText(const QString &text) void Wizard::MainWizard::addLogText(const QString &text)
{ {
QString logPath(toQString(mCfgMgr.getLogPath())); QString logPath(Files::pathToQString(mCfgMgr.getLogPath()));
logPath.append(QLatin1String("wizard.log")); logPath.append(QLatin1String("wizard.log"));
QFile file(logPath); QFile file(logPath);
@ -131,8 +134,8 @@ void Wizard::MainWizard::addLogText(const QString &text)
void Wizard::MainWizard::setupGameSettings() void Wizard::MainWizard::setupGameSettings()
{ {
QString userPath(toQString(mCfgMgr.getUserConfigPath())); QString userPath(Files::pathToQString(mCfgMgr.getUserConfigPath()));
QString globalPath(toQString(mCfgMgr.getGlobalPath())); QString globalPath(Files::pathToQString(mCfgMgr.getGlobalPath()));
QString message(tr("<html><head/><body><p><b>Could not open %1 for reading</b></p> \ 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 \ <p>Please make sure you have the right permissions \
and try again.</p></body></html>")); and try again.</p></body></html>"));
@ -196,7 +199,7 @@ void Wizard::MainWizard::setupGameSettings()
void Wizard::MainWizard::setupLauncherSettings() void Wizard::MainWizard::setupLauncherSettings()
{ {
QString path(toQString(mCfgMgr.getUserConfigPath())); QString path(Files::pathToQString(mCfgMgr.getUserConfigPath()));
path.append(QLatin1String(Config::LauncherSettings::sLauncherConfigFileName)); path.append(QLatin1String(Config::LauncherSettings::sLauncherConfigFileName));
QString message(tr("<html><head/><body><p><b>Could not open %1 for reading</b></p> \ QString message(tr("<html><head/><body><p><b>Could not open %1 for reading</b></p> \
@ -246,7 +249,7 @@ void Wizard::MainWizard::runSettingsImporter()
QString path(field(QLatin1String("installation.path")).toString()); QString path(field(QLatin1String("installation.path")).toString());
QString userPath(toQString(mCfgMgr.getUserConfigPath())); QString userPath(Files::pathToQString(mCfgMgr.getUserConfigPath()));
QFile file(userPath + QLatin1String("openmw.cfg")); QFile file(userPath + QLatin1String("openmw.cfg"));
// Construct the arguments to run the importer // Construct the arguments to run the importer
@ -392,7 +395,7 @@ void Wizard::MainWizard::writeSettings()
mGameSettings.removeDataDir(path); mGameSettings.removeDataDir(path);
mGameSettings.addDataDir(path); mGameSettings.addDataDir(path);
QString userPath(toQString(mCfgMgr.getUserConfigPath())); QString userPath(Files::pathToQString(mCfgMgr.getUserConfigPath()));
QDir dir(userPath); QDir dir(userPath);
if (!dir.exists()) { if (!dir.exists()) {
@ -468,8 +471,3 @@ bool Wizard::MainWizard::findFiles(const QString &name, const QString &path)
return (dir.entryList().contains(name + QLatin1String(".esm"), Qt::CaseInsensitive) return (dir.entryList().contains(name + QLatin1String(".esm"), Qt::CaseInsensitive)
&& dir.entryList().contains(name + QLatin1String(".bsa"), Qt::CaseInsensitive)); && dir.entryList().contains(name + QLatin1String(".bsa"), Qt::CaseInsensitive));
} }
QString Wizard::MainWizard::toQString(const std::filesystem::path& path)
{
return QString::fromStdU32String(path.u32string());
}

View File

@ -58,9 +58,6 @@ namespace Wizard
void addLogText(const QString &text); void addLogText(const QString &text);
private: private:
/// convert std::filesystem::path to QString
QString toQString(const std::filesystem::path& path);
void setupLog(); void setupLog();
void setupGameSettings(); void setupGameSettings();
void setupLauncherSettings(); void setupLauncherSettings();

View File

@ -379,6 +379,10 @@ if (USE_QT)
helpviewer helpviewer
) )
add_component_qt_dir (files
qtconversion
)
QT5_WRAP_UI(ESM_UI_HDR ${ESM_UI}) QT5_WRAP_UI(ESM_UI_HDR ${ESM_UI})
endif() endif()

View File

@ -4,9 +4,11 @@
#include <QTextCodec> #include <QTextCodec>
#include <QDir> #include <QDir>
#include <QRegExp> #include <QRegExp>
#include <QDebug>
#include <components/files/configurationmanager.hpp> #include <components/files/configurationmanager.hpp>
#include <components/files/conversion.hpp>
#include <components/files/qtconversion.hpp>
#include <components/misc/strings/conversion.hpp>
const char Config::GameSettings::sArchiveKey[] = "fallback-archive"; const char Config::GameSettings::sArchiveKey[] = "fallback-archive";
const char Config::GameSettings::sContentKey[] = "content"; const char Config::GameSettings::sContentKey[] = "content";
@ -24,19 +26,16 @@ void Config::GameSettings::validatePaths()
for (const QString &path : paths) for (const QString &path : paths)
{ {
dataDirs.emplace_back(path.toStdU32String()); dataDirs.emplace_back(Files::pathFromQString(path));
} }
// Parse the data dirs to convert the tokenized paths // Parse the data dirs to convert the tokenized paths
mCfgMgr.processPaths(dataDirs, /*basePath=*/""); mCfgMgr.processPaths(dataDirs, /*basePath=*/"");
mDataDirs.clear(); mDataDirs.clear();
for (auto & dataDir : dataDirs) { for (const auto & dataDir : dataDirs) {
QString path = QString::fromStdU32String(dataDir.u32string()); if (is_directory(dataDir))
mDataDirs.append(Files::pathToQString(dataDir));
QDir dir(path);
if (dir.exists())
mDataDirs.append(path);
} }
// Do the same for data-local // Do the same for data-local
@ -51,16 +50,14 @@ void Config::GameSettings::validatePaths()
return; return;
dataDirs.clear(); dataDirs.clear();
dataDirs.emplace_back(local.toStdU32String()); dataDirs.emplace_back(Files::pathFromQString(local));
mCfgMgr.processPaths(dataDirs, /*basePath=*/""); mCfgMgr.processPaths(dataDirs, /*basePath=*/"");
if (!dataDirs.empty()) { if (!dataDirs.empty()) {
QString path = QString::fromStdU32String(dataDirs.front().u32string()); const auto& path = dataDirs.front();
if (is_directory(path))
QDir dir(path); mDataLocal = Files::pathToQString(path);
if (dir.exists())
mDataLocal = path;
} }
} }

View File

@ -8,6 +8,8 @@
#include <QDebug> #include <QDebug>
#include <components/files/configurationmanager.hpp> #include <components/files/configurationmanager.hpp>
#include <components/files/conversion.hpp>
#include <components/files/qtconversion.hpp>
const char Config::LauncherSettings::sCurrentContentListKey[] = "Profiles/currentprofile"; const char Config::LauncherSettings::sCurrentContentListKey[] = "Profiles/currentprofile";
const char Config::LauncherSettings::sLauncherConfigFileName[] = "launcher.cfg"; const char Config::LauncherSettings::sLauncherConfigFileName[] = "launcher.cfg";
@ -119,7 +121,7 @@ void Config::LauncherSettings::setContentList(const GameSettings& gameSettings)
} }
// global and local data directories are not part of any profile // global and local data directories are not part of any profile
const auto globalDataDir = QString::fromStdU32String(gameSettings.getGlobalDataDir().u32string()); const auto globalDataDir = Files::pathToQString(gameSettings.getGlobalDataDir());
const auto dataLocal = gameSettings.getDataLocal(); const auto dataLocal = gameSettings.getDataLocal();
dirs.removeAll(globalDataDir); dirs.removeAll(globalDataDir);
dirs.removeAll(dataLocal); dirs.removeAll(dataLocal);

View File

@ -0,0 +1,28 @@
#include "qtconversion.hpp"
#include <components/misc/strings/conversion.hpp>
QString Files::pathToQString(const std::filesystem::path& path)
{
const auto tmp = path.u8string();
return QString::fromUtf8(Misc::StringUtils::u8StringToString(tmp.data()), tmp.size());
}
QString Files::pathToQString(std::filesystem::path&& path)
{
const auto tmp = path.u8string();
return QString::fromUtf8(Misc::StringUtils::u8StringToString(tmp.data()), tmp.size());
}
std::filesystem::path Files::pathFromQString(QStringView path)
{
const auto tmp = path.toUtf8();
return std::filesystem::path{ Misc::StringUtils::stringToU8String(tmp) };
}
std::filesystem::path Files::pathFromQString(QString&& path)
{
const auto tmp = path.toUtf8();
return std::filesystem::path{ Misc::StringUtils::stringToU8String(tmp) };
}

View File

@ -0,0 +1,18 @@
#ifndef COMPONENTS_FILES_QTCONVERSION_HPP
#define COMPONENTS_FILES_QTCONVERSION_HPP
#include <QString>
#include <filesystem>
namespace Files
{
QString pathToQString(const std::filesystem::path& path);
QString pathToQString(std::filesystem::path&& path);
std::filesystem::path pathFromQString(QStringView path);
std::filesystem::path pathFromQString(QString&& path);
}
#endif // COMPONENTS_FILES_QTCONVERSION_HPP