Skip to content

Commit 1cfaff1

Browse files
authored
Fix wrong arguments passed due to history in various dialogs (#1372)
* Fix PuTTY Connect * Update PuTTYHostViewModel.cs * Fix arguments in connect dialog * Update next-release.md * Update next-release.md
1 parent c324b2a commit 1cfaff1

9 files changed

+87
-124
lines changed

Source/NETworkManager.Settings/GlobalStaticConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static class GlobalStaticConfiguration
3030
// Settings
3131
public static ApplicationName General_DefaultApplicationViewName => ApplicationName.Dashboard;
3232
public static int General_BackgroundJobInterval => 15;
33-
public static int General_HistoryListEntries => 5;
33+
public static int General_HistoryListEntries => 10;
3434
public static bool SplashScreen_Enabled => true;
3535
public static string Appearance_Theme => "Dark";
3636
public static string Appearance_Accent => "Lime";

Source/NETworkManager/ViewModels/PowerShellConnectViewModel.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public string Host
3737
{
3838
if (value == _host)
3939
return;
40-
40+
4141
_host = value;
4242
OnPropertyChanged();
4343
}
@@ -98,7 +98,6 @@ public PowerShellConnectViewModel(Action<PowerShellConnectViewModel> connectComm
9898
EnableRemoteConsole = true;
9999
}
100100

101-
102101
HostHistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.PowerShell_HostHistory);
103102

104103
LoadSettings();
@@ -113,7 +112,7 @@ private void LoadSettings()
113112

114113
private void LoadExecutionPolicies()
115114
{
116-
ExecutionPolicies = System.Enum.GetValues(typeof(PowerShell.ExecutionPolicy)).Cast<PowerShell.ExecutionPolicy>().ToList();
115+
ExecutionPolicies = Enum.GetValues(typeof(PowerShell.ExecutionPolicy)).Cast<PowerShell.ExecutionPolicy>().ToList();
117116
ExecutionPolicy = ExecutionPolicies.FirstOrDefault(x => x == SettingsManager.Current.PowerShell_ExecutionPolicy);
118117
}
119118
}

Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,7 @@ private async Task Connect(string host = null)
336336
await _dialogCoordinator.HideMetroDialogAsync(this, customDialog);
337337
ConfigurationManager.Current.FixAirspace = false;
338338

339-
// Add host to history
340-
AddHostToHistory(instance.Host);
341-
342-
// Create Profile info
339+
// Create profile info
343340
var info = new PowerShellSessionInfo
344341
{
345342
EnableRemoteConsole = instance.EnableRemoteConsole,
@@ -348,6 +345,11 @@ private async Task Connect(string host = null)
348345
ExecutionPolicy = instance.ExecutionPolicy
349346
};
350347

348+
// Add to history
349+
// Note: The history can only be updated after the values have been read.
350+
// Otherwise, in some cases, incorrect values are taken over.
351+
AddHostToHistory(instance.Host);
352+
351353
// Connect
352354
Connect(info);
353355
}, async instance =>
@@ -375,7 +377,7 @@ private void ConnectProfileExternal()
375377
var info = new ProcessStartInfo
376378
{
377379
FileName = SettingsManager.Current.PowerShell_ApplicationFilePath,
378-
Arguments = Models.PowerShell.PowerShell.BuildCommandLine(NETworkManager.Profiles.Application.PowerShell.CreateSessionInfo(SelectedProfile))
380+
Arguments = PowerShell.BuildCommandLine(NETworkManager.Profiles.Application.PowerShell.CreateSessionInfo(SelectedProfile))
379381
};
380382

381383
Process.Start(info);
@@ -398,14 +400,10 @@ public void AddTab(string host)
398400
// Modify history list
399401
private static void AddHostToHistory(string host)
400402
{
401-
// Create the new list
402-
var list = ListHelper.Modify(SettingsManager.Current.PowerShell_HostHistory.ToList(), host, SettingsManager.Current.General_HistoryListEntries);
403-
404-
// Clear the old items
405-
SettingsManager.Current.PowerShell_HostHistory.Clear();
406-
407-
// Fill with the new items
408-
list.ForEach(x => SettingsManager.Current.PowerShell_HostHistory.Add(x));
403+
if (string.IsNullOrEmpty(host))
404+
return;
405+
406+
SettingsManager.Current.PowerShell_HostHistory = new ObservableCollection<string>(ListHelper.Modify(SettingsManager.Current.PowerShell_HostHistory.ToList(), host, SettingsManager.Current.General_HistoryListEntries));
409407
}
410408

