Skip to content

Commit 51e72bf

Browse files
committed
1 parent 5ab5ef9 commit 51e72bf

20 files changed

Lines changed: 253 additions & 85 deletions

Source/NETworkManager/App.xaml.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,22 @@ private void Application_Startup(object sender, StartupEventArgs e)
5858
SettingsManager.Load();
5959

6060
// Update settings (Default --> %AppData%\NETworkManager\Settings)
61-
if (AssemblyManager.Current.Version > new Version(SettingsManager.Current.SettingsVersion))
62-
SettingsManager.Update(AssemblyManager.Current.Version, new Version(SettingsManager.Current.SettingsVersion));
61+
Version assemblyVersion = AssemblyManager.Current.Version;
62+
Version settingsVersion = new Version(SettingsManager.Current.SettingsVersion);
63+
64+
if (assemblyVersion > settingsVersion)
65+
{
66+
SettingsManager.Update(assemblyVersion, settingsVersion);
67+
68+
try
69+
{
70+
ProfileManager.Upgrade(settingsVersion);
71+
}
72+
catch(Exception ex)
73+
{
74+
MessageBox.Show("Failed to update profiles...\n\n" + ex.Message, "Profile Manager - Update Error", MessageBoxButton.OK, MessageBoxImage.Error);
75+
}
76+
}
6377
}
6478
catch (InvalidOperationException)
6579
{

Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private void Connect()
172172
RdpClient.AdvancedSettings9.EnableCredSspSupport = _rdpSessionInfo.EnableCredSspSupport;
173173

174174
// Keyboard
175-
RdpClient.SecuredSettings3.KeyboardHookMode = _rdpSessionInfo.KeyboardHookMode;
175+
RdpClient.SecuredSettings3.KeyboardHookMode = (int)_rdpSessionInfo.KeyboardHookMode;
176176

177177
// Devices and resources
178178
RdpClient.AdvancedSettings9.RedirectClipboard = _rdpSessionInfo.RedirectClipboard;
@@ -189,7 +189,7 @@ private void Connect()
189189
// Experience
190190
if (_rdpSessionInfo.ConnectionSpeed != 0)
191191
{
192-
RdpClient.AdvancedSettings9.NetworkConnectionType = _rdpSessionInfo.ConnectionSpeed;
192+
RdpClient.AdvancedSettings9.NetworkConnectionType = (uint)_rdpSessionInfo.ConnectionSpeed;
193193

194194
if (!_rdpSessionInfo.DesktopBackground)
195195
RdpClient.AdvancedSettings9.PerformanceFlags |= RemoteDesktopPerformanceConstants.TS_PERF_DISABLE_WALLPAPER;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using NETworkManager.Models.Settings;
5+
6+
namespace NETworkManager.Converters
7+
{
8+
public sealed class RemoteDesktopConnectionSpeedToStringConverter : IValueConverter
9+
{
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
return LocalizationManager.TranslateRemoteDesktopConnectionSpeed(value);
13+
}
14+
15+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
16+
{
17+
throw new NotImplementedException();
18+
}
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using NETworkManager.Models.Settings;
5+
6+
namespace NETworkManager.Converters
7+
{
8+
public sealed class RemoteDesktopKeyboardHookModeToStringConverter : IValueConverter
9+
{
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
return LocalizationManager.TranslateRemoteDesktopKeyboardHookMode(value);
13+
}
14+
15+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
16+
{
17+
throw new NotImplementedException();
18+
}
19+
}
20+
}

Source/NETworkManager/GlobalStaticConfiguration.cs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using NETworkManager.Models.PuTTY;
1111
using NETworkManager.Utilities;
1212
using NETworkManager.Enum;
13+
using NETworkManager.Models.RemoteDesktop;
1314

1415
// ReSharper disable InconsistentNaming
1516

@@ -114,26 +115,11 @@ public class GlobalStaticConfiguration
114115
};
115116
public static int RemoteDesktop_ColorDepth = 32;
116117
public static int RemoteDesktop_Port => 3389;
117-
public static List<Tuple<int, string>> RemoteDesktop_KeyboardHookModes => new List<Tuple<int, string>>
118-
{
119-
Tuple.Create(0, Resources.Localization.Strings.OnThisComputer),
120-
Tuple.Create(1, Resources.Localization.Strings.OnTheRemoteComputer)/*,
121-
Tuple.Create(2, Resources.Localization.Strings.OnlyWhenUsingTheFullScreen),*/
122-
};
123-
public static int RemoteDesktop_KeyboardHookMode => 1;
118+
public static RemoteDesktop.KeyboardHookMode RemoteDesktop_KeyboardHookMode => RemoteDesktop.KeyboardHookMode.OnTheRemoteComputer;
124119
public static uint RemoteDesktop_AuthenticationLevel => 2;
125-
public static List<Tuple<uint, string>> RemoteDesktop_ConnectionSpeeds => new List<Tuple<uint, string>>
126-
{
127-
Tuple.Create((uint)0,Resources.Localization.Strings.RemoteDesktopConnectionType_DetectAutomatically),
128-
Tuple.Create((uint)1,Resources.Localization.Strings.RemoteDesktopConnectionType_Modem),
129-
Tuple.Create((uint)2,Resources.Localization.Strings.RemoteDesktopConnectionType_BroadbandLow),
130-
Tuple.Create((uint)3,Resources.Localization.Strings.RemoteDesktopConnectionType_Satellite),
131-
Tuple.Create((uint)4,Resources.Localization.Strings.RemoteDesktopConnectionType_BroadbandHigh),
132-
Tuple.Create((uint)5,Resources.Localization.Strings.RemoteDesktopConnectionType_WAN),
133-
Tuple.Create((uint)6,Resources.Localization.Strings.RemoteDesktopConnectionType_LAN)
134-
};
135-
public static uint RemoteDesktop_ConnectionSpeed => 0;
136-
120+
121+
public static RemoteDesktop.ConnectionSpeed RemoteDesktop_ConnectionSpeed => RemoteDesktop.ConnectionSpeed.DetectAutomatically;
122+
137123
// Application: PowerShell
138124
public static string PowerShell_ApplicationFileLocationPowerShell => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"System32\WindowsPowerShell\v1.0\powershell.exe");
139125
public static PowerShell.ExecutionPolicy PowerShell_ExecutionPolicy => PowerShell.ExecutionPolicy.RemoteSigned;

