From 8b850c2d095b3e391c62920b9b1096d5f994c7a6 Mon Sep 17 00:00:00 2001 From: Tom5521 Date: Sat, 13 Jan 2024 13:48:49 -0300 Subject: [PATCH] Now you can download and use zdoom on linux! --- README.md | 2 +- internal/download/main.go | 71 +++++++++++++++++++++++++++++++++-- internal/gui/configuration.go | 4 -- 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e9c87f8..6aaa8ad 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A cross-platform launcher for *zdoom - Light/dark mode toggle - Cross platform -- Auto download gzdoom/zdoom +- Assisted download of gzdoom/zdoom ## Installation diff --git a/internal/download/main.go b/internal/download/main.go index 142df69..025c54c 100644 --- a/internal/download/main.go +++ b/internal/download/main.go @@ -24,6 +24,7 @@ const ( WinGZDoomURL = "https://github.com/ZDoom/gzdoom/releases/download/g4.11.3/gzdoom-4-11-3.a.-Windows-64bit.zip" WinZDoomURL = "https://zdoom.org/files/zdoom/2.8/zdoom-2.8.1.zip" LinuxGZDoomURL = "https://github.com/ZDoom/gzdoom/releases/download/g4.11.3/gzdoom-g4.11.3-linux-portable.tar.xz" + LinuxZDoomURL = "https://zdoom.org/files/zdoom/2.8/zdoom_2.8.1_amd64.deb" ) func Download(url, file string) error { @@ -92,7 +93,7 @@ func GZDoom() error { if IsWindows { settings.GZDoomDir = config.CurrentPath + `\gzdoom\gzdoom.exe` } - err = settings.Write() + err = os.RemoveAll(path) if err != nil { return err } @@ -102,8 +103,15 @@ func GZDoom() error { // Only with windows. func ZDoom() error { if IsLinux { - return ErrOnlyForWindows + return linuxZdoom() } + if IsWindows { + return windowsZdoom() + } + return nil +} + +func windowsZdoom() error { path := config.CurrentPath + `\zdoom.zip` url := WinZDoomURL err := Download(url, path) @@ -119,9 +127,66 @@ func ZDoom() error { return err } settings.ZDoomDir = config.CurrentPath + `\zdoom\zdoom.exe` - err = settings.Write() + return nil +} + +func linuxZdoom() error { + var ( + debName = "zdoom.deb" + path = config.CurrentPath + "/" + debName + url = LinuxZDoomURL + tmpDir = "tmp-zdoom" + ) + err := Download(url, path) if err != nil { return err } + err = os.Chdir(config.CurrentPath) + if err != nil { + return err + } + if _, err = os.Stat(tmpDir); os.IsNotExist(err) { + err = os.Mkdir(tmpDir, os.ModePerm) + if err != nil { + return err + } + } + cmd := exec.Command("ar", "x", debName, "--output="+tmpDir) + err = cmd.Run() + if err != nil { + return err + } + err = os.Chdir(tmpDir) + if err != nil { + return err + } + if _, err = os.Stat("zdoom"); os.IsNotExist(err) { + err = os.Mkdir("zdoom", os.ModePerm) + if err != nil { + return err + } + } + cmd = exec.Command("tar", "-xf", "data.tar.xz", "-C", "zdoom") + err = cmd.Run() + if err != nil { + return err + } + cmd = exec.Command("cp", "-rf", "zdoom/opt/zdoom", config.CurrentPath) + err = cmd.Run() + if err != nil { + return err + } + err = os.Chdir(config.CurrentPath) + if err != nil { + return err + } + toRemove := []string{tmpDir, debName} + for _, f := range toRemove { + err = os.RemoveAll(f) + if err != nil { + return err + } + } + settings.ZDoomDir = config.CurrentPath + "/zdoom/zdoom" return nil } diff --git a/internal/gui/configuration.go b/internal/gui/configuration.go index 53f19cb..e3ad2a7 100644 --- a/internal/gui/configuration.go +++ b/internal/gui/configuration.go @@ -1,7 +1,6 @@ package gui import ( - "runtime" "time" "fyne.io/fyne/v2" @@ -137,9 +136,6 @@ func (ui *configUI) downBox() *fyne.Container { time.Sleep(time.Second * 2) down.zdoom.SetText(po.Get("Download ZDoom")) } - if runtime.GOOS == "linux" { - down.zdoom.Disable() - } downloadCont := container.NewAdaptiveGrid(2, down.gzdoom, down.zdoom) return downloadCont