-
Notifications
You must be signed in to change notification settings - Fork 1
/
wine.go
101 lines (97 loc) · 2.33 KB
/
wine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"github.com/gotk3/gotk3/gtk"
"github.com/mholt/archiver/v3"
)
const (
wineURL = "https://www.playonlinux.com/wine/binaries/phoenicis/staging-linux-amd64/PlayOnLinux-wine-5.20-staging-linux-amd64.tar.gz"
)
func downloadWine(parent *gtk.Window, cb chan bool) {
win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
win.SetTransientFor(parent)
win.SetDestroyWithParent(true)
win.Connect("destroy", func() {
parent.SetSensitive(true)
})
parent.SetSensitive(false)
spin, _ := gtk.SpinnerNew()
spin.Start()
txt, _ := gtk.LabelNew("Downloading Wine")
box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5)
box.SetMarginBottom(10)
box.SetMarginEnd(10)
box.SetMarginStart(10)
box.SetMarginTop(10)
box.Add(spin)
box.Add(txt)
win.Add(box)
win.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT)
win.ShowAll()
win.Show()
go func(win *gtk.Window, txt *gtk.Label) {
defer win.Close()
wineTar, err := os.Create("PortableApps/LinuxPACom/wine5.20.tar.bz2")
if err != nil {
fmt.Println(err)
cb <- false
return
}
defer wineTar.Close()
check := http.Client{
CheckRedirect: func(r *http.Request, _ []*http.Request) error {
r.URL.Opaque = r.URL.Path
return nil
},
}
resp, err := check.Get(wineURL)
if err != nil {
fmt.Println(err)
cb <- false
return
}
os.RemoveAll("PortableApps/LinuxPACom/Wine")
defer resp.Body.Close()
_, err = io.Copy(wineTar, resp.Body)
if err != nil {
fmt.Println(err)
cb <- false
return
}
txt.SetText("Extracting Wine")
err = archiver.DefaultTarBz2.Unarchive("PortableApps/LinuxPACom/wine2.5.tar.bz2", "PortableApps/LinuxPACom/Wine")
if err != nil {
fmt.Println(err)
cb <- false
return
}
fil, err := os.Open("PortableApps/LinuxPACom/common.sh")
if err != nil {
fmt.Println(err)
cb <- false
return
}
tmp, err := ioutil.ReadAll(fil)
if err != nil {
fmt.Println(err)
cb <- false
return
}
if !strings.Contains(string(tmp), "export PATH=$PWD/PortableApps/LinuxPACom/Wine/wineversion/2.5/bin:$PATH") {
tmp = append(tmp, []byte("\nexport PATH=$PWD/PortableApps/LinuxPACom/Wine/wineversion/2.5/bin:$PATH")...)
ioutil.WriteFile("PortableApps/LinuxPACom/common.sh", tmp, 0777)
if err != nil {
fmt.Println(err)
cb <- false
return
}
}
cb <- true
return
}(win, txt)
}