-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (48 loc) · 1.13 KB
/
main.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"crypto/sha256"
"encoding/hex"
"log"
"os"
"path/filepath"
"howett.net/plist"
)
func HashFile(filename string) (string, error) {
hasher := sha256.New()
s, err := os.ReadFile(filename)
hasher.Write(s)
if err != nil {
return "", err
}
return hex.EncodeToString(hasher.Sum(nil)), nil
}
func main() {
icons, err := filepath.Glob("*.png")
if err != nil {
log.Fatalf("could not find *.png files: %v", err)
}
hashes := make(map[string]string)
for _, icon := range icons {
hash, err := HashFile(icon)
if err != nil {
log.Fatalf("could not open file: %v", err)
}
hashes[icon] = hash
}
tempout, err := os.CreateTemp(".", "iconic-*.plist")
if err != nil {
log.Fatalf("could not open temp file: %v", err)
}
defer os.Remove(tempout.Name())
encoder := plist.NewEncoderForFormat(tempout, plist.XMLFormat)
encoder.Indent("\t")
encoder.Encode(hashes)
if err := tempout.Close(); err != nil {
log.Fatalf("could not save temp results: %v", err)
}
// replace
err = os.Rename(tempout.Name(), "_icon_hashes.plist")
if err != nil {
log.Fatalf("could not replace _icon_hashes.plist: %v", err)
}
}