-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
175 lines (143 loc) · 6.5 KB
/
main.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
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
173
174
175
import math
import os
import sys
version = 2.3
# Check if required imports are available
try:
from pathlib import Path
except ImportError:
print("Error: The 'pathlib' module is missing. Please install it by running 'pip install pathlib'.")
sys.exit(1)
try:
import requests
except ImportError:
print("Error: The 'requests' module is missing. Please install it by running 'pip install requests'.")
sys.exit(1)
try:
from tqdm import tqdm
except ImportError:
print("Error: The 'tqdm' module is missing. Please install it by running 'pip install tqdm'.")
sys.exit(1)
try:
import py7zr
except ImportError:
print("Error: The 'py7zr' module is missing. Please install it by running 'pip install py7zr'.")
sys.exit(1)
try:
from getpass import getuser
except ImportError:
print("Error: The 'getpass' module is missing which probably means something is very wrong.")
sys.exit(1)
def download_file(url, destination):
download_response = requests.get(url)
if download_response.status_code != 200:
print("Error: Failed to download the file.")
return
file_path = os.path.join(destination, "url.py")
with open(file_path, "wb") as f:
f.write(download_response.content)
print("Downloaded server updates.")
return file_path
from pathlib import Path
def download_and_extract(url, destination):
download_extract_response = requests.get(url, stream=True)
if download_extract_response.status_code != 200:
print("Error: Failed to download the archive.")
return
archive_path = os.path.join(destination, "mod.7z")
total_size = int(download_extract_response.headers.get("content-length", 0))
block_size = 1024
progress_bar = tqdm(total=total_size, unit="B", unit_scale=True, desc="Downloading")
with open(archive_path, "wb") as f:
for data in download_extract_response.iter_content(block_size):
progress_bar.update(len(data))
f.write(data)
progress_bar.close()
print("Downloaded the archive.")
print("Beginning extraction, this may take a few minutes.")
with py7zr.SevenZipFile(archive_path, mode='r') as z:
z.extractall(path=destination)
print("Extracted the contents.")
os.remove(archive_path) # Delete the archive file
print("Deleted the archive file.")
def compare_versions(web_version):
if variables['version']:
if variables['version'] != str(version):
print("It looks like there is an update available for this script.")
print("You have version " + str(version) + " but the latest version is " + str(variables['version']))
print("Go to the following website to get the latest version")
print("https://github.com/RagingFlames/Paradox-Mod-Updater/releases")
local_major, local_minor = map(int, str(version).split('.'))
web_major, web_minor = map(int, web_version.split('.'))
if web_major - local_major >= 1:
print("You are behind by at least 1 major revision, it is highly recommended that exit and download the newer version")
while True:
response = input("Do you want to continue? (y/n): ").lower()
if response == 'y':
print("Continuing...")
# Perform additional tasks or actions here
break
elif response == 'n':
print("Exiting...")
sys.exit(1)
else:
print("Invalid input. Please answer with 'y' or 'n'.")
print("Go to the pinned post and redownload the script to grab the new version")
if __name__ == "__main__":
scriptVariables = "http://96.227.58.11:160/Public/scriptVariables.txt"
archive_url = None
# Download the scriptVariables file
current_dir = os.getcwd()
scriptVariablesFile = download_file(scriptVariables, current_dir)
# Execute the url.py file and retrieve variables
if scriptVariablesFile:
url_module = {}
with open(scriptVariablesFile, "r") as f:
exec(f.read(), url_module)
variables = url_module.copy()
else:
print("An error has occurred, I could not acquire the url file.")
exit(9)
# Check version number.
compare_versions(str(variables['version']))
# Mod selection logic
if variables:
# Print special message
if variables['message']:
print(variables['message'])
# Select a game
print("What game would you like to install a mod for?")
for i, key in enumerate(variables['packs'].keys()):
print(f"{i}: {key}")
selection = input("Enter the number on the left corresponding to the game you want to install a modpack for: ")
selected_game = list(variables['packs'].keys())[int(selection)]
print("Mod packs available for:", selected_game)
# Select a Mod
for i, key in enumerate(variables['packs'].get(selected_game).keys()):
print(f"{i}: {key}")
selection = input("Enter the number on the left corresponding to the mod pack you want to install, 0 is the latest one: ")
selected_mod = list(variables['packs'].get(selected_game).keys())[int(selection)]
# Finding directory
username = getuser()
documents_path = Path.home() / "Documents"
destination = documents_path / "Paradox Interactive" / selected_game / "mod"
if os.path.exists(destination):
print("Using C drive for installation")
else:
destination = os.path.join("D:\\", "Users", username, "Documents", "Paradox Interactive", selected_game, "mod")
if os.path.exists(destination):
print("Using D drive for installation")
else:
print("I couldn't find your game folder on your C or D drive")
print("The mod pack will be downloaded to the current directory")
destination = os.getcwd()
# Use the selected key for the upcoming download
archive_url = variables['packs'].get(selected_game).get(selected_mod)[0]
download_and_extract(archive_url, destination)
# Print the hash for this mod pack
print("The hash for this mod pack is: " + str(variables['packs'].get(selected_game).get(selected_mod)[1]))
else:
print("Error: Failed to retrieve variables from the server.")
print("Finished!")
input("Press Enter to close the program...")
sys.exit(1)