File not found Fixes

Dieser Commit ist enthalten in:
Chaoscaot 2023-01-21 19:51:10 +01:00
Ursprung ec2a74de1f
Commit af638716ad

Datei anzeigen

@ -15,7 +15,14 @@ data class GroupData(val name: String, val fights: MutableList<Int>)
@OptIn(ExperimentalSerializationApi::class)
class Groups {
companion object {
private var groups: GroupsData = Cbor.decodeFromByteArray(kGroupsFile.readBytes())
private var groups: GroupsData = if (kGroupsFile.exists()) {
Cbor.decodeFromByteArray(kGroupsFile.readBytes())
} else {
kGroupsFile.createNewFile()
kGroupsFile.writeBytes(Cbor.encodeToByteArray(GroupsData(mutableListOf())))
GroupsData(mutableListOf())
}
fun getGroup(name: String): GroupData? {
return groups.groups.find { it.name == name }