summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/EnigmaProfile.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/EnigmaProfile.java')
-rw-r--r--src/main/java/cuchaz/enigma/EnigmaProfile.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/EnigmaProfile.java b/src/main/java/cuchaz/enigma/EnigmaProfile.java
index 5a68be1..09b90f5 100644
--- a/src/main/java/cuchaz/enigma/EnigmaProfile.java
+++ b/src/main/java/cuchaz/enigma/EnigmaProfile.java
@@ -14,8 +14,15 @@ import cuchaz.enigma.api.service.EnigmaServiceType;
14import cuchaz.enigma.translation.mapping.MappingFileNameFormat; 14import cuchaz.enigma.translation.mapping.MappingFileNameFormat;
15import cuchaz.enigma.translation.mapping.MappingSaveParameters; 15import cuchaz.enigma.translation.mapping.MappingSaveParameters;
16 16
17import javax.annotation.Nullable;
18import java.io.BufferedReader;
19import java.io.IOException;
20import java.io.InputStreamReader;
17import java.io.Reader; 21import java.io.Reader;
18import java.lang.reflect.Type; 22import java.lang.reflect.Type;
23import java.nio.charset.StandardCharsets;
24import java.nio.file.Files;
25import java.nio.file.Path;
19import java.util.Collections; 26import java.util.Collections;
20import java.util.List; 27import java.util.List;
21import java.util.Map; 28import java.util.Map;
@@ -41,6 +48,21 @@ public final class EnigmaProfile {
41 this.serviceProfiles = serviceProfiles; 48 this.serviceProfiles = serviceProfiles;
42 } 49 }
43 50
51 public static EnigmaProfile read(@Nullable Path file) throws IOException {
52 if (file != null) {
53 try (BufferedReader reader = Files.newBufferedReader(file)) {
54 return EnigmaProfile.parse(reader);
55 }
56 } else {
57 try (BufferedReader reader = new BufferedReader(new InputStreamReader(Main.class.getResourceAsStream("/profile.json"), StandardCharsets.UTF_8))) {
58 return EnigmaProfile.parse(reader);
59 } catch (IOException ex) {
60 System.err.println("Failed to load default profile, will use empty profile: " + ex.getMessage());
61 return EnigmaProfile.EMPTY;
62 }
63 }
64 }
65
44 public static EnigmaProfile parse(Reader reader) { 66 public static EnigmaProfile parse(Reader reader) {
45 return GSON.fromJson(reader, EnigmaProfile.class); 67 return GSON.fromJson(reader, EnigmaProfile.class);
46 } 68 }