<commit_before>﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Text.RegularExpressions;
using System.Net;

namespace Slidecopy
{
    public partial class FormSettings : Form
    {
        private bool gotData = false;
        private string code, ip, port;

        public FormSettings()
        {
            InitializeComponent();
            // initialize notifyIcon
            notifyIcon.DoubleClick += new EventHandler(notifyIcon_DoubleClick);

            // if they exist, load previously saved values from registry
            RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Software\Slidecopy");
            if (regKey != null)
            {
                code = (string) regKey.GetValue("code");
                ip = (string) regKey.GetValue("ip");
                port = (string) regKey.GetValue("port");
                textBoxCode.Text = code;
                textBoxIP.Text = ip;
                textBoxPort.Text = port;
                gotData = true;
            } else
            {
                // otherwise, show form to let user enter required data
                Show();
            }
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            if (e.CloseReason != CloseReason.UserClosing) return;
            // if the user closed the window, don't exit and hide instead
            e.Cancel = true;
            Hide();
        }

        void notifyIcon_DoubleClick(object sender, EventArgs e)
        {
            if (gotData)
            {
                // build request
                string url = @"http://" + ip + @":" + port + @"/photo/" + code + @".jpg";
                WebRequest request = WebRequest.Create(url);
                // show downloading notification
                notifyIcon.ShowBalloonTip(0, null, "Downloading image...", ToolTipIcon.Info);
                try
                { 
                    WebResponse response = request.GetResponse();
                    System.IO.Stream responseStream = response.GetResponseStream();
                    // build bitmap from downloaded data
                    Bitmap image = new Bitmap(responseStream);
                    // put image in clipboard
                    Clipboard.SetImage(image);
                    // release bitmap
                    image.Dispose();
                    // ugly hack to clear old balloonTip
                    notifyIcon.Visible = false;
                    notifyIcon.Visible = true;
                    notifyIcon.ShowBalloonTip(0, null, "Download complete", ToolTipIcon.Info);
                } catch (WebException)
                {
                    // ugly hack to clear old balloonTip
                    notifyIcon.Visible = false;
                    notifyIcon.Visible = true;
                    notifyIcon.ShowBalloonTip(0, null, "Download failed", ToolTipIcon.Error);
                }
            } else
            {
                // if no server settings available, show input form to user
                Show();
            }
        }

        private void toolStripMenuItemExit_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.Application.Exit();
        }

        private void toolStripMenuItemSettings_Click(object sender, EventArgs e)
        {
            // show form
            Show();
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            gotData = false;
            // check input for errors<commit_msg>Make sure notifyIcon is gone, even if Windows is bugged<commit_after>﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Text.RegularExpressions;
using System.Net;

namespace Slidecopy
{
    public partial class FormSettings : Form
    {
        private bool gotData = false;
        private string code, ip, port;

        public FormSettings()
        {
            InitializeComponent();
            // initialize notifyIcon
            notifyIcon.DoubleClick += new EventHandler(notifyIcon_DoubleClick);

            // if they exist, load previously saved values from registry
            RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Software\Slidecopy");
            if (regKey != null)
            {
                code = (string) regKey.GetValue("code");
                ip = (string) regKey.GetValue("ip");
                port = (string) regKey.GetValue("port");
                textBoxCode.Text = code;
                textBoxIP.Text = ip;
                textBoxPort.Text = port;
                gotData = true;
            } else
            {
                // otherwise, show form to let user enter required data
                Show();
            }
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            if (e.CloseReason != CloseReason.UserClosing) return;
            // if the user closed the window, don't exit and hide instead
            e.Cancel = true;
            Hide();
        }

        void notifyIcon_DoubleClick(object sender, EventArgs e)
        {
            if (gotData)
            {
                // build request
                string url = @"http://" + ip + @":" + port + @"/photo/" + code + @".jpg";
                WebRequest request = WebRequest.Create(url);
                // show downloading notification
                notifyIcon.ShowBalloonTip(0, null, "Downloading image...", ToolTipIcon.Info);
                try
                { 
                    WebResponse response = request.GetResponse();
                    System.IO.Stream responseStream = response.GetResponseStream();
                    // build bitmap from downloaded data
                    Bitmap image = new Bitmap(responseStream);
                    // put image in clipboard
                    Clipboard.SetImage(image);
                    // release bitmap
                    image.Dispose();
                    // ugly hack to clear old balloonTip
                    notifyIcon.Visible = false;
                    notifyIcon.Visible = true;
                    notifyIcon.ShowBalloonTip(0, null, "Download complete", ToolTipIcon.Info);
                } catch (WebException)
                {
                    // ugly hack to clear old balloonTip
                    notifyIcon.Visible = false;
                    notifyIcon.Visible = true;
                    notifyIcon.ShowBalloonTip(0, null, "Download failed", ToolTipIcon.Error);
                }
            } else
            {
                // if no server settings available, show input form to user
                Show();
            }
        }

        private void toolStripMenuItemExit_Click(object sender, EventArgs e)
        {
            // make sure it doesn't buggily hang around after the application is closed - thanks Windows!
            notifyIcon.Visible = false;
            // exit
            System.Windows.Forms.Application.Exit();
        }

        private void toolStripMenuItemSettings_Click(object sender, EventArgs e)
        {
            // show form
            Show();
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            gotData = false;
            // check input for errors
{'fraction_non_alphanumeric': 0.08176358176358177, 'fraction_numerical': 0.001365001365001365, 'mean_word_length': 1.4078212290502794, 'pattern_counts': {'":': 2, '<': 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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '211729', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1639, 'n_words': 477}