diff --git a/.github/workflows/Windows-GUI.yml b/.github/workflows/Windows-GUI.yml index 62923c5..27ac552 100644 --- a/.github/workflows/Windows-GUI.yml +++ b/.github/workflows/Windows-GUI.yml @@ -16,10 +16,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Setup .NET 7.0.x + - name: Setup .NET 8.0.x uses: actions/setup-dotnet@v2 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x - name: Setup MSBuild uses: microsoft/setup-msbuild@v1.1 diff --git a/CheckIP.Windows/CheckIP/Pages/App.xaml b/CheckIP.Windows/CheckIP/App.xaml similarity index 96% rename from CheckIP.Windows/CheckIP/Pages/App.xaml rename to CheckIP.Windows/CheckIP/App.xaml index 8f2d8f4..eba419b 100644 --- a/CheckIP.Windows/CheckIP/Pages/App.xaml +++ b/CheckIP.Windows/CheckIP/App.xaml @@ -4,7 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:CheckIP" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" - StartupUri="Main.xaml"> + StartupUri="/MainWindow.xaml"> diff --git a/CheckIP.Windows/CheckIP/Pages/App.xaml.cs b/CheckIP.Windows/CheckIP/App.xaml.cs similarity index 100% rename from CheckIP.Windows/CheckIP/Pages/App.xaml.cs rename to CheckIP.Windows/CheckIP/App.xaml.cs diff --git a/CheckIP.Windows/CheckIP/CheckIP.csproj b/CheckIP.Windows/CheckIP/CheckIP.csproj index b70f69b..28b861d 100644 --- a/CheckIP.Windows/CheckIP/CheckIP.csproj +++ b/CheckIP.Windows/CheckIP/CheckIP.csproj @@ -2,17 +2,19 @@ WinExe - net7.0-windows10.0.19041.0 + disable + net8.0-windows10.0.19041.0 true Assets\CheckIP.ico valnoxy Exploitox Get more information about an IP address. - Copyright © 2018 - 2023 Exploitox. All rights reserved. + Copyright © 2018 - 2024 Exploitox. All rights reserved. https://github.com/valnoxy/checkip - 2.2.1 + 2.3.0 AnyCPU;ARM32;ARM64;x64;x86 false + CheckIP.App @@ -287,15 +289,15 @@ - - - - - - + $(DefaultXamlRuntime) - MSBuild:Compile - + + + $(DefaultXamlRuntime) + + + $(DefaultXamlRuntime) + @@ -349,8 +351,8 @@ - - + + diff --git a/CheckIP.Windows/CheckIP/Common/IPManager.cs b/CheckIP.Windows/CheckIP/Common/IPManager.cs new file mode 100644 index 0000000..a011e5e --- /dev/null +++ b/CheckIP.Windows/CheckIP/Common/IPManager.cs @@ -0,0 +1,111 @@ +using Newtonsoft.Json.Linq; +using System.Net; +using System.Net.Http; +using System.Windows; +using System.Windows.Threading; + +namespace CheckIP.Common +{ + public class IPManager + { + public class IP + { + public string City { get; set; } + public string Country { get; set; } + public string CountryCode { get; set; } + public string Postal { get; set; } + public string Timezone { get; set; } + public string Latitude { get; set; } + public string Longitude { get; set; } + public string Isp { get; set; } + public string Asn { get; set; } + public bool Mobile { get; set; } + public bool Proxy { get; set; } + public bool Hosting { get; set; } + public bool ParseSuccess { get; set; } + public string Status { get; set; } + public IPAddress IPAddress { get; set; } + } + + public static IP Parse(string ip) + { + var ipData = new IP(); + + var validateIp = IPAddress.TryParse(ip, out var ipAddr); + if (!validateIp) + { + ipData.ParseSuccess = false; + Application.Current.Dispatcher.Invoke(() => + { + var error = (string)Application.Current.MainWindow!.FindResource("ErrorInvalidIP"); + ipData.Status = !string.IsNullOrEmpty(error) ? error : "Error: This is not a valid IP address."; + }); + return ipData; + } + + // Parse data + string dataJson; + var url = "http://ip-api.com/json/" + ip + "?fields=status,message,country,countryCode,city,zip,lat,lon,timezone,isp,as,mobile,proxy,hosting"; + try + { + var client = new HttpClient(); + using var response = client.GetAsync(url).Result; + using var content = response.Content; + dataJson = content.ReadAsStringAsync().Result; + } + catch + { + ipData.ParseSuccess = false; + Application.Current.Dispatcher.Invoke(() => + { + var error = (string)Application.Current.MainWindow!.FindResource("ErrorNoConnection"); + ipData.Status = !string.IsNullOrEmpty(error) ? error : "Error: No connection to server"; + }); + return ipData; + } + dynamic data = JObject.Parse(dataJson); + + // Parse data + string status = data.status; + string message = data.message; + string country = data.country; + string countryCode = data.countryCode; + string city = data.city; + string postal = data.zip; + string timezone = data.timezone; + string latitude = data.lat; + string longitude = data.lon; + string isp = data.isp; + string asn = data.@as; + string mobile = data.mobile; + string proxy = data.proxy; + string hosting = data.hosting; + + // Check status + if (status != "success") + { + var localizeError = Common.LocalizationManager.LocalizeError(message); + ipData.Status = localizeError; + ipData.ParseSuccess = false; + return ipData; + } + + ipData.City = city; + ipData.Country = country; + ipData.CountryCode = countryCode; + ipData.Postal = postal; + ipData.Timezone = timezone; + ipData.Latitude = latitude; + ipData.Longitude = longitude; + ipData.Isp = isp; + ipData.Asn = asn; + ipData.Mobile = mobile.Equals("true", System.StringComparison.CurrentCultureIgnoreCase); + ipData.Proxy = proxy.Equals("true", System.StringComparison.CurrentCultureIgnoreCase); + ipData.Hosting = hosting.Equals("true", System.StringComparison.CurrentCultureIgnoreCase); + ipData.IPAddress = ipAddr; + ipData.ParseSuccess = true; + + return ipData; + } + } +} diff --git a/CheckIP.Windows/CheckIP/Common/TrayIcon.cs b/CheckIP.Windows/CheckIP/Common/TrayIcon.cs index 8f8521e..945cf42 100644 --- a/CheckIP.Windows/CheckIP/Common/TrayIcon.cs +++ b/CheckIP.Windows/CheckIP/Common/TrayIcon.cs @@ -1,11 +1,6 @@ using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Drawing; -using System.Linq; using System.Net; -using System.Text; -using System.Threading.Tasks; using System.Windows.Media.Imaging; using Hardcodet.Wpf.TaskbarNotification; @@ -40,6 +35,17 @@ public static void Update(string country, string city, IPAddress ip, string coun Debug.WriteLine(ex); } } + + public static BitmapImage Create(string path) + { + var img = new BitmapImage(); + img.BeginInit(); + img.CacheOption = BitmapCacheOption.OnLoad; + img.UriSource = new Uri(path, UriKind.RelativeOrAbsolute); + img.EndInit(); + img.Freeze(); + return img; + } } } diff --git a/CheckIP.Windows/CheckIP/Localization/ResourceDictionary.de-DE.xaml b/CheckIP.Windows/CheckIP/Localization/ResourceDictionary.de-DE.xaml index afde582..38a87da 100644 --- a/CheckIP.Windows/CheckIP/Localization/ResourceDictionary.de-DE.xaml +++ b/CheckIP.Windows/CheckIP/Localization/ResourceDictionary.de-DE.xaml @@ -28,9 +28,10 @@ Drittanbieter Bibliotheken Liste aller verwendeten Bibliotheken und Bilder. {0} von {1} - Quellcode auf GitHub + Quellcode Homepage Lizenz + Spenden Bericht erstellt am {0} für IP-Adresse {1} diff --git a/CheckIP.Windows/CheckIP/Localization/ResourceDictionary.it-IT.xaml b/CheckIP.Windows/CheckIP/Localization/ResourceDictionary.it-IT.xaml index 443b156..ee45f40 100644 --- a/CheckIP.Windows/CheckIP/Localization/ResourceDictionary.it-IT.xaml +++ b/CheckIP.Windows/CheckIP/Localization/ResourceDictionary.it-IT.xaml @@ -31,9 +31,9 @@ Librerie di terze parti Elenco di tutte le librerie immagini open source usate. {0} di {1} - Codice sorgente su GitHub + Codice sorgente Pagina home - Licenza + Donare Rapporto creato il {0} per {1} indirizzi IP diff --git a/CheckIP.Windows/CheckIP/Localization/ResourceDictionary.xaml b/CheckIP.Windows/CheckIP/Localization/ResourceDictionary.xaml index af4d7c2..b29e4f2 100644 --- a/CheckIP.Windows/CheckIP/Localization/ResourceDictionary.xaml +++ b/CheckIP.Windows/CheckIP/Localization/ResourceDictionary.xaml @@ -33,7 +33,7 @@ {0} by {1} Source Code on GitHub Homepage - License + Donate Report created at {0} for IP address {1} diff --git a/CheckIP.Windows/CheckIP/MainWindow.xaml b/CheckIP.Windows/CheckIP/MainWindow.xaml new file mode 100644 index 0000000..e4438eb --- /dev/null +++ b/CheckIP.Windows/CheckIP/MainWindow.xaml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CheckIP.Windows/CheckIP/Pages/Main.xaml.cs b/CheckIP.Windows/CheckIP/MainWindow.xaml.cs similarity index 63% rename from CheckIP.Windows/CheckIP/Pages/Main.xaml.cs rename to CheckIP.Windows/CheckIP/MainWindow.xaml.cs index 0a78bcc..129b3cc 100644 --- a/CheckIP.Windows/CheckIP/Pages/Main.xaml.cs +++ b/CheckIP.Windows/CheckIP/MainWindow.xaml.cs @@ -1,30 +1,21 @@ -using System; +using CheckIP.Common; +using System; using System.Diagnostics; using System.Threading; using System.Windows; -using CheckIP.Common; - +using Wpf.Ui.Controls; namespace CheckIP { /// /// Interaktionslogik für Main.xaml /// - public partial class Main : Wpf.Ui.Controls.UiWindow + public partial class MainWindow { - public Main() + public MainWindow() { InitializeComponent(); - Loaded += (sender, args) => - { - Wpf.Ui.Appearance.Watcher.Watch( - this, // Window class - Wpf.Ui.Appearance.BackgroundType.Mica, // Background type - true // Whether to change accents automatically - ); - }; - // Set current language model var language = Thread.CurrentThread.CurrentCulture.ToString(); var dict = new ResourceDictionary(); @@ -45,15 +36,19 @@ public Main() Application.Current.Resources.MergedDictionaries.Add(dict); #if DEBUG - DebugLabel.Content = "Debug build - This is not a production ready build."; + DebugString.Text = "Debug build"; #endif } - private void RootNavigation_OnLoaded(object sender, RoutedEventArgs e) + private void MainWindow_OnContentRendered(object sender, EventArgs e) { - RootNavigation.Navigate("dashboard"); - + RootNavigation.Navigate(typeof(FetchIP)); TaskBar.Initialize(); } + + private void ThemeSwitch_Click(object sender, RoutedEventArgs e) + { + WindowBackdropType = WindowBackdropType == WindowBackdropType.Mica ? WindowBackdropType.Tabbed : WindowBackdropType.Mica; + } } } diff --git a/CheckIP.Windows/CheckIP/Pages/About.xaml b/CheckIP.Windows/CheckIP/Pages/About.xaml index 25c5a59..62ed6b7 100644 --- a/CheckIP.Windows/CheckIP/Pages/About.xaml +++ b/CheckIP.Windows/CheckIP/Pages/About.xaml @@ -5,71 +5,98 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CheckIP" mc:Ignorable="d" - Style="{StaticResource UiPageScrollable}" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" d:DesignHeight="516" d:DesignWidth="441" Title="About"> - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + Icon="{ui:SymbolIcon Person24}"> @@ -90,21 +117,6 @@ - - - diff --git a/CheckIP.Windows/CheckIP/Pages/About.xaml.cs b/CheckIP.Windows/CheckIP/Pages/About.xaml.cs index dd9ec18..cb2b2a3 100644 --- a/CheckIP.Windows/CheckIP/Pages/About.xaml.cs +++ b/CheckIP.Windows/CheckIP/Pages/About.xaml.cs @@ -1,31 +1,29 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics; -using System.Net; using System.Reflection; using System.Windows; using System.Windows.Controls; -using System.Windows.Documents; namespace CheckIP { /// /// Interaktionslogik für About.xaml /// - public partial class About : Page + public partial class About { private class ThirdParty { - internal string Author { get; set; } - internal string Product { get; set; } + internal string Author { get; init; } + internal string Product { get; init; } } public About() { InitializeComponent(); - var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location); - ValueVersion.Content = $"{versionInfo.ProductName} V. {versionInfo.ProductVersion}"; + var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly()!.Location); + ValueVersion.Content = $"{versionInfo.ProductName} v{versionInfo.ProductVersion}"; + ValueCopyright.Content = versionInfo.LegalCopyright; var legalCopyright = versionInfo.LegalCopyright; var localizedAllRightsReserved = Common.LocalizationManager.LocalizeValue("All rights reserved."); @@ -34,22 +32,22 @@ public About() var thirdPartyList = new List { - new ThirdParty + new() { Author = "Lecopo", Product = "WPF-UI" }, - new ThirdParty + new() { Author = "Hardcodet", Product = "Hardcodet.NotifyIcon.Wpf" }, - new ThirdParty + new() { Author = "Icons8", Product = "Flag Icons" }, - new ThirdParty + new() { Author = "James Newton-King", Product = "Newtonsoft.Json" @@ -69,5 +67,46 @@ public About() ThirdPartyList.Children.Add(tb); } } + + private void Homepage_OnClick(object sender, RoutedEventArgs e) + { + try + { + Process.Start(new ProcessStartInfo() { FileName = "https://exploitox.de", UseShellExecute = true }); + } + catch + { + // ignored + } + } + + private void Donate_OnClick(object sender, RoutedEventArgs e) + { + try + { + Process.Start(new ProcessStartInfo() { FileName = "https://paypal.me/valnoxy", UseShellExecute = true }); + } + catch + { + // ignored + } + } + + private void SourceCode_OnClick(object sender, RoutedEventArgs e) + { + try + { + Process.Start(new ProcessStartInfo() { FileName = "https://github.com/valnoxy/checkip", UseShellExecute = true }); + } + catch (System.ComponentModel.Win32Exception noBrowser) + { + if (noBrowser.ErrorCode == -2147467259) + MessageBox.Show(noBrowser.Message); + } + catch (System.Exception other) + { + MessageBox.Show(other.Message); + } + } } } diff --git a/CheckIP.Windows/CheckIP/Pages/FetchIP.xaml b/CheckIP.Windows/CheckIP/Pages/FetchIP.xaml index 4f49458..f660140 100644 --- a/CheckIP.Windows/CheckIP/Pages/FetchIP.xaml +++ b/CheckIP.Windows/CheckIP/Pages/FetchIP.xaml @@ -3,179 +3,186 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:CheckIP" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" mc:Ignorable="d" d:DesignHeight="625" d:DesignWidth="441" Title="FetchIP"> - - - - - - -