Fix writing mod.json on Windows in non Latin user folders.
Accepted by: @vladislavbelov Differential Revision: https://code.wildfiregames.com/D4741 This was SVN commit r27031.
This commit is contained in:
parent
0a54a4e2a5
commit
fb94d8aa59
@ -37,10 +37,14 @@
|
||||
#ifndef INCLUDED_PATH
|
||||
#define INCLUDED_PATH
|
||||
|
||||
#include "lib/sysdep/os.h"
|
||||
#include "lib/utf8.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#if OS_WIN
|
||||
#include <filesystem>
|
||||
#endif
|
||||
#include <functional>
|
||||
|
||||
namespace ERR
|
||||
@ -126,6 +130,19 @@ public:
|
||||
return path.empty();
|
||||
}
|
||||
|
||||
// TODO: This macro should be removed later when macOS supports std::filesystem.
|
||||
// Currently it does in more recent SDKs, but it also causes a slowdown on
|
||||
// OpenGL. See #6193.
|
||||
#if OS_WIN
|
||||
/**
|
||||
* @returns a STL version of the path.
|
||||
*/
|
||||
std::filesystem::path fileSystemPath() const
|
||||
{
|
||||
return std::filesystem::path(path);
|
||||
}
|
||||
#endif
|
||||
|
||||
const String& string() const
|
||||
{
|
||||
return path;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -22,6 +22,7 @@
|
||||
#include "i18n/L10n.h"
|
||||
#include "lib/file/file_system.h"
|
||||
#include "lib/file/vfs/vfs.h"
|
||||
#include "lib/sysdep/os.h"
|
||||
#include "lib/utf8.h"
|
||||
#include "ps/Filesystem.h"
|
||||
#include "ps/GameSetup/GameSetup.h"
|
||||
@ -35,6 +36,9 @@
|
||||
#include <algorithm>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#if OS_WIN
|
||||
#include <filesystem>
|
||||
#endif
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
@ -48,11 +52,14 @@ Mod g_ModInstance;
|
||||
|
||||
bool LoadModJSON(const PIVFS& vfs, OsPath modsPath, OsPath mod, std::string& text)
|
||||
{
|
||||
#if OS_WIN
|
||||
const std::filesystem::path modJsonPath = (modsPath / mod / L"mod.json").fileSystemPath();
|
||||
#else
|
||||
const std::string modJsonPath = (modsPath / mod / L"mod.json").string8();
|
||||
#endif
|
||||
// Attempt to open mod.json first.
|
||||
std::ifstream modjson;
|
||||
modjson.open((modsPath / mod / L"mod.json").string8());
|
||||
|
||||
if (!modjson.is_open())
|
||||
std::ifstream modjson(modJsonPath);
|
||||
if (!modjson)
|
||||
{
|
||||
modjson.close();
|
||||
|
||||
@ -69,8 +76,8 @@ bool LoadModJSON(const PIVFS& vfs, OsPath modsPath, OsPath mod, std::string& tex
|
||||
text = modinfo.GetAsString();
|
||||
|
||||
// Attempt to write the mod.json file so we'll take the fast path next time.
|
||||
std::ofstream out_mod_json((modsPath / mod / L"mod.json").string8());
|
||||
if (out_mod_json.good())
|
||||
std::ofstream out_mod_json(modJsonPath);
|
||||
if (out_mod_json)
|
||||
{
|
||||
out_mod_json << text;
|
||||
out_mod_json.close();
|
||||
|
Loading…
Reference in New Issue
Block a user