Skip to content

Commit

Permalink
修复脚本错误bug,解决版本判断错误,更新中禁用更新按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
Purple-CSGO committed Jan 25, 2021
1 parent 17e3199 commit 62150e1
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 47 deletions.
50 changes: 33 additions & 17 deletions backend/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ func (a *App) WailsInit(runtime *wails.Runtime) error {
return err
}

//设置前端
a.setAppVersion(a.cfg.AppVersion)
a.setVersionCode(a.cfg.VersionCode)

return nil
}
Expand All @@ -51,6 +48,12 @@ func (a *App) WailsShutdown() {
}
}

//设置前端变量
func (a *App) SetVar() {
a.setAppVersion(a.cfg.AppVersion)
a.setVersionCode(a.cfg.VersionCode)
}

//检查更新
func (a *App) CheckUpdate() {
var err error
Expand Down Expand Up @@ -180,6 +183,18 @@ func (a *App) installHLAE() error {
//识别已安装hlae,则检查更新
if ok, _ := tool.IsFileExisted(path + "/hlae.exe"); ok {
a.cfg.HlaePath = tool.FormatPath(path)
//解析修正本地hlae版本号
changelog, err := tool.ReadAll(a.cfg.HlaePath + "/changelog.xml")
if err != nil {
a.noticeError("读取本地版本号失败: " + err.Error())
return err
}
if tVersion, err := api.ParseChangelog(changelog); err != nil {
a.noticeError("解析本地版本号失败: " + err.Error())
return err
} else {
a.cfg.HlaeVersion = tVersion
}
if err := a.updateHLAE(); err != nil {
return err
}
Expand Down Expand Up @@ -258,7 +273,7 @@ func (a *App) installHLAE() error {
var jsonx = jsoniter.ConfigCompatibleWithStandardLibrary //使用高性能json-iterator/go库
err := jsonx.Unmarshal([]byte(cdnData), &cdnInst) //第二个参数要地址传递
if err != nil {
return err //TODO
return err
}
//获取版本号、下载地址和文件名
cdnVersion = cdnInst.Version
Expand All @@ -269,13 +284,14 @@ func (a *App) installHLAE() error {
//决定下载的文件
if srcVersion == "" && cdnVersion == "" {
return errors.New("hlae官方和CDN的API均获取或解析失败")
} else if srcVersion == "" {
a.noticeWarning("hlae官方API解析失败,CDN源可能不是最新版本")
} else if cdnVersion == "" {
a.noticeWarning("CDN源解析失败,下载速度可能较慢")
} else if srcVersion == "" {
a.noticeWarning("hlae官方API解析失败,CDN源可能不是最新版本")
}
if srcVersion != "" && srcVersion == cdnVersion {
//hlae版本非空且和CDN源版本一致,则下载CDN源

if srcVersion == "" || (srcVersion != "" && srcVersion == cdnVersion) {
//官方版本非空且和CDN源版本一致,则下载CDN源
version = cdnVersion
url = cdnURL
filename = cdnFilename
Expand Down Expand Up @@ -360,7 +376,7 @@ func (a *App) installFFmpeg() error {
var jsonx = jsoniter.ConfigCompatibleWithStandardLibrary //使用高性能json-iterator/go库
err := jsonx.Unmarshal([]byte(cdnData), &cdnInst) //第二个参数要地址传递
if err != nil {
return err //TODO
return err
}
//获取版本号、下载地址和文件名
cdnVersion = cdnInst.Version
Expand All @@ -376,8 +392,8 @@ func (a *App) installFFmpeg() error {
} else if cdnVersion == "" {
a.noticeWarning("CDN源解析失败,下载速度可能较慢")
}
if srcVersion != "" && srcVersion == cdnVersion {
//FFmpeg版本非空且和CDN源版本一致,则下载CDN源
if srcVersion == "" || (srcVersion != "" && srcVersion == cdnVersion) {
//官方版本非空且和CDN源版本一致,则下载CDN源
version = cdnVersion
url = cdnURL
filename = cdnFilename
Expand Down Expand Up @@ -482,7 +498,7 @@ func (a *App) updateHLAE() error {
var jsonx = jsoniter.ConfigCompatibleWithStandardLibrary //使用高性能json-iterator/go库
err := jsonx.Unmarshal([]byte(cdnData), &cdnInst) //第二个参数要地址传递
if err != nil {
return err //TODO
return err
}
//获取版本号、下载地址和文件名
cdnVersion = cdnInst.Version
Expand All @@ -498,8 +514,8 @@ func (a *App) updateHLAE() error {
} else if cdnVersion == "" {
a.noticeWarning("CDN源解析失败,下载速度可能较慢")
}
if srcVersion != "" && srcVersion == cdnVersion {
//hlae版本非空且和CDN源版本一致,则下载CDN源
if srcVersion == "" || (srcVersion != "" && srcVersion == cdnVersion) {
//官方版本非空且和CDN源版本一致,则下载CDN源
version = cdnVersion
url = cdnURL
filename = cdnFilename
Expand Down Expand Up @@ -589,7 +605,7 @@ func (a *App) updateFFmpeg() error {
var jsonx = jsoniter.ConfigCompatibleWithStandardLibrary //使用高性能json-iterator/go库
err := jsonx.Unmarshal([]byte(cdnData), &cdnInst) //第二个参数要地址传递
if err != nil {
return err //TODO
return err
}
//获取版本号、下载地址和文件名
cdnVersion = cdnInst.Version
Expand All @@ -605,8 +621,8 @@ func (a *App) updateFFmpeg() error {
} else if cdnVersion == "" {
a.noticeWarning("CDN源解析失败,下载速度可能较慢")
}
if srcVersion != "" && srcVersion == cdnVersion {
//FFmpeg版本非空且和CDN源版本一致,则下载CDN源
if srcVersion == "" || (srcVersion != "" && srcVersion == cdnVersion) {
//官方版本非空且和CDN源版本一致,则下载CDN源
version = cdnVersion
url = cdnURL
filename = cdnFilename
Expand Down
2 changes: 1 addition & 1 deletion backend/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package config

var defaultCFG = CFG{
VersionCode: "Testify",
AppVersion: "v0.0.4",
AppVersion: "v1.0.1",
HlaeVersion: "",
FFmpegVersion: "",
HlaeAPI: "https://api.github.com/repos/advancedfx/advancedfx/releases/latest",
Expand Down
17 changes: 12 additions & 5 deletions backend/wails.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,47 @@ func (a *App) SayHello() string {
return "Hello to Frontend!"
}

//设置进度条 需要前端Mount
//设置进度条
func (a *App) setProgress(percent int) {
a.runtime.Events.Emit("SetProgess", percent)
}

//设置日志信息
func (a *App) setLog(log string) {
a.runtime.Events.Emit("SetLog", log)
}

//设置版本代号
func (a *App) setVersionCode(versionCode string) {
a.runtime.Events.Emit("SetVersionCode", versionCode)
}

//设置App版本
func (a *App) setAppVersion(appVersion string) {
a.runtime.Events.Emit("SetAppVersion", appVersion)
}

func (a *App) setStandalone(standalone string) {
a.runtime.Events.Emit("SetStandalone", standalone)
}

//选择hlae安装方式
func (a *App) doSelectOption() {
a.runtime.Events.Emit("DoSelectOption")
}

//通知成功
func (a *App) noticeSuccess(msg string) {
a.runtime.Events.Emit("NoticeSuccess", msg)
}

//通知错误
func (a *App) noticeError(msg string) {
a.runtime.Events.Emit("NoticeError", msg)
}

//通知警告
func (a *App) noticeWarning(msg string) {
a.runtime.Events.Emit("NoticeWarning", msg)
}

//选择文件夹
func (a *App) SelectDirectory() string {
directory := a.runtime.Dialog.SelectDirectory()
if ok, err := tool.IsFileExisted(directory); err != nil || !ok {
Expand All @@ -63,6 +67,7 @@ func (a *App) SelectDirectory() string {
return directory
}

//选择文件
func (a *App) SelectFile() string {
path := a.runtime.Dialog.SelectFile()
if ok, err := tool.IsFileExisted(path); err != nil || !ok {
Expand All @@ -73,6 +78,7 @@ func (a *App) SelectFile() string {
return path
}

//选择文件,有标题
func (a *App) SelectFileTitle(Title string) string {
path := a.runtime.Dialog.SelectFile(Title)
if ok, err := tool.IsFileExisted(path); err != nil || !ok {
Expand All @@ -83,6 +89,7 @@ func (a *App) SelectFileTitle(Title string) string {
return path
}

//选择文件,有标题和过滤文件
func (a *App) SelectFileTitleFilter(Title string, Filter string) string {
path := a.runtime.Dialog.SelectFile(Title, Filter)
if ok, err := tool.IsFileExisted(path); err != nil || !ok {
Expand Down
15 changes: 15 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"VersionCode": "Testify",
"AppVersion": "v1.0.1",
"HlaeVersion": "v2.109.7",
"FFmpegVersion": "4.3.1-2021-01-01",
"HlaeAPI": "https://api.github.com/repos/advancedfx/advancedfx/releases/latest",
"HlaeCdnAPI": "https://cdn.jsdelivr.net/gh/One-Studio/HLAE-Archive@master/api.json",
"FFmpegAPI": "https://www.gyan.dev/ffmpeg/builds",
"FFmpegCdnAPI": "https://cdn.jsdelivr.net/gh/One-Studio/FFmpeg-Win64@master/api.json",
"HlaePath": "C:/Users/Purp1e/AppData/Local/AkiVer/hlae",
"Init": true,
"Standalone": false,
"HlaeState": true,
"FFmpegState": true
}
2 changes: 1 addition & 1 deletion frontend/package.json.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
03afdf9640466e356163d0a142747130
4437c0505ecf58a57eea92c048cf9cc2
51 changes: 28 additions & 23 deletions frontend/src/components/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
{{ log }}
</div>
<div class="btn-control">
<a-button class="btn" size="large" @click="tabSetting" :loading="btnSetting">
<a-button class="btn" size="large" @click="manualUpdate" :disabled="btnUpdate">
<!-- <a-icon type="setting" />-->
<a-icon type="reload" />
</a-button>
<a-button class="btn" size="large" @click="openDirHLAE"><a-icon type="folder-open" :loading="btnOpenDir" /></a-button>
<a-button class="btn" @click="launchHLAE" style="margin-right: 0;width: 36vw;font-size: 4.5vw;" size="large" :loading="btnLaunchHLAE" >打开HLAE</a-button>
<a-button class="btn" size="large" @click="openDirHLAE" >
<a-icon type="folder-open" />
</a-button>
<a-button class="btn" @click="launchHLAE" style="margin-right: 0;width: 36vw;font-size: 4.5vw;" size="large" >
打开HLAE <!-- :disabled="btnLaunchHLAE" -->
</a-button>
</div>
</div>
</template>
Expand All @@ -42,12 +46,12 @@ export default {
name: "Main",
data() {
return {
versionCode: "Testify",
appVersion: "v1.0.0",
versionCode: "Version",
appVersion: "v0.0.1",
progress: 0,
log: "",
standalone: true,
btnSetting: false,
btnUpdate: false,
btnOpenDir: false,
btnLaunchHLAE: false,
};
Expand All @@ -73,6 +77,8 @@ export default {
this.selectOption();
});
Wails.Events.On("NoticeSuccess", (msg) => {
// console.log(msg);
// let mes = msg;
this.$message.success(msg, 5);
});
Wails.Events.On("NoticeError", (msg) => {
Expand All @@ -81,29 +87,29 @@ export default {
Wails.Events.On("NoticeWarning", (msg) => {
this.$message.warning(msg, 5);
});
//通知传参
window.backend.App.SetVar();
//检查更新
this.checkUpdate();
},
methods: {
launchHLAE () {
// console.log("启动HLAE");
this.btnLaunchHLAE = true;
window.backend.App.LaunchHLAE().then(ok => {
if (ok === false) {
this.$message.warning('HLAE启动失败', 5);
}
this.btnLaunchHLAE = false;
});
this.btnLaunchHLAE = false;
},
tabSetting () {
console.log("切换到设置Tab页"); //TODO
//用于debug
this.checkUpdate()
manualUpdate () {
this.checkUpdate();
},
openDirHLAE () {
// console.log("打开HLAE安装位置");
this.btnOpenDir = true;
window.backend.App.OpenHlaeDirectory();
this.btnOpenDir = false;
window.backend.App.OpenHlaeDirectory().then( () => {
this.btnOpenDir = false;
});
//发送wails信息->Go?
// window.wails.Events.Emit("error", "这是一条错误信息!");
},
Expand All @@ -114,11 +120,10 @@ export default {
selectOption() {
//选择HLAE安装方法和安装位置
this.$confirm({
title: '选择HLAE和FFmpeg的安装方式',
content: '附属安装:关联CSGO Demos Manager\n单独安装:单独选择位置安装',
okText: '附属安装',
title: () => <div style="font-size: 4.5vw;">选择HLAE的安装方式</div>,
content: () => <div style="font-size: 3.75vw;">· 关联CSGO Demos Manager安装<br></br>· 单独选择位置安装</div>,
okText: '关联安装',
cancelText: '单独安装',
// bodyStyle: 'font-size: 20vw',
onOk() {
//选择完成,传给后端
window.backend.App.SetOption(false);
Expand All @@ -135,10 +140,10 @@ export default {
},
checkUpdate () {
// console.log("检查HLAE更新");
this.btnOpenDir = true; //TODO 修改成update相关名称
window.backend.App.CheckUpdate();
this.btnOpenDir = false;
this.btnUpdate = true;
window.backend.App.CheckUpdate().then( () => {
this.btnUpdate = false;
});
}
}
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as Wails from '@wailsapp/runtime';

Vue.use(Antd);


Wails.Init(() => {
new Vue({
render: h => h(App)
Expand Down

0 comments on commit 62150e1

Please sign in to comment.