# ============================================================================= # LoWOptimizer - lancador online # # Uso (cole no PowerShell): # irm lowopt.dev | iex # (endereco completo, se o dominio estiver fora do ar: # irm https://raw.githubusercontent.com/LoWzadas/LoWOptimizer/main/iniciar.ps1 | iex ) # # O que faz: # 1. baixa a versao mais nova do projeto (zip do GitHub); # 2. instala em %LOCALAPPDATA%\LoWOptimizer\app, preservando backup e logs; # 3. abre o programa como administrador. # # Arquivo propositalmente sem acentos: ele roda via "iex" e precisa ser ASCII puro. # ============================================================================= & { # ---- repositorio de onde o programa e baixado $Repo = 'LoWzadas/LoWOptimizer' $Branch = 'main' $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' $base = Join-Path $env:LOCALAPPDATA 'LoWOptimizer' $app = Join-Path $base 'app' $tmp = Join-Path $base 'tmp' $salvo = Join-Path $base 'dados-salvos' $zip = Join-Path $env:TEMP ('LoWOptimizer-' + [guid]::NewGuid().ToString('N') + '.zip') # para testes locais: $env:WOP_ZIP_URL aponta para outro zip; $env:WOP_NAO_ABRIR=1 nao abre o programa $url = "https://github.com/$Repo/archive/refs/heads/$Branch.zip" if ($env:WOP_ZIP_URL) { $url = $env:WOP_ZIP_URL } try { Write-Host '' Write-Host ' LoWOptimizer' -ForegroundColor Cyan Write-Host ' ---------------------' -ForegroundColor DarkGray if ($Repo -like 'SEU-USUARIO/*' -and -not $env:WOP_ZIP_URL) { throw 'O lancador ainda nao foi configurado: troque SEU-USUARIO pelo usuario do GitHub no iniciar.ps1.' } [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 Write-Host ' Baixando a versao mais nova...' Invoke-WebRequest -Uri $url -OutFile $zip -UseBasicParsing if (-not (Test-Path -LiteralPath $base)) { New-Item -ItemType Directory -Path $base -Force | Out-Null } # guarda backup.json e logs antes de trocar a versao $dados = Join-Path $app 'dados' if (Test-Path -LiteralPath $dados) { if (Test-Path -LiteralPath $salvo) { Remove-Item -LiteralPath $salvo -Recurse -Force } Move-Item -LiteralPath $dados -Destination $salvo -Force } Write-Host ' Instalando...' if (Test-Path -LiteralPath $tmp) { Remove-Item -LiteralPath $tmp -Recurse -Force } Expand-Archive -LiteralPath $zip -DestinationPath $tmp -Force # o zip do GitHub traz uma pasta raiz (ex.: LoWOptimizer-main); aceita tambem zip sem pasta raiz $raiz = $tmp $itens = @(Get-ChildItem -LiteralPath $tmp) if ($itens.Count -eq 1 -and $itens[0].PSIsContainer) { $raiz = $itens[0].FullName } if (-not (Test-Path -LiteralPath (Join-Path $raiz 'LoWOptimizer.ps1'))) { throw 'O pacote baixado nao contem LoWOptimizer.ps1.' } if (Test-Path -LiteralPath $app) { Remove-Item -LiteralPath $app -Recurse -Force } Move-Item -LiteralPath $raiz -Destination $app -Force if (Test-Path -LiteralPath $salvo) { Move-Item -LiteralPath $salvo -Destination $dados -Force } # arquivos baixados da internet vem marcados; desbloqueia para o PowerShell nao reclamar Get-ChildItem -LiteralPath $app -Recurse -File | Unblock-File -ErrorAction SilentlyContinue Write-Host (' Instalado em ' + $app) -ForegroundColor DarkGray if ($env:WOP_NAO_ABRIR -eq '1') { Write-Host ' (teste: programa nao aberto)'; return } Write-Host ' Abrindo (aceite o aviso de administrador)...' -ForegroundColor Green $ps = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe' Start-Process -FilePath $ps -Verb RunAs -ArgumentList @( '-NoProfile', '-ExecutionPolicy', 'Bypass', '-STA', '-WindowStyle', 'Hidden', '-File', ('"' + (Join-Path $app 'LoWOptimizer.ps1') + '"')) } catch { Write-Host '' Write-Host (' ERRO: ' + $_.Exception.Message) -ForegroundColor Red # se algo falhou no meio, devolve os dados guardados if ((Test-Path -LiteralPath $salvo) -and -not (Test-Path -LiteralPath (Join-Path $app 'dados'))) { if (-not (Test-Path -LiteralPath $app)) { New-Item -ItemType Directory -Path $app -Force | Out-Null } Move-Item -LiteralPath $salvo -Destination (Join-Path $app 'dados') -Force } } finally { if (Test-Path -LiteralPath $zip) { Remove-Item -LiteralPath $zip -Force -ErrorAction SilentlyContinue } if (Test-Path -LiteralPath $tmp) { Remove-Item -LiteralPath $tmp -Recurse -Force -ErrorAction SilentlyContinue } } }