23 package com.realtime.crossfire.jxclient.window;
29 import java.io.BufferedReader;
30 import java.io.BufferedWriter;
31 import java.io.IOException;
32 import java.nio.charset.StandardCharsets;
33 import java.nio.
file.Files;
34 import java.nio.file.NoSuchFileException;
35 import java.nio.file.Path;
36 import org.jetbrains.annotations.NotNull;
56 public static void loadShortcuts(@NotNull
final Shortcuts shortcuts, @NotNull
final CharSequence hostname, @NotNull
final CharSequence character) {
60 }
catch (
final IOException ex) {
61 System.err.println(
"Cannot read shortcuts file: "+ex.getMessage());
66 shortcuts.clearShortcuts();
67 shortcuts.setFile(file);
68 try (BufferedReader br = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
70 final String line = br.readLine();
71 shortcuts.setShortcutString(shortcutSlot, line ==
null ?
"" : line,
false);
75 }
catch (
final NoSuchFileException ignored) {
78 }
catch (
final IOException ex) {
79 System.err.println(
"Cannot read shortcuts file "+file+
": "+ex.getMessage());
90 public static void saveShortcuts(@NotNull
final Path file, @NotNull
final Iterable<Shortcut> shortcuts) {
92 try (BufferedWriter bw = Files.newBufferedWriter(file)) {
93 for (
Shortcut shortcut : shortcuts) {
94 if (shortcut ==
null) {
97 bw.write(shortcut.getCommand());
102 }
catch (
final IOException ex) {
103 System.err.println(
"Cannot write shortcuts file "+file+
": "+ex.getMessage());