aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
diff options
context:
space:
mode:
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.kt15
1 files changed, 9 insertions, 6 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 9aa2037..9e69790 100644
--- a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
+++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
@@ -1,6 +1,6 @@
1/* 1/*
2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon 2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
3 * Copyright (C) 2017-2020 Pacien TRAN-GIRARD 3 * Copyright (C) 2017-2023 Pacien TRAN-GIRARD
4 * 4 *
5 * This program is free software: you can redistribute it and/or modify 5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -49,11 +49,14 @@ object AppPaths {
49 49
50 private val context by lazy { App.getContext() } 50 private val context by lazy { App.getContext() }
51 51
52 private fun cacheDir() = context.cacheDir!! 52 private fun privateCacheDir() = context.cacheDir!!
53 private fun publicCacheDir() = context.externalCacheDir!!
54 private fun publicFilesDir() = context.getExternalFilesDir(null)
53 private fun binDir() = File(context.applicationInfo.nativeLibraryDir) 55 private fun binDir() = File(context.applicationInfo.nativeLibraryDir)
54 fun runtimeDir() = withDir(File(cacheDir(), APP_TINC_RUNTIME_DIR)) 56
55 fun logDir() = withDir(File(cacheDir(), APP_LOG_DIR)) 57 fun runtimeDir() = withDir(File(privateCacheDir(), APP_TINC_RUNTIME_DIR))
56 fun confDir() = withDir(File(context.filesDir!!, APP_TINC_NETWORKS_DIR)) 58 fun logDir() = withDir(File(publicCacheDir(), APP_LOG_DIR))
59 fun confDir() = withDir(File(publicFilesDir(), APP_TINC_NETWORKS_DIR))
57 60
58 fun confDir(netName: String) = File(confDir(), netName) 61 fun confDir(netName: String) = File(confDir(), netName)
59 fun hostsDir(netName: String) = File(confDir(netName), NET_HOSTS_DIR) 62 fun hostsDir(netName: String) = File(confDir(netName), NET_HOSTS_DIR)
@@ -63,7 +66,7 @@ object AppPaths {
63 fun logFile(netName: String) = File(logDir(), String.format(LOGFILE_FORMAT, netName)) 66 fun logFile(netName: String) = File(logDir(), String.format(LOGFILE_FORMAT, netName))
64 fun pidFile(netName: String) = File(runtimeDir(), String.format(PIDFILE_FORMAT, netName)) 67 fun pidFile(netName: String) = File(runtimeDir(), String.format(PIDFILE_FORMAT, netName))
65 fun appLogFile() = File(logDir(), APPLOG_FILE) 68 fun appLogFile() = File(logDir(), APPLOG_FILE)
66 fun crashFlagFile() = File(cacheDir(), CRASHFLAG_FILE) 69 fun crashFlagFile() = File(privateCacheDir(), CRASHFLAG_FILE)
67 70
68 fun existing(f: File) = f.apply { if (!exists()) throw FileNotFoundException(f.absolutePath) } 71 fun existing(f: File) = f.apply { if (!exists()) throw FileNotFoundException(f.absolutePath) }
69 fun withDir(f: File) = f.apply { if (!exists()) mkdirs() } 72 fun withDir(f: File) = f.apply { if (!exists()) mkdirs() }