summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/EnigmaProfile.java
diff options
context:
space:
mode:
authorGravatar Joseph Burton2020-05-03 21:06:38 +0100
committerGravatar GitHub2020-05-03 21:06:38 +0100
commit854f4d49407e45d67dd5754afd21a7e59970ca5b (patch)
tree582e3245786f9723b5895b0c8d41087b0e6bb416 /src/main/java/cuchaz/enigma/EnigmaProfile.java
parentRewrite search dialog (#233) (diff)
downloadenigma-fork-854f4d49407e45d67dd5754afd21a7e59970ca5b.tar.gz
enigma-fork-854f4d49407e45d67dd5754afd21a7e59970ca5b.tar.xz
enigma-fork-854f4d49407e45d67dd5754afd21a7e59970ca5b.zip
Multiplayer support (#221)
* First pass on multiplayer * Apply review suggestions * Dedicated Enigma server * Don't jump to references when other users do stuff * Better UI + translations * french translation * Apply review suggestions * Document the protocol * Fix most issues with scrolling. * Apply review suggestions * Fix zip hash issues + add a bit more logging * Optimize zip hash * Fix a couple of login bugs * Add message log and user list * Make Message an abstract class * Make status bar work, add chat box * Hide message log/users list when not connected * Fix status bar not resetting entirely * Run stop server task on server thread to prevent multithreading race conditions * Add c2s message to packet id list * Fix message scroll bar not scrolling to the end * Formatting * User list size -> ushort * Combine contains and remove check * Check removal before sending packet * Add password to login packet * Fix the GUI closing the rename text field when someone else renames something * Update fr_fr.json * oups * Make connection/server create dialogs not useless if it fails once * Refactor UI state updating * Fix imports * Fix Collab menu * Fix NPE when rename not allowed * Make the log file a configurable option * Don't use modified UTF * Update fr_fr.json * Bump version to 0.15.4 * Apparently I can't spell neither words nor semantic versions Co-authored-by: Yanis48 <doublecraft.official@gmail.com> Co-authored-by: 2xsaiko <git@dblsaiko.net>
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 }