Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data directory updates #65

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -346,6 +347,7 @@ fun App()
start_button_text = "stop"
}.start()
TrifaToxService.stop_me = false
savepathstore.createPathDirectories()
main_init()
}
}) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<savepathenabled_state>
val state get() = stateFlow.value
}
Expand All @@ -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 {
Expand All @@ -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)
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/org/briarproject/briar/desktop/SettingDetails.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,14 +56,18 @@ 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
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()
Expand Down Expand Up @@ -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,
Expand Down
Loading