1+ //go:build linux
2+
3+ package winegdk
4+
5+ import (
6+ "context"
7+ "os"
8+ "os/exec"
9+ "path/filepath"
10+ "strings"
11+ "github.com/wailsapp/wails/v3/pkg/application"
12+ "github.com/liteldev/LeviLauncher/internal/utils"
13+ "os/ioutil"
14+ )
15+
16+ const (
17+ EventSetupStatus = "winegdk.setup.status"
18+ EventSetupProgress = "winegdk.setup.progress"
19+ EventSetupError = "winegdk.setup.error"
20+ EventSetupDone = "winegdk.setup.done"
21+ )
22+
23+ func Setup (ctx context.Context ) string {
24+ base := utils .BaseRoot ()
25+ if strings .TrimSpace (base ) == "" { application .Get ().Event .Emit (EventSetupError , "ERR_BASE_ROOT" ); return "ERR_BASE_ROOT" }
26+ application .Get ().Event .Emit (EventSetupStatus , "start" )
27+ id := func () string {
28+ b , err := ioutil .ReadFile ("/etc/os-release" )
29+ if err != nil { return "" }
30+ for _ , l := range strings .Split (string (b ), "\n " ) {
31+ s := strings .TrimSpace (l )
32+ if strings .HasPrefix (s , "ID=" ) {
33+ v := strings .TrimPrefix (s , "ID=" )
34+ v = strings .Trim (v , "\" '" )
35+ return strings .ToLower (strings .TrimSpace (v ))
36+ }
37+ }
38+ return ""
39+ }()
40+ if id == "arch" {
41+ application .Get ().Event .Emit (EventSetupStatus , "deps_warning_arch" )
42+ pkgs := "mingw-w64-gcc base-devel git gcc multilib-devel winetricks wine vulkan-icd-loader lib32-vulkan-icd-loader libx11 lib32-libx11 freetype2 lib32-freetype2 mesa lib32-mesa glu lib32-glu alsa-lib lib32-alsa-lib libxrandr lib32-libxrandr libxi lib32-libxi libxext lib32-libxext libxrender lib32-libxrender libxcursor lib32-libxcursor libxinerama lib32-libxinerama libxcomposite lib32-libxcomposite libxfixes lib32-libxfixes libpng lib32-libpng libjpeg-turbo lib32-libjpeg-turbo libtiff lib32-libtiff openal lib32-openal mpg123 lib32-mpg123 sdl2 lib32-sdl2 libxml2 lib32-libxml2 libldap lib32-libldap vulkan-headers cups"
43+ application .Get ().Event .Emit (EventSetupStatus , "deps_install_arch" )
44+ cmd := exec .Command ("bash" , "-c" , "sudo pacman -S --needed --noconfirm " + pkgs )
45+ _ = cmd .Run ()
46+ } else {
47+ application .Get ().Event .Emit (EventSetupStatus , "deps_warning_other" )
48+ }
49+ wg := filepath .Join (base , "WineGDK" )
50+ if _ , err := os .Stat (wg ); err != nil {
51+ application .Get ().Event .Emit (EventSetupStatus , "cloning" )
52+ cmd := exec .Command ("git" , "clone" , "https://github.com/Weather-OS/WineGDK.git" , wg )
53+ if err := cmd .Run (); err != nil { application .Get ().Event .Emit (EventSetupError , "ERR_GIT_CLONE" ); return "ERR_GIT_CLONE" }
54+ }
55+ bd := filepath .Join (base , "build" )
56+ _ = os .MkdirAll (bd , 0755 )
57+ application .Get ().Event .Emit (EventSetupStatus , "configuring" )
58+ cfg := exec .Command ("bash" , "-c" , "cd '" + bd + "' && '../WineGDK/configure' --enable-win64" )
59+ if err := cfg .Run (); err != nil { application .Get ().Event .Emit (EventSetupError , "ERR_CONFIGURE" ); return "ERR_CONFIGURE" }
60+ application .Get ().Event .Emit (EventSetupStatus , "compiling" )
61+ mk := exec .Command ("bash" , "-c" , "cd '" + bd + "' && make -j$(nproc)" )
62+ if err := mk .Run (); err != nil { application .Get ().Event .Emit (EventSetupError , "ERR_MAKE" ); return "ERR_MAKE" }
63+ pf := filepath .Join (base , "prefix" )
64+ _ = os .MkdirAll (pf , 0755 )
65+ application .Get ().Event .Emit (EventSetupStatus , "winetricks" )
66+ wt := exec .Command ("bash" , "-c" , "WINEPREFIX='" + pf + "' winetricks vkd3d dxvk dxvk_nvapi0061" )
67+ if err := wt .Run (); err != nil { application .Get ().Event .Emit (EventSetupError , "ERR_WINETRICKS" ); return "ERR_WINETRICKS" }
68+ application .Get ().Event .Emit (EventSetupDone , struct {}{})
69+ return ""
70+ }
0 commit comments