Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions codechicken/lib/config/ConfigFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,43 @@

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.PrintWriter;
import java.io.UnsupportedEncodingException;

import net.minecraftforge.common.Configuration.UnicodeInputStreamReader;

public class ConfigFile extends ConfigTagParent
{
public String defaultEncoding = "UTF-8";

public ConfigFile(File file)
{
if(!file.exists())
try
{
try
if (file.getParentFile() != null)
{
file.createNewFile();
file.getParentFile().mkdirs();
}
catch(IOException e)

if (!file.exists() && !file.createNewFile())
{
throw new RuntimeException(e);
throw new IOException("Failed to create configuration file " + file.getCanonicalPath());
}

if(!file.canRead()) {
throw new IOException("Failed to read configuration file " + file.getCanonicalPath());
}
}
catch(IOException e)
{
throw new RuntimeException(e);
}

this.file = file;
newlinemode = 2;
loadConfig();
Expand All @@ -31,11 +48,11 @@ private void loadConfig()
{
loading = true;
BufferedReader reader;
try
{
reader = new BufferedReader(new FileReader(file));
while(true)

try {
reader = new BufferedReader(new UnicodeInputStreamReader(new FileInputStream(file), defaultEncoding));

while(true)
{
reader.mark(2000);
String line = reader.readLine();
Expand Down Expand Up @@ -127,12 +144,14 @@ public void saveConfig()
PrintWriter writer;
try
{
writer = new PrintWriter(file);
writer = new PrintWriter(file, defaultEncoding);
}
catch(FileNotFoundException e)
{
throw new RuntimeException(e);
}
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}

writeComment(writer, 0);
ConfigFile.writeLine(writer, "", 0);
Expand Down