diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/EnigmaProfile.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/EnigmaProfile.java | 22 |
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; | |||
| 14 | import cuchaz.enigma.translation.mapping.MappingFileNameFormat; | 14 | import cuchaz.enigma.translation.mapping.MappingFileNameFormat; |
| 15 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | 15 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; |
| 16 | 16 | ||
| 17 | import javax.annotation.Nullable; | ||
| 18 | import java.io.BufferedReader; | ||
| 19 | import java.io.IOException; | ||
| 20 | import java.io.InputStreamReader; | ||
| 17 | import java.io.Reader; | 21 | import java.io.Reader; |
| 18 | import java.lang.reflect.Type; | 22 | import java.lang.reflect.Type; |
| 23 | import java.nio.charset.StandardCharsets; | ||
| 24 | import java.nio.file.Files; | ||
| 25 | import java.nio.file.Path; | ||
| 19 | import java.util.Collections; | 26 | import java.util.Collections; |
| 20 | import java.util.List; | 27 | import java.util.List; |
| 21 | import java.util.Map; | 28 | import 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 | } |