提交 1473ccf4 编写于 作者: yanghye's avatar yanghye

修改 liblcl版本在liblclbinres获取

修改 liblcl版本升级检查工具
升级 内置库liblclbinres 1.0.3
上级 44768f79
......@@ -1062,11 +1062,6 @@ func (m *TCEFApplication) LibCefVersion() string {
return api.GoStr(r1)
}
// Version 返回 Energy 版本
func (m *TCEFApplication) Version() string {
return version.Version()
}
// LibVersion 返回 lib-lcl 版本
func (m *TCEFApplication) LibVersion() string {
return version.LibVersion()
......
......@@ -22,11 +22,6 @@ import (
// defInit
// GlobalInit
func defInit() {
{
// Set pascal lib-lcl version
r1, _, _ := imports.Proc(def.LibVersion).Call()
version.SetLibVersion(api.GoStr(r1))
}
{
// Set pascal lib-lcl build version
r1, _, _ := imports.Proc(def.LibBuildVersion).Call()
......
......@@ -11,30 +11,16 @@
// Package version Energy framework version config
package version
import "github.com/energye/liblclbinres"
// Current Branch Version
var (
version = "2.0.1-beta" // golang energy
libVersion = "" // pascal lib-lcl
libBuildVersion = "" // pascal lib-lcl build
libBuildVersion = "" // pascal lib-lcl build
)
// Version return energy version
func Version() string {
return version
}
// LibVersion return lib-lcl version
func LibVersion() string {
return libVersion
}
// SetLibVersion Set pascal lib-lcl version
func SetLibVersion(version string) {
if version == "" {
libVersion = "0.0.0"
} else {
libVersion = version
}
return liblclbinres.LibVersion()
}
// LibBuildVersion return pascal lib build version
......
......@@ -15,8 +15,7 @@ import (
"crypto/tls"
"encoding/json"
"github.com/energye/energy/v2/cmd/internal"
"github.com/energye/energy/v2/common/imports"
"github.com/energye/golcl/lcl/api"
"github.com/energye/liblclbinres"
"io/ioutil"
"net/http"
"strconv"
......@@ -32,34 +31,22 @@ var (
CanUpdateLiblcl LiblclCallback // 参数 model: 更新模块, Level: 更新版本级别, canUpdate: 是否有更新
)
// Update 更新模块
type Update struct {
Liblcl Model `json:"liblcl"`
Energy Model `json:"energy"`
CEF Model `json:"cef"`
}
// Model 模块
type Model struct {
CurrentVersion string `json:"-"`
CurrentVersion string `json:"-"` // 当前版本
Latest string `json:"latest"` // 最新版本
Download Download `json:"download"` // 下载源
Enable bool `json:"enable"` // 是否开启该模块更新
Versions map[string]VersionInfo `json:"versions"` // 当前模块所有版本集合 key=版本, value=版本信息
}
// 更新下载源
type Download struct {
Url string `json:"url"` // 下载地址模板 https://{url}/energye/energy/releases/download/{version}/{OSARCH}.zip
Source []string `json:"source"` // 下载地址源 ["gitee.com", "github.com"]
SourceSelect uint8 `json:"sourceSelect"` // 下载地址源选择, 根据下标(index)选择源(Source), 替换到(Url)模板
}
// 版本信息
type VersionInfo struct {
Content []string `json:"content"` // 更新内容
Forced bool `json:"forced"` // 是否强制更新, 适用当前版本时才启作用
EnergyVersion string `json:"energyVersion"` // 所属 energy 版本
Content string `json:"content"` // 更新内容
DownloadSource string `json:"downloadSource"` // 下载源 逗号分隔, 数组 ["gitee.com", "github.com"]
DownloadSourceSelect int `json:"downloadSourceSelect"` // 下载源 选择
DownloadUrl string `json:"downloadUrl"` // 下载地址, https://{url}/energye/energy/releases/download/{version}/{OSARCH}.zip
Module string `json:"module"` // 模块名
BuildSupportOSArch string `json:"supportOSArch"` // 已提供构建支持的系统架构
Version string `json:"version"` // 版本
}
// CheckUpdate
......@@ -92,9 +79,9 @@ func check() {
}
defer response.Body.Close()
if data, err := ioutil.ReadAll(response.Body); err == nil {
var v = Update{}
var v map[string]*Model
if err = json.Unmarshal(data, &v); err == nil {
liblcl(&v.Liblcl)
liblcl(v["liblcl"])
} else {
println("energy check update json.Unmarshal error", err.Error())
}
......@@ -105,24 +92,25 @@ func check() {
// liblcl Model
func liblcl(model *Model) {
if model.Enable {
r1, _, _ := imports.Proc(1).Call()
currentLib := api.GoStr(r1)
originLib := model.Latest
if currentLib == "" {
currentLib = "0.0.0"
}
if originLib == "" {
originLib = "0.0.0"
}
model.CurrentVersion = currentLib
can, level := compare(currentLib, originLib)
if CanUpdateLiblcl != nil {
CanUpdateLiblcl(model, level, can)
}
currentLib := liblclbinres.LibVersion()
originLib := model.Latest
if currentLib == "" {
currentLib = "0.0.0"
}
if originLib == "" {
originLib = "0.0.0"
}
model.CurrentVersion = currentLib
can, level := compare(currentLib, originLib)
if CanUpdateLiblcl != nil {
CanUpdateLiblcl(model, level, can)
}
}
func LibLCLName(version, buildSupportOSArch string) (string, bool) {
return internal.LibLCLName(version, buildSupportOSArch)
}
// Version comparison, returns true if the current version is smaller than the remote version
func compare(current, origin string) (bool, int) {
cmajor, cminor, crevision := versionConvert(current)
......
......@@ -233,7 +233,7 @@ func runInstall(c *CommandConfig) error {
// 最后根据模块名称来确定使用哪个liblcl
liblclVersion := ToRNilString(installVersion[liblclModuleName], "")
if liblclModule != nil {
libEnergyOS, isSupport := liblclOS(cef, liblclVersion, liblclModule)
libEnergyOS, isSupport := liblclOS(cef, liblclVersion, ToString(liblclModule["buildSupportOSArch"]))
downloadEnergyURL := ToString(liblclModule["downloadUrl"])
downloadEnergyURL = replaceSource(downloadEnergyURL, ToString(liblclModule["downloadSource"]), ToInt(liblclModule["downloadSourceSelect"]), "liblcl")
module := ToString(liblclModule["module"])
......@@ -391,8 +391,7 @@ func liblclName(version, cef string) (string, bool) {
// 命名规则 OS+[ARCH]+BIT+[GTK2]
// ARCH: 非必需, ARM 时填写, AMD为空
// GTK2: 非必需, GTK2(Linux CEF 106) 时填写, 非Linux或GTK3时为空
func liblclOS(cef, version string, module map[string]any) (string, bool) {
buildSupportOSArch := ToString(module["buildSupportOSArch"])
func liblclOS(cef, version, buildSupportOSArch string) (string, bool) {
archs := strings.Split(buildSupportOSArch, ",")
noSuport := fmt.Sprintf("%v %v", runtime.GOOS, runtime.GOARCH)
var isSupport = func(goarch string) bool {
......@@ -413,6 +412,11 @@ func liblclOS(cef, version string, module map[string]any) (string, bool) {
}
}
// LibLCLName
func LibLCLName(version, buildSupportOSArch string) (string, bool) {
return liblclOS("", version, buildSupportOSArch)
}
// 提取文件
func ExtractFiles(keyName, sourcePath string, di *downloadInfo, extractOSConfig map[string]any) {
println("Extract", keyName, "sourcePath:", sourcePath, "targetPath:", di.frameworkPath)
......
......@@ -17,13 +17,15 @@ import (
"fmt"
"github.com/energye/golcl/energy/homedir"
"hash/crc32"
"io/fs"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
)
const liblclVersion = "v2.2.4" // liblcl发布版本
const (
liblclbinres = "/src/github.com/energye/liblclbinres"
golcl = "golcl"
......@@ -54,64 +56,61 @@ func main() {
if err != nil {
panic(err)
}
liblclPath := filepath.Join(dir, golcl)
liblclPath := filepath.Join(dir, golcl, "liblcl")
fmt.Println("用户目录:", dir)
if len(os.Args) > 1 {
zipFileName := os.Args[1]
fmt.Println("指定压缩文件目录:", zipFileName)
if strings.ToLower(path.Ext(zipFileName)) != ".zip" {
panic("输入正确的zip包,如:“liblcl-2.2.2.zip”")
}
zz, err := zip.OpenReader(zipFileName)
finfo, err := ioutil.ReadDir(liblclPath)
if err != nil {
panic(err)
}
for _, info := range finfo {
zipPath := filepath.Join(liblclPath, info.Name())
zz, err := zip.OpenReader(zipPath)
if err != nil {
panic(err)
}
defer zz.Close()
for _, ff := range zz.File {
//fmt.Println(ff.Name)
switch ff.Name {
case "win32/liblcl.dll":
genresByte(readZipData(ff), "windows", filepath.Join(libLCLBinResDir, "liblcl_windows_386.go"))
case "win64/liblcl.dll":
genresByte(readZipData(ff), "windows", filepath.Join(libLCLBinResDir, "liblcl_windows_amd64.go"))
case "macos64-cocoa/liblcl.dylib":
genresByte(readZipData(ff), "darwin", filepath.Join(libLCLBinResDir, "liblcl_darwin_amd64.go"))
case "linux64-gtk3/liblcl.so":
genresByte(readZipData(ff), "linux && gtk3", filepath.Join(libLCLBinResDir, "liblcl_gtk3_linux_amd64.go"))
case "linux64-gtk2/liblcl.so":
genresByte(readZipData(ff), "linux && gtk2", filepath.Join(libLCLBinResDir, "liblcl_gtk2_linux_amd64.go"))
}
var (
file fs.File
)
name := strings.ToLower(info.Name())
if strings.Contains(name, "windows") {
file, err = zz.Open("liblcl.dll")
} else if strings.Contains(name, "linux") {
file, err = zz.Open("liblcl.so")
} else if strings.Contains(name, "macos") {
file, err = zz.Open("liblcl.dylib")
}
if err != nil {
panic(err)
}
defer file.Close()
data, err := ioutil.ReadAll(file)
if err != nil {
panic(err)
}
} else {
// windows 32
genresFile(filepath.Join(liblclPath, "win32", "liblcl.dll"), "windows", filepath.Join(libLCLBinResDir, "liblcl_windows_386.go"))
// windows 64
genresFile(filepath.Join(liblclPath, "win64", "liblcl.dll"), "windows", filepath.Join(libLCLBinResDir, "liblcl_windows_amd64.go"))
// windows arm 64
//genresFile(filepath.Join(liblclPath, "winarm64", "liblcl.dll"), "windows", filepath.Join(libLCLBinResDir, "liblcl_windows_arm64.go"))
// macos cocoa
genresFile(filepath.Join(liblclPath, "macos64-cocoa", "liblcl.dylib"), "darwin", filepath.Join(libLCLBinResDir, "liblcl_darwin_amd64.go"))
// macos arm cocoa
//genresFile(filepath.Join(liblclPath, "macosarm64-cocoa", "liblcl.dylib"), "darwin", filepath.Join(libLCLBinResDir, "liblcl_darwin_arm64.go"))
// linux 64 gtk3
genresFile(filepath.Join(liblclPath, "linux64-gtk3", "liblcl.so"), "linux && gtk3", filepath.Join(libLCLBinResDir, "liblcl_gtk3_linux_amd64.go"))
// linux 64 gtk2
genresFile(filepath.Join(liblclPath, "linux64-gtk2", "liblcl.so"), "linux && gtk2", filepath.Join(libLCLBinResDir, "liblcl_gtk2_linux_amd64.go"))
// linux arm 64 gtk3
//genresFile(filepath.Join(liblclPath, "linuxarm64-gtk3", "liblcl.so"), "linux && gtk3", filepath.Join(libLCLBinResDir, "liblcl_gtk3_linux_arm64.go"))
// linux arm 64 gtk2
//genresFile(filepath.Join(liblclPath, "linuxarm64-gtk2", "liblcl.so"), "linux && gtk2", filepath.Join(libLCLBinResDir, "liblcl_gtk2_linux_arm64.go"))
}
}
// 生成字节的单元
func genresFile(fileName, tags, newFileName string) {
bs, err := ioutil.ReadFile(fileName)
if err == nil {
genresByte(bs, tags, newFileName)
} else {
fmt.Println("生成字节Go文件:", newFileName, "Error:", err)
if strings.Contains(name, "windows32.zip") {
genresByte(data, "windows", filepath.Join(libLCLBinResDir, "liblcl_windows_386.go"))
} else if strings.Contains(name, "windows64.zip") {
genresByte(data, "windows", filepath.Join(libLCLBinResDir, "liblcl_windows_amd64.go"))
} else if strings.Contains(name, "windowsarm64.zip") {
genresByte(data, "windows", filepath.Join(libLCLBinResDir, "liblcl_windows_arm64.go"))
} else if strings.Contains(name, "linux64.zip") {
genresByte(data, "linux && gtk3", filepath.Join(libLCLBinResDir, "liblcl_gtk3_linux_amd64.go"))
} else if strings.Contains(name, "linux64gtk2.zip") {
genresByte(data, "linux && gtk2", filepath.Join(libLCLBinResDir, "liblcl_gtk2_linux_amd64.go"))
} else if strings.Contains(name, "linuxarm64.zip") {
genresByte(data, "linux && gtk3", filepath.Join(libLCLBinResDir, "liblcl_gtk3_linux_arm64.go"))
} else if strings.Contains(name, "linuxarm64gtk2.zip") {
genresByte(data, "linux && gtk2", filepath.Join(libLCLBinResDir, "liblcl_gtk2_linux_arm64.go"))
} else if strings.Contains(name, "macosarm64.zip") {
genresByte(data, "darwin", filepath.Join(libLCLBinResDir, "liblcl_darwin_arm64.go"))
} else if strings.Contains(name, "macosx64.zip") {
genresByte(data, "darwin", filepath.Join(libLCLBinResDir, "liblcl_darwin_amd64.go"))
}
}
genresLiblclVersion(libLCLBinResDir, liblclVersion)
}
func fileExists(path string) bool {
......@@ -125,18 +124,6 @@ func fileExists(path string) bool {
return false
}
func readZipData(ff *zip.File) []byte {
if rr, err := ff.Open(); err == nil {
defer rr.Close()
bs, err := ioutil.ReadAll(rr)
if err != nil {
return nil
}
return bs
}
return nil
}
// zlib压缩
func zlibCompress(input []byte) ([]byte, error) {
var in bytes.Buffer
......@@ -161,9 +148,7 @@ func genresByte(input []byte, tags, newFileName string) {
fmt.Println("000000")
return
}
crc32Val := crc32.ChecksumIEEE(input)
//压缩
bs, err := zlibCompress(input)
if err != nil {
......@@ -184,3 +169,16 @@ func genresByte(input []byte, tags, newFileName string) {
code.WriteString("\")\r\n")
ioutil.WriteFile(newFileName, code.Bytes(), 0666)
}
func genresLiblclVersion(libLCLBinResDir, version string) {
code := bytes.NewBuffer(nil)
code.WriteString("package liblclbinres")
code.WriteString("\r\n\r\n")
code.WriteString(`const version = "` + version + `"`)
code.WriteString("\r\n\r\n")
code.WriteString("func LibVersion() string {")
code.WriteString("\n\t")
code.WriteString("return version")
code.WriteString("\n}")
ioutil.WriteFile(filepath.Join(libLCLBinResDir, "liblcl.go"), code.Bytes(), 0666)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册