Make all ifstream creation utf8 path aware
This commit is contained in:
parent
cbf55b6ecf
commit
bc555ac514
@ -24,6 +24,7 @@
|
||||
#include "graphics/graphics_restrictions.hpp"
|
||||
#include "guiengine/message_queue.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
@ -42,7 +43,8 @@ const std::string& ShaderFilesManager::getHeader()
|
||||
// Only read file first time
|
||||
if (shader_header.empty())
|
||||
{
|
||||
std::ifstream stream(file_manager->getShader("header.txt"), std::ios::in);
|
||||
std::ifstream stream(FileUtils::getPortableReadingPath(
|
||||
file_manager->getShader("header.txt")), std::ios::in);
|
||||
if (stream.is_open())
|
||||
{
|
||||
std::string line = "";
|
||||
@ -59,9 +61,12 @@ const std::string& ShaderFilesManager::getHeader()
|
||||
void ShaderFilesManager::readFile(const std::string& file,
|
||||
std::ostringstream& code, bool not_header)
|
||||
{
|
||||
std::ifstream stream(((file.find('/') != std::string::npos ||
|
||||
std::string path = FileUtils::getPortableReadingPath(
|
||||
((file.find('/') != std::string::npos ||
|
||||
file.find('\\') != std::string::npos) && not_header) ?
|
||||
file : file_manager->getShader(file), std::ios::in);
|
||||
file : file_manager->getShader(file));
|
||||
|
||||
std::ifstream stream(path, std::ios::in);
|
||||
|
||||
if (!stream.is_open())
|
||||
{
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "guiengine/emoji_keyboard.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/utf8.h"
|
||||
|
||||
@ -57,8 +58,8 @@ ScreenKeyboard::KeyboardLayout*
|
||||
std::vector<std::string> emoji_chars;
|
||||
try
|
||||
{
|
||||
std::unique_ptr<std::istream> in(new std::ifstream(file_name.c_str()));
|
||||
if (!in.get())
|
||||
std::ifstream in(FileUtils::getPortableReadingPath(file_name));
|
||||
if (!in.is_open())
|
||||
{
|
||||
Log::error("EmojiKeyboard", "Error: failure opening: '%s'.",
|
||||
file_name.c_str());
|
||||
@ -66,7 +67,7 @@ ScreenKeyboard::KeyboardLayout*
|
||||
else
|
||||
{
|
||||
std::string line;
|
||||
while (!StringUtils::safeGetline(*in, line).eof())
|
||||
while (!StringUtils::safeGetline(in, line).eof())
|
||||
{
|
||||
// Check for possible bom mark
|
||||
if (line[0] == '#' ||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "network/server_config.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
@ -44,7 +45,7 @@ GameSetup::GameSetup()
|
||||
{
|
||||
const std::string& path = ServerConfig::getConfigDirectory() + "/" +
|
||||
motd;
|
||||
std::ifstream message(path);
|
||||
std::ifstream message(FileUtils::getPortableReadingPath(path));
|
||||
if (message.is_open())
|
||||
{
|
||||
for (std::string line; std::getline(message, line); )
|
||||
|
@ -32,6 +32,7 @@ using irr::core::stringc;
|
||||
#include "online/link_helper.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
@ -122,7 +123,8 @@ void CreditsScreen::loadedFromFile()
|
||||
|
||||
std::string creditsfile = file_manager->getAsset("CREDITS");
|
||||
|
||||
std::ifstream file( creditsfile.c_str(), std::ios::binary ) ;
|
||||
std::ifstream file(
|
||||
FileUtils::getPortableReadingPath(creditsfile), std::ios::binary);
|
||||
|
||||
if (file.fail() || !file.is_open() || file.eof())
|
||||
{
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "io/file_manager.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
|
||||
namespace tinygettext {
|
||||
|
||||
@ -49,7 +50,8 @@ StkFileSystem::open_directory(const std::string& pathname)
|
||||
std::unique_ptr<std::istream>
|
||||
StkFileSystem::open_file(const std::string& filename)
|
||||
{
|
||||
return std::unique_ptr<std::istream>(new std::ifstream(filename.c_str()));
|
||||
return std::unique_ptr<std::istream>(new std::ifstream(
|
||||
FileUtils::getPortableReadingPath(filename)));
|
||||
}
|
||||
|
||||
} // namespace tinygettext
|
||||
|
@ -52,7 +52,7 @@ namespace FileUtils
|
||||
// ------------------------------------------------------------------------
|
||||
/* Return a path which can be opened in all systems, as long as u8_path
|
||||
* is unicode encoded. */
|
||||
inline std::string getPortablePath(const std::string& u8_path)
|
||||
inline std::string getPortableReadingPath(const std::string& u8_path)
|
||||
{
|
||||
#if defined(WIN32)
|
||||
return Private::getShortPath(u8_path);
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "config/user_config.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
@ -119,15 +120,15 @@ Translations::Translations() //: m_dictionary_manager("UTF-16")
|
||||
const std::string file_name = file_manager->getAsset("localized_name.txt");
|
||||
try
|
||||
{
|
||||
std::unique_ptr<std::istream> in(new std::ifstream(file_name.c_str()));
|
||||
if (!in.get())
|
||||
std::ifstream in(FileUtils::getPortableReadingPath(file_name));
|
||||
if (!in.is_open())
|
||||
{
|
||||
Log::error("translation", "error: failure opening: '%s'.",
|
||||
file_name.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
for (std::string line; std::getline(*in, line, ';'); )
|
||||
for (std::string line; std::getline(in, line, ';'); )
|
||||
{
|
||||
line = StringUtils::removeWhitespaces(line);
|
||||
|
||||
@ -166,8 +167,8 @@ Translations::Translations() //: m_dictionary_manager("UTF-16")
|
||||
const std::string file_name = file_manager->getAsset("country_names.csv");
|
||||
try
|
||||
{
|
||||
std::unique_ptr<std::istream> in(new std::ifstream(file_name.c_str()));
|
||||
if (!in.get())
|
||||
std::ifstream in(FileUtils::getPortableReadingPath(file_name));
|
||||
if (!in.is_open())
|
||||
{
|
||||
Log::error("translation", "error: failure opening: '%s'.",
|
||||
file_name.c_str());
|
||||
@ -176,7 +177,7 @@ Translations::Translations() //: m_dictionary_manager("UTF-16")
|
||||
{
|
||||
std::vector<std::string> header;
|
||||
std::string line;
|
||||
while (!StringUtils::safeGetline(*in, line).eof())
|
||||
while (!StringUtils::safeGetline(in, line).eof())
|
||||
{
|
||||
std::vector<std::string> lists = StringUtils::split(line, ';');
|
||||
if (lists.size() < 2)
|
||||
@ -220,8 +221,8 @@ Translations::Translations() //: m_dictionary_manager("UTF-16")
|
||||
const std::string file_name = file_manager->getAsset("thaidict.txt");
|
||||
try
|
||||
{
|
||||
std::unique_ptr<std::istream> in(new std::ifstream(file_name.c_str()));
|
||||
if (!in.get())
|
||||
std::ifstream in(FileUtils::getPortableReadingPath(file_name));
|
||||
if (!in.is_open())
|
||||
{
|
||||
Log::error("translation", "error: failure opening: '%s'.",
|
||||
file_name.c_str());
|
||||
@ -229,7 +230,7 @@ Translations::Translations() //: m_dictionary_manager("UTF-16")
|
||||
else
|
||||
{
|
||||
std::string line;
|
||||
while (!StringUtils::safeGetline(*in, line).eof())
|
||||
while (!StringUtils::safeGetline(in, line).eof())
|
||||
{
|
||||
const std::u32string& u32line = StringUtils::utf8ToUtf32(line);
|
||||
char32_t thai = u32line[0];
|
||||
|
Loading…
x
Reference in New Issue
Block a user