-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flesh out creating stellaris modpack and add barotrauma stub
- Loading branch information
1 parent
147dee8
commit 9bab75b
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import os | ||
import shutil | ||
import sqlite3 | ||
|
||
|
||
def copy_files(src_folder, dest_folder): | ||
# Walk through the source folder | ||
for root, dirs, files in os.walk(src_folder): | ||
for file in files: | ||
src_path = os.path.join(root, file) | ||
|
||
# Preserve the relative path structure in the destination folder | ||
relative_path = os.path.relpath(src_path, src_folder) | ||
dest_path = os.path.join(dest_folder, relative_path) | ||
|
||
# Create the necessary directories in the destination folder | ||
os.makedirs(os.path.dirname(dest_path), exist_ok=True) | ||
|
||
# Copy the file, overwriting if it already exists | ||
shutil.copy2(src_path, dest_path) | ||
print(f"Copied: {src_path} to {dest_path}") | ||
|
||
|
||
def create_modpack(): | ||
# Connect to the SQLite database file (create a new file if it doesn't exist) | ||
destination = os.getcwd() | ||
db_file_path = os.path.join(os.path.expanduser("~"), "Documents", "Paradox Interactive", "Stellaris", "launcher-v2.sqlite") | ||
connection = sqlite3.connect(db_file_path) | ||
|
||
# Create a cursor object to execute SQL queries | ||
cursor = connection.cursor() | ||
# Get everything in the playset table | ||
cursor.execute("SELECT * FROM playsets") | ||
rows = cursor.fetchall() | ||
|
||
print("Found the following playsets, which playset will we use?") | ||
# Print the rows found | ||
for i in range(len(rows)): | ||
print("\033[1m" + str(i) + "\033[0m" + " : " + rows[i][1]) | ||
selection = input() | ||
playset = rows[int(selection)][0] | ||
print("Using playset with ID: " + playset) | ||
|
||
# Get all relevant mods | ||
cursor.execute("SELECT * FROM playsets_mods") | ||
rows = cursor.fetchall() | ||
modIDList = [] | ||
for row in rows: | ||
if (row[0] == playset): | ||
modIDList.append(row) | ||
# Sort the list by load order | ||
modIDList = sorted(modIDList, key=lambda x: x[3]) | ||
|
||
cursor.execute("SELECT * FROM mods") | ||
rows = cursor.fetchall() | ||
modWorkshopIDList = [] | ||
for mod in modIDList: # For every mod in the list | ||
for row in rows: # For every row in the mods table | ||
if row[0] == mod[1]: | ||
modWorkshopIDList.append(row) | ||
|
||
# Print sorted mod list | ||
print("The following mods will be used in this order for the modpack") | ||
for mod in modWorkshopIDList: | ||
print(mod[5]) | ||
input("Press 'Enter' to continue") | ||
|
||
# Make the mod folder | ||
modPackName = input("What is the name for this new modpack?") | ||
destination = os.path.join(destination, modPackName) | ||
try: | ||
os.mkdir(destination) | ||
print(f"Directory '{destination}' created successfully.") | ||
except FileExistsError: | ||
print(f"Directory '{destination}' already exists.") | ||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
|
||
# Find the workshop mods | ||
workshopPath = "" | ||
while True: | ||
workshopPath = input("Copy paste the path to your stellaris workshop folder") | ||
if not workshopPath.rsplit("\\", 1)[-1] == "281990": | ||
print("It looks like yu didn't paste the correct folder, the path should end at the '281990' folder") | ||
else: | ||
break | ||
|
||
# workshopPath = convert_path(workshopPath) | ||
# Start copying the files | ||
for mod in modWorkshopIDList: | ||
workshopModFolder = os.path.join(workshopPath, mod[2]) | ||
copy_files(workshopModFolder, destination) | ||
|
||
# Close the cursor | ||
cursor.close() | ||
# Commit the changes and close the connection | ||
connection.commit() | ||
connection.close() |