File size: 4,673 Bytes
9bf50c9
 
 
8619b8b
9bf50c9
 
 
8619b8b
 
 
9bf50c9
8619b8b
 
9bf50c9
 
 
 
 
 
 
 
8619b8b
 
 
 
 
9bf50c9
 
8619b8b
9bf50c9
8619b8b
 
 
 
 
 
9bf50c9
8619b8b
 
 
 
 
 
9bf50c9
8619b8b
 
 
 
 
 
 
9bf50c9
 
8619b8b
 
 
 
9bf50c9
8619b8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9bf50c9
8619b8b
 
 
 
 
 
9bf50c9
 
 
 
 
 
 
8619b8b
 
 
 
 
 
9bf50c9
8619b8b
 
9bf50c9
 
 
 
 
 
 
8619b8b
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Recursively search and replace through *.json workflows
# Preserves original Created and Modified timestamps
# Targets specific "video\ paths starting with a literal double quote

# --- Configuration ---
$rootPath = "C:\Data\ComfyUser\default\workflows\"
$preserveTimestamps = $true 

$replacements = [ordered]@{
    # 1.1 distilled LTX-2.3
    "ltx-2.3-22b-distilled-lora-384.safetensors" = "ltx-2.3-22b-distilled-lora-384-1.1.safetensors"  
    "ltx-2.3-22b-distilled.safetensors" = "ltx-2.3-22b-distilled-1.1.safetensors"

    # Directory migrations
    "<lora:wan\\" = "<lora:wan2.2\\"
    "<lora:video\\" = "<lora:wan2.1\\"
    
    # Specific targeted replacement: matches literal "video\ 
    '"video\\' = '"wan2.1\\'     
    '"wan\\' = '"wan2.2\\'

    # Transformer (dev)
    "LTXVideo\v2\ltx-2.3-22b-dev_transformer_only_fp8_scaled.safetensors"   = "ltx-2-3-22b-dev_transformer_only_fp8_input_scaled.safetensors"
    "LTXVideo\\v2\\ltx-2.3-22b-dev_transformer_only_fp8_scaled.safetensors" = "ltx-2-3-22b-dev_transformer_only_fp8_input_scaled.safetensors"
    
    # LoRA (path cleanup)
    "LTX\LTX-2\ltx-2.3-22b-distilled-lora-384.safetensors"                  = "ltx-2.3-22b-distilled-lora-384-1.1.safetensors"
    "LTX\\LTX-2\\ltx-2.3-22b-distilled-lora-384.safetensors"                = "ltx-2.3-22b-distilled-lora-384-1.1.safetensors"

    # Spatial upscaler
    "ltx-2.3-spatial-upscaler-x2-1.0.safetensors"                           = "ltx-2.3-spatial-upscaler-x2-1.1.safetensors"

    # Distilled transformer
    "LTXVideo\v2\ltx-2.3-22b-distilled_transformer_only_fp8_scaled.safetensors"   = "ltx-2.3-22b-distilled_transformer_only_fp8_input_scaled_v3.safetensors"
    "LTXVideo\\v2\\ltx-2.3-22b-distilled_transformer_only_fp8_scaled.safetensors" = "ltx-2.3-22b-distilled_transformer_only_fp8_input_scaled_v3.safetensors"

    # VAE cleanup
    "vae_approx\taeltx2_3.safetensors"  = "taeltx2_3.safetensors"
    "vae_approx\\taeltx2_3.safetensors" = "taeltx2_3.safetensors"

    # Gemma
    "gemma_3_12B_it_fpmixed.safetensors" = "gemma_3_12B_it_fp8_scaled.safetensors"

    # Additional VAE replacements
    "LTX23_audio_vae_bf16_KJ.safetensors" = "LTX23_audio_vae_bf16.safetensors"
    "LTX23_video_vae_bf16_KJ.safetensors" = "LTX23_video_vae_bf16.safetensors"
}

Add-Type -AssemblyName Microsoft.VisualBasic

function Get-LiteralMatchCount {
    param ([string]$Text, [string]$Search)
    if ([string]::IsNullOrEmpty($Search)) { return 0 }
    $count = 0
    $startIndex = 0
    while ($true) {
        $index = $Text.IndexOf($Search, $startIndex, [System.StringComparison]::Ordinal)
        if ($index -lt 0) { break }
        $count += 1
        $startIndex = $index + $Search.Length
    }
    return $count
}

$files = Get-ChildItem -Path $rootPath -Recurse -Filter *.json -File

foreach ($file in $files) {
    $content = Get-Content -Path $file.FullName -Raw -Encoding UTF8
    $originalContent = $content
    $changed = $false

    foreach ($oldValue in $replacements.Keys) {
        $newValue = $replacements[$oldValue]
        $count = Get-LiteralMatchCount -Text $content -Search $oldValue

        if ($count -gt 0) {
            $content = $content.Replace($oldValue, $newValue)
            Write-Host "[$($file.Name)] Replaced $count occurrence(s): $oldValue -> $newValue"
            $changed = $true
        }
    }

    if ($changed -and $content -ne $originalContent) {
        try {
            # Capture timestamps
            if ($preserveTimestamps) {
                $origCreated = $file.CreationTime
                $origModified = $file.LastWriteTime
            }

            # Move to Recycle Bin
            [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile(
                $file.FullName,
                [Microsoft.VisualBasic.FileIO.UIOption]::OnlyErrorDialogs,
                [Microsoft.VisualBasic.FileIO.RecycleOption]::SendToRecycleBin
            )

            # Write new file
            Set-Content -Path $file.FullName -Value $content -Encoding UTF8

            # Restore timestamps
            if ($preserveTimestamps) {
                $newFile = Get-Item -Path $file.FullName
                $newFile.CreationTime = $origCreated
                $newFile.LastWriteTime = $origModified
            }

            Write-Host "Updated: $($file.FullName)"
            Write-Host ""
        }
        catch {
            Write-Host "ERROR updating: $($file.FullName)"
            Write-Host "    $($_.Exception.Message)"
            Write-Host ""
        }
    }
}

Write-Host "Done."