├── .gitattributes
├── .github
└── workflows
│ └── build.yml
├── .gitignore
├── Directory.Build.props
├── LICENSE.txt
├── README.md
├── Windows11ContextMenuManager.sln
├── docs
├── screenshot-1.png
└── screenshot-2.png
├── src
└── Windows11ContextMenuManager
│ ├── App.axaml
│ ├── App.axaml.cs
│ ├── Assets
│ └── icon.ico
│ ├── Core
│ ├── Blocks.cs
│ └── Packages.cs
│ ├── FodyWeavers.xml
│ ├── Helpers
│ ├── Permissions.cs
│ └── Try.cs
│ ├── Program.cs
│ ├── Styles
│ ├── Icons.axaml
│ ├── ResourceDictionary.axaml
│ └── Styles.axaml
│ ├── ViewModels
│ ├── ItemViewModel.cs
│ └── MainViewModel.cs
│ ├── Views
│ ├── MainWindow.axaml
│ └── MainWindow.axaml.cs
│ ├── Windows11ContextMenuManager.csproj
│ └── app.manifest
└── test
└── Windows11ContextMenuManager.Tests
├── BlocksTests.cs
├── Data
└── Microsoft.WindowsNotepad
│ └── AppxManifest.xml
├── PackagesTests.cs
└── Windows11ContextMenuManager.Tests.csproj
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a .NET project
2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3 |
4 | name: Build
5 |
6 | on:
7 | push:
8 | pull_request:
9 |
10 | jobs:
11 | build:
12 | runs-on: windows-latest
13 | steps:
14 | - uses: actions/checkout@v4
15 | with:
16 | fetch-depth: 0
17 | - uses: actions/setup-dotnet@v4
18 | with:
19 | dotnet-version: 8.0.x
20 | - name: Restore
21 | run: dotnet restore
22 | - name: Build
23 | run: dotnet build --no-restore
24 | - name: Test
25 | run: dotnet test --no-build --verbosity normal
26 | - name: Publish
27 | run: |
28 | foreach ($runtime in 'win-x64', 'win-arm64') {
29 | dotnet publish src/Windows11ContextMenuManager --no-restore -c Release -r $runtime -p:DebugType=none -p:Version=$((git describe --tags).TrimStart('v'))
30 | }
31 | - name: Upload
32 | uses: actions/upload-artifact@v4
33 | with:
34 | name: artifacts
35 | path: artifacts/publish/Windows11ContextMenuManager/
36 |
37 | release:
38 | if: startsWith(github.ref, 'refs/tags/')
39 | needs: build
40 | runs-on: windows-latest
41 | steps:
42 | - uses: actions/download-artifact@v4
43 | with:
44 | name: artifacts
45 | - name: Archive
46 | run: Get-ChildItem -Directory | ForEach-Object { Compress-Archive -Path "$($_.Name)\*" -DestinationPath "$($_.Name).zip" }
47 | - name: Release
48 | uses: softprops/action-gh-release@v1
49 | with:
50 | files: "*.zip"
51 |
--------------------------------------------------------------------------------
/.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 | [Oo]ut/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
364 |
365 | *.lutconfig
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0-windows10.0.17763.0
5 | enable
6 | enable
7 | true
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Brandon Hill
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Windows 11 Context Menu Manager
2 |
3 | Windows 11 Context Menu Manager is a simple tool that allows you to disable unwanted entries in Windows 11 Explorer _new_ right-click context menu.
4 |
5 | ## Download
6 |
7 | [Latest release](https://github.com/branhill/windows-11-context-menu-manager/releases/latest)
8 |
9 | ## Screenshots
10 |
11 | 
12 |
13 | 
14 |
15 | ## License
16 |
17 | This project is licensed under the [MIT License](LICENSE)
18 |
19 | Copyright (c) 2024 [Brandon Hill](https://branhill.com/)
20 |
--------------------------------------------------------------------------------
/Windows11ContextMenuManager.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.9.34518.117
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED55D167-E9C9-481C-A0BD-4F58EB17023A}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Windows11ContextMenuManager", "src\Windows11ContextMenuManager\Windows11ContextMenuManager.csproj", "{AE714DCE-2803-4893-A407-F148DF069655}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7A91BAAB-D025-4B3F-90C0-981A9820A525}"
11 | ProjectSection(SolutionItems) = preProject
12 | .gitattributes = .gitattributes
13 | .gitignore = .gitignore
14 | Directory.Build.props = Directory.Build.props
15 | LICENSE.txt = LICENSE.txt
16 | README.md = README.md
17 | EndProjectSection
18 | EndProject
19 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2CCF2423-8E05-4379-B29A-A7018E924468}"
20 | EndProject
21 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Windows11ContextMenuManager.Tests", "test\Windows11ContextMenuManager.Tests\Windows11ContextMenuManager.Tests.csproj", "{2FAB6C0A-69AC-499D-840C-951CBFBA3AD1}"
22 | EndProject
23 | Global
24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
25 | Debug|Any CPU = Debug|Any CPU
26 | Release|Any CPU = Release|Any CPU
27 | EndGlobalSection
28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
29 | {AE714DCE-2803-4893-A407-F148DF069655}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30 | {AE714DCE-2803-4893-A407-F148DF069655}.Debug|Any CPU.Build.0 = Debug|Any CPU
31 | {AE714DCE-2803-4893-A407-F148DF069655}.Release|Any CPU.ActiveCfg = Release|Any CPU
32 | {AE714DCE-2803-4893-A407-F148DF069655}.Release|Any CPU.Build.0 = Release|Any CPU
33 | {2FAB6C0A-69AC-499D-840C-951CBFBA3AD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34 | {2FAB6C0A-69AC-499D-840C-951CBFBA3AD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
35 | {2FAB6C0A-69AC-499D-840C-951CBFBA3AD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
36 | {2FAB6C0A-69AC-499D-840C-951CBFBA3AD1}.Release|Any CPU.Build.0 = Release|Any CPU
37 | EndGlobalSection
38 | GlobalSection(SolutionProperties) = preSolution
39 | HideSolutionNode = FALSE
40 | EndGlobalSection
41 | GlobalSection(NestedProjects) = preSolution
42 | {AE714DCE-2803-4893-A407-F148DF069655} = {ED55D167-E9C9-481C-A0BD-4F58EB17023A}
43 | {2FAB6C0A-69AC-499D-840C-951CBFBA3AD1} = {2CCF2423-8E05-4379-B29A-A7018E924468}
44 | EndGlobalSection
45 | GlobalSection(ExtensibilityGlobals) = postSolution
46 | SolutionGuid = {1537E278-46F6-4D48-82F7-116F3562E74F}
47 | EndGlobalSection
48 | EndGlobal
49 |
--------------------------------------------------------------------------------
/docs/screenshot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/branhill/windows-11-context-menu-manager/04599d59a090aa43116ea013273df9e69af28b3b/docs/screenshot-1.png
--------------------------------------------------------------------------------
/docs/screenshot-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/branhill/windows-11-context-menu-manager/04599d59a090aa43116ea013273df9e69af28b3b/docs/screenshot-2.png
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/App.axaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/App.axaml.cs:
--------------------------------------------------------------------------------
1 | using Avalonia;
2 | using Avalonia.Controls.ApplicationLifetimes;
3 | using Avalonia.Data.Core.Plugins;
4 | using Avalonia.Markup.Xaml;
5 | using Windows11ContextMenuManager.Helpers;
6 | using Windows11ContextMenuManager.ViewModels;
7 | using Windows11ContextMenuManager.Views;
8 |
9 | namespace Windows11ContextMenuManager;
10 |
11 | public partial class App : Application
12 | {
13 | public override void Initialize()
14 | {
15 | AvaloniaXamlLoader.Load(this);
16 | }
17 |
18 | public override void OnFrameworkInitializationCompleted()
19 | {
20 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
21 | {
22 | TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
23 | // Line below is needed to remove Avalonia data validation.
24 | // Without this line you will get duplicate validations from both Avalonia and CT
25 | BindingPlugins.DataValidators.RemoveAt(0);
26 | desktop.MainWindow = new MainWindow
27 | {
28 | DataContext = new MainViewModel()
29 | };
30 | }
31 |
32 | base.OnFrameworkInitializationCompleted();
33 | }
34 |
35 | private static void OnUnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
36 | {
37 | e.SetObserved();
38 | foreach (var ex in e.Exception.Flatten().InnerExceptions)
39 | Try.Handle(ex);
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/Assets/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/branhill/windows-11-context-menu-manager/04599d59a090aa43116ea013273df9e69af28b3b/src/Windows11ContextMenuManager/Assets/icon.ico
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/Core/Blocks.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Security;
3 | using Microsoft.Win32;
4 |
5 | namespace Windows11ContextMenuManager.Core;
6 |
7 | public class Blocks : IReadOnlyCollection
8 | {
9 | internal const string RegKey = @"Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked";
10 |
11 | private readonly RegistryKey _baseKey;
12 |
13 | private HashSet _items = [];
14 |
15 | private readonly Lazy _isReadOnly;
16 | public bool IsReadOnly => _isReadOnly.Value;
17 |
18 | public int Count => _items.Count;
19 |
20 | public BlockScope Scope { get; }
21 |
22 | private Blocks(BlockScope scope)
23 | {
24 | Scope = scope;
25 | _baseKey = RegistryKey.OpenBaseKey((RegistryHive)scope, RegistryView.Default);
26 | _isReadOnly = new(() =>
27 | {
28 | try
29 | {
30 | using var subKey = _baseKey.OpenSubKey(RegKey, true) ??
31 | _baseKey.OpenSubKey(RegKey[..RegKey.LastIndexOf('\\')], true);
32 | return false;
33 | }
34 | catch (SecurityException)
35 | {
36 | return true;
37 | }
38 | });
39 | }
40 |
41 | public void Load()
42 | {
43 | using var subKey = _baseKey.OpenSubKey(RegKey);
44 | _items = subKey?.GetValueNames().Select(FromRegName).ToHashSet() ?? [];
45 | }
46 |
47 | public void Add(string id)
48 | {
49 | using var subKey = _baseKey.OpenSubKey(RegKey, true) ?? _baseKey.CreateSubKey(RegKey);
50 | subKey.SetValue(ToRegName(id), "");
51 | _items.Add(id);
52 | }
53 |
54 | public void Remove(string id)
55 | {
56 | if (!_items.Contains(id))
57 | return;
58 | using var subKey = _baseKey.OpenSubKey(RegKey, true);
59 | if (subKey is null)
60 | {
61 | _items = [];
62 | }
63 | else
64 | {
65 | subKey.DeleteValue(ToRegName(id), false);
66 | _items.Remove(id);
67 | }
68 | }
69 |
70 | public bool Contains(string id) => _items.Contains(id);
71 |
72 | public IEnumerator GetEnumerator() => _items.GetEnumerator();
73 |
74 | IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
75 |
76 | private static string ToRegName(string val) => '{' + val + '}';
77 |
78 | private static string FromRegName(string val) => val.Trim('{', '}');
79 |
80 | public static Blocks User { get; } = new(BlockScope.User);
81 |
82 | public static Blocks Machine { get; } = new(BlockScope.Machine);
83 |
84 | public static BlockScope WriteScope { get; set; } = BlockScope.User;
85 |
86 | public static IEnumerable GetScopes()
87 | {
88 | yield return User;
89 | yield return Machine;
90 | }
91 |
92 | public static Blocks GetScope(BlockScope scope)
93 | {
94 | return scope switch
95 | {
96 | BlockScope.User => User,
97 | BlockScope.Machine => Machine,
98 | _ => throw new ArgumentOutOfRangeException(nameof(scope), scope, null)
99 | };
100 | }
101 |
102 | public static void LoadAll()
103 | {
104 | foreach (var blocks in GetScopes())
105 | blocks.Load();
106 | }
107 | }
108 |
109 | public enum BlockScope
110 | {
111 | User = RegistryHive.CurrentUser,
112 | Machine = RegistryHive.LocalMachine
113 | }
114 |
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/Core/Packages.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Concurrent;
2 | using System.Xml;
3 | using System.Xml.Linq;
4 | using Microsoft.Win32;
5 | using Windows.Management.Deployment;
6 | using Windows11ContextMenuManager.Helpers;
7 |
8 | namespace Windows11ContextMenuManager.Core;
9 |
10 | public static class Packages
11 | {
12 | private const string NsCom = "http://schemas.microsoft.com/appx/manifest/com/windows10";
13 | private const string NsDesktop4 = "http://schemas.microsoft.com/appx/manifest/desktop/windows10/4";
14 |
15 | public static async Task> GetExtensions()
16 | {
17 | var comPackages = GetPackagedComPackages();
18 | var packageManager = new PackageManager();
19 | var extensions = new ConcurrentDictionary();
20 | await Parallel.ForEachAsync(comPackages, new ParallelOptions { MaxDegreeOfParallelism = 4 }, async (fullName, _) =>
21 | {
22 | try
23 | {
24 | var package = Permissions.IsElevated
25 | ? packageManager.FindPackage(fullName)
26 | : packageManager.FindPackageForUser("", fullName);
27 | if (package is null)
28 | return;
29 | var ver = package.Id.Version;
30 | var pkg = new Pkg(
31 | package.Id.FamilyName,
32 | package.Id.FullName,
33 | package.DisplayName,
34 | package.PublisherDisplayName,
35 | package.Logo.LocalPath,
36 | package.InstalledLocation.Path,
37 | new Version(ver.Major, ver.Minor, ver.Build, ver.Revision));
38 | var res = await AnalyzeManifest(pkg, package.IsBundle);
39 | foreach (var item in res)
40 | {
41 | if (!extensions.TryGetValue(item.Id, out var existing) ||
42 | existing.Package.Version < item.Package.Version)
43 | {
44 | extensions[item.Id] = item;
45 | }
46 | }
47 | }
48 | catch (Exception)
49 | {
50 | // ignored
51 | }
52 | });
53 | return extensions.Values;
54 | }
55 |
56 | internal static string[] GetPackagedComPackages()
57 | {
58 | using var subKey = Registry.ClassesRoot.OpenSubKey(@"PackagedCom\Package");
59 | return subKey?.GetSubKeyNames() ?? [];
60 | }
61 |
62 | internal static async Task> AnalyzeManifest(Pkg pkg, bool isBundle)
63 | {
64 | var manifestPath = Path.Join(
65 | pkg.InstallPath,
66 | isBundle ? @"\AppxMetadata\AppxBundleManifest.xml" : @"\AppxManifest.xml");
67 | await using var stream = File.OpenRead(manifestPath);
68 | using var reader = XmlReader.Create(stream, new XmlReaderSettings
69 | {
70 | Async = true,
71 | DtdProcessing = DtdProcessing.Ignore
72 | });
73 |
74 | var nsResolver = (IXmlNamespaceResolver)reader;
75 | if (!reader.ReadToFollowing("Package") ||
76 | nsResolver.LookupPrefix(NsDesktop4) is null ||
77 | nsResolver.LookupPrefix(NsCom) is null)
78 | {
79 | return [];
80 | }
81 |
82 | var contextMenus = new Dictionary>();
83 | var comServers = new Dictionary();
84 | while (await reader.ReadAsync())
85 | {
86 | if (reader.NodeType != XmlNodeType.Element)
87 | continue;
88 | switch (reader.LocalName)
89 | {
90 | case "FileExplorerContextMenus":
91 | {
92 | var el = (XElement)XNode.ReadFrom(reader);
93 | var query =
94 | from itemType in el.Elements()
95 | where itemType.Name.LocalName == "ItemType"
96 | from verb in itemType.Elements()
97 | where verb.Name.LocalName == "Verb"
98 | let type = itemType.Attribute("Type")?.Value
99 | let item = new ContextMenu(
100 | verb.Attribute("Clsid")?.Value,
101 | verb.Attribute("Id")?.Value,
102 | type.Contains("Directory") ? type : $"File: {type}")
103 | group item by item.Clsid;
104 | contextMenus = query.ToDictionary(x => x.Key, x => x.ToList());
105 | break;
106 | }
107 | case "ComServer":
108 | {
109 | var el = (XElement)XNode.ReadFrom(reader);
110 | var query =
111 | from server in el.Elements()
112 | where server.Name.LocalName is "SurrogateServer" or "ExeServer"
113 | from cls in server.Elements()
114 | where cls.Name.LocalName == "Class"
115 | let item = new ComServer(
116 | cls.Attribute("Id")?.Value,
117 | Path.Join(
118 | pkg.InstallPath,
119 | cls.Attribute("Path")?.Value ?? server.Attribute("Executable")?.Value),
120 | server.Attribute("DisplayName")?.Value)
121 | group item by item.Id;
122 | comServers = query.ToDictionary(x => x.Key, x => x.First());
123 | break;
124 | }
125 | }
126 | }
127 |
128 | return contextMenus
129 | .Select(x => x.Key)
130 | .Intersect(comServers.Select(x => x.Key))
131 | .Select(id => new Extension(id, pkg, contextMenus[id], comServers[id]));
132 | }
133 | }
134 |
135 | public record Pkg(
136 | string FamilyName,
137 | string FullName,
138 | string DisplayName,
139 | string PublisherDisplayName,
140 | string Logo,
141 | string InstallPath,
142 | Version Version);
143 |
144 | public record ContextMenu(
145 | string? Clsid,
146 | string? Id,
147 | string? Type);
148 |
149 | public record ComServer(
150 | string? Id,
151 | string? Path,
152 | string? DisplayName);
153 |
154 | public record Extension(
155 | string Id,
156 | Pkg Package,
157 | List ContextMenus,
158 | ComServer ComServer);
159 |
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/FodyWeavers.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/Helpers/Permissions.cs:
--------------------------------------------------------------------------------
1 | using System.Security.Principal;
2 |
3 | namespace Windows11ContextMenuManager.Helpers;
4 |
5 | public static class Permissions
6 | {
7 | private static readonly Lazy IsElevatedLazy = new(() =>
8 | {
9 | using var identity = WindowsIdentity.GetCurrent();
10 | return new WindowsPrincipal(identity).IsInRole(WindowsBuiltInRole.Administrator);
11 | });
12 |
13 | public static bool IsElevated => IsElevatedLazy.Value;
14 | }
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/Helpers/Try.cs:
--------------------------------------------------------------------------------
1 | using System.Security;
2 | using Avalonia.Controls.Notifications;
3 | using CommunityToolkit.Mvvm.Messaging;
4 |
5 | namespace Windows11ContextMenuManager.Helpers;
6 |
7 | public static class Try
8 | {
9 | public static void Run(Action action)
10 | {
11 | try
12 | {
13 | action();
14 | }
15 | catch (Exception e)
16 | {
17 | Handle(e);
18 | }
19 | }
20 |
21 | public static async Task Run(Func action)
22 | {
23 | try
24 | {
25 | await action();
26 | }
27 | catch (Exception e)
28 | {
29 | Handle(e);
30 | }
31 | }
32 |
33 | public static void Handle(Exception e)
34 | {
35 | string msg;
36 | switch (e)
37 | {
38 | case SecurityException:
39 | case UnauthorizedAccessException:
40 | msg = "Access denied, please try run as administrator.";
41 | break;
42 | default:
43 | msg = e.Message;
44 | break;
45 | }
46 | WeakReferenceMessenger.Default.Send(new Notification("Error", msg, NotificationType.Error));
47 | }
48 | }
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/Program.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using Avalonia;
3 |
4 | [assembly: InternalsVisibleTo("Windows11ContextMenuManager.Tests")]
5 |
6 | namespace Windows11ContextMenuManager;
7 |
8 | internal sealed class Program
9 | {
10 | // Initialization code. Don't use any Avalonia, third-party APIs or any
11 | // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
12 | // yet and stuff might break.
13 | [STAThread]
14 | public static void Main(string[] args) => BuildAvaloniaApp()
15 | .StartWithClassicDesktopLifetime(args);
16 |
17 | // Avalonia configuration, don't remove; also used by visual designer.
18 | public static AppBuilder BuildAvaloniaApp()
19 | => AppBuilder.Configure()
20 | .UseWin32()
21 | .UseSkia()
22 | .LogToTrace();
23 | }
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/Styles/Icons.axaml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
17 |
18 |
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/Styles/ResourceDictionary.axaml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | #B3FFFFFF
7 | #80F9F9F9
8 | #4DF9F9F9
9 | #4DF9F9F9
10 | #0F000000
11 | #29000000
12 |
13 |
14 |
15 | #0FFFFFFF
16 | #15FFFFFF
17 | #08FFFFFF
18 | #0BFFFFFF
19 | #12FFFFFF
20 | #18FFFFFF
21 |
22 |
23 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
40 |
41 |
42 |
43 |
44 |
46 |
48 |
49 |
50 |
51 |
53 |
55 |
57 |
59 |
61 |
63 |
65 |
67 |
68 |
70 |
72 |
74 |
76 |
78 |
80 |
82 |
84 |
86 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/Styles/Styles.axaml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
17 |
18 |
27 |
31 |
35 |
39 |
43 |
44 |
45 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/ViewModels/ItemViewModel.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 | using Avalonia;
3 | using Avalonia.Controls;
4 | using Avalonia.Controls.Notifications;
5 | using Avalonia.Media.Imaging;
6 | using CommunityToolkit.Mvvm.ComponentModel;
7 | using CommunityToolkit.Mvvm.Input;
8 | using CommunityToolkit.Mvvm.Messaging;
9 | using Windows11ContextMenuManager.Core;
10 | using Windows11ContextMenuManager.Helpers;
11 |
12 | namespace Windows11ContextMenuManager.ViewModels;
13 |
14 | public partial class ItemViewModel : ObservableRecipient
15 | {
16 | [ObservableProperty]
17 | private bool _isEnabled;
18 |
19 | public Extension Info { get; }
20 |
21 | private readonly Lazy> _logo;
22 | public Task Logo => _logo.Value;
23 |
24 | [ObservableProperty]
25 | private bool _isExpanded;
26 |
27 | public ItemViewModel(Extension info)
28 | {
29 | Info = info;
30 | IsEnabled = GetIsEnabled();
31 | _logo = new Lazy>(() => Task.Run(LoadLogo));
32 | }
33 |
34 | private Bitmap? LoadLogo()
35 | {
36 | try
37 | {
38 | return new Bitmap(Info.Package.Logo);
39 | }
40 | catch (Exception)
41 | {
42 | return null;
43 | }
44 | }
45 |
46 | [RelayCommand]
47 | private void UpdateIsEnabled()
48 | {
49 | Try.Run(() =>
50 | {
51 | if (IsEnabled)
52 | foreach (var blocks in Blocks.GetScopes())
53 | blocks.Remove(Info.Id);
54 | else
55 | Blocks.GetScope(Blocks.WriteScope).Add(Info.Id);
56 |
57 | Messenger.Send(new Notification(
58 | "Success",
59 | $"{Info.Package.DisplayName} context menu {(IsEnabled ? "enabled" : "disabled")}",
60 | NotificationType.Success));
61 | });
62 | IsEnabled = GetIsEnabled();
63 | }
64 |
65 | [RelayCommand]
66 | private async Task CopyDisplayName(Visual sender)
67 | {
68 | await Copy(sender, Info.Package.DisplayName);
69 | }
70 |
71 | [RelayCommand]
72 | private async Task CopyFamilyName(Visual sender)
73 | {
74 | await Copy(sender, Info.Package.FamilyName);
75 | }
76 |
77 | [RelayCommand]
78 | private void OpenFileLocation()
79 | {
80 | Start(Info.Package.InstallPath);
81 | }
82 |
83 | [RelayCommand]
84 | private void AppSettings()
85 | {
86 | Start("ms-settings:appsfeatures-app");
87 | }
88 |
89 | [RelayCommand]
90 | private void MicrosoftStore()
91 | {
92 | Start($"ms-windows-store://pdp?PFN={Info.Package.FamilyName}");
93 | }
94 |
95 | [RelayCommand]
96 | private async Task Uninstall()
97 | {
98 | await Try.Run(async () =>
99 | {
100 | var info = new ProcessStartInfo
101 | {
102 | FileName = "powershell",
103 | UseShellExecute = true
104 | };
105 | info.ArgumentList.Add("-c");
106 | info.ArgumentList.Add($"Remove-AppxPackage {Info.Package.FullName} -Confirm");
107 | using var process = Process.Start(info);
108 | await (process?.WaitForExitAsync() ?? Task.CompletedTask);
109 | Messenger.Send(new ReloadMessage());
110 | });
111 | }
112 |
113 | private bool GetIsEnabled()
114 | {
115 | return !Blocks.GetScopes().Any(x => x.Contains(Info.Id));
116 | }
117 |
118 | private async Task Copy(Visual sender, string text)
119 | {
120 | if (TopLevel.GetTopLevel(sender)?.Clipboard is { } clipboard)
121 | {
122 | await clipboard.SetTextAsync(text);
123 | Messenger.Send(
124 | new Notification("Success", "Copied to clipboard", NotificationType.Success));
125 | }
126 | }
127 |
128 | private static void Start(string cmd)
129 | {
130 | Try.Run(() =>
131 | {
132 | using var _ = Process.Start(new ProcessStartInfo { FileName = cmd, UseShellExecute = true });
133 | });
134 | }
135 | }
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/ViewModels/MainViewModel.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 | using System.Diagnostics.CodeAnalysis;
3 | using Avalonia.Threading;
4 | using CommunityToolkit.Mvvm.ComponentModel;
5 | using CommunityToolkit.Mvvm.Input;
6 | using CommunityToolkit.Mvvm.Messaging;
7 | using Windows11ContextMenuManager.Core;
8 | using Windows11ContextMenuManager.Helpers;
9 |
10 | namespace Windows11ContextMenuManager.ViewModels;
11 |
12 | public partial class MainViewModel : ObservableRecipient, IRecipient
13 | {
14 | [ObservableProperty]
15 | [NotifyPropertyChangedFor(nameof(DisplayItems))]
16 | private List _items = [];
17 |
18 | [ObservableProperty]
19 | [NotifyPropertyChangedFor(nameof(DisplayItems))]
20 | private string? _search;
21 |
22 | [ObservableProperty]
23 | private BlockScope? _scope = Blocks.WriteScope;
24 |
25 | [ObservableProperty]
26 | private long _loadElapsed;
27 |
28 | public BlockScopeItem[] Scopes { get; } = Blocks.GetScopes()
29 | .Select(x => new BlockScopeItem(x.Scope, x.Scope.ToString(), !x.IsReadOnly))
30 | .ToArray();
31 |
32 | public IEnumerable DisplayItems
33 | {
34 | get
35 | {
36 | if (string.IsNullOrWhiteSpace(Search))
37 | return Items;
38 | var search = Search.Trim();
39 | return Items.Where(x =>
40 | Contains(x.Info.Package.DisplayName) ||
41 | Contains(x.Info.Package.FamilyName) ||
42 | Contains(x.Info.Package.InstallPath) ||
43 | Contains(x.Info.ComServer.Id) ||
44 | Contains(x.Info.ComServer.DisplayName) ||
45 | Contains(x.Info.ComServer.Path) ||
46 | x.Info.ContextMenus.Any(m =>
47 | Contains(m.Id) ||
48 | Contains(m.Type)));
49 | bool Contains(string? val) => val?.Contains(search, StringComparison.OrdinalIgnoreCase) == true;
50 | }
51 | }
52 |
53 | [UnconditionalSuppressMessage("Trimming", "IL2026")]
54 | public MainViewModel()
55 | {
56 | Dispatcher.UIThread.InvokeAsync(() => LoadCommand.ExecuteAsync(null));
57 | IsActive = true;
58 | }
59 |
60 | [RelayCommand]
61 | private async Task Load()
62 | {
63 | var stopwatch = Stopwatch.StartNew();
64 |
65 | await Try.Run(async () =>
66 | {
67 | Blocks.LoadAll();
68 | var extensions = await Packages.GetExtensions();
69 | Items = extensions
70 | .OrderBy(x => x.Package.DisplayName)
71 | .Select(x => new ItemViewModel(x))
72 | .ToList();
73 | });
74 |
75 | stopwatch.Stop();
76 | LoadElapsed = stopwatch.ElapsedMilliseconds;
77 | }
78 |
79 | [RelayCommand]
80 | private void ExpandAll()
81 | {
82 | foreach (var item in Items)
83 | item.IsExpanded = true;
84 | }
85 |
86 | [RelayCommand]
87 | private void CollapseAll()
88 | {
89 | foreach (var item in Items)
90 | item.IsExpanded = false;
91 | }
92 |
93 | partial void OnScopeChanged(BlockScope? value)
94 | {
95 | if (value is { } val)
96 | Blocks.WriteScope = val;
97 | }
98 |
99 | public void Receive(ReloadMessage message)
100 | {
101 | Dispatcher.UIThread.InvokeAsync(() => LoadCommand.ExecuteAsync(null));
102 | }
103 | }
104 |
105 | public record BlockScopeItem(
106 | BlockScope Value,
107 | string Name,
108 | bool IsEnabled);
109 |
110 | public record ReloadMessage();
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/Views/MainWindow.axaml:
--------------------------------------------------------------------------------
1 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
34 |
35 |
42 |
43 |
44 |
48 |
49 |
50 |
51 |
52 |
56 |
60 |
61 |
62 |
65 |
66 |
71 |
72 |
78 |
79 |
82 |
83 |
84 |
85 |
86 |
91 |
95 |
96 |
101 |
102 |
103 |
104 |
105 |
106 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
122 |
128 |
129 |
130 |
131 |
132 |
133 |
135 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
154 |
155 |
156 |
157 |
160 |
161 |
165 |
166 |
167 |
168 |
172 |
174 |
175 |
177 |
187 |
190 |
200 |
201 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
222 |
223 |
224 |
225 |
229 |
230 |
232 |
235 |
238 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/Views/MainWindow.axaml.cs:
--------------------------------------------------------------------------------
1 | using Avalonia.Controls;
2 | using Avalonia.Controls.Notifications;
3 | using Avalonia.Controls.Primitives;
4 | using Avalonia.Threading;
5 | using CommunityToolkit.Mvvm.Messaging;
6 |
7 | namespace Windows11ContextMenuManager.Views;
8 |
9 | public partial class MainWindow : Window, IRecipient
10 | {
11 | private WindowNotificationManager? _notificationManager;
12 |
13 | public MainWindow()
14 | {
15 | InitializeComponent();
16 |
17 | WeakReferenceMessenger.Default.Register(this);
18 | }
19 |
20 | protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
21 | {
22 | _notificationManager = new(this)
23 | {
24 | Classes = { "bottom-center" }
25 | };
26 | }
27 |
28 | public void Receive(Notification message)
29 | {
30 | Dispatcher.UIThread.Invoke(() => _notificationManager?.Show(message));
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/Windows11ContextMenuManager.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | WinExe
4 | win-x64;win-arm64
5 | app.manifest
6 | true
7 | true
8 | Size
9 | true
10 | false
11 | false
12 | Assets\icon.ico
13 | Windows 11 Context Menu Manager
14 | Windows 11 Context Menu Manager
15 | Copyright © 2024 Brandon Hill
16 | Brandon Hill
17 | true
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | all
34 |
35 |
36 | all
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/Windows11ContextMenuManager/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/Windows11ContextMenuManager.Tests/BlocksTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Win32;
2 | using Windows11ContextMenuManager.Core;
3 | using Windows11ContextMenuManager.Helpers;
4 |
5 | namespace Windows11ContextMenuManager.Tests;
6 |
7 | public class BlocksTests
8 | {
9 | public BlocksTests()
10 | {
11 | Blocks.LoadAll();
12 | }
13 |
14 | [Fact]
15 | public void IsReadOnlyTest()
16 | {
17 | Assert.False(Blocks.User.IsReadOnly);
18 | Assert.NotEqual(Permissions.IsElevated, Blocks.Machine.IsReadOnly);
19 | }
20 |
21 | [Fact]
22 | public void ReadWriteTest()
23 | {
24 | var blocks = Blocks.User;
25 | var id = Guid.NewGuid().ToString().ToUpper();
26 | var beforeCount = blocks.Count;
27 |
28 | blocks.Add(id);
29 |
30 | Assert.Equal(beforeCount + 1, blocks.Count);
31 | Assert.Contains(id, blocks);
32 |
33 | blocks.Load();
34 |
35 | Assert.Equal(beforeCount + 1, blocks.Count);
36 | Assert.Contains(id, blocks);
37 |
38 | using (var subKey = Registry.CurrentUser.OpenSubKey(Blocks.RegKey))
39 | {
40 | Assert.NotNull(subKey);
41 | Assert.NotNull(subKey.GetValue('{' + id + '}'));
42 | }
43 |
44 | blocks.Remove(id);
45 |
46 | Assert.Equal(beforeCount, blocks.Count);
47 | Assert.DoesNotContain(id, blocks);
48 |
49 | blocks.Load();
50 |
51 | Assert.Equal(beforeCount, blocks.Count);
52 | Assert.DoesNotContain(id, blocks);
53 | }
54 | }
--------------------------------------------------------------------------------
/test/Windows11ContextMenuManager.Tests/Data/Microsoft.WindowsNotepad/AppxManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | ms-resource:Resources/AppStoreName
8 | Microsoft Corporation
9 | Assets\NotepadStoreLogo.png
10 | disabled
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | ms-resource:Resources/FileTypeDisplayName_Inffile
44 | Assets\inifile.png
45 |
46 | .inf
47 |
48 |
49 | ms-resource:Resources/ShellContextMenuEdit
50 | ms-resource:Resources/ShellContextMenuPrint
51 | ms-resource:Resources/ShellContextMenuPrint
52 |
53 |
54 |
55 |
56 |
57 | ms-resource:Resources/FileTypeDisplayName_Inifile
58 | Assets\inifile.png
59 |
60 | .ini
61 |
62 |
63 | ms-resource:Resources/ShellContextMenuEdit
64 | ms-resource:Resources/ShellContextMenuPrint
65 | ms-resource:Resources/ShellContextMenuPrint
66 |
67 |
68 |
69 |
70 |
71 | ms-resource:Resources/FileTypeDisplayName_Ps1file
72 | Assets\ps1file.png
73 |
74 |
75 | .ps1
76 |
77 |
78 |
79 |
80 |
81 | ms-resource:Resources/FileTypeDisplayName_Psd1file
82 | Assets\ps1file.png
83 |
84 |
85 | .psd1
86 |
87 |
88 |
89 |
90 |
91 | ms-resource:Resources/FileTypeDisplayName_Psm1file
92 | Assets\ps1file.png
93 |
94 |
95 | .psm1
96 |
97 |
98 |
99 |
100 |
101 | ms-resource:Resources/FileTypeDisplayName_Txtfile
102 | Assets\txtfile.png
103 |
104 | .scp
105 | .log
106 | .wtx
107 | .txt
108 |
109 |
110 | ms-resource:Resources/ShellContextMenuEdit
111 | ms-resource:Resources/ShellContextMenuPrint
112 | ms-resource:Resources/ShellContextMenuPrint
113 |
114 |
115 |
116 |
117 |
118 | Assets\txtfile.png
119 |
120 | *
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 | Notepad\NotepadXamlUI.dll
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
--------------------------------------------------------------------------------
/test/Windows11ContextMenuManager.Tests/PackagesTests.cs:
--------------------------------------------------------------------------------
1 | using Windows11ContextMenuManager.Core;
2 |
3 | namespace Windows11ContextMenuManager.Tests;
4 |
5 | public class PackagesTests
6 | {
7 | [Fact]
8 | public async Task GetExtensionsTest()
9 | {
10 | var extensions = await Packages.GetExtensions();
11 |
12 | if (Packages.GetPackagedComPackages().Length != 0)
13 | {
14 | Assert.NotEmpty(extensions);
15 | }
16 | }
17 |
18 | [Theory]
19 | [MemberData(nameof(ManifestData))]
20 | public async Task AnalyzeManifestTest(string name, ExtensionExpected[] expected)
21 | {
22 | var installPath = Path.Join("Data", name);
23 | var pkg = new Pkg(name, name, name, name, name, installPath, new Version());
24 |
25 | var res = (await Packages.AnalyzeManifest(pkg, false)).ToDictionary(x => x.Id, x => x);
26 |
27 | Assert.Equal(expected.Select(x => x.Id), res.Keys);
28 | foreach (var exp in expected)
29 | {
30 | var actual = res[exp.Id];
31 | Assert.Equal(Path.Join(installPath, exp.Path), actual.ComServer.Path);
32 | Assert.Equal(exp.Types, actual.ContextMenus.Select(x => x.Type));
33 | }
34 | }
35 |
36 | public static TheoryData ManifestData()
37 | {
38 |
39 | return new()
40 | {
41 | {
42 | "Microsoft.WindowsNotepad", [
43 | new ExtensionExpected(
44 | "CA6CC9F1-867A-481E-951E-A28C5E4F01EA",
45 | @"NotepadExplorerCommand\NotepadExplorerCommand.dll",
46 | ["File: *", "Directory"])
47 | ]
48 | }
49 | };
50 | }
51 |
52 | public record ExtensionExpected(
53 | string Id,
54 | string Path,
55 | string[] Types);
56 | }
--------------------------------------------------------------------------------
/test/Windows11ContextMenuManager.Tests/Windows11ContextMenuManager.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | false
5 | true
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | all
14 | runtime; build; native; contentfiles; analyzers; buildtransitive
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | PreserveNewest
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------