Newer
Older
Twilight / src / main / kotlin / net / taehui / twilight / system / NoteFilesSystem.kt
@Taehui Taehui on 6 Nov 1 KB 2023-11-06 오후 7:15
package net.taehui.twilight.system

import net.taehui.twilight.Logger
import net.taehui.twilight.TwilightComponent
import net.taehui.twilight.Utility
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Path
import java.util.concurrent.ConcurrentHashMap

object NoteFilesSystem : Logger {
    private val noteFiles = ConcurrentHashMap<String, Path>()

    fun loadNoteFiles() {
        try {
            noteFiles.clear()
            Files.list(TwilightComponent.NOTE_ENTRY_PATH).use { noteFilePaths ->
                noteFilePaths.forEach { noteFilePath ->
                    noteFiles["${noteFilePath.fileName}:0"] = noteFilePath
                }
            }
            logInfo("Loaded Note Files")
        } catch (e: IOException) {
            logFault(e)
        }
    }

    val noteFile: Map.Entry<String, Path>?
        get() = Utility.getSaltedItem(ArrayList<Map.Entry<String, Path>?>(noteFiles.entries), null)

    fun getNoteFile(noteID: String): Path? {
        return noteFiles[noteID]
    }

    fun hasNoteFile(noteID: String): Boolean {
        return noteFiles.containsKey(noteID)
    }
}