Skip to content
Snippets Groups Projects
Commit dc64fdd9 authored by Rsge's avatar Rsge
Browse files

v2.1.0 - UnitPanel addon auto-detection & other small stuff:

- Auto-detect and add mods' UnitPanel addons to EUI
- Replaced own file name function w/ os.path.basename
- Reformatted legacy version (v1.0.1)
parent 9dd4f745
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>ea28d07f-cd43-45d1-b01d-1eeeb360d215</ProjectGuid> <ProjectGuid>ea28d07f-cd43-45d1-b01d-1eeeb360d215</ProjectGuid>
<ProjectHome>.</ProjectHome> <ProjectHome>.</ProjectHome>
<StartupFile>converter_new_WIP.py</StartupFile> <StartupFile>converter.py</StartupFile>
<SearchPath> <SearchPath>
</SearchPath> </SearchPath>
<WorkingDirectory>.</WorkingDirectory> <WorkingDirectory>.</WorkingDirectory>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<Content Include="Process.txt" /> <Content Include="Process.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="converter_new_WIP.py" /> <Compile Include="converter.py" />
<Compile Include="converter_legacy.py" /> <Compile Include="converter_legacy.py" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
......
######################################################################## ########################################################################
# # # #
# © 2021 - MPL 2.0 - Rsge - v2.0.1 # # © 2021 - MPL 2.0 - Rsge - v2.1.0 #
# https://github.com/Rsge/Civ-V-EUI-Modpack-Converter # # https://github.com/Rsge/Civ-V-EUI-Modpack-Converter #
# # # #
# WINDOWS ONLY! # # WINDOWS ONLY! #
...@@ -33,6 +33,7 @@ vanilla_packs_folder = "zz_Vanilla_Versions" ...@@ -33,6 +33,7 @@ vanilla_packs_folder = "zz_Vanilla_Versions"
# Imports # Imports
import os import os
import winreg as wr import winreg as wr
import os.path as p
from os.path import join as j from os.path import join as j
from glob import glob as g from glob import glob as g
import subprocess import subprocess
...@@ -54,10 +55,6 @@ def error(msg): ...@@ -54,10 +55,6 @@ def error(msg):
input("Press Enter to exit. . .") input("Press Enter to exit. . .")
exit(1) exit(1)
# Get file name
def get_file_name(file, get_folder = False):
return file.split(os.sep)[-1]
# Get 7-zip install dir # Get 7-zip install dir
def get_szip_dir(): def get_szip_dir():
key_location = r"SOFTWARE\7-Zip" key_location = r"SOFTWARE\7-Zip"
...@@ -86,11 +83,13 @@ def get_civ_install_dir(): ...@@ -86,11 +83,13 @@ def get_civ_install_dir():
print("Configuring variables...") print("Configuring variables...")
# Names # Names
modpack_folder_name = "MP_MODSPACK" modpack_folder_name = "MP_MODSPACK"
preservation_extension = ".orig"
load_tag = "ContextPtr:LoadNewContext"
unit_panel_tag = "LuaEvents.UnitPanelActionAddin"
unit_panel_insert_marker = "--Insert ContextPtr for modded unit panel buttons here\n"
eui_cuc_file_names = ["CityBannerManager.lua", eui_cuc_file_names = ["CityBannerManager.lua",
"CityView.lua", "CityView.lua",
"Highlights.xml"] "Highlights.xml"]
load_tag = "ContextPtr:LoadNewContext"
unit_panel_tag = "LuaEvents.UnitPanelActionAddin"
unit_panel_file_name = "UnitPanel.lua" unit_panel_file_name = "UnitPanel.lua"
ige_compat_file_name = "IGE_Window.lua" ige_compat_file_name = "IGE_Window.lua"
# Paths # Paths
...@@ -103,20 +102,21 @@ modpack_path = j(base_path, modpack_folder_name) ...@@ -103,20 +102,21 @@ modpack_path = j(base_path, modpack_folder_name)
mods_path = j(modpack_path, "Mods") mods_path = j(modpack_path, "Mods")
ui_folder_path = j(modpack_path, "UI") ui_folder_path = j(modpack_path, "UI")
# Files # Files
files_ext = j("**", "*.lua") file_ext = "*.lua"
base_ui_files = j(base_path, "..", "UI", files_ext) file_ext_recursive = j("**", file_ext)
gnk_ui_files = j(base_path, "Expansion", "UI", files_ext)
bnw_ui_files = j(base_path, "Expansion2", "UI", files_ext)
vanilla_eui_zip_path = j(vanilla_packs_path, vanilla_eui_zip) vanilla_eui_zip_path = j(vanilla_packs_path, vanilla_eui_zip)
modded_eui_zip_path = j(base_path, modded_eui_zip) modded_eui_zip_path = j(base_path, modded_eui_zip)
mod_files = j(mods_path, files_ext) base_ui_files = j(base_path, "..", "UI", file_ext_recursive)
ui_files = j(ui_folder_path, files_ext) gnk_ui_files = j(base_path, "Expansion", "UI", file_ext_recursive)
eui_files = j(eui_folder_path, files_ext) bnw_ui_files = j(base_path, "Expansion2", "UI", file_ext_recursive)
mod_files = j(mods_path, file_ext_recursive)
ui_files = j(ui_folder_path, file_ext)
eui_files = j(eui_folder_path, file_ext_recursive)
# Global variables # Global variables
eui_only = False eui_only = False
vanilla_ui_files = [] vanilla_ui_file_names = []
unit_panel_files = [] unit_panel_addon_file_names = []
load_tags = {} load_tags = {}
...@@ -136,37 +136,37 @@ while True: ...@@ -136,37 +136,37 @@ while True:
print("This file doesn't exist, try again.") print("This file doesn't exist, try again.")
print("") print("")
## Remove previous modpack # Remove previous modpack
#print("Removing previous modpack and EUI leftovers...") print("Removing previous modpack and EUI leftovers...")
#if os.path.isdir(modpack_path): if os.path.isdir(modpack_path):
# shutil.rmtree(modpack_path) shutil.rmtree(modpack_path)
#if os.path.isdir(eui_folder_path): if os.path.isdir(eui_folder_path):
# shutil.rmtree(eui_folder_path) shutil.rmtree(eui_folder_path)
## Compile EUI with colored unlocked citizens # Compile EUI with colored unlocked citizens
#if not os.path.isfile(modded_eui_zip_path): if not os.path.isfile(modded_eui_zip_path):
# print("Creating colored unlocked citizens EUI...") print("Creating colored unlocked citizens EUI...")
# subprocess.run([szip, 'x', vanilla_eui_zip_path], stdout=null, stderr=null) subprocess.run([szip, 'x', vanilla_eui_zip_path], stdout=null, stderr=null)
# for eui_cuc_file_name in eui_cuc_file_names: for eui_cuc_file_name in eui_cuc_file_names:
# eui_cuc_file = g(j(modsave_path, eui_cuc_file_name + "*"))[0] eui_cuc_file = g(j(modsave_path, eui_cuc_file_name + "*"))[0]
# orig_eui_file = g(j(eui_folder_path, "*", eui_cuc_file_name))[0] orig_eui_file = g(j(eui_folder_path, "*", eui_cuc_file_name))[0]
# shutil.move(orig_eui_file, orig_eui_file + ".orig") shutil.move(orig_eui_file, orig_eui_file + preservation_extension)
# shutil.copyfile(eui_cuc_file, orig_eui_file) shutil.copyfile(eui_cuc_file, orig_eui_file)
# subprocess.run([szip, 'a', modded_eui_zip, eui_folder_path], stdout=null, stderr=null) subprocess.run([szip, 'a', modded_eui_zip, eui_folder_path], stdout=null, stderr=null)
#else: else:
# # Unzip EUI # Unzip EUI
# print("Unzipping EUI...") print("Unzipping EUI...")
# subprocess.run([szip, 'x', modded_eui_zip_path], stdout=null, stderr=null) subprocess.run([szip, 'x', modded_eui_zip_path], stdout=null, stderr=null)
## Stop here if only EUI should be converted # Stop here if only EUI should be converted
#if eui_only: if eui_only:
# quit() quit()
## Unzip modpack zip # Unzip modpack zip
#print("Unzipping Modpack...") print("Unzipping Modpack...")
#subprocess.run([szip, 'x', j(vanilla_packs_path, modpack_zip)], stdout=null, stderr=null) subprocess.run([szip, 'x', j(vanilla_packs_path, modpack_zip)], stdout=null, stderr=null)
# Get vanilla UI files # Get vanilla UI files
...@@ -175,24 +175,24 @@ globbed = g(base_ui_files, recursive=True) ...@@ -175,24 +175,24 @@ globbed = g(base_ui_files, recursive=True)
globbed.extend(g(gnk_ui_files, recursive=True)) globbed.extend(g(gnk_ui_files, recursive=True))
globbed.extend(g(bnw_ui_files, recursive=True)) globbed.extend(g(bnw_ui_files, recursive=True))
for file in globbed: for file in globbed:
file_name = get_file_name(file) file_name = p.basename(file)
if not file_name in ui_files: if not file_name in ui_files:
vanilla_ui_files.append(file_name) vanilla_ui_file_names.append(file_name)
# Manage mod files # Manage mod files
print("Managing mod's files:") print("Managing mod's files:")
for mod_file in g(mod_files, recursive = True): for mod_file in g(mod_files, recursive = True):
mod_file_name = get_file_name(mod_file) mod_file_name = p.basename(mod_file)
mod_file_short_path = mod_file.removeprefix(mods_path + os.sep) mod_file_short_path = mod_file.removeprefix(mods_path + os.sep)
# IGE UI compat file # IGE UI compat file
if mod_file_name == ige_compat_file_name: if mod_file_name == ige_compat_file_name:
print("\tProviding IGE-EUI-compat...") print("\tProviding IGE-EUI-compat...")
#shutil.move(mod_file, mod_file + ".orig") shutil.move(mod_file, mod_file + preservation_extension)
#shutil.copyfile(g(j(modsave_path, ige_compat_file_name + "*"))[0], mod_file) shutil.copyfile(g(j(modsave_path, ige_compat_file_name + "*"))[0], mod_file)
# Delete UI overwrite duplicates # Delete UI overwrite duplicates
elif mod_file_name in vanilla_ui_files: elif mod_file_name in vanilla_ui_file_names:
print("\tRemoving overwriting file \"{}\"...".format(mod_file_short_path)) print("\tRemoving overwriting file \"{}\"...".format(mod_file_short_path))
#os.remove(mod_file) os.remove(mod_file)
# Get unit panel addon files # Get unit panel addon files
else: else:
with open(mod_file, 'r') as file: with open(mod_file, 'r') as file:
...@@ -200,56 +200,64 @@ for mod_file in g(mod_files, recursive = True): ...@@ -200,56 +200,64 @@ for mod_file in g(mod_files, recursive = True):
for line in lines: for line in lines:
if unit_panel_tag in line: if unit_panel_tag in line:
print("\tDetecting unit panel addon in file \"{}\"...".format(mod_file_short_path)) print("\tDetecting unit panel addon in file \"{}\"...".format(mod_file_short_path))
unit_panel_files.append(mod_file_name) unit_panel_addon_file_names.append(mod_file_name)
break break
## Delete useless desktop.ini (Thanks True...) # Delete useless desktop.ini (Thanks True...)
#ini_files = re.sub(r"\.\w+$", ".ini", mod_files) ini_files = re.sub(r"\.\w+$", ".ini", mod_files)
#for ini_file in g(ini_files, recursive = True): for ini_file in g(ini_files, recursive = True):
# ini_file_name = get_file_name(ini_file) ini_file_name = p.basename(ini_file)
# if ini_file_name == "desktop.ini": if ini_file_name == "desktop.ini":
# print("Removing useless desktop.ini (Thanks True)...") print("Removing useless desktop.ini (Thanks True)...")
# os.remove(mod_file) os.remove(mod_file)
## Get stuff from UI files # Get stuff from UI files
#for ui_file in g(ui_files): for ui_file in g(ui_files):
# ui_file_name = get_file_name(ui_file) ui_file_name = p.basename(ui_file)
# print("Getting tags from " + ui_file_name + "...") print("Getting tags from modpack UI's " + ui_file_name + "...")
# load_tags[ui_file_name] = [] load_tags[ui_file_name] = []
# with open(ui_file, 'r') as file: with open(ui_file, 'r') as file:
# lines = file.readlines() lines = file.readlines()
# for line in lines: for line in lines:
# if line.startswith(load_tag): if line.startswith(load_tag):
# load_tags[ui_file_name].append(line) load_tags[ui_file_name].append(line)
## Insert stuff into EUI files # Insert stuff into EUI files
#for eui_file in g(eui_files): for eui_file in g(eui_files):
# eui_file_name = get_file_name(eui_file) eui_file_name = p.basename(eui_file)
# # Base UI files # Base UI files
# if eui_file_name in load_tags.keys(): if eui_file_name in load_tags.keys():
# print("Writing tags to " + eui_file_name + "...") print("Writing tags to EUI's " + eui_file_name + "...")
# with open(eui_file, 'a') as file: with open(eui_file, 'a') as file:
# file.write('\n') file.write('\n')
# for load_tag in load_tags[eui_file_name]: for load_tag in load_tags[eui_file_name]:
# file.write(load_tag) file.write(load_tag)
# # Modcompat unit panel # Modcompat unit panel
# elif eui_file_name == unit_panel_file_name and unit_panel_modcompat_needed: elif eui_file_name == unit_panel_file_name and len(unit_panel_addon_file_names) > 0:
# print("Providing EUI-UnitPanel-Modcompat...") print("Providing EUI-UnitPanel-Modcompat...")
# shutil.move(eui_file, eui_file + ".orig") unit_panel_load_tags = ""
# shutil.copyfile(g(j(modsave_path, unit_panel_file_name + "*"))[0], eui_file) for unit_panel_addon_file_name in unit_panel_addon_file_names:
unit_panel_load_tags += "{}(\"{}\")\n".format(load_tag, p.splitext(unit_panel_addon_file_name)[0])
shutil.move(eui_file, eui_file + preservation_extension)
## Move EUI folder shutil.copyfile(g(j(modsave_path, unit_panel_file_name + "*"))[0], eui_file)
#print("Moving EUI folder...") with open(eui_file, 'r') as file:
#shutil.move(eui_folder_path, modpack_path) lines = file.readlines()
#print("Removing UI folder...") lines[lines.index(unit_panel_insert_marker)] = unit_panel_load_tags
#shutil.rmtree(ui_folder_path) with open(eui_file, 'w') as file:
file.write("".join(lines))
## Zip modpack folder
#print("Zipping Modpack...")
#subprocess.run([szip, 'a', modpack_name + "_EUI.7z", modpack_path], stdout=null, stderr=null) # Move EUI folder
print("Moving EUI folder...")
shutil.move(eui_folder_path, modpack_path)
print("Removing UI folder...")
shutil.rmtree(ui_folder_path)
# Zip modpack folder
print("Zipping Modpack...")
subprocess.run([szip, 'a', modpack_name + "_EUI.7z", modpack_path], stdout=null, stderr=null)
#Finishing up #Finishing up
quit() quit()
\ No newline at end of file
######################################################################## ########################################################################
# # # #
# © 2021 - MPL 2.0 - Rsge - v1.0.0 # # © 2021 - MPL 2.0 - Rsge - v1.0.1 #
# https://github.com/Rsge/Civ-V-EUI-Modpack-Converter # # https://github.com/Rsge/Civ-V-EUI-Modpack-Converter #
# # # #
# WINDOWS ONLY! # # WINDOWS ONLY! #
...@@ -10,6 +10,42 @@ ...@@ -10,6 +10,42 @@
# # # #
######################################################################## ########################################################################
#-----------------------------------------#
# Customize these according to your setup #
#-----------------------------------------#
# Vanilla EUI file (in vanilla_packs_folder)
vanilla_eui_zip = "!EUI.7z"
# CUC-version file name of EUI
modded_eui_zip = "!EUI_CUC.7z"
# Folder containing this scripts project folder and it's needed edited files
modsave_folder = "zzz_Modsaves"
# Folder containing the vanilla packs
vanilla_packs_folder = "zz_Vanilla_Versions"
#-------------------------------------------#
# Maybe you also need to add to these lists #
#-------------------------------------------#
# Mod files overwriting original UI files, conflicting with EUI
delete_file_names = ["CivilopediaScreen.lua",
"CityView.lua",
"TechTree.lua",
"TechButtonInclude.lua"]
# Mod files adding new actions to units
unit_panel_modcompat_file_names = ["EvilSpiritsMission.lua",
"THTanukiMission.lua"]
#----------------------------------------------------#
# Don't change anything after here #
# [except if you know what you're doing of cause ;)] #
#----------------------------------------------------#
# Imports # Imports
import os import os
from os.path import join as j from os.path import join as j
...@@ -18,17 +54,12 @@ import subprocess ...@@ -18,17 +54,12 @@ import subprocess
import shutil import shutil
import re import re
# Change to base DLC directory
os.chdir("../..")
## Global Values ## Global Values
print("Configuring variables...") print("Configuring variables...")
# Names # Names
# Customize these according to your setup #
vanilla_eui_zip = "!EUI.7z" # Vanilla EUI file (in vanilla_packs_folder)
modded_eui_zip = "!EUI_CUC.7z" # CUC-version file name of EUI
modsave_folder = "zzz_Modsaves" # Folder containing this scripts project folder and it's needed edited files
vanilla_packs_folder = "zz_Vanilla_Versions" # Folder containing the vanilla packs
# Ignore these #
modpack_folder_name = "MP_MODSPACK" modpack_folder_name = "MP_MODSPACK"
eui_cuc_file_names = ["CityBannerManager.lua", eui_cuc_file_names = ["CityBannerManager.lua",
"CityView.lua", "CityView.lua",
...@@ -36,23 +67,7 @@ eui_cuc_file_names = ["CityBannerManager.lua", ...@@ -36,23 +67,7 @@ eui_cuc_file_names = ["CityBannerManager.lua",
load_tag = "ContextPtr:LoadNewContext" load_tag = "ContextPtr:LoadNewContext"
unit_panel_file_name = "UnitPanel.lua" unit_panel_file_name = "UnitPanel.lua"
ige_compat_file_name = "IGE_Window.lua" ige_compat_file_name = "IGE_Window.lua"
# Maybe you also need to add to these lists #
delete_file_names = ["CivilopediaScreen.lua", # Mod files overwriting original UI files, conflicting with EUI
"CityView.lua",
"TechTree.lua",
"TechButtonInclude.lua",
unit_panel_file_name]
unit_panel_modcompat_file_names = ["EvilSpiritsMission.lua", # Mod files adding new actions to units
"THTanukiMission.lua"]
# Don't change from here [if you don't really know what you're doing that is of cause ;)] #
# This only runs with 7zip. If you want to use WinRar you'll have to change the methods yourself - or just download 7zip =P
szip = r"C:\Program Files\7-Zip\7z.exe"
# Paths # Paths
# Change to base DLC directory
os.chdir("../..")
base_path = os.getcwd() base_path = os.getcwd()
modsave_path = j(base_path, modsave_folder) modsave_path = j(base_path, modsave_folder)
modpack_path = j(base_path, modpack_folder_name) modpack_path = j(base_path, modpack_folder_name)
...@@ -60,11 +75,14 @@ vanilla_packs_path = j(base_path, vanilla_packs_folder) ...@@ -60,11 +75,14 @@ vanilla_packs_path = j(base_path, vanilla_packs_folder)
ui_path = j(modpack_path, "UI") ui_path = j(modpack_path, "UI")
eui_path = j(base_path, "UI_bc1") eui_path = j(base_path, "UI_bc1")
# Files # Files
file_ext = "*.lua"
base_eui_zip_path = j(vanilla_packs_path, vanilla_eui_zip) base_eui_zip_path = j(vanilla_packs_path, vanilla_eui_zip)
modded_eui_zip_path = j(base_path, modded_eui_zip) modded_eui_zip_path = j(base_path, modded_eui_zip)
mod_files = j(modpack_path, "Mods", "**", "*.lua") mod_files = j(modpack_path, "Mods", "**", file_ext)
ui_files = j(ui_path, "*.lua") ui_files = j(ui_path, file_ext)
eui_files = j(eui_path, "*", "*.lua") eui_files = j(eui_path, "*", file_ext)
# This only runs with 7zip. If you want to use WinRar you'll have to change the methods yourself - or just download 7zip =P
szip = r"C:\Program Files\7-Zip\7z.exe"
# Global Variables # Global Variables
load_tags = {} load_tags = {}
...@@ -72,6 +90,12 @@ unit_panel_modcompat_needed = False ...@@ -72,6 +90,12 @@ unit_panel_modcompat_needed = False
null = open(os.devnull, 'w') null = open(os.devnull, 'w')
eui_only = False eui_only = False
# Quitting function
def quit():
null.close()
print("Done.\n")
input("Press Enter to exit. . .")
exit(0)
# Get modpack zip # Get modpack zip
while True: while True:
...@@ -113,9 +137,7 @@ elif not eui_only: ...@@ -113,9 +137,7 @@ elif not eui_only:
if eui_only: if eui_only:
if os.path.isdir(eui_path): if os.path.isdir(eui_path):
shutil.rmtree(eui_path) shutil.rmtree(eui_path)
null.close() quit()
print("Done.\n")
exit(0)
# Unzip modpack zip # Unzip modpack zip
...@@ -158,14 +180,10 @@ for ini_file in g(ini_files, recursive = True): ...@@ -158,14 +180,10 @@ for ini_file in g(ini_files, recursive = True):
for ui_file in g(ui_files): for ui_file in g(ui_files):
with open(ui_file, 'r') as file: with open(ui_file, 'r') as file:
lines = file.readlines() lines = file.readlines()
ui_file_path = ui_file.split(os.sep) ui_file_path = ui_file.split(os.sep)
ui_file_name = ui_file_path[len(ui_file_path) - 1] ui_file_name = ui_file_path[len(ui_file_path) - 1]
print("Getting tags from " + ui_file_name + "...") print("Getting tags from " + ui_file_name + "...")
load_tags[ui_file_name] = [] load_tags[ui_file_name] = []
for line in lines: for line in lines:
if line.startswith(load_tag): if line.startswith(load_tag):
load_tags[ui_file_name].append(line) load_tags[ui_file_name].append(line)
...@@ -174,7 +192,6 @@ for ui_file in g(ui_files): ...@@ -174,7 +192,6 @@ for ui_file in g(ui_files):
for eui_file in g(eui_files): for eui_file in g(eui_files):
eui_file_path = eui_file.split(os.sep) eui_file_path = eui_file.split(os.sep)
eui_file_name = eui_file_path[len(eui_file_path) - 1] eui_file_name = eui_file_path[len(eui_file_path) - 1]
# Base UI files # Base UI files
if eui_file_name in load_tags.keys(): if eui_file_name in load_tags.keys():
print("Writing tags to " + eui_file_name + "...") print("Writing tags to " + eui_file_name + "...")
...@@ -199,12 +216,5 @@ shutil.rmtree(ui_path) ...@@ -199,12 +216,5 @@ shutil.rmtree(ui_path)
print("Zipping Modpack...") print("Zipping Modpack...")
subprocess.run([szip, 'a', modpack_name + "_EUI.7z", modpack_path], stdout=null, stderr=null) subprocess.run([szip, 'a', modpack_name + "_EUI.7z", modpack_path], stdout=null, stderr=null)
## Move modpack folder
#print("Moving Modspack folder")
#shutil.move(modpack_path, j(base_path, modpack_folder_name))
#Finishing up #Finishing up
null.close() quit()
print("Done.\n") \ No newline at end of file
input("Press Enter to exit. . .")
exit(0)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment