<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Microsoft.WindowsAPICodePack.Dialogs;

namespace ZeroMunge
{
	public partial class EasyFilePicker : Form
	{
		public EasyFilePicker()
		{
			InitializeComponent();
		}

		private Dictionary<int, string> rootPaths = new Dictionary<int, string>();
		private int curRoot = 0;
		public List<string> mungeFilePaths = new List<string>();


		private void EasyFilePicker_Load(object sender, EventArgs e)
		{
			Prompt_AddProject();
		}

		private void EasyFilePicker_FormClosed(object sender, FormClosedEventArgs e)
		{

		}

		private void btn_Accept_Click(object sender, EventArgs e)
		{
			List<TreeNode> selectedNodes = tv_Files.Nodes.Descendants()
				.Where(n => n.Checked)
				.ToList();

			foreach (TreeNode node in selectedNodes)
			{
				string nodePath = node.FullPath;
				string buildPath = "\\_BUILD";
				string fileName = "\\munge.bat";
				if (nodePath.EndsWith("addme", StringComparison.CurrentCultureIgnoreCase))
				{
					buildPath = "";
					fileName = "mungeAddme.bat";
				}
				string partialPath = nodePath.Substring(nodePath.IndexOf('\\'), nodePath.Length - nodePath.IndexOf('\\'));
				string filePath = rootPaths[GetRootNode(node).Index] + buildPath + partialPath + fileName;

				// Add the file to the file list if it exists and is not a template munge script
				if (File.Exists(filePath) 
					&& !filePath.EndsWith("\\_BUILD\\munge.bat") 
					&& !filePath.EndsWith("\\_BUILD\\Sides\\munge.bat") 
					&& !filePath.EndsWith("\\_BUILD\\Worlds\\munge.bat"))
				{
					mungeFilePaths.Add(filePath);
				}
			}

			// Close the form
			Close();
		}

		private void btn_Cancel_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void btn_AddProject_Click(object sender, EventArgs e)
		{
			Prompt_AddProject();
		}

		private void tv_Files_AfterCheck(object sender, TreeViewEventArgs e)
		{
			// TODO: check/uncheck all children (and subchildren etc.)
		}

		private void Prompt_AddProject()
		{
			CommonOpenFileDialog openDlg_AddProjectPrompt = new CommonOpenFileDialog
			{
				Title = "Select Project Folder",
				InitialDirectory = "J:\\BF2_ModTools",
				IsFolderPicker = true,
				RestoreDirectory = true
			};

			// Auto-detect the munge.bat file inside each selected folder and add it to the file list
			if (openDlg_AddProjectPrompt.ShowDialog() == CommonFileDialogResult.Ok)
			{
				string path = openDlg_AddProjectPrompt.FileName;
				rootPaths.Add(curRoot, path);
				curRoot++;
<commit_msg>#36: Add functionality to check/uncheck child nodes when a node is checked/unchecked<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Microsoft.WindowsAPICodePack.Dialogs;

namespace ZeroMunge
{
	public partial class EasyFilePicker : Form
	{
		public EasyFilePicker()
		{
			InitializeComponent();
		}

		private Dictionary<int, string> rootPaths = new Dictionary<int, string>();
		private int curRoot = 0;
		public List<string> mungeFilePaths = new List<string>();


		private void EasyFilePicker_Load(object sender, EventArgs e)
		{
			Prompt_AddProject();
		}

		private void EasyFilePicker_FormClosed(object sender, FormClosedEventArgs e)
		{

		}

		private void btn_Accept_Click(object sender, EventArgs e)
		{
			List<TreeNode> selectedNodes = tv_Files.Nodes.Descendants()
				.Where(n => n.Checked)
				.ToList();

			foreach (TreeNode node in selectedNodes)
			{
				string nodePath = node.FullPath;
				string buildPath = "\\_BUILD";
				string fileName = "\\munge.bat";
				if (nodePath.EndsWith("addme", StringComparison.CurrentCultureIgnoreCase))
				{
					buildPath = "";
					fileName = "mungeAddme.bat";
				}
				string partialPath = nodePath.Substring(nodePath.IndexOf('\\'), nodePath.Length - nodePath.IndexOf('\\'));
				string filePath = rootPaths[GetRootNode(node).Index] + buildPath + partialPath + fileName;

				// Add the file to the file list if it exists and is not a template munge script
				if (File.Exists(filePath) 
					&& !filePath.EndsWith("\\_BUILD\\munge.bat") 
					&& !filePath.EndsWith("\\_BUILD\\Sides\\munge.bat") 
					&& !filePath.EndsWith("\\_BUILD\\Worlds\\munge.bat"))
				{
					mungeFilePaths.Add(filePath);
				}
			}

			// Close the form
			Close();
		}

		private void btn_Cancel_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void btn_AddProject_Click(object sender, EventArgs e)
		{
			Prompt_AddProject();
		}

		private void tv_Files_AfterCheck(object sender, TreeViewEventArgs e)
		{
			// Check/uncheck child nodes
			TreeNode node = e.Node;
			if (node.Nodes.Count > 0)
			{
				foreach (TreeNode childNode in node.Nodes)
				{
					childNode.Checked = e.Node.Checked;
				}
			}
		}

		private void Prompt_AddProject()
		{
			CommonOpenFileDialog openDlg_AddProjectPrompt = new CommonOpenFileDialog
			{
				Title = "Select Project Folder",
				InitialDirectory = "J:\\BF2_ModTools",
				IsFolderPicker = true,
				RestoreDirectory = true
			};

			// Auto-detect the munge.bat file inside each selected folder and add it to the file list
			if (openDlg_AddProjectPrompt.ShowDialog() == CommonFileDialogResult.Ok)
			{
				string path = openDlg_AddProjectPrompt.FileName;
				rootPaths.Add(curRoot, path);
				curRoot++;

{'fraction_non_alphanumeric': 0.11057434245840043, 'fraction_numerical': 0.0012524601896582574, 'mean_word_length': 3.616019818331957, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3376712', 'n_tokens_mistral': 2073, 'n_tokens_neox': 1739, 'n_words': 418}