Skip to content

Commit

Permalink
Added guided modpack creator
Browse files Browse the repository at this point in the history
  • Loading branch information
RagingFlames committed Jan 29, 2024
1 parent 63ca8f7 commit 147dee8
Showing 1 changed file with 113 additions and 1 deletion.
114 changes: 113 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shutil
import sqlite3


def is_admin():
Expand Down Expand Up @@ -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")


Expand Down Expand Up @@ -76,18 +80,126 @@ 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:

match selection:
case "0":
rename_folders()
break
case "1":
create_modpack()
break
case "9":
main_help()
break
Expand Down

0 comments on commit 147dee8

Please sign in to comment.