1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-25 12:41:01 +00:00

Merge pull request #2651 from akortunov/encoding

Unify streams usage to support non-ASCII paths
This commit is contained in:
Alexei Dobrohotov 2020-01-09 22:12:55 +03:00 committed by GitHub
commit ff2739b8a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 16 deletions

View File

@ -187,6 +187,7 @@
Bug #5223: Bow replacement during attack animation removes attached arrow Bug #5223: Bow replacement during attack animation removes attached arrow
Bug #5226: Reputation should be capped Bug #5226: Reputation should be capped
Bug #5229: Crash if mesh controller node has no data node Bug #5229: Crash if mesh controller node has no data node
Bug #5239: OpenMW-CS does not support non-ASCII characters in path names
Feature #1774: Handle AvoidNode Feature #1774: Handle AvoidNode
Feature #2229: Improve pathfinding AI Feature #2229: Improve pathfinding AI
Feature #3025: Analogue gamepad movement controls Feature #3025: Analogue gamepad movement controls

View File

@ -2,6 +2,7 @@
#include <iomanip> #include <iomanip>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <osgDB/ReadFile> #include <osgDB/ReadFile>
@ -349,7 +350,7 @@ namespace ESSImport
writer.setFormat (ESM::SavedGame::sCurrentFormat); writer.setFormat (ESM::SavedGame::sCurrentFormat);
std::ofstream stream(mOutFile.c_str(), std::ios::binary); boost::filesystem::ofstream stream(boost::filesystem::path(mOutFile), std::ios::out | std::ios::binary);
// all unused // all unused
writer.setVersion(0); writer.setVersion(0);
writer.setType(0); writer.setType(0);

View File

@ -1,7 +1,6 @@
#include "document.hpp" #include "document.hpp"
#include <cassert> #include <cassert>
#include <fstream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
@ -289,19 +288,22 @@ CSMDoc::Document::Document (const Files::ConfigurationManager& configuration,
if (mNew || !boost::filesystem::exists (mProjectPath)) if (mNew || !boost::filesystem::exists (mProjectPath))
{ {
boost::filesystem::path customFiltersPath (configuration.getUserDataPath()); boost::filesystem::path filtersPath (configuration.getUserDataPath() / "defaultfilters");
customFiltersPath /= "defaultfilters";
std::ofstream destination (mProjectPath.string().c_str(), std::ios::binary); boost::filesystem::ofstream destination(mProjectPath, std::ios::out | std::ios::binary);
if (!destination.is_open())
throw std::runtime_error("Can not create project file: " + mProjectPath.string());
destination.exceptions(std::ios::failbit | std::ios::badbit);
if (boost::filesystem::exists (customFiltersPath)) if (!boost::filesystem::exists (filtersPath))
{ filtersPath = mResDir / "defaultfilters";
destination << std::ifstream(customFiltersPath.string().c_str(), std::ios::binary).rdbuf();
} boost::filesystem::ifstream source(filtersPath, std::ios::in | std::ios::binary);
else if (!source.is_open())
{ throw std::runtime_error("Can not read filters file: " + filtersPath.string());
destination << std::ifstream(std::string(mResDir.string() + "/defaultfilters").c_str(), std::ios::binary).rdbuf(); source.exceptions(std::ios::failbit | std::ios::badbit);
}
destination << source.rdbuf();
} }
if (mNew) if (mNew)

View File

@ -4,14 +4,15 @@
#include <DetourNavMesh.h> #include <DetourNavMesh.h>
#include <fstream> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
namespace DetourNavigator namespace DetourNavigator
{ {
void writeToFile(const RecastMesh& recastMesh, const std::string& pathPrefix, const std::string& revision) void writeToFile(const RecastMesh& recastMesh, const std::string& pathPrefix, const std::string& revision)
{ {
const auto path = pathPrefix + "recastmesh" + revision + ".obj"; const auto path = pathPrefix + "recastmesh" + revision + ".obj";
std::ofstream file(path); boost::filesystem::ofstream file(boost::filesystem::path(path), std::ios::out);
if (!file.is_open()) if (!file.is_open())
throw NavigatorException("Open file failed: " + path); throw NavigatorException("Open file failed: " + path);
file.exceptions(std::ios::failbit | std::ios::badbit); file.exceptions(std::ios::failbit | std::ios::badbit);
@ -64,7 +65,7 @@ namespace DetourNavigator
}; };
const auto path = pathPrefix + "all_tiles_navmesh" + revision + ".bin"; const auto path = pathPrefix + "all_tiles_navmesh" + revision + ".bin";
std::ofstream file(path, std::ios::binary); boost::filesystem::ofstream file(boost::filesystem::path(path), std::ios::out | std::ios::binary);
if (!file.is_open()) if (!file.is_open())
throw NavigatorException("Open file failed: " + path); throw NavigatorException("Open file failed: " + path);
file.exceptions(std::ios::failbit | std::ios::badbit); file.exceptions(std::ios::failbit | std::ios::badbit);