<commit_before>﻿using System;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.Drawing;

namespace unison_notifier
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();

      unisonProcess.StartInfo.FileName = "unison.exe";
      unisonProcess.StartInfo.RedirectStandardError = true;
      unisonProcess.StartInfo.UseShellExecute = false;
      unisonProcess.StartInfo.CreateNoWindow = true;

      Load += new EventHandler(Form1_Load);
      Resize += new EventHandler(Form1_Resize);
      FormClosing += new FormClosingEventHandler(Form1_Closing);

      ContextMenu contextMenu = new ContextMenu();
      MenuItem logMenuItem = new MenuItem(),
        settingsMenuItem = new MenuItem(),
        exitMenuItem = new MenuItem();

      logMenuItem.Text = "Log";
      logMenuItem.Click += new EventHandler(logMenuItem_Click);
      contextMenu.MenuItems.Add(logMenuItem);

      settingsMenuItem.Text = "Settings";
      settingsMenuItem.Click += new EventHandler(settingsMenuItem_Click);
      contextMenu.MenuItems.Add(settingsMenuItem);

      contextMenu.MenuItems.Add("-");

      exitMenuItem.Text = "Exit";
      exitMenuItem.Click += new EventHandler(exitMenuItem_Click);
      contextMenu.MenuItems.Add(exitMenuItem);

      notifyIcon1.MouseClick += new MouseEventHandler(notifyIcon1_MouseClick);
      notifyIcon1.ContextMenu = contextMenu;

      notifierThread = new Thread(notifier);
      notifierThread.Start();
    }

    private Process unisonProcess = new Process();
    private Thread notifierThread;
    private ManualResetEvent notifierResetEvent = new ManualResetEvent(false);
    private string log;
    private bool terminate = false, firstTimeShown = true;
    private delegate void notifyDelegate(Icon icon, string title, string text);
    private delegate void updateLogDelegate();
    private delegate void clearLogDelegate();

    private void notifier()
    {
      while (!terminate)
      {
        unisonProcess.Start();

        while (!unisonProcess.HasExited && !terminate)
        {
          string line = unisonProcess.StandardError.ReadLine();
          
          if (line != null)
          {
            if (line.Contains("Nothing to do"))
            {
              safeInvoke(new notifyDelegate(notify), Properties.Resources.SyncedIcon, "Synced", "Unison is connected and synced.");
            }
            else if (line.Contains("Propagating updates"))
            {
              safeInvoke(new notifyDelegate(notify), Properties.Resources.SyncingIcon, "Syncing", "Unison is syncing files...");
            }

            log = line + Environment.NewLine;
            safeInvoke(new updateLogDelegate(updateLog));
          }
        }

        safeInvoke(new notifyDelegate(notify), Properties.Resources.ErrorIcon, "Disconnected", "Unison has lost connection.");
        notifierResetEvent.WaitOne(10000);
        safeInvoke(new clearLogDelegate(clearLog));
      }
    }

    private void safeInvoke(Delegate method, params object[] args)
    {
      if (!terminate)
      {
        Invoke(method, args);
      }
    }

    private void notify(Icon icon, string title, string text)
    {
      notifyIcon1.Icon = icon;
      notifyIcon1.BalloonTipTitle = title;
      notifyIcon1.BalloonTipText = text;
    }

    private void updateLog()
    {
      richTextBox1.AppendText(log);
    }

    private void clearLog()
    {
      richTextBox1.Clear();
    }

    private void logMenuItem_Click(object sender, EventArgs e)
    {
      if (firstTimeShown)
      {
        firstTimeShown = false;<commit_msg>Removed unnecessary class attribute<commit_after>﻿using System;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.Drawing;

namespace unison_notifier
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();

      unisonProcess.StartInfo.FileName = "unison.exe";
      unisonProcess.StartInfo.RedirectStandardError = true;
      unisonProcess.StartInfo.UseShellExecute = false;
      unisonProcess.StartInfo.CreateNoWindow = true;

      Load += new EventHandler(Form1_Load);
      Resize += new EventHandler(Form1_Resize);
      FormClosing += new FormClosingEventHandler(Form1_Closing);

      ContextMenu contextMenu = new ContextMenu();
      MenuItem logMenuItem = new MenuItem(),
        settingsMenuItem = new MenuItem(),
        exitMenuItem = new MenuItem();

      logMenuItem.Text = "Log";
      logMenuItem.Click += new EventHandler(logMenuItem_Click);
      contextMenu.MenuItems.Add(logMenuItem);

      settingsMenuItem.Text = "Settings";
      settingsMenuItem.Click += new EventHandler(settingsMenuItem_Click);
      contextMenu.MenuItems.Add(settingsMenuItem);

      contextMenu.MenuItems.Add("-");

      exitMenuItem.Text = "Exit";
      exitMenuItem.Click += new EventHandler(exitMenuItem_Click);
      contextMenu.MenuItems.Add(exitMenuItem);

      notifyIcon1.MouseClick += new MouseEventHandler(notifyIcon1_MouseClick);
      notifyIcon1.ContextMenu = contextMenu;

      notifierThread = new Thread(notifier);
      notifierThread.Start();
    }

    private Process unisonProcess = new Process();
    private Thread notifierThread;
    private ManualResetEvent notifierResetEvent = new ManualResetEvent(false);
    private bool terminate = false, firstTimeShown = true;
    private delegate void notifyDelegate(Icon icon, string title, string text);
    private delegate void updateLogDelegate(string line);
    private delegate void clearLogDelegate();

    private void notifier()
    {
      while (!terminate)
      {
        unisonProcess.Start();

        while (!unisonProcess.HasExited && !terminate)
        {
          string line = unisonProcess.StandardError.ReadLine();
          
          if (line != null)
          {
            if (line.Contains("Nothing to do"))
            {
              safeInvoke(new notifyDelegate(notify), Properties.Resources.SyncedIcon, "Synced", "Unison is connected and synced.");
            }
            else if (line.Contains("Propagating updates"))
            {
              safeInvoke(new notifyDelegate(notify), Properties.Resources.SyncingIcon, "Syncing", "Unison is syncing files...");
            }

            safeInvoke(new updateLogDelegate(updateLog), line + Environment.NewLine);
          }
        }

        safeInvoke(new notifyDelegate(notify), Properties.Resources.ErrorIcon, "Disconnected", "Unison has lost connection.");
        notifierResetEvent.WaitOne(10000);
        safeInvoke(new clearLogDelegate(clearLog));
      }
    }

    private void safeInvoke(Delegate method, params object[] args)
    {
      if (!terminate)
      {
        Invoke(method, args);
      }
    }

    private void notify(Icon icon, string title, string text)
    {
      notifyIcon1.Icon = icon;
      notifyIcon1.BalloonTipTitle = title;
      notifyIcon1.BalloonTipText = text;
    }

    private void updateLog(string line)
    {
      richTextBox1.AppendText(line);
    }

    private void clearLog()
    {
      richTextBox1.Clear();
    }

    private void logMenuItem_Click(object sender, EventArgs e)
    {
      if (firstTimeShown)
      {
        firstTimeShown = false;
{'fraction_non_alphanumeric': 0.09454843557863096, 'fraction_numerical': 0.0049187047410848474, 'mean_word_length': 2.8506049447659128, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3067907', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1919, 'n_words': 438}