|
|
@@ -1,5 +1,6 @@
|
|
|
package eu.mjdev.desktop.provider.data
|
|
|
|
|
|
+import org.ini4j.Ini
|
|
|
import java.io.File
|
|
|
|
|
|
@Suppress("ConstPropertyName", "unused")
|
|
|
@@ -7,54 +8,43 @@ class DesktopFile(
|
|
|
val file: File
|
|
|
) {
|
|
|
private val content
|
|
|
- get() = file.readText()
|
|
|
-
|
|
|
- private val lines
|
|
|
- get() = content.split("\n").map { line ->
|
|
|
- line.trim()
|
|
|
- }
|
|
|
+ get() = Ini(file)
|
|
|
|
|
|
private val props
|
|
|
- get() = lines.mapNotNull { line ->
|
|
|
- if (line.contains("=")) {
|
|
|
- val first = line.substring(0, line.indexOf('='))
|
|
|
- val second = line.substring(line.indexOf('=') + 1)
|
|
|
- Pair(first, second)
|
|
|
- } else null
|
|
|
- }.toMap()
|
|
|
+ get() = content.get("Desktop Entry")
|
|
|
|
|
|
val type
|
|
|
- get() = props[Prop_Type] ?: ""
|
|
|
+ get() = props?.get(Prop_Type) ?: ""
|
|
|
|
|
|
val version
|
|
|
- get() = props[Prop_Version] ?: ""
|
|
|
+ get() = props?.get(Prop_Version) ?: ""
|
|
|
|
|
|
val name
|
|
|
- get() = props[Prop_Name] ?: ""
|
|
|
+ get() = props?.get(Prop_Name) ?: ""
|
|
|
|
|
|
val comment
|
|
|
- get() = props[Prop_Comment] ?: ""
|
|
|
+ get() = props?.get(Prop_Comment) ?: ""
|
|
|
|
|
|
val path
|
|
|
- get() = props[Prop_Path] ?: ""
|
|
|
+ get() = props?.get(Prop_Path) ?: ""
|
|
|
|
|
|
val exec
|
|
|
- get() = props[Prop_Exec] ?: ""
|
|
|
+ get() = props?.get(Prop_Exec) ?: ""
|
|
|
|
|
|
val icon
|
|
|
- get() = props[Prop_Icon] ?: ""
|
|
|
+ get() = props?.get(Prop_Icon) ?: ""
|
|
|
|
|
|
val categories
|
|
|
- get() = (props[Prop_Categories] ?: "").split(";").toList()
|
|
|
+ get() = (props?.get(Prop_Categories) ?: "").split(";").toList()
|
|
|
|
|
|
val notifyOnStart
|
|
|
- get() = (props[Prop_StartupNotify] ?: "false").asBoolean()
|
|
|
+ get() = (props?.get(Prop_StartupNotify) ?: "false").asBoolean()
|
|
|
|
|
|
val runInTerminal
|
|
|
- get() = (props[Prop_Terminal] ?: "false").asBoolean()
|
|
|
+ get() = (props?.get(Prop_Terminal) ?: "false").asBoolean()
|
|
|
|
|
|
companion object {
|
|
|
- const val Prop_Type = "Type" // string
|
|
|
+ const val Prop_Type = "Type" // string "Application"
|
|
|
const val Prop_Version = "Version" // string
|
|
|
const val Prop_Path = "Path" // string
|
|
|
const val Prop_Name = "Name" // string
|
|
|
@@ -64,6 +54,9 @@ class DesktopFile(
|
|
|
const val Prop_Terminal = "Terminal" // boolean
|
|
|
const val Prop_Icon = "Icon" // string
|
|
|
const val Prop_Categories = "Categories" // string delimited ;
|
|
|
+ const val Prop_GenericName = "GenericName"
|
|
|
+ const val Prop_MimeType = "MimeType" // string delimited ;
|
|
|
+ const val Prop_Actions = "Actions"
|
|
|
|
|
|
private fun String.asBoolean(): Boolean = when (this.lowercase()) {
|
|
|
"true" -> true
|