Add reset option

This commit is contained in:
2019-06-05 12:21:01 +02:00
parent 7cf97a54d6
commit e3ae12d33d
2 changed files with 31 additions and 1 deletions

View File

@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:KurtzPelRegionPicker"
mc:Ignorable="d"
Title="KPRP" Height="190" Width="220"
Title="KPRP" Height="225" Width="220"
ResizeMode="CanMinimize">
<StackPanel Orientation="Vertical"
Margin="10">
@@ -19,5 +19,9 @@
Height="25"
Content="Apply"
Click="Button_Apply_Click" />
<Button Height="25"
Background="#FFD2D2"
Content="Reset"
Click="Button_Reset_Click" />
</StackPanel>
</Window>

View File

@@ -55,6 +55,13 @@ namespace KurtzPelRegionPicker
}
}
private void Button_Reset_Click(object sender, RoutedEventArgs e)
{
ResetRegion();
MessageBox.Show("Region reset", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void ApplyRegion(Region source, Region destination)
{
string[] content = File.ReadAllLines(HOSTS_PATH);
@@ -85,6 +92,25 @@ namespace KurtzPelRegionPicker
File.WriteAllLines(HOSTS_PATH, newContent);
}
private void ResetRegion()
{
string[] content = File.ReadAllLines(HOSTS_PATH);
if (content.Contains(COMMENT))
{
// Purge
int index = content.IndexOf(COMMENT);
var list = content.ToList();
list.RemoveAt(index);
list.RemoveAt(index);
content = list.ToArray();
File.WriteAllLines(HOSTS_PATH, content);
}
}
private string GetRealIP(string dns)
{
var process = new Process()