<commit_before>﻿using System;
using System.IO;
using System.Windows.Forms;

using Kyru.Core;
using Kyru.Network.Objects;
using System.Threading;

namespace Kyru
{
	public partial class KyruForm : Form
	{
		private Session session;

		internal KyruForm(Session session)
		{
			this.session = session;
			InitializeComponent();

			virtualLocalFileTreeInit();
			Text = session.Username + " - " + Text;

			session.User.OnFileAdded += new Action<UserFile>(showFile);
		}

		internal void virtualLocalFileTreeInit()
		{
			foreach (var fileToShow in session.User.Files)
			{
				showFile(fileToShow);
			}
		}

		internal void showFile(UserFile fileToShow)
		{
			string fileName = session.DecryptFileName(fileToShow);
			var dirs = fileName.Split('\\');
			TreeNode node = null;
			TreeNodeCollection nodes = virtualLocalFileTree.Nodes;
			foreach (var dir in dirs)
			{
				if (nodes.ContainsKey(dir))
				{
					node = nodes[dir];
				}
				else
				{
					node = nodes.Add(dir, dir);
					// TODO: Add images
				}
				nodes = node.Nodes;
			}
			node.Tag = fileToShow;
		}

		private void addAFileToolStripMenuItem_Click(object sender, EventArgs e)
		{
			var dialog = new OpenFileDialog();
			dialog.Multiselect = true;
			Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
			dialog.ShowDialog();
			foreach (string filename in dialog.FileNames)
			{
				try
				{
					using (var fs = new FileStream(filename, FileMode.Open))
					{
						session.AddFile(fs, filename);
					}
				}
				catch (IOException ex)
				{
					Console.WriteLine(ex.Message);
					MessageBox.Show("Could not add file " + filename);
				}
			}
		}

		private void virtualLocalFileTree_MouseUp(object sender, MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right)
			{
				// Select the clicked node
				virtualLocalFileTree.SelectedNode = virtualLocalFileTree.GetNodeAt(e.X, e.Y);<commit_msg>Using relative file names in the form<commit_after>﻿using System;
using System.IO;
using System.Windows.Forms;

using Kyru.Core;
using Kyru.Network.Objects;
using System.Threading;

namespace Kyru
{
	public partial class KyruForm : Form
	{
		private Session session;

		internal KyruForm(Session session)
		{
			this.session = session;
			InitializeComponent();

			virtualLocalFileTreeInit();
			Text = session.Username + " - " + Text;

			session.User.OnFileAdded += new Action<UserFile>(showFile);
		}

		internal void virtualLocalFileTreeInit()
		{
			foreach (var fileToShow in session.User.Files)
			{
				showFile(fileToShow);
			}
		}

		internal void showFile(UserFile fileToShow)
		{
			string fileName = session.DecryptFileName(fileToShow);
			Console.Write("showing file" + fileName);
			var dirs = fileName.Split('\\');
			TreeNode node = null;
			TreeNodeCollection nodes = virtualLocalFileTree.Nodes;
			foreach (var dir in dirs)
			{
				if (nodes.ContainsKey(dir))
				{
					node = nodes[dir];
				}
				else
				{
					node = nodes.Add(dir, dir);
					// TODO: Add images
				}
				nodes = node.Nodes;
			}
			node.Tag = fileToShow;
		}

		private void addAFileToolStripMenuItem_Click(object sender, EventArgs e)
		{
			var dialog = new OpenFileDialog();
			dialog.Multiselect = true;
			Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
			dialog.ShowDialog();
			foreach (string filename in dialog.FileNames)
			{
				try
				{
					using (var fs = new FileStream(filename, FileMode.Open))
					{
						var splitted = filename.Split('\\');
						session.AddFile(fs, splitted[splitted.Length - 1]);
					}
				}
				catch (IOException ex)
				{
					Console.WriteLine(ex.Message);
					MessageBox.Show("Could not add file " + filename);
				}
			}
		}

		private void virtualLocalFileTree_MouseUp(object sender, MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right)
			{
				// Select the clicked node
				virtualLocalFileTree.SelectedNode = virtualLocalFileTree.GetNodeAt(e.X, e.Y);
{'fraction_non_alphanumeric': 0.10749936012285641, 'fraction_numerical': 0.0002559508574353724, 'mean_word_length': 3.139830508474576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '571151', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1230, 'n_words': 278}