Skip to content

Commit

Permalink
Added the possibility to remember the user's WiFi passwords (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Dec 29, 2023
1 parent fa5f291 commit 3aea2da
Showing 1 changed file with 37 additions and 30 deletions.
67 changes: 37 additions & 30 deletions InternetTest/InternetTest/Pages/WiFiPasswordsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,18 @@ private void InitUI()
{
TitleTxt.Text = $"{Properties.Resources.Commands} > {Properties.Resources.WifiPasswords}";
PlaceholderGrid.Children.Add(Placeholder); // Show the placeholder instead of an empty page

try
{
if (!Directory.Exists(FileSys.AppDataPath + @"\Léo Corporation\InternetTest Pro\WiFis")) return;
LoadWiFiInfo(FileSys.AppDataPath + @"\Léo Corporation\InternetTest Pro\WiFis");
}
catch { }
}

internal async void GetWiFiBtn_Click(object sender, RoutedEventArgs e)
{
await GetWiFiNetworksInfo(); // Update the UI
if (WiFiItemDisplayer.Children.Count == 0)
{
PlaceholderGrid.Visibility = Visibility.Visible;
Placeholder.Visibility = Visibility.Visible;
}
else
{
PlaceholderGrid.Visibility = Visibility.Collapsed;
Placeholder.Visibility = Visibility.Collapsed;
}
await GetWiFiNetworksInfo(); // Update the UI

// Increment the interaction count of the ActionInfo in Global.SynethiaConfig
Global.SynethiaConfig.ActionsInfo.First(a => a.Name == "WiFiPasswords.Get").UsageCount++;
Expand All @@ -80,11 +77,9 @@ internal async Task GetWiFiNetworksInfo()
try
{
WiFiItemDisplayer.Children.Clear(); // Clear the panel
PlaceholderGrid.Visibility = Visibility.Collapsed; // Hide the placeholder
Placeholder.Visibility = Visibility.Collapsed; // Hide the placeholder

// Check if the temp directory exists
string path = FileSys.AppDataPath + @"\Léo Corporation\InternetTest Pro\Temp";
string path = FileSys.AppDataPath + @"\Léo Corporation\InternetTest Pro\WiFis";

if (!Directory.Exists(path))
{
Expand All @@ -102,28 +97,40 @@ internal async Task GetWiFiNetworksInfo()
await process.WaitForExitAsync();

// Read the files
string[] files = Directory.GetFiles(path);
for (int i = 0; i < files.Length; i++)
{
XmlSerializer serializer = new(typeof(WLANProfile));
StreamReader streamReader = new(files[i]); // Where the file is going to be read

var test = (WLANProfile?)serializer.Deserialize(streamReader);
LoadWiFiInfo(path);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
}
}

if (test != null)
{
WiFiItemDisplayer.Children.Add(new WiFiInfoItem(test));
}
streamReader.Close();
internal void LoadWiFiInfo(string path)
{
string[] files = Directory.GetFiles(path);
for (int i = 0; i < files.Length; i++)
{
XmlSerializer serializer = new(typeof(WLANProfile));
StreamReader streamReader = new(files[i]); // Where the file is going to be read

File.Delete(files[i]); // Remove the temp file
var test = (WLANProfile?)serializer.Deserialize(streamReader);

if (test != null)
{
WiFiItemDisplayer.Children.Add(new WiFiInfoItem(test));
}
Directory.Delete(path); // Delete the temp directory
streamReader.Close();
}
catch (Exception ex)

if (WiFiItemDisplayer.Children.Count == 0)
{
MessageBox.Show(ex.Message, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
PlaceholderGrid.Visibility = Visibility.Visible;
Placeholder.Visibility = Visibility.Visible;
}
else
{
PlaceholderGrid.Visibility = Visibility.Collapsed;
Placeholder.Visibility = Visibility.Collapsed;
}
}

Expand Down

0 comments on commit 3aea2da

Please sign in to comment.