diff --git a/apps/bsatool/bsatool.cpp b/apps/bsatool/bsatool.cpp index 0f6a7d35e7..b250cf9862 100644 --- a/apps/bsatool/bsatool.cpp +++ b/apps/bsatool/bsatool.cpp @@ -244,7 +244,7 @@ int extractAll(std::unique_ptr& bsa, Arguments& info) // Get the target path (the path the file will be extracted to) auto target = info.outdir; - target /= extractPath; + target /= Misc::StringUtils::stringToU8String(extractPath); // Create the directory hierarchy std::filesystem::create_directories(target.parent_path()); @@ -261,7 +261,7 @@ int extractAll(std::unique_ptr& bsa, Arguments& info) std::ofstream out(target, std::ios::binary); // Write the file to disk - std::cout << "Extracting " << target << std::endl; + std::cout << "Extracting " << Files::pathToUnicodeString(target) << std::endl; out << data->rdbuf(); out.close(); } diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index dab212c076..2e274bfe74 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -289,7 +289,7 @@ void loadCell(const Arguments& info, ESM::Cell &cell, ESM::ESMReader &esm, ESMDa void printRawTes3(const std::filesystem::path &path) { - std::cout << "TES3 RAW file listing: " << path << '\n'; + std::cout << "TES3 RAW file listing: " << Files::pathToUnicodeString(path) << '\n'; ESM::ESMReader esm; esm.openRaw(path); while(esm.hasMoreRecs()) diff --git a/apps/essimporter/importer.cpp b/apps/essimporter/importer.cpp index fbb333740b..5bc8079bd1 100644 --- a/apps/essimporter/importer.cpp +++ b/apps/essimporter/importer.cpp @@ -345,7 +345,7 @@ namespace ESSImport writer.setFormat (ESM::SavedGame::sCurrentFormat); - std::ofstream stream(std::filesystem::path(mOutFile), std::ios::out | std::ios::binary); + std::ofstream stream(mOutFile, std::ios::out | std::ios::binary); // all unused writer.setVersion(0); writer.setType(0); diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 3495d04502..7d00c05bba 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -232,7 +232,7 @@ void Launcher::DataFilesPage::populateFileViews(const QString& contentModelName) const auto& globalDataDir = mGameSettings.getGlobalDataDir(); if (!globalDataDir.empty()) - directories.insert(0, QString::fromStdWString(globalDataDir.wstring())); + directories.insert(0, QString::fromStdU32String(globalDataDir.u32string())); // normalize user supplied directories: resolve symlink, convert to native separator, make absolute for (auto& currentDir : directories) @@ -264,7 +264,7 @@ void Launcher::DataFilesPage::populateFileViews(const QString& contentModelName) } // deactivate data-local and global data directory: they are always included - if (currentDir == mDataLocal || std::filesystem::path(currentDir.toStdWString()) == globalDataDir) + if (currentDir == mDataLocal || std::filesystem::path(currentDir.toStdU32String()) == globalDataDir) { auto flags = item->flags(); item->setFlags(flags & ~(Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled|Qt::ItemIsEnabled)); diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 7b5fbe5c4c..830a80d01d 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -163,7 +163,7 @@ Launcher::FirstRunDialogResult Launcher::MainDialog::showFirstRunDialog() cfgError(tr("Error opening OpenMW configuration file"), tr("
Could not create directory %0

\ Please make sure you have the right permissions \ - and try again.
").arg(QString::fromStdWString(canonical(userConfigDir).wstring())) + and try again.
").arg(QString::fromStdU32String(canonical(userConfigDir).u32string())) ); return FirstRunDialogResultFailure; } @@ -296,7 +296,7 @@ bool Launcher::MainDialog::setupLauncherSettings() mLauncherSettings.setMultiValueEnabled(true); - QString userPath = QString::fromStdWString(mCfgMgr.getUserConfigPath().wstring()); + QString userPath = QString::fromStdU32String(mCfgMgr.getUserConfigPath().u32string()); QStringList paths; paths.append(QString(Config::LauncherSettings::sLauncherConfigFileName)); @@ -329,9 +329,9 @@ bool Launcher::MainDialog::setupGameSettings() { mGameSettings.clear(); - QString localPath = QString::fromStdWString(mCfgMgr.getLocalPath().wstring()); - QString userPath = QString::fromStdWString(mCfgMgr.getUserConfigPath().wstring()); - QString globalPath = QString::fromStdWString(mCfgMgr.getGlobalPath().wstring()); + QString localPath = QString::fromStdU32String(mCfgMgr.getLocalPath().u32string()); + QString userPath = QString::fromStdU32String(mCfgMgr.getUserConfigPath().u32string()); + QString globalPath = QString::fromStdU32String(mCfgMgr.getGlobalPath().u32string()); QFile file; @@ -487,13 +487,13 @@ bool Launcher::MainDialog::writeSettings() cfgError(tr("Error creating OpenMW configuration directory"), tr("
Could not create %0

