Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Specified variable values
- $SourceFolder = "C:\Program Files (x86)\Steam\steamapps\common\Red Dead Redemption 2\lml\WickedHorseMan\Textures\FirearmCosmetics" # Folder with source files
- $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
- # Define path to the log file and XML file in the same folder as the text file
- $LogFolder = Split-Path $TextFilePath
- $LogFile = Join-Path $LogFolder "log.log" # Use .log extension
- $XmlFileName = Join-Path $LogFolder "EasyInstall.xml"
- # Clear old log (ignore errors if the file doesn't exist)
- if (Test-Path $LogFile) {
- Clear-Content $LogFile
- }
- # Read content of the text file into an array of strings
- $TextFileContent = Get-Content $TextFilePath
- # Get a list of all files in the folder and subfolders
- $FilesInFolder = Get-ChildItem -Path $SourceFolder -File -Recurse
- # Create XML file
- $XmlDocument = New-Object System.Xml.XmlDocument
- # Create root element
- $RootElement = $XmlDocument.CreateElement("EasyInstall")
- $XmlDocument.AppendChild($RootElement)
- # Add Name element (folder name)
- $NameElement = $XmlDocument.CreateElement("Name")
- $NameElement.InnerText = (Get-Item $SourceFolder).Name
- $RootElement.AppendChild($NameElement)
- # Add Author element
- $AuthorElement = $XmlDocument.CreateElement("Author")
- $AuthorElement.InnerText = "werwolf969"
- $RootElement.AppendChild($AuthorElement)
- # Add Version element
- $VersionElement = $XmlDocument.CreateElement("Version")
- $VersionElement.InnerText = "1.0"
- $RootElement.AppendChild($VersionElement)
- # Create Resources section
- $ResourcesElement = $XmlDocument.CreateElement("Resources")
- $RootElement.AppendChild($ResourcesElement)
- # Create Resource section
- $ResourceElement = $XmlDocument.CreateElement("Resource")
- $ResourcesElement.AppendChild($ResourceElement)
- # Function to convert path with mappings
- function Convert-FilePath {
- param ([string]$FilePath)
- # Archive and mount point mappings
- $Mapping = @{
- "common_0.rpf" = "common:/"
- "movies_0.rpf" = "common:/"
- "anim_0.rpf" = "platform:/"
- "data_0.rpf" = "platform:/"
- "rowpack_0.rpf" = "platform:/"
- "hd_0.rpf" = "platform:/"
- "levels_0.rpf" = "platform:/"
- "levels_1.rpf" = "platform:/"
- "levels_2.rpf" = "platform:/"
- "levels_3.rpf" = "platform:/"
- "levels_4.rpf" = "platform:/"
- "levels_5.rpf" = "platform:/"
- "levels_6.rpf" = "platform:/"
- "levels_7.rpf" = "platform:/"
- "packs_0.rpf" = "platform:/"
- "packs_1.rpf" = "platform:/"
- "textures_0.rpf" = "platform:/"
- "textures_1.rpf" = "platform:/"
- "shaders_x64.rpf" = "common:/"
- "update_2.rpf" = "update:/"
- "update_3.rpf" = "update:/"
- "update_4.rpf" = "update:/"
- "update_1.rpf" = "update:/"
- "audio_rel.rpf" = "audio:/"
- "dlc.rpf" = "extra:/"
- "dlcpacks:/dlc_content_extra/dlc.rpf" = "extra:/"
- "dlcpacks:/mp001/dlc.rpf" = "extra:/"
- "dlcpacks:/mp003/dlc.rpf" = "extra:/"
- "dlcpacks:/mp004/dlc.rpf" = "extra:/"
- "dlcpacks:/mp005/dlc.rpf" = "extra:/"
- "dlcpacks:/mp006/dlc.rpf" = "extra:/"
- "dlcpacks:/mp007/dlc.rpf" = "extra:/"
- "dlcpacks:/mp008/dlc.rpf" = "extra:/"
- "dlcpacks:/mp009/dlc.rpf" = "extra:/"
- "dlcpacks:/opt001/dlc.rpf" = "extra:/"
- "dlcpacks:/patchpack_mp001/dlc.rpf" = "extra:/"
- "dlcpacks:/patchpack_mp003/dlc.rpf" = "extra:/"
- "dlcpacks:/patchpack_mp006/dlc.rpf" = "extra:/"
- "dlcpacks:/patchpack001/dlc.rpf" = "extra:/"
- "dlcpacks:/patchpack002/dlc.rpf" = "extra:/"
- "dlcpacks:/patchpack003/dlc.rpf" = "extra:/"
- "dlcpacks:/patchpack004/dlc.rpf" = "extra:/"
- "dlcpacks:/patchpack005/dlc.rpf" = "extra:/"
- "dlcpacks:/patchpack006/dlc.rpf" = "extra:/"
- "dlcpacks:/patchpack007/dlc.rpf" = "extra:/"
- "dlcpacks:/patchpack008/dlc.rpf" = "extra:/"
- "dlcpacks:/patchpack009/dlc.rpf" = "extra:/"
- "dlcpacks:/row_patchpack002/dlc.rpf" = "extra:/"
- "dlcpacks:/row_patchpack005/dlc.rpf" = "extra:/"
- "dlcpacks:/row_patchpack008/dlc.rpf" = "extra:/"
- # Add other mappings here
- }
- # Split the path into elements
- $PathParts = $FilePath -split '\\'
- # Determine the mount point based on the archive name
- foreach ($part in $PathParts) {
- if ($Mapping.ContainsKey($part)) {
- $MountPoint = $Mapping[$part]
- # Remove everything after the .rpf archive (keep only the necessary part of the path)
- $RemainingPath = ($PathParts -join '/') -replace "^.+?/$part", ''
- $RemainingPath = $RemainingPath.TrimStart('/') # Remove extra slash at the beginning
- return "$MountPoint$RemainingPath"
- }
- }
- return $FilePath # If no mapping is found, return the original path
- }
- # Convert paths and add FileReplacement
- foreach ($line in $TextFileContent) {
- # Determine the file and its name
- $FileName = [System.IO.Path]::GetFileName($line)
- if (!$FileName) {
- # Skip lines that don't contain a file
- continue
- }
- # Check for file existence in the source folder or its subfolders
- $MatchingFile = $FilesInFolder | Where-Object { $_.Name -eq $FileName } | Select-Object -First 1
- if ($MatchingFile) {
- # Convert path
- $TransformedPath = Convert-FilePath -FilePath $line
- # Name of the source folder
- $RelativeFilePath = $MatchingFile.FullName.Substring($SourceFolder.Length + 1) -replace '\\', '/' # Path relative to the source folder
- $RelativeFilePath = $RelativeFilePath.TrimStart('/') # Remove extra slash at the beginning
- # Create FileReplacement element
- $FileReplacementElement = $XmlDocument.CreateElement("FileReplacement")
- # Fill in the GamePath element
- $GamePathElement = $XmlDocument.CreateElement("GamePath")
- $GamePathElement.InnerText = "$TransformedPath"
- $FileReplacementElement.AppendChild($GamePathElement)
- # Fill in the FilePath element
- $FilePathElement = $XmlDocument.CreateElement("FilePath")
- $FilePathElement.InnerText = $RelativeFilePath
- $FileReplacementElement.AppendChild($FilePathElement)
- # Add to the resource
- $ResourceElement.AppendChild($FileReplacementElement)
- } else {
- # Write to log and output to console if file is missing
- $LogEntry = "File not found: $FileName"
- Add-Content -Path $LogFile -Value $LogEntry
- Write-Host $LogEntry
- }
- }
- # Save XML file in the same folder as the text file
- $XmlDocument.Save($XmlFileName)
- # Remove duplicates by GamePath and FilePath pairs
- $UniquePairs = @{}
- $NewResourceElement = $XmlDocument.CreateElement("Resource") # Create a new Resource element
- foreach ($resource in $XmlDocument.SelectNodes("//Resource/FileReplacement")) {
- $GamePath = $resource.SelectSingleNode("GamePath").InnerText
- $FilePath = $resource.SelectSingleNode("FilePath").InnerText
- $Key = "$GamePath|$FilePath" # Unique key based on GamePath and FilePath pairs
- if (-not $UniquePairs.ContainsKey($Key)) {
- $UniquePairs[$Key] = $resource
- $NewResourceElement.AppendChild($resource.Clone()) # Clone resource for the new element
- }
- }
- # Clear old resource and add new one with unique pairs
- $ResourcesElement.RemoveAll()
- $ResourcesElement.AppendChild($NewResourceElement)
- # Save final XML file
- $XmlDocument.Save($XmlFileName)
- # Load XML file into an object
- $XmlDocument = [xml](Get-Content $XmlFileName)
- # Remove ".rpf" text from all XML nodes
- $XmlDocument.SelectNodes("//*[contains(text(), '.rpf')]") | ForEach-Object {
- $_.InnerXml = $_.InnerXml -replace '\.rpf', ''
- }
- # Save final XML file
- $XmlDocument.Save($XmlFileName)
- Write-Host "XML file successfully created: $XmlFileName"
Advertisement
Add Comment
Please, Sign In to add comment