m3u8d/export/main.go

149 lines
3.0 KiB
Go
Raw Normal View History

2022-05-15 03:05:31 +00:00
package main
import (
"fmt"
"github.com/orestonce/go2cpp"
"golang.org/x/text/encoding/simplifiedchinese"
"io/ioutil"
2022-05-15 03:05:31 +00:00
"m3u8d"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
2022-05-15 03:05:31 +00:00
)
const version = "1.5.1"
2022-05-15 03:05:31 +00:00
func main() {
2022-06-20 23:28:58 +00:00
BuildCliBinary() // 编译二进制
2022-06-21 14:17:26 +00:00
CreateLibForQtUi() // 创建Qt需要使用的.a库文件
WriteVersionDotRc()
2022-05-15 03:05:31 +00:00
}
func BuildCliBinary() {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
type buildCfg struct {
GOOS string
GOARCH string
}
var list = []buildCfg{
{
GOOS: "linux",
GOARCH: "386",
},
2022-05-28 02:11:38 +00:00
{
GOOS: "linux",
GOARCH: "arm",
},
{
GOOS: "linux",
GOARCH: "mipsle",
},
2022-05-15 03:05:31 +00:00
{
GOOS: "darwin",
GOARCH: "amd64",
},
}
for _, cfg := range list {
name := "m3u8d_cli_v" + version + "_" + cfg.GOOS + "_" + cfg.GOARCH
2022-06-25 12:16:21 +00:00
cmd := exec.Command("go", "build", "-trimpath", "-ldflags", "-s -w", "-o", filepath.Join(wd, "bin", name))
2022-05-15 03:05:31 +00:00
cmd.Dir = filepath.Join(wd, "cmd")
cmd.Env = append(os.Environ(), "GOOS="+cfg.GOOS)
cmd.Env = append(cmd.Env, "GOARCH="+cfg.GOARCH)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
fmt.Println(cmd.Dir)
panic(err)
}
fmt.Println("done", name)
}
}
func CreateLibForQtUi() {
ctx := go2cpp.NewGo2cppContext(go2cpp.NewGo2cppContext_Req{
CppBaseName: "m3u8d",
EnableQtClass_RunOnUiThread: true,
EnableQtClass_Toast: true,
})
ctx.Generate1(m3u8d.RunDownload)
2022-06-12 14:43:20 +00:00
ctx.Generate1(m3u8d.CloseOldEnv)
2022-05-15 03:05:31 +00:00
ctx.Generate1(m3u8d.GetProgress)
ctx.Generate1(m3u8d.GetWd)
2022-06-25 12:16:21 +00:00
ctx.Generate1(m3u8d.ParseCurlStr)
ctx.Generate1(m3u8d.RunDownload_Req_ToCurlStr)
2022-05-15 03:05:31 +00:00
ctx.MustCreateAmd64LibraryInDir("m3u8d-qt")
2022-05-29 09:43:00 +00:00
}
func WriteVersionDotRc() {
tmp := strings.Split(version, ".")
ok := len(tmp) == 3
for _, v := range tmp {
vi, err := strconv.Atoi(v)
if err != nil {
ok = false
break
}
if vi < 0 {
ok = false
break
}
}
if ok == false {
panic("version invalid: " + strconv.Quote(version))
}
tmp = append(tmp, "0")
v1 := strings.Join(tmp, ",")
data := []byte(`IDI_ICON1 ICON "favicon.ico"
#if defined(UNDER_CE)
#include <winbase.h>
#else
#include <winver.h>
#endif
VS_VERSION_INFO VERSIONINFO
FILEVERSION ` + v1 + `
PRODUCTVERSION ` + v1 + `
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080404b0"
BEGIN
VALUE "ProductVersion", "` + version + `.0\0"
VALUE "ProductName", "m3u8视频下载工具\0"
VALUE "LegalCopyright", "https://github.com/orestonce/m3u8d\0"
VALUE "FileDescription", "m3u8视频下载工具\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x804, 1200
END
END
`)
data, err := simplifiedchinese.GBK.NewEncoder().Bytes(data)
if err != nil {
panic(err)
}
err = ioutil.WriteFile("m3u8d-qt/version.rc", data, 0777)
if err != nil {
panic(err)
}
}