411409
private void StartDelayedSearch()

Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs

Lines changed: 38 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ private bool PuTTY_Connected_CanExecute(object view)
249249

250250
return false;
251251
}
252-
252+
253253
public ICommand PuTTY_ReconnectCommand => new RelayCommand(PuTTY_ReconnectAction);
254254

255255
private void PuTTY_ReconnectAction(object view)
@@ -376,16 +376,7 @@ private async Task Connect(string host = null)
376376
await _dialogCoordinator.HideMetroDialogAsync(this, customDialog);
377377
ConfigurationManager.Current.FixAirspace = false;
378378

379-
// Add host to history
380-
AddHostToHistory(instance.Host);
381-
AddSerialLineToHistory(instance.SerialLine);
382-
AddPortToHistory(instance.Port.ToString());
383-
AddBaudToHistory(instance.Baud.ToString());
384-
AddUsernameToHistory(instance.Username);
385-
AddPrivateKeyToHistory(instance.PrivateKeyFile);
386-
AddProfileToHistory(instance.Profile);
387-
388-
// Create Profile info
379+
// Create profile info
389380
var info = new PuTTYSessionInfo
390381
{
391382
HostOrSerialLine = instance.ConnectionMode == ConnectionMode.Serial ? instance.SerialLine : instance.Host,
@@ -401,6 +392,17 @@ private async Task Connect(string host = null)
401392
AdditionalCommandLine = instance.AdditionalCommandLine
402393
};
403394

