Guest User

LML Install.xml generator

a guest
Nov 2nd, 2024
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Specified variable values
  2. $SourceFolder = "Path\to\folder\where\install.xml\will\be\saved"   # Folder with source files
  3. $TextFilePath = "Path\to\file\with\gamepaths\to\files\that\we\replacing\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 -ErrorAction SilentlyContinue
  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 Convert-FilePath {
  52.     param ([string]$FilePath)
  53.  
  54.     # Archive and mount point mappings
  55.     $Mapping = @{
  56.         "common_0.rpf" = "common:/"
  57.         "movies_0.rpf" = "common:/"
  58.         "anim_0.rpf" = "platform:/"
  59.         "data_0.rpf" = "platform:/"
  60.         "rowpack_0.rpf" = "platform:/"
  61.         "hd_0.rpf" = "platform:/"
  62.         "levels_0.rpf" = "platform:/"
  63.         "levels_1.rpf" = "platform:/"
  64.         "levels_2.rpf" = "platform:/"
  65.         "levels_3.rpf" = "platform:/"
  66.         "levels_4.rpf" = "platform:/"
  67.         "levels_5.rpf" = "platform:/"
  68.         "levels_6.rpf" = "platform:/"
  69.         "levels_7.rpf" = "platform:/"
  70.         "packs_0.rpf" = "platform:/"
  71.         "packs_1.rpf" = "platform:/"
  72.         "textures_0.rpf" = "platform:/"
  73.         "textures_1.rpf" = "platform:/"
  74.         "shaders_x64.rpf" = "common:/"
  75.         "update_2.rpf" = "update:/"
  76.         "update_3.rpf" = "update:/"
  77.         "update_4.rpf" = "update:/"
  78.         "update_1.rpf" = "update:/"
  79.         "audio_rel.rpf" = "audio:/"
  80.         "dlc_content_extra\dlc.rpf" = "dlc_content_extra:/"
  81.         "mp001\dlc.rpf" = "dlc_mp001:/"
  82.         "mp003\dlc.rpf" = "dlc_mp003:/"
  83.         "mp004\dlc.rpf" = "dlc_mp004:/"
  84.         "mp005\dlc.rpf" = "dlc_mp005:/"
  85.         "mp006\dlc.rpf" = "dlc_mp006:/"
  86.         "mp007\dlc.rpf" = "dlc_mp007:/"
  87.         "mp008\dlc.rpf" = "dlc_mp008:/"
  88.         "mp009\dlc.rpf" = "dlc_mp009:/"
  89.         "opt001\dlc.rpf" = "dlc_opt001:/"
  90.         "patchpack_mp001\dlc.rpf" = "dlc_patchpack_mp001:/"
  91.         "patchpack_mp003\dlc.rpf" = "dlc_patchpack_mp003:/"
  92.         "patchpack_mp006\dlc.rpf" = "dlc_patchpack_mp006:/"
  93.         "patchpack001\dlc.rpf" = "dlc_patchPack001:/"
  94.         "patchpack002\dlc.rpf" = "dlc_patchPack002:/"
  95.         "patchpack003\dlc.rpf" = "dlc_patchPack003:/"
  96.         "patchpack004\dlc.rpf" = "dlc_patchPack004:/"
  97.         "patchpack005\dlc.rpf" = "dlc_patchPack005:/"
  98.         "patchpack006\dlc.rpf" = "dlc_patchPack006:/"
  99.         "patchpack007\dlc.rpf" = "dlc_patchPack007:/"
  100.         "patchpack008\dlc.rpf" = "dlc_patchPack008:/"
  101.         "patchpack009\dlc.rpf" = "dlc_patchPack009:/"
  102.         "row_patchpack002\dlc.rpf" = "dlc_row_patchpack002:/"
  103.         "row_patchpack005\dlc.rpf" = "dlc_row_patchpack005:/"
  104.         "row_patchpack008\dlc.rpf" = "dlc_row_patchpack008:/"
  105.         # Add other mappings here
  106.     }
  107.     # Search for the longest matching key in the path
  108.     foreach ($key in $Mapping.Keys | Sort-Object Length -Descending) {
  109.         # Check if the key matches part of the FilePath
  110.         if ($FilePath -like "*$key*") {
  111.             # Get the mount point
  112.             $MountPoint = $Mapping[$key]
  113.            
  114.             # Remove everything up to and including the key from the path
  115.             $RemainingPath = $FilePath -replace ".*$([regex]::Escape($key))", ""
  116.             $RemainingPath = $RemainingPath -replace '\\', '/' # Convert to forward slashes
  117.            
  118.             # Concatenate the mount point and remaining path, ensuring no double slashes
  119.             if ($MountPoint -like "*/" -and $RemainingPath -like "/*") {
  120.                 $RemainingPath = $RemainingPath.TrimStart('/')
  121.             }
  122.            
  123.             return "$MountPoint$RemainingPath"
  124.         }
  125.     }
  126.  
  127.     return $FilePath # If no mapping is found, return the original path
  128. }
  129.  
  130. # Convert paths and add unique FileReplacement elements
  131. $UniquePairs = @{}
  132. foreach ($line in $TextFileContent) {
  133.     $FileName = [System.IO.Path]::GetFileName($line)
  134.     if (!$FileName) { continue }
  135.  
  136.     $MatchingFile = $FilesInFolder | Where-Object { $_.Name -eq $FileName } | Select-Object -First 1
  137.  
  138.     if ($MatchingFile) {
  139.         $TransformedPath = Convert-FilePath -FilePath $line
  140.         $RelativeFilePath = ($MatchingFile.FullName.Substring($SourceFolder.Length + 1) -replace '\\', '/').TrimStart('/')
  141.  
  142.         $Key = "$TransformedPath|$RelativeFilePath"
  143.         if (-not $UniquePairs.ContainsKey($Key)) {
  144.             $UniquePairs[$Key] = $true
  145.             $FileReplacementElement = $XmlDocument.CreateElement("FileReplacement")
  146.  
  147.             $GamePathElement = $XmlDocument.CreateElement("GamePath")
  148.             $GamePathElement.InnerText = $TransformedPath
  149.             $FileReplacementElement.AppendChild($GamePathElement)
  150.  
  151.             $FilePathElement = $XmlDocument.CreateElement("FilePath")
  152.             $FilePathElement.InnerText = $RelativeFilePath
  153.             $FileReplacementElement.AppendChild($FilePathElement)
  154.  
  155.             $ResourceElement.AppendChild($FileReplacementElement)
  156.         }
  157.     } else {
  158.         $LogEntry = "File not found: $FileName"
  159.         Add-Content -Path $LogFile -Value $LogEntry -Encoding UTF8
  160.         Write-Host $LogEntry
  161.     }
  162. }
  163.  
  164. $XmlDocument.Save($XmlFileName)
  165. Write-Host "XML file successfully created: $XmlFileName"
  166.  
  167. # Remove ".rpf" from GamePath and FilePath values
  168. foreach ($fileReplacement in $XmlDocument.SelectNodes("//FileReplacement")) {
  169.     $gamePathNode = $fileReplacement.SelectSingleNode("GamePath")
  170.     if ($gamePathNode) {
  171.         $gamePathNode.InnerText = $gamePathNode.InnerText -replace '\.rpf', ''
  172.     }
  173.  
  174.     $filePathNode = $fileReplacement.SelectSingleNode("FilePath")
  175.     if ($filePathNode) {
  176.         $filePathNode.InnerText = $filePathNode.InnerText -replace '\.rpf', ''
  177.     }
  178. }
  179.  
  180. # Save the modified XML file
  181. $XmlDocument.Save($XmlFileName)
  182. Write-Host "XML file successfully updated to remove '.rpf': $XmlFileName"
  183.  
Advertisement
Add Comment
Please, Sign In to add comment