From 147dee852363bf9b84a8b79e2bcad07eb795d161 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 28 Jan 2024 22:14:00 -0500 Subject: [PATCH] Added guided modpack creator --- main.py | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 28b4054..9b40999 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ import os import shutil +import sqlite3 def is_admin(): @@ -37,7 +38,10 @@ def main_help(): "You can use this to rename the stellaris workshop folder sto something human readable. First copy everything in your stellaris workshop folder to a" + "temporary directory. Then run the script from that directory, or point the script at that directory. This will make a copy of all your stellaris mod" + " folders with relevant names. For example '1121692237' would be renamed to 'Gigastructural Engineering & More '") - print("0: Rename mod folders") + print("1: Create modpack") + print("A guided process to create a new modpack using an existing playset from the stellaris launcher. Make sure the mods in the playlist are already in "+ + "the proper mod load order.") + print("9: Help") print("This is help") @@ -76,11 +80,116 @@ def rename_folders(): print(f"Error processing folder {folder_path}: {e}") input("Press enter to continue") +def sort_mods(e): + return e[3] + + +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 relavent 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) + workshopMods = [f for f in os.listdir(workshopPath) if os.path.isdir(os.path.join(workshopPath, f))] #List of every folder in the workshop path + # 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() + if __name__ == '__main__': print("This is a multi tool script, Please type the number for what you would like to do:") print("0: Rename mod folders") + print("1: Create modpack") selection = input("9: help") while True: @@ -88,6 +197,9 @@ def rename_folders(): case "0": rename_folders() break + case "1": + create_modpack() + break case "9": main_help() break