mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 02:46:49 +00:00
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:
+14
-7
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user