<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Media;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Gmail.v1;
using Google.Apis.Gmail.v1.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using HtmlAgilityPack;
using Microsoft.Win32;
using notifier.Languages;
using notifier.Properties;

namespace notifier {
	public partial class Main : Form {

		// privacy possibilities
		private enum Privacy : uint {
			None = 0,
			Short = 1,
			All = 2
		}

		// update period possibilities
		private enum Period : uint {
			Startup = 0,
			Day = 1,
			Week = 2,
			Month = 3
		}

		// gmail api service
		private GmailService service;

		// user credential for the gmail authentication
		private UserCredential credential;

		// inbox label
		private Google.Apis.Gmail.v1.Data.Label inbox;

		// unread threads
		private int? unreadthreads = 0;

		// number of automatic reconnection
		private uint reconnect = 0;

		// last synchronization time
		private DateTime synctime = DateTime.Now;

		// local application data folder name
		private string appdata = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "/Gmail Notifier";

		// version number
		private string version = "";

		// flag defining the update state
		private bool updating = false;

		// http client used to check for updates
		private HttpClient http = new HttpClient();

		// number of maximum automatic reconnection
		private const int MAX_AUTO_RECONNECT = 3;

		// number in seconds between reconnections (in seconds)
		private const int INTERVAL_RECONNECT = 10;

		// github repository root link
		private const string GITHUB_REPOSITORY = "https://github.com/xavierfoucrier/gmail-notifier";

		// gmail base root link
		private const string GMAIL_BASEURL = "https://mail.google.com/mail/u/0";

		/// <summary>
		/// Initializes the class
		/// </summary>
		public Main() {
			InitializeComponent();
		}

		/// <summary>
		/// Loads the form
		/// </summary>
		private void Main_Load(object sender, EventArgs e) {

			// hides the form by default
			Visible = false;

			// upgrades the user configuration if necessary
			if (Settings.Default.UpdateRequired) {
				Settings.Default.Upgrade();

				// switches the update required state
				Settings.Default.UpdateRequired = false;
				Settings.Default.Save();

				// cleans temporary update files from previous upgrade
				if (Directory.Exists(appdata)) {
					IEnumerable<string> executables = Directory.EnumerateFiles(appdata, "*.exe", SearchOption.TopDirectoryOnly);

					foreach (string executable in executables) {
						File.Delete(executable);
					}
				}
			}

			// initializes the application version number
			string[] version = Application.ProductVersion.Split('.');
			this.version = "v" + version[0] + "." + version[1] + "-" + (version[2] == "0" ? "alpha" : version[2] == "1" ? "beta" : version[2] == "2" ? "rc" : version[2] == "3" ? "release" : "") + (version[3] != "0" ? "." + version[3] : "");

			// displays a systray notification on first load
			if (Settings.Default.FirstLoad && !Directory.Exists(this.appdata)) {
				notifyIcon.ShowBalloonTip(7000, translation.welcome, translation.firstLoad, ToolTipIcon.Info);<commit_msg>Fixes lock setup<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Media;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Gmail.v1;
using Google.Apis.Gmail.v1.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using HtmlAgilityPack;
using Microsoft.Win32;
using notifier.Languages;
using notifier.Properties;

namespace notifier {
	public partial class Main : Form {

		// privacy possibilities
		private enum Privacy : uint {
			None = 0,
			Short = 1,
			All = 2
		}

		// update period possibilities
		private enum Period : uint {
			Startup = 0,
			Day = 1,
			Week = 2,
			Month = 3
		}

		// gmail api service
		private GmailService service;

		// user credential for the gmail authentication
		private UserCredential credential;

		// inbox label
		private Google.Apis.Gmail.v1.Data.Label inbox;

		// unread threads
		private int? unreadthreads = 0;

		// number of automatic reconnection
		private uint reconnect = 0;

		// last synchronization time
		private DateTime synctime = DateTime.Now;

		// local application data folder name
		private string appdata = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "/Gmail Notifier";

		// version number
		private string version = "";

		// flag defining the update state
		private bool updating = false;

		// http client used to check for updates
		private HttpClient http = new HttpClient();

		// number of maximum automatic reconnection
		private const int MAX_AUTO_RECONNECT = 3;

		// number in seconds between reconnections (in seconds)
		private const int INTERVAL_RECONNECT = 10;

		// github repository root link
		private const string GITHUB_REPOSITORY = "https://github.com/xavierfoucrier/gmail-notifier";

		// gmail base root link
		private const string GMAIL_BASEURL = "https://mail.google.com/mail/u/0";

		/// <summary>
		/// Initializes the class
		/// </summary>
		public Main() {
			InitializeComponent();
		}

		/// <summary>
		/// Loads the form
		/// </summary>
		private void Main_Load(object sender, EventArgs e) {

			// hides the form by default
			Visible = false;

			// upgrades the user configuration if necessary
			if (Settings.Default.UpdateRequired) {
				Settings.Default.Upgrade();

				// switches the update required state
				Settings.Default.UpdateRequired = false;
				Settings.Default.Save();

				// cleans temporary update files from previous upgrade
				if (Directory.Exists(appdata)) {
					IEnumerable<string> executables = Directory.EnumerateFiles(appdata, "*.exe", SearchOption.TopDirectoryOnly);

					foreach (string executable in executables) {
						try {
							File.Delete(executable);
						} catch(Exception) {
							// nothing to catch: executable is currently locked
							// setup package will be removed next time
						}
					}
				}
			}

			// initializes the application version number
			string[] version = Application.ProductVersion.Split('.');
			this.version = "v" + version[0] + "." + version[1] + "-" + (version[2] == "0" ? "alpha" : version[2] == "1" ? "beta" : version[2] == "2" ? "rc" : version[2] == "3" ? "release" : "") + (version[3] != "0" ? "." + version[3] : "");

			// displays a systray notification on first load
			if (Settings.Default.FirstLoad && !Directory.Exists(this.appdata)) {
				notifyIcon.ShowBalloonTip(7000, translation.welcome, translation.firstLoad, ToolTipIcon.Info);
{'fraction_non_alphanumeric': 0.11272075055187639, 'fraction_numerical': 0.009933774834437087, 'mean_word_length': 3.4913258983890954, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 4, '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': '1588951', 'n_tokens_mistral': 2451, 'n_tokens_neox': 2093, 'n_words': 625}