From 4e428dee125109557976e5f4280fdd3d74ec7579 Mon Sep 17 00:00:00 2001 From: Project579 Date: Sat, 6 Aug 2022 18:09:50 +0200 Subject: [PATCH] Update some settings that accept paths by "std::string" to accept them as "std::filesystem::path" instead. --- apps/bsatool/bsatool.cpp | 4 ++-- apps/esmtool/esmtool.cpp | 4 ++-- apps/essimporter/main.cpp | 15 ++++++++------- apps/mwiniimporter/main.cpp | 16 +++++++++------- apps/niftest/niftest.cpp | 4 ++-- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/apps/bsatool/bsatool.cpp b/apps/bsatool/bsatool.cpp index 26fa981cb3..3af5e08ecb 100644 --- a/apps/bsatool/bsatool.cpp +++ b/apps/bsatool/bsatool.cpp @@ -57,7 +57,7 @@ bool parseOptions (int argc, char** argv, Arguments &info) hidden.add_options() ( "mode,m", bpo::value(), "bsatool mode") - ( "input-file,i", bpo::value< std::vector >(), "input file") + ( "input-file,i", bpo::value< Files::MaybeQuotedPathContainer >(), "input file") ; bpo::positional_options_description p; @@ -114,7 +114,7 @@ bool parseOptions (int argc, char** argv, Arguments &info) << desc << std::endl; return false; } - auto inputFiles = variables["input-file"].as< std::vector >(); + auto inputFiles = variables["input-file"].as< Files::MaybeQuotedPathContainer >(); info.filename = inputFiles[0].u8string(); // This call to u8string is redundant, but required to build on MSVC 14.26 due to implementation bugs. diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 74e471b948..dab212c076 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -85,7 +85,7 @@ bool parseOptions (int argc, char** argv, Arguments &info) hidden.add_options() ( "mode,m", bpo::value(), "esmtool mode") - ( "input-file,i", bpo::value< std::vector >(), "input file") + ( "input-file,i", bpo::value< Files::MaybeQuotedPathContainer >(), "input file") ; bpo::positional_options_description p; @@ -156,7 +156,7 @@ bool parseOptions (int argc, char** argv, Arguments &info) return false; }*/ - const auto inputFiles = variables["input-file"].as< std::vector >(); + const auto inputFiles = variables["input-file"].as< Files::MaybeQuotedPathContainer >(); info.filename = inputFiles[0].u8string(); // This call to u8string is redundant, but required to build on MSVC 14.26 due to implementation bugs. if (inputFiles.size() > 1) info.outname = inputFiles[1].u8string(); // This call to u8string is redundant, but required to build on MSVC 14.26 due to implementation bugs. diff --git a/apps/essimporter/main.cpp b/apps/essimporter/main.cpp index 9517df2d2a..56c3828c1c 100644 --- a/apps/essimporter/main.cpp +++ b/apps/essimporter/main.cpp @@ -18,8 +18,8 @@ int main(int argc, char** argv) bpo::positional_options_description p_desc; desc.add_options() ("help,h", "produce help message") - ("mwsave,m", bpo::value(), "morrowind .ess save file") - ("output,o", bpo::value(), "output file (.omwsave)") + ("mwsave,m", bpo::value(), "morrowind .ess save file") + ("output,o", bpo::value(), "output file (.omwsave)") ("compare,c", "compare two .ess files") ("encoding", boost::program_options::value()->default_value("win1252"), "encoding of the save file") ; @@ -45,8 +45,8 @@ int main(int argc, char** argv) Files::ConfigurationManager cfgManager(true); cfgManager.readConfiguration(variables, desc); - std::string essFile = variables["mwsave"].as(); - std::string outputFile = variables["output"].as(); + const auto essFile = variables["mwsave"].as(); + const auto outputFile = variables["output"].as(); std::string encoding = variables["encoding"].as(); ESSImport::Importer importer(essFile, outputFile, encoding); @@ -55,9 +55,10 @@ int main(int argc, char** argv) importer.compare(); else { - const std::string& ext = ".omwsave"; - if (std::filesystem::exists(std::filesystem::path(outputFile)) - && (outputFile.size() < ext.size() || outputFile.substr(outputFile.size()-ext.size()) != ext)) + static constexpr std::u8string_view ext{u8".omwsave"}; + const auto length = outputFile.native().size(); + if (std::filesystem::exists(outputFile) + && (length < ext.size() || outputFile.u8string().substr(length-ext.size()) != ext)) { throw std::runtime_error("Output file already exists and does not end in .omwsave. Did you mean to use --compare?"); } diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 2de80ffb96..ed6ff907f4 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -6,6 +6,8 @@ #include +#include + namespace bpo = boost::program_options; namespace sfs = std::filesystem; @@ -61,9 +63,9 @@ int wmain(int argc, wchar_t *wargv[]) { desc.add_options() ("help,h", "produce help message") ("verbose,v", "verbose output") - ("ini,i", bpo::value(), "morrowind.ini file") - ("cfg,c", bpo::value(), "openmw.cfg file") - ("output,o", bpo::value()->default_value(""), "openmw.cfg file") + ("ini,i", bpo::value(), "morrowind.ini file") + ("cfg,c", bpo::value(), "openmw.cfg file") + ("output,o", bpo::value()->default_value({}), "openmw.cfg file") ("game-files,g", "import esm and esp files") ("fonts,f", "import bitmap fonts") ("no-archives,A", "disable bsa archives import") @@ -91,13 +93,13 @@ int wmain(int argc, wchar_t *wargv[]) { bpo::notify(vm); - std::filesystem::path iniFile(vm["ini"].as()); - std::filesystem::path cfgFile(vm["cfg"].as()); + std::filesystem::path iniFile(vm["ini"].as()); + std::filesystem::path cfgFile(vm["cfg"].as()); // if no output is given, write back to cfg file - std::string outputFile(vm["output"].as()); + std::string outputFile(vm["output"].as()); if(vm["output"].defaulted()) { - outputFile = vm["cfg"].as(); + outputFile = vm["cfg"].as(); } if(!std::filesystem::exists(iniFile)) { diff --git a/apps/niftest/niftest.cpp b/apps/niftest/niftest.cpp index 4919b923c9..9328c4f2c6 100644 --- a/apps/niftest/niftest.cpp +++ b/apps/niftest/niftest.cpp @@ -77,7 +77,7 @@ bool parseOptions (int argc, char** argv, std::vector &f "Allowed options"); desc.add_options() ("help,h", "print help message.") - ("input-file", bpo::value< std::vector >(), "input file") + ("input-file", bpo::value< Files::MaybeQuotedPathContainer >(), "input file") ; //Default option if none provided @@ -98,7 +98,7 @@ bool parseOptions (int argc, char** argv, std::vector &f } if (variables.count("input-file")) { - files = variables["input-file"].as< std::vector >(); + files = variables["input-file"].as< Files::MaybeQuotedPathContainer >(); return true; } }