File size: 5,053 Bytes
f459246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#Requires -RunAsAdministrator

<#

.SYNOPSIS

    A dedicated update script for the ComfyUI installation.

.DESCRIPTION

    This script performs a 'git pull' on the main ComfyUI repository,

    all custom nodes, and the workflow repository. It then updates all

    Python dependencies from any found 'requirements.txt' files.

    It is designed to be run from a subfolder.

#>

#===========================================================================
# SECTION 1: SCRIPT CONFIGURATION & HELPER FUNCTIONS
#===========================================================================

# === CORRECTION : Le script s'exécute depuis un sous-dossier, on cible donc le dossier parent ===
$InstallPath = (Split-Path -Path $PSScriptRoot -Parent)

$comfyPath = Join-Path $InstallPath "ComfyUI"
$customNodesPath = Join-Path $InstallPath "custom_nodes"
$workflowPath = Join-Path $InstallPath "user\default\workflows\UmeAiRT-Workflow"
$venvPython = Join-Path $comfyPath "venv\Scripts\python.exe"
$logPath = Join-Path $InstallPath "logs"
$logFile = Join-Path $logPath "update_log.txt"

if (-not (Test-Path $logPath)) { New-Item -ItemType Directory -Force -Path $logPath | Out-Null }

function Write-Log {
    param([string]$Message, [string]$Color = "White")
    $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    $formattedMessage = "[$timestamp] $Message"
    Write-Host $Message -ForegroundColor $Color
    Add-Content -Path $logFile -Value $formattedMessage
}

function Invoke-Git-Pull {
    param([string]$DirectoryPath)
    if (Test-Path (Join-Path $DirectoryPath ".git")) {
        # On utilise cmd.exe pour lancer git pull et rediriger la sortie vers le log
        $commandToRun = "git -C `"$DirectoryPath`" pull"
        $cmdArguments = "/C `"$commandToRun >> `"`"$logFile`"`" 2>&1`""
        try {
            Start-Process -FilePath "cmd.exe" -ArgumentList $cmdArguments -Wait -WindowStyle Hidden
        } catch {
            Write-Log "  - FAILED to run git pull in '$DirectoryPath'" -Color Red
        }
    } else {
        Write-Log "  - Skipping: Not a git repository." -Color Gray
    }
}

function Invoke-Pip-Install {
    param([string]$RequirementsPath)
    if (Test-Path $RequirementsPath) {
        Write-Log "  - Found requirements: $RequirementsPath. Updating..." -Color Cyan
        $tempLogFile = Join-Path $env:TEMP ([System.Guid]::NewGuid().ToString() + ".tmp")
        try {
            $commandToRun = "`"$venvPython`" -m pip install -r `"$RequirementsPath`""
            $cmdArguments = "/C `"$commandToRun > `"`"$tempLogFile`"`" 2>&1`""
            Start-Process -FilePath "cmd.exe" -ArgumentList $cmdArguments -Wait -WindowStyle Hidden
            if (Test-Path $tempLogFile) { $output = Get-Content $tempLogFile; if($output){ Add-Content -Path $logFile -Value $output } }
        } finally {
            if (Test-Path $tempLogFile) { Remove-Item $tempLogFile }
        }
    }
}

#===========================================================================
# SECTION 2: UPDATE PROCESS
#===========================================================================
Clear-Host
Write-Log "==============================================================================="
Write-Log "             Starting UmeAiRT ComfyUI Update Process" -Color Yellow
Write-Log "==============================================================================="

# --- 1. Update ComfyUI Core ---
Write-Log "`n[1/4] Updating ComfyUI Core..." -Color Green
Invoke-Git-Pull -DirectoryPath $comfyPath

# --- 2. Update Custom Nodes ---
Write-Log "`n[2/4] Updating Custom Nodes..." -Color Green
if (Test-Path $customNodesPath) {
    $nodeDirs = Get-ChildItem -Path $customNodesPath -Directory
    foreach ($dir in $nodeDirs) {
        Write-Log "  - Checking node: $($dir.Name)"
        Invoke-Git-Pull -DirectoryPath $dir.FullName
    }
} else {
    Write-Log "  - Custom nodes directory not found, skipping."
}


# --- 3. Update Workflows ---
Write-Log "`n[3/4] Updating UmeAiRT Workflows..." -Color Green
if (Test-Path $workflowPath) {
    Invoke-Git-Pull -DirectoryPath $workflowPath
} else {
    Write-Log "  - Workflow directory not found, skipping." -Color Gray
}

# --- 4. Update Python Dependencies ---
Write-Log "`n[4/4] Updating all Python dependencies..." -Color Green
Write-Log "  - Checking main ComfyUI requirements..."
Invoke-Pip-Install -RequirementsPath (Join-Path $comfyPath "requirements.txt")

Write-Log "  - Checking custom node requirements..."
if (Test-Path $customNodesPath) {
    foreach ($dir in (Get-ChildItem -Path $customNodesPath -Directory)) {
        Invoke-Pip-Install -RequirementsPath (Join-Path $dir.FullName "requirements.txt")
    }
}

Write-Log "==============================================================================="
Write-Log "Update process complete!" -Color Yellow
Write-Log "==============================================================================="
Read-Host "Press Enter to exit."