-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
75 lines (56 loc) · 2.23 KB
/
utils.py
File metadata and controls
75 lines (56 loc) · 2.23 KB
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
import os
import sys
import requests
curseforgeAPIHeader = None
def initializeProgram():
getHeader()
def getHeader():
global curseforgeAPIHeader
apikey = getAPIKey()
curseforgeAPIHeader = {'x-api-key': apikey}
def getAPIKey():
path = os.getcwd() + os.sep + "apikey"
if not os.path.exists(path):
open(path, "x")
f = open(path, "r")
token = f.read()
if token == "":
print(f"Please put a curseforge API Key in \"{path}\" then restart program.")
print("Please note: If you'd like to apply for an API Key, see here: https://support.curseforge.com/en/support/solutions/articles/9000208346-about-the-curseforge-api-and-how-to-apply-for-a-key")
sys.exit()
else:
return token
def getFromCurseforgeAPI(url):
returned = requests.get(url, headers=curseforgeAPIHeader)
if returned.status_code == 403:
print(f"Status: {returned.status_code} Forbidden.")
print("This means the api key is likely invalid, please check your key at this point, or add a proper key.")
sys.exit()
return returned.text
def makeFolders(name):
if not os.path.exists(os.getcwd() + os.sep + name):
os.mkdir(os.getcwd() + os.sep + name)
os.mkdir(os.getcwd() + os.sep + name + os.sep + ".minecraft")
os.mkdir(os.getcwd() + os.sep + name + os.sep + f".minecraft{os.sep}mods")
return os.getcwd() + os.sep + name + os.sep
def getTextFromFile(path):
f = open(path, "r")
return f.read()
def writeInstallInstructions(path, modpackName, mcVersion, modLoader):
f = open(path + "README.txt", 'w')
f.write(f"Instructions for {modpackName}:\n1. Make an instance with:\n- Minecraft Version: {mcVersion}\n- Mod Loader Version: {modLoader}\n2. Copy over the .minecraft folder in this folder to the .minecraft folder of the instance you just made.\n3. Launch instance.\n\nMod List:")
f.close()
def isInt(userinput: str) -> bool:
try:
int(userinput)
except ValueError:
return False
return True
def openFiles(folder):
print(f"Opening folder for {folder}")
# Windows
if os.name == "nt":
os.startfile(os.path.normpath(folder))
# Linux
if os.name == "posix":
os.system('xdg-open "%s"' % folder)