2021-07-19 06:05:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var qrcExtensions = map[string]bool{
|
|
|
|
".qml": true,
|
|
|
|
".js": true,
|
|
|
|
".svg": true,
|
|
|
|
".png": true,
|
|
|
|
".ico": true,
|
|
|
|
".icns": true,
|
|
|
|
".mp3": true,
|
|
|
|
".wav": true,
|
|
|
|
".otf": true,
|
|
|
|
".ttf": true,
|
|
|
|
".webm": true,
|
2022-05-12 10:28:46 +00:00
|
|
|
".qm": true,
|
|
|
|
".txt": true,
|
|
|
|
".gif": true,
|
2023-03-08 10:26:45 +00:00
|
|
|
".json": true,
|
2023-09-22 10:08:28 +00:00
|
|
|
".mdwn": true,
|
2023-11-16 15:15:37 +00:00
|
|
|
".html": true,
|
2021-07-19 06:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
sourceDirName := flag.String("source", "", "source dir containing ui files")
|
|
|
|
qrcFileName := flag.String("output", "resources.qrc", "output filename")
|
|
|
|
flag.Parse()
|
|
|
|
if flag.NFlag() == 0 {
|
|
|
|
flag.Usage()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
qrcFile, err := os.Create(*qrcFileName)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed creating qrc file: %s", err)
|
|
|
|
}
|
|
|
|
defer qrcFile.Close()
|
|
|
|
|
|
|
|
qrcFile.WriteString("<!DOCTYPE RCC>\n")
|
|
|
|
qrcFile.WriteString("<RCC version=\"1.0\">\n")
|
|
|
|
qrcFile.WriteString(" <qresource>\n")
|
|
|
|
|
|
|
|
counter := 0
|
|
|
|
err = filepath.Walk(*sourceDirName,
|
|
|
|
func(path string, info os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-10-03 15:43:35 +00:00
|
|
|
if info.IsDir() && (info.Name() == "vendor" || info.Name() == "tests" || info.Name() == "StatusQ" || info.Name() == "node_modules") {
|
2023-03-08 10:26:45 +00:00
|
|
|
return filepath.SkipDir
|
|
|
|
}
|
2021-07-19 06:05:15 +00:00
|
|
|
if !info.IsDir() {
|
|
|
|
ext := filepath.Ext(path)
|
|
|
|
base := filepath.Base(path)
|
|
|
|
if qrcExtensions[ext] || base == "qmldir" {
|
|
|
|
counter++
|
|
|
|
fixedPath := strings.ReplaceAll(path, "\\", "/")
|
|
|
|
fixedPath = "./" + strings.TrimPrefix(fixedPath, *sourceDirName)
|
|
|
|
qrcFile.WriteString(" <file>" + fixedPath + "</file>\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
qrcFile.WriteString(" </qresource>\n")
|
|
|
|
qrcFile.WriteString("</RCC>")
|
|
|
|
|
|
|
|
fmt.Printf("%d resources added\n", counter)
|
|
|
|
}
|