Skip to content
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

Feature: Find app path #2962

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ Provide a Copilot generated summary of the changes in this pull request.

## To-Do

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

## Contributing

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

- [ ] 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).
- [ ] 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.
- [ ] 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.
- [ ] The code or resource is compatible with the [GNU General Public License v3.0](https://github.com/BornToBeRoot/NETworkManager/blob/main/LICENSE).
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- You found a bug or have a feature request? Feel free to create a [new issue](https://github.com/BornToBeRoot/NETworkManager/issues/new/choose).
- General questions can be discussed in the [GitHub discussions](https://github.com/BornToBeRoot/NETworkManager/discussions).
- 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.
- 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.

## Code
- If you want to fix a bug or implement a new features, let me know in the issues that you are work on it.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Want to contribute to NETworkManager? Here are a few information on how to get s
- [Improve the documentation](CONTRIBUTING.md#documentation)
- [Report a security vulnerability](https://github.com/BornToBeRoot/NETworkManager/blob/main/SECURITY.md)

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

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/).

Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager.Models/ApplicationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static Canvas GetIcon(ApplicationName name)
canvas.Children.Add(new PackIconFontAwesome { Kind = PackIconFontAwesomeKind.TerminalSolid });
break;
case ApplicationName.AWSSessionManager:
canvas.Children.Add(new PackIconMaterial { Kind = PackIconMaterialKind.Aws });
canvas.Children.Add(new PackIconFontAwesome { Kind = PackIconFontAwesomeKind.AwsBrands });
break;
case ApplicationName.TigerVNC:
canvas.Children.Add(new PackIconMaterial { Kind = PackIconMaterialKind.EyeOutline });
Expand Down
68 changes: 33 additions & 35 deletions Source/NETworkManager.Models/PowerShell/PowerShell.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using log4net;
using Microsoft.Win32;

namespace NETworkManager.Models.PowerShell;
Expand All @@ -11,44 +11,43 @@ namespace NETworkManager.Models.PowerShell;
/// </summary>
public static class PowerShell
{
private static readonly ILog Log = LogManager.GetLogger(typeof(PowerShell));

/// <summary>
/// Default installation paths for PowerShell.
/// Windows PowerShell file name.
/// </summary>
public static readonly List<string> GetDefaultInstallationPaths = new()
{
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "PowerShell", "7", "pwsh.exe"),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "PowerShell", "7",
"pwsh.exe"),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows),
@"System32\WindowsPowerShell\v1.0\powershell.exe")
};

public const string WindowsPowerShellFileName = "powershell.exe";

/// <summary>
/// PowerShell Core file name.
/// </summary>
public const string PwshFileName = "pwsh.exe";

/// <summary>
/// Default SZ registry keys for the global PowerShell profile.
/// </summary>
private static readonly List<Tuple<string, string>> DefaultProfileRegkeysSzBase = new()
{
new Tuple<string, string>("FaceName", "Consolas")
};
private static readonly List<Tuple<string, string>> DefaultProfileRegkeysSzBase =
[
new("FaceName", "Consolas")
];

/// <summary>
/// Default DWORD registry keys for the global PowerShell profile.
/// </summary>
private static readonly List<Tuple<string, int>> DefaultProfileRegkeysDwordBase = new()
{
new Tuple<string, int>("CursorType", 1),
new Tuple<string, int>("FontFamily", 54), // 36
new Tuple<string, int>("FontSize", 1179648), // 120000
new Tuple<string, int>("FontWeight", 400) // 190
};
private static readonly List<Tuple<string, int>> DefaultProfileRegkeysDwordBase =
[
new("CursorType", 1),
new("FontFamily", 54), // 36
new("FontSize", 1179648), // 120000
new("FontWeight", 400)
];

/// <summary>
/// Default DWORD registry keys for the global PowerShell profile to delete.
/// </summary>
private static readonly List<string> DefaultProfileRegkeysDwordDelete = new()
{
private static readonly List<string> DefaultProfileRegkeysDwordDelete = [
"ScreenColors"
};
];

/// <summary>
/// Default DWORD registry keys for the global PowerShell profile with dark theme.
Expand All @@ -57,12 +56,11 @@ public static class PowerShell
private static List<Tuple<string, int>> GetProfileRegkeysDwordDark()
{
return DefaultProfileRegkeysDwordBase.Concat(
new[]
{
new Tuple<string, int>("DefaultBackground", 2434341), // HEX: 252525
[
new Tuple<string, int>("DefaultBackground", 2434341), // HEX: 252525
new Tuple<string, int>("ColorTable00", 2434341), // HEX: 252525
new Tuple<string, int>("ColorTable07", 13421772) // HEX: cccccc
}).ToList();
]).ToList();
}

