Read all files as UTF-8 (#1035)

Fix encoding issues with some languages such as Chinese
by forcing UTF-8 everywhere. Configuration files written
in ANSI/Latin-1 and other encodings will need conversion.
This commit is contained in:
ORelio 2020-05-29 20:23:03 +02:00
parent cf9bc4c3d5
commit 20fb2323a4
9 changed files with 12 additions and 10 deletions

View file

@ -399,7 +399,7 @@ namespace MinecraftClient
{
string[] lines = null;
ChatBots.Script.LookForScript(ref script);
try { lines = File.ReadAllLines(script); }
try { lines = File.ReadAllLines(script, Encoding.UTF8); }
catch (Exception e) { throw new CSharpException(CSErrorType.FileReadError, e); }
return CSharpRunner.Run(this, tickHandler, lines, args, localVars);
}

View file

@ -791,7 +791,7 @@ namespace MinecraftClient
{
//Read all lines from file, remove lines with no text, convert to lowercase,
//remove duplicate entries, convert to a string array, and return the result.
return File.ReadAllLines(file)
return File.ReadAllLines(file, Encoding.UTF8)
.Where(line => !String.IsNullOrWhiteSpace(line))
.Select(line => line.ToLower())
.Distinct().ToArray();

View file

@ -45,7 +45,7 @@ namespace MinecraftClient.ChatBots
if (Settings.DebugMessages)
LogToConsole("Loading messages from file: " + System.IO.Path.GetFullPath(Settings.AutoRelog_KickMessagesFile));
dictionary = System.IO.File.ReadAllLines(Settings.AutoRelog_KickMessagesFile);
dictionary = System.IO.File.ReadAllLines(Settings.AutoRelog_KickMessagesFile, Encoding.UTF8);
for (int i = 0; i < dictionary.Length; i++)
{

View file

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace MinecraftClient.ChatBots
@ -143,7 +144,7 @@ namespace MinecraftClient.ChatBots
if (Settings.DebugMessages)
LogToConsole("Loading matches from file: " + System.IO.Path.GetFullPath(matchesFile));
foreach (string lineRAW in File.ReadAllLines(matchesFile))
foreach (string lineRAW in File.ReadAllLines(matchesFile, Encoding.UTF8))
{
string line = lineRAW.Split('#')[0].Trim();
if (line.Length > 0)

View file

@ -143,7 +143,7 @@ namespace MinecraftClient.ChatBots
{
if (System.IO.File.Exists(English ? Settings.Hangman_FileWords_EN : Settings.Hangman_FileWords_FR))
{
string[] dico = System.IO.File.ReadAllLines(English ? Settings.Hangman_FileWords_EN : Settings.Hangman_FileWords_FR);
string[] dico = System.IO.File.ReadAllLines(English ? Settings.Hangman_FileWords_EN : Settings.Hangman_FileWords_FR, Encoding.UTF8);
return dico[new Random().Next(dico.Length)];
}
else

View file

@ -132,7 +132,7 @@ namespace MinecraftClient.ChatBots
//Load the given file from the startup parameters
if (LookForScript(ref file))
{
lines = System.IO.File.ReadAllLines(file);
lines = System.IO.File.ReadAllLines(file, Encoding.UTF8);
csharp = file.EndsWith(".cs");
thread = null;

View file

@ -47,7 +47,7 @@ namespace MinecraftClient.ChatBots
if (Settings.DebugMessages)
LogToConsole("Loading tasks from '" + System.IO.Path.GetFullPath(tasksfile) + "'");
TaskDesc current_task = null;
String[] lines = System.IO.File.ReadAllLines(tasksfile);
String[] lines = System.IO.File.ReadAllLines(tasksfile, Encoding.UTF8);
foreach (string lineRAW in lines)
{
string line = lineRAW.Split('#')[0].Trim();

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace MinecraftClient.Mapping.BlockPalettes
{
@ -11,7 +12,7 @@ namespace MinecraftClient.Mapping.BlockPalettes
public static class BlockPaletteGenerator
{
/// <summary>
/// Generate mapping from Minecraft blocks.jsom
/// Generate mapping from Minecraft blocks.json
/// </summary>
/// <param name="blocksJsonFile">path to blocks.json</param>
/// <param name="outputClass">output path for blocks.cs</param>
@ -23,7 +24,7 @@ namespace MinecraftClient.Mapping.BlockPalettes
HashSet<int> knownStates = new HashSet<int>();
Dictionary<string, HashSet<int>> blocks = new Dictionary<string, HashSet<int>>();
Json.JSONData palette = Json.ParseJson(File.ReadAllText(blocksJsonFile));
Json.JSONData palette = Json.ParseJson(File.ReadAllText(blocksJsonFile, Encoding.UTF8));
foreach (KeyValuePair<string, Json.JSONData> item in palette.Properties)
{
//minecraft:item_name => ItemName

View file

@ -1633,7 +1633,7 @@ namespace MinecraftClient
public void OnExplosion(Location location, float strength, int affectedBlocks)
{
foreach (ChatBot bot in bots.ToArray())
bot.OnExplosion(explode, strength, ExplosionRecordCount);
bot.OnExplosion(location, strength, affectedBlocks);
}
/// <summary>