Skip to content

Commit

Permalink
Added the possibility to export saved WiFi Networks (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Feb 4, 2024
1 parent 36d0b79 commit 65a5ad3
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 58 deletions.
182 changes: 124 additions & 58 deletions InternetTest/InternetTest/Pages/WiFiPasswordsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,64 +38,130 @@
FontWeight="ExtraBold" />
</StackPanel>

<Border
Grid.Row="1"
Width="300"
Margin="10 3 3 3"
HorizontalAlignment="Left"
Background="{DynamicResource CardBackground}"
CornerRadius="5">
<Border.Effect>
<DropShadowEffect
BlurRadius="15"
Opacity="0.2"
ShadowDepth="0"
Color="{DynamicResource AccentColor}" />
</Border.Effect>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox
x:Name="SearchTxt"
Margin="5"
Padding="1"
d:Text="123.54.132.56"
Background="Transparent"
BorderThickness="0"
FontWeight="Bold"
Foreground="{DynamicResource DarkGray}"
TextChanged="TextBox_TextChanged" />
<Button
x:Name="DismissBtn"
Grid.Column="1"
Margin="2"
Padding="4"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="Transparent"
BorderThickness="0"
Click="DismissBtn_Click"
Content="&#xF36A;"
FontFamily="../Fonts/#FluentSystemIcons-Regular"
Foreground="{DynamicResource Foreground1}"
Style="{DynamicResource ToolButton}" />
</Grid>
</Border>
<Button
x:Name="GetWiFiBtn"
Grid.Row="1"
Margin="5"
Padding="5"
HorizontalAlignment="Right"
Background="{DynamicResource LightAccent}"
Click="GetWiFiBtn_Click"
Content="{x:Static lang:Resources.GetWiFi}"
Cursor="Hand"
FontWeight="ExtraBold"
Foreground="{DynamicResource Accent}"
Style="{DynamicResource PrimaryButton}" />
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border
Width="300"
Margin="10 3 3 3"
HorizontalAlignment="Left"
Background="{DynamicResource CardBackground}"
CornerRadius="5">
<Border.Effect>
<DropShadowEffect
BlurRadius="15"
Opacity="0.2"
ShadowDepth="0"
Color="{DynamicResource AccentColor}" />
</Border.Effect>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox
x:Name="SearchTxt"
Margin="5"
Padding="1"
VerticalContentAlignment="Center"
d:Text="123.54.132.56"
Background="Transparent"
BorderThickness="0"
FontWeight="Bold"
Foreground="{DynamicResource DarkGray}"
TextChanged="TextBox_TextChanged" />
<Button
x:Name="DismissBtn"
Grid.Column="1"
Margin="2"
Padding="4"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="Transparent"
BorderThickness="0"
Click="DismissBtn_Click"
Content="&#xF36A;"
FontFamily="../Fonts/#FluentSystemIcons-Regular"
Foreground="{DynamicResource Foreground1}"
Style="{DynamicResource ToolButton}" />
</Grid>
</Border>
<Button
x:Name="ExportBtn"
Grid.Column="2"
Margin="5"
Padding="5"
Background="Transparent"
Click="ExportBtn_Click"
Content="&#xF1A5;"
Cursor="Hand"
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
Foreground="{DynamicResource Foreground1}"
Style="{DynamicResource ToolButton}" />
<Button
x:Name="GetWiFiBtn"
Grid.Column="3"
Margin="5"
Padding="5"
Background="{DynamicResource LightAccent}"
Click="GetWiFiBtn_Click"
Content="{x:Static lang:Resources.GetWiFi}"
Cursor="Hand"
FontWeight="ExtraBold"
Foreground="{DynamicResource Accent}"
Style="{DynamicResource PrimaryButton}" />
<Popup
x:Name="ExportPopup"
AllowsTransparency="True"
Placement="Bottom"
PlacementTarget="{Binding ElementName=ExportBtn}"
PopupAnimation="Fade"
StaysOpen="False">
<Border
Margin="10"
Padding="5"
Background="{DynamicResource Background1}"
CornerRadius="5">
<Border.Effect>
<DropShadowEffect
BlurRadius="10"
Opacity="0.4"
RenderingBias="Performance"
ShadowDepth="0"
Color="Black" />
</Border.Effect>
<StackPanel>
<Button
x:Name="ExportWithPasswordBtn"
Grid.Column="3"
Padding="5"
Background="Transparent"
Click="ExportWithPasswordBtn_Click"
Content="{x:Static lang:Resources.ExportWithPasswords}"
Cursor="Hand"
FontWeight="ExtraBold"
Foreground="{DynamicResource Foreground1}"
Style="{DynamicResource PrimaryButton}" />

<Button
x:Name="ExportWithoutPasswordBtn"
Grid.Column="3"
Padding="5"
Background="Transparent"
Click="ExportWithoutPasswordBtn_Click"
Content="{x:Static lang:Resources.ExportWithoutPasswords}"
Cursor="Hand"
FontWeight="ExtraBold"
Foreground="{DynamicResource Foreground1}"
Style="{DynamicResource PrimaryButton}" />
</StackPanel>
</Border>
</Popup>
</Grid>

<Grid x:Name="PlaceholderGrid" Grid.Row="2" />
<StackPanel
Expand Down
45 changes: 45 additions & 0 deletions InternetTest/InternetTest/Pages/WiFiPasswordsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ MIT License
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Xml.Serialization;

namespace InternetTest.Pages;
Expand Down Expand Up @@ -105,6 +106,27 @@ internal async Task GetWiFiNetworksInfo()
}
}

internal async Task ExportWiFiNetworkInfo(string path,bool includePasswords)
{
try
{
Process process = new();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = $"/c netsh wlan export profile {(includePasswords ? "key=clear" : "")} folder=\"{path}\"";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
await process.WaitForExitAsync();

MessageBox.Show(Properties.Resources.WiFiExportSuccessful, Properties.Resources.Export, MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
}
}

internal void LoadWiFiInfo(string path)
{
string[] files = Directory.GetFiles(path);
Expand Down Expand Up @@ -192,4 +214,27 @@ internal void ToggleConfidentialMode()
}
catch { }
}

private void ExportBtn_Click(object sender, RoutedEventArgs e)
{
ExportPopup.IsOpen = true;
}

private async void ExportWithPasswordBtn_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new() { UseDescriptionForTitle = true, Description = Properties.Resources.ExportWithPasswords };
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
await ExportWiFiNetworkInfo(folderBrowserDialog.SelectedPath, true);
}
}

private async void ExportWithoutPasswordBtn_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new() { UseDescriptionForTitle = true, Description = Properties.Resources.ExportWithoutPasswords };
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
await ExportWiFiNetworkInfo(folderBrowserDialog.SelectedPath, false);
}
}
}

0 comments on commit 65a5ad3

Please sign in to comment.