395+
// Add to history
396+
// Note: The history can only be updated after the values have been read.
397+
// Otherwise, in some cases, incorrect values are taken over.
398+
AddHostToHistory(instance.Host);
399+
AddSerialLineToHistory(instance.SerialLine);
400+
AddPortToHistory(instance.Port);
401+
AddBaudToHistory(instance.Baud);
402+
AddUsernameToHistory(instance.Username);
403+
AddPrivateKeyToHistory(instance.PrivateKeyFile);
404+
AddProfileToHistory(instance.Profile);
405+
404406
Connect(info);
405407
}, async instance =>
406408
{
@@ -454,86 +456,58 @@ public void AddTab(string host)
454456
// Modify history list
455457
private static void AddHostToHistory(string host)
456458
{
457-
// Create the new list
458-
var list = ListHelper.Modify(SettingsManager.Current.PuTTY_HostHistory.ToList(), host, SettingsManager.Current.General_HistoryListEntries);
459+
if (string.IsNullOrEmpty(host))
460+
return;
459461

460-
// Clear the old items
461-
SettingsManager.Current.PuTTY_HostHistory.Clear();
462-
463-
// Fill with the new items
464-
list.ForEach(x => SettingsManager.Current.PuTTY_HostHistory.Add(x));
462+
SettingsManager.Current.PuTTY_HostHistory = new ObservableCollection<string>(ListHelper.Modify(SettingsManager.Current.PuTTY_HostHistory.ToList(), host, SettingsManager.Current.General_HistoryListEntries));
465463
}
466464

467465
private static void AddSerialLineToHistory(string serialLine)
468466
{
469-
// Create the new list
470-
var list = ListHelper.Modify(SettingsManager.Current.PuTTY_SerialLineHistory.ToList(), serialLine, SettingsManager.Current.General_HistoryListEntries);
471-
472-
// Clear the old items
473-
SettingsManager.Current.PuTTY_SerialLineHistory.Clear();
467+
if (string.IsNullOrEmpty(serialLine))
468+
return;
474469

475-
// Fill with the new items
476-
list.ForEach(x => SettingsManager.Current.PuTTY_SerialLineHistory.Add(x));
470+
SettingsManager.Current.PuTTY_SerialLineHistory = new ObservableCollection<string>(ListHelper.Modify(SettingsManager.Current.PuTTY_SerialLineHistory.ToList(), serialLine, SettingsManager.Current.General_HistoryListEntries));
477471
}
478472

479-
private static void AddPortToHistory(string port)
473+
private static void AddPortToHistory(int port)
480474
{
481-
// Create the new list
482-
var list = ListHelper.Modify(SettingsManager.Current.PuTTY_PortHistory.ToList(), port, SettingsManager.Current.General_HistoryListEntries);
475+
if (port == 0)
476+
return;
483477

484-
// Clear the old items
485-
SettingsManager.Current.PuTTY_PortHistory.Clear();
486-
487-
// Fill with the new items
488-
list.ForEach(x => SettingsManager.Current.PuTTY_PortHistory.Add(x));
478+
SettingsManager.Current.PuTTY_PortHistory = new ObservableCollection<string>(ListHelper.Modify(SettingsManager.Current.PuTTY_PortHistory.ToList(), port.ToString(), SettingsManager.Current.General_HistoryListEntries));
489479
}
490480

491-
private static void AddBaudToHistory(string baud)
481+
private static void AddBaudToHistory(int baud)
492482
{
493-
// Create the new list
494-
var list = ListHelper.Modify(SettingsManager.Current.PuTTY_BaudHistory.ToList(), baud, SettingsManager.Current.General_HistoryListEntries);
495-
496-
// Clear the old items
497-
SettingsManager.Current.PuTTY_BaudHistory.Clear();
483+
if (baud == 0)
484+
return;
498485

499-
// Fill with the new items
500-
list.ForEach(x => SettingsManager.Current.PuTTY_BaudHistory.Add(x));
486+
SettingsManager.Current.PuTTY_BaudHistory = new ObservableCollection<string>(ListHelper.Modify(SettingsManager.Current.PuTTY_BaudHistory.ToList(), baud.ToString(), SettingsManager.Current.General_HistoryListEntries));
501487
}
502488

503489
private static void AddUsernameToHistory(string username)
504490
{
505-
// Create the new list
506-
var list = ListHelper.Modify(SettingsManager.Current.PuTTY_UsernameHistory.ToList(), username, SettingsManager.Current.General_HistoryListEntries);
507-
508-
// Clear the old items
509-
SettingsManager.Current.PuTTY_UsernameHistory.Clear();
491+
if (string.IsNullOrEmpty(username))
492+
return;
510493

511-
// Fill with the new items
512-
list.ForEach(x => SettingsManager.Current.PuTTY_UsernameHistory.Add(x));
494+
SettingsManager.Current.PuTTY_UsernameHistory = new ObservableCollection<string>(ListHelper.Modify(SettingsManager.Current.PuTTY_UsernameHistory.ToList(), username, SettingsManager.Current.General_HistoryListEntries));
513495
}
514496

515-
private static void AddPrivateKeyToHistory(string host)
497+
private static void AddPrivateKeyToHistory(string privateKey)
516498
{
517-
// Create the new list
518-
var list = ListHelper.Modify(SettingsManager.Current.PuTTY_PrivateKeyFileHistory.ToList(), host, SettingsManager.Current.General_HistoryListEntries);
499+
if (string.IsNullOrEmpty(privateKey))
500+
return;
519501

520-
// Clear the old items
521-
SettingsManager.Current.PuTTY_PrivateKeyFileHistory.Clear();
522-
523-
// Fill with the new items
524-
list.ForEach(x => SettingsManager.Current.PuTTY_PrivateKeyFileHistory.Add(x));
502+
SettingsManager.Current.PuTTY_PrivateKeyFileHistory = new ObservableCollection<string>(ListHelper.Modify(SettingsManager.Current.PuTTY_PrivateKeyFileHistory.ToList(), privateKey, SettingsManager.Current.General_HistoryListEntries));
525503
}
526504

527-
private static void AddProfileToHistory(string host)
505+
private static void AddProfileToHistory(string profile)
528506
{
529-
// Create the new list
530-
var list = ListHelper.Modify(SettingsManager.Current.PuTTY_ProfileHistory.ToList(), host, SettingsManager.Current.General_HistoryListEntries);
531-
532-
// Clear the old items
533-
SettingsManager.Current.PuTTY_ProfileHistory.Clear();
507+
if (string.IsNullOrEmpty(profile))
508+
return;
534509

535-
// Fill with the new items
536-
list.ForEach(x => SettingsManager.Current.PuTTY_ProfileHistory.Add(x));
510+
SettingsManager.Current.PuTTY_ProfileHistory = new ObservableCollection<string>(ListHelper.Modify(SettingsManager.Current.PuTTY_ProfileHistory.ToList(), profile, SettingsManager.Current.General_HistoryListEntries));
537511
}
538512

539513
private void StartDelayedSearch()

Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,6 @@ private async Task Connect(string host = null)
367367
await _dialogCoordinator.HideMetroDialogAsync(this, customDialog);
368368
ConfigurationManager.Current.FixAirspace = false;
369369

370-
// Add host to history
371-
AddHostToHistory(instance.Host);
372-
373370
// Create new session info with default settings
374371
var sessionInfo = NETworkManager.Profiles.Application.RemoteDesktop.CreateSessionInfo();
375372

@@ -392,6 +389,11 @@ private async Task Connect(string host = null)
392389
sessionInfo.Password = instance.Password;
393390
}
394391

