github.com/Mrs4s/go-cqhttp@v1.2.0/winres/gen/json.go (about) 1 // Package main generates winres.json 2 package main 3 4 import ( 5 "bytes" 6 "fmt" 7 "os" 8 "os/exec" 9 "strings" 10 "time" 11 12 "github.com/Mrs4s/go-cqhttp/internal/base" 13 ) 14 15 const js = `{ 16 "RT_GROUP_ICON": { 17 "APP": { 18 "0000": [ 19 "icon.png", 20 "icon16.png" 21 ] 22 } 23 }, 24 "RT_MANIFEST": { 25 "#1": { 26 "0409": { 27 "identity": { 28 "name": "go-cqhttp", 29 "version": "%s" 30 }, 31 "description": "", 32 "minimum-os": "vista", 33 "execution-level": "as invoker", 34 "ui-access": false, 35 "auto-elevate": false, 36 "dpi-awareness": "system", 37 "disable-theming": false, 38 "disable-window-filtering": false, 39 "high-resolution-scrolling-aware": false, 40 "ultra-high-resolution-scrolling-aware": false, 41 "long-path-aware": false, 42 "printer-driver-isolation": false, 43 "gdi-scaling": false, 44 "segment-heap": false, 45 "use-common-controls-v6": false 46 } 47 } 48 }, 49 "RT_VERSION": { 50 "#1": { 51 "0000": { 52 "fixed": { 53 "file_version": "%s", 54 "product_version": "%s", 55 "timestamp": "%s" 56 }, 57 "info": { 58 "0409": { 59 "Comments": "Golang implementation of cqhttp.", 60 "CompanyName": "Mrs4s", 61 "FileDescription": "https://github.com/Mrs4s/go-cqhttp", 62 "FileVersion": "%s", 63 "InternalName": "", 64 "LegalCopyright": "©️ 2020 - %d Mrs4s. All Rights Reserved.", 65 "LegalTrademarks": "", 66 "OriginalFilename": "GOCQHTTP.EXE", 67 "PrivateBuild": "", 68 "ProductName": "go-cqhttp", 69 "ProductVersion": "%s", 70 "SpecialBuild": "" 71 } 72 } 73 } 74 } 75 } 76 }` 77 78 const timeformat = `2006-01-02T15:04:05+08:00` 79 80 func main() { 81 f, err := os.Create("winres.json") 82 if err != nil { 83 panic(err) 84 } 85 defer f.Close() 86 v := "" 87 if base.Version == "(devel)" { 88 vartag := bytes.NewBuffer(nil) 89 vartagcmd := exec.Command("git", "tag", "--sort=committerdate") 90 vartagcmd.Stdout = vartag 91 err = vartagcmd.Run() 92 if err != nil { 93 panic(err) 94 } 95 s := strings.Split(vartag.String(), "\n") 96 v = s[len(s)-2] 97 } else { 98 v = base.Version 99 } 100 i := strings.Index(v, "-") // remove -rc / -beta 101 if i <= 0 { 102 i = len(v) 103 } 104 commitcnt := strings.Builder{} 105 commitcnt.WriteString(v[1:i]) 106 commitcnt.WriteByte('.') 107 commitcntcmd := exec.Command("git", "rev-list", "--count", "master") 108 commitcntcmd.Stdout = &commitcnt 109 err = commitcntcmd.Run() 110 if err != nil { 111 panic(err) 112 } 113 fv := commitcnt.String()[:commitcnt.Len()-1] 114 _, err = fmt.Fprintf(f, js, fv, fv, v, time.Now().Format(timeformat), fv, time.Now().Year(), v) 115 if err != nil { 116 panic(err) 117 } 118 }