Turn paths into UTF-8 strings in all exception and log messages

These aren't tested, but I don't think they're worth testing.
This commit is contained in:
Oliver Hamlet
2018-10-20 12:48:20 +01:00
parent 6f0d2116ba
commit 74491931cd
9 changed files with 25 additions and 25 deletions
+4 -4
View File
@@ -73,18 +73,18 @@ LOOT_API std::shared_ptr<GameInterface> CreateGameHandle(
logger->info(
"Attempting to create a game handle with game path \"{}\" "
"and local path \"{}\"",
gamePath.string(),
gameLocalPath.string());
gamePath.u8string(),
gameLocalPath.u8string());
}
auto resolvedGamePath = ResolvePath(gamePath);
if (!fs::is_directory(resolvedGamePath))
throw std::invalid_argument("Given game path \"" + gamePath.string() +
throw std::invalid_argument("Given game path \"" + gamePath.u8string() +
"\" does not resolve to a valid directory.");
auto resolvedGameLocalPath = ResolvePath(gameLocalPath);
if (!gameLocalPath.empty() && !fs::is_directory(resolvedGameLocalPath))
throw std::invalid_argument("Given game local path \"" + gameLocalPath.string() +
throw std::invalid_argument("Given game local path \"" + gameLocalPath.u8string() +
"\" does not resolve to a valid directory.");
return std::make_shared<Game>(game, resolvedGamePath, resolvedGameLocalPath);
+3 -3
View File
@@ -56,7 +56,7 @@ void ApiDatabase::LoadLists(const std::filesystem::path& masterlistPath,
temp.Load(masterlistPath);
} else {
throw FileAccessError("The given masterlist path does not exist: " +
masterlistPath.string());
masterlistPath.u8string());
}
}
@@ -65,7 +65,7 @@ void ApiDatabase::LoadLists(const std::filesystem::path& masterlistPath,
userTemp.Load(userlistPath);
} else {
throw FileAccessError("The given userlist path does not exist: " +
userlistPath.string());
userlistPath.u8string());
}
}
@@ -93,7 +93,7 @@ bool ApiDatabase::UpdateMasterlist(const std::filesystem::path& masterlistPath,
const std::string& remoteURL,
const std::string& remoteBranch) {
if (!std::filesystem::is_directory(masterlistPath.parent_path()))
throw std::invalid_argument("Given masterlist path \"" + masterlistPath.string() +
throw std::invalid_argument("Given masterlist path \"" + masterlistPath.u8string() +
"\" does not have a valid parent directory.");
Masterlist masterlist;
+1 -1
View File
@@ -65,7 +65,7 @@ Game::Game(const GameType gameType,
if (logger) {
logger->info("Initialising load order data for game of type {} at: {}",
(int)type_,
gamePath_.string());
gamePath_.u8string());
}
loadOrderHandler_->Init(type_, gamePath_, localDataPath);
+3 -3
View File
@@ -51,7 +51,7 @@ uint32_t GetCrc32(const std::filesystem::path& filename) {
try {
auto logger = getLogger();
if (logger) {
logger->trace("Calculating CRC for: {}", filename.string());
logger->trace("Calculating CRC for: {}", filename.u8string());
}
std::ifstream ifile(filename, std::ios::binary);
@@ -73,12 +73,12 @@ uint32_t GetCrc32(const std::filesystem::path& filename) {
uint32_t checksum = result.checksum();
if (logger) {
logger->debug("CRC32(\"{}\"): {:x}", filename.string(), checksum);
logger->debug("CRC32(\"{}\"): {:x}", filename.u8string(), checksum);
}
return checksum;
} catch (std::exception& e) {
throw FileAccessError("Unable to open \"" + filename.string() +
throw FileAccessError("Unable to open \"" + filename.u8string() +
"\" for CRC calulation: " + e.what());
}
}
+1 -1
View File
@@ -112,7 +112,7 @@ void GitHelper::InitialiseOptions(const std::string& branch,
void GitHelper::Open(const std::filesystem::path& repoRoot) {
if (logger_) {
logger_->info("Attempting to open Git repository at: {}",
repoRoot.string());
repoRoot.u8string());
}
Call(git_repository_open(&data_.repo, repoRoot.u8string().c_str()));
}
+4 -4
View File
@@ -48,12 +48,12 @@ MasterlistInfo Masterlist::GetInfo(const std::filesystem::path& path,
logger->info("Unknown masterlist revision: No masterlist present.");
}
throw FileAccessError(string("N/A: No masterlist present at ") +
path.string());
path.u8string());
} else if (!git.IsRepository(path.parent_path())) {
if (logger) {
logger->info("Unknown masterlist revision: Git repository missing.");
}
throw GitStateError(string("Unknown: \"") + path.parent_path().string() +
throw GitStateError(string("Unknown: \"") + path.parent_path().u8string() +
"\" is not a Git repository.");
}
@@ -84,7 +84,7 @@ bool Masterlist::IsLatest(const std::filesystem::path& path,
logger->info(
"Cannot get latest masterlist revision: Git repository missing.");
}
throw GitStateError(string("Unknown: \"") + path.parent_path().string() +
throw GitStateError(string("Unknown: \"") + path.parent_path().u8string() +
"\" is not a Git repository.");
}
@@ -115,7 +115,7 @@ bool Masterlist::Update(const std::filesystem::path& path,
// Now try to access the repository if it exists, or clone one if it doesn't.
if (logger) {
logger->trace("Checking for Git repository at: {}", repoPath.string());
logger->trace("Checking for Git repository at: {}", repoPath.u8string());
}
if (!GitHelper::IsRepository(repoPath)) {
git.Clone(repoPath, repoUrl);
+3 -3
View File
@@ -264,7 +264,7 @@ bool ConditionEvaluator::compareVersions(const std::string& filePath,
void ConditionEvaluator::validatePath(const std::filesystem::path& path) {
auto logger = getLogger();
if (logger) {
logger->trace("Checking to see if the path \"{}\" is safe.", path.string());
logger->trace("Checking to see if the path \"{}\" is safe.", path.u8string());
}
std::filesystem::path temp;
@@ -273,7 +273,7 @@ void ConditionEvaluator::validatePath(const std::filesystem::path& path) {
continue;
if (component == ".." && temp.filename() == "..") {
throw ConditionSyntaxError("Invalid file path: " + path.string());
throw ConditionSyntaxError("Invalid file path: " + path.u8string());
}
temp /= component;
@@ -350,7 +350,7 @@ bool ConditionEvaluator::isRegexMatchInDataDirectory(
auto logger = getLogger();
if (logger) {
logger->trace("The path \"{}\" is not a game subdirectory.",
pathRegex.first.string());
pathRegex.first.u8string());
}
return false;
}
+4 -4
View File
@@ -40,18 +40,18 @@ void MetadataList::Load(const std::filesystem::path& filepath) {
auto logger = getLogger();
if (logger) {
logger->debug("Loading file: {}", filepath.string());
logger->debug("Loading file: {}", filepath.u8string());
}
std::ifstream in(filepath);
if (!in.good())
throw FileAccessError("Cannot open " + filepath.string());
throw FileAccessError("Cannot open " + filepath.u8string());
YAML::Node metadataList = YAML::Load(in);
in.close();
if (!metadataList.IsMap())
throw FileAccessError("The root of the metadata file " + filepath.string() +
throw FileAccessError("The root of the metadata file " + filepath.u8string() +
" is not a YAML map.");
if (metadataList["plugins"]) {
@@ -83,7 +83,7 @@ void MetadataList::Load(const std::filesystem::path& filepath) {
void MetadataList::Save(const std::filesystem::path& filepath) const {
auto logger = getLogger();
if (logger) {
logger->trace("Saving metadata list to: {}", filepath.string());
logger->trace("Saving metadata list to: {}", filepath.u8string());
}
YAML::Emitter emitter;
emitter.SetIndent(2);
+2 -2
View File
@@ -276,7 +276,7 @@ void Plugin::Load(const std::filesystem::path& path,
int ret = esp_plugin_new(
&plugin, GetEspluginGameId(gameType), path.u8string().c_str());
if (ret != ESP_OK) {
throw FileAccessError(path.string() +
throw FileAccessError(path.u8string() +
" : esplugin error code: " + std::to_string(ret));
}
@@ -285,7 +285,7 @@ void Plugin::Load(const std::filesystem::path& path,
ret = esp_plugin_parse(esPlugin.get(), headerOnly);
if (ret != ESP_OK) {
throw FileAccessError(path.string() +
throw FileAccessError(path.u8string() +
" : esplugin error code: " + std::to_string(ret));
}
}