Source/NETworkManager/Models/RemoteDesktop/RemoteDesktop.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,25 @@ public static RemoteDesktopSessionInfo CreateSessionInfo(ProfileInfo profileInfo
6464

6565
return info;
6666
}
67+
68+
public enum KeyboardHookMode
69+
{
70+
OnThisComputer,
71+
OnTheRemoteComputer,
72+
//OnlyWhenUsingTheFullScreen
73+
}
74+
75+
// https://docs.microsoft.com/en-us/windows/desktop/termserv/imsrdpclientadvancedsettings7-networkconnectiontype
76+
// Convert to uint
77+
public enum ConnectionSpeed
78+
{
79+
DetectAutomatically,
80+
Modem,
81+
BroadbandLow,
82+
Satellite,
83+
BroadbandHigh,
84+
WAN,
85+
LAN
86+
}
6787
}
6888
}

Source/NETworkManager/Models/RemoteDesktop/RemoteDesktopSessionInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class RemoteDesktopSessionInfo
1616
public int ColorDepth { get; set; }
1717
public bool EnableCredSspSupport { get; set; }
1818
public uint AuthenticationLevel { get; set; }
19-
public int KeyboardHookMode { get; set; }
19+
public RemoteDesktop.KeyboardHookMode KeyboardHookMode { get; set; }
2020
public bool RedirectClipboard { get; set; }
2121
public bool RedirectDevices { get; set; }
2222
public bool RedirectDrives { get; set; }
@@ -25,7 +25,7 @@ public class RemoteDesktopSessionInfo
2525
public bool RedirectPrinters { get; set; }
2626
public bool PersistentBitmapCaching { get; set; }
2727
public bool ReconnectIfTheConnectionIsDropped { get; set; }
28-
public uint ConnectionSpeed { get; set; }
28+
public RemoteDesktop.ConnectionSpeed ConnectionSpeed { get; set; }
2929
public bool DesktopBackground { get; set; }
3030
public bool FontSmoothing { get; set; }
3131
public bool DesktopComposition { get; set; }

Source/NETworkManager/Models/Settings/LocalizationManager.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Net.NetworkInformation;
66
using NETworkManager.Models.Network;
77
using NETworkManager.Enum;
8+
using static NETworkManager.Models.RemoteDesktop.RemoteDesktop;
89

910
namespace NETworkManager.Models.Settings
1011
{
@@ -101,5 +102,25 @@ public static string TranslateConnectionState(object value)
101102

102103
return string.IsNullOrEmpty(status) ? connectionState.ToString() : status;
103104
}
105+
106+
public static string TranslateRemoteDesktopConnectionSpeed(object value)
107+
{
108+
if (!(value is ConnectionSpeed connectionSpeed))
109+
return "-/-";
110+
111+
var status = Resources.Localization.Strings.ResourceManager.GetString("RemoteDesktopConnectionType_" + connectionSpeed, Culture);
112+
113+
return string.IsNullOrEmpty(status) ? connectionSpeed.ToString() : status;
114+
}
115+
116+
public static string TranslateRemoteDesktopKeyboardHookMode(object value)
117+
{
118+
if (!(value is KeyboardHookMode keyboardHookMode))
119+
return "-/-";
120+
121+
var status = Resources.Localization.Strings.ResourceManager.GetString("RemoteDesktopKeyboardHookMode_" + keyboardHookMode, Culture);
122+
123+
return string.IsNullOrEmpty(status) ? keyboardHookMode.ToString() : status;
124+
}
104125
}
105126
}

