<commit_before>﻿namespace POGOLib.Util.Devices
{
    public class Device
    {

        internal string AndroidBoardName { get; set; }
        internal string AndroidBootloader { get; set; }
        internal string DeviceBrand { get; set; }
        internal string DeviceId { get; set; }
        internal string DeviceModel { get; set; }
        internal string DeviceModelBoot { get; set; }
        internal string DeviceModelIdentifier { get; set; }
        internal string FirmwareBrand { get; set; }
        internal string FirmwareFingerprint { get; set; }
        internal string FirmwareTags { get; set; }
        internal string FirmwareType { get; set; }
        internal string HardwareManufacturer { get; set; }
        internal string HardwareModel { get; set; }
        internal string UserAgent { get; set; } = "Dalvik/2.1.0 (Linux; U; Android 5.0; Nexus 5 Build/LPX13D)"; // Device "nexus5".

    }
}<commit_msg>User-Agent Generation (#49)<commit_after>﻿using System;

namespace POGOLib.Util.Devices
{
    public class Device
    {
        private string _userAgent;
        private const string DefaultUserAgent = "Dalvik/2.1.0 (Linux; U; Android 5.0; Nexus 5 Build/LPX13D)";
        private const string UserAgentFormat = "Dalvik/{0} (Linux; U; Android {1}; {2} Build/{3})";

        internal string AndroidBoardName { get; set; }
        internal string AndroidBootloader { get; set; }
        internal string DeviceBrand { get; set; }
        internal string DeviceId { get; set; }
        internal string DeviceModel { get; set; }
        internal string DeviceModelBoot { get; set; }
        internal string DeviceModelIdentifier { get; set; }
        internal string FirmwareBrand { get; set; }
        internal string FirmwareFingerprint { get; set; }
        internal string FirmwareTags { get; set; }
        internal string FirmwareType { get; set; }
        internal string HardwareManufacturer { get; set; }
        internal string HardwareModel { get; set; }

        internal string UserAgent
        {
            get
            {
                if (_userAgent == null)
                {
                    if (TryParseUserAgent(out _userAgent))
                    {
                        return _userAgent;
                    }
                    _userAgent = DefaultUserAgent;
                }
                return _userAgent;
            }
            set { _userAgent = value; }
        }

        private bool TryParseUserAgent(out string userAgent)
        {
            userAgent = null;
            if (string.IsNullOrWhiteSpace(FirmwareFingerprint))
            {
                return false;
            }
            var fingerPrintParts = FirmwareFingerprint.Split('/');
            if (fingerPrintParts.Length < 4)
            {
                return false;
            }
            if (!fingerPrintParts[2].Contains(":"))
            {
                return false;
            }
            try
            {
                string jvmVersion;
                var androidVersion = fingerPrintParts[2].Split(':')[1];
                if (androidVersion.StartsWith("2.1"))
                {
                    jvmVersion = "1.1.0";
                }
                else if (androidVersion.StartsWith("2.2"))
                {
                    jvmVersion = "1.2.0";
                }
                else if (androidVersion.StartsWith("2.3"))
                {
                    jvmVersion = "1.4.0";
                }
                else if (androidVersion.StartsWith("4"))
                {
                    jvmVersion = "1.6.0";
                }
                else
                {
                    jvmVersion = "2.1.0";
                }

                var build = fingerPrintParts[3];
                userAgent = string.Format(UserAgentFormat, jvmVersion, androidVersion, DeviceModel, build);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08901044256588762, 'fraction_numerical': 0.012431626056688214, 'mean_word_length': 1.4411407766990292, 'pattern_counts': {'":': 1, '<': 4, '<?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': '5506464', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1011, 'n_words': 270}