Replace boost::filesystem with std::filesystem

This allows us to use a header-only copy of Boost
This commit is contained in:
Daniel Wolf 2021-06-18 22:00:01 +02:00
parent 74822c4a84
commit 8a94fb7db0
29 changed files with 83 additions and 93 deletions

View File

@ -65,7 +65,7 @@ set(Boost_USE_STATIC_LIBS ON) # Use static libs
set(Boost_USE_MULTITHREADED ON) # Enable multithreading support set(Boost_USE_MULTITHREADED ON) # Enable multithreading support
set(Boost_USE_STATIC_RUNTIME ON) # Use static C++ runtime set(Boost_USE_STATIC_RUNTIME ON) # Use static C++ runtime
set(Boost_NO_BOOST_CMAKE ON) # Workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/18865 set(Boost_NO_BOOST_CMAKE ON) # Workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/18865
find_package(Boost 1.54 REQUIRED COMPONENTS filesystem locale system) find_package(Boost 1.54 REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
link_libraries(${Boost_LIBRARIES}) # Just about every project needs Boost link_libraries(${Boost_LIBRARIES}) # Just about every project needs Boost

View File

@ -6,7 +6,7 @@
#include <format.h> #include <format.h>
#include "tools/fileTools.h" #include "tools/fileTools.h"
using boost::filesystem::path; using std::filesystem::path;
using std::vector; using std::vector;
using std::make_shared; using std::make_shared;
using std::ifstream; using std::ifstream;

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "AudioClip.h" #include "AudioClip.h"
#include <boost/filesystem/path.hpp> #include <filesystem>
class OggVorbisFileReader : public AudioClip { class OggVorbisFileReader : public AudioClip {
public: public:
OggVorbisFileReader(const boost::filesystem::path& filePath); OggVorbisFileReader(const std::filesystem::path& filePath);
std::unique_ptr<AudioClip> clone() const override; std::unique_ptr<AudioClip> clone() const override;
int getSampleRate() const override { return sampleRate; } int getSampleRate() const override { return sampleRate; }
size_type size() const override { return sampleCount; } size_type size() const override { return sampleCount; }
@ -13,7 +13,7 @@ public:
private: private:
SampleReader createUnsafeSampleReader() const override; SampleReader createUnsafeSampleReader() const override;
boost::filesystem::path filePath; std::filesystem::path filePath;
int sampleRate; int sampleRate;
int channelCount; int channelCount;
size_type sampleCount; size_type sampleCount;

View File

@ -12,7 +12,7 @@ using namespace little_endian;
using std::unique_ptr; using std::unique_ptr;
using std::make_unique; using std::make_unique;
using std::make_shared; using std::make_shared;
using boost::filesystem::path; using std::filesystem::path;
#define INT24_MIN (-8388608) #define INT24_MIN (-8388608)
#define INT24_MAX 8388607 #define INT24_MAX 8388607

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <boost/filesystem/path.hpp> #include <filesystem>
#include "AudioClip.h" #include "AudioClip.h"
enum class SampleFormat { enum class SampleFormat {
@ -12,7 +12,7 @@ enum class SampleFormat {
class WaveFileReader : public AudioClip { class WaveFileReader : public AudioClip {
public: public:
WaveFileReader(const boost::filesystem::path& filePath); WaveFileReader(const std::filesystem::path& filePath);
std::unique_ptr<AudioClip> clone() const override; std::unique_ptr<AudioClip> clone() const override;
int getSampleRate() const override; int getSampleRate() const override;
size_type size() const override; size_type size() const override;
@ -29,7 +29,7 @@ private:
std::streampos dataOffset; std::streampos dataOffset;
}; };
boost::filesystem::path filePath; std::filesystem::path filePath;
WaveFormatInfo formatInfo; WaveFormatInfo formatInfo;
}; };

View File

@ -4,7 +4,7 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "OggVorbisFileReader.h" #include "OggVorbisFileReader.h"
using boost::filesystem::path; using std::filesystem::path;
using std::string; using std::string;
using std::runtime_error; using std::runtime_error;
using fmt::format; using fmt::format;
@ -12,7 +12,7 @@ using fmt::format;
std::unique_ptr<AudioClip> createAudioFileClip(path filePath) { std::unique_ptr<AudioClip> createAudioFileClip(path filePath) {
try { try {
const string extension = const string extension =
boost::algorithm::to_lower_copy(boost::filesystem::extension(filePath)); boost::algorithm::to_lower_copy(filePath.extension().u8string());
if (extension == ".wav") { if (extension == ".wav") {
return std::make_unique<WaveFileReader>(filePath); return std::make_unique<WaveFileReader>(filePath);
} }
@ -24,6 +24,6 @@ std::unique_ptr<AudioClip> createAudioFileClip(path filePath) {
extension extension
)); ));
} catch (...) { } catch (...) {
std::throw_with_nested(runtime_error(format("Could not open sound file {}.", filePath))); std::throw_with_nested(runtime_error(format("Could not open sound file {}.", filePath.u8string())));
} }
} }

View File

@ -2,6 +2,6 @@
#include <memory> #include <memory>
#include "AudioClip.h" #include "AudioClip.h"
#include <boost/filesystem.hpp> #include <filesystem>
std::unique_ptr<AudioClip> createAudioFileClip(boost::filesystem::path filePath); std::unique_ptr<AudioClip> createAudioFileClip(std::filesystem::path filePath);

View File

@ -2,19 +2,19 @@
#include "core/Shape.h" #include "core/Shape.h"
#include "time/ContinuousTimeline.h" #include "time/ContinuousTimeline.h"
#include <boost/filesystem/path.hpp> #include <filesystem>
class ExporterInput { class ExporterInput {
public: public:
ExporterInput( ExporterInput(
const boost::filesystem::path& inputFilePath, const std::filesystem::path& inputFilePath,
const JoiningContinuousTimeline<Shape>& animation, const JoiningContinuousTimeline<Shape>& animation,
const ShapeSet& targetShapeSet) : const ShapeSet& targetShapeSet) :
inputFilePath(inputFilePath), inputFilePath(inputFilePath),
animation(animation), animation(animation),
targetShapeSet(targetShapeSet) {} targetShapeSet(targetShapeSet) {}
boost::filesystem::path inputFilePath; std::filesystem::path inputFilePath;
JoiningContinuousTimeline<Shape> animation; JoiningContinuousTimeline<Shape> animation;
ShapeSet targetShapeSet; ShapeSet targetShapeSet;
}; };

View File

@ -1,7 +1,6 @@
#include "JsonExporter.h" #include "JsonExporter.h"
#include "exporterTools.h" #include "exporterTools.h"
#include "tools/stringTools.h" #include "tools/stringTools.h"
#include <boost/filesystem.hpp>
using std::string; using std::string;
@ -11,7 +10,7 @@ void JsonExporter::exportAnimation(const ExporterInput& input, std::ostream& out
// the formatting. // the formatting.
outputStream << "{\n"; outputStream << "{\n";
outputStream << " \"metadata\": {\n"; outputStream << " \"metadata\": {\n";
outputStream << " \"soundFile\": \"" << escapeJsonString(absolute(input.inputFilePath).string()) << "\",\n"; outputStream << " \"soundFile\": \"" << escapeJsonString(absolute(input.inputFilePath).u8string()) << "\",\n";
outputStream << " \"duration\": " << formatDuration(input.animation.getRange().getDuration()) << "\n"; outputStream << " \"duration\": " << formatDuration(input.animation.getRange().getDuration()) << "\n";
outputStream << " },\n"; outputStream << " },\n";
outputStream << " \"mouthCues\": [\n"; outputStream << " \"mouthCues\": [\n";

View File

@ -3,7 +3,6 @@
#include <boost/property_tree/xml_parser.hpp> #include <boost/property_tree/xml_parser.hpp>
#include <boost/version.hpp> #include <boost/version.hpp>
#include "exporterTools.h" #include "exporterTools.h"
#include <boost/filesystem.hpp>
using std::string; using std::string;
using boost::property_tree::ptree; using boost::property_tree::ptree;
@ -12,7 +11,7 @@ void XmlExporter::exportAnimation(const ExporterInput& input, std::ostream& outp
ptree tree; ptree tree;
// Add metadata // Add metadata
tree.put("rhubarbResult.metadata.soundFile", absolute(input.inputFilePath).string()); tree.put("rhubarbResult.metadata.soundFile", absolute(input.inputFilePath).u8string());
tree.put( tree.put(
"rhubarbResult.metadata.duration", "rhubarbResult.metadata.duration",
formatDuration(input.animation.getRange().getDuration()) formatDuration(input.animation.getRange().getDuration())

View File

@ -6,7 +6,7 @@
using boost::optional; using boost::optional;
using std::string; using std::string;
using boost::filesystem::path; using std::filesystem::path;
JoiningContinuousTimeline<Shape> animateAudioClip( JoiningContinuousTimeline<Shape> animateAudioClip(
const AudioClip& audioClip, const AudioClip& audioClip,

View File

@ -4,7 +4,7 @@
#include "time/ContinuousTimeline.h" #include "time/ContinuousTimeline.h"
#include "audio/AudioClip.h" #include "audio/AudioClip.h"
#include "tools/progress.h" #include "tools/progress.h"
#include <boost/filesystem.hpp> #include <filesystem>
#include "animation/targetShapeSet.h" #include "animation/targetShapeSet.h"
#include "recognition/Recognizer.h" #include "recognition/Recognizer.h"
@ -17,7 +17,7 @@ JoiningContinuousTimeline<Shape> animateAudioClip(
ProgressSink& progressSink); ProgressSink& progressSink);
JoiningContinuousTimeline<Shape> animateWaveFile( JoiningContinuousTimeline<Shape> animateWaveFile(
boost::filesystem::path filePath, std::filesystem::path filePath,
const boost::optional<std::string>& dialog, const boost::optional<std::string>& dialog,
const Recognizer& recognizer, const Recognizer& recognizer,
const ShapeSet& targetShapeSet, const ShapeSet& targetShapeSet,

View File

@ -17,9 +17,9 @@ static lambda_unique_ptr<ps_decoder_t> createDecoder(optional<std::string> dialo
cmd_ln_init( cmd_ln_init(
nullptr, ps_args(), true, nullptr, ps_args(), true,
// Set acoustic model // Set acoustic model
"-hmm", (getSphinxModelDirectory() / "acoustic-model").string().c_str(), "-hmm", (getSphinxModelDirectory() / "acoustic-model").u8string().c_str(),
// Set phonetic language model // Set phonetic language model
"-allphone", (getSphinxModelDirectory() / "en-us-phone.lm.bin").string().c_str(), "-allphone", (getSphinxModelDirectory() / "en-us-phone.lm.bin").u8string().c_str(),
"-allphone_ci", "yes", "-allphone_ci", "yes",
// Set language model probability weight. // Set language model probability weight.
// Low values (<= 0.4) can lead to fluttering animation. // Low values (<= 0.4) can lead to fluttering animation.

View File

@ -20,7 +20,7 @@ using std::unique_ptr;
using std::string; using std::string;
using std::vector; using std::vector;
using std::map; using std::map;
using boost::filesystem::path; using std::filesystem::path;
using std::regex; using std::regex;
using std::regex_replace; using std::regex_replace;
using boost::optional; using boost::optional;
@ -58,10 +58,10 @@ void addMissingDictionaryWords(const vector<string>& words, ps_decoder_t& decode
lambda_unique_ptr<ngram_model_t> createDefaultLanguageModel(ps_decoder_t& decoder) { lambda_unique_ptr<ngram_model_t> createDefaultLanguageModel(ps_decoder_t& decoder) {
path modelPath = getSphinxModelDirectory() / "en-us.lm.bin"; path modelPath = getSphinxModelDirectory() / "en-us.lm.bin";
lambda_unique_ptr<ngram_model_t> result( lambda_unique_ptr<ngram_model_t> result(
ngram_model_read(decoder.config, modelPath.string().c_str(), NGRAM_AUTO, decoder.lmath), ngram_model_read(decoder.config, modelPath.u8string().c_str(), NGRAM_AUTO, decoder.lmath),
[](ngram_model_t* lm) { ngram_model_free(lm); }); [](ngram_model_t* lm) { ngram_model_free(lm); });
if (!result) { if (!result) {
throw runtime_error(fmt::format("Error reading language model from {}.", modelPath)); throw runtime_error(fmt::format("Error reading language model from {}.", modelPath.u8string()));
} }
return result; return result;
@ -120,9 +120,9 @@ static lambda_unique_ptr<ps_decoder_t> createDecoder(optional<std::string> dialo
cmd_ln_init( cmd_ln_init(
nullptr, ps_args(), true, nullptr, ps_args(), true,
// Set acoustic model // Set acoustic model
"-hmm", (getSphinxModelDirectory() / "acoustic-model").string().c_str(), "-hmm", (getSphinxModelDirectory() / "acoustic-model").u8string().c_str(),
// Set pronunciation dictionary // Set pronunciation dictionary
"-dict", (getSphinxModelDirectory() / "cmudict-en-us.dict").string().c_str(), "-dict", (getSphinxModelDirectory() / "cmudict-en-us.dict").u8string().c_str(),
// Add noise against zero silence // Add noise against zero silence
// (see http://cmusphinx.sourceforge.net/wiki/faq#qwhy_my_accuracy_is_poor) // (see http://cmusphinx.sourceforge.net/wiki/faq#qwhy_my_accuracy_is_poor)
"-dither", "yes", "-dither", "yes",

View File

@ -5,7 +5,7 @@
#include <map> #include <map>
#include <tuple> #include <tuple>
#include "tools/platformTools.h" #include "tools/platformTools.h"
#include <boost/filesystem/fstream.hpp> #include <fstream>
#include "core/appInfo.h" #include "core/appInfo.h"
#include <cmath> #include <cmath>
#include <gsl_util.h> #include <gsl_util.h>
@ -17,7 +17,7 @@ using std::map;
using std::tuple; using std::tuple;
using std::get; using std::get;
using std::endl; using std::endl;
using boost::filesystem::path; using std::filesystem::path;
using Unigram = string; using Unigram = string;
using Bigram = tuple<string, string>; using Bigram = tuple<string, string>;
@ -151,7 +151,7 @@ void createLanguageModelFile(const vector<string>& words, const path& filePath)
map<Bigram, double> bigramBackoffWeights = map<Bigram, double> bigramBackoffWeights =
getBigramBackoffWeights(bigramCounts, bigramProbabilities, trigramCounts, discountMass); getBigramBackoffWeights(bigramCounts, bigramProbabilities, trigramCounts, discountMass);
boost::filesystem::ofstream file(filePath); std::ofstream file(filePath);
file << "Generated by " << appName << " " << appVersion << endl << endl; file << "Generated by " << appName << " " << appVersion << endl << endl;
file << "\\data\\" << endl; file << "\\data\\" << endl;
@ -193,9 +193,9 @@ lambda_unique_ptr<ngram_model_t> createLanguageModel(
) { ) {
path tempFilePath = getTempFilePath(); path tempFilePath = getTempFilePath();
createLanguageModelFile(words, tempFilePath); createLanguageModelFile(words, tempFilePath);
auto deleteTempFile = gsl::finally([&]() { boost::filesystem::remove(tempFilePath); }); auto deleteTempFile = gsl::finally([&]() { std::filesystem::remove(tempFilePath); });
return lambda_unique_ptr<ngram_model_t>( return lambda_unique_ptr<ngram_model_t>(
ngram_model_read(decoder.config, tempFilePath.string().c_str(), NGRAM_ARPA, decoder.lmath), ngram_model_read(decoder.config, tempFilePath.u8string().c_str(), NGRAM_ARPA, decoder.lmath),
[](ngram_model_t* lm) { ngram_model_free(lm); }); [](ngram_model_t* lm) { ngram_model_free(lm); });
} }

View File

@ -19,7 +19,7 @@ using std::invalid_argument;
using std::unique_ptr; using std::unique_ptr;
using std::string; using std::string;
using std::vector; using std::vector;
using boost::filesystem::path; using std::filesystem::path;
using std::regex; using std::regex;
using boost::optional; using boost::optional;
using std::chrono::duration_cast; using std::chrono::duration_cast;

View File

@ -4,7 +4,7 @@
#include "core/Phone.h" #include "core/Phone.h"
#include "audio/AudioClip.h" #include "audio/AudioClip.h"
#include "tools/progress.h" #include "tools/progress.h"
#include <boost/filesystem/path.hpp> #include <filesystem>
extern "C" { extern "C" {
#include <pocketsphinx.h> #include <pocketsphinx.h>
@ -32,7 +32,7 @@ BoundedTimeline<Phone> recognizePhones(
constexpr int sphinxSampleRate = 16000; constexpr int sphinxSampleRate = 16000;
const boost::filesystem::path& getSphinxModelDirectory(); const std::filesystem::path& getSphinxModelDirectory();
JoiningTimeline<void> getNoiseSounds(TimeRange utteranceTimeRange, const Timeline<Phone>& phones); JoiningTimeline<void> getNoiseSounds(TimeRange utteranceTimeRange, const Timeline<Phone>& phones);

View File

@ -9,10 +9,9 @@
#include <gsl_util.h> #include <gsl_util.h>
#include "exporters/Exporter.h" #include "exporters/Exporter.h"
#include "time/ContinuousTimeline.h" #include "time/ContinuousTimeline.h"
#include <boost/filesystem/operations.hpp>
#include "tools/stringTools.h" #include "tools/stringTools.h"
#include <boost/range/adaptor/transformed.hpp> #include <boost/range/adaptor/transformed.hpp>
#include <boost/filesystem/fstream.hpp> #include <fstream>
#include "tools/parallel.h" #include "tools/parallel.h"
#include "tools/exceptions.h" #include "tools/exceptions.h"
#include "tools/textFiles.h" #include "tools/textFiles.h"
@ -39,7 +38,8 @@ using std::unique_ptr;
using std::make_unique; using std::make_unique;
using std::shared_ptr; using std::shared_ptr;
using std::make_shared; using std::make_shared;
using boost::filesystem::path; using std::filesystem::path;
using std::filesystem::u8path;
using boost::adaptors::transformed; using boost::adaptors::transformed;
using boost::optional; using boost::optional;
@ -64,7 +64,7 @@ namespace TCLAP {
} }
shared_ptr<logging::Sink> createFileSink(const path& path, logging::Level minLevel) { shared_ptr<logging::Sink> createFileSink(const path& path, logging::Level minLevel) {
auto file = make_shared<boost::filesystem::ofstream>(); auto file = make_shared<std::ofstream>();
file->exceptions(std::ifstream::failbit | std::ifstream::badbit); file->exceptions(std::ifstream::failbit | std::ifstream::badbit);
file->open(path); file->open(path);
auto FileSink = auto FileSink =
@ -121,9 +121,8 @@ int main(int platformArgc, char* platformArgv[]) {
shared_ptr<logging::Sink> defaultSink = make_shared<NiceStderrSink>(defaultMinStderrLevel); shared_ptr<logging::Sink> defaultSink = make_shared<NiceStderrSink>(defaultMinStderrLevel);
logging::addSink(defaultSink); logging::addSink(defaultSink);
// Use UTF-8 throughout // Make sure the console uses UTF-8 on all platforms including Windows
useUtf8ForConsole(); useUtf8ForConsole();
useUtf8ForBoostFilesystem();
// Convert command-line arguments to UTF-8 // Convert command-line arguments to UTF-8
const vector<string> args = argsToUtf8(platformArgc, platformArgv); const vector<string> args = argsToUtf8(platformArgc, platformArgv);
@ -229,7 +228,7 @@ int main(int platformArgc, char* platformArgv[]) {
logging::removeSink(defaultSink); logging::removeSink(defaultSink);
// ... to log file // ... to log file
if (logFileName.isSet()) { if (logFileName.isSet()) {
auto fileSink = createFileSink(path(logFileName.getValue()), logLevel.getValue()); auto fileSink = createFileSink(u8path(logFileName.getValue()), logLevel.getValue());
logging::addSink(fileSink); logging::addSink(fileSink);
} }
@ -237,7 +236,7 @@ int main(int platformArgc, char* platformArgv[]) {
if (maxThreadCount.getValue() < 1) { if (maxThreadCount.getValue() < 1) {
throw std::runtime_error("Thread count must be 1 or higher."); throw std::runtime_error("Thread count must be 1 or higher.");
} }
path inputFilePath(inputFileName.getValue()); path inputFilePath = u8path(inputFileName.getValue());
ShapeSet targetShapeSet = getTargetShapeSet(extendedShapes.getValue()); ShapeSet targetShapeSet = getTargetShapeSet(extendedShapes.getValue());
unique_ptr<Exporter> exporter = createExporter( unique_ptr<Exporter> exporter = createExporter(
@ -262,7 +261,7 @@ int main(int platformArgc, char* platformArgv[]) {
JoiningContinuousTimeline<Shape> animation = animateWaveFile( JoiningContinuousTimeline<Shape> animation = animateWaveFile(
inputFilePath, inputFilePath,
dialogFile.isSet() dialogFile.isSet()
? readUtf8File(path(dialogFile.getValue())) ? readUtf8File(u8path(dialogFile.getValue()))
: boost::optional<string>(), : boost::optional<string>(),
*createRecognizer(recognizerType.getValue()), *createRecognizer(recognizerType.getValue()),
targetShapeSet, targetShapeSet,
@ -271,9 +270,9 @@ int main(int platformArgc, char* platformArgv[]) {
logging::info("Done animating."); logging::info("Done animating.");
// Export animation // Export animation
optional<boost::filesystem::ofstream> outputFile; optional<std::ofstream> outputFile;
if (outputFileName.isSet()) { if (outputFileName.isSet()) {
outputFile = boost::in_place(outputFileName.getValue()); outputFile = boost::in_place(u8path(outputFileName.getValue()));
outputFile->exceptions(std::ifstream::failbit | std::ifstream::badbit); outputFile->exceptions(std::ifstream::failbit | std::ifstream::badbit);
} }
ExporterInput exporterInput = ExporterInput(inputFilePath, animation, targetShapeSet); ExporterInput exporterInput = ExporterInput(inputFilePath, animation, targetShapeSet);
@ -284,7 +283,7 @@ int main(int platformArgc, char* platformArgv[]) {
logging::log(SuccessEntry()); logging::log(SuccessEntry());
} catch (...) { } catch (...) {
std::throw_with_nested( std::throw_with_nested(
std::runtime_error(fmt::format("Error processing file {}.", inputFilePath)) std::runtime_error(fmt::format("Error processing file {}.", inputFilePath.u8string()))
); );
} }

View File

@ -7,12 +7,12 @@ SemanticEntry::SemanticEntry(Level level, const string& message) :
Entry(level, message) Entry(level, message)
{} {}
StartEntry::StartEntry(const boost::filesystem::path& inputFilePath) : StartEntry::StartEntry(const std::filesystem::path& inputFilePath) :
SemanticEntry(Level::Info, fmt::format("Application startup. Input file: {}.", inputFilePath)), SemanticEntry(Level::Info, fmt::format("Application startup. Input file: {}.", inputFilePath.u8string())),
inputFilePath(inputFilePath) inputFilePath(inputFilePath)
{} {}
boost::filesystem::path StartEntry::getInputFilePath() const { std::filesystem::path StartEntry::getInputFilePath() const {
return inputFilePath; return inputFilePath;
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "logging/Entry.h" #include "logging/Entry.h"
#include <boost/filesystem/path.hpp> #include <filesystem>
// Marker class for semantic entries // Marker class for semantic entries
class SemanticEntry : public logging::Entry { class SemanticEntry : public logging::Entry {
@ -10,10 +10,10 @@ public:
class StartEntry : public SemanticEntry { class StartEntry : public SemanticEntry {
public: public:
StartEntry(const boost::filesystem::path& inputFilePath); StartEntry(const std::filesystem::path& inputFilePath);
boost::filesystem::path getInputFilePath() const; std::filesystem::path getInputFilePath() const;
private: private:
boost::filesystem::path inputFilePath; std::filesystem::path inputFilePath;
}; };
class ProgressEntry : public SemanticEntry { class ProgressEntry : public SemanticEntry {

View File

@ -24,7 +24,7 @@ void NiceStderrSink::receive(const logging::Entry& entry) {
// the technical log message. // the technical log message.
if (const auto* startEntry = dynamic_cast<const StartEntry*>(&entry)) { if (const auto* startEntry = dynamic_cast<const StartEntry*>(&entry)) {
std::cerr std::cerr
<< fmt::format("Generating lip sync data for {}.", startEntry->getInputFilePath()) << fmt::format("Generating lip sync data for {}.", startEntry->getInputFilePath().u8string())
<< std::endl; << std::endl;
startProgressIndication(); startProgressIndication();
} else if (const auto* progressEntry = dynamic_cast<const ProgressEntry*>(&entry)) { } else if (const auto* progressEntry = dynamic_cast<const ProgressEntry*>(&entry)) {
@ -75,7 +75,7 @@ void QuietStderrSink::receive(const logging::Entry& entry) {
if (quietSoFar) { if (quietSoFar) {
// This is the first message we print. Give a bit of context. // This is the first message we print. Give a bit of context.
const string intro = inputFilePath const string intro = inputFilePath
? fmt::format("{} {} processing file {}:", appName, appVersion, *inputFilePath) ? fmt::format("{} {} processing file {}:", appName, appVersion, inputFilePath->u8string())
: fmt::format("{} {}:", appName, appVersion); : fmt::format("{} {}:", appName, appVersion);
std::cerr << intro << std::endl; std::cerr << intro << std::endl;
quietSoFar = false; quietSoFar = false;
@ -100,7 +100,7 @@ void MachineReadableStderrSink::receive(const logging::Entry& entry) {
optional<string> line; optional<string> line;
if (dynamic_cast<const SemanticEntry*>(&entry)) { if (dynamic_cast<const SemanticEntry*>(&entry)) {
if (const auto* startEntry = dynamic_cast<const StartEntry*>(&entry)) { if (const auto* startEntry = dynamic_cast<const StartEntry*>(&entry)) {
const string file = escapeJsonString(startEntry->getInputFilePath().string()); const string file = escapeJsonString(startEntry->getInputFilePath().u8string());
line = fmt::format( line = fmt::format(
R"({{ "type": "start", "file": "{}", {} }})", R"({{ "type": "start", "file": "{}", {} }})",
file, file,

View File

@ -3,7 +3,7 @@
#include "logging/Entry.h" #include "logging/Entry.h"
#include "logging/Sink.h" #include "logging/Sink.h"
#include "tools/ProgressBar.h" #include "tools/ProgressBar.h"
#include <boost/filesystem/path.hpp> #include <filesystem>
// Prints nicely formatted progress to stderr. // Prints nicely formatted progress to stderr.
// Non-semantic entries are only printed if their log level at least matches the specified minimum level. // Non-semantic entries are only printed if their log level at least matches the specified minimum level.
@ -31,7 +31,7 @@ public:
private: private:
logging::Level minLevel; logging::Level minLevel;
bool quietSoFar = true; bool quietSoFar = true;
boost::optional<boost::filesystem::path> inputFilePath; boost::optional<std::filesystem::path> inputFilePath;
std::shared_ptr<Sink> innerSink; std::shared_ptr<Sink> innerSink;
}; };

View File

@ -10,7 +10,7 @@ using std::cout;
using std::endl; using std::endl;
string getBinaryName() { string getBinaryName() {
return getBinPath().filename().string(); return getBinPath().filename().u8string();
} }
void NiceCmdLineOutput::version(CmdLineInterface& cli) { void NiceCmdLineOutput::version(CmdLineInterface& cli) {

View File

@ -2,7 +2,7 @@
#include <cerrno> #include <cerrno>
using boost::filesystem::path; using std::filesystem::path;
std::ifstream openFile(path filePath) { std::ifstream openFile(path filePath) {
try { try {

View File

@ -1,7 +1,8 @@
#pragma once #pragma once
#include "platformTools.h" #include "platformTools.h"
#include <fstream> #include <fstream>
#include <filesystem>
std::ifstream openFile(boost::filesystem::path filePath); std::ifstream openFile(std::filesystem::path filePath);
void throwIfNotReadable(boost::filesystem::path filePath); void throwIfNotReadable(std::filesystem::path filePath);

View File

@ -1,5 +1,4 @@
#include <boost/filesystem/operations.hpp> #include <filesystem>
#include <boost/filesystem/path.hpp>
#include <format.h> #include <format.h>
#include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp> #include <boost/uuid/uuid_generators.hpp>
@ -9,14 +8,14 @@
#include <utf8.h> #include <utf8.h>
#include <gsl_util.h> #include <gsl_util.h>
#include "tools.h" #include "tools.h"
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp> #include <codecvt>
#include <iostream> #include <iostream>
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#endif #endif
using boost::filesystem::path; using std::filesystem::path;
using std::string; using std::string;
using std::vector; using std::vector;
@ -39,9 +38,9 @@ path getBinPath() {
} }
buffer[pathLength] = 0; buffer[pathLength] = 0;
// Convert to boost::filesystem::path // Convert to std::filesystem::path
const string pathString(buffer.data()); const string pathString(buffer.data());
path result(boost::filesystem::canonical(pathString).make_preferred()); path result(std::filesystem::canonical(pathString).make_preferred());
return result; return result;
} catch (...) { } catch (...) {
std::throw_with_nested(std::runtime_error("Could not determine path of bin directory.")); std::throw_with_nested(std::runtime_error("Could not determine path of bin directory."));
@ -55,7 +54,7 @@ path getBinDirectory() {
} }
path getTempFilePath() { path getTempFilePath() {
const path tempDirectory = boost::filesystem::temp_directory_path(); const path tempDirectory = std::filesystem::temp_directory_path();
static boost::uuids::random_generator generateUuid; static boost::uuids::random_generator generateUuid;
const string fileName = to_string(generateUuid()); const string fileName = to_string(generateUuid());
return tempDirectory / fileName; return tempDirectory / fileName;
@ -145,9 +144,3 @@ void useUtf8ForConsole() {
std::cerr.rdbuf(new ConsoleBuffer(stderr)); std::cerr.rdbuf(new ConsoleBuffer(stderr));
#endif #endif
} }
void useUtf8ForBoostFilesystem() {
const std::locale globalLocale = std::locale();
const std::locale utf8Locale(globalLocale, new boost::filesystem::detail::utf8_codecvt_facet);
path::imbue(utf8Locale);
}

View File

@ -1,12 +1,13 @@
#pragma once #pragma once
#include <boost/filesystem.hpp> #include <filesystem>
#include <ctime> #include <ctime>
#include <string> #include <string>
#include <vector>
boost::filesystem::path getBinPath(); std::filesystem::path getBinPath();
boost::filesystem::path getBinDirectory(); std::filesystem::path getBinDirectory();
boost::filesystem::path getTempFilePath(); std::filesystem::path getTempFilePath();
std::tm getLocalTime(const time_t& time); std::tm getLocalTime(const time_t& time);
std::string errorNumberToString(int errorNumber); std::string errorNumberToString(int errorNumber);
@ -14,4 +15,3 @@ std::string errorNumberToString(int errorNumber);
std::vector<std::string> argsToUtf8(int argc, char* argv[]); std::vector<std::string> argsToUtf8(int argc, char* argv[]);
void useUtf8ForConsole(); void useUtf8ForConsole();
void useUtf8ForBoostFilesystem();

View File

@ -1,18 +1,17 @@
#include "textFiles.h" #include "textFiles.h"
#include <boost/filesystem/operations.hpp>
#include <format.h> #include <format.h>
#include <boost/filesystem/fstream.hpp> #include <fstream>
#include "stringTools.h" #include "stringTools.h"
using std::string; using std::string;
using boost::filesystem::path; using std::filesystem::path;
string readUtf8File(path filePath) { string readUtf8File(path filePath) {
if (!exists(filePath)) { if (!exists(filePath)) {
throw std::invalid_argument(fmt::format("File {} does not exist.", filePath)); throw std::invalid_argument(fmt::format("File {} does not exist.", filePath.u8string()));
} }
try { try {
boost::filesystem::ifstream file; std::ifstream file;
file.exceptions(std::ifstream::failbit | std::ifstream::badbit); file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
file.open(filePath); file.open(filePath);
string text((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); string text((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
@ -22,7 +21,7 @@ string readUtf8File(path filePath) {
return text; return text;
} catch (...) { } catch (...) {
std::throw_with_nested(std::runtime_error(fmt::format("Error reading file {0}.", filePath))); std::throw_with_nested(std::runtime_error(fmt::format("Error reading file {0}.", filePath.u8string())));
} }
} }

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include <boost/filesystem/path.hpp> #include <filesystem>
std::string readUtf8File(boost::filesystem::path filePath); std::string readUtf8File(std::filesystem::path filePath);