diff --git a/energy/emfs/emfs.go b/energy/emfs/emfs.go index d788671..7686380 100644 --- a/energy/emfs/emfs.go +++ b/energy/emfs/emfs.go @@ -1,49 +1,34 @@ package emfs import ( - "embed" "io/ioutil" - "os" ) var ( - resourcesFS *embed.FS - libsFS *embed.FS + resourcesFS IEmbedFS + libsFS IEmbedFS ) -func SetLibsFS(lib *embed.FS) { +type IEmbedFS interface { + ReadFile(name string) ([]byte, error) +} + +func SetLibsFS(lib IEmbedFS) { libsFS = lib } -func SetResourcesFS(resource *embed.FS) { +func SetResourcesFS(resource IEmbedFS) { resourcesFS = resource } -func GetLibsFS() *embed.FS { +func GetLibsFS() IEmbedFS { return libsFS } -func GetResourcesFS() *embed.FS { +func GetResourcesFS() IEmbedFS { return resourcesFS } -func IsExist(file string) bool { - if GetResourcesFS() == nil { - return false - } - if fs, err := GetResourcesFS().Open(file); err != nil { - return false - } else { - _, err := fs.Stat() - if os.IsExist(err) { - return true - } else if os.IsNotExist(err) { - return false - } - return true - } -} - func GetResources(file string) ([]byte, error) { if GetResourcesFS() != nil { return GetResourcesFS().ReadFile(file) @@ -60,7 +45,7 @@ func GetLibs(fileName string) ([]byte, error) { } } -func SetEMFS(libs *embed.FS, resources *embed.FS) { +func SetEMFS(libs IEmbedFS, resources IEmbedFS) { SetLibsFS(libs) SetResourcesFS(resources) } diff --git a/energy/inits/inits.go b/energy/inits/inits.go index 27df295..bd5db31 100644 --- a/energy/inits/inits.go +++ b/energy/inits/inits.go @@ -13,7 +13,6 @@ package inits import ( - "embed" "fmt" "github.com/energye/golcl/energy/consts" "github.com/energye/golcl/energy/emfs" @@ -26,7 +25,6 @@ import ( "github.com/energye/golcl/lcl/rtl/version" "github.com/energye/golcl/pkgs/libname" "github.com/energye/golcl/pkgs/macapp" - "io" "os" "path" "runtime" @@ -37,7 +35,7 @@ var ( emfsLibsPath = "libs" ) -func Init(libs *embed.FS, resources *embed.FS) { +func Init(libs emfs.IEmbedFS, resources emfs.IEmbedFS) { emfs.SetEMFS(libs, resources) if libname.LibName == "" { if runtime.GOOS == "darwin" { @@ -74,7 +72,7 @@ func Init(libs *embed.FS, resources *embed.FS) { // 如果liblcl动态库内置到EXE中, 在EXE中把liblcl释放到out目录 func releaseLib(fsPath, out string) { if emfs.GetLibsFS() != nil { - var fsFile, err = emfs.GetLibsFS().Open(fsPath) + var liblcl, err = emfs.GetLibsFS().ReadFile(fsPath) if err == nil { var file *os.File file, err = os.OpenFile(out, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) @@ -82,17 +80,7 @@ func releaseLib(fsPath, out string) { panic(err) } defer file.Close() - defer fsFile.Close() - var n int - //读取数据 - buf := make([]byte, 4096) - for { - n, err = fsFile.Read(buf) - if err == io.EOF { - break - } - file.Write(buf[:n]) - } + file.Write(liblcl) fmt.Println("release success.") } } diff --git a/go.mod b/go.mod index c4109f7..ff3e04c 100644 --- a/go.mod +++ b/go.mod @@ -1,22 +1,3 @@ module github.com/energye/golcl -go 1.18 - -require ( - github.com/Knetic/govaluate v3.0.0+incompatible - github.com/disintegration/gift v1.2.1 - github.com/energye/dylib v0.0.0-20230814115552-32dda0972e9e - github.com/fogleman/gg v1.3.0 - github.com/go-ole/go-ole v1.2.6 - github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 - github.com/gomodule/redigo v2.0.0+incompatible - github.com/tryor/gdiplus v0.0.0-20200830101413-c570de9579b3 - github.com/tryor/winapi v0.0.0-20200525040926-cd87d62e2f9b - github.com/vdobler/chart v1.0.0 - golang.org/x/image v0.5.0 -) - -require ( - github.com/llgcode/draw2d v0.0.0-20180825133448-f52c8a71aff0 // indirect - golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect -) +go 1.10 diff --git a/go.sum b/go.sum deleted file mode 100644 index 6d0a6e1..0000000 --- a/go.sum +++ /dev/null @@ -1,58 +0,0 @@ -github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg= -github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/ajstarks/svgo v0.0.0-20181006003313-6ce6a3bcf6cd/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= -github.com/disintegration/gift v1.2.1 h1:Y005a1X4Z7Uc+0gLpSAsKhWi4qLtsdEcMIbbdvdZ6pc= -github.com/disintegration/gift v1.2.1/go.mod h1:Jh2i7f7Q2BM7Ezno3PhfezbR1xpUg9dUg3/RlKGr4HI= -github.com/energye/dylib v0.0.0-20230814115552-32dda0972e9e h1:vtsQv7Lf1cujnfldYiViosSmQxWdyIUG9fJ5FHGMYXk= -github.com/energye/dylib v0.0.0-20230814115552-32dda0972e9e/go.mod h1:N8GS4d3Ix83Cff6mLHb+09iiPg9huBB4XETDfuMN5LM= -github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8= -github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= -github.com/go-gl/gl v0.0.0-20180407155706-68e253793080/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk= -github.com/go-gl/glfw v0.0.0-20180426074136-46a8d530c326/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= -github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= -github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= -github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= -github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= -github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0= -github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= -github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= -github.com/llgcode/draw2d v0.0.0-20180825133448-f52c8a71aff0 h1:2vp6ESimuT8pCuZHThVyV0hlfa9oPL06HnGCL9pbUgc= -github.com/llgcode/draw2d v0.0.0-20180825133448-f52c8a71aff0/go.mod h1:mVa0dA29Db2S4LVqDYLlsePDzRJLDfdhVZiI15uY0FA= -github.com/llgcode/ps v0.0.0-20150911083025-f1443b32eedb h1:61ndUreYSlWFeCY44JxDDkngVoI7/1MVhEl98Nm0KOk= -github.com/llgcode/ps v0.0.0-20150911083025-f1443b32eedb/go.mod h1:1l8ky+Ew27CMX29uG+a2hNOKpeNYEQjjtiALiBlFQbY= -github.com/tryor/gdiplus v0.0.0-20200830101413-c570de9579b3 h1:uNa9sFwF8kySVpKAQdEUlLOnTrT/cACkQajQ9eyH+mA= -github.com/tryor/gdiplus v0.0.0-20200830101413-c570de9579b3/go.mod h1:TrDGUugAfbUWjSKyYBuUWpjK/A7pwedAB8x+cZWobzs= -github.com/tryor/winapi v0.0.0-20200525040926-cd87d62e2f9b h1:1AGoyclL+cx3LKzptgjHsRpG8ltCOaj36qUrIHRJEec= -github.com/tryor/winapi v0.0.0-20200525040926-cd87d62e2f9b/go.mod h1:NUZCLXgdFgm/L5ovQjuZxttpvHVGcRL+9lZ8N/KeBls= -github.com/vdobler/chart v1.0.0 h1:ySWmgHJtBsb7/SItvKb+VM3Nxb0SksDIjZhSbiK+Wi0= -github.com/vdobler/chart v1.0.0/go.mod h1:gRwLtqIJLDw1CkK9kxJXv3X9OaMfM4dYsbZtWtVLxvM= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= -golang.org/x/image v0.0.0-20181030002151-69cc3646b96e/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= -golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI= -golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/samples/action/main.go b/samples/action/main.go index 90e630d..e75221e 100644 --- a/samples/action/main.go +++ b/samples/action/main.go @@ -1,16 +1,12 @@ package main import ( - "embed" "github.com/energye/golcl/energy/inits" "github.com/energye/golcl/lcl" "github.com/energye/golcl/samples/action/src" ) import _ "github.com/energye/golcl/pkgs/winappres" -//go:embed resources -var resources embed.FS - func main() { inits.Init(nil, nil) lcl.Application.Initialize()