diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/context/AppPaths.kt')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/context/AppPaths.kt | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt index 005cded..2d5e2e4 100644 --- a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt +++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt | |||
@@ -11,40 +11,40 @@ import java.io.FileNotFoundException | |||
11 | */ | 11 | */ |
12 | object AppPaths { | 12 | object AppPaths { |
13 | 13 | ||
14 | private val TINCD_BIN = "libtincd.so" | 14 | private val TINCD_BIN = "libtincd.so" |
15 | private val TINC_BIN = "libtinc.so" | 15 | private val TINC_BIN = "libtinc.so" |
16 | 16 | ||
17 | private val LOGFILE_FORMAT = "tinc.%s.log" | 17 | private val LOGFILE_FORMAT = "tinc.%s.log" |
18 | private val PIDFILE_FORMAT = "tinc.%s.pid" | 18 | private val PIDFILE_FORMAT = "tinc.%s.pid" |
19 | 19 | ||
20 | private val NET_CONF_FILE = "network.conf" | 20 | private val NET_CONF_FILE = "network.conf" |
21 | private val NET_TINC_CONF_FILE = "tinc.conf" | 21 | private val NET_TINC_CONF_FILE = "tinc.conf" |
22 | private val NET_HOSTS_DIR = "hosts" | 22 | private val NET_HOSTS_DIR = "hosts" |
23 | private val NET_INVITATION_FILE = "invitation-data" | 23 | private val NET_INVITATION_FILE = "invitation-data" |
24 | private val NET_DEFAULT_ED25519_PRIVATE_KEY_FILE = "ed25519_key.priv" | 24 | private val NET_DEFAULT_ED25519_PRIVATE_KEY_FILE = "ed25519_key.priv" |
25 | private val NET_DEFAULT_RSA_PRIVATE_KEY_FILE = "rsa_key.priv" | 25 | private val NET_DEFAULT_RSA_PRIVATE_KEY_FILE = "rsa_key.priv" |
26 | 26 | ||
27 | fun storageAvailable() = | 27 | fun storageAvailable() = |
28 | Environment.getExternalStorageState().let { it == Environment.MEDIA_MOUNTED && it != Environment.MEDIA_MOUNTED_READ_ONLY } | 28 | Environment.getExternalStorageState().let { it == Environment.MEDIA_MOUNTED && it != Environment.MEDIA_MOUNTED_READ_ONLY } |
29 | 29 | ||
30 | fun cacheDir() = App.getContext().externalCacheDir | 30 | fun cacheDir() = App.getContext().externalCacheDir |
31 | fun confDir() = App.getContext().getExternalFilesDir(null) | 31 | fun confDir() = App.getContext().getExternalFilesDir(null) |
32 | fun binDir() = File(App.getContext().applicationInfo.nativeLibraryDir) | 32 | fun binDir() = File(App.getContext().applicationInfo.nativeLibraryDir) |
33 | 33 | ||
34 | fun confDir(netName: String) = File(confDir(), netName) | 34 | fun confDir(netName: String) = File(confDir(), netName) |
35 | fun hostsDir(netName: String) = File(confDir(netName), NET_HOSTS_DIR) | 35 | fun hostsDir(netName: String) = File(confDir(netName), NET_HOSTS_DIR) |
36 | fun netConfFile(netName: String) = File(confDir(netName), NET_CONF_FILE) | 36 | fun netConfFile(netName: String) = File(confDir(netName), NET_CONF_FILE) |
37 | fun tincConfFile(netName: String) = File(confDir(netName), NET_TINC_CONF_FILE) | 37 | fun tincConfFile(netName: String) = File(confDir(netName), NET_TINC_CONF_FILE) |
38 | fun invitationFile(netName: String) = File(confDir(netName), NET_INVITATION_FILE) | 38 | fun invitationFile(netName: String) = File(confDir(netName), NET_INVITATION_FILE) |
39 | fun logFile(netName: String) = File(cacheDir(), String.format(LOGFILE_FORMAT, netName)) | 39 | fun logFile(netName: String) = File(cacheDir(), String.format(LOGFILE_FORMAT, netName)) |
40 | fun pidFile(netName: String) = File(App.getContext().cacheDir, String.format(PIDFILE_FORMAT, netName)) | 40 | fun pidFile(netName: String) = File(App.getContext().cacheDir, String.format(PIDFILE_FORMAT, netName)) |
41 | 41 | ||
42 | fun existing(f: File) = f.apply { if (!exists()) throw FileNotFoundException(f.absolutePath) } | 42 | fun existing(f: File) = f.apply { if (!exists()) throw FileNotFoundException(f.absolutePath) } |
43 | 43 | ||
44 | fun defaultEd25519PrivateKeyFile(netName: String) = File(confDir(netName), NET_DEFAULT_ED25519_PRIVATE_KEY_FILE) | 44 | fun defaultEd25519PrivateKeyFile(netName: String) = File(confDir(netName), NET_DEFAULT_ED25519_PRIVATE_KEY_FILE) |
45 | fun defaultRsaPrivateKeyFile(netName: String) = File(confDir(netName), NET_DEFAULT_RSA_PRIVATE_KEY_FILE) | 45 | fun defaultRsaPrivateKeyFile(netName: String) = File(confDir(netName), NET_DEFAULT_RSA_PRIVATE_KEY_FILE) |
46 | 46 | ||
47 | fun tincd() = File(binDir(), TINCD_BIN) | 47 | fun tincd() = File(binDir(), TINCD_BIN) |
48 | fun tinc() = File(binDir(), TINC_BIN) | 48 | fun tinc() = File(binDir(), TINC_BIN) |
49 | 49 | ||
50 | } | 50 | } |