/// <summary>
Expand All @@ -72,12 +70,11 @@ private static List<Tuple<string, int>> GetProfileRegkeysDwordDark()
private static List<Tuple<string, int>> GetProfileRegkeysDwordWhite()
{
return DefaultProfileRegkeysDwordBase.Concat(
new[]
{
new Tuple<string, int>("DefaultBackground", 16777215), // HEX: FFFFFF
[
new Tuple<string, int>("DefaultBackground", 16777215), // HEX: FFFFFF
new Tuple<string, int>("ColorTable00", 16777215), // HEX: FFFFFF
new Tuple<string, int>("ColorTable07", 2434341) // HEX: 252525
}).ToList();
]).ToList();
}

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

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

Log.Info($"Registry path for PowerShell profile: \"{registryPath}\"");

var registryKey = Registry.CurrentUser.OpenSubKey(registryPath, true);

registryKey ??= Registry.CurrentUser.CreateSubKey(registryPath);
Expand Down
108 changes: 46 additions & 62 deletions Source/NETworkManager.Models/PuTTY/PuTTY.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,95 +10,79 @@ namespace NETworkManager.Models.PuTTY;
/// <summary>
/// Class control PuTTY.
/// </summary>
public class PuTTY
public static class PuTTY
{
/// <summary>
/// Default PuTTY installation paths.
/// PuTTY file name.
/// </summary>
public static readonly List<string> GetDefaultInstallationPaths = new()
{
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), _puttyFolder, _puttyFile),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), _puttyFolder, _puttyFile)
};
public const string FileName = "putty.exe";

/// <summary>
/// Default SZ registry keys for PuTTY profile NETworkManager.
/// </summary>
private static readonly List<Tuple<string, string>> DefaultProfileRegkeysSZBase = new()
{
new Tuple<string, string>("Colour1", "255,255,255"),
new Tuple<string, string>("Colour3", "85,85,85"),
new Tuple<string, string>("Colour4", "0,0,0"),
new Tuple<string, string>("Colour5", "0,255,0"),
new Tuple<string, string>("Colour6", "0,0,0"),
new Tuple<string, string>("Colour7", "85,85,85"),
new Tuple<string, string>("Colour8", "187,0,0"),
new Tuple<string, string>("Colour9", "255,85,85"),
new Tuple<string, string>("Colour10", "0,187,0"),
new Tuple<string, string>("Colour11", "85,255,85"),
new Tuple<string, string>("Colour12", "187,187,0"),
new Tuple<string, string>("Colour13", "255,255,85"),
new Tuple<string, string>("Colour14", "0,0,187"),
new Tuple<string, string>("Colour15", "85,85,255"),
new Tuple<string, string>("Colour16", "187,0,187"),
new Tuple<string, string>("Colour17", "255,85,255"),
new Tuple<string, string>("Colour18", "0,187,187"),
new Tuple<string, string>("Colour19", "85,255,255"),
new Tuple<string, string>("Colour20", "187,187,187"),
new Tuple<string, string>("Colour21", "255,255,255"),
new Tuple<string, string>("LineCodePage", "UTF-8"),
new Tuple<string, string>("Font", "Consolas")
};
private static readonly List<Tuple<string, string>> DefaultProfileRegkeysSzBase =
[
new("Colour1", "255,255,255"),
new("Colour3", "85,85,85"),
new("Colour4", "0,0,0"),
new("Colour5", "0,255,0"),
new("Colour6", "0,0,0"),
new("Colour7", "85,85,85"),
new("Colour8", "187,0,0"),
new("Colour9", "255,85,85"),
new("Colour10", "0,187,0"),
new("Colour11", "85,255,85"),
new("Colour12", "187,187,0"),
new("Colour13", "255,255,85"),
new("Colour14", "0,0,187"),
new("Colour15", "85,85,255"),
new("Colour16", "187,0,187"),
new("Colour17", "255,85,255"),
new("Colour18", "0,187,187"),
new("Colour19", "85,255,255"),
new("Colour20", "187,187,187"),
new("Colour21", "255,255,255"),
new("LineCodePage", "UTF-8"),
new("Font", "Consolas")
];

