<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Steam4NET;

namespace SteamBulkActivator
{
    public partial class MainForm : Form
    {
        private const int HT_CAPTION = 0x2;
        private const int WM_NCLBUTTONDOWN = 0xA1;
        private const int _eM_SETCUEBANNER = 0x1501;

        private int _user, _pipe;
        private bool _enableRegexChecking = true;
        private bool _waitingForActivationResp = false;

        private ISteam006 _steam006;
        private IClientEngine _clientEngine;
        private IClientBilling _clientBilling;
        private ISteamClient012 _steamClient012;

        private Result _result;
        private List<string> _cdKeyList;
        private BackgroundWorker _callbackBwg;
        private BackgroundWorker _purchaseBwg;

        protected override CreateParams CreateParams
        {
            get
            {
                const int CS_DROPSHADOW = 0x20000;
                CreateParams cp = base.CreateParams;
                cp.ClassStyle |= CS_DROPSHADOW;
                return cp;
            }
        }

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            if (connectToSteam())
            {
                panelMain.Visible = true;
                panelLoading.Visible = false;
                _cdKeyList = new List<string>();
                this.ActiveControl = lblKeyCount;
                NativeMethods.SendMessage(txtKeys.Handle, _eM_SETCUEBANNER, IntPtr.Zero, "6EZ77-35QQY-9BTT8");

                _callbackBwg = new BackgroundWorker() { WorkerSupportsCancellation = true };
                _callbackBwg.DoWork += _callbacks_DoWork;
                _callbackBwg.RunWorkerCompleted += _callbacks_RunWorkerCompleted;
                _callbackBwg.RunWorkerAsync();

                _purchaseBwg = new BackgroundWorker();
                _purchaseBwg.DoWork += _purchaseBwg_DoWork;
            }
        }

