Skip to content

Commit

Permalink
fixed save file encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
zmilla93 committed Oct 17, 2021
1 parent 337bc2a commit 1ca0e44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/main/java/com/slimtrade/core/managers/SaveManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import java.awt.*;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;

public class SaveManager {
Expand Down Expand Up @@ -44,7 +46,8 @@ public class SaveManager {
// File Stuff
private FileReader fr;
private BufferedReader br;
private FileWriter fw;
private Writer fw;
private BufferedWriter bw;
private Gson gson;

// TODO : OPTIMIZE : Combine all saving and loading functions into one using wildcars?
Expand Down Expand Up @@ -150,7 +153,7 @@ public void loadPinsFromDisk() {
private String getJsonString(String path) {
StringBuilder builder = new StringBuilder();
try {
br = new BufferedReader(new FileReader(path));
br = new BufferedReader(new InputStreamReader(new FileInputStream(path), StandardCharsets.UTF_8));
while (br.ready()) {
builder.append(br.readLine());
}
Expand All @@ -163,7 +166,7 @@ private String getJsonString(String path) {

public void saveSettingsToDisk() {
try {
fw = new FileWriter(savePath);
fw = new OutputStreamWriter(new FileOutputStream(savePath), StandardCharsets.UTF_8);
fw.write(gson.toJson(settingsSaveFile));
fw.close();
} catch (IOException e) {
Expand All @@ -173,7 +176,7 @@ public void saveSettingsToDisk() {

public void saveStashToDisk() {
try {
fw = new FileWriter(stashSavePath);
fw = new OutputStreamWriter(new FileOutputStream(stashSavePath), StandardCharsets.UTF_8);
fw.write(gson.toJson(stashSaveFile));
fw.close();
} catch (IOException e) {
Expand All @@ -183,7 +186,7 @@ public void saveStashToDisk() {

public void saveOverlayToDisk() {
try {
fw = new FileWriter(overlaySavePath);
fw = new OutputStreamWriter(new FileOutputStream(overlaySavePath), StandardCharsets.UTF_8);
fw.write(gson.toJson(overlaySaveFile));
fw.close();
} catch (IOException e) {
Expand All @@ -193,7 +196,7 @@ public void saveOverlayToDisk() {

public void saveScannerToDisk() {
try {
fw = new FileWriter(scannerSavePath);
fw = new OutputStreamWriter(new FileOutputStream(scannerSavePath), StandardCharsets.UTF_8);
fw.write(gson.toJson(scannerSaveFile));
fw.close();
} catch (IOException e) {
Expand All @@ -203,7 +206,7 @@ public void saveScannerToDisk() {

public void savePinsToDisk() {
try {
fw = new FileWriter(pinSavePath);
fw = new OutputStreamWriter(new FileOutputStream(pinSavePath), StandardCharsets.UTF_8);
fw.write(gson.toJson(pinSaveFile));
fw.close();
} catch (IOException e) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/slimtrade/gui/options/general/BasicsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import javax.swing.*;
import java.awt.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public class BasicsPanel extends ContainerPanel implements ISaveable, IColorable {

Expand Down Expand Up @@ -208,11 +210,22 @@ private void updateQuickPasteVis() {

@Override
public void save() {
byte[] source = characterInput.getText().getBytes(Charset.defaultCharset());
System.out.println("C1:" + (int)characterInput.getText().charAt(0));
System.out.println("src" + source);
String good = new String(source);
System.out.println("GOOD: " + good);

System.out.println("charSET:" + Charset.defaultCharset());
// System.out.println("data:" + data);
System.out.println("charText:" + characterInput.getText());
System.out.println("thrd:" + SwingUtilities.isEventDispatchThread());
String characterName = characterInput.getText().replaceAll("\\s+", "");
if (characterName.equals("")) {
characterName = null;
}
ColorTheme colorTheme = (ColorTheme) colorThemeCombo.getSelectedItem();
System.out.println("charName:" + characterName);
App.saveManager.settingsSaveFile.characterName = characterName;
App.saveManager.settingsSaveFile.showGuildName = guildCheckbox.isSelected();
App.saveManager.settingsSaveFile.folderOffset = folderOffsetCheckbox.isSelected();
Expand Down

0 comments on commit 1ca0e44

Please sign in to comment.