#Requires -RunAsAdministrator <# .SYNOPSIS Central de Manutenção e Downloads - RD ETI CORP .DESCRIPTION Faz o download sequencial de arquivos do Google Drive selecionados via CheckBox. .AUTHOR Ronaldo Mendonça | RD ETI CORP #> [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $Host.UI.RawUI.WindowTitle = "CENTRAL DE MANUTENÇÃO - RD ETI CORP" Clear-Host # ============================================================================ # VERIFICAÇÃO DE ELEVAÇÃO (ADMINISTRADOR - COMPATÍVEL COM WEB E LOCAL) # ============================================================================ if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Warning "Acesso negado. Elevando privilégios para Administrador..." Start-Sleep -Seconds 2 if ($PSCommandPath) { Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs } else { Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"irm https://getmaintenancefiles.rd.eti.br | iex`"" -Verb RunAs } exit } # ============================================================================ # DEFINIÇÃO DO DIRETÓRIO DE DESTINO # ============================================================================ $TargetDir = "C:\TI" # ============================================================================ # CATÁLOGO DE ARQUIVOS DO GOOGLE DRIVE # ============================================================================ $CatalogoArquivos = @( @{ Nome = "ADV.exe"; ID = "1uKZSpXYu2mC_zrs_86mC479_my4bcJ10" }, @{ Nome = "AE.exe"; ID = "1PJAjrBU06C8UBtC0iLh0FXUo3IyFUB9Y" }, @{ Nome = "Backup_Drivers.zip"; ID = "1M6ygKbOsWS0-bfm_a713EWvDbkd7_wuo" }, @{ Nome = "CCleaner.zip"; ID = "1CNzd8oAQ_nBRZYVZxl8Z_43xy7rYkNT2" }, @{ Nome = "config_oem_exe_spw.exe"; ID = "1eKjU6axvN9SsZXD0ALciwV9gmw2rfKUm" }, @{ Nome = "DiskGeniusPortable.zip"; ID = "1LnogWL1mGOzdkNrC3FTinAEPGAmwWSGG" }, @{ Nome = "Everest_Ultimate_AIDA64_Extreme.zip"; ID = "1oHtAWNtwIC8OKqAToRPgxkvdn4H6cqnk" }, @{ Nome = "Get-Navegadores.zip"; ID = "1F8PUp3ivemHNQ7BP9eRZ346aaHWddnIZ" }, @{ Nome = "HardDisk.zip"; ID = "1Cq38tEzW9srJucl7JPaa0OSjNE9faTli" }, @{ Nome = "Hasleo_Backup_Suite_Free.zip"; ID = "1PqA8TD1vuBzGbEX6tCwV9YbYo4qpBiXb" }, @{ Nome = "HDTune_Portable.zip"; ID = "1ifre2oQygbPD7GNPeMBlfVQJxnxz_wev" }, @{ Nome = "Inventarios.exe"; ID = "1zMzQnqEmFTfuHqLR68kGLc9Wjdc2Gbu2" }, @{ Nome = "IObitUnlockerPortable.zip"; ID = "1FBRXXzC5aimmbY2unju6OFeMNjY4KJev" }, @{ Nome = "KIT_SUPORTE_WATCHDOG.exe"; ID = "11qjSGIRzHklEQeYsNcLBQLJfHvsoEJlT" }, @{ Nome = "OEM_Configurator_2.0.zip"; ID = "1vnmrnU55WjZozfV6dcYWXmDZeLNp9CqJ" }, @{ Nome = "Office_2024_online.exe"; ID = "1rUI8XUE-yDGzbGjzTOJEgENWYq7nRFHI" }, @{ Nome = "Office_2024_x32_local.exe"; ID = "1U_CFY6HOCLheaAGgKTdOMYG4cbkN853n" }, @{ Nome = "Office_2024_x64_local.exe"; ID = "1J9ZSlSLrrsJ4-GgBRuSXKo-oaWsrOHwH" }, @{ Nome = "Otimizacao_Install_Apps.exe"; ID = "1PNWjugkUe96GdOvbKmECPnr9cGgCoaE0" }, @{ Nome = "PSD_codec.zip"; ID = "1ZlBtnsEwygwgRgPmFLXanMdSSEE9bPr2" }, @{ Nome = "RAM_Saver_Pro_23.12.zip"; ID = "14Uy5t9yjnWbKBRxPEq6Y2rwl7kRuoWmk" }, @{ Nome = "ReNamer.zip"; ID = "1i_VXVgU-CjB5jstHav3DXQkNnuCBibP3" }, @{ Nome = "resetar_shadow_defender.zip"; ID = "1kTNNJ__7kClVhPCdCj5e1OHSnCW2dXGQ" }, @{ Nome = "Resizer.zip"; ID = "1IkEl2QoI3Y383w-l119NyAbjRW-LUjpk" }, @{ Nome = "Revo.Uninstaller.Pro.5.3.4.zip"; ID = "1t0jb5eTZNpAEmQ-jc2jqTVakM-xvCIO2" }, @{ Nome = "Sayro_Digital.zip"; ID = "1xkwZLCgJqCPT0v1pA3omoRzTuto3xBBu" }, @{ Nome = "Serial.zip"; ID = "1RgZfCxWNjTbc6hkPjvZ73WTCB9f31OXB" }, @{ Nome = "Sounder.zip"; ID = "1VLAFJz-hr2-vnRCO7HRPEB_FEPiMaSjt" }, @{ Nome = "Tools.exe"; ID = "1GMTw4dYiTxVualPXWwukyuKn1GD30rxH" }, @{ Nome = "WIFI_REDE.exe"; ID = "1k6CgK_wUgJqMS2iJWbiAjxOKQbaBNIdk" } ) # ============================================================================ # FUNÇÃO DE DOWNLOAD BLINDADA (GOOGLE DRIVE) # ============================================================================ function Download-GoogleDriveFile { param( [string]$FileID, [string]$Destino ) $Url = "https://drive.usercontent.google.com/download?id=$FileID&export=download&confirm=t" $fileName = Split-Path $Destino -Leaf Write-Host "" Write-Host "==================================================" Write-Host "Arquivo: $fileName" Write-Host "==================================================" Write-Host "`n`n`n`n`n`n" $consoleTop = [Console]::CursorTop - 6 Add-Type -AssemblyName System.Net.Http $handler = New-Object System.Net.Http.HttpClientHandler $handler.AllowAutoRedirect = $true $client = [System.Net.Http.HttpClient]::new($handler) $client.Timeout = [System.Threading.Timeout]::InfiniteTimeSpan $totalBytes = $null $totalRead = 0L $buffer = New-Object byte[] (1MB) try { $fileStream = [System.IO.FileStream]::new($Destino, [System.IO.FileMode]::OpenOrCreate, [System.IO.FileAccess]::Write, [System.IO.FileShare]::None) if ($fileStream.Length -gt 0) { $fileStream.Position = $fileStream.Length $totalRead = $fileStream.Position } $downloading = $true $watch = [System.Diagnostics.Stopwatch]::StartNew() $lastUpdate = 0 while ($downloading) { try { $request = New-Object System.Net.Http.HttpRequestMessage([System.Net.Http.HttpMethod]::Get, $Url) if ($totalRead -gt 0) { $request.Headers.Range = New-Object System.Net.Http.Headers.RangeHeaderValue($totalRead, $null) } $response = $client.SendAsync($request, [System.Net.Http.HttpCompletionOption]::ResponseHeadersRead).Result $response.EnsureSuccessStatusCode() | Out-Null if ($null -eq $totalBytes) { if ($response.StatusCode -eq [System.Net.HttpStatusCode]::PartialContent) { $totalBytes = $totalRead + $response.Content.Headers.ContentLength } else { if ($totalRead -gt 0) { $fileStream.SetLength(0) $fileStream.Position = 0 $totalRead = 0 } $totalBytes = $response.Content.Headers.ContentLength } } $stream = $response.Content.ReadAsStreamAsync().Result $bytesRead = 1 while ($bytesRead -gt 0) { $bytesRead = $stream.Read($buffer, 0, $buffer.Length) if ($bytesRead -gt 0) { $fileStream.Write($buffer, 0, $bytesRead) $fileStream.Flush() $totalRead += $bytesRead $elapsed = $watch.Elapsed.TotalSeconds if ($elapsed - $lastUpdate -gt 0.2) { $lastUpdate = $elapsed $speed = $totalRead / $elapsed if ($totalBytes) { $percent = ($totalRead / $totalBytes) * 100 $remaining = ($totalBytes - $totalRead) / $speed [Console]::SetCursorPosition(0, $consoleTop) [Console]::WriteLine("Baixando: {0,-40}" -f $fileName) [Console]::WriteLine("Recebido.......: {0:N2} MB " -f ($totalRead / 1MB)) [Console]::WriteLine("Total..........: {0:N2} MB " -f ($totalBytes / 1MB)) [Console]::WriteLine("Velocidade.....: {0:N2} MB/s " -f ($speed / 1MB)) [Console]::WriteLine("Tempo restante.: {0:mm\:ss} " -f [TimeSpan]::FromSeconds($remaining)) [Console]::WriteLine("{0:N2}% concluído(s) " -f $percent) } } } } $stream.Close() $downloading = $false } catch { [Console]::SetCursorPosition(0, $consoleTop + 6) Write-Host "Falha na conexão! Tentando reconectar..." -ForegroundColor Red Start-Sleep -Seconds 5 } } $fileStream.Close() $client.Dispose() $watch.Stop() [Console]::SetCursorPosition(0, $consoleTop) [Console]::WriteLine("Baixando: {0,-40}" -f $fileName) [Console]::WriteLine("Recebido.......: {0:N2} MB " -f ($totalRead / 1MB)) [Console]::WriteLine("Total..........: {0:N2} MB " -f ($totalBytes / 1MB)) [Console]::WriteLine("100,00% concluído(s) ") [Console]::SetCursorPosition(0, $consoleTop + 6) Write-Host "Download de '$fileName' concluído com sucesso!" -ForegroundColor Green } catch { Write-Host "`n[ERRO CRÍTICO] Falha ao baixar '$fileName': $_" -ForegroundColor Red } } # ============================================================================ # INTERFACE GRÁFICA (FORMULÁRIO COM CHECKBOXES) # ============================================================================ Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing $form = New-Object System.Windows.Forms.Form $form.Text = "Central de Manutenção - RD ETI CORP" $form.Size = New-Object System.Drawing.Size(450, 400) $form.StartPosition = "CenterScreen" $form.FormBorderStyle = "FixedDialog" $form.MaximizeBox = $false # Ícone Nativo do Windows (Seta de Download do imageres.dll) $iconPath = "$env:windir\System32\imageres.dll" if (Test-Path $iconPath) { try { $iconExtracted = [System.Drawing.Icon]::ExtractAssociatedIcon($iconPath) $form.Icon = $iconExtracted } catch { try { $form.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon("$env:windir\System32\shell32.dll") } catch {} } } $lblTitle = New-Object System.Windows.Forms.Label $lblTitle.Text = "Selecione os arquivos que deseja baixar para '$TargetDir':" $lblTitle.Location = New-Object System.Drawing.Point(15, 15) $lblTitle.AutoSize = $true $lblTitle.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Bold) $form.Controls.Add($lblTitle) # Caixa de Seleção Múltipla (CheckedListBox) $checkedListBox = New-Object System.Windows.Forms.CheckedListBox $checkedListBox.Location = New-Object System.Drawing.Point(15, 45) $checkedListBox.Size = New-Object System.Drawing.Size(400, 240) $checkedListBox.CheckOnClick = $true # Preenche a lista com o catálogo foreach ($arquivo in $CatalogoArquivos) { $checkedListBox.Items.Add($arquivo.Nome) | Out-Null } $form.Controls.Add($checkedListBox) # Botão Baixar $btnBaixar = New-Object System.Windows.Forms.Button $btnBaixar.Text = "Baixar Selecionado(s)" $btnBaixar.Location = New-Object System.Drawing.Point(175, 310) $btnBaixar.Size = New-Object System.Drawing.Size(142, 35) $btnBaixar.BackColor = [System.Drawing.Color]::LightGreen $btnBaixar.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Bold) $btnBaixar.Add_Click({ if ($checkedListBox.CheckedItems.Count -eq 0) { [System.Windows.Forms.MessageBox]::Show("Por favor, selecione ao menos um arquivo para baixar.", "Aviso", 0, [System.Windows.Forms.MessageBoxIcon]::Warning) return } # === VERIFICAÇÃO E CRIAÇÃO DO DIRETÓRIO C:\TI AO CLICAR EM BAIXAR === try { if (-not (Test-Path $TargetDir)) { New-Item -ItemType Directory -Path $TargetDir -Force | Out-Null } } catch { [System.Windows.Forms.MessageBox]::Show("Não foi possível criar o diretório $TargetDir : $_", "Erro", 0, [System.Windows.Forms.MessageBoxIcon]::Error) return } $form.DialogResult = [System.Windows.Forms.DialogResult]::OK $form.Close() }) $form.Controls.Add($btnBaixar) # Botão Cancelar $btnCancelar = New-Object System.Windows.Forms.Button $btnCancelar.Text = "Cancelar" $btnCancelar.Location = New-Object System.Drawing.Point(325, 310) $btnCancelar.Size = New-Object System.Drawing.Size(90, 35) $btnCancelar.Add_Click({ $form.DialogResult = [System.Windows.Forms.DialogResult]::Cancel $form.Close() }) $form.Controls.Add($btnCancelar) $form.AcceptButton = $btnBaixar $form.CancelButton = $btnCancelar # Exibe o formulário $result = $form.ShowDialog() # ============================================================================ # LÓGICA DE DOWNLOAD SEQUENCIAL # ============================================================================ if ($result -eq [System.Windows.Forms.DialogResult]::OK) { Clear-Host Write-Host "Iniciando downloads na pasta: $TargetDir`n" -ForegroundColor Cyan $arquivosSelecionados = $checkedListBox.CheckedItems $total = $arquivosSelecionados.Count $contador = 1 foreach ($nomeArquivo in $arquivosSelecionados) { Write-Host "[$contador/$total] Processando..." -ForegroundColor Yellow # Encontra o ID correspondente ao nome no catálogo $arquivoInfo = $CatalogoArquivos | Where-Object { $_.Nome -eq $nomeArquivo } if ($arquivoInfo) { $CaminhoCompleto = Join-Path $TargetDir $arquivoInfo.Nome Download-GoogleDriveFile -FileID $arquivoInfo.ID -Destino $CaminhoCompleto } else { Write-Host "[ERRO] ID não encontrado para o arquivo: $nomeArquivo" -ForegroundColor Red } $contador++ Write-Host "--------------------------------------------------`n" -ForegroundColor DarkGray } Write-Host "Todos os downloads solicitados foram concluídos!" -ForegroundColor Green Write-Host "Verifique os arquivos na pasta: $TargetDir" -ForegroundColor Cyan Write-Host "" Write-Host "Pressione qualquer tecla para encerrar..." -ForegroundColor Yellow $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") } else { Write-Host "Operação cancelada pelo usuário." -ForegroundColor Yellow Start-Sleep -Seconds 2 }