Skip to content

Commit 4761f3f

Browse files
authored
Feature: Find app path (BornToBeRoot#2962)
* Feature: Find app path * Fix: Docs * Fix: Docs * Feature: Detect executable in AWS * Docs: BornToBeRoot#2962 * Feature: Find PowerShell/PuTTY by path * Docs: Typo * Feature: PowerShell path
1 parent a128bd6 commit 4761f3f

22 files changed

+456
-421
lines changed

.github/pull_request_template.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ Provide a Copilot generated summary of the changes in this pull request.
2020

2121
## To-Do
2222

23-
- [ ] Update [documentation](https://github.com/BornToBeRoot/NETworkManager/tree/main/docs/Documentation) to reflect this changes
24-
- [ ] Update [changelog](https://github.com/BornToBeRoot/NETworkManager/tree/main/docs/Changelog) to reflect this changes
23+
- [ ] Update [documentation](https://github.com/BornToBeRoot/NETworkManager/tree/main/Website/docs) to reflect this changes
24+
- [ ] Update [changelog](https://github.com/BornToBeRoot/NETworkManager/tree/main/Website/docs/changelog) to reflect this changes
2525

2626
## Contributing
2727

2828
**By submitting this pull request, I confirm the following:**
2929

3030
- [ ] I have read and understood the [contributing guidelines](https://github.com/BornToBeRoot/NETworkManager/blob/main/CONTRIBUTING.md) and the [code of conduct](https://github.com/BornToBeRoot/NETworkManager/blob/main/CODE_OF_CONDUCT.md).
31-
- [ ] I have have added my name, username or email to the [contributors](https://github.com/BornToBeRoot/NETworkManager/blob/main/Contributors.md) list or don't want to.
31+
- [ ] I have have added my name, username or email to the [contributors](https://github.com/BornToBeRoot/NETworkManager/blob/main/CONTRIBUTORS.md) list or don't want to.
3232
- [ ] The code or resource is compatible with the [GNU General Public License v3.0](https://github.com/BornToBeRoot/NETworkManager/blob/main/LICENSE).

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
- You found a bug or have a feature request? Feel free to create a [new issue](https://github.com/BornToBeRoot/NETworkManager/issues/new/choose).
44
- General questions can be discussed in the [GitHub discussions](https://github.com/BornToBeRoot/NETworkManager/discussions).
5-
- If you contribute to the code, documentation or translation, you can add your name to the [contributors](https://github.com/BornToBeRoot/NETworkManager/blob/main/Contributors.md) list with a pull request.
5+
- If you contribute to the code, documentation or translation, you can add your name to the [contributors](https://github.com/BornToBeRoot/NETworkManager/blob/main/CONTRIBUTORS.md) list with a pull request.
66

77
## Code
88
- If you want to fix a bug or implement a new features, let me know in the issues that you are work on it.
File renamed without changes.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Want to contribute to NETworkManager? Here are a few information on how to get s
121121
- [Improve the documentation](CONTRIBUTING.md#documentation)
122122
- [Report a security vulnerability](https://github.com/BornToBeRoot/NETworkManager/blob/main/SECURITY.md)
123123

124-
A list of all contributors can be found [here](https://github.com/BornToBeRoot/NETworkManager/blob/main/Contributors.md).
124+
A list of all contributors can be found [here](https://github.com/BornToBeRoot/NETworkManager/blob/main/CONTRIBUTORS.md).
125125

126126
This project has adopted the [code of conduct](https://github.com/BornToBeRoot/NETworkManager/blob/main/CODE_OF_CONDUCT.md) defined by the [Contributor Covenant](https://contributor-covenant.org/).
127127

Source/GlobalAssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
[assembly: AssemblyTrademark("")]
77
[assembly: AssemblyCulture("")]
88

9-
[assembly: AssemblyVersion("2024.11.18.0")]
10-
[assembly: AssemblyFileVersion("2024.11.18.0")]
9+
[assembly: AssemblyVersion("2025.1.18.0")]
10+
[assembly: AssemblyFileVersion("2025.1.18.0")]

Source/NETworkManager.Models/ApplicationManager.cs

+1-1
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

+35-37
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,44 +11,43 @@ 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>
17-
public static readonly List<string> GetDefaultInstallationPaths = new()
18-
{
19-
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "PowerShell", "7", "pwsh.exe"),
20-
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "PowerShell", "7",
21-
"pwsh.exe"),
22-
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows),
23-
@"System32\WindowsPowerShell\v1.0\powershell.exe")
24-
};
25-
19+
public const string WindowsPowerShellFileName = "powershell.exe";
20+
21+
/// <summary>
22+
/// PowerShell Core file name.
23+
/// </summary>
24+
public const string PwshFileName = "pwsh.exe";
25+
2626
/// <summary>
2727
/// Default SZ registry keys for the global PowerShell profile.
2828
/// </summary>
29-
private static readonly List<Tuple<string, string>> DefaultProfileRegkeysSzBase = new()
30-
{
31-
new Tuple<string, string>("FaceName", "Consolas")
32-
};
29+
private static readonly List<Tuple<string, string>> DefaultProfileRegkeysSzBase =
30+
[
31+
new("FaceName", "Consolas")
32+
];
3333

3434
/// <summary>
3535
/// Default DWORD registry keys for the global PowerShell profile.
3636
/// </summary>
37-
private static readonly List<Tuple<string, int>> DefaultProfileRegkeysDwordBase = new()
38-
{
39-
new Tuple<string, int>("CursorType", 1),
40-
new Tuple<string, int>("FontFamily", 54), // 36
41-
new Tuple<string, int>("FontSize", 1179648), // 120000
42-
new Tuple<string, int>("FontWeight", 400) // 190
43-
};
37+
private static readonly List<Tuple<string, int>> DefaultProfileRegkeysDwordBase =
38+
[
39+
new("CursorType", 1),
40+
new("FontFamily", 54), // 36
41+
new("FontSize", 1179648), // 120000
42+
new("FontWeight", 400) // 190
43+
];
4444

4545
/// <summary>
4646
/// Default DWORD registry keys for the global PowerShell profile to delete.
4747
/// </summary>
48-
private static readonly List<string> DefaultProfileRegkeysDwordDelete = new()
49-
{
48+
private static readonly List<string> DefaultProfileRegkeysDwordDelete = [
5049
"ScreenColors"
51-
};
50+
];
5251

5352
/// <summary>
5453
/// Default DWORD registry keys for the global PowerShell profile with dark theme.
@@ -57,12 +56,11 @@ public static class PowerShell
5756
private static List<Tuple<string, int>> GetProfileRegkeysDwordDark()
5857
{
5958
return DefaultProfileRegkeysDwordBase.Concat(
60-
new[]
61-
{
62-
new Tuple<string, int>("DefaultBackground", 2434341), // HEX: 252525
63-
new Tuple<string, int>("ColorTable00", 2434341), // HEX: 252525
64-
new Tuple<string, int>("ColorTable07", 13421772) // HEX: cccccc
65-
}).ToList();
59+
[
60+
new Tuple<string, int>("DefaultBackground", 2434341), // HEX: 252525
61+
new Tuple<string, int>("ColorTable00", 2434341), // HEX: 252525
62+
new Tuple<string, int>("ColorTable07", 13421772) // HEX: cccccc
63+
]).ToList();
6664
}
6765

6866
/// <summary>
@@ -72,12 +70,11 @@ private static List<Tuple<string, int>> GetProfileRegkeysDwordDark()
7270
private static List<Tuple<string, int>> GetProfileRegkeysDwordWhite()
7371
{
7472
return DefaultProfileRegkeysDwordBase.Concat(
75-
new[]
76-
{
77-
new Tuple<string, int>("DefaultBackground", 16777215), // HEX: FFFFFF
73+
[
74+
new Tuple<string, int>("DefaultBackground", 16777215), // HEX: FFFFFF
7875
new Tuple<string, int>("ColorTable00", 16777215), // HEX: FFFFFF
7976
new Tuple<string, int>("ColorTable07", 2434341) // HEX: 252525
80-
}).ToList();
77+
]).ToList();
8178
}
8279

8380
/// <summary>
@@ -93,12 +90,13 @@ public static void WriteDefaultProfileToRegistry(string theme, string powerShell
9390

9491
// Windows PowerShell --> HKCU:\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe
9592
if (powerShellPath.StartsWith(systemRoot))
96-
registryPath += "%SystemRoot%" + powerShellPath
97-
.Substring(systemRoot.Length, powerShellPath.Length - systemRoot.Length).Replace(@"\", "_");
93+
registryPath += "%SystemRoot%" + powerShellPath.Substring(systemRoot.Length, powerShellPath.Length - systemRoot.Length).Replace(@"\", "_");
9894
// PWSH --> HKCU:\Console\C:_Program Files_PowerShell_7_pwsh.exe
9995
else
10096
registryPath += powerShellPath.Replace(@"\", "_");
10197

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

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

Source/NETworkManager.Models/PuTTY/PuTTY.cs

+46-62
Original file line numberDiff line numberDiff line change
@@ -10,95 +10,79 @@ namespace NETworkManager.Models.PuTTY;
1010
/// <summary>
1111
/// Class control PuTTY.
1212
/// </summary>
13-
public class PuTTY
13+
public static class PuTTY
1414
{
1515
/// <summary>
16-
/// Default PuTTY installation paths.
16+
/// PuTTY file name.
1717
/// </summary>
18-
public static readonly List<string> GetDefaultInstallationPaths = new()
19-
{
20-
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), _puttyFolder, _puttyFile),
21-
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), _puttyFolder, _puttyFile)
22-
};
18+
public const string FileName = "putty.exe";
2319

2420
/// <summary>
2521
/// Default SZ registry keys for PuTTY profile NETworkManager.
2622
/// </summary>
27-
private static readonly List<Tuple<string, string>> DefaultProfileRegkeysSZBase = new()
28-
{
29-
new Tuple<string, string>("Colour1", "255,255,255"),
30-
new Tuple<string, string>("Colour3", "85,85,85"),
31-
new Tuple<string, string>("Colour4", "0,0,0"),
32-
new Tuple<string, string>("Colour5", "0,255,0"),
33-
new Tuple<string, string>("Colour6", "0,0,0"),
34-
new Tuple<string, string>("Colour7", "85,85,85"),
35-
new Tuple<string, string>("Colour8", "187,0,0"),
36-
new Tuple<string, string>("Colour9", "255,85,85"),
37-
new Tuple<string, string>("Colour10", "0,187,0"),
38-
new Tuple<string, string>("Colour11", "85,255,85"),
39-
new Tuple<string, string>("Colour12", "187,187,0"),
40-
new Tuple<string, string>("Colour13", "255,255,85"),
41-
new Tuple<string, string>("Colour14", "0,0,187"),
42-
new Tuple<string, string>("Colour15", "85,85,255"),
43-
new Tuple<string, string>("Colour16", "187,0,187"),
44-
new Tuple<string, string>("Colour17", "255,85,255"),
45-
new Tuple<string, string>("Colour18", "0,187,187"),
46-
new Tuple<string, string>("Colour19", "85,255,255"),
47-
new Tuple<string, string>("Colour20", "187,187,187"),
48-
new Tuple<string, string>("Colour21", "255,255,255"),
49-
new Tuple<string, string>("LineCodePage", "UTF-8"),
50-
new Tuple<string, string>("Font", "Consolas")
51-
};
23+
private static readonly List<Tuple<string, string>> DefaultProfileRegkeysSzBase =
24+
[
25+
new("Colour1", "255,255,255"),
26+
new("Colour3", "85,85,85"),
27+
new("Colour4", "0,0,0"),
28+
new("Colour5", "0,255,0"),
29+
new("Colour6", "0,0,0"),
30+
new("Colour7", "85,85,85"),
31+
new("Colour8", "187,0,0"),
32+
new("Colour9", "255,85,85"),
33+
new("Colour10", "0,187,0"),
34+
new("Colour11", "85,255,85"),
35+
new("Colour12", "187,187,0"),
36+
new("Colour13", "255,255,85"),
37+
new("Colour14", "0,0,187"),
38+
new("Colour15", "85,85,255"),
39+
new("Colour16", "187,0,187"),
40+
new("Colour17", "255,85,255"),
41+
new("Colour18", "0,187,187"),
42+
new("Colour19", "85,255,255"),
43+
new("Colour20", "187,187,187"),
44+
new("Colour21", "255,255,255"),
45+
new("LineCodePage", "UTF-8"),
46+
new("Font", "Consolas")
47+
];
5248

5349
/// <summary>
5450
/// Default DWORD registry keys for PuTTY profile NETworkManager.
5551
/// </summary>
56-
private static readonly List<Tuple<string, int>> DefaultProfileRegkeysDwordBase = new()
57-
{
58-
new Tuple<string, int>("CurType", 2),
59-
new Tuple<string, int>("FontHeight", 12),
60-
new Tuple<string, int>("BlinkCur", 1),
61-
new Tuple<string, int>("ScrollBar", 0)
62-
};
63-
64-
/// <summary>
65-
/// Name of the PuTTY folder.
66-
/// </summary>
67-
private static string _puttyFolder => "PuTTY";
68-
69-
/// <summary>
70-
/// Name of the PuTTY executable.
71-
/// </summary>
72-
private static string _puttyFile => "putty.exe";
52+
private static readonly List<Tuple<string, int>> DefaultProfileRegkeysDwordBase =
53+
[
54+
new("CurType", 2),
55+
new("FontHeight", 12),
56+
new("BlinkCur", 1),
57+
new("ScrollBar", 0)
58+
];
7359

7460
/// <summary>
7561
/// SZ registry keys for PuTTY profile NETworkManager if app theme is dark.
7662
/// </summary>
7763
/// <returns>List with SZ registry keys.</returns>
78-
private static List<Tuple<string, string>> GetProfileRegkeysSZDark()
64+
private static List<Tuple<string, string>> GetProfileRegkeysSzDark()
7965
{
80-
return DefaultProfileRegkeysSZBase.Concat(
81-
new[]
82-
{
83-
// new Tuple<string, string>("Colour0", "255,255,255"),
66+
return DefaultProfileRegkeysSzBase.Concat(
67+
[
68+
// new Tuple<string, string>("Colour0", "255,255,255"),
8469
new Tuple<string, string>("Colour0", "187,187,187"), // Foreground
8570
new Tuple<string, string>("Colour2", "37,37,37") // Background
86-
}).ToList();
71+
]).ToList();
8772
}
8873

8974
/// <summary>
9075
/// SZ registry keys for PuTTY profile NETworkManager if app theme is white.
9176
/// </summary>
9277
/// <returns>List with DWORD registry keys.</returns>
93-
private static List<Tuple<string, string>> GetProfileRegkeysSZWhite()
78+
private static List<Tuple<string, string>> GetProfileRegkeysSzWhite()
9479
{
95-
return DefaultProfileRegkeysSZBase.Concat(
96-
new[]
97-
{
98-
// new Tuple<string, string>("Colour0", "68,68,68"),
80+
return DefaultProfileRegkeysSzBase.Concat(
81+
[
82+
// new Tuple<string, string>("Colour0", "68,68,68"),
9983
new Tuple<string, string>("Colour0", "0,0,0"), // Foreground
10084
new Tuple<string, string>("Colour2", "255,255,255") // Background
101-
}).ToList();
85+
]).ToList();
10286
}
10387

10488
/// <summary>
@@ -116,7 +100,7 @@ public static void WriteDefaultProfileToRegistry(string theme)
116100

117101
if (registryKey != null)
118102
{
119-
foreach (var item in theme == "Dark" ? GetProfileRegkeysSZDark() : GetProfileRegkeysSZWhite())
103+
foreach (var item in theme == "Dark" ? GetProfileRegkeysSzDark() : GetProfileRegkeysSzWhite())
120104
registryKey.SetValue(item.Item1, item.Item2);
121105

122106
foreach (var item in DefaultProfileRegkeysDwordBase)

0 commit comments

Comments
 (0)