Skip to content

Commit 714cef7

Browse files
committed
Added the possibility to export save WLAN profiles (#671)
1 parent db047ef commit 714cef7

File tree

11 files changed

+157
-57
lines changed

11 files changed

+157
-57
lines changed
Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net8.0-windows</TargetFramework>
6-
<Nullable>enable</Nullable>
7-
<ImplicitUsings>enable</ImplicitUsings>
8-
<UseWPF>true</UseWPF>
9-
<ApplicationIcon>InternetTest.ico</ApplicationIcon>
10-
<ApplicationManifest>app.manifest</ApplicationManifest>
11-
<Version>9.0.0.2508-pre1</Version>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net8.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<UseWPF>true</UseWPF>
9+
<ApplicationIcon>InternetTest.ico</ApplicationIcon>
10+
<ApplicationManifest>app.manifest</ApplicationManifest>
11+
<Version>9.0.0.2508-pre1</Version>
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<None Remove="Assets\DarkTheme.png" />
16-
<None Remove="Assets\LightTheme.png" />
17-
<None Remove="Assets\SystemTheme.png" />
18-
<None Remove="Fonts\FluentSystemIcons-Filled.ttf" />
19-
<None Remove="Fonts\FluentSystemIcons-Regular.ttf" />
20-
<None Remove="Fonts\Hauora-ExtraBold.ttf" />
21-
<None Remove="Fonts\Hauora-Regular.ttf" />
22-
<None Remove="Fonts\Hauora-SemiBold.ttf" />
23-
<None Remove="InternetTest.ico" />
15+
<None Remove="Assets\DarkTheme.png" />
16+
<None Remove="Assets\LightTheme.png" />
17+
<None Remove="Assets\SystemTheme.png" />
18+
<None Remove="Fonts\FluentSystemIcons-Filled.ttf" />
19+
<None Remove="Fonts\FluentSystemIcons-Regular.ttf" />
20+
<None Remove="Fonts\Hauora-ExtraBold.ttf" />
21+
<None Remove="Fonts\Hauora-Regular.ttf" />
22+
<None Remove="Fonts\Hauora-SemiBold.ttf" />
23+
<None Remove="InternetTest.ico" />
2424
</ItemGroup>
2525

2626
<ItemGroup>
2727
<Content Include="InternetTest.ico" />
2828
</ItemGroup>
2929

3030
<ItemGroup>
31-
<PackageReference Include="ManagedNativeWifi" Version="3.0.2" />
32-
<PackageReference Include="MicaWPF.Lite" Version="6.3.0" />
33-
<PackageReference Include="PeyrSharp.Core" Version="2.1.0.2312" />
34-
<PackageReference Include="PeyrSharp.Env" Version="2.1.0.2312" />
35-
<PackageReference Include="QRCoder" Version="1.6.0" />
31+
<PackageReference Include="ManagedNativeWifi" Version="3.0.2" />
32+
<PackageReference Include="MicaWPF.Lite" Version="6.3.0" />
33+
<PackageReference Include="PeyrSharp.Core" Version="2.1.0.2312" />
34+
<PackageReference Include="PeyrSharp.Env" Version="2.1.0.2312" />
35+
<PackageReference Include="QRCoder" Version="1.6.0" />
3636
</ItemGroup>
3737

3838
<ItemGroup>
39-
<Resource Include="Assets\DarkTheme.png">
40-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
41-
</Resource>
42-
<Resource Include="Assets\LightTheme.png">
43-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
44-
</Resource>
45-
<Resource Include="Assets\SystemTheme.png">
46-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
47-
</Resource>
48-
<Resource Include="Fonts\FluentSystemIcons-Filled.ttf">
49-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
50-
</Resource>
51-
<Resource Include="Fonts\FluentSystemIcons-Regular.ttf">
52-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
53-
</Resource>
54-
<Resource Include="Fonts\Hauora-ExtraBold.ttf">
55-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
56-
</Resource>
57-
<Resource Include="Fonts\Hauora-Regular.ttf">
58-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
59-
</Resource>
60-
<Resource Include="Fonts\Hauora-SemiBold.ttf">
61-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
62-
</Resource>
39+
<Resource Include="Assets\DarkTheme.png">
40+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
41+
</Resource>
42+
<Resource Include="Assets\LightTheme.png">
43+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
44+
</Resource>
45+
<Resource Include="Assets\SystemTheme.png">
46+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
47+
</Resource>
48+
<Resource Include="Fonts\FluentSystemIcons-Filled.ttf">
49+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
50+
</Resource>
51+
<Resource Include="Fonts\FluentSystemIcons-Regular.ttf">
52+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
53+
</Resource>
54+
<Resource Include="Fonts\Hauora-ExtraBold.ttf">
55+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
56+
</Resource>
57+
<Resource Include="Fonts\Hauora-Regular.ttf">
58+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
59+
</Resource>
60+
<Resource Include="Fonts\Hauora-SemiBold.ttf">
61+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
62+
</Resource>
6363
</ItemGroup>
6464

6565
<ItemGroup>
66-
<Compile Update="Properties\Resources.Designer.cs">
67-
<DesignTime>True</DesignTime>
68-
<AutoGen>True</AutoGen>
69-
<DependentUpon>Resources.resx</DependentUpon>
70-
</Compile>
66+
<Compile Update="Properties\Resources.Designer.cs">
67+
<DesignTime>True</DesignTime>
68+
<AutoGen>True</AutoGen>
69+
<DependentUpon>Resources.resx</DependentUpon>
70+
</Compile>
7171
</ItemGroup>
7272

7373
<ItemGroup>
74-
<EmbeddedResource Update="Properties\Resources.resx">
75-
<Generator>PublicResXFileCodeGenerator</Generator>
76-
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
77-
</EmbeddedResource>
74+
<EmbeddedResource Update="Properties\Resources.resx">
75+
<Generator>PublicResXFileCodeGenerator</Generator>
76+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
77+
</EmbeddedResource>
7878
</ItemGroup>
7979

8080
</Project>

InternetTest/InternetTest/Models/WlanProfile.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,27 @@ public static async Task<List<WlanProfile>> GetProfilesAsync(bool forceRefresh =
158158
}
159159
}
160160

