|
| 1 | +function Use-WiFiFilterTool { |
| 2 | + <# |
| 3 | + .SYNOPSIS |
| 4 | + Launches the Wi-Fi Filter Tool application. |
| 5 | +
|
| 6 | + .DESCRIPTION |
| 7 | + This function starts the Wi-Fi Filter Tool, which allows users to manage Wi-Fi network filters through a graphical user interface. |
| 8 | +
|
| 9 | + .EXAMPLE |
| 10 | + Use-WiFiFilterTool -StartApplication |
| 11 | +
|
| 12 | + .NOTES |
| 13 | + v0.0.1 |
| 14 | + #> |
| 15 | + [CmdletBinding()] |
| 16 | + param ( |
| 17 | + [Parameter(Mandatory = $false, HelpMessage = "Start the Wi-Fi Filter Tool application in a GUI mode")] |
| 18 | + [switch]$StartApplication, |
| 19 | + |
| 20 | + [Parameter(Mandatory = $false, HelpMessage = "Path to the directory where Wi-Fi Filter Tool will be downloaded and extracted")] |
| 21 | + [string]$DownloadPath = "$env:TEMP\WiFiFilterTool", |
| 22 | + |
| 23 | + [Parameter(Mandatory = $false, HelpMessage = "Remove the temporary folder after the operation")] |
| 24 | + [switch]$RemoveFiles |
| 25 | + ) |
| 26 | + $ZipFilePath = Join-Path $DownloadPath "WifiFilter.zip" |
| 27 | + $ExtractPath = Join-Path $DownloadPath "WifiFilter" |
| 28 | + $Executable = Join-Path $ExtractPath "WifiFilter_x64.exe" |
| 29 | + try { |
| 30 | + Write-Host "Creating download directory..." -ForegroundColor Green |
| 31 | + if (-not (Test-Path -Path $DownloadPath)) { |
| 32 | + New-Item -Path $DownloadPath -ItemType Directory -Force | Out-Null |
| 33 | + } |
| 34 | + if (-not (Test-Path -Path $ZipFilePath)) { |
| 35 | + Write-Host "Downloading Wi-Fi Filter Tool..." -ForegroundColor Green |
| 36 | + Invoke-WebRequest -Uri "https://www.sordum.org/files/download/wi-fi-filter-tool/WifiFilter.zip" -OutFile $ZipFilePath -UseBasicParsing -Verbose |
| 37 | + if ((Get-Item $ZipFilePath).Length -eq 0) { |
| 38 | + throw "The downloaded ZIP file is empty or corrupt!" |
| 39 | + } |
| 40 | + } |
| 41 | + Write-Host "Extracting Wi-Fi Filter Tool..." -ForegroundColor Green |
| 42 | + if (Test-Path -Path $ExtractPath) { |
| 43 | + Remove-Item -Path $ExtractPath -Recurse -Force -ErrorAction Stop |
| 44 | + } |
| 45 | + try { |
| 46 | + Add-Type -AssemblyName System.IO.Compression.FileSystem |
| 47 | + [System.IO.Compression.ZipFile]::ExtractToDirectory($ZipFilePath, $ExtractPath) |
| 48 | + } |
| 49 | + catch { |
| 50 | + Write-Host "Extracting with Shell.Application..." -ForegroundColor Yellow |
| 51 | + $Shell = New-Object -ComObject Shell.Application |
| 52 | + $Zip = $Shell.NameSpace($ZipFilePath) |
| 53 | + $Destination = $Shell.NameSpace($ExtractPath) |
| 54 | + $Destination.CopyHere($Zip.Items(), 4) |
| 55 | + } |
| 56 | + if (-not (Test-Path -Path $Executable)) { |
| 57 | + $ExtractedSubfolder = Get-ChildItem -Path $ExtractPath | Where-Object { $_.PSIsContainer } | Select-Object -First 1 |
| 58 | + if ($ExtractedSubfolder) { |
| 59 | + $Executable = Join-Path $ExtractedSubfolder.FullName "WifiFilter_x64.exe" |
| 60 | + } |
| 61 | + } |
| 62 | + Write-Host "Files in extraction directory:" -ForegroundColor Yellow |
| 63 | + Get-ChildItem -Path $ExtractPath -Recurse | ForEach-Object { |
| 64 | + Write-Host $_.FullName -ForegroundColor Yellow |
| 65 | + } |
| 66 | + if (-Not (Test-Path -Path $Executable)) { |
| 67 | + throw "Wi-Fi Filter Tool executable not found at $Executable" |
| 68 | + } |
| 69 | + if ($StartApplication) { |
| 70 | + Write-Host "Starting Wi-Fi Filter Tool application..." -ForegroundColor Green |
| 71 | + Start-Process -FilePath $Executable -Wait |
| 72 | + } |
| 73 | + } |
| 74 | + catch { |
| 75 | + Write-Error -Message "An error occurred: $_" |
| 76 | + } |
| 77 | + finally { |
| 78 | + Write-Host "Wi-Fi Filter Tool operation completed." -ForegroundColor Cyan |
| 79 | + if ($RemoveFiles) { |
| 80 | + Write-Warning -Message "Cleaning up, removing the temporary folder..." |
| 81 | + try { |
| 82 | + Remove-Item -Path $DownloadPath -Force -Recurse -Verbose |
| 83 | + } |
| 84 | + catch { |
| 85 | + Write-Warning -Message "Failed to remove temporary files: $_" |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments