Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
215fe347
energy
项目概览
energye
/
energy
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
energy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
215fe347
编写于
9月 08, 2023
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
energy command-line tools: install upx
上级
0cd874e5
变更
16
展开全部
隐藏空白更改
内联
并排
Showing
16 changed file
with
1090 addition
and
6 deletion
+1090
-6
cmd/internal/assets/assets.go
cmd/internal/assets/assets.go
+4
-0
cmd/internal/assets/assets_linux_amd64.go
cmd/internal/assets/assets_linux_amd64.go
+26
-0
cmd/internal/assets/assets_linux_arm64.go
cmd/internal/assets/assets_linux_arm64.go
+26
-0
cmd/internal/assets/assets_other.go
cmd/internal/assets/assets_other.go
+23
-0
cmd/internal/assets/assets_windows_386.go
cmd/internal/assets/assets_windows_386.go
+26
-0
cmd/internal/assets/assets_windows_amd64.go
cmd/internal/assets/assets_windows_amd64.go
+26
-0
cmd/internal/assets/upx/upx-4.1.0-doc.txt
cmd/internal/assets/upx/upx-4.1.0-doc.txt
+842
-0
cmd/internal/assets/upx/upx-linux-amd64
cmd/internal/assets/upx/upx-linux-amd64
+0
-0
cmd/internal/assets/upx/upx-linux-arm64
cmd/internal/assets/upx/upx-linux-arm64
+0
-0
cmd/internal/assets/upx/upx-windows-amd32.exe
cmd/internal/assets/upx/upx-windows-amd32.exe
+0
-0
cmd/internal/assets/upx/upx-windows-amd64.exe
cmd/internal/assets/upx/upx-windows-amd64.exe
+0
-0
cmd/internal/consts/consts.go
cmd/internal/consts/consts.go
+4
-0
cmd/internal/env/env_posix.go
cmd/internal/env/env_posix.go
+26
-0
cmd/internal/env/env_windows.go
cmd/internal/env/env_windows.go
+12
-0
cmd/internal/install/install.go
cmd/internal/install/install.go
+20
-3
cmd/internal/install/install_upx.go
cmd/internal/install/install_upx.go
+55
-3
未找到文件。
cmd/internal/assets/assets.go
浏览文件 @
215fe347
...
...
@@ -24,6 +24,10 @@ import (
//go:embed assets
var
assets
embed
.
FS
const
(
UpxVersion
=
"4.1.0"
)
// AssetsPath 返回配置资源目录
func
AssetsPath
(
projectData
*
project
.
Project
,
file
string
)
string
{
return
filepath
.
ToSlash
(
filepath
.
Join
(
projectData
.
AssetsDir
,
file
))
...
...
cmd/internal/assets/assets_linux_amd64.go
0 → 100644
浏览文件 @
215fe347
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
//go:build linux && amd64
// +build linux,amd64
package
assets
import
(
"embed"
"io/fs"
)
//go:embed upx/upx-linux-amd64
var
upx
embed
.
FS
func
UpxBytes
()
(
fs
.
File
,
error
)
{
return
upx
.
Open
(
"upx/upx-linux-amd64"
)
}
cmd/internal/assets/assets_linux_arm64.go
0 → 100644
浏览文件 @
215fe347
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
//go:build linux && arm64
// +build linux,arm64
package
assets
import
(
"embed"
"io/fs"
)
//go:embed upx/upx-linux-arm64
var
upx
embed
.
FS
func
UpxBytes
()
(
fs
.
File
,
error
)
{
return
upx
.
Open
(
"upx/upx-linux-arm64"
)
}
cmd/internal/assets/assets_other.go
0 → 100644
浏览文件 @
215fe347
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
//go:build darwin || (windows && arm64)
// +build darwin windows,arm64
package
assets
import
(
"errors"
"io/fs"
)
func
UpxBytes
()
(
fs
.
File
,
error
)
{
return
nil
,
errors
.
New
(
"not support"
)
}
cmd/internal/assets/assets_windows_386.go
0 → 100644
浏览文件 @
215fe347
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
//go:build windows && 386
// +build windows,386
package
assets
import
(
"embed"
"io/fs"
)
//go:embed upx/upx-windows-amd32.exe
var
upx
embed
.
FS
func
UpxBytes
()
(
fs
.
File
,
error
)
{
return
upx
.
Open
(
"upx/upx-windows-amd32.exe"
)
}
cmd/internal/assets/assets_windows_amd64.go
0 → 100644
浏览文件 @
215fe347
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
//go:build windows && amd64
// +build windows,amd64
package
assets
import
(
"embed"
"io/fs"
)
//go:embed upx/upx-windows-amd64.exe
var
upx
embed
.
FS
func
UpxBytes
()
(
fs
.
File
,
error
)
{
return
upx
.
Open
(
"upx/upx-windows-amd64.exe"
)
}
cmd/internal/assets/upx/upx-4.1.0-doc.txt
0 → 100644
浏览文件 @
215fe347
此差异已折叠。
点击以展开。
cmd/internal/assets/upx/upx-linux-amd64
0 → 100644
浏览文件 @
215fe347
文件已添加
cmd/internal/assets/upx/upx-linux-arm64
0 → 100644
浏览文件 @
215fe347
文件已添加
cmd/internal/assets/upx/upx-windows-amd32.exe
0 → 100644
浏览文件 @
215fe347
文件已添加
cmd/internal/assets/upx/upx-windows-amd64.exe
0 → 100644
浏览文件 @
215fe347
文件已添加
cmd/internal/consts/consts.go
浏览文件 @
215fe347
...
...
@@ -46,6 +46,10 @@ const (
NSISHomeKey
=
"NSIS_HOME"
)
const
(
UPXHomeKey
=
"UPX_HOME"
)
const
(
CefKey
=
"cef"
LiblclKey
=
"liblcl"
...
...
cmd/internal/env/env_posix.go
浏览文件 @
215fe347
...
...
@@ -27,6 +27,32 @@ import (
"strings"
)
func
SetUPXEnv
(
upxRoot
string
)
{
upx
:=
filepath
.
Join
(
upxRoot
,
"upx"
)
if
!
tools
.
IsExist
(
upx
)
{
println
(
"
\n
Error: Failed to set the UPX environment variable, not a correct UPX installation directory. "
,
upxRoot
)
return
}
println
(
"
\n
Setting UPX environment Variables to:"
,
upxRoot
)
cmd
:=
toolsCommand
.
NewCMD
()
cmd
.
IsPrint
=
false
cmd
.
MessageCallback
=
func
(
s
[]
byte
,
e
error
)
{
msg
:=
strings
.
TrimSpace
(
string
(
s
))
if
msg
!=
""
{
fmt
.
Println
(
"CMD:"
,
msg
)
}
if
e
!=
nil
{
fmt
.
Println
(
"CMD Error:"
,
e
)
}
}
defer
cmd
.
Close
()
var
exUpxRoot
=
fmt
.
Sprintf
(
"export UPX_HOME=%s"
,
upxRoot
)
var
exPath
=
"export PATH=$PATH:$UPX_HOME"
var
exs
=
[]
string
{
exUpxRoot
,
exPath
}
setPosixEnv
(
exs
,
exPath
,
"$UPX_HOME"
)
println
(
"Hint: Reopen the cmd window for the upx command to take effect."
)
}
func
SetNSISEnv
(
nsisRoot
string
)
{
}
...
...
cmd/internal/env/env_windows.go
浏览文件 @
215fe347
...
...
@@ -22,6 +22,18 @@ import (
"strings"
)
func
SetUPXEnv
(
upxRoot
string
)
{
upx
:=
filepath
.
Join
(
upxRoot
,
"upx.exe"
)
if
!
tools
.
IsExist
(
upx
)
{
println
(
"
\n
Error: Failed to set the UPX environment variable, not a correct UPX installation directory. "
,
upxRoot
)
return
}
println
(
"
\n
Setting UPX environment Variables to:"
,
upxRoot
)
setWindowsEnv
(
consts
.
UPXHomeKey
,
upxRoot
)
appendWindowsEnv
(
"Path"
,
"%UPX_HOME%"
)
println
(
"Hint: Reopen the cmd window for the upx command to take effect."
)
}
func
SetNSISEnv
(
nsisRoot
string
)
{
makensis
:=
filepath
.
Join
(
nsisRoot
,
"makensis.exe"
)
if
!
tools
.
IsExist
(
makensis
)
{
...
...
cmd/internal/install/install.go
浏览文件 @
215fe347
...
...
@@ -53,6 +53,8 @@ func Install(c *command.Config) {
cefFrameworkSuccessCallback
func
()
nsisRoot
string
nsisSuccessCallback
func
()
upxRoot
string
upxSuccessCallback
func
()
)
if
len
(
willInstall
)
>
0
{
println
(
"Following will be installed"
)
...
...
@@ -75,6 +77,12 @@ func Install(c *command.Config) {
if
nsisRoot
!=
""
{
env
.
SetNSISEnv
(
nsisRoot
)
}
// 安装upx, 内置, 仅windows, linux
upxRoot
,
upxSuccessCallback
=
installUPX
(
c
)
// 设置upx环境变量
if
upxRoot
!=
""
{
env
.
SetUPXEnv
(
upxRoot
)
}
// 安装CEF二进制框架
cefFrameworkRoot
,
cefFrameworkSuccessCallback
=
installCEFFramework
(
c
)
// 设置 energy cef 环境变量
...
...
@@ -82,7 +90,7 @@ func Install(c *command.Config) {
env
.
SetEnergyHomeEnv
(
cefFrameworkRoot
)
}
// success 输出
if
nsisSuccessCallback
!=
nil
||
goSuccessCallback
!=
nil
||
cefFrameworkSuccessCallback
!=
nil
{
if
nsisSuccessCallback
!=
nil
||
goSuccessCallback
!=
nil
||
upxSuccessCallback
!=
nil
||
cefFrameworkSuccessCallback
!=
nil
{
println
(
"-----------------------------------------------------
\n
-----------------------------------------------------"
)
println
(
"Hint: Reopen the cmd window for command to take effect."
)
println
(
"-----------------------------------------------------
\n
-----------------------------------------------------"
)
...
...
@@ -93,6 +101,9 @@ func Install(c *command.Config) {
if
goSuccessCallback
!=
nil
{
goSuccessCallback
()
}
if
upxSuccessCallback
!=
nil
{
upxSuccessCallback
()
}
if
cefFrameworkSuccessCallback
!=
nil
{
cefFrameworkSuccessCallback
()
}
...
...
@@ -130,9 +141,15 @@ func nsisIsInstall() bool {
}
func
upxIsInstall
()
bool
{
return
consts
.
IsWindows
return
(
consts
.
IsWindows
&&
runtime
.
GOARCH
!=
"arm64"
)
||
(
consts
.
IsLinux
)
}
// 检查当前环境
// golang, nsis, cef, upx
// golang: all os
// nsis: windows
// cef: all os
// upx: windows amd64, 386, linux amd64, arm64
func
checkInstallEnv
(
c
*
command
.
Config
)
(
result
[]
string
)
{
skip
:=
c
.
Install
.
All
var
check
=
func
(
chkInstall
func
()
bool
,
name
string
,
yes
func
())
{
...
...
@@ -354,6 +371,7 @@ func ExtractUnZip(filePath, targetPath string, rmRootDir bool, files ...any) err
os
.
MkdirAll
(
fDir
,
0755
)
}
if
targetFile
,
err
:=
os
.
Create
(
targetFileName
);
err
==
nil
{
defer
targetFile
.
Close
()
fmt
.
Println
(
"extract file: "
,
path
)
bar
.
SetCurrentValue
(
0
)
writeFile
(
file
,
targetFile
,
info
.
Size
(),
func
(
totalLength
,
processLength
int64
)
{
...
...
@@ -361,7 +379,6 @@ func ExtractUnZip(filePath, targetPath string, rmRootDir bool, files ...any) err
})
bar
.
PrintBar
(
100
)
bar
.
PrintEnd
()
targetFile
.
Close
()
return
nil
}
else
{
println
(
"createWriteFile"
,
err
.
Error
())
...
...
cmd/internal/install/install_upx.go
浏览文件 @
215fe347
...
...
@@ -10,8 +10,60 @@
package
install
import
"github.com/energye/energy/v2/cmd/internal/command"
import
(
"fmt"
"github.com/energye/energy/v2/cmd/internal/assets"
"github.com/energye/energy/v2/cmd/internal/command"
"github.com/energye/energy/v2/cmd/internal/consts"
progressbar
"github.com/energye/energy/v2/cmd/internal/progress-bar"
"github.com/energye/energy/v2/cmd/internal/tools"
"os"
"path/filepath"
"runtime"
)
func
installUPX
(
c
*
command
.
Config
)
string
{
return
""
func
installUPX
(
c
*
command
.
Config
)
(
string
,
func
())
{
if
!
c
.
Install
.
IUPX
{
return
""
,
nil
}
if
(
consts
.
IsWindows
&&
runtime
.
GOARCH
!=
"arm64"
)
||
(
consts
.
IsLinux
)
{
s
:=
upxInstallPathName
(
c
)
// 安装目录
if
!
tools
.
IsExist
(
s
)
{
os
.
MkdirAll
(
s
,
0755
)
}
var
upxName
=
"upx"
if
consts
.
IsWindows
{
upxName
+=
".exe"
}
targetFileName
:=
filepath
.
Join
(
s
,
upxName
)
// 保存安装目录
if
targetFile
,
err
:=
os
.
Create
(
targetFileName
);
err
==
nil
{
defer
targetFile
.
Close
()
fmt
.
Println
(
"extract file: "
,
upxName
)
bar
:=
progressbar
.
NewBar
(
100
)
bar
.
SetNotice
(
"
\t
"
)
bar
.
HideRatio
()
fs
,
err
:=
assets
.
UpxBytes
()
if
err
!=
nil
{
println
(
"UPX Installed Error:"
,
err
.
Error
())
return
""
,
nil
}
stat
,
err
:=
fs
.
Stat
()
if
err
!=
nil
{
println
(
"UPX Installed Error:"
,
err
.
Error
())
return
""
,
nil
}
writeFile
(
fs
,
targetFile
,
stat
.
Size
(),
func
(
totalLength
,
processLength
int64
)
{
bar
.
PrintBar
(
int
((
float64
(
processLength
)
/
float64
(
totalLength
))
*
100
))
})
bar
.
PrintBar
(
100
)
bar
.
PrintEnd
()
return
s
,
func
()
{
println
(
"UPX Installed Successfully Version:"
,
assets
.
UpxVersion
)
}
}
else
{
println
(
"createWriteFile"
,
err
.
Error
())
return
""
,
nil
}
}
return
""
,
nil
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录