阶段十:完成 Go Cmd Tools 注释基线清零

This commit is contained in:
Christ committed 2026-08-15 05:40:01 +08:00
1 parent 393c45a1e3
commit ea1f2ec430
25 files changed
+694 -4281

No files matched your search

+8 -1
View File
@@ -8,12 +8,14 @@ import (
"os"
)
// main 负责main相关处理。
func main() {
if len(os.Args) != 3 {
fmt.Fprintln(os.Stderr, "usage: iconconv input.png output.ico")
os.Exit(2)
}
// data、err 保存data、err,供当前处理流程使用
data, err := os.ReadFile(os.Args[1])
if err != nil {
panic(err)
@@ -21,12 +23,16 @@ func main() {
// A PNG-compressed 256x256 image is valid in an ICO file and keeps the
// alpha channel of the original product icon.
// headerSize 保存header数量,供当前处理流程使用
const headerSize = 6
// entrySize 保存entry数量,供当前处理流程使用
const entrySize = 16
// result 保存结果,供当前处理流程使用
result := make([]byte, headerSize+entrySize+len(data))
binary.LittleEndian.PutUint16(result[0:2], 0)
binary.LittleEndian.PutUint16(result[2:4], 1)
binary.LittleEndian.PutUint16(result[4:6], 1)
// entry 保存entry,供当前处理流程使用
entry := result[headerSize : headerSize+entrySize]
entry[0] = 0 // 0 means 256 in the ICO format.
entry[1] = 0
@@ -36,7 +42,8 @@ func main() {
binary.LittleEndian.PutUint32(entry[12:16], headerSize+entrySize)
copy(result[headerSize+entrySize:], data)
if err := os.WriteFile(os.Args[2], result, 0644); err != nil {
if // err 保存err,供当前处理流程使用
err := os.WriteFile(os.Args[2], result, 0644); err != nil {
panic(err)
}
}