<commit_before>using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Xml;

namespace VSPackage.CPPCheckPlugin
{
	class ChecksPanel
	{
		private StackPanel mPanel;

		class CheckInfo
		{
			public string id;
			public string toolTip;
			public CheckBox box;
		};
		class SeverityInfo
		{
			public string id;
			public string toolTip;
			public List<CheckInfo> checks = new List<CheckInfo>();

			public CheckBox box;
			public ScrollViewer scrollView;
		};
		Dictionary<string, SeverityInfo> mChecks = new Dictionary<string, SeverityInfo>();

		public ChecksPanel(StackPanel panel)
		{
			mPanel = panel;

			LoadChecksList();
			GenerateControls();
			LoadSettings();
		}

		public void LoadSettings()
		{
			var enabledSeverities = Properties.Settings.Default.SeveritiesString.Split(',');
			HashSet<string> suppressions = new HashSet<string>(Properties.Settings.Default.SuppressionsString.Split(','));
			
			foreach (var severity in mChecks)
			{
				severity.Value.scrollView.IsEnabled = false;
				foreach (CheckInfo check in severity.Value.checks)
				{
					check.box.IsChecked = suppressions.Contains(check.id) == false;
				}
			}

			foreach (var severity in enabledSeverities)
			{
				if (mChecks.ContainsKey(severity))
				{
					mChecks[severity].box.IsChecked = true;
					mChecks[severity].scrollView.IsEnabled = true;
				}
			}
		}

		private string GetSeveritiesString()
		{
			string result = "";
			foreach (var severity in mChecks)
			{
				if (severity.Value.box.IsChecked == true)
				{
					if (result.Length != 0)
						result += ",";
					result += severity.Value.id;
				}
			}
			return result;
		}

		private string GetSuppressionsString()
		{
			string result = "";
			foreach (var severity in mChecks)
			{
				foreach (CheckInfo check in severity.Value.checks)
				{
					if (check.box.IsChecked == false)
					{
						if (result.Length != 0)
							result += ",";
						result += check.id;
					}
				}
			}
			return result;
		}

		private void LoadChecksList()
		{
			// TODO: generate xml file by running next command:
			// cppcheck --errorlist --xml-version=2

			System.Xml.XmlDocument checksList = new System.Xml.XmlDocument();
			checksList.Load(@"C:\Users\Altren\Documents\checksList.xml");

			foreach (XmlNode node in checksList.SelectNodes("//errors/error"))
			{
				string id = node.Attributes["id"].Value;
				string severity = node.Attributes["severity"].Value;
				string message = node.Attributes["msg"].Value;
				string verboseMessage = node.Attributes["verbose"].Value;

				if (!mChecks.ContainsKey(severity))
					mChecks.Add(severity, new SeverityInfo { id = severity, toolTip = "TODO" });

				mChecks[severity].checks.Add(new CheckInfo { id = id, toolTip = verboseMessage });
			}<commit_msg>fix hardcoded checks list path (#30)<commit_after>using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Xml;

namespace VSPackage.CPPCheckPlugin
{
	class ChecksPanel
	{
		private StackPanel mPanel;

		class CheckInfo
		{
			public string id;
			public string toolTip;
			public CheckBox box;
		};
		class SeverityInfo
		{
			public string id;
			public string toolTip;
			public List<CheckInfo> checks = new List<CheckInfo>();

			public CheckBox box;
			public ScrollViewer scrollView;
		};
		Dictionary<string, SeverityInfo> mChecks = new Dictionary<string, SeverityInfo>();

		public ChecksPanel(StackPanel panel)
		{
			mPanel = panel;

			LoadChecksList();
			GenerateControls();
			LoadSettings();
		}

		public void LoadSettings()
		{
			var enabledSeverities = Properties.Settings.Default.SeveritiesString.Split(',');
			HashSet<string> suppressions = new HashSet<string>(Properties.Settings.Default.SuppressionsString.Split(','));
			
			foreach (var severity in mChecks)
			{
				severity.Value.scrollView.IsEnabled = false;
				foreach (CheckInfo check in severity.Value.checks)
				{
					check.box.IsChecked = suppressions.Contains(check.id) == false;
				}
			}

			foreach (var severity in enabledSeverities)
			{
				if (mChecks.ContainsKey(severity))
				{
					mChecks[severity].box.IsChecked = true;
					mChecks[severity].scrollView.IsEnabled = true;
				}
			}
		}

		private string GetSeveritiesString()
		{
			string result = "";
			foreach (var severity in mChecks)
			{
				if (severity.Value.box.IsChecked == true)
				{
					if (result.Length != 0)
						result += ",";
					result += severity.Value.id;
				}
			}
			return result;
		}

		private string GetSuppressionsString()
		{
			string result = "";
			foreach (var severity in mChecks)
			{
				foreach (CheckInfo check in severity.Value.checks)
				{
					if (check.box.IsChecked == false)
					{
						if (result.Length != 0)
							result += ",";
						result += check.id;
					}
				}
			}
			return result;
		}

		private void LoadChecksList()
		{
			System.Diagnostics.Process p = new System.Diagnostics.Process();
			p.StartInfo.UseShellExecute = false;
			p.StartInfo.RedirectStandardOutput = true;
			p.StartInfo.FileName = Properties.Settings.Default.CPPcheckPath;
			p.StartInfo.Arguments = "--errorlist --xml-version=2";
			p.Start();
			string output = p.StandardOutput.ReadToEnd();
			p.WaitForExit();

			System.Xml.XmlDocument checksList = new System.Xml.XmlDocument();
			checksList.LoadXml(output);

			foreach (XmlNode node in checksList.SelectNodes("//errors/error"))
			{
				string id = node.Attributes["id"].Value;
				string severity = node.Attributes["severity"].Value;
				string message = node.Attributes["msg"].Value;
				string verboseMessage = node.Attributes["verbose"].Value;

				if (!mChecks.ContainsKey(severity))
					mChecks.Add(severity, new SeverityInfo { id = severity, toolTip = "TODO" });

				mChecks[severity].checks.Add(new CheckInfo { id = id, toolTip = verboseMessage });
			}
{'fraction_non_alphanumeric': 0.11908841672378341, 'fraction_numerical': 0.0013708019191226869, 'mean_word_length': 3.2636961285609933, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '2107890', 'n_tokens_mistral': 2306, 'n_tokens_neox': 1779, 'n_words': 398}