-
Notifications
You must be signed in to change notification settings - Fork 0
/
launcher.go
53 lines (46 loc) · 1.02 KB
/
launcher.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
//go:build launcher
package main
import (
"os"
"os/exec"
"path/filepath"
_ "embed"
)
//go:embed modpack.exe
var modpackExe []byte
//go:embed webview.dll
var webviewDll []byte
//go:embed WebView2Loader.dll
var webview2LoaderDll []byte
func main() {
// Extract modpack.exe to %LocalAppData%.
folder, err := os.UserCacheDir()
if err != nil {
panic(err)
}
err = os.MkdirAll(filepath.Join(folder, "modpack"), os.ModePerm)
if err != nil {
panic(err)
}
err = os.WriteFile(filepath.Join(folder, "modpack", "modpack.exe"), modpackExe, os.ModePerm)
if err != nil {
panic(err)
}
err = os.WriteFile(filepath.Join(folder, "modpack", "webview.dll"), webviewDll, os.ModePerm)
if err != nil {
panic(err)
}
err = os.WriteFile(filepath.Join(folder, "modpack", "WebView2Loader.dll"), webview2LoaderDll, os.ModePerm)
if err != nil {
panic(err)
}
cmd := exec.Command(filepath.Join(folder, "modpack", "modpack.exe"))
err = cmd.Start()
if err != nil {
panic(err)
}
cmd.Process.Release()
if err != nil {
panic(err)
}
}