Skip to content

Commit

Permalink
Force load scripts as UTF-8.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 committed Aug 17, 2021
1 parent a2c1fa4 commit 44f1d60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Expand Up @@ -29,8 +29,10 @@
import org.openzen.zenscript.parser.expression.ParsedExpressionArray;
import org.openzen.zenscript.parser.expression.ParsedExpressionMap;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.StringReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
Expand Down Expand Up @@ -156,7 +158,8 @@ public static void loadScriptsFromRecipeManager(RecipeManager recipeManager, Scr
final Comparator<FileAccessSingle> comparator = FileAccessSingle.createComparator(CraftTweakerRegistry.getPreprocessors());
final SourceFile[] sourceFiles = recipes.stream()
.map(iRecipe -> (ScriptRecipe) iRecipe)
.map(recipe -> new FileAccessSingle(recipe.getFileName(), new StringReader(recipe.getContent()), scriptLoadingOptions, CraftTweakerRegistry
.map(recipe -> new FileAccessSingle(recipe.getFileName(), new InputStreamReader(new ByteArrayInputStream(recipe.getContent()
.getBytes(StandardCharsets.UTF_8))), scriptLoadingOptions, CraftTweakerRegistry
.getPreprocessors()))
.filter(FileAccessSingle::shouldBeLoaded)
.sorted(comparator)
Expand Down
Expand Up @@ -8,11 +8,20 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;

public class FileAccessSingle {
Expand All @@ -38,7 +47,7 @@ public FileAccessSingle(File file, ScriptLoadingOptions scriptLoadingOptions, Co
this.fileName = file.getName();
this.fileContents = new ArrayList<>();
try {
readFile(new FileReader(file));
readFile(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
} catch(FileNotFoundException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -67,7 +76,7 @@ public FileAccessSingle(File baseDirectory, File file, ScriptLoadingOptions scri
this.fileName = file.getAbsolutePath().substring(baseDirectory.getAbsolutePath().length() + 1);
this.fileContents = new ArrayList<>();
try {
readFile(new FileReader(file));
readFile(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
} catch(FileNotFoundException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 44f1d60

Please sign in to comment.