2023-03-25 18:09:22 +09:00
|
|
|
package main
|
2022-10-05 20:58:35 +09:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2023-03-25 18:09:22 +09:00
|
|
|
"os"
|
|
|
|
"strings"
|
2022-10-05 20:58:35 +09:00
|
|
|
|
2023-03-25 18:09:22 +09:00
|
|
|
"github.com/fumiama/imgsz"
|
2022-10-05 20:58:35 +09:00
|
|
|
)
|
|
|
|
|
2023-03-25 18:09:22 +09:00
|
|
|
//go:generate go run main.go
|
2022-10-05 20:58:35 +09:00
|
|
|
|
2023-03-25 18:09:22 +09:00
|
|
|
const wifvesdir = "./wives/"
|
|
|
|
const jsonfile = "wife.json"
|
2022-10-05 20:58:35 +09:00
|
|
|
|
2023-03-25 18:09:22 +09:00
|
|
|
func main() {
|
|
|
|
ent, err := os.ReadDir(wifvesdir)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
cards := make([]string, 0, len(ent))
|
|
|
|
for _, en := range ent {
|
|
|
|
if en.IsDir() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
name := en.Name()
|
|
|
|
fn := wifvesdir + name
|
|
|
|
f, err := os.Open(fn)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
_, format, err := imgsz.DecodeSize(f)
|
|
|
|
_ = f.Close()
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
i := strings.LastIndex(name, ".")
|
|
|
|
if i <= 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
name = name[:i] + "." + format
|
|
|
|
nfn := wifvesdir + name
|
|
|
|
if fn != nfn {
|
|
|
|
err = os.Rename(fn, nfn)
|
2022-10-05 20:58:35 +09:00
|
|
|
if err != nil {
|
2023-03-25 18:09:22 +09:00
|
|
|
continue
|
2022-10-15 01:16:07 +09:00
|
|
|
}
|
2023-03-25 18:09:22 +09:00
|
|
|
}
|
|
|
|
cards = append(cards, name)
|
|
|
|
}
|
|
|
|
f, err := os.Create(jsonfile)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
err = json.NewEncoder(f).Encode(cards)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-10-05 20:58:35 +09:00
|
|
|
}
|