/
desktopfile.go
36 lines (31 loc) · 1.09 KB
/
desktopfile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package helpers
import (
"errors"
"gopkg.in/ini.v1"
"path/filepath"
"strings"
)
func CheckDesktopFile(desktopfile string) error {
// Check for presence of required keys and abort otherwise
d, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: true}, // Do not cripple lines hat contain ";"
desktopfile)
PrintError("ini.load", err)
neededKeys := []string{"Categories", "Name", "Exec", "Type", "Icon"}
for _, k := range neededKeys {
if d.Section("Desktop Entry").HasKey(k) == false {
return errors.New(".desktop file is missing a '" + k + "'= key\n")
}
}
val, _ := d.Section("Desktop Entry").GetKey("Icon")
iconname := val.String()
if strings.Contains(iconname, "/") {
return errors.New("Desktop file contains Icon= entry with a path")
}
if strings.HasSuffix(filepath.Base(iconname), ".png") ||
strings.HasSuffix(filepath.Base(iconname), ".svg") ||
strings.HasSuffix(filepath.Base(iconname), ".svgz") ||
strings.HasSuffix(filepath.Base(iconname), ".xpm") {
return errors.New("Desktop file contains Icon= entry with a suffix, please remove the suffix")
}
return nil
}