refactor: updater was reworked and moved to https://github.com/throneproj/updater

This commit is contained in:
parhelia512 2025-10-04 19:01:02 +08:00
parent cbbb83a878
commit 0b691cf56f
9 changed files with 15 additions and 278 deletions

View File

@ -57,7 +57,6 @@ jobs:
go-version: ${{ matrix.go_version }}
cache-dependency-path: |
core/server/go.sum
core/updater/go.sum
- name: Install Golang For Legacy Windows
if: matrix.cross_os == 'windowslegacy'
run: |

View File

@ -1,2 +0,0 @@
/updater
/launcher

View File

@ -1,14 +0,0 @@
module updater
go 1.22
toolchain go1.24.4
require github.com/codeclysm/extract/v4 v4.0.0
require (
github.com/h2non/filetype v1.1.3 // indirect
github.com/juju/errors v0.0.0-20220331221717-b38fca44723b // indirect
github.com/klauspost/compress v1.15.13 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
)

View File

@ -1,28 +0,0 @@
github.com/arduino/go-paths-helper v1.12.1 h1:WkxiVUxBjKWlLMiMuYy8DcmVrkxdP7aKxQOAq7r2lVM=
github.com/arduino/go-paths-helper v1.12.1/go.mod h1:jcpW4wr0u69GlXhTYydsdsqAjLaYK5n7oWHfKqOG6LM=
github.com/codeclysm/extract/v4 v4.0.0 h1:H87LFsUNaJTu2e/8p/oiuiUsOK/TaPQ5wxsjPnwPEIY=
github.com/codeclysm/extract/v4 v4.0.0/go.mod h1:SFju1lj6as7FvUgalpSct7torJE0zttbJUWtryPRG6s=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
github.com/juju/errors v0.0.0-20220331221717-b38fca44723b h1:AxFeSQJfcm2O3ov1wqAkTKYFsnMw2g1B4PkYujfAdkY=
github.com/juju/errors v0.0.0-20220331221717-b38fca44723b/go.mod h1:jMGj9DWF/qbo91ODcfJq6z/RYc3FX3taCBZMCcpI4Ls=
github.com/klauspost/compress v1.15.13 h1:NFn1Wr8cfnenSJSA46lLq4wHCcBzKTSjnBIexDMMOV0=
github.com/klauspost/compress v1.15.13/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -1,67 +0,0 @@
package main
import (
"io"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"
)
func main() {
// update & launcher
exe, err := os.Executable()
if err != nil {
panic(err.Error())
}
wd := filepath.Dir(exe)
os.Chdir(wd)
exe = filepath.Base(os.Args[0])
log.Println("exe:", exe, "exe dir:", wd)
if strings.HasPrefix(strings.ToLower(exe), "updater") {
if runtime.GOOS == "windows" {
if strings.HasPrefix(strings.ToLower(exe), "updater.old") {
// 2. "updater.old" update files
time.Sleep(time.Second)
Updater()
// 3. start
exec.Command("./Throne.exe").Start()
} else {
// 1. Throne stop itself and run "updater.exe"
Copy("./updater.exe", "./updater.old")
exec.Command("./updater.old", os.Args[1:]...).Start()
}
} else {
// 1. update files
Updater()
// 2. start
exec.Command("./Throne").Start()
}
return
}
log.Fatalf("wrong name")
}
func Copy(src string, dst string) {
srcFile, err := os.Open(src)
if err != nil {
log.Println(err)
return
}
defer srcFile.Close()
dstFile, err := os.OpenFile(dst, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644)
if err != nil {
log.Println(err)
return
}
defer dstFile.Close()
_, err = io.Copy(dstFile, srcFile)
if err != nil {
log.Println(err)
}
}

View File

@ -1,7 +0,0 @@
//go:build !windows
package main
func MessageBoxPlain(title, caption string) int {
return 0
}

View File

@ -1,26 +0,0 @@
package main
import (
"syscall"
"unsafe"
)
// MessageBoxPlain of Win32 API.
func MessageBoxPlain(title, caption string) int {
const (
NULL = 0
MB_OK = 0
)
return MessageBox(NULL, caption, title, MB_OK)
}
// MessageBox of Win32 API.
func MessageBox(hwnd uintptr, caption, title string, flags uint) int {
ret, _, _ := syscall.NewLazyDLL("user32.dll").NewProc("MessageBoxW").Call(
uintptr(hwnd),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(caption))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))),
uintptr(flags))
return int(ret)
}

