Advertisement
Guest User

Untitled

a guest
Apr 21st, 2024
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. import os
  2. import xml.etree.ElementTree as ET
  3. import xml.dom.minidom
  4.  
  5. #This script requires all modded files to be in a folder matching their rockstar counter-part
  6. #Change the levels/rdr3/props/vegetation/ and hd_0/hd/levels/rdr3/props/vegetation/ to wherever it needs to be
  7.  
  8. # Define the directory and xml file paths
  9. directory_path = "D:\\Games\\Red Dead Redemption 2\\MODWORKINGFOLDER\\###DONE\\Mega Pack\\lml\\Upscaled Textures\\Upscaled Documents"
  10. xml_file_path = "D:\\Games\\Red Dead Redemption 2\\MODWORKINGFOLDER\\###DONE\\install replace.xml"
  11. output_file_path = os.path.join(directory_path, "install python.xml")
  12.  
  13. # Parse the XML file
  14. tree = ET.parse(xml_file_path)
  15. root = tree.getroot()
  16.  
  17. # Find the 'Resources' tag
  18. resources_tag = root.find('Resources')
  19.  
  20. # Traverse the directory structure
  21. for folder_name, subfolders, filenames in os.walk(directory_path):
  22. # Get the relative folder name
  23. relative_folder_name = os.path.relpath(folder_name, directory_path)
  24.  
  25. for filename in filenames:
  26. # Skip .py, .xml, and .txt files
  27. if filename.endswith(('.py', '.xml', '.txt', '.bak')):
  28. continue
  29.  
  30. # Create a new 'Resource' tag
  31. resource_tag = ET.SubElement(resources_tag, 'Resource')
  32.  
  33. # Create a new 'FileReplacement' tag
  34. file_replacement_tag = ET.SubElement(resource_tag, 'FileReplacement')
  35.  
  36. # Determine the 'GamePath' and 'FilePath' based on the folder name
  37. if relative_folder_name.startswith("hd"):
  38. game_path = f"platform:/hd/levels/rdr3/props/vegetation/{relative_folder_name[2:]}/{filename}" #old unused code for this instance
  39. file_path = f"{relative_folder_name[2:]}/{filename}"
  40. else:
  41. game_path = f"platform:textures/textures/ui/{relative_folder_name}/{filename}" #correct format??
  42. file_path = f"{relative_folder_name}/{filename}"
  43.  
  44. # Create the 'GamePath' and 'FilePath' tags
  45. game_path_tag = ET.SubElement(file_replacement_tag, 'GamePath')
  46. game_path_tag.text = game_path
  47. file_path_tag = ET.SubElement(file_replacement_tag, 'FilePath')
  48. file_path_tag.text = file_path
  49.  
  50. # Convert the ElementTree to a string
  51. xml_string = ET.tostring(root, encoding='utf-8')
  52.  
  53. # Parse the string to a minidom object
  54. dom = xml.dom.minidom.parseString(xml_string)
  55.  
  56. # Pretty print the XML to the output file
  57. with open(output_file_path, 'w') as f:
  58. f.write(dom.toprettyxml(indent=" "))
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement