Skip to content

Commit 6fc0d79

Browse files
committed
Fix remote desktop settings
1 parent 7171676 commit 6fc0d79

13 files changed

Lines changed: 203 additions & 43 deletions

File tree

Source/NETworkManager.Localization/Resources/Strings.Designer.cs

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/NETworkManager.Localization/Resources/Strings.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3101,4 +3101,13 @@ Enable profile file encryption in Settings>Profile to store credentials secur
31013101
<data name="RemoteDesktopDisconnectReason_TotalLoginTimeLimitReached" xml:space="preserve">
31023102
<value>The remote session ended because the total login time limit was reached. This limit is set by the server administrator or by network policies.</value>
31033103
</data>
3104+
<data name="EnterValidHostname" xml:space="preserve">
3105+
<value>Enter a valid hostname!</value>
3106+
</data>
3107+
<data name="EnterValidHostnameAndPort" xml:space="preserve">
3108+
<value>Enter a valid hostname and port!</value>
3109+
</data>
3110+
<data name="RemoteDesktopDisconnectReason_UnableToReconnectToRemoteSession" xml:space="preserve">
3111+
<value>Unable to reconnect to the remote session.</value>
3112+
</data>
31043113
</root>
Lines changed: 121 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,148 @@
11
using NETworkManager.Models.RemoteDesktop;
22
using NETworkManager.Settings;
3+
using System.Windows.Forms;
34

45
namespace NETworkManager.Profiles.Application
56
{
67
public static class RemoteDesktop
78
{
8-
public static RemoteDesktopSessionInfo CreateSessionInfo(ProfileInfo profileInfo = null)
9+
public static RemoteDesktopSessionInfo CreateSessionInfo()
910
{
10-
if (profileInfo == null)
11-
return new RemoteDesktopSessionInfo();
12-
13-
var info = new RemoteDesktopSessionInfo
11+
return new RemoteDesktopSessionInfo
1412
{
1513
// Hostname
16-
Hostname = profileInfo.Host,
17-
18-
// Display
19-
AdjustScreenAutomatically = profileInfo.RemoteDesktop_OverrideDisplay ? profileInfo.RemoteDesktop_AdjustScreenAutomatically : SettingsManager.Current.RemoteDesktop_AdjustScreenAutomatically,
20-
UseCurrentViewSize = profileInfo.RemoteDesktop_OverrideDisplay ? profileInfo.RemoteDesktop_UseCurrentViewSize : SettingsManager.Current.RemoteDesktop_UseCurrentViewSize,
21-
DesktopWidth = profileInfo.RemoteDesktop_OverrideDisplay ? (profileInfo.RemoteDesktop_UseCustomScreenSize ? profileInfo.RemoteDesktop_CustomScreenWidth : profileInfo.RemoteDesktop_ScreenWidth) : (SettingsManager.Current.RemoteDesktop_UseCustomScreenSize ? SettingsManager.Current.RemoteDesktop_CustomScreenWidth : SettingsManager.Current.RemoteDesktop_ScreenWidth),
22-
DesktopHeight = profileInfo.RemoteDesktop_OverrideDisplay ? (profileInfo.RemoteDesktop_UseCustomScreenSize ? profileInfo.RemoteDesktop_CustomScreenHeight : profileInfo.RemoteDesktop_ScreenHeight) : (SettingsManager.Current.RemoteDesktop_UseCustomScreenSize ? SettingsManager.Current.RemoteDesktop_CustomScreenHeight : SettingsManager.Current.RemoteDesktop_ScreenHeight),
23-
ColorDepth = profileInfo.RemoteDesktop_OverrideColorDepth ? profileInfo.RemoteDesktop_ColorDepth : SettingsManager.Current.RemoteDesktop_ColorDepth,
14+
Hostname = string.Empty,
2415

2516
// Network
26-
Port = profileInfo.RemoteDesktop_OverridePort ? profileInfo.RemoteDesktop_Port : SettingsManager.Current.RemoteDesktop_Port,
17+
Port = SettingsManager.Current.RemoteDesktop_Port,
18+
19+
// Display
20+
AdjustScreenAutomatically = SettingsManager.Current.RemoteDesktop_AdjustScreenAutomatically,
21+
UseCurrentViewSize = SettingsManager.Current.RemoteDesktop_UseCurrentViewSize,
22+
DesktopWidth = SettingsManager.Current.RemoteDesktop_UseCustomScreenSize ? SettingsManager.Current.RemoteDesktop_CustomScreenWidth : SettingsManager.Current.RemoteDesktop_ScreenWidth,
23+
DesktopHeight = SettingsManager.Current.RemoteDesktop_UseCustomScreenSize ? SettingsManager.Current.RemoteDesktop_CustomScreenHeight : SettingsManager.Current.RemoteDesktop_ScreenHeight,
24+
ColorDepth = SettingsManager.Current.RemoteDesktop_ColorDepth,
2725

2826
// Authentication
29-
EnableCredSspSupport = profileInfo.RemoteDesktop_OverrideCredSspSupport ? profileInfo.RemoteDesktop_EnableCredSspSupport : SettingsManager.Current.RemoteDesktop_EnableCredSspSupport,
30-
AuthenticationLevel = profileInfo.RemoteDesktop_OverrideAuthenticationLevel ? profileInfo.RemoteDesktop_AuthenticationLevel : SettingsManager.Current.RemoteDesktop_AuthenticationLevel,
27+
EnableCredSspSupport = SettingsManager.Current.RemoteDesktop_EnableCredSspSupport,
28+
AuthenticationLevel = SettingsManager.Current.RemoteDesktop_AuthenticationLevel,
3129

3230
// Remote audio
33-
AudioRedirectionMode = profileInfo.RemoteDesktop_OverrideAudioRedirectionMode ? profileInfo.RemoteDesktop_AudioRedirectionMode : SettingsManager.Current.RemoteDesktop_AudioRedirectionMode,
34-
AudioCaptureRedirectionMode = profileInfo.RemoteDesktop_OverrideAudioCaptureRedirectionMode ? profileInfo.RemoteDesktop_AudioCaptureRedirectionMode : SettingsManager.Current.RemoteDesktop_AudioCaptureRedirectionMode,
31+
AudioRedirectionMode = SettingsManager.Current.RemoteDesktop_AudioRedirectionMode,
32+
AudioCaptureRedirectionMode = SettingsManager.Current.RemoteDesktop_AudioCaptureRedirectionMode,
3533

3634
// Keyboard
37-
KeyboardHookMode = profileInfo.RemoteDesktop_OverrideApplyWindowsKeyCombinations ? profileInfo.RemoteDesktop_KeyboardHookMode : SettingsManager.Current.RemoteDesktop_KeyboardHookMode,
35+
KeyboardHookMode = SettingsManager.Current.RemoteDesktop_KeyboardHookMode,
3836

3937
// Local devices and resources
40-
RedirectClipboard = profileInfo.RemoteDesktop_OverrideRedirectClipboard ? profileInfo.RemoteDesktop_RedirectClipboard : SettingsManager.Current.RemoteDesktop_RedirectClipboard,
41-
RedirectDevices = profileInfo.RemoteDesktop_OverrideRedirectDevices ? profileInfo.RemoteDesktop_RedirectDevices : SettingsManager.Current.RemoteDesktop_RedirectDevices,
42-
RedirectDrives = profileInfo.RemoteDesktop_OverrideRedirectDrives ? profileInfo.RemoteDesktop_RedirectDrives : SettingsManager.Current.RemoteDesktop_RedirectDrives,
43-
RedirectPorts = profileInfo.RemoteDesktop_OverrideRedirectPorts ? profileInfo.RemoteDesktop_RedirectPorts : SettingsManager.Current.RemoteDesktop_RedirectPorts,
44-
RedirectSmartCards = profileInfo.RemoteDesktop_OverrideRedirectSmartcards ? profileInfo.RemoteDesktop_RedirectSmartCards : SettingsManager.Current.RemoteDesktop_RedirectSmartCards,
45-
RedirectPrinters = profileInfo.RemoteDesktop_OverrideRedirectPrinters ? profileInfo.RemoteDesktop_RedirectPrinters : SettingsManager.Current.RemoteDesktop_RedirectPrinters,
38+
RedirectClipboard = SettingsManager.Current.RemoteDesktop_RedirectClipboard,
39+
RedirectDevices = SettingsManager.Current.RemoteDesktop_RedirectDevices,
40+
RedirectDrives = SettingsManager.Current.RemoteDesktop_RedirectDrives,
41+
RedirectPorts = SettingsManager.Current.RemoteDesktop_RedirectPorts,
42+
RedirectSmartCards = SettingsManager.Current.RemoteDesktop_RedirectSmartCards,
43+
RedirectPrinters = SettingsManager.Current.RemoteDesktop_RedirectPrinters,
4644

4745
// Experience
48-
PersistentBitmapCaching = profileInfo.RemoteDesktop_OverridePersistentBitmapCaching ? profileInfo.RemoteDesktop_PersistentBitmapCaching : SettingsManager.Current.RemoteDesktop_PersistentBitmapCaching,
49-
ReconnectIfTheConnectionIsDropped = profileInfo.RemoteDesktop_OverrideReconnectIfTheConnectionIsDropped ? profileInfo.RemoteDesktop_ReconnectIfTheConnectionIsDropped : SettingsManager.Current.RemoteDesktop_ReconnectIfTheConnectionIsDropped,
46+
PersistentBitmapCaching = SettingsManager.Current.RemoteDesktop_PersistentBitmapCaching,
47+
ReconnectIfTheConnectionIsDropped = SettingsManager.Current.RemoteDesktop_ReconnectIfTheConnectionIsDropped,
5048

5149
// Performance
52-
NetworkConnectionType = profileInfo.RemoteDesktop_OverrideNetworkConnectionType ? profileInfo.RemoteDesktop_NetworkConnectionType : SettingsManager.Current.RemoteDesktop_NetworkConnectionType,
53-
DesktopBackground = profileInfo.RemoteDesktop_OverrideDesktopBackground ? profileInfo.RemoteDesktop_DesktopBackground : SettingsManager.Current.RemoteDesktop_DesktopBackground,
54-
FontSmoothing = profileInfo.RemoteDesktop_OverrideFontSmoothing ? profileInfo.RemoteDesktop_FontSmoothing : SettingsManager.Current.RemoteDesktop_FontSmoothing,
55-
DesktopComposition = profileInfo.RemoteDesktop_OverrideDesktopComposition ? profileInfo.RemoteDesktop_DesktopComposition : SettingsManager.Current.RemoteDesktop_DesktopComposition,
56-
ShowWindowContentsWhileDragging = profileInfo.RemoteDesktop_OverrideShowWindowContentsWhileDragging ? profileInfo.RemoteDesktop_ShowWindowContentsWhileDragging : SettingsManager.Current.RemoteDesktop_ShowWindowContentsWhileDragging,
57-
MenuAndWindowAnimation = profileInfo.RemoteDesktop_OverrideMenuAndWindowAnimation ? profileInfo.RemoteDesktop_MenuAndWindowAnimation : SettingsManager.Current.RemoteDesktop_MenuAndWindowAnimation,
58-
VisualStyles = profileInfo.RemoteDesktop_OverrideVisualStyles ? profileInfo.RemoteDesktop_VisualStyles : SettingsManager.Current.RemoteDesktop_VisualStyles
50+
NetworkConnectionType = SettingsManager.Current.RemoteDesktop_NetworkConnectionType,
51+
DesktopBackground = SettingsManager.Current.RemoteDesktop_DesktopBackground,
52+
FontSmoothing = SettingsManager.Current.RemoteDesktop_FontSmoothing,
53+
DesktopComposition = SettingsManager.Current.RemoteDesktop_DesktopComposition,
54+
ShowWindowContentsWhileDragging = SettingsManager.Current.RemoteDesktop_ShowWindowContentsWhileDragging,
55+
MenuAndWindowAnimation = SettingsManager.Current.RemoteDesktop_MenuAndWindowAnimation,
56+
VisualStyles = SettingsManager.Current.RemoteDesktop_VisualStyles
5957
};
58+
}
59+
60+
public static RemoteDesktopSessionInfo CreateSessionInfo(ProfileInfo profileInfo)
61+
{
62+
var info = new RemoteDesktopSessionInfo();
63+
// Override hostname
64+
info.Hostname = profileInfo.Host;
65+
66+
// Network
67+
if (profileInfo.RemoteDesktop_OverridePort)
68+
info.Port = profileInfo.RemoteDesktop_Port;
69+
70+
// Display
71+
if (profileInfo.RemoteDesktop_OverrideDisplay)
72+
{
73+
info.AdjustScreenAutomatically = profileInfo.RemoteDesktop_AdjustScreenAutomatically;
74+
info.UseCurrentViewSize = profileInfo.RemoteDesktop_UseCurrentViewSize;
75+
info.DesktopWidth = profileInfo.RemoteDesktop_UseCustomScreenSize ? profileInfo.RemoteDesktop_CustomScreenWidth : profileInfo.RemoteDesktop_ScreenWidth;
76+
info.DesktopHeight = profileInfo.RemoteDesktop_UseCustomScreenSize ? profileInfo.RemoteDesktop_CustomScreenHeight : profileInfo.RemoteDesktop_ScreenHeight;
77+
info.ColorDepth = profileInfo.RemoteDesktop_ColorDepth;
78+
}
79+
80+
// Authentication
81+
if (profileInfo.RemoteDesktop_OverrideCredSspSupport)
82+
info.EnableCredSspSupport = profileInfo.RemoteDesktop_EnableCredSspSupport;
83+
84+
if (profileInfo.RemoteDesktop_OverrideAuthenticationLevel)
85+
info.AuthenticationLevel = profileInfo.RemoteDesktop_AuthenticationLevel;
86+
87+
// Remote audio
88+
if (profileInfo.RemoteDesktop_OverrideAudioRedirectionMode)
89+
info.AudioRedirectionMode = profileInfo.RemoteDesktop_AudioRedirectionMode;
90+
91+
if (profileInfo.RemoteDesktop_OverrideAudioCaptureRedirectionMode)
92+
info.AudioCaptureRedirectionMode = profileInfo.RemoteDesktop_AudioCaptureRedirectionMode;
93+
94+
// Keyboard
95+
if (profileInfo.RemoteDesktop_OverrideApplyWindowsKeyCombinations)
96+
info.KeyboardHookMode = profileInfo.RemoteDesktop_KeyboardHookMode;
97+
98+
// Local devices and resources
99+
if (profileInfo.RemoteDesktop_OverrideRedirectClipboard)
100+
info.RedirectClipboard = profileInfo.RemoteDesktop_RedirectClipboard;
101+
102+
if (profileInfo.RemoteDesktop_OverrideRedirectDevices)
103+
info.RedirectDevices = profileInfo.RemoteDesktop_RedirectDevices;
104+
105+
if (profileInfo.RemoteDesktop_OverrideRedirectDrives)
106+
info.RedirectDrives = profileInfo.RemoteDesktop_RedirectDrives;
107+
108+
if (profileInfo.RemoteDesktop_OverrideRedirectPorts)
109+
info.RedirectPorts = profileInfo.RemoteDesktop_RedirectPorts;
110+
111+
if (profileInfo.RemoteDesktop_OverrideRedirectSmartcards)
112+
info.RedirectSmartCards = profileInfo.RemoteDesktop_RedirectSmartCards;
113+
114+
if (profileInfo.RemoteDesktop_OverrideRedirectPrinters)
115+
info.RedirectPrinters = profileInfo.RemoteDesktop_RedirectPrinters;
116+
117+
// Experience
118+
if (profileInfo.RemoteDesktop_OverridePersistentBitmapCaching)
119+
info.PersistentBitmapCaching = profileInfo.RemoteDesktop_PersistentBitmapCaching;
120+
121+
if (profileInfo.RemoteDesktop_OverrideReconnectIfTheConnectionIsDropped)
122+
info.ReconnectIfTheConnectionIsDropped = profileInfo.RemoteDesktop_ReconnectIfTheConnectionIsDropped;
123+
124+
// Performance
125+
if (profileInfo.RemoteDesktop_OverrideNetworkConnectionType)
126+
info.NetworkConnectionType = profileInfo.RemoteDesktop_NetworkConnectionType;
127+
128+
if (profileInfo.RemoteDesktop_OverrideDesktopBackground)
129+
info.DesktopBackground = profileInfo.RemoteDesktop_DesktopBackground;
130+
131+
if (profileInfo.RemoteDesktop_OverrideFontSmoothing)
132+
info.FontSmoothing = profileInfo.RemoteDesktop_FontSmoothing;
133+
134+
if (profileInfo.RemoteDesktop_OverrideDesktopComposition)
135+
info.DesktopComposition = profileInfo.RemoteDesktop_DesktopComposition;
136+
137+
if (profileInfo.RemoteDesktop_OverrideShowWindowContentsWhileDragging)
138+
info.ShowWindowContentsWhileDragging = profileInfo.RemoteDesktop_ShowWindowContentsWhileDragging;
139+
140+
if (profileInfo.RemoteDesktop_OverrideMenuAndWindowAnimation)
141+
info.MenuAndWindowAnimation = profileInfo.RemoteDesktop_MenuAndWindowAnimation;
142+
143+
if (profileInfo.RemoteDesktop_OverrideVisualStyles)
144+
info.VisualStyles = profileInfo.RemoteDesktop_VisualStyles;
145+
60146

61147
// Set credentials
62148
if (profileInfo.RemoteDesktop_UseCredentials)
@@ -68,6 +154,6 @@ public static RemoteDesktopSessionInfo CreateSessionInfo(ProfileInfo profileInfo
68154
}
69155

70156
return info;
71-
}
157+
}
72158
}
73159
}

