1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-10 03:39:55 +00:00

Upgraded "input-file" command line option to Files::MaybeQuotedPath from std::string to allow unicode characters on Windows.

This commit is contained in:
Project579 2022-06-20 20:48:06 +02:00
parent e5c417c968
commit 6bf4c7a04f
3 changed files with 26 additions and 22 deletions

View File

@ -8,6 +8,7 @@
#include <components/bsa/compressedbsafile.hpp>
#include <components/misc/strings/algorithm.hpp>
#include <components/files/configurationmanager.hpp>
#define BSATOOL_VERSION 1.1
@ -112,37 +113,39 @@ bool parseOptions (int argc, char** argv, Arguments &info)
<< desc << std::endl;
return false;
}
info.filename = variables["input-file"].as< std::vector<std::string> >()[0]; //TODO(Project579): This will probably break in windows with unicode paths
auto inputFiles = variables["input-file"].as< std::vector<Files::MaybeQuotedPath> >();
info.filename = inputFiles[0];
// Default output to the working directory
info.outdir = ".";
if (info.mode == "extract")
{
if (variables["input-file"].as< std::vector<std::string> >().size() < 2)
if (inputFiles.size() < 2)
{
std::cout << "\nERROR: file to extract unspecified\n\n"
<< desc << std::endl;
return false;
}
if (variables["input-file"].as< std::vector<std::string> >().size() > 1)
info.extractfile = variables["input-file"].as< std::vector<std::string> >()[1];
if (variables["input-file"].as< std::vector<std::string> >().size() > 2)
info.outdir = variables["input-file"].as< std::vector<std::string> >()[2];
if (inputFiles.size() > 1)
info.extractfile = inputFiles[1];
if (inputFiles.size() > 2)
info.outdir = inputFiles[2];
}
else if (info.mode == "add")
{
if (variables["input-file"].as< std::vector<std::string> >().size() < 1)
if (inputFiles.empty())
{
std::cout << "\nERROR: file to add unspecified\n\n"
<< desc << std::endl;
return false;
}
if (variables["input-file"].as< std::vector<std::string> >().size() > 1)
info.addfile = variables["input-file"].as< std::vector<std::string> >()[1];
if (inputFiles.size() > 1)
info.addfile = inputFiles[1];
}
else if (variables["input-file"].as< std::vector<std::string> >().size() > 1)
info.outdir = variables["input-file"].as< std::vector<std::string> >()[1];
else if (inputFiles.size() > 1)
info.outdir = inputFiles[1];
info.longformat = variables.count("long") != 0;
info.fullpath = variables.count("full-path") != 0;

View File

@ -17,6 +17,7 @@
#include <components/esm/format.hpp>
#include <components/files/openfile.hpp>
#include <components/misc/strings/algorithm.hpp>
#include <components/files/configurationmanager.hpp>
#include "record.hpp"
#include "labels.hpp"
@ -154,9 +155,10 @@ bool parseOptions (int argc, char** argv, Arguments &info)
return false;
}*/
info.filename = variables["input-file"].as< std::vector<std::filesystem::path> >()[0];
if (variables["input-file"].as< std::vector<std::string> >().size() > 1)
info.outname = variables["input-file"].as< std::vector<std::filesystem::path> >()[1];
const auto inputFiles = variables["input-file"].as< std::vector<Files::MaybeQuotedPath> >();
info.filename = inputFiles[0];
if (inputFiles.size() > 1)
info.outname = inputFiles[1];
if (const auto it = variables.find("raw"); it != variables.end())
info.mRawFormat = ESM::parseFormat(it->second.as<std::string>());

View File

@ -9,6 +9,7 @@
#include <components/vfs/manager.hpp>
#include <components/vfs/bsaarchive.hpp>
#include <components/vfs/filesystemarchive.hpp>
#include <components/files/configurationmanager.hpp>
#include <boost/program_options.hpp>
@ -66,7 +67,7 @@ void readVFS(std::unique_ptr<VFS::Archive>&& anArchive, const std::filesystem::p
}
}
bool parseOptions (int argc, char** argv, std::vector<std::string>& files)
bool parseOptions (int argc, char** argv, std::vector<Files::MaybeQuotedPath> &files)
{
bpo::options_description desc("Ensure that OpenMW can use the provided NIF and BSA files\n\n"
"Usages:\n"
@ -75,7 +76,7 @@ bool parseOptions (int argc, char** argv, std::vector<std::string>& files)
"Allowed options");
desc.add_options()
("help,h", "print help message.")
("input-file", bpo::value< std::vector<std::filesystem::path> >(), "input file")
("input-file", bpo::value< std::vector<Files::MaybeQuotedPath> >(), "input file")
;
//Default option if none provided
@ -96,7 +97,7 @@ bool parseOptions (int argc, char** argv, std::vector<std::string>& files)
}
if (variables.count("input-file"))
{
files = variables["input-file"].as< std::vector<std::string> >();
files = variables["input-file"].as< std::vector<Files::MaybeQuotedPath> >();
return true;
}
}
@ -114,18 +115,16 @@ bool parseOptions (int argc, char** argv, std::vector<std::string>& files)
int main(int argc, char **argv)
{
std::vector<std::string> files;
std::vector<Files::MaybeQuotedPath> files;
if(!parseOptions (argc, argv, files))
return 1;
Nif::NIFFile::setLoadUnsupportedFiles(true);
// std::cout << "Reading Files" << std::endl;
for(const auto& name : files)
for(const auto& path : files)
{
try
{
const std::filesystem::path path(name); //TODO(Project579): This will probably break in windows with unicode paths
if(isNIF(path))
{
//std::cout << "Decoding: " << name << std::endl;
@ -143,7 +142,7 @@ int main(int argc, char **argv)
}
else
{
std::cerr << "ERROR: \"" << path << "\" is not a nif file, bsa file, or directory!" << std::endl;
std::cerr << "ERROR: \"" << path << "\" is not a nif file, bsa file, or directory!" << std::endl; //TODO(Project579): This will probably break in windows with unicode paths
}
}
catch (std::exception& e)