Guest User

LML Install.xml generator

a guest
Nov 1st, 2024
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Specified variable values
  2. $SourceFolder = "C:\Program Files (x86)\Steam\steamapps\common\Red Dead Redemption 2\lml\WickedHorseMan\Textures\FirearmCosmetics"   # Folder with source files
  3. $TextFilePath = "C:\Program Files (x86)\Steam\steamapps\common\Red Dead Redemption 2\lml\WickedHorseMan\Textures\FirearmCosmetics\source_paths.txt"   # Path to the text file with paths
  4.  
  5. # Define path to the log file and XML file in the same folder as the text file
  6. $LogFolder = Split-Path $TextFilePath
  7. $LogFile = Join-Path $LogFolder "log.log"   # Use .log extension
  8. $XmlFileName = Join-Path $LogFolder "EasyInstall.xml"
  9.  
  10. # Clear old log (ignore errors if the file doesn't exist)
  11. if (Test-Path $LogFile) {
  12.     Clear-Content $LogFile
  13. }
  14.  
  15. # Read content of the text file into an array of strings
  16. $TextFileContent = Get-Content $TextFilePath
  17.  
  18. # Get a list of all files in the folder and subfolders
  19. $FilesInFolder = Get-ChildItem -Path $SourceFolder -File -Recurse
  20.  
  21. # Create XML file
  22. $XmlDocument = New-Object System.Xml.XmlDocument
  23.  
  24. # Create root element
  25. $RootElement = $XmlDocument.CreateElement("EasyInstall")
  26. $XmlDocument.AppendChild($RootElement)
  27.  
  28. # Add Name element (folder name)
  29. $NameElement = $XmlDocument.CreateElement("Name")
  30. $NameElement.InnerText = (Get-Item $SourceFolder).Name
  31. $RootElement.AppendChild($NameElement)
  32.  
  33. # Add Author element
  34. $AuthorElement = $XmlDocument.CreateElement("Author")
  35. $AuthorElement.InnerText = "werwolf969"
  36. $RootElement.AppendChild($AuthorElement)
  37.  
  38. # Add Version element
  39. $VersionElement = $XmlDocument.CreateElement("Version")
  40. $VersionElement.InnerText = "1.0"
  41. $RootElement.AppendChild($VersionElement)
  42.  
  43. # Create Resources section
  44. $ResourcesElement = $XmlDocument.CreateElement("Resources")
  45. $RootElement.AppendChild($ResourcesElement)
  46.  
  47. # Create Resource section
  48. $ResourceElement = $XmlDocument.CreateElement("Resource")
  49. $ResourcesElement.AppendChild($ResourceElement)
  50.  
  51. # Function to convert path with mappings
  52. function Convert-FilePath {
  53.     param ([string]$FilePath)
  54.  
  55.     # Archive and mount point mappings
  56.     $Mapping = @{
  57.         "common_0.rpf" = "common:/"
  58.         "movies_0.rpf" = "common:/"
  59.         "anim_0.rpf" = "platform:/"
  60.         "data_0.rpf" = "platform:/"
  61.         "rowpack_0.rpf" = "platform:/"
  62.         "hd_0.rpf" = "platform:/"
  63.         "levels_0.rpf" = "platform:/"
  64.         "levels_1.rpf" = "platform:/"
  65.         "levels_2.rpf" = "platform:/"
  66.         "levels_3.rpf" = "platform:/"
  67.         "levels_4.rpf" = "platform:/"
  68.         "levels_5.rpf" = "platform:/"
  69.         "levels_6.rpf" = "platform:/"
  70.         "levels_7.rpf" = "platform:/"
  71.         "packs_0.rpf" = "platform:/"
  72.         "packs_1.rpf" = "platform:/"
  73.         "textures_0.rpf" = "platform:/"
  74.         "textures_1.rpf" = "platform:/"
  75.         "shaders_x64.rpf" = "common:/"
  76.         "update_2.rpf" = "update:/"
  77.         "update_3.rpf" = "update:/"
  78.         "update_4.rpf" = "update:/"
  79.         "update_1.rpf" = "update:/"
  80.         "audio_rel.rpf" = "audio:/"
  81.         "dlc.rpf" = "extra:/"
  82.         "dlcpacks:/dlc_content_extra/dlc.rpf" = "extra:/"
  83.         "dlcpacks:/mp001/dlc.rpf" = "extra:/"
  84.         "dlcpacks:/mp003/dlc.rpf" = "extra:/"
  85.         "dlcpacks:/mp004/dlc.rpf" = "extra:/"
  86.         "dlcpacks:/mp005/dlc.rpf" = "extra:/"
  87.         "dlcpacks:/mp006/dlc.rpf" = "extra:/"
  88.         "dlcpacks:/mp007/dlc.rpf" = "extra:/"
  89.         "dlcpacks:/mp008/dlc.rpf" = "extra:/"
  90.         "dlcpacks:/mp009/dlc.rpf" = "extra:/"
  91.         "dlcpacks:/opt001/dlc.rpf" = "extra:/"
  92.         "dlcpacks:/patchpack_mp001/dlc.rpf" = "extra:/"
  93.         "dlcpacks:/patchpack_mp003/dlc.rpf" = "extra:/"
  94.         "dlcpacks:/patchpack_mp006/dlc.rpf" = "extra:/"
  95.         "dlcpacks:/patchpack001/dlc.rpf" = "extra:/"
  96.         "dlcpacks:/patchpack002/dlc.rpf" = "extra:/"
  97.         "dlcpacks:/patchpack003/dlc.rpf" = "extra:/"
  98.         "dlcpacks:/patchpack004/dlc.rpf" = "extra:/"
  99.         "dlcpacks:/patchpack005/dlc.rpf" = "extra:/"
  100.         "dlcpacks:/patchpack006/dlc.rpf" = "extra:/"
  101.         "dlcpacks:/patchpack007/dlc.rpf" = "extra:/"
  102.         "dlcpacks:/patchpack008/dlc.rpf" = "extra:/"
  103.         "dlcpacks:/patchpack009/dlc.rpf" = "extra:/"
  104.         "dlcpacks:/row_patchpack002/dlc.rpf" = "extra:/"
  105.         "dlcpacks:/row_patchpack005/dlc.rpf" = "extra:/"
  106.         "dlcpacks:/row_patchpack008/dlc.rpf" = "extra:/"
  107.         # Add other mappings here
  108.     }
  109.  
  110.     # Split the path into elements
  111.     $PathParts = $FilePath -split '\\'
  112.    
  113.     # Determine the mount point based on the archive name
  114.     foreach ($part in $PathParts) {
  115.         if ($Mapping.ContainsKey($part)) {
  116.             $MountPoint = $Mapping[$part]
  117.             # Remove everything after the .rpf archive (keep only the necessary part of the path)
  118.             $RemainingPath = ($PathParts -join '/') -replace "^.+?/$part", ''
  119.             $RemainingPath = $RemainingPath.TrimStart('/')  # Remove extra slash at the beginning
  120.             return "$MountPoint$RemainingPath"
  121.         }
  122.     }
  123.    
  124.     return $FilePath # If no mapping is found, return the original path
  125. }
  126.  
  127. # Convert paths and add FileReplacement
  128. foreach ($line in $TextFileContent) {
  129.     # Determine the file and its name
  130.     $FileName = [System.IO.Path]::GetFileName($line)
  131.     if (!$FileName) {
  132.         # Skip lines that don't contain a file
  133.         continue
  134.     }
  135.  
  136.     # Check for file existence in the source folder or its subfolders
  137.     $MatchingFile = $FilesInFolder | Where-Object { $_.Name -eq $FileName } | Select-Object -First 1
  138.  
  139.     if ($MatchingFile) {
  140.         # Convert path
  141.         $TransformedPath = Convert-FilePath -FilePath $line
  142.  
  143.         # Name of the source folder
  144.         $RelativeFilePath = $MatchingFile.FullName.Substring($SourceFolder.Length + 1) -replace '\\', '/' # Path relative to the source folder
  145.         $RelativeFilePath = $RelativeFilePath.TrimStart('/')  # Remove extra slash at the beginning
  146.  
  147.         # Create FileReplacement element
  148.         $FileReplacementElement = $XmlDocument.CreateElement("FileReplacement")
  149.  
  150.         # Fill in the GamePath element
  151.         $GamePathElement = $XmlDocument.CreateElement("GamePath")
  152.         $GamePathElement.InnerText = "$TransformedPath"
  153.         $FileReplacementElement.AppendChild($GamePathElement)
  154.  
  155.         # Fill in the FilePath element
  156.         $FilePathElement = $XmlDocument.CreateElement("FilePath")
  157.         $FilePathElement.InnerText = $RelativeFilePath
  158.         $FileReplacementElement.AppendChild($FilePathElement)
  159.  
  160.         # Add to the resource
  161.         $ResourceElement.AppendChild($FileReplacementElement)
  162.     } else {
  163.         # Write to log and output to console if file is missing
  164.         $LogEntry = "File not found: $FileName"
  165.         Add-Content -Path $LogFile -Value $LogEntry
  166.         Write-Host $LogEntry
  167.     }
  168. }
  169.  
  170. # Save XML file in the same folder as the text file
  171. $XmlDocument.Save($XmlFileName)
  172.  
  173. # Remove duplicates by GamePath and FilePath pairs
  174. $UniquePairs = @{}
  175. $NewResourceElement = $XmlDocument.CreateElement("Resource") # Create a new Resource element
  176.  
  177. foreach ($resource in $XmlDocument.SelectNodes("//Resource/FileReplacement")) {
  178.     $GamePath = $resource.SelectSingleNode("GamePath").InnerText
  179.     $FilePath = $resource.SelectSingleNode("FilePath").InnerText
  180.  
  181.     $Key = "$GamePath|$FilePath" # Unique key based on GamePath and FilePath pairs
  182.  
  183.     if (-not $UniquePairs.ContainsKey($Key)) {
  184.         $UniquePairs[$Key] = $resource
  185.         $NewResourceElement.AppendChild($resource.Clone()) # Clone resource for the new element
  186.     }
  187. }
  188.  
  189. # Clear old resource and add new one with unique pairs
  190. $ResourcesElement.RemoveAll()
  191. $ResourcesElement.AppendChild($NewResourceElement)
  192.  
  193. # Save final XML file
  194. $XmlDocument.Save($XmlFileName)
  195.  
  196. # Load XML file into an object
  197. $XmlDocument = [xml](Get-Content $XmlFileName)
  198.  
  199. # Remove ".rpf" text from all XML nodes
  200. $XmlDocument.SelectNodes("//*[contains(text(), '.rpf')]") | ForEach-Object {
  201.     $_.InnerXml = $_.InnerXml -replace '\.rpf', ''
  202. }
  203.  
  204. # Save final XML file
  205. $XmlDocument.Save($XmlFileName)
  206.  
  207. Write-Host "XML file successfully created: $XmlFileName"
  208.  
Advertisement
Add Comment
Please, Sign In to add comment