diff --git a/src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java b/src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java index 733cd1eb..92770b23 100644 --- a/src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java +++ b/src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java @@ -138,9 +138,9 @@ public class TRIFAGlobals static long MESSAGE_V2_MSG_SENT_OK = (Long.MAX_VALUE - 1); static int global_self_connection_status = ToxVars.TOX_CONNECTION.TOX_CONNECTION_NONE.value; - final static String VFS_TMP_FILE_DIR = "./tempdir/files/"; + static String VFS_TMP_FILE_DIR = "./tempdir/files/"; // final static String VFS_TMP_AVATAR_DIR = "/avatar_tempdir/files/"; // TODO: avatar should get their own directory! - public final static String VFS_FILE_DIR = "./datadir/files/"; + public static String VFS_FILE_DIR = "./datadir/files/"; final static String VFS_OWN_AVATAR_DIR = "./datadir/myavatar/"; static String VFS_PREFIX = ""; // only set for normal (unencrypted) storage diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index c3de9c17..f6a1bbeb 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -258,6 +258,7 @@ fun App() println("User data dir: " + APPDIRS.getUserDataDir()) println("User data dir (roaming): " + APPDIRS.getUserDataDir(roaming = true)) + savepathstore.updatePath(APPDIRS.getUserDataDir(roaming = true)) println("User config dir: " + APPDIRS.getUserConfigDir()) println("User config dir (roaming): " + APPDIRS.getUserConfigDir(roaming = true)) println("User cache dir: " + APPDIRS.getUserCacheDir()) @@ -346,6 +347,7 @@ fun App() start_button_text = "stop" }.start() TrifaToxService.stop_me = false + savepathstore.createPathDirectories() main_init() } }) { diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt index b49541a5..40ea640b 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt @@ -304,6 +304,14 @@ class MainActivity } catch (_: Exception) { } + + try + { + PrintWriter("toxid.txt", "UTF-8").use { out -> out.write(my_tox_id_temp) } + Log.i(TAG, "also writing toxid to current directory: " + "toxid.txt") + } catch (_: Exception) + { + } } init diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/savepathenabled_state.kt b/src/main/kotlin/com/zoffcc/applications/trifa/savepathenabled_state.kt index cfc623d0..d4405ebc 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/savepathenabled_state.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/savepathenabled_state.kt @@ -1,5 +1,9 @@ package com.zoffcc.applications.trifa +import com.zoffcc.applications.trifa.MainActivity.Companion.PREF__database_files_dir +import com.zoffcc.applications.trifa.MainActivity.Companion.PREF__tox_savefile_dir +import com.zoffcc.applications.trifa.TRIFAGlobals.VFS_FILE_DIR +import com.zoffcc.applications.trifa.TRIFAGlobals.VFS_TMP_FILE_DIR import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.MutableStateFlow @@ -15,7 +19,9 @@ data class savepathenabled_state( interface SavepathStore { fun updatePath(p: String) + fun createPathDirectories() fun updateEnabled(e: Boolean) + fun isEnabled(): Boolean val stateFlow: StateFlow val state get() = stateFlow.value } @@ -33,12 +39,28 @@ fun CoroutineScope.createSavepathStore(): SavepathStore { channelPath.send(p) } } + override fun createPathDirectories() + { + try + { + val dir_file = File(PREF__tox_savefile_dir) + dir_file.mkdirs() + } + catch(e: Exception) + { + Log.i(TAG, "error creating savefile directory and parents: " + PREF__tox_savefile_dir) + } + } override fun updateEnabled(e: Boolean) { launch { channelEnabled.send(e) } } + override fun isEnabled(): Boolean + { + return state.savePathEnabled + } init { launch { @@ -52,11 +74,23 @@ fun CoroutineScope.createSavepathStore(): SavepathStore { } launch { channelPath.consumeAsFlow().collect { item -> - mutableStateFlow.value = - state.copy( - savePathEnabled = state.savePathEnabled, - savePath = item - ) + try + { + val dir_file = File(item) + PREF__tox_savefile_dir = item + PREF__database_files_dir = item + VFS_TMP_FILE_DIR = PREF__tox_savefile_dir + File.separator + "/tempdir/files/" + VFS_FILE_DIR = PREF__tox_savefile_dir + File.separator + "/datadir/files/" + mutableStateFlow.value = + state.copy( + savePathEnabled = state.savePathEnabled, + savePath = item + ) + } + catch(e: Exception) + { + Log.i(TAG, "error setting savefile dir: " + item) + } } } diff --git a/src/main/kotlin/org/briarproject/briar/desktop/SettingDetails.kt b/src/main/kotlin/org/briarproject/briar/desktop/SettingDetails.kt index 5af895dc..85d7d62c 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/SettingDetails.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/SettingDetails.kt @@ -42,6 +42,7 @@ import androidx.compose.material.MaterialTheme import androidx.compose.material.Switch import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -55,6 +56,8 @@ import com.zoffcc.applications.trifa.HelperFriend import com.zoffcc.applications.trifa.HelperFriend.get_g_opts import com.zoffcc.applications.trifa.HelperFriend.set_g_opts import com.zoffcc.applications.trifa.HelperNotification +import com.zoffcc.applications.trifa.HelperOSFile.show_containing_dir_in_explorer +import com.zoffcc.applications.trifa.MainActivity import com.zoffcc.applications.trifa.MainActivity.Companion.DB_PREF__open_files_directly import com.zoffcc.applications.trifa.TrifaToxService.Companion.orma import global_prefs @@ -62,7 +65,9 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import org.briarproject.briar.desktop.ui.VerticallyScrollableArea import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n +import savepathstore import update_bootstrap_nodes_from_internet +import java.io.File @Composable fun SettingDetails() @@ -254,6 +259,21 @@ fun SettingDetails() } // database prefs =================== + val savepathdata by savepathstore.stateFlow.collectAsState() + if (!savepathdata.savePathEnabled) + { + Row(Modifier.wrapContentHeight().fillMaxWidth().padding(start = 15.dp)) { + Button(modifier = Modifier.width(400.dp), + enabled = true, + onClick = { + show_containing_dir_in_explorer(MainActivity.PREF__tox_savefile_dir + File.separator + ".") + }) + { + Text("Open data directory") + } + } + } + Row(Modifier.wrapContentHeight().fillMaxWidth().padding(start = 15.dp)) { Button(modifier = Modifier.width(400.dp), enabled = true,