 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
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");
static Path getSettingsFile()
Returns the main settings file.
static Path getKeybindingsFileVersion2(@Nullable final CharSequence hostname, @Nullable final CharSequence character)
Returns the keybindings file.
static Path getDialogsFile(@NotNull final String skinName)
Returns the file for storing dialog related information for a skin.
static Path getCrossfireFile()
Returns the crossfire settings directory.
Filenames()
Private constructor to prevent instantiation.
static String encode(@NotNull final CharSequence str)
Encodes a string to make it safe as a file name.
static void hexEncode2(@NotNull final StringBuilder sb, final int value)
Append a given value as a two digits hexadecimal number.
Utility class for en-/decoding hexadecimal strings.
static Path getMagicMapImageCacheDir()
Returns the image cache directory for magic map sized images.
Utility class to return references to settings files.
static Path getShortcutsFile(@NotNull final CharSequence hostname, @NotNull final CharSequence character)
Returns the shortcuts file.
static Path getScaledImageCacheDir()
Returns the image cache directory for double size images.
static Path getSettingsFile(@NotNull final String filename)
Returns a file within the settings directory.
static Path getMessageLogFile(@Nullable final String hostname)
Returns the log file for text message logging.
static Path getOriginalImageCacheDir()
Returns the image cache directory.
static Path getKeybindingsFileVersion1(@Nullable final CharSequence hostname, @Nullable final CharSequence character)
Returns the fallback keybindings file.
static Path getMetaserverCacheFile()
Returns the metaserver cache file.