mirror of
https://github.com/2dust/v2rayN.git
synced 2026-09-27 17:28:01 +03:00
Fetch and display tested server IP and country (with emoji) in speed tests. Adds CountryExtension for country->emoji mapping and a new IpInfoResult type; ConnectionHandler now retrieves/parses IP API results and GetRealPingTime signature adjusted. Models and entities (ProfileItemModel, ProfileExItem, SpeedTestResult) gain IpInfo fields; ProfileExManager can store test IP info. UI/UX updated: new IpInfo column in ProfilesView (desktop and Avalonia), ResUI resource strings for "IP Info", and EServerColName ordering supports IpInfo. SpeedtestService now captures IP info and forwards it to the view model via the update function.
93 lines
3.1 KiB
C#
93 lines
3.1 KiB
C#
namespace ServiceLib.Common;
|
|
|
|
/// <summary>
|
|
/// Extension methods for country code utilities
|
|
/// </summary>
|
|
public static class CountryExtension
|
|
{
|
|
/// <summary>
|
|
/// Country code to emoji flag mapping for common countries
|
|
/// </summary>
|
|
private static readonly Dictionary<string, string> CountryEmojiMap = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
// Asia
|
|
{ "CN", "🇨🇳" }, // China
|
|
{ "HK", "🇭🇰" }, // Hong Kong
|
|
{ "TW", "🇹🇼" }, // Taiwan
|
|
{ "JP", "🇯🇵" }, // Japan
|
|
{ "SG", "🇸🇬" }, // Singapore
|
|
{ "KR", "🇰🇷" }, // South Korea
|
|
{ "TH", "🇹🇭" }, // Thailand
|
|
{ "VN", "🇻🇳" }, // Vietnam
|
|
{ "ID", "🇮🇩" }, // Indonesia
|
|
{ "PH", "🇵🇭" }, // Philippines
|
|
{ "MY", "🇲🇾" }, // Malaysia
|
|
{ "IN", "🇮🇳" }, // India
|
|
{ "PK", "🇵🇰" }, // Pakistan
|
|
{ "BD", "🇧🇩" }, // Bangladesh
|
|
{ "LK", "🇱🇰" }, // Sri Lanka
|
|
{ "KH", "🇰🇭" }, // Cambodia
|
|
{ "LA", "🇱🇦" }, // Laos
|
|
{ "MM", "🇲🇲" }, // Myanmar
|
|
|
|
// Americas
|
|
{ "US", "🇺🇸" }, // United States
|
|
{ "CA", "🇨🇦" }, // Canada
|
|
{ "MX", "🇲🇽" }, // Mexico
|
|
{ "BR", "🇧🇷" }, // Brazil
|
|
{ "AR", "🇦🇷" }, // Argentina
|
|
{ "CL", "🇨🇱" }, // Chile
|
|
{ "CO", "🇨🇴" }, // Colombia
|
|
|
|
// Europe
|
|
{ "GB", "🇬🇧" }, // United Kingdom
|
|
{ "DE", "🇩🇪" }, // Germany
|
|
{ "FR", "🇫🇷" }, // France
|
|
{ "IT", "🇮🇹" }, // Italy
|
|
{ "ES", "🇪🇸" }, // Spain
|
|
{ "RU", "🇷🇺" }, // Russia
|
|
{ "NL", "🇳🇱" }, // Netherlands
|
|
{ "CH", "🇨🇭" }, // Switzerland
|
|
{ "SE", "🇸🇪" }, // Sweden
|
|
{ "NO", "🇳🇴" }, // Norway
|
|
{ "DK", "🇩🇰" }, // Denmark
|
|
{ "FI", "🇫🇮" }, // Finland
|
|
{ "PL", "🇵🇱" }, // Poland
|
|
{ "CZ", "🇨🇿" }, // Czech Republic
|
|
{ "AT", "🇦🇹" }, // Austria
|
|
{ "GR", "🇬🇷" }, // Greece
|
|
{ "PT", "🇵🇹" }, // Portugal
|
|
{ "TR", "🇹🇷" }, // Turkey
|
|
{ "UA", "🇺🇦" }, // Ukraine
|
|
{ "RO", "🇷🇴" }, // Romania
|
|
|
|
// Middle East & Central Asia
|
|
{ "AE", "🇦🇪" }, // United Arab Emirates
|
|
{ "SA", "🇸🇦" }, // Saudi Arabia
|
|
{ "IL", "🇮🇱" }, // Israel
|
|
{ "KZ", "🇰🇿" }, // Kazakhstan
|
|
|
|
// Oceania
|
|
{ "AU", "🇦🇺" }, // Australia
|
|
{ "NZ", "🇳🇿" }, // New Zealand
|
|
|
|
// Africa
|
|
{ "ZA", "🇿🇦" }, // South Africa
|
|
{ "EG", "🇪🇬" }, // Egypt
|
|
};
|
|
|
|
/// <summary>
|
|
/// Converts country code to flag emoji using predefined mapping
|
|
/// Example: "US" -> "🇺🇸", "CN" -> "🇨🇳"
|
|
/// </summary>
|
|
public static string? CountryToEmoji(this string? countryCode)
|
|
{
|
|
if (countryCode.IsNullOrEmpty())
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return CountryEmojiMap.TryGetValue(countryCode, out var emoji) ? emoji : null;
|
|
}
|
|
}
|