Source/NETworkManager/Models/Settings/ProfileInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class ProfileInfo
6464
public bool RemoteDesktop_OverrideAuthenticationLevel { get; set; }
6565
public uint RemoteDesktop_AuthenticationLevel { get; set; } = GlobalStaticConfiguration.RemoteDesktop_AuthenticationLevel;
6666
public bool RemoteDesktop_OverrideApplyWindowsKeyCombinations { get; set; }
67-
public int RemoteDesktop_KeyboardHookMode { get; set; } = GlobalStaticConfiguration.RemoteDesktop_KeyboardHookMode;
67+
public RemoteDesktop.RemoteDesktop.KeyboardHookMode RemoteDesktop_KeyboardHookMode { get; set; } = GlobalStaticConfiguration.RemoteDesktop_KeyboardHookMode;
6868
public bool RemoteDesktop_OverrideRedirectClipboard { get; set; }
6969
public bool RemoteDesktop_RedirectClipboard { get; set; } = true;
7070
public bool RemoteDesktop_OverrideRedirectDevices { get; set; }
@@ -82,7 +82,7 @@ public class ProfileInfo
8282
public bool RemoteDesktop_OverrideReconnectIfTheConnectionIsDropped { get; set; }
8383
public bool RemoteDesktop_ReconnectIfTheConnectionIsDropped { get; set; }
8484
public bool RemoteDesktop_OverrideConnectionSpeed { get; set; }
85-
public uint RemoteDesktop_ConnectionSpeed { get; set; }
85+
public RemoteDesktop.RemoteDesktop.ConnectionSpeed RemoteDesktop_ConnectionSpeed { get; set; }
8686
public bool RemoteDesktop_OverrideDesktopBackground { get; set; }
8787
public bool RemoteDesktop_DesktopBackground { get; set; }
8888
public bool RemoteDesktop_OverrideFontSmoothing { get; set; }

Source/NETworkManager/Models/Settings/ProfileManager.cs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Collections.ObjectModel;
4+
using System.Diagnostics;
35
using System.IO;
6+
using System.Xml;
47
using System.Xml.Serialization;
58
using NETworkManager.ViewModels;
69

@@ -86,6 +89,11 @@ private static void SerializeToFile()
8689
}
8790
}
8891

92+
internal static void Update(Version assemblyVersion, Version settingsVersion)
93+
{
94+
throw new NotImplementedException();
95+
}
96+
8997
public static void Reset()
9098
{
9199
if (Profiles == null)
@@ -165,7 +173,7 @@ public static void AddProfile(ProfileViewModel instance)
165173
RemoteDesktop_OverrideAuthenticationLevel = instance.RemoteDesktop_OverrideAuthenticationLevel,
166174
RemoteDesktop_AuthenticationLevel = instance.RemoteDesktop_AuthenticationLevel,
167175
RemoteDesktop_OverrideApplyWindowsKeyCombinations = instance.RemoteDesktop_OverrideApplyWindowsKeyCombinations,
168-
RemoteDesktop_KeyboardHookMode = instance.RemoteDesktop_KeyboardHookMode.Item1,
176+
RemoteDesktop_KeyboardHookMode = instance.RemoteDesktop_KeyboardHookMode,
169177
RemoteDesktop_OverrideRedirectClipboard = instance.RemoteDesktop_OverrideRedirectClipboard,
170178
RemoteDesktop_RedirectClipboard = instance.RemoteDesktop_RedirectClipboard,
171179
RemoteDesktop_OverrideRedirectDevices = instance.RemoteDesktop_OverrideRedirectDevices,
@@ -242,5 +250,50 @@ public static void RenameGroup(string oldGroup, string group)
242250
ProfilesChanged = true;
243251
}
244252
}
253+
254+
public static void Upgrade(Version settingsVersion)
255+
{
256+
if (settingsVersion > new Version("0.0.0.0"))
257+
{
258+
Debug.WriteLine("Upgrade profile...");
259+
260+
bool needUpdate = false;
261+
262+
// Changes in 1.11.0.0
263+
if (settingsVersion < new Version("1.11.0.0"))
264+
needUpdate = true;
265+
266+
if(needUpdate)
267+
RunUpgrade(settingsVersion);
268+
}
269+
}
270+
271+
private static void RunUpgrade(Version version)
272+
{
273+
string filePath = GetProfilesFilePath();
274+
275+
if (!File.Exists(filePath))
276+
return;
277+
278+
XmlDocument xmlDocument = new XmlDocument();
279+
xmlDocument.Load(filePath);
280+
281+
if (version < new Version("1.11.0.0"))
282+
{
283+
foreach (XmlNode x in xmlDocument.SelectNodes(@"/ArrayOfProfileInfo/ProfileInfo/RemoteDesktop_KeyboardHookMode"))
284+
{
285+
if (x.InnerText == "0")
286+
x.InnerText = "OnThisComputer";
287+
else if (x.InnerText == "1")
288+
x.InnerText = "OnTheRemoteComputer";
289+
else
290+
x.InnerText = "OnlyWhenUsingTheFullScreen";
291+
}
292+
}
293+
294+
xmlDocument.Save(filePath);
295+
296+
Debug.WriteLine("Test");
297+
}
245298
}
246299
}

0 commit comments

Comments
 (0)