import os
import re
import subprocess
import shutil
import time
import pyautogui
mdx_files = [f for f in os.listdir() if f.endswith('.mdx')]
processes = []
for i, mdx_file in enumerate(mdx_files):
p = subprocess.Popen(['MdlxConv.exe', mdx_file])
processes.append(p)
if i == len(mdx_files) - 1:
# start timer when processing the last mdx file
time.sleep(1)
# Get a list of all currently open windows
windows = pyautogui.getAllWindows()
# Loop through all windows
for window in windows:
# Check if window name matches any of the specified names
if window.title in ["Assertion failure", "Conversion Result", "Warcraft III Mdlx Converter 1.03"]:
# Close the window
window.close()
time.sleep(2)
# run code to create texture list
root_dir = os.getcwd()
output_file = os.path.join(root_dir, 'TextureList.txt')
unique_images = set()
with open(output_file, 'w') as outfile:
for root, dirs, files in os.walk(root_dir):
for filename in files:
if filename.endswith('.mdl'):
filepath = os.path.join(root, filename)
with open(filepath, 'r') as infile:
mdl_contents = infile.read()
pattern = r'Image\s+"([^"]+)"'
matches = re.findall(pattern, mdl_contents)
for match in matches:
if match not in unique_images:
unique_images.add(match)
outfile.write(f'{match}\n')
# wait for all MdlxConv processes to finish
for p in processes:
p.wait()
# create new directories if they don't exist
if not os.path.exists('mdl files new directory'):
os.mkdir('mdl files new directory')
if not os.path.exists('mdx files new directory'):
os.mkdir('mdx files new directory')
# move files to new directories
for f in os.listdir():
if f.endswith('.mdl') or f.endswith('.mdx'):
# check if file is currently being used by a process
file_used = False
for p in processes:
if p.poll() is None and f in p.args:
file_used = True
break
if not file_used:
if f.endswith('.mdl'):
shutil.move(f, 'mdl files new directory')
elif f.endswith('.mdx'):
shutil.move(f, 'mdx files new directory')