Skip to content

Commit

Permalink
Stable Release 3 - Fix partial crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
nealol committed Apr 23, 2022
1 parent e2a3ac3 commit e3a5b60
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/dist/
/.idea/
/.idea/
lilith.log
8 changes: 4 additions & 4 deletions build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

./with-env.sh ./env/windows.env go build -o "./dist/lilith-launcher-windows-s2.exe" main.go
./with-env.sh ./env/linux.env go build -o "./dist/lilith-launcher-linux-s2" main.go
./with-env.sh ./env/macos.env go build -o "./dist/lilith-launcher-macos-s2" main.go
./with-env.sh ./env/m1.env go build -o "./dist/lilith-launcher-m1-s2" main.go
./with-env.sh ./env/windows.env go build -o "./dist/lilith-launcher-windows-s3.exe" main.go
./with-env.sh ./env/linux.env go build -o "./dist/lilith-launcher-linux-s3" main.go
./with-env.sh ./env/macos.env go build -o "./dist/lilith-launcher-macos-s3" main.go
./with-env.sh ./env/m1.env go build -o "./dist/lilith-launcher-m1-s3" main.go
2 changes: 2 additions & 0 deletions env/linux.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GOOS=linux
GOARCH=amd64
2 changes: 2 additions & 0 deletions env/m1.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GOOS=darwin
GOARCH=arm64
2 changes: 2 additions & 0 deletions env/macos.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GOOS=darwin
GOARCH=amd64
2 changes: 2 additions & 0 deletions env/windows.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GOOS=windows
GOARCH=amd64
33 changes: 25 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"runtime"
"strconv"
"strings"
"syscall"
"time"
)

Expand All @@ -37,8 +38,10 @@ type launcherConfig struct {

func main() {
//println(runtime.GOARCH)
println("Lilith Launcher Stable Release 2")
println("================================")
if !hasArg("--headless") {
println("Lilith Launcher Stable Release 3")
println("================================")
}

config := launcherConfig{
Alpha: false,
Expand Down Expand Up @@ -128,7 +131,7 @@ func main() {

deathCount := 0
for {
if deathCount > 9 {
if deathCount > 4 {
println("Relaunched too many times, shutting down...")
break
}
Expand All @@ -144,13 +147,14 @@ func main() {
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
if strings.Contains(err.Error(), "valid Win32 application") {
println("Invalid application found, deleting and restarting")
if strings.Contains(err.Error(), "valid Win32 application") || strings.Contains(err.Error(), "segmentation") || deathCount == 4 {
println("Failed to launch Lilith, deleting...")
err := os.Remove(path)
handle(err)
main()
} else {
os.Exit(1)
path, err := os.Executable()
handle(err)
err = syscall.Exec(path, []string{os.Args[0], "--headless"}, os.Environ())
handle(err)
}
}
deathCount++
Expand All @@ -164,6 +168,19 @@ func handle(err error) {
}
}

func hasArg(str string) bool {
return isElementExist(os.Args, str)
}

func isElementExist(s []string, str string) bool {
for _, v := range s {
if v == str {
return true
}
}
return false
}

func DownloadFile(dest string, url string) error {

out, err := os.Create(dest)
Expand Down
Empty file modified with-env.sh
100644 → 100755
Empty file.

0 comments on commit e3a5b60

Please sign in to comment.