Skip to content

Commit

Permalink
🔄️ New UI, IPManager, .NET 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
valnoxy committed Mar 24, 2024
1 parent aeca747 commit 6fffcf8
Show file tree
Hide file tree
Showing 18 changed files with 878 additions and 726 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/Windows-GUI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down
File renamed without changes.
28 changes: 15 additions & 13 deletions CheckIP.Windows/CheckIP/CheckIP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
<Nullable>disable</Nullable>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon>Assets\CheckIP.ico</ApplicationIcon>
<Authors>valnoxy</Authors>
<Company>Exploitox</Company>
<Description>Get more information about an IP address.</Description>
<Copyright>Copyright © 2018 - 2023 Exploitox. All rights reserved.</Copyright>
<Copyright>Copyright © 2018 - 2024 Exploitox. All rights reserved.</Copyright>
<RepositoryUrl>https://github.com/valnoxy/checkip</RepositoryUrl>
<Version>2.2.1</Version>
<Version>2.3.0</Version>
<Platforms>AnyCPU;ARM32;ARM64;x64;x86</Platforms>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<StartupObject>CheckIP.App</StartupObject>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -287,15 +289,15 @@
</ItemGroup>

<ItemGroup>
<Page Remove="Pages\App.xaml" />
<Page Remove="W11App.xaml" />
</ItemGroup>

<ItemGroup>
<ApplicationDefinition Include="Pages\App.xaml">
<Page Update="Pages\About.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<Generator>MSBuild:Compile</Generator>
</ApplicationDefinition>
</Page>
<Page Update="Pages\FetchIP.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
<Page Update="Pages\MyIP.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -349,8 +351,8 @@

<ItemGroup>
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="WPF-UI" Version="2.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="WPF-UI" Version="3.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
111 changes: 111 additions & 0 deletions CheckIP.Windows/CheckIP/Common/IPManager.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
16 changes: 11 additions & 5 deletions CheckIP.Windows/CheckIP/Common/TrayIcon.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
<system:String x:Key="ThirdPartyLibraries">Drittanbieter Bibliotheken</system:String>
<system:String x:Key="ThirdPartyLibrariesDescription">Liste aller verwendeten Bibliotheken und Bilder.</system:String>
<system:String x:Key="By">{0} von {1}</system:String>
<system:String x:Key="SourceCodeBtn">Quellcode auf GitHub</system:String>
<system:String x:Key="SourceCodeBtn">Quellcode</system:String>
<system:String x:Key="HomepageBtn">Homepage</system:String>
<system:String x:Key="LicenseBtn">Lizenz</system:String>
<system:String x:Key="DonateBtn">Spenden</system:String>

<!-- Report -->
<system:String x:Key="ReportCreatedMessage">Bericht erstellt am {0} für IP-Adresse {1}</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
<system:String x:Key="ThirdPartyLibraries">Librerie di terze parti</system:String>
<system:String x:Key="ThirdPartyLibrariesDescription">Elenco di tutte le librerie immagini open source usate.</system:String>
<system:String x:Key="By">{0} di {1}</system:String>
<system:String x:Key="SourceCodeBtn">Codice sorgente su GitHub</system:String>
<system:String x:Key="SourceCodeBtn">Codice sorgente</system:String>
<system:String x:Key="HomepageBtn">Pagina home</system:String>
<system:String x:Key="LicenseBtn">Licenza</system:String>
<system:String x:Key="DonateBtn">Donare</system:String>

<!-- Report -->
<system:String x:Key="ReportCreatedMessage">Rapporto creato il {0} per {1} indirizzi IP</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<system:String x:Key="By">{0} by {1}</system:String>
<system:String x:Key="SourceCodeBtn">Source Code on GitHub</system:String>
<system:String x:Key="HomepageBtn">Homepage</system:String>
<system:String x:Key="LicenseBtn">License</system:String>
<system:String x:Key="DonateBtn">Donate</system:String>

<!-- Report -->
<system:String x:Key="ReportCreatedMessage">Report created at {0} for IP address {1}</system:String>
Expand Down
74 changes: 74 additions & 0 deletions CheckIP.Windows/CheckIP/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<ui:FluentWindow x:Class="CheckIP.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="CheckIP" Height="669" Width="512"
MinHeight="669" MinWidth="512"
xmlns:pages="clr-namespace:CheckIP"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
WindowStartupLocation="CenterScreen"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowCornerPreference="Round"
ResizeMode="NoResize"
ContentRendered="MainWindow_OnContentRendered">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<Grid Grid.Row="1" Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<ui:NavigationView x:Name="RootNavigation" PaneDisplayMode="Top" IsBackButtonVisible="Collapsed" Margin="6,0" Grid.Row="0">
<ui:NavigationView.MenuItems>
<ui:NavigationViewItem Content="{DynamicResource Fetch}" NavigationCacheMode="Enabled" TargetPageType="{x:Type pages:FetchIP}">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="Search24" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
<ui:NavigationViewItem Content="{DynamicResource MyIP}" NavigationCacheMode="Enabled" TargetPageType="{x:Type pages:MyIP}">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="MyLocation24" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
</ui:NavigationView.MenuItems>

<ui:NavigationView.FooterMenuItems>
<ui:NavigationViewItem Click="ThemeSwitch_Click">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="PaintBrush24"/>
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
<ui:NavigationViewItem TargetPageType="{x:Type pages:About}" NavigationCacheMode="Enabled">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="QuestionCircle24" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
</ui:NavigationView.FooterMenuItems>
</ui:NavigationView>
</Grid>

<ui:TitleBar
Title="CheckIP"
ShowMinimize="False"
ShowMaximize="False"
Grid.Row="0">
<ui:TitleBar.Icon>
<ui:ImageIcon Source="pack://application:,,,/Assets/CheckIP.ico" />
</ui:TitleBar.Icon>
</ui:TitleBar>

<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<TextBlock Grid.Column="1" x:Name="DebugString" Text="Debug" Margin="0,17,50,0" Foreground="Red" TextAlignment="Right" HorizontalAlignment="Right"/>
</Grid>
</Grid>
</ui:FluentWindow>
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Interaktionslogik für Main.xaml
/// </summary>
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();
Expand All @@ -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;
}
}
}
Loading

0 comments on commit 6fffcf8

Please sign in to comment.