-
This commit is contained in:
parent
b325d26281
commit
78cdb4a33b
1 changed files with 196 additions and 180 deletions
342
bleachbit.ps1
342
bleachbit.ps1
|
|
@ -1,189 +1,205 @@
|
||||||
# Define BleachBit cleaners
|
# BleachBit Script
|
||||||
$BleachBitCleaners = @(
|
# Downloads BleachBit portable, extracts it, and runs specified cleaners
|
||||||
"adobe_reader.cache", "adobe_reader.mru", "adobe_reader.tmp",
|
|
||||||
"amule.known_clients", "amule.known_files", "amule.logs", "amule.temp",
|
param(
|
||||||
|
# Array of cleaners to run - can be customized for different use cases
|
||||||
|
[string[]]$Cleaners = @(
|
||||||
|
"adobe_reader.cache",
|
||||||
|
"adobe_reader.mru",
|
||||||
|
"adobe_reader.tmp",
|
||||||
|
"amule.known_clients",
|
||||||
|
"amule.known_files",
|
||||||
|
"amule.logs",
|
||||||
|
"amule.temp",
|
||||||
"brave.cache",
|
"brave.cache",
|
||||||
"chromium.cache", "chromium.vacuum",
|
"chromium.cache",
|
||||||
"deepscan.backup", "deepscan.ds_store", "deepscan.thumbs_db", "deepscan.tmp",
|
"chromium.vacuum",
|
||||||
"deepscan.vim_swap_root", "deepscan.vim_swap_user",
|
"deepscan.backup",
|
||||||
"discord.cache", "discord.vacuum",
|
"deepscan.ds_store",
|
||||||
|
"deepscan.thumbs_db",
|
||||||
|
"deepscan.tmp",
|
||||||
|
"deepscan.vim_swap_root",
|
||||||
|
"deepscan.vim_swap_user",
|
||||||
|
"discord.cache",
|
||||||
|
"discord.vacuum",
|
||||||
"filezilla.mru",
|
"filezilla.mru",
|
||||||
"firefox.cache", "firefox.crash_reports", "firefox.url_history",
|
"firefox.cache",
|
||||||
"flash.cache", "flash.cookies",
|
"firefox.crash_reports",
|
||||||
|
"firefox.url_history",
|
||||||
|
"flash.cache",
|
||||||
|
"flash.cookies",
|
||||||
"gimp.tmp",
|
"gimp.tmp",
|
||||||
"google_chrome.cache", "google_earth.temporary_files", "google_toolbar.search_history",
|
"google_chrome.cache",
|
||||||
"gpodder.cache", "gpodder.logs",
|
"google_earth.temporary_files",
|
||||||
"hexchat.logs", "hippo_opensim_viewer.cache",
|
"google_toolbar.search_history",
|
||||||
|
"gpodder.cache",
|
||||||
|
"gpodder.logs",
|
||||||
|
"hexchat.logs",
|
||||||
|
"hippo_opensim_viewer.cache",
|
||||||
"internet_explorer.cache",
|
"internet_explorer.cache",
|
||||||
"java.cache",
|
"java.cache",
|
||||||
"libreoffice.history",
|
"libreoffice.history",
|
||||||
"microsoft_edge.cache", "microsoft_office.debug_logs", "microsoft_office.mru",
|
"microsoft_edge.cache",
|
||||||
"midnightcommander.history", "miro.cache", "miro.logs",
|
"microsoft_office.debug_logs",
|
||||||
"octave.history", "openofficeorg.cache", "openofficeorg.recent_documents",
|
"microsoft_office.mru",
|
||||||
|
"midnightcommander.history",
|
||||||
|
"miro.cache",
|
||||||
|
"miro.logs",
|
||||||
|
"octave.history",
|
||||||
|
"openofficeorg.cache",
|
||||||
|
"openofficeorg.recent_documents",
|
||||||
"opera.cache",
|
"opera.cache",
|
||||||
"paint.mru", "palemoon.cache", "pidgin.cache", "pidgin.logs",
|
"paint.mru",
|
||||||
|
"palemoon.cache",
|
||||||
|
"pidgin.cache",
|
||||||
|
"pidgin.logs",
|
||||||
"realplayer.logs",
|
"realplayer.logs",
|
||||||
"safari.cache", "screenlets.logs", "seamonkey.cache",
|
"safari.cache",
|
||||||
"secondlife_viewer.Cache", "secondlife_viewer.Logs", "silverlight.temp",
|
"screenlets.logs",
|
||||||
"skype.installers", "slack.cache", "smartftp.cache", "smartftp.log", "smartftp.mru",
|
"seamonkey.cache",
|
||||||
"system.recycle_bin", "system.tmp", "system.updates",
|
"secondlife_viewer.cache",
|
||||||
"teamviewer.logs", "teamviewer.mru", "thunderbird.cache",
|
"secondlife_viewer.logs",
|
||||||
"vim.history", "vlc.memory_dump", "vlc.mru", "vuze.cache", "vuze.logs", "vuze.stats", "vuze.temp",
|
"silverlight.temp",
|
||||||
"warzone2100.logs", "waterfox.cache", "winamp.mru",
|
"skype.installers",
|
||||||
"windows_defender.backup", "windows_defender.history", "windows_defender.logs",
|
"slack.cache",
|
||||||
"windows_defender.quarantine", "windows_defender.temp",
|
"smartftp.cache",
|
||||||
"windows_explorer.mru", "windows_explorer.run", "windows_explorer.search_history",
|
"smartftp.log",
|
||||||
"windows_explorer.shellbags", "windows_explorer.thumbnails",
|
"smartftp.mru",
|
||||||
"windows_media_player.cache", "windows_media_player.mru",
|
"system.recycle_bin",
|
||||||
"winrar.history", "winrar.temp", "winzip.mru", "wordpad.mru",
|
"system.tmp",
|
||||||
"yahoo_messenger.cache", "yahoo_messenger.chat_logs", "yahoo_messenger.logs",
|
"system.updates",
|
||||||
"zoom.cache", "zoom.logs"
|
"teamviewer.logs",
|
||||||
|
"teamviewer.mru",
|
||||||
|
"thunderbird.cache",
|
||||||
|
"vim.history",
|
||||||
|
"vlc.memory_dump",
|
||||||
|
"vlc.mru",
|
||||||
|
"vuze.cache",
|
||||||
|
"vuze.logs",
|
||||||
|
"vuze.stats",
|
||||||
|
"vuze.temp",
|
||||||
|
"warzone2100.logs",
|
||||||
|
"waterfox.cache",
|
||||||
|
"winamp.mru",
|
||||||
|
"windows_defender.backup",
|
||||||
|
"windows_defender.history",
|
||||||
|
"windows_defender.logs",
|
||||||
|
"windows_defender.quarantine",
|
||||||
|
"windows_defender.temp",
|
||||||
|
"windows_explorer.mru",
|
||||||
|
"windows_explorer.run",
|
||||||
|
"windows_explorer.search_history",
|
||||||
|
"windows_explorer.shellbags",
|
||||||
|
"windows_explorer.thumbnails",
|
||||||
|
"windows_media_player.cache",
|
||||||
|
"windows_media_player.mru",
|
||||||
|
"winrar.history",
|
||||||
|
"winrar.temp",
|
||||||
|
"winzip.mru",
|
||||||
|
"wordpad.mru",
|
||||||
|
"yahoo_messenger.cache",
|
||||||
|
"yahoo_messenger.chat_logs",
|
||||||
|
"yahoo_messenger.logs",
|
||||||
|
"zoom.cache",
|
||||||
|
"zoom.logs"
|
||||||
|
),
|
||||||
|
|
||||||
|
# Download URL - can be overridden for different versions
|
||||||
|
[string]$DownloadURL = "https://download.bleachbit.org/BleachBit-5.0.2-portable.zip",
|
||||||
|
|
||||||
|
# Installation path
|
||||||
|
[string]$InstallPath = "C:\Quest\BleachBit"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Stop Edge processes
|
# Set strict mode
|
||||||
Write-Log "Stopping Edge processes..." -Level "INFO"
|
Set-StrictMode -Version Latest
|
||||||
try {
|
$ErrorActionPreference = "Stop"
|
||||||
$EdgeProcesses = Get-Process -Name "*Edge*" -ErrorAction SilentlyContinue
|
|
||||||
if ($EdgeProcesses) {
|
|
||||||
$EdgeProcesses | Stop-Process -Force -ErrorAction Stop
|
|
||||||
Write-Log "Edge processes stopped successfully." -Level "INFO"
|
|
||||||
} else {
|
|
||||||
Write-Log "No Edge processes running." -Level "INFO"
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
Write-Log "Warning: Could not stop Edge processes: $($_.Exception.Message)" -Level "WARNING"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Download BleachBit Portable
|
|
||||||
Write-Log "Downloading BleachBit Portable..." -Level "INFO"
|
|
||||||
$BleachBitZip = "C:\Quest\BleachBitPortable.zip"
|
|
||||||
$BleachBitUrl = "https://download.bleachbit.org/BleachBit-5.0.2-portable.zip"
|
|
||||||
$MinFileSizeBytes = 10000000 # Minimum 10MB
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
# Remove old zip file if exists
|
# Create installation directory if it doesn't exist
|
||||||
if (Test-Path $BleachBitZip) {
|
if (-not (Test-Path $InstallPath)) {
|
||||||
Remove-Item $BleachBitZip -Force -ErrorAction Stop
|
New-Item -Path $InstallPath -ItemType Directory -Force | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download with retry logic
|
$zipPath = "$InstallPath\BleachBit-5.0.2-portable.zip"
|
||||||
$DownloadSuccess = $false
|
$exePath = "$InstallPath\bleachbit_console.exe"
|
||||||
$RetryCount = 0
|
|
||||||
$MaxRetries = 3
|
|
||||||
|
|
||||||
while (-not $DownloadSuccess -and $RetryCount -lt $MaxRetries) {
|
# Download BleachBit if not already present
|
||||||
$RetryCount++
|
if (-not (Test-Path $zipPath)) {
|
||||||
Write-Log "Download attempt $RetryCount of $MaxRetries..." -Level "INFO"
|
Write-Host "Downloading BleachBit..."
|
||||||
|
Invoke-WebRequest -Uri $DownloadURL -OutFile $zipPath -UseBasicParsing
|
||||||
try {
|
Write-Host "Download complete."
|
||||||
$WebClient = New-Object System.Net.WebClient
|
|
||||||
$WebClient.DownloadFile($BleachBitUrl, $BleachBitZip)
|
|
||||||
$DownloadSuccess = $true
|
|
||||||
Write-Log "Download completed." -Level "INFO"
|
|
||||||
} catch {
|
|
||||||
Write-Log "Download attempt failed: $($_.Exception.Message)" -Level "WARNING"
|
|
||||||
Start-Sleep -Seconds 5
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $DownloadSuccess) {
|
# Extract if executable doesn't exist
|
||||||
throw "Failed to download after $MaxRetries attempts"
|
if (-not (Test-Path $exePath)) {
|
||||||
|
Write-Host "Extracting BleachBit..."
|
||||||
|
|
||||||
|
# Use Expand-Archive for extraction (built-in since PowerShell 5.0)
|
||||||
|
$tempExtractPath = "$env:TEMP\BleachBit_Extract"
|
||||||
|
|
||||||
|
if (Test-Path $tempExtractPath) {
|
||||||
|
Remove-Item -Path $tempExtractPath -Recurse -Force
|
||||||
}
|
}
|
||||||
|
|
||||||
# Verify file size
|
Expand-Archive -Path $zipPath -DestinationPath $tempExtractPath -Force
|
||||||
$FileSize = (Get-Item $BleachBitZip).Length
|
|
||||||
Write-Log "Downloaded file size: $($FileSize / 1MB) MB" -Level "INFO"
|
|
||||||
|
|
||||||
if ($FileSize -lt $MinFileSizeBytes) {
|
# Move contents to install path
|
||||||
throw "Downloaded file is too small ($($FileSize / 1MB) MB). Expected at least $($MinFileSizeBytes / 1MB) MB."
|
$extractedContent = Get-ChildItem -Path $tempExtractPath -Recurse
|
||||||
}
|
|
||||||
|
|
||||||
$ScriptResult.bleachbit_cleanup.downloaded = $true
|
foreach ($item in $extractedContent) {
|
||||||
Write-Log "BleachBit Portable downloaded successfully." -Level "INFO"
|
$destination = $item.FullName.Replace($tempExtractPath, $InstallPath)
|
||||||
} catch {
|
|
||||||
$ErrorMsg = "Failed to download BleachBit Portable: $($_.Exception.Message)"
|
|
||||||
$ScriptResult.bleachbit_cleanup.errors += $ErrorMsg
|
|
||||||
Write-Log $ErrorMsg -Level "ERROR"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Extract BleachBit Portable
|
if ($item.PSIsContainer) {
|
||||||
if ($ScriptResult.bleachbit_cleanup.downloaded) {
|
if (-not (Test-Path $destination)) {
|
||||||
Write-Log "Extracting BleachBit Portable..." -Level "INFO"
|
New-Item -Path $destination -ItemType Directory -Force | Out-Null
|
||||||
$BleachBitDest = "C:\Quest"
|
|
||||||
|
|
||||||
try {
|
|
||||||
# Remove old extraction folder if exists
|
|
||||||
$OldBleachBitPath = Join-Path $BleachBitDest "BleachBit-Portable"
|
|
||||||
if (Test-Path $OldBleachBitPath) {
|
|
||||||
Remove-Item $OldBleachBitPath -Recurse -Force -ErrorAction Stop
|
|
||||||
}
|
|
||||||
|
|
||||||
# Extract using Expand-Archive
|
|
||||||
Expand-Archive -Path $BleachBitZip -DestinationPath $BleachBitDest -Force -ErrorAction Stop
|
|
||||||
$ScriptResult.bleachbit_cleanup.extracted = $true
|
|
||||||
Write-Log "BleachBit Portable extracted successfully." -Level "INFO"
|
|
||||||
|
|
||||||
# Remove zip file
|
|
||||||
Remove-Item $BleachBitZip -Force -ErrorAction SilentlyContinue
|
|
||||||
Write-Log "Removed temporary zip file." -Level "INFO"
|
|
||||||
} catch {
|
|
||||||
$ErrorMsg = "Failed to extract BleachBit Portable: $($_.Exception.Message)"
|
|
||||||
$ScriptResult.bleachbit_cleanup.errors += $ErrorMsg
|
|
||||||
Write-Log $ErrorMsg -Level "ERROR"
|
|
||||||
|
|
||||||
# Try alternative extraction using shell
|
|
||||||
try {
|
|
||||||
Write-Log "Trying alternative extraction method..." -Level "WARNING"
|
|
||||||
|
|
||||||
$shell = New-Object -ComObject Shell.Application
|
|
||||||
$zip = $shell.NameSpace($BleachBitZip)
|
|
||||||
$dest = $shell.NameSpace($BleachBitDest)
|
|
||||||
$dest.CopyHere($zip.items(), 16)
|
|
||||||
|
|
||||||
Start-Sleep -Seconds 5
|
|
||||||
$ScriptResult.bleachbit_cleanup.extracted = $true
|
|
||||||
Write-Log "BleachBit Portable extracted using shell method." -Level "INFO"
|
|
||||||
|
|
||||||
# Remove zip file
|
|
||||||
Remove-Item $BleachBitZip -Force -ErrorAction SilentlyContinue
|
|
||||||
} catch {
|
|
||||||
Write-Log "Alternative extraction also failed: $($_.Exception.Message)" -Level "ERROR"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run BleachBit cleanup
|
|
||||||
$BleachBitExe = "C:\Quest\BleachBit-Portable\bleachbit_console.exe"
|
|
||||||
if (Test-Path $BleachBitExe) {
|
|
||||||
Write-Log "Running BleachBit cleanup with $($BleachBitCleaners.Count) cleaners..." -Level "INFO"
|
|
||||||
|
|
||||||
try {
|
|
||||||
# Build cleaner arguments
|
|
||||||
$CleanerArgs = $BleachBitCleaners -join " "
|
|
||||||
|
|
||||||
# Run BleachBit
|
|
||||||
$BleachBitProcess = Start-Process -FilePath $BleachBitExe -ArgumentList "--clean $CleanerArgs" -NoNewWindow -Wait -PassThru -ErrorAction Stop
|
|
||||||
|
|
||||||
$ScriptResult.bleachbit_cleanup.cleaners_run = $BleachBitCleaners.Count
|
|
||||||
Write-Log "BleachBit cleanup completed. Exit code: $($BleachBitProcess.ExitCode)" -Level "INFO"
|
|
||||||
|
|
||||||
# Clean up BleachBit files after use
|
|
||||||
try {
|
|
||||||
Write-Log "Cleaning up BleachBit Portable files..." -Level "INFO"
|
|
||||||
Remove-Item "C:\Quest\BleachBit-Portable" -Recurse -Force -ErrorAction SilentlyContinue
|
|
||||||
Write-Log "BleachBit Portable files removed." -Level "INFO"
|
|
||||||
} catch {
|
|
||||||
Write-Log "Warning: Could not remove BleachBit files: $($_.Exception.Message)" -Level "WARNING"
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
$ErrorMsg = "Failed to run BleachBit cleanup: $($_.Exception.Message)"
|
|
||||||
$ScriptResult.bleachbit_cleanup.errors += $ErrorMsg
|
|
||||||
$ScriptResult.bleachbit_cleanup.cleaners_failed = $BleachBitCleaners.Count
|
|
||||||
Write-Log $ErrorMsg -Level "ERROR"
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Write-Log "BleachBit executable not found at: $BleachBitExe" -Level "ERROR"
|
$parentDir = Split-Path $destination -Parent
|
||||||
|
if (-not (Test-Path $parentDir)) {
|
||||||
|
New-Item -Path $parentDir -ItemType Directory -Force | Out-Null
|
||||||
|
}
|
||||||
|
Move-Item -Path $item.FullName -Destination $destination -Force
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Log "BleachBit cleanup section completed." -Level "INFO"
|
# Clean up temp extraction
|
||||||
"" | Out-File -FilePath $LogFile -Append -Encoding UTF8
|
Remove-Item -Path $tempExtractPath -Recurse -Force
|
||||||
|
Write-Host "Extraction complete."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify executable exists
|
||||||
|
if (-not (Test-Path $exePath)) {
|
||||||
|
throw "BleachBit executable not found at: $exePath"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Build the cleaner string
|
||||||
|
$cleanerString = $Cleaners -join " "
|
||||||
|
|
||||||
|
Write-Host "Running BleachBit cleaners..."
|
||||||
|
Write-Host "Cleaners: $cleanerString"
|
||||||
|
|
||||||
|
# Run BleachBit with the specified cleaners
|
||||||
|
$output = & $exePath --clean $cleanerString 2>&1
|
||||||
|
|
||||||
|
# Return success response as JSON
|
||||||
|
$result = @{
|
||||||
|
success = $true
|
||||||
|
cleaners = $Cleaners
|
||||||
|
output = $output
|
||||||
|
message = "BleachBit cleanup completed successfully"
|
||||||
|
} | ConvertTo-Json -Compress
|
||||||
|
|
||||||
|
Write-Output $result
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
# Return error response as JSON
|
||||||
|
$errorResult = @{
|
||||||
|
success = $false
|
||||||
|
error = $_.Exception.Message
|
||||||
|
cleaners = $Cleaners
|
||||||
|
} | ConvertTo-Json -Compress
|
||||||
|
|
||||||
|
Write-Error $errorResult
|
||||||
|
Write-Output $errorResult
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue