Skip to content

Feature: Profile file unlock child window #3010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

3 changes: 3 additions & 0 deletions Source/NETworkManager.Localization/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3876,4 +3876,7 @@ Right-click for more options.</value>
<data name="Donate" xml:space="preserve">
<value>Donate</value>
</data>
<data name="ProfileFile" xml:space="preserve">
<value>Profile file</value>
</data>
</root>
21 changes: 21 additions & 0 deletions Source/NETworkManager.Settings/ConfigurationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,27 @@ public string ProfileManagerErrorMessage
}
}

/// <summary>
/// Private variable for <see cref="IsChildWindowOpen" />.
/// </summary>
private bool _isChildWindowOpen;

/// <summary>
/// Indicates if a child window is open.
/// </summary>
public bool IsChildWindowOpen
{
get => _isChildWindowOpen;
set
{
if (value == _isChildWindowOpen)
return;

_isChildWindowOpen = value;
OnPropertyChanged();
}
}

/// <summary>
/// Private variable for <see cref="FixAirspace" />.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
</mah:WindowCommands>
</mah:MetroWindow.LeftWindowCommands>
<mah:MetroWindow.RightWindowCommands>
<mah:WindowCommands ShowSeparators="False" Visibility="{Binding IsWelcomeWindowOpen, Converter={StaticResource BooleanReverseToVisibilityCollapsedConverter}}">
<mah:WindowCommands ShowSeparators="False" Visibility="{Binding Source={x:Static settings:ConfigurationManager.Current}, Path=IsChildWindowOpen, Converter={StaticResource BooleanReverseToVisibilityCollapsedConverter}}">
<Button Command="{Binding OpenRunCommand}"
Visibility="{Binding Path=FlyoutRunCommandIsOpen, Converter={StaticResource ResourceKey=BooleanReverseToVisibilityCollapsedConverter}}"
ToolTip="{x:Static localization:Strings.ToolTip_RunCommandWithHotKey}"
Expand Down
99 changes: 38 additions & 61 deletions Source/NETworkManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using log4net;
using Dragablz;
using log4net;
using MahApps.Metro.Controls.Dialogs;
using MahApps.Metro.SimpleChildWindow;
using NETworkManager.Controls;
Expand All @@ -9,8 +10,6 @@
using NETworkManager.Models.AWS;
using NETworkManager.Models.EventSystem;
using NETworkManager.Models.Network;
using NETworkManager.Models.PowerShell;
using NETworkManager.Models.PuTTY;
using NETworkManager.Profiles;
using NETworkManager.Settings;
using NETworkManager.Update;
Expand All @@ -19,11 +18,9 @@
using NETworkManager.Views;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Runtime.CompilerServices;
Expand All @@ -38,7 +35,6 @@
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Threading;
using Dragablz;
using Application = System.Windows.Application;
using ContextMenu = System.Windows.Controls.ContextMenu;
using MouseEventArgs = System.Windows.Forms.MouseEventArgs;
Expand Down Expand Up @@ -116,21 +112,6 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null)
private bool _isInTray;
private bool _isClosing;

private bool _isWelcomeWindowOpen;

public bool IsWelcomeWindowOpen
{
get => _isWelcomeWindowOpen;
set
{
if (value == _isWelcomeWindowOpen)
return;

_isWelcomeWindowOpen = value;
OnPropertyChanged();
}
}

private bool _applicationViewIsExpanded;

public bool ApplicationViewIsExpanded
Expand Down Expand Up @@ -412,7 +393,7 @@ public ProfileFileInfo SelectedProfileFile
{
if (!_isProfileFileUpdating)
LoadProfile(value);

ConfigurationManager.Current.ProfileManagerShowUnlock = value.IsEncrypted && !value.IsPasswordValid;
SettingsManager.Current.Profiles_LastSelected = value.Name;
}
Expand Down Expand Up @@ -492,13 +473,13 @@ await this.ShowMessageAsync(Strings.SettingsHaveBeenReset,
if (SettingsManager.Current.WelcomeDialog_Show)
{

var welcomeChildWindow = new WelcomeChildWindow();
var childWindow = new WelcomeChildWindow();

var welcomeViewModel = new WelcomeViewModel(async instance =>
var viewModel = new WelcomeViewModel(instance =>
{
IsWelcomeWindowOpen = false;
childWindow.IsOpen = false;

welcomeChildWindow.IsOpen = false;
ConfigurationManager.Current.IsChildWindowOpen = false;

// Set settings based on user choice
SettingsManager.Current.Update_CheckForUpdatesAtStartup = instance.CheckForUpdatesAtStartup;
Expand All @@ -511,21 +492,13 @@ await this.ShowMessageAsync(Strings.SettingsHaveBeenReset,
instance.PowerShellModifyGlobalProfile;

// Generate lists at runtime
SettingsManager.Current.General_ApplicationList =
new ObservableSetCollection<ApplicationInfo>(ApplicationManager.GetDefaultList());
SettingsManager.Current.IPScanner_CustomCommands =
new ObservableCollection<CustomCommandInfo>(IPScannerCustomCommand.GetDefaultList());
SettingsManager.Current.PortScanner_PortProfiles =
new ObservableCollection<PortProfileInfo>(PortProfile.GetDefaultList());
SettingsManager.Current.DNSLookup_DNSServers =
new ObservableCollection<DNSServerConnectionInfoProfile>(DNSServer.GetDefaultList());
SettingsManager.Current.AWSSessionManager_AWSProfiles =
new ObservableCollection<AWSProfileInfo>(AWSProfile.GetDefaultList());
SettingsManager.Current.SNMP_OidProfiles =
new ObservableCollection<SNMPOIDProfileInfo>(SNMPOIDProfile.GetDefaultList());
SettingsManager.Current.SNTPLookup_SNTPServers =
new ObservableCollection<ServerConnectionInfoProfile>(SNTPServer.GetDefaultList());

SettingsManager.Current.General_ApplicationList = [.. ApplicationManager.GetDefaultList()];
SettingsManager.Current.IPScanner_CustomCommands = [.. IPScannerCustomCommand.GetDefaultList()];
SettingsManager.Current.PortScanner_PortProfiles = [.. PortProfile.GetDefaultList()];
SettingsManager.Current.DNSLookup_DNSServers = [.. DNSServer.GetDefaultList()];
SettingsManager.Current.AWSSessionManager_AWSProfiles = [.. AWSProfile.GetDefaultList()];
SettingsManager.Current.SNMP_OidProfiles = [.. SNMPOIDProfile.GetDefaultList()];
SettingsManager.Current.SNTPLookup_SNTPServers = [.. SNTPServer.GetDefaultList()];
SettingsManager.Current.WelcomeDialog_Show = false;

// Save it to create a settings file
Expand All @@ -534,11 +507,11 @@ await this.ShowMessageAsync(Strings.SettingsHaveBeenReset,
Load();
});

welcomeChildWindow.DataContext = welcomeViewModel;
childWindow.DataContext = viewModel;

IsWelcomeWindowOpen = true;
ConfigurationManager.Current.IsChildWindowOpen = true;

await this.ShowChildWindowAsync(welcomeChildWindow);
await this.ShowChildWindowAsync(childWindow);
}
else
{
Expand Down Expand Up @@ -1395,7 +1368,7 @@ private void LoadProfiles()
.FirstOrDefault(x => x.Name == SettingsManager.Current.Profiles_LastSelected);
SelectedProfileFile ??= ProfileFiles.SourceCollection.Cast<ProfileFileInfo>().FirstOrDefault();
}

private async void LoadProfile(ProfileFileInfo info, bool showWrongPassword = false)
{
// Disable profile management while switching profiles
Expand All @@ -1404,34 +1377,37 @@ private async void LoadProfile(ProfileFileInfo info, bool showWrongPassword = fa

if (info.IsEncrypted && !info.IsPasswordValid)
{
var customDialog = new CustomDialog
{
Title = Strings.UnlockProfileFile
};
var childWindow = new CredentialsPasswordProfileFileChildWindow();

var viewModel = new CredentialsPasswordProfileFileViewModel(async instance =>
var viewModel = new CredentialsPasswordProfileFileViewModel(instance =>
{
await this.HideMetroDialogAsync(customDialog);
childWindow.IsOpen = false;

ConfigurationManager.Current.IsChildWindowOpen = false;

ConfigurationManager.OnDialogClose();

info.Password = instance.Password;

SwitchProfile(info);
}, async _ =>
}, _ =>
{
await this.HideMetroDialogAsync(customDialog);
childWindow.IsOpen = false;

ConfigurationManager.Current.IsChildWindowOpen = false;

ConfigurationManager.OnDialogClose();

ProfileManager.Unload();
}, info.Name, showWrongPassword);

customDialog.Content = new CredentialsPasswordProfileFileDialog
{
DataContext = viewModel
};
childWindow.DataContext = viewModel;

ConfigurationManager.OnDialogOpen();
await this.ShowMetroDialogAsync(customDialog);

ConfigurationManager.Current.IsChildWindowOpen = true;

await this.ShowChildWindowAsync(childWindow);
}
else
{
Expand Down Expand Up @@ -1566,7 +1542,7 @@ private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref

// Handle system commands (like maximize and restore)
case WmSysCommand:

switch (wParam.ToInt32())
{
// Window is maximized
Expand All @@ -1584,7 +1560,7 @@ private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref

return IntPtr.Zero;
}

private void UpdateOnWindowResize()
{
foreach (var tabablzControl in VisualTreeHelper.FindVisualChildren<TabablzControl>(this))
Expand All @@ -1609,6 +1585,7 @@ private void UpdateOnWindowResize()
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);

[DllImport("user32.dll")]

private static extern bool UnregisterHotKey(IntPtr hWnd, int id);

// WM_HOTKEY
Expand Down Expand Up @@ -1920,7 +1897,7 @@ private void ConfigureDNSServer()

DNSClient.GetInstance().Configure(dnsSettings);
}

#endregion

#region Status window
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<Setter Property="FontSize" Value="14" />
<Setter Property="BorderBrush" Value="{DynamicResource MahApps.Brushes.Gray8}" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="mah:ControlsHelper.FocusBorderBrush" Value="{DynamicResource MahApps.Brushes.Gray8}" />
<Setter Property="mah:PasswordBoxHelper.CapsLockWarningToolTip"
Value="{x:Static localization:Strings.CapsLockIsEnabled}" />
<Setter Property="mah:PasswordBoxHelper.CapsLockIcon">
Expand Down
16 changes: 10 additions & 6 deletions Source/NETworkManager/ViewModels/ARPTableViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ private set

private bool Refresh_CanExecute(object parameter)
{
return Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen;
return Application.Current.MainWindow != null &&
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
!ConfigurationManager.Current.IsChildWindowOpen;
}

private async Task RefreshAction()
Expand All @@ -267,7 +269,9 @@ private async Task RefreshAction()

private bool DeleteTable_CanExecute(object parameter)
{
return Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen;
return Application.Current.MainWindow != null &&
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
!ConfigurationManager.Current.IsChildWindowOpen;
}

private async Task DeleteTableAction()
Expand Down Expand Up @@ -297,8 +301,8 @@ private async Task DeleteTableAction()
private bool DeleteEntry_CanExecute(object parameter)
{
return Application.Current.MainWindow != null &&
!((MetroWindow)Application.Current.MainWindow)
.IsAnyDialogOpen;
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
!ConfigurationManager.Current.IsChildWindowOpen;;
}

private async Task DeleteEntryAction()
Expand Down Expand Up @@ -328,8 +332,8 @@ private async Task DeleteEntryAction()
private bool AddEntry_CanExecute(object parameter)
{
return Application.Current.MainWindow != null &&
!((MetroWindow)Application.Current.MainWindow)
.IsAnyDialogOpen;
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
!ConfigurationManager.Current.IsChildWindowOpen;
}

private async Task AddEntryAction()
Expand Down
4 changes: 2 additions & 2 deletions Source/NETworkManager/ViewModels/BitCalculatorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ private void LoadSettings()
private bool Calculate_CanExecute(object parameter)
{
return Application.Current.MainWindow != null &&
!((MetroWindow)Application.Current.MainWindow)
.IsAnyDialogOpen;
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
!ConfigurationManager.Current.IsChildWindowOpen;
}

private void CalculateAction()
Expand Down
4 changes: 3 additions & 1 deletion Source/NETworkManager/ViewModels/ConnectionsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ public string StatusMessage

private bool Refresh_CanExecute(object parameter)
{
return Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen;
return Application.Current.MainWindow != null &&
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
!ConfigurationManager.Current.IsChildWindowOpen;
}

private async Task RefreshAction()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using NETworkManager.Utilities;
using System;
using System.Security;
using System.Windows.Input;
using NETworkManager.Utilities;

namespace NETworkManager.ViewModels;

Expand All @@ -27,7 +27,6 @@ public class CredentialsPasswordProfileFileViewModel : ViewModelBase
/// </summary>
private bool _showWrongPassword;


/// <summary>
/// Initialize a new class <see cref="CredentialsPasswordProfileFileViewModel" /> with <see cref="OKCommand" /> and
/// <see cref="CancelCommand" />.
Expand Down
3 changes: 2 additions & 1 deletion Source/NETworkManager/ViewModels/DNSLookupViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ x is QueryType.A or QueryType.AAAA or QueryType.ANY or QueryType.CNAME or QueryT
private bool Query_CanExecute(object parameter)
{
return Application.Current.MainWindow != null &&
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen;
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
!ConfigurationManager.Current.IsChildWindowOpen;
}

private void QueryAction()
Expand Down
3 changes: 2 additions & 1 deletion Source/NETworkManager/ViewModels/IPGeolocationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ private void LoadSettings()
private bool Query_CanExecute(object parameter)
{
return Application.Current.MainWindow != null &&
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen;
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
!ConfigurationManager.Current.IsChildWindowOpen;
}

private void QueryAction()
Expand Down
Loading