        private void panelHeader_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                NativeMethods.ReleaseCapture();
                NativeMethods.SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
            }
        }

        private void MainForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                NativeMethods.ReleaseCapture();
                NativeMethods.SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
            }
        }

        private void linkGithub_Click(object sender, EventArgs e)
        {
            Process.Start("https://github.com/Ezzpify");
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            if (_callbackBwg.IsBusy)
                _callbackBwg.CancelAsync();

            Environment.Exit(1);
        }

        private void btnMinimize_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void btnRegister_Click(object sender, EventArgs e)
        {
            if (_cdKeyList.Count == 0)
            {
                if (_enableRegexChecking && !string.IsNullOrWhiteSpace(txtKeys.Text))
                {
                    string chk = "No keys passed the validity check. If you are certain that the keys you have inputted"
                        + " are valid, then you can disable the validity check for cd-keys by pressing Yes.";

                    var diagRes = MessageBox.Show(chk, "No valid keys", MessageBoxButtons.YesNo);
                    if (diagRes == DialogResult.Yes)
                    {
                        _enableRegexChecking = false;
                        addKeysToList();
                    }
                }
                else
                {
                    MessageBox.Show("No keys added.", "Error");
                }
            }
            else
            {
                _result = new Result(_cdKeyList);
                _result.Show();

                _purchaseBwg.RunWorkerAsync(_cdKeyList);
            }
        }

        private void txtKeys_Enter(object sender, EventArgs e)
        {
            txtKeys.Multiline = true;
        }

        private void btnClose_MouseEnter(object sender, EventArgs e)
        {
            btnClose.ForeColor = Color.FromArgb(255, 255, 255);
        }

        private void btnClose_MouseLeave(object sender, EventArgs e)
        {
            btnClose.ForeColor = Color.FromArgb(224, 224, 224);
        }

        private void btnMinimize_MouseEnter(object sender, EventArgs e)
        {
            btnMinimize.ForeColor = Color.FromArgb(255, 255, 255);
        }

        private void btnMinimize_MouseLeave(object sender, EventArgs e)
        {
            btnMinimize.ForeColor = Color.FromArgb(224, 224, 224);
        }

        private void _purchaseBwg_DoWork(object sender, DoWorkEventArgs e)
        {
            var cdkeys = (List<string>)e.Argument;
            foreach (var pchActivationCode in cdkeys)
            {
                _clientBilling.PurchaseWithActivationCode(pchActivationCode);

                while (_waitingForActivationResp)
                    Thread.Sleep(100);
            }
        }

        private void _callbacks_DoWork(object sender, DoWorkEventArgs e)
        {
            CallbackMsg_t callbackMsg = new CallbackMsg_t();<commit_msg>Added a wait period between each key<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Steam4NET;

namespace SteamBulkActivator
{
    public partial class MainForm : Form
    {
        private const int HT_CAPTION = 0x2;
        private const int WM_NCLBUTTONDOWN = 0xA1;
        private const int _eM_SETCUEBANNER = 0x1501;

        private int _user, _pipe;
        private bool _enableRegexChecking = true;
        private bool _waitingForActivationResp = false;

        private ISteam006 _steam006;
        private IClientEngine _clientEngine;
        private IClientBilling _clientBilling;
        private ISteamClient012 _steamClient012;

        private Result _result;
        private List<string> _cdKeyList;
        private BackgroundWorker _callbackBwg;
        private BackgroundWorker _purchaseBwg;

        protected override CreateParams CreateParams
        {
            get
            {
                const int CS_DROPSHADOW = 0x20000;
                CreateParams cp = base.CreateParams;
                cp.ClassStyle |= CS_DROPSHADOW;
                return cp;
            }
        }

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            if (connectToSteam())
            {
                panelMain.Visible = true;
                panelLoading.Visible = false;
                _cdKeyList = new List<string>();
                this.ActiveControl = lblKeyCount;
                NativeMethods.SendMessage(txtKeys.Handle, _eM_SETCUEBANNER, IntPtr.Zero, "6EZ77-35QQY-9BTT8");

                _callbackBwg = new BackgroundWorker() { WorkerSupportsCancellation = true };
                _callbackBwg.DoWork += _callbacks_DoWork;
                _callbackBwg.RunWorkerCompleted += _callbacks_RunWorkerCompleted;
                _callbackBwg.RunWorkerAsync();

                _purchaseBwg = new BackgroundWorker();
                _purchaseBwg.DoWork += _purchaseBwg_DoWork;
            }
        }

        private void panelHeader_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                NativeMethods.ReleaseCapture();
                NativeMethods.SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
            }
        }

        private void MainForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                NativeMethods.ReleaseCapture();
                NativeMethods.SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
            }
        }

        private void linkGithub_Click(object sender, EventArgs e)
        {
            Process.Start("https://github.com/Ezzpify");
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            if (_callbackBwg.IsBusy)
                _callbackBwg.CancelAsync();

            Environment.Exit(1);
        }

        private void btnMinimize_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void btnRegister_Click(object sender, EventArgs e)
        {
            if (_cdKeyList.Count == 0)
            {
                if (_enableRegexChecking && !string.IsNullOrWhiteSpace(txtKeys.Text))
                {
                    string chk = "No keys passed the validity check. If you are certain that the keys you have inputted"
                        + " are valid, then you can disable the validity check for cd-keys by pressing Yes.";

                    var diagRes = MessageBox.Show(chk, "No valid keys", MessageBoxButtons.YesNo);
                    if (diagRes == DialogResult.Yes)
                    {
                        _enableRegexChecking = false;
                        addKeysToList();
                    }
                }
                else
                {
                    MessageBox.Show("No keys added.", "Error");
                }
            }
            else
            {
                _result = new Result(_cdKeyList);
                _result.Show();

                _purchaseBwg.RunWorkerAsync(_cdKeyList);
            }
        }

        private void txtKeys_Enter(object sender, EventArgs e)
        {
            txtKeys.Multiline = true;
        }

        private void btnClose_MouseEnter(object sender, EventArgs e)
        {
            btnClose.ForeColor = Color.FromArgb(255, 255, 255);
        }

        private void btnClose_MouseLeave(object sender, EventArgs e)
        {
            btnClose.ForeColor = Color.FromArgb(224, 224, 224);
        }

        private void btnMinimize_MouseEnter(object sender, EventArgs e)
        {
            btnMinimize.ForeColor = Color.FromArgb(255, 255, 255);
        }

        private void btnMinimize_MouseLeave(object sender, EventArgs e)
        {
            btnMinimize.ForeColor = Color.FromArgb(224, 224, 224);
        }

        private void _purchaseBwg_DoWork(object sender, DoWorkEventArgs e)
        {
            var cdkeys = (List<string>)e.Argument;
            foreach (var pchActivationCode in cdkeys)
            {
                _clientBilling.PurchaseWithActivationCode(pchActivationCode);
                Thread.Sleep(2000);

                while (_waitingForActivationResp)
                    Thread.Sleep(100);
            }
        }

        private void _callbacks_DoWork(object sender, DoWorkEventArgs e)
        {
            CallbackMsg_t callbackMsg = new CallbackMsg_t();
{'fraction_non_alphanumeric': 0.07067994802944998, 'fraction_numerical': 0.013858813339107838, 'mean_word_length': 1.7046146638557038, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '2950024', 'n_tokens_mistral': 3244, 'n_tokens_neox': 2968, 'n_words': 674}