forked from Edru2/DeMuddler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResourcesHelper.go
48 lines (41 loc) · 909 Bytes
/
ResourcesHelper.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
package main
import (
"archive/zip"
"io"
"os"
"path/filepath"
"strings"
)
func handleResources(f *zip.File, destDir string) {
destPath := filepath.Join(destDir, f.Name)
if f.FileInfo().IsDir() {
if err := os.MkdirAll(destPath, os.ModePerm); err != nil {
panic(err)
}
} else {
if err := os.MkdirAll(filepath.Dir(destPath), os.ModePerm); err != nil {
panic(err)
}
rc, err := f.Open()
if err != nil {
panic(err)
}
defer rc.Close()
outFile, err := os.Create(destPath)
if err != nil {
panic(err)
}
defer outFile.Close()
if _, err = io.Copy(outFile, rc); err != nil {
panic(err)
}
if strings.HasPrefix(f.Name, ".mudlet/Icon/") {
content, err := io.ReadAll(rc)
if err != nil {
panic(err)
}
fileName := strings.TrimPrefix(filepath.FromSlash(f.Name), ".mudlet/Icon/")
os.WriteFile(filepath.Join(destDir, fileName), content, 0644)
}
}
}