-
Notifications
You must be signed in to change notification settings - Fork 807
Expand file tree
/
Copy pathConfigurationManager.cs
More file actions
68 lines (61 loc) · 2.65 KB
/
ConfigurationManager.cs
File metadata and controls
68 lines (61 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using NETworkManager.Models;
using System.IO;
using System.Security.Principal;
namespace NETworkManager.Settings;
/// <summary>
/// Class includes static and dynamic configuration used in the application
/// across multiple windows, views, dialogs, etc.
/// </summary>
public static class ConfigurationManager
{
/// <summary>
/// Name of the file that indicates that the application is portable.
/// </summary>
private const string IsPortableFileName = "IsPortable";
/// <summary>
/// Extension of the file that indicates that the application is portable.
/// </summary>
private const string IsPortableExtension = "settings";
/// <summary>
/// Create a new instance of the <see cref="ConfigurationManager" /> class and load static configuration.
/// </summary>
static ConfigurationManager()
{
Current = new ConfigurationInfo(
isAdmin: new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator),
executionPath: AssemblyManager.Current.Location,
applicationFullName: Path.Combine(AssemblyManager.Current.Location, AssemblyManager.Current.Name + ".exe"),
applicationName: AssemblyManager.Current.Name,
isPortable: File.Exists(Path.Combine(AssemblyManager.Current.Location, $"{IsPortableFileName}.{IsPortableExtension}"))
);
}
/// <summary>
/// Current <see cref="ConfigurationInfo" /> that is used in the application.
/// </summary>
public static ConfigurationInfo Current { get; }
/// <summary>
/// Method can be called before opening a dialog to fix airspace issues.
/// Call the <see cref="OnDialogClose" /> method after the dialog has been closed.
/// </summary>
public static void OnDialogOpen()
{
switch (Current.CurrentApplication)
{
case ApplicationName.RemoteDesktop when Current.RemoteDesktopTabCount > 0:
case ApplicationName.PowerShell when Current.PowerShellTabCount > 0:
case ApplicationName.PuTTY when Current.PuTTYTabCount > 0:
case ApplicationName.AWSSessionManager when Current.AWSSessionManagerTabCount > 0:
case ApplicationName.TigerVNC when Current.TigerVNCTabCount > 0:
case ApplicationName.WebConsole when Current.WebConsoleTabCount > 0:
Current.FixAirspace = true;
break;
}
}
/// <summary>
/// Method must be called after closing a dialog if <see cref="OnDialogOpen" /> was called before.
/// </summary>
public static void OnDialogClose()
{
Current.FixAirspace = false;
}
}