Skip to content

Commit

Permalink
Now you can download and use zdoom on linux!
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom5521 committed Jan 13, 2024
1 parent 182ba23 commit 8b850c2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
71 changes: 68 additions & 3 deletions internal/download/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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
}
4 changes: 0 additions & 4 deletions internal/gui/configuration.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gui

import (
"runtime"
"time"

"fyne.io/fyne/v2"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b850c2

Please # to comment.