<commit_before>﻿using Microsoft.Win32;

namespace DrawShip.Viewer
{
	/// <summary>
	/// Run mode for uninstalling the context menu items from windows
	/// </summary>
	public class UninstallRunMode : IRunMode
	{
		public bool Run(ApplicationContext applicationContext)
		{
			var xml = Registry.ClassesRoot.OpenKey(@".xml", createIfRequired: true);
			var xmlFileType = (string)xml.GetValue(null, null);
			if (xmlFileType == null)
			{
				xmlFileType = "xmlfile";
				xml.SetValue(null, xmlFileType);
			}

			var windows10XmlShell = Registry.ClassesRoot.OpenPath(@"SystemFileAssociations\.xml\shell");
			var xmlShell = Registry.ClassesRoot.OpenPath(xmlFileType + @"\shell");

			_RemoveContextMenuItems(
				new[] { windows10XmlShell, xmlShell },
				new[] { InstallRunMode.HtmlPreviewContextMenuName, InstallRunMode.ImagePreviewContextMenuName, InstallRunMode.PrintContextMenuName });
			
			return true;
		}

		private void _RemoveContextMenuItems(RegistryKey[] registryKey, string[] itemNames)
		{
			foreach (var key in registryKey)
			foreach (var name in itemNames)
				key.DeleteSubKeyTree(name, false);
		}
	}
}<commit_msg>UninstallRunMode: Updated to tolerate null keys<commit_after>﻿using Microsoft.Win32;
using System.Linq;

namespace DrawShip.Viewer
{
	/// <summary>
	/// Run mode for uninstalling the context menu items from windows
	/// </summary>
	public class UninstallRunMode : IRunMode
	{
		public bool Run(ApplicationContext applicationContext)
		{
			var xml = Registry.ClassesRoot.OpenKey(@".xml", createIfRequired: true);
			var xmlFileType = (string)xml.GetValue(null, null);
			if (xmlFileType == null)
			{
				xmlFileType = "xmlfile";
				xml.SetValue(null, xmlFileType);
			}

			var windows10XmlShell = Registry.ClassesRoot.OpenPath(@"SystemFileAssociations\.xml\shell");
			var xmlShell = Registry.ClassesRoot.OpenPath(xmlFileType + @"\shell");

			_RemoveContextMenuItems(
				new[] { windows10XmlShell, xmlShell },
				new[] { InstallRunMode.HtmlPreviewContextMenuName, InstallRunMode.ImagePreviewContextMenuName, InstallRunMode.PrintContextMenuName });
			
			return true;
		}

		private void _RemoveContextMenuItems(RegistryKey[] registryKey, string[] itemNames)
		{
			foreach (var key in registryKey.Where(k => k != null))
			foreach (var name in itemNames)
				key.DeleteSubKeyTree(name, false);
		}
	}
}
{'fraction_non_alphanumeric': 0.11096884336320956, 'fraction_numerical': 0.005121638924455826, 'mean_word_length': 4.4766355140186915, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 26}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7131155', 'n_tokens_mistral': 813, 'n_tokens_neox': 689, 'n_words': 159}