Source/NETworkManager.Utilities/RegexHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public static class RegexHelper
7676
// Match a domain local.example.com
7777
public const string DomainRegex = @"^(?!:\/\/)([a-zA-Z0-9-_]+\.)*[a-zA-Z0-9][a-zA-Z0-9-_]+\.[a-zA-Z]{2,11}?$";
7878

79+
// Match a hostname and port like local.example.com:443
80+
public const string HostnameAndPortRegex = @"^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]):((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}))$";
81+
7982
// Match any filepath (like "c:\temp\") --> https://www.codeproject.com/Tips/216238/Regular-Expression-to-Validate-File-Path-and-Exten
8083
public const string FilePath = @"^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)+$";
8184

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Globalization;
2+
using System.Text.RegularExpressions;
3+
using System.Windows.Controls;
4+
using NETworkManager.Localization.Resources;
5+
using NETworkManager.Utilities;
6+
7+
namespace NETworkManager.Validators
8+
{
9+
public class RemoteDesktopHostnameAndPortValidator : ValidationRule
10+
{
11+
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
12+
{
13+
string hostnameAndPort = (string)value;
14+
15+
if(hostnameAndPort.Contains(":"))
16+
{
17+
return Regex.IsMatch((string)value, RegexHelper.HostnameAndPortRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.EnterValidHostnameAndPort);
18+
}
19+
else
20+
{
21+
return Regex.IsMatch((string)value, RegexHelper.DomainRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.EnterValidHostname);
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)