23 package com.realtime.crossfire.jxclient.settings;
26 import java.io.IOException;
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30 import org.jetbrains.annotations.NotNull;
31 import org.jetbrains.annotations.Nullable;
53 }
catch (
final IOException ex) {
54 System.err.println(ex.getMessage());
56 throw new AssertionError(ex);
68 }
catch (
final IOException ex) {
69 System.err.println(ex.getMessage());
71 throw new AssertionError(ex);
83 }
catch (
final IOException ex) {
84 System.err.println(ex.getMessage());
86 throw new AssertionError(ex);
110 public static Path
getShortcutsFile(@NotNull
final CharSequence hostname, @NotNull
final CharSequence character)
throws IOException {
124 public static Path
getKeybindingsFileVersion2(@Nullable
final CharSequence hostname, @Nullable
final CharSequence character)
throws IOException {
125 return getSettingsFile(hostname ==
null || character ==
null ?
"keybindings2.txt" :
"keybindings2-"+
encode(hostname)+
"-"+
encode(character)+
".txt");
138 public static Path
getKeybindingsFileVersion1(@Nullable
final CharSequence hostname, @Nullable
final CharSequence character)
throws IOException {
139 return getSettingsFile(hostname ==
null || character ==
null ?
"keybindings.txt" :
"keybindings-"+
encode(hostname)+
"-"+
encode(character)+
".txt");
151 }
catch (
final IOException ex) {
152 System.err.println(
"Cannot access metaserver cache file: "+ex.getMessage());
164 public static Path
getDialogsFile(@NotNull
final String skinName)
throws IOException {
175 public static Path
getSettingsFile(@NotNull
final String filename)
throws IOException {
177 Files.createDirectories(settingsDir);
178 return settingsDir.resolve(filename);
188 final String home = System.getProperty(
"user.home");
190 throw new IOException(
"cannot find home directory");
193 return Paths.get(home).resolve(
".crossfire");
202 private static String
encode(@NotNull
final CharSequence str) {
203 final StringBuilder sb =
new StringBuilder();
204 for (
int i = 0; i < str.length(); i++) {
205 final char ch = str.charAt(i);
206 if ((
'a' <= ch && ch <=
'z') || (
'A' <= ch && ch <=
'Z') || (
'0' <= ch && ch <=
'9') || ch ==
'-' || ch ==
'_' || ch ==
'.') {
213 return sb.toString();
224 return getSettingsFile(hostname ==
null ?
"jxclient.txt" :
"jxclient-"+hostname+
".txt");