Update some settings that accept paths by "std::string" to accept them as "std::filesystem::path" instead.

crashfix_debugdraw
Project579 2 years ago
parent 2df8bfed25
commit 4e428dee12

@ -57,7 +57,7 @@ bool parseOptions (int argc, char** argv, Arguments &info)
hidden.add_options() hidden.add_options()
( "mode,m", bpo::value<std::string>(), "bsatool mode") ( "mode,m", bpo::value<std::string>(), "bsatool mode")
( "input-file,i", bpo::value< std::vector<std::string> >(), "input file") ( "input-file,i", bpo::value< Files::MaybeQuotedPathContainer >(), "input file")
; ;
bpo::positional_options_description p; bpo::positional_options_description p;
@ -114,7 +114,7 @@ bool parseOptions (int argc, char** argv, Arguments &info)
<< desc << std::endl; << desc << std::endl;
return false; return false;
} }
auto inputFiles = variables["input-file"].as< std::vector<Files::MaybeQuotedPath> >(); 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. info.filename = inputFiles[0].u8string(); // This call to u8string is redundant, but required to build on MSVC 14.26 due to implementation bugs.

@ -85,7 +85,7 @@ bool parseOptions (int argc, char** argv, Arguments &info)
hidden.add_options() hidden.add_options()
( "mode,m", bpo::value<std::string>(), "esmtool mode") ( "mode,m", bpo::value<std::string>(), "esmtool mode")
( "input-file,i", bpo::value< std::vector<std::string> >(), "input file") ( "input-file,i", bpo::value< Files::MaybeQuotedPathContainer >(), "input file")
; ;
bpo::positional_options_description p; bpo::positional_options_description p;
@ -156,7 +156,7 @@ bool parseOptions (int argc, char** argv, Arguments &info)
return false; return false;
}*/ }*/
const auto inputFiles = variables["input-file"].as< std::vector<Files::MaybeQuotedPath> >(); 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. 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) 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. info.outname = inputFiles[1].u8string(); // This call to u8string is redundant, but required to build on MSVC 14.26 due to implementation bugs.

@ -18,8 +18,8 @@ int main(int argc, char** argv)
bpo::positional_options_description p_desc; bpo::positional_options_description p_desc;
desc.add_options() desc.add_options()
("help,h", "produce help message") ("help,h", "produce help message")
("mwsave,m", bpo::value<std::string>(), "morrowind .ess save file") ("mwsave,m", bpo::value<Files::MaybeQuotedPath>(), "morrowind .ess save file")
("output,o", bpo::value<std::string>(), "output file (.omwsave)") ("output,o", bpo::value<Files::MaybeQuotedPath>(), "output file (.omwsave)")
("compare,c", "compare two .ess files") ("compare,c", "compare two .ess files")
("encoding", boost::program_options::value<std::string>()->default_value("win1252"), "encoding of the save file") ("encoding", boost::program_options::value<std::string>()->default_value("win1252"), "encoding of the save file")
; ;
@ -45,8 +45,8 @@ int main(int argc, char** argv)
Files::ConfigurationManager cfgManager(true); Files::ConfigurationManager cfgManager(true);
cfgManager.readConfiguration(variables, desc); cfgManager.readConfiguration(variables, desc);
std::string essFile = variables["mwsave"].as<std::string>(); const auto essFile = variables["mwsave"].as<Files::MaybeQuotedPath>();
std::string outputFile = variables["output"].as<std::string>(); const auto outputFile = variables["output"].as<Files::MaybeQuotedPath>();
std::string encoding = variables["encoding"].as<std::string>(); std::string encoding = variables["encoding"].as<std::string>();
ESSImport::Importer importer(essFile, outputFile, encoding); ESSImport::Importer importer(essFile, outputFile, encoding);
@ -55,9 +55,10 @@ int main(int argc, char** argv)
importer.compare(); importer.compare();
else else
{ {
const std::string& ext = ".omwsave"; static constexpr std::u8string_view ext{u8".omwsave"};
if (std::filesystem::exists(std::filesystem::path(outputFile)) const auto length = outputFile.native().size();
&& (outputFile.size() < ext.size() || outputFile.substr(outputFile.size()-ext.size()) != ext)) 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?"); throw std::runtime_error("Output file already exists and does not end in .omwsave. Did you mean to use --compare?");
} }

@ -6,6 +6,8 @@
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <components/files/configurationmanager.hpp>
namespace bpo = boost::program_options; namespace bpo = boost::program_options;
namespace sfs = std::filesystem; namespace sfs = std::filesystem;
@ -61,9 +63,9 @@ int wmain(int argc, wchar_t *wargv[]) {
desc.add_options() desc.add_options()
("help,h", "produce help message") ("help,h", "produce help message")
("verbose,v", "verbose output") ("verbose,v", "verbose output")
("ini,i", bpo::value<std::string>(), "morrowind.ini file") ("ini,i", bpo::value<Files::MaybeQuotedPath>(), "morrowind.ini file")
("cfg,c", bpo::value<std::string>(), "openmw.cfg file") ("cfg,c", bpo::value<Files::MaybeQuotedPath>(), "openmw.cfg file")
("output,o", bpo::value<std::string>()->default_value(""), "openmw.cfg file") ("output,o", bpo::value<Files::MaybeQuotedPath>()->default_value({}), "openmw.cfg file")
("game-files,g", "import esm and esp files") ("game-files,g", "import esm and esp files")
("fonts,f", "import bitmap fonts") ("fonts,f", "import bitmap fonts")
("no-archives,A", "disable bsa archives import") ("no-archives,A", "disable bsa archives import")
@ -91,13 +93,13 @@ int wmain(int argc, wchar_t *wargv[]) {
bpo::notify(vm); bpo::notify(vm);
std::filesystem::path iniFile(vm["ini"].as<std::string>()); std::filesystem::path iniFile(vm["ini"].as<Files::MaybeQuotedPath>());
std::filesystem::path cfgFile(vm["cfg"].as<std::string>()); std::filesystem::path cfgFile(vm["cfg"].as<Files::MaybeQuotedPath>());
// if no output is given, write back to cfg file // if no output is given, write back to cfg file
std::string outputFile(vm["output"].as<std::string>()); std::string outputFile(vm["output"].as<Files::MaybeQuotedPath>());
if(vm["output"].defaulted()) { if(vm["output"].defaulted()) {
outputFile = vm["cfg"].as<std::string>(); outputFile = vm["cfg"].as<Files::MaybeQuotedPath>();
} }
if(!std::filesystem::exists(iniFile)) { if(!std::filesystem::exists(iniFile)) {

@ -77,7 +77,7 @@ bool parseOptions (int argc, char** argv, std::vector<Files::MaybeQuotedPath> &f
"Allowed options"); "Allowed options");
desc.add_options() desc.add_options()
("help,h", "print help message.") ("help,h", "print help message.")
("input-file", bpo::value< std::vector<Files::MaybeQuotedPath> >(), "input file") ("input-file", bpo::value< Files::MaybeQuotedPathContainer >(), "input file")
; ;
//Default option if none provided //Default option if none provided
@ -98,7 +98,7 @@ bool parseOptions (int argc, char** argv, std::vector<Files::MaybeQuotedPath> &f
} }
if (variables.count("input-file")) if (variables.count("input-file"))
{ {
files = variables["input-file"].as< std::vector<Files::MaybeQuotedPath> >(); files = variables["input-file"].as< Files::MaybeQuotedPathContainer >();
return true; return true;
} }
} }

Loading…
Cancel
Save