161+
public static async Task ExportProfilesAsync(string path, bool keyVis)
162+
{
163+
try
164+
{
165+
Process process = new();
166+
process.StartInfo.FileName = "cmd.exe";
167+
process.StartInfo.Arguments = $"/c netsh wlan export profile {(keyVis ? "key=clear" : "")} folder=\"{path}\"";
168+
process.StartInfo.UseShellExecute = false;
169+
process.StartInfo.CreateNoWindow = true;
170+
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
171+
process.Start();
172+
await process.WaitForExitAsync();
173+
174+
MessageBox.Show(Properties.Resources.WiFiExportSuccessful, Properties.Resources.Export, MessageBoxButton.OK, MessageBoxImage.Information);
175+
}
176+
catch (Exception ex)
177+
{
178+
MessageBox.Show(ex.Message, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
179+
}
180+
}
181+
161182
private static async Task<string[]> GetFilesAsync(string directory, string searchPatternn)
162183
{
163184
return await Task.Run(() => Directory.GetFiles(directory, searchPatternn));

InternetTest/InternetTest/Properties/Resources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

InternetTest/InternetTest/Properties/Resources.en-US.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,4 +1185,10 @@ Absolutely NO data is sent to Léo Corporation.</value>
11851185
<data name="Manual" xml:space="preserve">
11861186
<value>Manual</value>
11871187
</data>
1188+
<data name="ExportWlanProfilesMsg" xml:space="preserve">
1189+
<value>Do you want to include passwords in the exported files?</value>
1190+
</data>
1191+
<data name="ExportWlanProfiles" xml:space="preserve">
1192+
<value>Export saved WiFi networks</value>
1193+
</data>
11881194
</root>

InternetTest/InternetTest/Properties/Resources.fr-FR.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,4 +1185,10 @@ Absolument AUCUNE donnée n'est envoyée à Léo Corporation.</value>
11851185
<data name="Manual" xml:space="preserve">
11861186
<value>Manuel</value>
11871187
</data>
1188+
<data name="ExportWlanProfilesMsg" xml:space="preserve">
1189+
<value>Souhaitez-vous inclure les mots de passe dans les fichiers exportés ?</value>
1190+
</data>
1191+
<data name="ExportWlanProfiles" xml:space="preserve">
1192+
<value>Export les réseaux WiFi sauvegardés</value>
1193+
</data>
11881194
</root>

InternetTest/InternetTest/Properties/Resources.it-IT.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,4 +1185,10 @@ Assolutamente NESSUN dato verrà inviato a Léo Corporation.</value>
11851185
<data name="Manual" xml:space="preserve">
11861186
<value>Manuale</value>
11871187
</data>
1188+
<data name="ExportWlanProfilesMsg" xml:space="preserve">
1189+
<value>Vuoi includere le password nei file esportati?</value>
1190+
</data>
1191+
<data name="ExportWlanProfiles" xml:space="preserve">
1192+
<value>Esporta reti WiFi salvate</value>
1193+
</data>
11881194
</root>

InternetTest/InternetTest/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,4 +1185,10 @@ Absolutely NO data is sent to Léo Corporation.</value>
11851185
<data name="Manual" xml:space="preserve">
11861186
<value>Manual</value>
11871187
</data>
1188+
<data name="ExportWlanProfilesMsg" xml:space="preserve">
1189+
<value>Do you want to include passwords in the exported files?</value>
1190+
</data>
1191+
<data name="ExportWlanProfiles" xml:space="preserve">
1192+
<value>Export saved WiFi networks</value>
1193+
</data>
11881194
</root>

InternetTest/InternetTest/Properties/Resources.zh-CN.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,4 +1176,10 @@
11761176
<data name="Manual" xml:space="preserve">
11771177
<value>手册</value>
11781178
</data>
1179+
<data name="ExportWlanProfilesMsg" xml:space="preserve">
1180+
<value>您是否希望在导出的文件中包含密码?</value>
1181+
</data>
1182+
<data name="ExportWlanProfiles" xml:space="preserve">
1183+
<value>导出已保存的Wi-Fi网络</value>
1184+
</data>
11791185
</root>

InternetTest/InternetTest/ViewModels/Components/WlanProfileItemViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public bool KeyVisible
9191
{
9292
if (QrCodeImage == null)
9393
return;
94-
94+
9595
var dialog = new SaveFileDialog() { Filter = "PNG Files|*.png", Title = Properties.Resources.Save, FileName = _wlanProfile.SSIDConfig?.SSID?.Name ?? "" };
9696
if (dialog.ShowDialog() ?? false)
9797
{

InternetTest/InternetTest/ViewModels/WiFiPageViewModel.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2626
using InternetTest.Models;
2727
using InternetTest.ViewModels.Components;
2828
using ManagedNativeWifi;
29+
using Microsoft.Win32;
2930
using System.Collections.ObjectModel;
3031
using System.Net.NetworkInformation;
3132
using System.Windows;
@@ -64,6 +65,23 @@ public ObservableCollection<NetworkAdapterItemViewModel> Adapters
6465
public ICommand RefreshCommand => new RelayCommand(o => GetAdapters());
6566
public ICommand RefreshWiFiCommand { get; set; }
6667
public ICommand RefreshProfilesCommand => new RelayCommand(o => RefreshProfiles(true));
68+
public ICommand ExportCommand => new RelayCommand(async o =>
69+
{
70+
if (MessageBox.Show(Properties.Resources.ExportWlanProfilesMsg, Properties.Resources.InternetTest, MessageBoxButton.YesNoCancel, MessageBoxImage.Question) != MessageBoxResult.Yes)
71+
return;
72+
73+
OpenFolderDialog openFolderDialog = new()
74+
{
75+
Title = Properties.Resources.Export,
76+
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
77+
Multiselect = false
78+
};
79+
80+
if (openFolderDialog.ShowDialog() == true)
81+
{
82+
await WlanProfile.ExportProfilesAsync(openFolderDialog.FolderNames[0], true);
83+
}
84+
});
6785

6886
public WiFiPageViewModel(Settings settings)
6987
{
@@ -83,7 +101,7 @@ public WiFiPageViewModel(Settings settings)
83101
{
84102
IsRefreshing = true;
85103
WiFiNetworks.Clear();
86-
104+
87105
await NativeWifi.ScanNetworksAsync(TimeSpan.FromSeconds(10));
88106

89107
string? currentSsid = NetworkHelper.GetCurrentWifiSSID();

0 commit comments

Comments
 (0)