View File

@ -1,128 +0,0 @@
package main
import (
"context"
"log"
"os"
"path/filepath"
"runtime"
"strings"
"github.com/codeclysm/extract/v4"
)
func Updater() {
pre_cleanup := func() {
if runtime.GOOS == "linux" {
os.RemoveAll("./usr")
}
os.RemoveAll("./Throne_update")
}
// find update package
var updatePackagePath string
if len(os.Args) == 2 && Exist(os.Args[1]) {
updatePackagePath = os.Args[1]
} else if Exist("./Throne.zip") {
updatePackagePath = "./Throne.zip"
} else if Exist("./Throne.tar.gz") {
updatePackagePath = "./Throne.tar.gz"
} else {
log.Fatalln("no update")
}
log.Println("updating from", updatePackagePath)
dir, err := os.Getwd()
if err != nil {
log.Fatalln(err)
}
// extract update package
if strings.HasSuffix(updatePackagePath, ".zip") {
pre_cleanup()
f, err := os.Open(updatePackagePath)
if err != nil {
log.Fatalln(err.Error())
}
err = extract.Zip(context.Background(), f, dir+string(os.PathSeparator)+"Throne_update", nil)
if err != nil {
log.Fatalln(err.Error())
}
f.Close()
} else if strings.HasSuffix(updatePackagePath, ".tar.gz") {
pre_cleanup()
f, err := os.Open(updatePackagePath)
if err != nil {
log.Fatalln(err.Error())
}
err = extract.Gz(context.Background(), f, dir+string(os.PathSeparator)+"Throne_update", nil)
if err != nil {
log.Fatalln(err.Error())
}
f.Close()
}
// remove old file
removeAll("./*.dll")
removeAll("./*.dmp")
// update move
err = Mv("./Throne_update/Throne", "./")
if err != nil {
MessageBoxPlain("Throne Updater", "Update failed. Please close the running instance and run the updater again.\n\n"+err.Error())
log.Fatalln(err.Error())
}
os.RemoveAll("./Throne_update")
os.RemoveAll("./Throne.zip")
os.RemoveAll("./Throne.tar.gz")
}
func Exist(path string) bool {
_, err := os.Stat(path)
return err == nil
}
func FindExist(paths []string) string {
for _, path := range paths {
if Exist(path) {
return path
}
}
return ""
}
func Mv(src, dst string) error {
s, err := os.Stat(src)
if err != nil {
return err
}
if s.IsDir() {
es, err := os.ReadDir(src)
if err != nil {
return err
}
for _, e := range es {
err = Mv(filepath.Join(src, e.Name()), filepath.Join(dst, e.Name()))
if err != nil {
return err
}
}
} else {
err = os.MkdirAll(filepath.Dir(dst), 0755)
if err != nil {
return err
}
err = os.Rename(src, dst)
if err != nil {
return err
}
}
return nil
}
func removeAll(glob string) {
files, _ := filepath.Glob(glob)
for _, f := range files {
os.Remove(f)
}
}

View File

@ -29,12 +29,22 @@ fi
rm -rf $DEST
mkdir -p $DEST
export CGO_ENABLED=0
if [[ "$GOOS" == "windows" ]]; then
if [[ "$GOARCH" == "386" ]]; then
curl -fLso $DEST/updater.exe "https://github.com/throneproj/updater/releases/latest/download/updater-windows32.exe"
else
curl -fLso $DEST/updater.exe "https://github.com/throneproj/updater/releases/latest/download/updater-windows64.exe"
fi
fi
if [[ "$GOOS" == "linux" ]]; then
if [[ "$GOARCH" == "arm64" ]]; then
curl -fLso $DEST/updater "https://github.com/throneproj/updater/releases/latest/download/updater-linux-arm64"
else
curl -fLso $DEST/updater "https://github.com/throneproj/updater/releases/latest/download/updater-linux-amd64"
fi
fi
#### Go: updater ####
pushd core/updater
[ "$GOOS" == "darwin" ] || $GOCMD build -o $DEST -trimpath -ldflags "-w -s"
popd
export CGO_ENABLED=0
#### Go: core ####
pushd core/server