forked from Vencord/Installer
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cli.go
172 lines (146 loc) · 4.34 KB
/
cli.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//go:build cli
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Installer, a cross platform gui/cli app for installing Vencord
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
package main
import (
"flag"
"fmt"
"os"
)
var discords []any
func isValidBranch(branch string) bool {
switch branch {
case "", "stable", "ptb", "canary", "auto":
return true
default:
return false
}
}
func die(msg string) {
fmt.Println(msg)
os.Exit(1)
}
func main() {
InitGithubDownloader()
discords = FindDiscords()
var installFlag = flag.Bool("install", false, "Install Vencord on a Discord install")
var updateFlag = flag.Bool("reinstall", false, "Reinstall & update Vencord")
var uninstallFlag = flag.Bool("uninstall", false, "Uninstall Vencord from a Discord install")
var installOpenAsar = flag.Bool("install-openasar", false, "Install OpenAsar on a Discord install")
var uninstallOpenAsar = flag.Bool("uninstall-openasar", false, "Uninstall OpenAsar from a Discord install")
var locationFlag = flag.String("location", "", "Select the location of your Discord install")
var branchFlag = flag.String("branch", "", "Select the branch of Discord you want to modify [auto|stable|ptb|canary]")
flag.Parse()
if *locationFlag != "" && *branchFlag != "" {
die("The 'location' and 'branch' flags are mutually exclusive.")
}
if !isValidBranch(*branchFlag) {
die("The 'branch' flag must be one of the following: [auto|stable|ptb|canary]")
}
if *installFlag || *updateFlag {
if !<-GithubDoneChan {
die("Not " + Ternary(*installFlag, "installing", "updating") + " as fetching release data failed")
}
}
fmt.Println("Vencord Installer cli", InstallerTag, "("+InstallerGitHash+")")
var err error
if *installFlag {
_ = PromptDiscord("patch", *locationFlag, *branchFlag).patch()
} else if *uninstallFlag {
_ = PromptDiscord("unpatch", *locationFlag, *branchFlag).unpatch()
} else if *updateFlag {
err := installLatestBuilds()
if err == nil {
PromptDiscord("repatch", *locationFlag, *branchFlag).patch()
}
} else if *installOpenAsar {
discord := PromptDiscord("patch", *locationFlag, *branchFlag)
if !discord.IsOpenAsar() {
err = discord.InstallOpenAsar()
} else {
die("OpenAsar already installed")
}
} else if *uninstallOpenAsar {
discord := PromptDiscord("patch", *locationFlag, *branchFlag)
if discord.IsOpenAsar() {
err = discord.UninstallOpenAsar()
} else {
die("OpenAsar not installed")
}
} else {
flag.Usage()
}
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func PromptDiscord(action, dir, branch string) *DiscordInstall {
if branch == "auto" {
for _, b := range []string{"stable", "canary", "ptb"} {
for _, discord := range discords {
install := discord.(*DiscordInstall)
if install.branch == b {
return install
}
}
}
die("No Discord install found. Try manually specifying it with the --dir flag")
}
if branch != "" {
for _, discord := range discords {
install := discord.(*DiscordInstall)
if install.branch == branch {
return install
}
}
die("Discord " + branch + " not found")
}
if dir != "" {
if discord := ParseDiscord(dir, branch); discord != nil {
return discord
} else {
die(dir + " is not a valid Discord install")
}
}
fmt.Println("Please choose a Discord install to", action)
for i, discord := range discords {
install := discord.(*DiscordInstall)
fmt.Printf("[%d] %s%s (%s)\n", i+1, Ternary(install.isPatched, "(PATCHED) ", ""), install.path, install.branch)
}
fmt.Printf("[%d] Custom Location\n", len(discords)+1)
var choice int
for {
fmt.Printf("> ")
if _, err := fmt.Scan(&choice); err != nil {
fmt.Println("That wasn't a valid choice")
continue
}
choice--
if choice >= 0 && choice < len(discords) {
return discords[choice].(*DiscordInstall)
}
if choice == len(discords) {
var custom string
fmt.Print("Custom Discord Install: ")
if _, err := fmt.Scan(&custom); err == nil {
if discord := ParseDiscord(custom, branch); discord != nil {
return discord
}
}
}
fmt.Println("That wasn't a valid choice")
}
}
func InstallLatestBuilds() error {
return installLatestBuilds()
}
func HandleScuffedInstall() {
fmt.Println("Hold On!")
fmt.Println("You have a broken Discord Install.")
fmt.Println("Please reinstall Discord before proceeding!")
fmt.Println("Otherwise, Vencord will likely not work.")
}