<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Windows.Forms;
using Lib.WinAPI;

namespace Lib.Network.Http
{
    public partial class Download : Form
    {
        HttpWebRequest request;
        HttpWebResponse response;
        string fileName;
        int crc32;
        long length;
        long received = 0;
        long lastReceived = 0;
        Action<bool, string> callback;
        System.Timers.Timer timer = new System.Timers.Timer();
        bool downloadEnabled = true;

        public Download(string url, string fileName, int crc32, long length, Action<bool, string> callback)
        {
            if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                Directory.CreateDirectory(Path.GetDirectoryName(fileName));
            int lastCrc32 = 0;
            if (File.Exists(fileName))
            {
                try
                {
                    BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open));
                    int size;
                    byte[] buffer = new byte[512];
                    while ((size = reader.Read(buffer, 0, 512)) > 0)
                        lastCrc32 = Ntdll.RtlComputeCrc32(lastCrc32, buffer, (uint)size);
                    reader.Close();
                    if (lastCrc32 == crc32)
                    {
                        Close();
                        callback(true, fileName);
                        return;
                    }
                }
                catch { }
            }
            InitializeComponent();
            textBox2.Text = Path.GetFullPath(fileName);
            label6.Text = "0B out of " + Unit.AutoScale(length, "B");
            request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.UserAgent = "SB Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (Exception ex)
            {
                Close();
                System.Windows.Forms.MessageBox.Show("Unable to connect to server:\n\n" + ex.Message, "Download", MessageBoxButtons.OK, MessageBoxIcon.Error);
                callback(false, fileName);
                return;
            }
            
            textBox1.Text = response.ResponseUri.AbsoluteUri;
            this.fileName = fileName;<commit_msg>Updated User-Agent<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Windows.Forms;
using Lib.WinAPI;

namespace Lib.Network.Http
{
    /// <summary>
    /// TODO: Implement pause/resume download
    /// </summary>
    public partial class Download : Form
    {
        HttpWebRequest request;
        HttpWebResponse response;
        string fileName;
        int crc32;
        long length;
        long received = 0;
        long lastReceived = 0;
        Action<bool, string> callback;
        System.Timers.Timer timer = new System.Timers.Timer();
        bool downloadEnabled = true;

        public Download(string url, string fileName, int crc32, long length, Action<bool, string> callback)
        {
            if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                Directory.CreateDirectory(Path.GetDirectoryName(fileName));
            int lastCrc32 = 0;
            if (File.Exists(fileName))
            {
                try
                {
                    BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open));
                    int size;
                    byte[] buffer = new byte[512];
                    while ((size = reader.Read(buffer, 0, 512)) > 0)
                        lastCrc32 = Ntdll.RtlComputeCrc32(lastCrc32, buffer, (uint)size);
                    reader.Close();
                    if (lastCrc32 == crc32)
                    {
                        Close();
                        callback(true, fileName);
                        return;
                    }
                }
                catch { }
            }
            InitializeComponent();
            textBox2.Text = Path.GetFullPath(fileName);
            label6.Text = "0B out of " + Unit.AutoScale(length, "B");
            request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.UserAgent = "SB Mozilla/4.0 (compatible; MSIE 6.0; Windows NT " + Environment.OSVersion.Version.MajorRevision + "." + Environment.OSVersion.Version.Minor + "; .NET CLR 1.0.3705;)";
            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (Exception ex)
            {
                Close();
                System.Windows.Forms.MessageBox.Show("Unable to connect to server:\n\n" + ex.Message, "Download", MessageBoxButtons.OK, MessageBoxIcon.Error);
                callback(false, fileName);
                return;
            }
            
            textBox1.Text = response.ResponseUri.AbsoluteUri;
            this.fileName = fileName;
{'fraction_non_alphanumeric': 0.09742921013412817, 'fraction_numerical': 0.01564828614008942, 'mean_word_length': 1.6254278728606357, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3801021', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1365, 'n_words': 317}