From be34fb625479ea0a32d40d50c0b9e10f2559a38e Mon Sep 17 00:00:00 2001 From: CAPEL Maxime <83071634+fortyup@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:37:03 +0100 Subject: [PATCH] Remove readJsonFile function --- src/main/kotlin/main/Main.kt | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/main/kotlin/main/Main.kt b/src/main/kotlin/main/Main.kt index a8e2609..57b29ba 100644 --- a/src/main/kotlin/main/Main.kt +++ b/src/main/kotlin/main/Main.kt @@ -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() @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> { - 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 { if (!File("glossaire.json").exists() || File("glossaire.json").length() == 0L) { return emptyList() } - try { + return try { val content = File("glossaire.json").readText() - return Json.decodeFromString>(content) + Json.decodeFromString>(content) } catch (e: IOException) { e.printStackTrace() - return emptyList() // Handle the exception as needed + emptyList() // Handle the exception as needed } }