Remove readJsonFile function

main
CAPEL Maxime 2023-12-06 12:37:03 +01:00
parent 7806821abc
commit be34fb6254
1 changed files with 8 additions and 28 deletions

View File

@ -16,26 +16,17 @@ import java.awt.FileDialog
import java.awt.Frame
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.*
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.window.*
import database.DatabaseManager
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import java.io.File
import java.io.FileWriter
import java.io.IOException
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.JsonObject
val connection = DatabaseManager.getConnection()
val customRedColor = Color(0xFFB70D1B)
val glossaireList = mutableListOf<JsonObject>()
@OptIn(ExperimentalComposeUiApi::class)
@Composable
@ -43,7 +34,6 @@ fun HomePage(
onGlossaireClick: () -> Unit,
onCodeAVerifierClick: () -> Unit
) {
var isHover by remember { mutableStateOf(false) }
Column(
modifier = Modifier.fillMaxSize(),
@ -133,9 +123,8 @@ fun App() {
val selectedDirectory = fileDialog.directory
if (selectedFile != null) {
val csvFilePath = "$selectedDirectory$selectedFile"
val jsonFilePath = "glossaire.json" // Replace with the actual path to your JSON file
println("Exporting to: $csvFilePath")
exportToCSV(jsonFilePath, csvFilePath)
exportToCSV(csvFilePath)
} else {
println("Export command cancelled by user.")
}
@ -207,14 +196,14 @@ fun App() {
}
}
fun exportToCSV(jsonFilePath: String, csvFilePath: String) {
val glossary = readJsonFile(jsonFilePath)
fun exportToCSV(csvFilePath: String) {
val glossary = chargerDonneesDepuisFichier()
val csvContent = buildString {
appendLine("Mot;Description;Contexte principal;Contexte 2;Lié à;Synonyme;Antonyme;")
glossary.forEach { entry ->
appendLine(
"${entry["nom"]};${entry["description"]};${entry["contextePrincipal"]};" +
"${entry["contexte2"]};${entry["lieA"]};${entry["synonyme"]};${entry["antonyme"]}"
"${entry.nom};${entry.description};${entry.contextePrincipal};" +
"${entry.contexte2};${entry.lieA};${entry.synonyme};${entry.antonyme}"
)
}
}
@ -226,15 +215,6 @@ fun exportToCSV(jsonFilePath: String, csvFilePath: String) {
e.printStackTrace()
}
}
fun readJsonFile(filePath: String): List<Map<String, String>> {
return try {
val content = File(filePath).readText(Charsets.UTF_8)
Json.decodeFromString(content)
} catch (e: Exception) {
e.printStackTrace()
emptyList()
}
}
fun importCSV(cheminFichier: String) {
val file = File(cheminFichier).readText(Charsets.UTF_8)
@ -587,12 +567,12 @@ fun chargerDonneesDepuisFichier(): List<Mot> {
if (!File("glossaire.json").exists() || File("glossaire.json").length() == 0L) {
return emptyList()
}
try {
return try {
val content = File("glossaire.json").readText()
return Json.decodeFromString<List<Mot>>(content)
Json.decodeFromString<List<Mot>>(content)
} catch (e: IOException) {
e.printStackTrace()
return emptyList() // Handle the exception as needed
emptyList() // Handle the exception as needed
}
}