\ Please make sure you have the right permissions \ - and try again.
").arg(QString::fromStdWString(userPath.wstring()))); + and try again.
").arg(QString::fromStdU32String(userPath.u32string()))); return false; } } // Game settings - QFile file(QString::fromStdWString((userPath / "openmw.cfg").wstring())); + QFile file(QString::fromStdU32String((userPath / "openmw.cfg").u32string())); if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { // File cannot be opened or created @@ -521,7 +521,7 @@ bool Launcher::MainDialog::writeSettings() } // Launcher settings - file.setFileName(QString::fromStdWString((userPath / Config::LauncherSettings::sLauncherConfigFileName).wstring())); + file.setFileName(QString::fromStdU32String((userPath / Config::LauncherSettings::sLauncherConfigFileName).u32string())); if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) { // File cannot be opened or created diff --git a/apps/launcher/settingspage.cpp b/apps/launcher/settingspage.cpp index 1a9670a292..325fa4dfa1 100644 --- a/apps/launcher/settingspage.cpp +++ b/apps/launcher/settingspage.cpp @@ -104,7 +104,7 @@ void Launcher::SettingsPage::on_importerButton_clicked() // Create the file if it doesn't already exist, else the importer will fail auto path = mCfgMgr.getUserConfigPath(); path /= "openmw.cfg"; - QFile file(QString::fromStdWString(path.wstring())); + QFile file(QString::fromStdU32String(path.u32string())); if (!file.exists()) { if (!file.open(QIODevice::ReadWrite)) { @@ -137,7 +137,7 @@ void Launcher::SettingsPage::on_importerButton_clicked() arguments.append(QString("--ini")); arguments.append(settingsComboBox->currentText()); arguments.append(QString("--cfg")); - arguments.append(QString::fromStdWString(path.wstring())); + arguments.append(QString::fromStdU32String(path.u32string())); qDebug() << "arguments " << arguments; diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index ed962c4c5f..43f2b429b1 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -658,7 +658,7 @@ void MwIniImporter::setVerbose(bool verbose) { } MwIniImporter::multistrmap MwIniImporter::loadIniFile(const std::filesystem::path& filename) const { - std::cout << "load ini file: " << filename << std::endl; + std::cout << "load ini file: " << Files::pathToUnicodeString(filename) << std::endl; std::string section(""); MwIniImporter::multistrmap map; @@ -719,7 +719,7 @@ MwIniImporter::multistrmap MwIniImporter::loadIniFile(const std::filesystem::pat } MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const std::filesystem::path& filename) { - std::cout << "load cfg file: " << filename << std::endl; + std::cout << "load cfg file: " << Files::pathToUnicodeString(filename) << std::endl; MwIniImporter::multistrmap map; std::ifstream file(filename); @@ -872,7 +872,7 @@ void MwIniImporter::addPaths(std::vector& output, std::ve // Drop first and last characters - quotation marks path = path.substr(1, path.size() - 2); } - output.emplace_back(path); + output.emplace_back(Files::pathFromUnicodeString(path)); } } diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 58b5a9e6c5..690afe64c8 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -7,6 +7,7 @@ #include #include +#include namespace bpo = boost::program_options; namespace sfs = std::filesystem; @@ -137,7 +138,7 @@ int wmain(int argc, wchar_t *wargv[]) { importer.importArchives(cfg, ini); } - std::cout << "write to: " << outputFile << std::endl; + std::cout << "write to: " << Files::pathToUnicodeString(outputFile) << std::endl; std::ofstream file(outputFile); importer.writeToFile(file, cfg); } diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 669fa83a4c..5f165a95a4 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -231,7 +231,7 @@ void CS::Editor::openFiles (const std::filesystem::path &savePath, const std::ve if(discoveredFiles.empty()) { for (const QString &path : mFileDialog.selectedFilePaths()) - files.emplace_back(path.toUtf8().constData()); + files.emplace_back(path.toStdU32String()); } else { @@ -248,7 +248,7 @@ void CS::Editor::createNewFile (const std::filesystem::path &savePath) std::vector files; for (const QString &path : mFileDialog.selectedFilePaths()) { - files.emplace_back(path.toUtf8().constData()); + files.emplace_back(path.toStdU32String()); } files.push_back (savePath); @@ -377,23 +377,20 @@ int CS::Editor::run() std::vector discoveredFiles; - for (std::vector::const_iterator itemIter = fileReader.getGameFiles().begin(); - itemIter != fileReader.getGameFiles().end(); ++itemIter) + for (const auto& item : fileReader.getGameFiles()) { - for (Files::PathContainer::const_iterator pathIter = mDataDirs.begin(); - pathIter != mDataDirs.end(); ++pathIter) + for (const auto& path : mDataDirs) { - const std::filesystem::path masterPath = *pathIter / itemIter->name; - if (std::filesystem::exists(masterPath)) + if (auto masterPath = path / item.name; std::filesystem::exists(masterPath)) { - discoveredFiles.push_back(masterPath); + discoveredFiles.emplace_back(std::move(masterPath)); break; } } } discoveredFiles.push_back(mFileToLoad); - QString extension = QString::fromStdWString(mFileToLoad.extension().wstring()).toLower(); + QString extension = QString::fromStdU32String(mFileToLoad.extension().u32string()).toLower(); if (extension == ".esm") { mFileToLoad.replace_extension(".omwgame"); diff --git a/apps/opencs/model/doc/runner.cpp b/apps/opencs/model/doc/runner.cpp index 2b16ea3eff..dd99ede234 100644 --- a/apps/opencs/model/doc/runner.cpp +++ b/apps/opencs/model/doc/runner.cpp @@ -83,17 +83,17 @@ void CSMDoc::Runner::start (bool delayed) arguments << ("--script-run="+mStartup->fileName()); arguments << - QString::fromStdWString (L"--data=\""+mProjectPath.parent_path().wstring()+L"\""); + QString::fromStdU32String (U"--data=\""+mProjectPath.parent_path().u32string()+U"\""); arguments << "--replace=content"; for (const auto & mContentFile : mContentFiles) { - arguments << QString::fromStdWString (L"--content="+mContentFile.wstring()); + arguments << QString::fromStdU32String (U"--content="+mContentFile.u32string()); } arguments - << QString::fromStdWString (L"--content="+mProjectPath.filename().wstring()); + << QString::fromStdU32String (U"--content="+mProjectPath.filename().u32string()); mProcess.start (path, arguments); } diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index ae2c94b11a..e5a1ef71a5 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -648,8 +648,7 @@ CSMPrefs::State::~State() void CSMPrefs::State::save() { - std::filesystem::path user = mConfigurationManager.getUserConfigPath() / mConfigFile; - Settings::Manager::saveUser (user); + Settings::Manager::saveUser (mConfigurationManager.getUserConfigPath() / mConfigFile); } CSMPrefs::State::Iterator CSMPrefs::State::begin() diff --git a/apps/opencs/view/doc/adjusterwidget.cpp b/apps/opencs/view/doc/adjusterwidget.cpp index 6eb479d694..791a1c556d 100644 --- a/apps/opencs/view/doc/adjusterwidget.cpp +++ b/apps/opencs/view/doc/adjusterwidget.cpp @@ -68,7 +68,7 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon) } else { - std::filesystem::path path (name.toStdWString()); + std::filesystem::path path (name.toStdU32String()); const auto extension = Misc::StringUtils::lowerCase(path.extension().u8string()); @@ -85,7 +85,7 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon) if (!isFilePathChanged && !isLegacyPath) { // path already points to the local data directory - message = QString::fromStdWString (L"Will be saved as: " + path.wstring()); + message = QString::fromStdU32String (U"Will be saved as: " + path.u32string()); mResultPath = path; } //in all other cases, ensure the path points to data-local and do an existing file check @@ -95,7 +95,7 @@ void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon) if (isFilePathChanged) path = mLocalData / path.filename(); - message = QString::fromStdWString (L"Will be saved as: " + path.wstring()); + message = QString::fromStdU32String (U"Will be saved as: " + path.u32string()); mResultPath = path; if (std::filesystem::exists (path)) diff --git a/apps/opencs/view/doc/loader.cpp b/apps/opencs/view/doc/loader.cpp index ffd1d66756..4e8eab0541 100644 --- a/apps/opencs/view/doc/loader.cpp +++ b/apps/opencs/view/doc/loader.cpp @@ -19,7 +19,7 @@ void CSVDoc::LoadingDocument::closeEvent (QCloseEvent *event) CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document) : mDocument (document), mTotalRecordsLabel (0), mRecordsLabel (0), mAborted (false), mMessages (nullptr), mRecords(0) { - setWindowTitle (QString::fromStdWString(L"Opening " + document->getSavePath().filename().wstring())); + setWindowTitle (QString::fromStdU32String(U"Opening " + document->getSavePath().filename().u32string())); setMinimumWidth (400); diff --git a/apps/opencs/view/doc/viewmanager.cpp b/apps/opencs/view/doc/viewmanager.cpp index 71e8987bb1..358bc05e8b 100644 --- a/apps/opencs/view/doc/viewmanager.cpp +++ b/apps/opencs/view/doc/viewmanager.cpp @@ -261,7 +261,7 @@ bool CSVDoc::ViewManager::showModifiedDocumentMessageBox (CSVDoc::View *view) QMessageBox messageBox(view); CSMDoc::Document *document = view->getDocument(); - messageBox.setWindowTitle (QString::fromStdWString(document->getSavePath().filename().wstring())); + messageBox.setWindowTitle (QString::fromStdU32String(document->getSavePath().filename().u32string())); messageBox.setText ("The document has been modified."); messageBox.setInformativeText ("Do you want to save your changes?"); messageBox.setStandardButtons (QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); diff --git a/apps/opencs/view/tools/merge.cpp b/apps/opencs/view/tools/merge.cpp index 6c4d076849..8e78364cea 100644 --- a/apps/opencs/view/tools/merge.cpp +++ b/apps/opencs/view/tools/merge.cpp @@ -102,7 +102,7 @@ void CSVTools::Merge::configure (CSMDoc::Document *document) for (std::vector::const_iterator iter (files.begin()); iter!=files.end(); ++iter) - mFiles->addItem (QString::fromStdWString(iter->filename().wstring())); + mFiles->addItem (QString::fromStdU32String(iter->filename().u32string())); } void CSVTools::Merge::setLocalData (const std::filesystem::path& localData) diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp index ebf22b5c83..5149552ea9 100644 --- a/apps/openmw/mwgui/savegamedialog.cpp +++ b/apps/openmw/mwgui/savegamedialog.cpp @@ -440,7 +440,7 @@ namespace MWGui const std::vector& data = mCurrentSlot->mProfile.mScreenshot; if (!data.size()) { - Log(Debug::Warning) << "Selected save file '" << mCurrentSlot->mPath.filename().string() << "' has no savegame screenshot"; + Log(Debug::Warning) << "Selected save file '" << Files::pathToUnicodeString(mCurrentSlot->mPath.filename()) << "' has no savegame screenshot"; return; } diff --git a/apps/wizard/mainwizard.cpp b/apps/wizard/mainwizard.cpp index 759fe7edd7..aa25f1fd3e 100644 --- a/apps/wizard/mainwizard.cpp +++ b/apps/wizard/mainwizard.cpp @@ -471,5 +471,5 @@ bool Wizard::MainWizard::findFiles(const QString &name, const QString &path) QString Wizard::MainWizard::toQString(const std::filesystem::path& path) { - return QString::fromStdWString(path.wstring()); + return QString::fromStdU32String(path.u32string()); } diff --git a/components/config/gamesettings.cpp b/components/config/gamesettings.cpp index e99e31372a..36f0cdad08 100644 --- a/components/config/gamesettings.cpp +++ b/components/config/gamesettings.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -23,8 +24,7 @@ void Config::GameSettings::validatePaths() for (const QString &path : paths) { - QByteArray bytes = path.toUtf8(); - dataDirs.push_back(Files::PathContainer::value_type(std::string(bytes.constData(), bytes.length()))); + dataDirs.emplace_back(path.toStdU32String()); } // Parse the data dirs to convert the tokenized paths @@ -32,7 +32,7 @@ void Config::GameSettings::validatePaths() mDataDirs.clear(); for (auto & dataDir : dataDirs) { - QString path = QString::fromStdWString(dataDir.wstring()); + QString path = QString::fromStdU32String(dataDir.u32string()); QDir dir(path); if (dir.exists()) @@ -51,13 +51,12 @@ void Config::GameSettings::validatePaths() return; dataDirs.clear(); - QByteArray bytes = local.toUtf8(); - dataDirs.push_back(Files::PathContainer::value_type(std::string(bytes.constData(), bytes.length()))); + dataDirs.emplace_back(local.toStdU32String()); mCfgMgr.processPaths(dataDirs, /*basePath=*/""); if (!dataDirs.empty()) { - QString path = QString::fromStdWString(dataDirs.front().wstring()); + QString path = QString::fromStdU32String(dataDirs.front().u32string()); QDir dir(path); if (dir.exists()) @@ -68,8 +67,9 @@ void Config::GameSettings::validatePaths() std::filesystem::path Config::GameSettings::getGlobalDataDir() const { // global data dir may not exists if OpenMW is not installed (ie if run from build directory) - if (std::filesystem::exists(mCfgMgr.getGlobalDataPath())) - return std::filesystem::canonical(mCfgMgr.getGlobalDataPath()); + const auto& path = mCfgMgr.getGlobalDataPath(); + if (std::filesystem::exists(path)) + return std::filesystem::canonical(path); return {}; } diff --git a/components/config/launchersettings.cpp b/components/config/launchersettings.cpp index 2932a211cf..b06203c2a2 100644 --- a/components/config/launchersettings.cpp +++ b/components/config/launchersettings.cpp @@ -119,7 +119,7 @@ void Config::LauncherSettings::setContentList(const GameSettings& gameSettings) } // global and local data directories are not part of any profile - const auto globalDataDir = QString::fromStdWString(gameSettings.getGlobalDataDir().wstring()); + const auto globalDataDir = QString::fromStdU32String(gameSettings.getGlobalDataDir().u32string()); const auto dataLocal = gameSettings.getDataLocal(); dirs.removeAll(globalDataDir); dirs.removeAll(dataLocal); diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index fdd955207f..550bb3eb1c 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -99,7 +99,7 @@ void ConfigurationManager::readConfiguration(bpo::variables_map& variables, while (!extraConfigDirs.empty()) { - std::filesystem::path path = extraConfigDirs.top(); + auto path = extraConfigDirs.top(); extraConfigDirs.pop(); if (alreadyParsedPaths.count(path) > 0) { @@ -116,7 +116,7 @@ void ConfigurationManager::readConfiguration(bpo::variables_map& variables, Log(Debug::Info) << "Skipping previous configs except " << (mActiveConfigPaths.front() / "openmw.cfg") << " due to replace=config in " << (path / "openmw.cfg"); } - mActiveConfigPaths.push_back(path); + mActiveConfigPaths.emplace_back(std::move(path)); if (config) { addExtraConfigDirs(extraConfigDirs, *config); diff --git a/components/settings/parser.cpp b/components/settings/parser.cpp index 1c1eeccc90..3232855989 100644 --- a/components/settings/parser.cpp +++ b/components/settings/parser.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -324,6 +325,6 @@ bool Settings::SettingsFileParser::skipWhiteSpace(size_t& i, std::string& str) [[noreturn]] void Settings::SettingsFileParser::fail(const std::string& message) { std::stringstream error; - error << "Error on line " << mLine << " in " << mFile << ":\n" << message; + error << "Error on line " << mLine << " in " << Files::pathToUnicodeString(mFile) << ":\n" << message; throw std::runtime_error(error.str()); } diff --git a/components/shader/shadermanager.cpp b/components/shader/shadermanager.cpp index 189881fe97..80652eb499 100644 --- a/components/shader/shadermanager.cpp +++ b/components/shader/shadermanager.cpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace Shader { @@ -384,7 +385,7 @@ namespace Shader const std::set& shaderFiles = templateIncludedFiles[templateName]; for (const std::filesystem::path& file : shaderFiles) { - mShaderFiles[file.string()].insert(std::make_pair(templateName, defines)); + mShaderFiles[Files::pathToUnicodeString(file)].insert(std::make_pair(templateName, defines)); } } @@ -426,7 +427,7 @@ namespace Shader stream.open(path); if (stream.fail()) { - Log(Debug::Error) << "Failed to open " << path.string(); + Log(Debug::Error) << "Failed to open " << Files::pathToUnicodeString(path); } std::stringstream buffer; buffer << stream.rdbuf();