/// <summary>
/// Default DWORD registry keys for PuTTY profile NETworkManager.
/// </summary>
private static readonly List<Tuple<string, int>> DefaultProfileRegkeysDwordBase = new()
{
new Tuple<string, int>("CurType", 2),
new Tuple<string, int>("FontHeight", 12),
new Tuple<string, int>("BlinkCur", 1),
new Tuple<string, int>("ScrollBar", 0)
};

/// <summary>
/// Name of the PuTTY folder.
/// </summary>
private static string _puttyFolder => "PuTTY";

/// <summary>
/// Name of the PuTTY executable.
/// </summary>
private static string _puttyFile => "putty.exe";
private static readonly List<Tuple<string, int>> DefaultProfileRegkeysDwordBase =
[
new("CurType", 2),
new("FontHeight", 12),
new("BlinkCur", 1),
new("ScrollBar", 0)
];

/// <summary>
/// SZ registry keys for PuTTY profile NETworkManager if app theme is dark.
/// </summary>
/// <returns>List with SZ registry keys.</returns>
private static List<Tuple<string, string>> GetProfileRegkeysSZDark()
private static List<Tuple<string, string>> GetProfileRegkeysSzDark()
{
return DefaultProfileRegkeysSZBase.Concat(
new[]
{
// new Tuple<string, string>("Colour0", "255,255,255"),
return DefaultProfileRegkeysSzBase.Concat(
[
// new Tuple<string, string>("Colour0", "255,255,255"),
new Tuple<string, string>("Colour0", "187,187,187"), // Foreground
new Tuple<string, string>("Colour2", "37,37,37") // Background
}).ToList();
]).ToList();
}

/// <summary>
/// SZ registry keys for PuTTY profile NETworkManager if app theme is white.
/// </summary>
/// <returns>List with DWORD registry keys.</returns>
private static List<Tuple<string, string>> GetProfileRegkeysSZWhite()
private static List<Tuple<string, string>> GetProfileRegkeysSzWhite()
{
return DefaultProfileRegkeysSZBase.Concat(
new[]
{
// new Tuple<string, string>("Colour0", "68,68,68"),
return DefaultProfileRegkeysSzBase.Concat(
[
// new Tuple<string, string>("Colour0", "68,68,68"),
new Tuple<string, string>("Colour0", "0,0,0"), // Foreground
new Tuple<string, string>("Colour2", "255,255,255") // Background
}).ToList();
]).ToList();
}

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

if (registryKey != null)
{
foreach (var item in theme == "Dark" ? GetProfileRegkeysSZDark() : GetProfileRegkeysSZWhite())
foreach (var item in theme == "Dark" ? GetProfileRegkeysSzDark() : GetProfileRegkeysSzWhite())
registryKey.SetValue(item.Item1, item.Item2);

foreach (var item in DefaultProfileRegkeysDwordBase)
Expand Down
Loading
Loading