Skip to content

Commit 3d2833e

Browse files
committed
Feature: Detect executable in AWS
1 parent 378512a commit 3d2833e

File tree

11 files changed

+148
-145
lines changed

11 files changed

+148
-145
lines changed

Source/NETworkManager.Models/ApplicationManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static Canvas GetIcon(ApplicationName name)
7878
canvas.Children.Add(new PackIconFontAwesome { Kind = PackIconFontAwesomeKind.TerminalSolid });
7979
break;
8080
case ApplicationName.AWSSessionManager:
81-
canvas.Children.Add(new PackIconMaterial { Kind = PackIconMaterialKind.Aws });
81+
canvas.Children.Add(new PackIconFontAwesome { Kind = PackIconFontAwesomeKind.AwsBrands });
8282
break;
8383
case ApplicationName.TigerVNC:
8484
canvas.Children.Add(new PackIconMaterial { Kind = PackIconMaterialKind.EyeOutline });

Source/NETworkManager.Models/PowerShell/PowerShell.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.Linq;
4+
using log4net;
55
using Microsoft.Win32;
66

77
namespace NETworkManager.Models.PowerShell;
@@ -11,20 +11,18 @@ namespace NETworkManager.Models.PowerShell;
1111
/// </summary>
1212
public static class PowerShell
1313
{
14+
private static readonly ILog Log = LogManager.GetLogger(typeof(PowerShell));
15+
1416
/// <summary>
15-
/// Default installation paths for PowerShell.
17+
/// Windows PowerShell file name.
1618
/// </summary>
19+
public const string WindowsPowerShellFileName = "powershell.exe";
20+
21+
/// <summary>
22+
/// PowerShell Core file name.
23+
/// </summary>
24+
public const string PwshFileName = "pwsh.exe";
1725

18-
public static readonly List<string> GetDefaultInstallationPaths =
19-
[
20-
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "PowerShell", "7", "pwsh.exe"),
21-
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "PowerShell", "7",
22-
"pwsh.exe"),
23-
24-
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows),
25-
@"System32\WindowsPowerShell\v1.0\powershell.exe")
26-
];
27-
2826
/// <summary>
2927
/// Default SZ registry keys for the global PowerShell profile.
3028
/// </summary>
@@ -92,12 +90,13 @@ public static void WriteDefaultProfileToRegistry(string theme, string powerShell
9290

9391
// Windows PowerShell --> HKCU:\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe
9492
if (powerShellPath.StartsWith(systemRoot))
95-
registryPath += "%SystemRoot%" + powerShellPath
96-
.Substring(systemRoot.Length, powerShellPath.Length - systemRoot.Length).Replace(@"\", "_");
93+
registryPath += "%SystemRoot%" + powerShellPath.Substring(systemRoot.Length, powerShellPath.Length - systemRoot.Length).Replace(@"\", "_");
9794
// PWSH --> HKCU:\Console\C:_Program Files_PowerShell_7_pwsh.exe
9895
else
9996
registryPath += powerShellPath.Replace(@"\", "_");
10097

98+
Log.Info($"Registry path for PowerShell profile: \"{registryPath}\"");
99+
101100
var registryKey = Registry.CurrentUser.OpenSubKey(registryPath, true);
102101

103102
registryKey ??= Registry.CurrentUser.CreateSubKey(registryPath);

Source/NETworkManager.Models/PuTTY/PuTTY.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ namespace NETworkManager.Models.PuTTY;
1010
/// <summary>
1111
/// Class control PuTTY.
1212
/// </summary>
13-
public class PuTTY
13+
public static class PuTTY
1414
{
1515
/// <summary>
1616
/// PuTTY file name.
1717
/// </summary>
18-
public static readonly string FileName = "putty.exe";
18+
public const string FileName = "putty.exe";
1919

2020
/// <summary>
2121
/// Default SZ registry keys for PuTTY profile NETworkManager.

Source/NETworkManager.Settings/SettingsManager.cs

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,6 @@ public static void Upgrade(Version fromVersion, Version toVersion)
173173
{
174174
Log.Info($"Start settings upgrade from {fromVersion} to {toVersion}...");
175175

176-
// 2022.12.20.0
177-
if (fromVersion < new Version(2022, 12, 20, 0))
178-
UpgradeTo_2022_12_20_0();
179-
180176
// 2023.3.7.0
181177
if (fromVersion < new Version(2023, 3, 7, 0))
182178
UpgradeTo_2023_3_7_0();
@@ -193,6 +189,11 @@ public static void Upgrade(Version fromVersion, Version toVersion)
193189
if (fromVersion < new Version(2023, 11, 28, 0))
194190
UpgradeTo_2023_11_28_0();
195191

192+
193+
// 2024.11.11.0
194+
if (fromVersion < new Version(2024, 11, 11, 0))
195+
UpgradeTo_2024_11_11_0();
196+
196197
// Latest
197198
if (fromVersion < toVersion)
198199
UpgradeToLatest(toVersion);
@@ -204,35 +205,7 @@ public static void Upgrade(Version fromVersion, Version toVersion)
204205
Log.Info("Settings upgrade finished!");
205206
}
206207

207-
/// <summary>
208-
/// Method to apply changes for version 2022.12.20.0.
209-
/// </summary>
210-
private static void UpgradeTo_2022_12_20_0()
211-
{
212-
Log.Info("Apply update to 2022.12.20.0...");
213-
214-
// Add AWS Session Manager application
215-
Log.Info("Add new app \"AWSSessionManager\"...");
216-
Current.General_ApplicationList.Add(ApplicationManager.GetDefaultList()
217-
.First(x => x.Name == ApplicationName.AWSSessionManager));
218-
219-
var powerShellPath = "";
220-
foreach (var file in PowerShell.GetDefaultInstallationPaths.Where(File.Exists))
221-
{
222-
powerShellPath = file;
223-
break;
224-
}
225-
226-
Log.Info($"Set \"AWSSessionManager_ApplicationFilePath\" to \"{powerShellPath}\"...");
227-
Current.AWSSessionManager_ApplicationFilePath = powerShellPath;
228-
229-
// Add Bit Calculator application
230-
Log.Info("Add new app \"BitCalculator\"...");
231-
Current.General_ApplicationList.Add(ApplicationManager.GetDefaultList()
232-
.First(x => x.Name == ApplicationName.BitCalculator));
233-
}
234-
235-
/// <summary>
208+
/// <summary>
236209
/// Method to apply changes for version 2023.3.7.0.
237210
/// </summary>
238211
private static void UpgradeTo_2023_3_7_0()
@@ -326,6 +299,18 @@ private static void UpgradeTo_2023_11_28_0()
326299
Current.DNSLookup_DNSServers =
327300
new ObservableCollection<DNSServerConnectionInfoProfile>(DNSServer.GetDefaultList());
328301
}
302+
303+
/// <summary>
304+
/// Method to apply changes for version 2024.11.11.0.
305+
/// </summary>
306+
private static void UpgradeTo_2024_11_11_0()
307+
{
308+
Log.Info("Apply upgrade to 2024.11.11.0...");
309+
310+
Log.Info("Reset ApplicationList to default...");
311+
Current.General_ApplicationList =
312+
new ObservableSetCollection<ApplicationInfo>(ApplicationManager.GetDefaultList());
313+
}
329314

330315
/// <summary>
331316
/// Method to apply changes for the latest version.
@@ -335,9 +320,7 @@ private static void UpgradeToLatest(Version version)
335320
{
336321
Log.Info($"Apply upgrade to {version}...");
337322

338-
Log.Info("Reset ApplicationList to default...");
339-
Current.General_ApplicationList =
340-
new ObservableSetCollection<ApplicationInfo>(ApplicationManager.GetDefaultList());
323+
341324
}
342325

343326
#endregion

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,6 @@ private void SettingsManager_PropertyChanged(object sender, PropertyChangedEvent
7373
case nameof(SettingsInfo.Network_CustomDNSServer):
7474
ConfigureDNSServer();
7575

76-
break;
77-
78-
// Update PowerShell profile if changed in the settings
79-
case nameof(SettingsInfo.Appearance_PowerShellModifyGlobalProfile):
80-
case nameof(SettingsInfo.Appearance_Theme):
81-
case nameof(SettingsInfo.PowerShell_ApplicationFilePath):
82-
case nameof(SettingsInfo.AWSSessionManager_ApplicationFilePath):
83-
// Skip on welcome dialog
84-
if (SettingsManager.Current.WelcomeDialog_Show)
85-
return;
86-
87-
WriteDefaultPowerShellProfileToRegistry();
88-
8976
break;
9077
}
9178
}
@@ -538,15 +525,6 @@ await this.ShowMessageAsync(Strings.SettingsHaveBeenReset,
538525
SettingsManager.Current.SNTPLookup_SNTPServers =
539526
new ObservableCollection<ServerConnectionInfoProfile>(SNTPServer.GetDefaultList());
540527

541-
// Check if PowerShell is installed
542-
foreach (var file in PowerShell.GetDefaultInstallationPaths.Where(File.Exists))
543-
{
544-
SettingsManager.Current.PowerShell_ApplicationFilePath = file;
545-
SettingsManager.Current.AWSSessionManager_ApplicationFilePath = file;
546-
547-
break;
548-
}
549-
550528
SettingsManager.Current.WelcomeDialog_Show = false;
551529

552530
// Save it to create a settings file
@@ -593,9 +571,6 @@ private void Load()
593571
NetworkChange.NetworkAvailabilityChanged += (_, _) => OnNetworkHasChanged();
594572
NetworkChange.NetworkAddressChanged += (_, _) => OnNetworkHasChanged();
595573

596-
// Set PowerShell global profile
597-
WriteDefaultPowerShellProfileToRegistry();
598-
599574
// Search for updates...
600575
if (SettingsManager.Current.Update_CheckForUpdatesAtStartup)
601576
CheckForUpdates();
@@ -1895,28 +1870,7 @@ private void ConfigureDNSServer()
18951870

18961871
DNSClient.GetInstance().Configure(dnsSettings);
18971872
}
1898-
1899-
private void WriteDefaultPowerShellProfileToRegistry()
1900-
{
1901-
if (!SettingsManager.Current.Appearance_PowerShellModifyGlobalProfile)
1902-
return;
1903-
1904-
HashSet<string> paths = [];
1905-
1906-
// PowerShell
1907-
if (!string.IsNullOrEmpty(SettingsManager.Current.PowerShell_ApplicationFilePath) &&
1908-
File.Exists(SettingsManager.Current.PowerShell_ApplicationFilePath))
1909-
paths.Add(SettingsManager.Current.PowerShell_ApplicationFilePath);
1910-
1911-
// AWS Session Manager
1912-
if (!string.IsNullOrEmpty(SettingsManager.Current.AWSSessionManager_ApplicationFilePath) &&
1913-
File.Exists(SettingsManager.Current.AWSSessionManager_ApplicationFilePath))
1914-
paths.Add(SettingsManager.Current.AWSSessionManager_ApplicationFilePath);
1915-
1916-
foreach (var path in paths)
1917-
PowerShell.WriteDefaultProfileToRegistry(SettingsManager.Current.Appearance_Theme, path);
1918-
}
1919-
1873+
19201874
#endregion
19211875

19221876
#region Status window
@@ -2003,4 +1957,4 @@ private async void FocusEmbeddedWindow()
20031957
}
20041958

20051959
#endregion
2006-
}
1960+
}

0 commit comments

Comments
 (0)