392+
// Add to history
393+
// Note: The history can only be updated after the values have been read.
394+
// Otherwise, in some cases, incorrect values are taken over.
395+
AddHostToHistory(instance.Host);
396+
395397
Connect(sessionInfo);
396398
}, async instance =>
397399
{
@@ -483,14 +485,10 @@ public void AddTab(string host)
483485
// Modify history list
484486
private static void AddHostToHistory(string host)
485487
{
486-
// Create the new list
487-
var list = ListHelper.Modify(SettingsManager.Current.RemoteDesktop_HostHistory.ToList(), host, SettingsManager.Current.General_HistoryListEntries);
488-
489-
// Clear the old items
490-
SettingsManager.Current.RemoteDesktop_HostHistory.Clear();
491-
492-
// Fill with the new items
493-
list.ForEach(x => SettingsManager.Current.RemoteDesktop_HostHistory.Add(x));
488+
if (string.IsNullOrEmpty(host))
489+
return;
490+
491+
SettingsManager.Current.RemoteDesktop_HostHistory = new ObservableCollection<string>( ListHelper.Modify(SettingsManager.Current.RemoteDesktop_HostHistory.ToList(), host, SettingsManager.Current.General_HistoryListEntries));
494492
}
495493

496494
private void StartDelayedSearch()

Source/NETworkManager/ViewModels/TigerVNCConnectViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using NETworkManager.Utilities;
33
using System;
44
using System.ComponentModel;
5+
using System.Diagnostics;
56
using System.Windows.Data;
67
using System.Windows.Input;
78

Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,19 @@ private async Task Connect(string host = null)
337337
await _dialogCoordinator.HideMetroDialogAsync(this, customDialog);
338338
ConfigurationManager.Current.FixAirspace = false;
339339

340-
// Add host to history
341-
AddHostToHistory(instance.Host);
342-
AddPortToHistory(instance.Port);
343-
344-
// Create Profile info
340+
// Create profile info
345341
var info = new TigerVNCSessionInfo
346342
{
347343
Host = instance.Host,
348344
Port = instance.Port
349345
};
350346

347+
// Add to history
348+
// Note: The history can only be updated after the values have been read.
349+
// Otherwise, in some cases, incorrect values are taken over.
350+
AddHostToHistory(instance.Host);
351+
AddPortToHistory(instance.Port);
352+
351353
// Connect
352354
Connect(info);
353355
}, async instance =>
@@ -398,26 +400,18 @@ public void AddTab(string host)
398400
// Modify history list
399401
private static void AddHostToHistory(string host)
400402
{
401-
// Create the new list
402-
var list = ListHelper.Modify(SettingsManager.Current.TigerVNC_HostHistory.ToList(), host, SettingsManager.Current.General_HistoryListEntries);
403+
if (string.IsNullOrEmpty(host))
404+
return;
403405

404-
// Clear the old items
405-
SettingsManager.Current.TigerVNC_HostHistory.Clear();
406-
407-
// Fill with the new items
408-
list.ForEach(x => SettingsManager.Current.TigerVNC_HostHistory.Add(x));
406+
SettingsManager.Current.TigerVNC_HostHistory = new ObservableCollection<string>(ListHelper.Modify(SettingsManager.Current.TigerVNC_HostHistory.ToList(), host, SettingsManager.Current.General_HistoryListEntries));
409407
}
410408

411409
private static void AddPortToHistory(int port)
412410
{
413-
// Create the new list
414-
var list = ListHelper.Modify(SettingsManager.Current.TigerVNC_PortHistory.ToList(), port, SettingsManager.Current.General_HistoryListEntries);
415-
416-
// Clear the old items
417-
SettingsManager.Current.TigerVNC_PortHistory.Clear();
411+
if (port == 0)
412+
return;
418413

419-
// Fill with the new items
420-
list.ForEach(x => SettingsManager.Current.TigerVNC_PortHistory.Add(x));
414+
SettingsManager.Current.TigerVNC_PortHistory = new ObservableCollection<int>(ListHelper.Modify(SettingsManager.Current.TigerVNC_PortHistory.ToList(), port, SettingsManager.Current.General_HistoryListEntries));
421415
}
422416

423417
private void StartDelayedSearch()

0 commit comments

Comments
 (0)