Skip to content

Commit

Permalink
Added the possibility to save the details of an IP (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Aug 15, 2022
1 parent 8c879f6 commit 2f35a34
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 28 deletions.
65 changes: 37 additions & 28 deletions InternetTest/InternetTest/Classes/IPInfo.cs
Expand Up @@ -26,45 +26,54 @@ MIT License
namespace InternetTest.Classes;
public class IPInfo
{
[JsonPropertyName("query")]
public string? Query { get; set; }
[JsonPropertyName("query")]
public string? Query { get; set; }

[JsonPropertyName("status")]
public string? Status { get; set; }
[JsonPropertyName("status")]
public string? Status { get; set; }

[JsonPropertyName("country")]
public string? Country { get; set; }
[JsonPropertyName("country")]
public string? Country { get; set; }

[JsonPropertyName("countryCode")]
public string? CountryCode { get; set; }
[JsonPropertyName("countryCode")]
public string? CountryCode { get; set; }

[JsonPropertyName("region")]
public string? Region { get; set; }
[JsonPropertyName("region")]
public string? Region { get; set; }

[JsonPropertyName("regionName")]
public string? RegionName { get; set; }
[JsonPropertyName("regionName")]
public string? RegionName { get; set; }

[JsonPropertyName("city")]
public string? City { get; set; }
[JsonPropertyName("city")]
public string? City { get; set; }

[JsonPropertyName("zip")]
public string? Zip { get; set; }
[JsonPropertyName("zip")]
public string? Zip { get; set; }

[JsonPropertyName("lat")]
public double Lat { get; set; }
[JsonPropertyName("lat")]
public double Lat { get; set; }

[JsonPropertyName("lon")]
public double Lon { get; set; }
[JsonPropertyName("lon")]
public double Lon { get; set; }

[JsonPropertyName("timezone")]
public string? Timezone { get; set; }
[JsonPropertyName("timezone")]
public string? Timezone { get; set; }

[JsonPropertyName("isp")]
public string? Isp { get; set; }
[JsonPropertyName("isp")]
public string? Isp { get; set; }

[JsonPropertyName("org")]
public string? Org { get; set; }
[JsonPropertyName("org")]
public string? Org { get; set; }

[JsonPropertyName("as")]
public string? As { get; set; }
[JsonPropertyName("as")]
public string? As { get; set; }

public override string ToString() => $"{Properties.Resources.Country}: {Country}\n" +
$"{Properties.Resources.Region}: {RegionName}\n" +
$"{Properties.Resources.City}: {City}\n" +
$"{Properties.Resources.ZIPCode}: {Zip}\n" +
$"{Properties.Resources.Latitude}: {Lat}\n" +
$"{Properties.Resources.Longitude}: {Lon}\n" +
$"{Properties.Resources.Timezone}: {Timezone}\n" +
$"{Properties.Resources.ISP}: {Isp}";
}
1 change: 1 addition & 0 deletions InternetTest/InternetTest/Pages/LocateIpPage.xaml
Expand Up @@ -28,6 +28,7 @@
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button x:Name="LocateIPBtn" Click="LocateIPBtn_Click" Cursor="Hand" Content="{x:Static lang:Resources.LocateIP}" Margin="5 10" Padding="5 2" BorderThickness="0" Background="{Binding Source={StaticResource AccentColor}}" Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}" FontWeight="ExtraBold" Style="{DynamicResource PrimaryButton}"/>
<Button x:Name="MapBtn" Click="MapBtn_Click" Cursor="Hand" Content="{x:Static lang:Resources.ShowOnMap}" Margin="5 10" Padding="5 2" BorderThickness="0" Background="{Binding Source={StaticResource LightAccentColor}}" Foreground="{Binding Source={StaticResource AccentColor}}" FontWeight="ExtraBold" Style="{DynamicResource PrimaryButton}"/>
<Button x:Name="SaveBtn" Click="SaveBtn_Click" Cursor="Hand" Content="&#xF680;" Margin="5 10" Padding="5 2" BorderThickness="0" Background="{Binding Source={StaticResource LightAccentColor}}" Foreground="{Binding Source={StaticResource AccentColor}}" FontFamily="../Fonts/#FluentSystemIcons-Regular" FontWeight="ExtraBold" Style="{DynamicResource PrimaryButton}"/>
</StackPanel>
<Border Background="{Binding Source={StaticResource CardBackground}}" Width="300" CornerRadius="5" HorizontalAlignment="Center">
<Border.Effect>
Expand Down
22 changes: 22 additions & 0 deletions InternetTest/InternetTest/Pages/LocateIpPage.xaml.cs
Expand Up @@ -22,9 +22,11 @@ MIT License
SOFTWARE.
*/
using InternetTest.Classes;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -45,6 +47,7 @@ namespace InternetTest.Pages;
public partial class LocateIpPage : Page
{
bool codeInjected = false;
private IPInfo? CurrentIP { get; set; }
public LocateIpPage()
{
InitializeComponent();
Expand Down Expand Up @@ -129,6 +132,7 @@ internal async void LocateIP(string ip)
MyIPTxt.Text = Properties.Resources.IPShowHere2;

var ipInfo = await Global.GetIPInfoAsync(ip); // Giving an empty IP returns the user's current IP
CurrentIP = ipInfo;
if (ipInfo is not null)
{
MyIPTxt.Text = ipInfo.Query;
Expand All @@ -152,4 +156,22 @@ internal async void LocateIP(string ip)
StatusIconTxt.Foreground = new SolidColorBrush(Global.GetColorFromResource("Red"));
}
}

private void SaveBtn_Click(object sender, RoutedEventArgs e)
{
if (CurrentIP is null) return;
SaveFileDialog dialog = new()
{
Title = Properties.Resources.Save,
Filter = Properties.Resources.TxtFiles + " (*.txt)|*.txt",
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
FileName = IpTxt.Text + ".txt",
DefaultExt = ".txt"
};

if (dialog.ShowDialog().Value)
{
File.WriteAllText(dialog.FileName, CurrentIP?.ToString());
}
}
}
18 changes: 18 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.en-US.resx
Expand Up @@ -297,4 +297,10 @@
<data name="InternetTestPro" xml:space="preserve">
<value>InternetTest Pro</value>
</data>
<data name="Save" xml:space="preserve">
<value>Save</value>
</data>
<data name="TxtFiles" xml:space="preserve">
<value>Text files</value>
</data>
</root>
6 changes: 6 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.fr-FR.resx
Expand Up @@ -297,4 +297,10 @@
<data name="InternetTestPro" xml:space="preserve">
<value>InternetTest Pro</value>
</data>
<data name="Save" xml:space="preserve">
<value>Enregistrer</value>
</data>
<data name="TxtFiles" xml:space="preserve">
<value>Fichiers texte</value>
</data>
</root>
6 changes: 6 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.resx
Expand Up @@ -297,4 +297,10 @@
<data name="InternetTestPro" xml:space="preserve">
<value>InternetTest Pro</value>
</data>
<data name="Save" xml:space="preserve">
<value>Save</value>
</data>
<data name="TxtFiles" xml:space="preserve">
<value>Text files</value>
</data>
</root>
6 changes: 6 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.zh-CN.resx
Expand Up @@ -297,4 +297,10 @@
<data name="InternetTestPro" xml:space="preserve">
<value>InternetTest Pro</value>
</data>
<data name="Save" xml:space="preserve">
<value>Save</value>
</data>
<data name="TxtFiles" xml:space="preserve">
<value>Text files</value>
</data>
</root>

0 comments on commit 2f35a34

Please sign in to comment.