mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-12-17 17:55:28 +00:00
Update-WPFTweaksBlockAdobeNet (#3708)
* Update tweaks.json * Fix * Final Fix * Added comments to WPFTweaksBlockAdobeNet * Syntax change for WPFTweaksBlockAdobeNet * Removed double \ from WPFTweaksBlockAdobeNet * Added back double \ for WPFTweaksBlockAdobeNet * Syntax fix for WPFTweaksBlockAdobeNet * Syntax fix for WPFTweaksBlockAdobeNet again * Fix for WPFTweaksBlockAdobeNet * Merge branch 'ChrisTitusTech:main' into Update-WPFTweaksBlockAdobeNet
This commit is contained in:
parent
63221a7cb9
commit
067ec31086
@ -3050,102 +3050,26 @@
|
|||||||
"Order": "a021_",
|
"Order": "a021_",
|
||||||
"InvokeScript": [
|
"InvokeScript": [
|
||||||
"
|
"
|
||||||
# Define the URL of the remote HOSTS file and the local paths
|
$hostsUrl = \"https://github.com/Ruddernation-Designs/Adobe-URL-Block-List/raw/refs/heads/master/hosts\"
|
||||||
$remoteHostsUrl = \"https://raw.githubusercontent.com/Ruddernation-Designs/Adobe-URL-Block-List/master/hosts\"
|
$hosts = \"$env:SystemRoot\\System32\\drivers\\etc\\hosts\"
|
||||||
$localHostsPath = \"C:\\Windows\\System32\\drivers\\etc\\hosts\"
|
|
||||||
$tempHostsPath = \"C:\\Windows\\System32\\drivers\\etc\\temp_hosts\"
|
|
||||||
|
|
||||||
# Download the remote HOSTS file to a temporary location
|
Copy-Item $hosts \"$hosts.bak\"
|
||||||
try {
|
Invoke-WebRequest $hostsUrl -OutFile $hosts
|
||||||
Invoke-WebRequest -Uri $remoteHostsUrl -OutFile $tempHostsPath
|
ipconfig flushdns
|
||||||
Write-Output \"Downloaded the remote HOSTS file to a temporary location.\"
|
|
||||||
} catch {
|
|
||||||
Write-Error \"Failed to download the HOSTS file. Error: $_\"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if the AdobeNetBlock has already been started
|
Write-Host \"Added Adobe url block list from host file\"
|
||||||
try {
|
|
||||||
$localHostsContent = Get-Content $localHostsPath -ErrorAction Stop
|
|
||||||
|
|
||||||
# Check if AdobeNetBlock markers exist
|
|
||||||
$blockStartExists = $localHostsContent -like \"*#AdobeNetBlock-start*\"
|
|
||||||
if ($blockStartExists) {
|
|
||||||
Write-Output \"AdobeNetBlock-start already exists. Skipping addition of new block.\"
|
|
||||||
} else {
|
|
||||||
# Load the new block from the downloaded file
|
|
||||||
$newBlockContent = Get-Content $tempHostsPath -ErrorAction Stop
|
|
||||||
$newBlockContent = $newBlockContent | Where-Object { $_ -notmatch \"^\\s*#\" -and $_ -ne \"\" } # Exclude empty lines and comments
|
|
||||||
$newBlockHeader = \"#AdobeNetBlock-start\"
|
|
||||||
$newBlockFooter = \"#AdobeNetBlock-end\"
|
|
||||||
|
|
||||||
# Combine the contents, ensuring new block is properly formatted
|
|
||||||
$combinedContent = $localHostsContent + $newBlockHeader, $newBlockContent, $newBlockFooter | Out-String
|
|
||||||
|
|
||||||
# Write the combined content back to the original HOSTS file
|
|
||||||
$combinedContent | Set-Content $localHostsPath -Encoding ASCII
|
|
||||||
Write-Output \"Successfully added the AdobeNetBlock.\"
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
Write-Error \"Error during processing: $_\"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Clean up temporary file
|
|
||||||
Remove-Item $tempHostsPath -ErrorAction Ignore
|
|
||||||
|
|
||||||
# Flush the DNS resolver cache
|
|
||||||
try {
|
|
||||||
Invoke-Expression \"ipconfig /flushdns\"
|
|
||||||
Write-Output \"DNS cache flushed successfully.\"
|
|
||||||
} catch {
|
|
||||||
Write-Error \"Failed to flush DNS cache. Error: $_\"
|
|
||||||
}
|
|
||||||
"
|
"
|
||||||
],
|
],
|
||||||
"UndoScript": [
|
"UndoScript": [
|
||||||
"
|
"
|
||||||
# Define the local path of the HOSTS file
|
$hosts = \"$env:SystemRoot\\System32\\drivers\\etc\\hosts\"
|
||||||
$localHostsPath = \"C:\\Windows\\System32\\drivers\\etc\\hosts\"
|
$backup = \"$hosts.bak\"
|
||||||
|
|
||||||
# Load the content of the HOSTS file
|
Copy-Item $backup $hosts
|
||||||
try {
|
Remove-Item $backup
|
||||||
$hostsContent = Get-Content $localHostsPath -ErrorAction Stop
|
ipconfig flushdns
|
||||||
} catch {
|
|
||||||
Write-Error \"Failed to load the HOSTS file. Error: $_\"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
# Initialize flags and buffer for new content
|
Write-Host \"Removed Adobe url block list from host file\"
|
||||||
$recording = $true
|
|
||||||
$newContent = @()
|
|
||||||
|
|
||||||
# Iterate over each line of the HOSTS file
|
|
||||||
foreach ($line in $hostsContent) {
|
|
||||||
if ($line -match \"#AdobeNetBlock-start\") {
|
|
||||||
$recording = $false
|
|
||||||
}
|
|
||||||
if ($recording) {
|
|
||||||
$newContent += $line
|
|
||||||
}
|
|
||||||
if ($line -match \"#AdobeNetBlock-end\") {
|
|
||||||
$recording = $true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Write the filtered content back to the HOSTS file
|
|
||||||
try {
|
|
||||||
$newContent | Set-Content $localHostsPath -Encoding ASCII
|
|
||||||
Write-Output \"Successfully removed the AdobeNetBlock section from the HOSTS file.\"
|
|
||||||
} catch {
|
|
||||||
Write-Error \"Failed to write back to the HOSTS file. Error: $_\"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Flush the DNS resolver cache
|
|
||||||
try {
|
|
||||||
Invoke-Expression \"ipconfig /flushdns\"
|
|
||||||
Write-Output \"DNS cache flushed successfully.\"
|
|
||||||
} catch {
|
|
||||||
Write-Error \"Failed to flush DNS cache. Error: $_\"
|
|
||||||
}
|
|
||||||
"
|
"
|
||||||
],
|
],
|
||||||
"link": "https://winutil.christitus.com/dev/tweaks/z--advanced-tweaks---caution/blockadobenet"
|
"link": "https://winutil.christitus.com/dev/tweaks/z--advanced-tweaks---caution/blockadobenet"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user