├── .editorconfig ├── .gitignore ├── EZBlocker3.sln ├── EZBlocker3 ├── App.xaml ├── App.xaml.cs ├── AssemblyInfo.cs ├── Audio │ ├── CoreAudio │ │ ├── AudioDevice.cs │ │ ├── AudioSession.cs │ │ ├── AudioSessionCollection.cs │ │ └── AudioSessionManager.cs │ └── VolumeMixer.cs ├── AutoUpdate │ ├── DownloadUpdateWindow.xaml │ ├── DownloadUpdateWindow.xaml.cs │ ├── DownloadedUpdate.cs │ ├── UpdateChecker.cs │ ├── UpdateDownloader.cs │ ├── UpdateFoundWindow.xaml │ ├── UpdateFoundWindow.xaml.cs │ ├── UpdateInfo.cs │ └── UpdateInstaller.cs ├── CliArgs.cs ├── EZBlocker3.csproj ├── Extensions │ ├── ArrayExtensions.cs │ ├── DirectoryInfoExtensions.cs │ ├── DispatcherExtensions.cs │ ├── IEnumerableExtensions.cs │ ├── KeyValuePairExtensions.cs │ ├── PointExtensions.cs │ ├── ProcessExtensions.cs │ ├── QueueExtensions.cs │ ├── SizeExtensions.cs │ ├── StreamExtensions.cs │ ├── StringExtensions.cs │ └── TypeExtensions.cs ├── FodyWeavers.xml ├── GlobalSingletons.cs ├── Icon │ ├── Icon.ai │ ├── Icon128.ico │ ├── Icon128.png │ ├── Icon16.ico │ ├── Icon16.png │ ├── Icon256.ico │ ├── Icon256.png │ ├── Icon32.ico │ ├── Icon32.png │ ├── Icon64.ico │ └── Icon64.png ├── IllegalStateException.cs ├── ImageDictionary.xaml ├── Interop │ ├── NativeUtils.cs │ └── PInvokeExtra.cs ├── IsExternalInit.cs ├── Logging │ ├── LogLevel.cs │ ├── Logger.cs │ └── NamedLogger.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Program.cs ├── Properties │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Settings │ ├── Autostart.cs │ ├── SettingsWindow.xaml │ ├── SettingsWindow.xaml.cs │ ├── StartWithSpotify.cs │ └── Uninstall.cs ├── Spotify │ ├── AbstractSpotifyAdBlocker.cs │ ├── AbstractSpotifyHook.cs │ ├── GlobalSystemMediaTransportControlSpotifyHook.cs │ ├── IActivatable.cs │ ├── IMutingSpotifyHook.cs │ ├── ISpotifyHook.cs │ ├── MutingSpotifyAdBlocker.cs │ ├── ProcessAndWindowEventSpotifyHook.cs │ ├── SkippingSpotifyAdBlocker.cs │ ├── SongInfo.cs │ ├── SpotifyHandler.cs │ ├── SpotifyState.cs │ └── SpotifyUtils.cs ├── Utils │ ├── BitmapUtils.cs │ ├── DisposableList.cs │ ├── KeyDisposableDictionary.cs │ ├── KeyValueDisposableDictionary.cs │ ├── ValueDisposableDictionary.cs │ └── WindowHelper.cs └── app.manifest ├── Interop ├── Interop.csproj ├── NativeMethods.json └── NativeMethods.txt ├── LICENSE ├── README.md └── screenshots ├── screenshot-app-dark.png └── screenshot-app-light.png /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | 3 | # U2U1012: Parameter types should be specific 4 | dotnet_diagnostic.U2U1012.severity = none 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.vspscc 94 | *.vssscc 95 | .builds 96 | *.pidb 97 | *.svclog 98 | *.scc 99 | 100 | # Chutzpah Test files 101 | _Chutzpah* 102 | 103 | # Visual C++ cache files 104 | ipch/ 105 | *.aps 106 | *.ncb 107 | *.opendb 108 | *.opensdf 109 | *.sdf 110 | *.cachefile 111 | *.VC.db 112 | *.VC.VC.opendb 113 | 114 | # Visual Studio profiler 115 | *.psess 116 | *.vsp 117 | *.vspx 118 | *.sap 119 | 120 | # Visual Studio Trace Files 121 | *.e2e 122 | 123 | # TFS 2012 Local Workspace 124 | $tf/ 125 | 126 | # Guidance Automation Toolkit 127 | *.gpState 128 | 129 | # ReSharper is a .NET coding add-in 130 | _ReSharper*/ 131 | *.[Rr]e[Ss]harper 132 | *.DotSettings.user 133 | 134 | # TeamCity is a build add-in 135 | _TeamCity* 136 | 137 | # DotCover is a Code Coverage Tool 138 | *.dotCover 139 | 140 | # AxoCover is a Code Coverage Tool 141 | .axoCover/* 142 | !.axoCover/settings.json 143 | 144 | # Coverlet is a free, cross platform Code Coverage Tool 145 | coverage*.json 146 | coverage*.xml 147 | coverage*.info 148 | 149 | # Visual Studio code coverage results 150 | *.coverage 151 | *.coveragexml 152 | 153 | # NCrunch 154 | _NCrunch_* 155 | .*crunch*.local.xml 156 | nCrunchTemp_* 157 | 158 | # MightyMoose 159 | *.mm.* 160 | AutoTest.Net/ 161 | 162 | # Web workbench (sass) 163 | .sass-cache/ 164 | 165 | # Installshield output folder 166 | [Ee]xpress/ 167 | 168 | # DocProject is a documentation generator add-in 169 | DocProject/buildhelp/ 170 | DocProject/Help/*.HxT 171 | DocProject/Help/*.HxC 172 | DocProject/Help/*.hhc 173 | DocProject/Help/*.hhk 174 | DocProject/Help/*.hhp 175 | DocProject/Help/Html2 176 | DocProject/Help/html 177 | 178 | # Click-Once directory 179 | publish/ 180 | 181 | # Publish Web Output 182 | *.[Pp]ublish.xml 183 | *.azurePubxml 184 | # Note: Comment the next line if you want to checkin your web deploy settings, 185 | # but database connection strings (with potential passwords) will be unencrypted 186 | *.pubxml 187 | *.publishproj 188 | 189 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 190 | # checkin your Azure Web App publish settings, but sensitive information contained 191 | # in these scripts will be unencrypted 192 | PublishScripts/ 193 | 194 | # NuGet Packages 195 | *.nupkg 196 | # NuGet Symbol Packages 197 | *.snupkg 198 | # The packages folder can be ignored because of Package Restore 199 | **/[Pp]ackages/* 200 | # except build/, which is used as an MSBuild target. 201 | !**/[Pp]ackages/build/ 202 | # Uncomment if necessary however generally it will be regenerated when needed 203 | #!**/[Pp]ackages/repositories.config 204 | # NuGet v3's project.json files produces more ignorable files 205 | *.nuget.props 206 | *.nuget.targets 207 | 208 | # Microsoft Azure Build Output 209 | csx/ 210 | *.build.csdef 211 | 212 | # Microsoft Azure Emulator 213 | ecf/ 214 | rcf/ 215 | 216 | # Windows Store app package directories and files 217 | AppPackages/ 218 | BundleArtifacts/ 219 | Package.StoreAssociation.xml 220 | _pkginfo.txt 221 | *.appx 222 | *.appxbundle 223 | *.appxupload 224 | 225 | # Visual Studio cache files 226 | # files ending in .cache can be ignored 227 | *.[Cc]ache 228 | # but keep track of directories ending in .cache 229 | !?*.[Cc]ache/ 230 | 231 | # Others 232 | ClientBin/ 233 | ~$* 234 | *~ 235 | *.dbmdl 236 | *.dbproj.schemaview 237 | *.jfm 238 | *.pfx 239 | *.publishsettings 240 | orleans.codegen.cs 241 | 242 | # Including strong name files can present a security risk 243 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 244 | #*.snk 245 | 246 | # Since there are multiple workflows, uncomment next line to ignore bower_components 247 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 248 | #bower_components/ 249 | 250 | # RIA/Silverlight projects 251 | Generated_Code/ 252 | 253 | # Backup & report files from converting an old project file 254 | # to a newer Visual Studio version. Backup files are not needed, 255 | # because we have git ;-) 256 | _UpgradeReport_Files/ 257 | Backup*/ 258 | UpgradeLog*.XML 259 | UpgradeLog*.htm 260 | ServiceFabricBackup/ 261 | *.rptproj.bak 262 | 263 | # SQL Server files 264 | *.mdf 265 | *.ldf 266 | *.ndf 267 | 268 | # Business Intelligence projects 269 | *.rdl.data 270 | *.bim.layout 271 | *.bim_*.settings 272 | *.rptproj.rsuser 273 | *- [Bb]ackup.rdl 274 | *- [Bb]ackup ([0-9]).rdl 275 | *- [Bb]ackup ([0-9][0-9]).rdl 276 | 277 | # Microsoft Fakes 278 | FakesAssemblies/ 279 | 280 | # GhostDoc plugin setting file 281 | *.GhostDoc.xml 282 | 283 | # Node.js Tools for Visual Studio 284 | .ntvs_analysis.dat 285 | node_modules/ 286 | 287 | # Visual Studio 6 build log 288 | *.plg 289 | 290 | # Visual Studio 6 workspace options file 291 | *.opt 292 | 293 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 294 | *.vbw 295 | 296 | # Visual Studio LightSwitch build output 297 | **/*.HTMLClient/GeneratedArtifacts 298 | **/*.DesktopClient/GeneratedArtifacts 299 | **/*.DesktopClient/ModelManifest.xml 300 | **/*.Server/GeneratedArtifacts 301 | **/*.Server/ModelManifest.xml 302 | _Pvt_Extensions 303 | 304 | # Paket dependency manager 305 | .paket/paket.exe 306 | paket-files/ 307 | 308 | # FAKE - F# Make 309 | .fake/ 310 | 311 | # CodeRush personal settings 312 | .cr/personal 313 | 314 | # Python Tools for Visual Studio (PTVS) 315 | __pycache__/ 316 | *.pyc 317 | 318 | # Cake - Uncomment if you are using it 319 | # tools/** 320 | # !tools/packages.config 321 | 322 | # Tabs Studio 323 | *.tss 324 | 325 | # Telerik's JustMock configuration file 326 | *.jmconfig 327 | 328 | # BizTalk build output 329 | *.btp.cs 330 | *.btm.cs 331 | *.odx.cs 332 | *.xsd.cs 333 | 334 | # OpenCover UI analysis results 335 | OpenCover/ 336 | 337 | # Azure Stream Analytics local run output 338 | ASALocalRun/ 339 | 340 | # MSBuild Binary and Structured Log 341 | *.binlog 342 | 343 | # NVidia Nsight GPU debugger configuration file 344 | *.nvuser 345 | 346 | # MFractors (Xamarin productivity tool) working folder 347 | .mfractor/ 348 | 349 | # Local History for Visual Studio 350 | .localhistory/ 351 | 352 | # BeatPulse healthcheck temp database 353 | healthchecksdb 354 | 355 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 356 | MigrationBackup/ 357 | 358 | # Ionide (cross platform F# VS Code tools) working folder 359 | .ionide/ 360 | 361 | # Fody - auto-generated XML schema 362 | FodyWeavers.xsd 363 | -------------------------------------------------------------------------------- /EZBlocker3.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30503.244 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EZBlocker3", "EZBlocker3\EZBlocker3.csproj", "{BEBA52C5-91DB-4597-9ED0-C95FA33D9CFB}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Interop", "Interop\Interop.csproj", "{A16469B9-FB64-4B0A-AC62-E69DDD103068}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EDAC5A89-F78E-4A8C-B57A-B08830753CA4}" 11 | ProjectSection(SolutionItems) = preProject 12 | .editorconfig = .editorconfig 13 | EndProjectSection 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Debug|x64 = Debug|x64 19 | Release|Any CPU = Release|Any CPU 20 | Release|x64 = Release|x64 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {BEBA52C5-91DB-4597-9ED0-C95FA33D9CFB}.Debug|Any CPU.ActiveCfg = Debug|x64 24 | {BEBA52C5-91DB-4597-9ED0-C95FA33D9CFB}.Debug|Any CPU.Build.0 = Debug|x64 25 | {BEBA52C5-91DB-4597-9ED0-C95FA33D9CFB}.Debug|x64.ActiveCfg = Debug|x64 26 | {BEBA52C5-91DB-4597-9ED0-C95FA33D9CFB}.Debug|x64.Build.0 = Debug|x64 27 | {BEBA52C5-91DB-4597-9ED0-C95FA33D9CFB}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {BEBA52C5-91DB-4597-9ED0-C95FA33D9CFB}.Release|Any CPU.Build.0 = Release|Any CPU 29 | {BEBA52C5-91DB-4597-9ED0-C95FA33D9CFB}.Release|x64.ActiveCfg = Release|x64 30 | {BEBA52C5-91DB-4597-9ED0-C95FA33D9CFB}.Release|x64.Build.0 = Release|x64 31 | {A16469B9-FB64-4B0A-AC62-E69DDD103068}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {A16469B9-FB64-4B0A-AC62-E69DDD103068}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {A16469B9-FB64-4B0A-AC62-E69DDD103068}.Debug|x64.ActiveCfg = Debug|Any CPU 34 | {A16469B9-FB64-4B0A-AC62-E69DDD103068}.Debug|x64.Build.0 = Debug|Any CPU 35 | {A16469B9-FB64-4B0A-AC62-E69DDD103068}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {A16469B9-FB64-4B0A-AC62-E69DDD103068}.Release|Any CPU.Build.0 = Release|Any CPU 37 | {A16469B9-FB64-4B0A-AC62-E69DDD103068}.Release|x64.ActiveCfg = Release|Any CPU 38 | {A16469B9-FB64-4B0A-AC62-E69DDD103068}.Release|x64.Build.0 = Release|Any CPU 39 | EndGlobalSection 40 | GlobalSection(SolutionProperties) = preSolution 41 | HideSolutionNode = FALSE 42 | EndGlobalSection 43 | GlobalSection(ExtensibilityGlobals) = postSolution 44 | SolutionGuid = {D23630D6-230B-44F0-85EE-B19536266F12} 45 | EndGlobalSection 46 | EndGlobal 47 | -------------------------------------------------------------------------------- /EZBlocker3/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /EZBlocker3/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Reflection; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using EZBlocker3.Logging; 8 | using EZBlocker3.Settings; 9 | 10 | namespace EZBlocker3 { 11 | public partial class App : Application { 12 | public static readonly Assembly Assembly = Assembly.GetExecutingAssembly(); 13 | public static readonly AssemblyName AssemblyName = Assembly.GetName(); 14 | public static readonly string Name = AssemblyName.Name; 15 | public static readonly string ProductName = Assembly.GetCustomAttribute().Product; 16 | public static readonly string CompanyName = Assembly.GetCustomAttribute().Company; 17 | public static readonly string Location = Assembly.Location; 18 | public static readonly string Directory = Path.GetDirectoryName(Location); 19 | public static readonly Version Version = AssemblyName.Version; 20 | 21 | private const bool IsDebugBuild = 22 | #if DEBUG 23 | true; 24 | #else 25 | false; 26 | # endif 27 | internal static bool ForceDebugMode = false; 28 | public static bool DebugModeEnabled => IsDebugBuild || ForceDebugMode || EZBlocker3.Properties.Settings.Default.DebugMode; 29 | public static readonly bool ForceUpdate = false; 30 | public static readonly bool ForceUpdateCheck = IsDebugBuild || ForceUpdate; 31 | internal static bool SaveSettingsOnClose = true; 32 | 33 | protected override void OnStartup(StartupEventArgs eventArgs) { 34 | base.OnStartup(eventArgs); 35 | 36 | // enable all security protocols 37 | // without this statement https requests fail. 38 | ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; 39 | 40 | // reenable settings after update (disabled in UpdateInstaller.InstallUpdateAndRestart) 41 | var settings = EZBlocker3.Properties.Settings.Default; 42 | if (settings.UpgradeRequired || Program.CliArgs.IsUpdateRestart) { 43 | if (StartWithSpotify.Available) 44 | StartWithSpotify.SetEnabled(settings.StartWithSpotify); 45 | Autostart.SetEnabled(settings.StartOnLogin); 46 | } 47 | 48 | // upgrade settings on first start (after update) 49 | if (settings.UpgradeRequired) { 50 | settings.Upgrade(); 51 | settings.UpgradeRequired = false; 52 | settings.Save(); 53 | } 54 | 55 | // check if executable has moved 56 | if (Location != settings.AppPath) { 57 | try { 58 | if (settings.StartOnLogin) 59 | Autostart.SetEnabled(settings.StartOnLogin); 60 | // StartWithSpotify.SetEnabled(settings.StartWithSpotify); 61 | } catch (Exception e) { 62 | Logger.LogException("Failed to adjust to changed app path:", e); 63 | } 64 | 65 | settings.AppPath = Location; 66 | } 67 | 68 | if (settings.StartWithSpotify) { 69 | Task.Run(static () => { 70 | // Ensure that the proxy is still installed correctly if enabled. 71 | StartWithSpotify.Enable(); 72 | 73 | // start spotify if start with spotify is enabled but we did not start through the proxy 74 | // if (!Program.CliArgs.IsProxyStart) { 75 | // StartWithSpotify.TransformToProxied(); 76 | // StartWithSpotify.StartSpotify(); 77 | // } 78 | }); 79 | } 80 | 81 | // create main window 82 | var mainWindow = new MainWindow(); 83 | if (EZBlocker3.Properties.Settings.Default.StartMinimized) { 84 | mainWindow.ShowActivated = false; 85 | mainWindow.Minimize(); 86 | 87 | if (!EZBlocker3.Properties.Settings.Default.MinimizeToTray) 88 | mainWindow.Show(); 89 | } else { 90 | mainWindow.Show(); 91 | } 92 | } 93 | 94 | protected override void OnExit(ExitEventArgs e) { 95 | base.OnExit(e); 96 | GlobalSingletons.Dispose(); 97 | } 98 | 99 | protected override void OnSessionEnding(SessionEndingCancelEventArgs e) { 100 | // Cancel forced shutdown and shutdown normally. 101 | // This allows the cleanup code after the app.Run() method in Program.cs to run. 102 | e.Cancel = true; 103 | Shutdown(); 104 | 105 | base.OnSessionEnding(e); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /EZBlocker3/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo( 4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 5 | //(used if a resource is not found in the page, 6 | // or application resource dictionaries) 7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 8 | //(used if a resource is not found in the page, 9 | // app, or any theme specific resource dictionaries) 10 | )] 11 | -------------------------------------------------------------------------------- /EZBlocker3/Audio/CoreAudio/AudioDevice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using Microsoft.Windows.Sdk; 4 | 5 | namespace EZBlocker3.Audio.CoreAudio { 6 | public unsafe class AudioDevice : IDisposable { 7 | private readonly IMMDevice device; 8 | 9 | public AudioDevice(IMMDevice device) { 10 | this.device = device; 11 | } 12 | 13 | public static AudioDevice GetDefaultAudioDevice(EDataFlow dataFlow, ERole role) { 14 | IMMDeviceEnumerator? deviceEnumerator = null; 15 | try { 16 | PInvoke.CoCreateInstance(typeof(MMDeviceEnumerator).GUID, null, (uint)CLSCTX.CLSCTX_INPROC_SERVER, typeof(IMMDeviceEnumerator).GUID, out var tmp); 17 | deviceEnumerator = (IMMDeviceEnumerator)tmp; 18 | deviceEnumerator.GetDefaultAudioEndpoint(dataFlow, role, out IMMDevice device); 19 | return new AudioDevice(device); 20 | } finally { 21 | if (deviceEnumerator != null) 22 | Marshal.FinalReleaseComObject(deviceEnumerator); 23 | } 24 | } 25 | 26 | public AudioSessionManager GetSessionManager() { 27 | device.Activate(typeof(IAudioSessionManager2).GUID, 0, default, out var sessionManager); 28 | return new AudioSessionManager((IAudioSessionManager2)Marshal.GetObjectForIUnknown((IntPtr)sessionManager)); 29 | } 30 | 31 | #region IDisposable 32 | private bool isDisposed; 33 | protected virtual void Dispose(bool disposing) { 34 | if (!isDisposed) { 35 | isDisposed = true; 36 | 37 | Marshal.FinalReleaseComObject(device); 38 | } 39 | } 40 | 41 | ~AudioDevice() { 42 | Dispose(disposing: false); 43 | } 44 | 45 | public void Dispose() { 46 | // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method 47 | Dispose(disposing: true); 48 | GC.SuppressFinalize(this); 49 | } 50 | #endregion IDisposable 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /EZBlocker3/Audio/CoreAudio/AudioSession.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.ConstrainedExecution; 3 | using System.Runtime.InteropServices; 4 | using Microsoft.Windows.Sdk; 5 | 6 | namespace EZBlocker3.Audio.CoreAudio { 7 | public unsafe class AudioSession : CriticalFinalizerObject, IDisposable { 8 | private readonly IAudioSessionControl audioSessionControl; 9 | private readonly IAudioSessionControl2? audioSessionControl2; 10 | private readonly ISimpleAudioVolume? simpleAudioVolume; 11 | private readonly IAudioMeterInformation? audioMeterInformation; 12 | 13 | public AudioSession(IAudioSessionControl session) { 14 | audioSessionControl = session; 15 | 16 | simpleAudioVolume = session as ISimpleAudioVolume; 17 | audioMeterInformation = session as IAudioMeterInformation; 18 | audioSessionControl2 = session as IAudioSessionControl2; 19 | } 20 | 21 | public uint ProcessID { 22 | get { 23 | if (audioSessionControl2 is null) 24 | throw new NotSupportedException(); 25 | audioSessionControl2.GetProcessId(out var processId); 26 | return processId; 27 | } 28 | } 29 | 30 | public bool IsMuted { 31 | get { 32 | if (simpleAudioVolume is null) 33 | throw new NotSupportedException(); 34 | simpleAudioVolume.GetMute(out var isMuted); 35 | return isMuted; 36 | } 37 | set { 38 | if (simpleAudioVolume is null) 39 | throw new NotSupportedException(); 40 | simpleAudioVolume.SetMute(value, default); 41 | } 42 | } 43 | 44 | public float MasterVolume { 45 | get { 46 | if (simpleAudioVolume is null) 47 | throw new NotSupportedException(); 48 | simpleAudioVolume.GetMasterVolume(out var level); 49 | return level; 50 | } 51 | set { 52 | if (simpleAudioVolume is null) 53 | throw new NotSupportedException(); 54 | simpleAudioVolume.SetMasterVolume(value, default); 55 | } 56 | } 57 | 58 | public float PeakVolume { 59 | get { 60 | if (audioMeterInformation is null) 61 | throw new NotSupportedException(); 62 | audioMeterInformation.GetPeakValue(out var peak); 63 | return peak; 64 | } 65 | } 66 | 67 | #region IDisposable 68 | private bool _disposed; 69 | protected virtual void Dispose(bool disposing) { 70 | if (!_disposed) { 71 | _disposed = true; 72 | 73 | if (audioSessionControl != null) 74 | Marshal.FinalReleaseComObject(audioSessionControl); 75 | if (audioSessionControl2 != null) 76 | Marshal.FinalReleaseComObject(audioSessionControl2); 77 | if (simpleAudioVolume != null) 78 | Marshal.FinalReleaseComObject(simpleAudioVolume); 79 | if (audioMeterInformation != null) 80 | Marshal.FinalReleaseComObject(audioMeterInformation); 81 | } 82 | } 83 | 84 | ~AudioSession() { 85 | Dispose(disposing: false); 86 | } 87 | 88 | public void Dispose() { 89 | Dispose(disposing: true); 90 | GC.SuppressFinalize(this); 91 | } 92 | #endregion 93 | } 94 | } -------------------------------------------------------------------------------- /EZBlocker3/Audio/CoreAudio/AudioSessionCollection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.ConstrainedExecution; 3 | using System.Runtime.InteropServices; 4 | using Microsoft.Windows.Sdk; 5 | 6 | namespace EZBlocker3.Audio.CoreAudio { 7 | public unsafe class AudioSessionCollection : CriticalFinalizerObject, IDisposable { 8 | private readonly IAudioSessionEnumerator sessionEnumerator; 9 | 10 | public AudioSessionCollection(IAudioSessionEnumerator sessionEnumerator) { 11 | this.sessionEnumerator = sessionEnumerator; 12 | } 13 | 14 | public AudioSession this[int index] { 15 | get { 16 | sessionEnumerator.GetSession(index, out var session); 17 | return new AudioSession(session); 18 | } 19 | } 20 | 21 | public int Count { 22 | get { 23 | sessionEnumerator.GetCount(out var count); 24 | return count; 25 | } 26 | } 27 | 28 | #region IDisposable 29 | private bool _disposed; 30 | protected virtual void Dispose(bool disposing) { 31 | if (!_disposed) { 32 | _disposed = true; 33 | 34 | if (sessionEnumerator != null) 35 | Marshal.FinalReleaseComObject(sessionEnumerator); 36 | } 37 | } 38 | 39 | ~AudioSessionCollection() { 40 | Dispose(disposing: false); 41 | } 42 | 43 | public void Dispose() { 44 | Dispose(disposing: true); 45 | GC.SuppressFinalize(this); 46 | } 47 | #endregion 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /EZBlocker3/Audio/CoreAudio/AudioSessionManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.ConstrainedExecution; 3 | using System.Runtime.InteropServices; 4 | using Microsoft.Windows.Sdk; 5 | 6 | namespace EZBlocker3.Audio.CoreAudio { 7 | public unsafe class AudioSessionManager : CriticalFinalizerObject, IDisposable { 8 | private readonly IAudioSessionManager2 sessionManager; 9 | 10 | public AudioSessionManager(IAudioSessionManager2 sessionManager) { 11 | this.sessionManager = sessionManager; 12 | } 13 | 14 | public AudioSessionCollection GetSessionCollection() { 15 | IAudioSessionEnumerator? sessionEnumerator = null; 16 | try { 17 | sessionEnumerator = sessionManager.GetSessionEnumerator(); 18 | return new AudioSessionCollection(sessionEnumerator); 19 | } catch { 20 | if (sessionEnumerator != null) 21 | Marshal.FinalReleaseComObject(sessionEnumerator); 22 | throw; 23 | } 24 | } 25 | 26 | #region IDisposable 27 | private bool _disposed; 28 | protected virtual void Dispose(bool disposing) { 29 | if (!_disposed) { 30 | _disposed = true; 31 | 32 | if (sessionManager != null) 33 | Marshal.FinalReleaseComObject(sessionManager); 34 | } 35 | } 36 | 37 | ~AudioSessionManager() { 38 | Dispose(disposing: false); 39 | } 40 | 41 | public void Dispose() { 42 | Dispose(disposing: true); 43 | GC.SuppressFinalize(this); 44 | } 45 | #endregion 46 | } 47 | } -------------------------------------------------------------------------------- /EZBlocker3/Audio/VolumeMixer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace EZBlocker3.Audio { 5 | public static class VolumeMixer { 6 | public static readonly string Path = Environment.GetEnvironmentVariable("WINDIR") + @"\System32\SndVol.exe"; 7 | 8 | public static void Open() => Process.Start(Path).Dispose(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /EZBlocker3/AutoUpdate/DownloadUpdateWindow.xaml: -------------------------------------------------------------------------------- 1 |  13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |