From 9bab75b6539c4f10b1ff823a79ed8f56fa6b5b76 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 30 Mar 2024 12:22:11 -0400 Subject: [PATCH] Flesh out creating stellaris modpack and add barotrauma stub --- createBarotraumaPack.py | 0 createStellarisPack.py | 98 +++++++++++++++++++++++++++++++++++++++++ util.py | 0 3 files changed, 98 insertions(+) create mode 100644 createBarotraumaPack.py create mode 100644 createStellarisPack.py create mode 100644 util.py diff --git a/createBarotraumaPack.py b/createBarotraumaPack.py new file mode 100644 index 0000000..e69de29 diff --git a/createStellarisPack.py b/createStellarisPack.py new file mode 100644 index 0000000..d306379 --- /dev/null +++ b/createStellarisPack.py @@ -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() diff --git a/util.py b/util.py new file mode 100644 index 0000000..e69de29