This repository was archived by the owner on May 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.py
62 lines (47 loc) · 2.19 KB
/
installer.py
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
import dns.resolver
import platform
import os
current_os = platform.system()
print(current_os)
LINE_IDENTIFIER = "ADDED BY RECAPE"
try:
hosts_file_dir = {
"Windows": "C:\Windows\System32\drivers\etc\hosts",
"Linux": "/etc/hosts",
"Darwin": "/private/etc/hosts"
}[current_os]
except KeyError:
hosts_file_dir = "/etc/hosts"
OPTIFINE_URL = "s.optifine.net"
RECAPE_URL = "recape-server.boyne.dev"
if False: #os.path.exists(".debug"):
RECAPE_IP = "127.0.0.1"
else:
RECAPE_IP = dns.resolver.resolve(RECAPE_URL)[0].to_text()
def install():
uninstall()
try:
with open(hosts_file_dir, "r") as hosts:
content = hosts.readlines()
with open(hosts_file_dir, "w") as hosts:
content.append("\n" + RECAPE_IP + " " + OPTIFINE_URL + " #" + LINE_IDENTIFIER)
hosts.write("".join(content))
except PermissionError as e:
return "Could not access your hosts file. You need to start ReCape as an administrator/root in order to do this. Proceed with the manual installation or run this installer as an administrator, root, or superuser."
return "Installed succesfully!"
def uninstall():
try:
with open(hosts_file_dir, "r") as hosts:
content = hosts.readlines()
for i in range(0, len(content)):
if LINE_IDENTIFIER in content[i]:
content.pop(i)
break
with open(hosts_file_dir, "w") as hosts:
hosts.write("".join(content))
except PermissionError:
print("Access Denied")
return "Could not access your hosts file. You need to start ReCape as an administrator/root in order to do this. Proceed with the manual uninstallation or run this installer as an administrator, root, or superuser."
return "Uninstalled ReCape!"
def get_installer_text():
return "You can also install ReCape yourself by manually inputting text into your hosts file. On your system, this file should be located at \"" + hosts_file_dir + "\". On a new line, put in this text:\n" + RECAPE_IP + " " + OPTIFINE_URL + " #" + LINE_IDENTIFIER + "\nSimilarly, you can uninstall ReCape by deleting that line in the hosts file later."