code corrections

This commit is contained in:
Dimitrij
2023-06-16 19:24:33 +01:00
parent 51015e6b51
commit 4ca7f34989
10 changed files with 94 additions and 149 deletions

View File

@@ -46,15 +46,13 @@ namespace mRemoteNG.App
public static NotificationAreaIcon NotificationAreaIcon { get; set; }
public static ExternalToolsService ExternalToolsService { get; } = new ExternalToolsService();
public static SecureString EncryptionKey { get; set; } =
new RootNodeInfo(RootNodeType.Connection).PasswordString.ConvertToSecureString();
public static SecureString EncryptionKey { get; set; } = new RootNodeInfo(RootNodeType.Connection).PasswordString.ConvertToSecureString();
public static ICredentialRepositoryList CredentialProviderCatalog { get; } = new CredentialRepositoryList();
public static ConnectionInitiator ConnectionInitiator { get; set; } = new ConnectionInitiator();
public static ConnectionsService ConnectionsService { get; } =
new ConnectionsService(PuttySessionsManager.Instance);
public static ConnectionsService ConnectionsService { get; } = new ConnectionsService(PuttySessionsManager.Instance);
#region Connections Loading/Saving

View File

@@ -22,11 +22,8 @@ namespace mRemoteNG.Config.Connections
{
if (string.IsNullOrEmpty(connectionFileName))
throw new ArgumentException($"Argument '{nameof(connectionFileName)}' cannot be null or empty");
if (saveFilter == null)
throw new ArgumentNullException(nameof(saveFilter));
_connectionFileName = connectionFileName;
_saveFilter = saveFilter;
_saveFilter = saveFilter ?? throw new ArgumentNullException(nameof(saveFilter));
}
public void Save(ConnectionTreeModel connectionTreeModel, string propertyNameTrigger = "")
@@ -36,11 +33,7 @@ namespace mRemoteNG.Config.Connections
var cryptographyProvider = new CryptoProviderFactoryFromSettings().Build();
var serializerFactory = new XmlConnectionSerializerFactory();
var xmlConnectionsSerializer = serializerFactory.Build(
cryptographyProvider,
connectionTreeModel,
_saveFilter,
Properties.OptionsSecurityPage.Default.EncryptCompleteConnectionsFile);
var xmlConnectionsSerializer = serializerFactory.Build(cryptographyProvider, connectionTreeModel, _saveFilter, Properties.OptionsSecurityPage.Default.EncryptCompleteConnectionsFile);
var rootNode = connectionTreeModel.RootNodes.OfType<RootNodeInfo>().First();
var xml = xmlConnectionsSerializer.Serialize(rootNode);

View File

@@ -28,9 +28,9 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
private XmlDocument _xmlDocument;
private double _confVersion;
private XmlConnectionsDecryptor _decryptor;
private string ConnectionFileName = "";
private readonly string ConnectionFileName = "";
private const double MaxSupportedConfVersion = 2.8;
private readonly RootNodeInfo _rootNodeInfo = new RootNodeInfo(RootNodeType.Connection);
private readonly RootNodeInfo _rootNodeInfo = new(RootNodeType.Connection);
public Func<Optional<SecureString>> AuthenticationRequestor { get; set; }
@@ -235,11 +235,10 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
if (!Runtime.UseCredentialManager || _confVersion <= 2.6) // 0.2 - 2.6
{
#pragma warning disable 618
connectionInfo.Username = xmlnode.GetAttributeAsString("Username");
//connectionInfo.Password = _decryptor.Decrypt(xmlnode.GetAttributeAsString("Password"));
connectionInfo.Password = _decryptor.Decrypt(xmlnode.GetAttributeAsString("Password"));
connectionInfo.Domain = xmlnode.GetAttributeAsString("Domain");
#pragma warning restore 618
}
}
@@ -327,27 +326,15 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
}
else
{
switch (xmlnode.GetAttributeAsInt("Colors"))
connectionInfo.Colors = xmlnode.GetAttributeAsInt("Colors") switch
{
case 0:
connectionInfo.Colors = RDPColors.Colors256;
break;
case 1:
connectionInfo.Colors = RDPColors.Colors16Bit;
break;
case 2:
connectionInfo.Colors = RDPColors.Colors24Bit;
break;
case 3:
connectionInfo.Colors = RDPColors.Colors32Bit;
break;
0 => RDPColors.Colors256,
1 => RDPColors.Colors16Bit,
2 => RDPColors.Colors24Bit,
3 => RDPColors.Colors32Bit,
// ReSharper disable once RedundantCaseLabel
case 4:
default:
connectionInfo.Colors = RDPColors.Colors15Bit;
break;
}
_ => RDPColors.Colors15Bit,
};
connectionInfo.RedirectSound = xmlnode.GetAttributeAsEnum<RDPSounds>("RedirectSound");
connectionInfo.RedirectAudioCapture = xmlnode.GetAttributeAsBool("RedirectAudioCapture");
}
@@ -372,8 +359,7 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
connectionInfo.Inheritance.RedirectSound = xmlnode.GetAttributeAsBool("InheritRedirectSound");
connectionInfo.Inheritance.RedirectAudioCapture = xmlnode.GetAttributeAsBool("RedirectAudioCapture");
connectionInfo.Inheritance.Resolution = xmlnode.GetAttributeAsBool("InheritResolution");
connectionInfo.Inheritance.UseConsoleSession =
xmlnode.GetAttributeAsBool("InheritUseConsoleSession");
connectionInfo.Inheritance.UseConsoleSession = xmlnode.GetAttributeAsBool("InheritUseConsoleSession");
if (!Runtime.UseCredentialManager || _confVersion <= 2.6) // 1.3 - 2.6
{
@@ -408,19 +394,16 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
if (_confVersion >= 1.7)
{
connectionInfo.VNCCompression =
xmlnode.GetAttributeAsEnum<ProtocolVNC.Compression>("VNCCompression");
connectionInfo.VNCCompression = xmlnode.GetAttributeAsEnum<ProtocolVNC.Compression>("VNCCompression");
connectionInfo.VNCEncoding = xmlnode.GetAttributeAsEnum<ProtocolVNC.Encoding>("VNCEncoding");
connectionInfo.VNCAuthMode = xmlnode.GetAttributeAsEnum<ProtocolVNC.AuthMode>("VNCAuthMode");
connectionInfo.VNCProxyType = xmlnode.GetAttributeAsEnum<ProtocolVNC.ProxyType>("VNCProxyType");
connectionInfo.VNCProxyIP = xmlnode.GetAttributeAsString("VNCProxyIP");
connectionInfo.VNCProxyPort = xmlnode.GetAttributeAsInt("VNCProxyPort");
connectionInfo.VNCProxyUsername = xmlnode.GetAttributeAsString("VNCProxyUsername");
connectionInfo.VNCProxyPassword =
_decryptor.Decrypt(xmlnode.GetAttributeAsString("VNCProxyPassword"));
connectionInfo.VNCProxyPassword = _decryptor.Decrypt(xmlnode.GetAttributeAsString("VNCProxyPassword"));
connectionInfo.VNCColors = xmlnode.GetAttributeAsEnum<ProtocolVNC.Colors>("VNCColors");
connectionInfo.VNCSmartSizeMode =
xmlnode.GetAttributeAsEnum<ProtocolVNC.SmartSizeMode>("VNCSmartSizeMode");
connectionInfo.VNCSmartSizeMode = xmlnode.GetAttributeAsEnum<ProtocolVNC.SmartSizeMode>("VNCSmartSizeMode");
connectionInfo.VNCViewOnly = xmlnode.GetAttributeAsBool("VNCViewOnly");
connectionInfo.Inheritance.VNCCompression = xmlnode.GetAttributeAsBool("InheritVNCCompression");
connectionInfo.Inheritance.VNCEncoding = xmlnode.GetAttributeAsBool("InheritVNCEncoding");
@@ -437,16 +420,13 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
if (_confVersion >= 1.8)
{
connectionInfo.RDPAuthenticationLevel =
xmlnode.GetAttributeAsEnum<AuthenticationLevel>("RDPAuthenticationLevel");
connectionInfo.Inheritance.RDPAuthenticationLevel =
xmlnode.GetAttributeAsBool("InheritRDPAuthenticationLevel");
connectionInfo.RDPAuthenticationLevel = xmlnode.GetAttributeAsEnum<AuthenticationLevel>("RDPAuthenticationLevel");
connectionInfo.Inheritance.RDPAuthenticationLevel = xmlnode.GetAttributeAsBool("InheritRDPAuthenticationLevel");
}
if (_confVersion >= 1.9)
{
connectionInfo.RenderingEngine =
xmlnode.GetAttributeAsEnum<HTTPBase.RenderingEngine>("RenderingEngine");
connectionInfo.RenderingEngine = xmlnode.GetAttributeAsEnum<HTTPBase.RenderingEngine>("RenderingEngine");
connectionInfo.MacAddress = xmlnode.GetAttributeAsString("MacAddress");
connectionInfo.Inheritance.RenderingEngine = xmlnode.GetAttributeAsBool("InheritRenderingEngine");
connectionInfo.Inheritance.MacAddress = xmlnode.GetAttributeAsBool("InheritMacAddress");

View File

@@ -18,16 +18,10 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
private SecureString _encryptionKey;
private readonly ISerializer<ConnectionInfo, XElement> _connectionNodeSerializer;
public XmlConnectionsDocumentCompiler(ICryptographyProvider cryptographyProvider,
ISerializer<ConnectionInfo, XElement> connectionNodeSerializer)
public XmlConnectionsDocumentCompiler(ICryptographyProvider cryptographyProvider, ISerializer<ConnectionInfo, XElement> connectionNodeSerializer)
{
if (cryptographyProvider == null)
throw new ArgumentNullException(nameof(cryptographyProvider));
if (connectionNodeSerializer == null)
throw new ArgumentNullException(nameof(connectionNodeSerializer));
_cryptographyProvider = cryptographyProvider;
_connectionNodeSerializer = connectionNodeSerializer;
_cryptographyProvider = cryptographyProvider ?? throw new ArgumentNullException(nameof(cryptographyProvider));
_connectionNodeSerializer = connectionNodeSerializer ?? throw new ArgumentNullException(nameof(connectionNodeSerializer));
}
public XDocument CompileDocument(ConnectionTreeModel connectionTreeModel, bool fullFileEncryption)
@@ -46,38 +40,34 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
var xmlDeclaration = new XDeclaration("1.0", "utf-8", null);
var xmlDocument = new XDocument(xmlDeclaration, rootElement);
if (fullFileEncryption)
xmlDocument =
new XmlConnectionsDocumentEncryptor(_cryptographyProvider).EncryptDocument(xmlDocument,
_encryptionKey);
xmlDocument = new XmlConnectionsDocumentEncryptor(_cryptographyProvider).EncryptDocument(xmlDocument, _encryptionKey);
return xmlDocument;
}
private void CompileRecursive(ConnectionInfo serializationTarget, XContainer parentElement)
{
var newElement = parentElement;
if (!(serializationTarget is RootNodeInfo))
if (serializationTarget is not RootNodeInfo)
{
newElement = CompileConnectionInfoNode(serializationTarget);
parentElement.Add(newElement);
}
var serializationTargetAsContainer = serializationTarget as ContainerInfo;
if (serializationTargetAsContainer == null) return;
if (serializationTarget is not ContainerInfo serializationTargetAsContainer) return;
foreach (var child in serializationTargetAsContainer.Children.ToArray())
CompileRecursive(child, newElement);
}
private RootNodeInfo GetRootNodeFromConnectionTreeModel(ConnectionTreeModel connectionTreeModel)
private static RootNodeInfo GetRootNodeFromConnectionTreeModel(ConnectionTreeModel connectionTreeModel)
{
return (RootNodeInfo)connectionTreeModel.RootNodes.First(node => node is RootNodeInfo);
}
private RootNodeInfo GetRootNodeFromConnectionInfo(ConnectionInfo connectionInfo)
private static RootNodeInfo GetRootNodeFromConnectionInfo(ConnectionInfo connectionInfo)
{
while (true)
{
var connectionInfoAsRootNode = connectionInfo as RootNodeInfo;
if (connectionInfoAsRootNode != null) return connectionInfoAsRootNode;
if (connectionInfo is RootNodeInfo connectionInfoAsRootNode) return connectionInfoAsRootNode;
connectionInfo = connectionInfo?.Parent ?? new RootNodeInfo(RootNodeType.Connection);
}
}
@@ -85,8 +75,7 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
private XElement CompileRootNode(RootNodeInfo rootNodeInfo, bool fullFileEncryption)
{
var rootNodeSerializer = new XmlRootNodeSerializer();
return rootNodeSerializer.SerializeRootNodeInfo(rootNodeInfo, _cryptographyProvider,
_connectionNodeSerializer.Version, fullFileEncryption);
return rootNodeSerializer.SerializeRootNodeInfo(rootNodeInfo, _cryptographyProvider, _connectionNodeSerializer.Version, fullFileEncryption);
}
private XElement CompileConnectionInfoNode(ConnectionInfo connectionInfo)

View File

@@ -33,7 +33,7 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
: defaultValue;
}
public static T GetAttributeAsEnum<T>(this XmlNode xmlNode, string attribute, T defaultValue = default(T))
public static T GetAttributeAsEnum<T>(this XmlNode xmlNode, string attribute, T defaultValue = default)
where T : struct
{
var value = xmlNode?.Attributes?[attribute]?.Value;

View File

@@ -26,7 +26,7 @@ namespace mRemoteNG.Security.SymmetricEncryption
{
private readonly IAeadBlockCipher _aeadBlockCipher;
private readonly Encoding _encoding;
private readonly SecureRandom _random = new SecureRandom();
private readonly SecureRandom _random = new();
//Preconfigured Encryption Parameters
protected virtual int NonceBitSize { get; set; } = 128;
@@ -90,8 +90,7 @@ namespace mRemoteNG.Security.SymmetricEncryption
private void SetNonceForCcm()
{
var ccm = _aeadBlockCipher as CcmBlockCipher;
if (ccm != null)
if (_aeadBlockCipher is CcmBlockCipher)
NonceBitSize = 88;
}
@@ -113,7 +112,7 @@ namespace mRemoteNG.Security.SymmetricEncryption
private byte[] SimpleEncryptWithPassword(byte[] secretMessage, string password, byte[] nonSecretPayload = null)
{
nonSecretPayload = nonSecretPayload ?? new byte[] { };
nonSecretPayload ??= ""u8.ToArray();
//User Error Checks
if (string.IsNullOrWhiteSpace(password) || password.Length < MinPasswordLength)
@@ -148,7 +147,7 @@ namespace mRemoteNG.Security.SymmetricEncryption
throw new ArgumentException(@"Secret Message Required!", nameof(secretMessage));
//Non-secret Payload Optional
nonSecretPayload = nonSecretPayload ?? new byte[] { };
nonSecretPayload ??= ""u8.ToArray();
//Using random nonce large enough not to repeat
var nonce = new byte[NonceBitSize / 8];
@@ -184,27 +183,21 @@ namespace mRemoteNG.Security.SymmetricEncryption
return decryptedText;
}
private string SimpleDecryptWithPassword(string encryptedMessage,
SecureString decryptionKey,
int nonSecretPayloadLength = 0)
private string SimpleDecryptWithPassword(string encryptedMessage, SecureString decryptionKey, int nonSecretPayloadLength = 0)
{
if (string.IsNullOrWhiteSpace(encryptedMessage))
return ""; //throw new ArgumentException(@"Encrypted Message Required!", nameof(encryptedMessage));
var cipherText = Convert.FromBase64String(encryptedMessage);
var plainText = SimpleDecryptWithPassword(cipherText, decryptionKey.ConvertToUnsecureString(),
nonSecretPayloadLength);
var plainText = SimpleDecryptWithPassword(cipherText, decryptionKey.ConvertToUnsecureString(), nonSecretPayloadLength);
return plainText == null ? null : _encoding.GetString(plainText);
}
private byte[] SimpleDecryptWithPassword(byte[] encryptedMessage,
string password,
int nonSecretPayloadLength = 0)
private byte[] SimpleDecryptWithPassword(byte[] encryptedMessage, string password, int nonSecretPayloadLength = 0)
{
//User Error Checks
if (string.IsNullOrWhiteSpace(password) || password.Length < MinPasswordLength)
throw new ArgumentException($"Must have a password of at least {MinPasswordLength} characters!",
nameof(password));
throw new ArgumentException($"Must have a password of at least {MinPasswordLength} characters!", nameof(password));
if (encryptedMessage == null || encryptedMessage.Length == 0)
throw new ArgumentException(@"Encrypted Message Required!", nameof(encryptedMessage));
@@ -230,34 +223,32 @@ namespace mRemoteNG.Security.SymmetricEncryption
throw new ArgumentException(@"Encrypted Message Required!", nameof(encryptedMessage));
var cipherStream = new MemoryStream(encryptedMessage);
using (var cipherReader = new BinaryReader(cipherStream))
using var cipherReader = new BinaryReader(cipherStream);
//Grab Payload
var nonSecretPayload = cipherReader.ReadBytes(nonSecretPayloadLength);
//Grab Nonce
var nonce = cipherReader.ReadBytes(NonceBitSize / 8);
var parameters = new AeadParameters(new KeyParameter(key), MacBitSize, nonce, nonSecretPayload);
_aeadBlockCipher.Init(false, parameters);
//Decrypt Cipher Text
var cipherText =
cipherReader.ReadBytes(encryptedMessage.Length - nonSecretPayloadLength - nonce.Length);
var plainText = new byte[_aeadBlockCipher.GetOutputSize(cipherText.Length)];
try
{
//Grab Payload
var nonSecretPayload = cipherReader.ReadBytes(nonSecretPayloadLength);
//Grab Nonce
var nonce = cipherReader.ReadBytes(NonceBitSize / 8);
var parameters = new AeadParameters(new KeyParameter(key), MacBitSize, nonce, nonSecretPayload);
_aeadBlockCipher.Init(false, parameters);
//Decrypt Cipher Text
var cipherText =
cipherReader.ReadBytes(encryptedMessage.Length - nonSecretPayloadLength - nonce.Length);
var plainText = new byte[_aeadBlockCipher.GetOutputSize(cipherText.Length)];
try
{
var len = _aeadBlockCipher.ProcessBytes(cipherText, 0, cipherText.Length, plainText, 0);
_aeadBlockCipher.DoFinal(plainText, len);
}
catch (InvalidCipherTextException e)
{
throw new EncryptionException(Language.ErrorDecryptionFailed, e);
}
return plainText;
var len = _aeadBlockCipher.ProcessBytes(cipherText, 0, cipherText.Length, plainText, 0);
_aeadBlockCipher.DoFinal(plainText, len);
}
catch (InvalidCipherTextException e)
{
throw new EncryptionException(Language.ErrorDecryptionFailed, e);
}
return plainText;
}
private byte[] GenerateSalt()

View File

@@ -58,7 +58,7 @@ namespace mRemoteNG.Tree.Root
}
}
[Browsable(false)] public string DefaultPassword { get; } = "mR3m";
[Browsable(false)] public string DefaultPassword { get; } = "mR3m"; //TODO move password away from code to settings
[Browsable(false)] public RootNodeType Type { get; set; }

View File

@@ -52,12 +52,12 @@ namespace mRemoteNG.UI.Controls
CMenToolbarShowText.Name = "cMenToolbarShowText";
CMenToolbarShowText.Size = new System.Drawing.Size(128, 22);
CMenToolbarShowText.Text = Language.ShowText;
CMenToolbarShowText.Click += cMenToolbarShowText_Click;
CMenToolbarShowText.Click += CMenToolbarShowText_Click;
}
#region Ext Apps Toolbar
private void cMenToolbarShowText_Click(object sender, EventArgs e)
private void CMenToolbarShowText_Click(object sender, EventArgs e)
{
SwitchToolBarText(!CMenToolbarShowText.Checked);
}
@@ -75,7 +75,7 @@ namespace mRemoteNG.UI.Controls
foreach (var tool in Runtime.ExternalToolsService.ExternalTools)
{
if (!tool.ShowOnToolbar) continue;
var button = (ToolStripButton)Items.Add(tool.DisplayName, tool.Image, tsExtAppEntry_Click);
var button = (ToolStripButton)Items.Add(tool.DisplayName, tool.Image, TsExtAppEntry_Click);
if (CMenToolbarShowText.Checked)
button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
else
@@ -96,7 +96,7 @@ namespace mRemoteNG.UI.Controls
}
}
private static void tsExtAppEntry_Click(object sender, EventArgs e)
private static void TsExtAppEntry_Click(object sender, EventArgs e)
{
var extA = (ExternalTool)((ToolStripButton)sender).Tag;
@@ -129,8 +129,6 @@ namespace mRemoteNG.UI.Controls
#endregion
// CodeAyalysis doesn't like null propagation
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed",
MessageId = "components")]
protected override void Dispose(bool disposing)
{
try

View File

@@ -65,7 +65,7 @@ namespace mRemoteNG.UI.Forms
this.pnlDock.Name = "pnlDock";
this.pnlDock.Size = new System.Drawing.Size(1129, 546);
this.pnlDock.TabIndex = 13;
this.pnlDock.ActiveDocumentChanged += new System.EventHandler(this.pnlDock_ActiveDocumentChanged);
this.pnlDock.ActiveDocumentChanged += new System.EventHandler(this.PnlDock_ActiveDocumentChanged);
//
// msMain
//
@@ -183,7 +183,7 @@ namespace mRemoteNG.UI.Forms
// tmrAutoSave
//
this.tmrAutoSave.Interval = 10000;
this.tmrAutoSave.Tick += new System.EventHandler(this.tmrAutoSave_Tick);
this.tmrAutoSave.Tick += new System.EventHandler(this.TmrAutoSave_Tick);
//
// vsToolStripExtender
//
@@ -201,7 +201,7 @@ namespace mRemoteNG.UI.Forms
this.tsModeUser.Name = "tsModeUser";
this.tsModeUser.Size = new System.Drawing.Size(180, 22);
this.tsModeUser.Text = "UserMode";
this.tsModeUser.Click += new System.EventHandler(this.tsModeUser_Click);
this.tsModeUser.Click += new System.EventHandler(this.TsModeUser_Click);
//
// FrmMain
//
@@ -217,12 +217,12 @@ namespace mRemoteNG.UI.Forms
this.Opacity = 0D;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = " ";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmMain_FormClosing);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmMain_FormClosing);
this.Load += new System.EventHandler(this.FrmMain_Load);
this.Shown += new System.EventHandler(this.frmMain_Shown);
this.ResizeBegin += new System.EventHandler(this.frmMain_ResizeBegin);
this.ResizeEnd += new System.EventHandler(this.frmMain_ResizeEnd);
this.Resize += new System.EventHandler(this.frmMain_Resize);
this.Shown += new System.EventHandler(this.FrmMain_Shown);
this.ResizeBegin += new System.EventHandler(this.FrmMain_ResizeBegin);
this.ResizeEnd += new System.EventHandler(this.FrmMain_ResizeEnd);
this.Resize += new System.EventHandler(this.FrmMain_Resize);
this.msMain.ResumeLayout(false);
this.msMain.PerformLayout();
this.tsContainer.ContentPanel.ResumeLayout(false);

View File

@@ -55,7 +55,7 @@ namespace mRemoteNG.UI.Forms
private ConnectionInfo _selectedConnection;
private readonly IList<IMessageWriter> _messageWriters = new List<IMessageWriter>();
private readonly ThemeManager _themeManager;
private readonly FileBackupPruner _backupPruner = new FileBackupPruner();
private readonly FileBackupPruner _backupPruner = new();
public static FrmOptions OptionsForm;
internal FullscreenHandler Fullscreen { get; set; }
@@ -337,7 +337,7 @@ namespace mRemoteNG.UI.Forms
}
}
private async void frmMain_Shown(object sender, EventArgs e)
private async void FrmMain_Shown(object sender, EventArgs e)
{
PromptForUpdatesPreference();
await CheckForUpdates();
@@ -380,7 +380,7 @@ namespace mRemoteNG.UI.Forms
await Startup.Instance.CheckForUpdate();
}
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (Runtime.WindowList != null)
{
@@ -396,8 +396,7 @@ namespace mRemoteNG.UI.Forms
if (Properties.OptionsAppearancePage.Default.CloseToTray)
{
if (Runtime.NotificationAreaIcon == null)
Runtime.NotificationAreaIcon = new NotificationAreaIcon();
Runtime.NotificationAreaIcon ??= new NotificationAreaIcon();
if (WindowState == FormWindowState.Normal || WindowState == FormWindowState.Maximized)
{
@@ -415,9 +414,9 @@ namespace mRemoteNG.UI.Forms
{
foreach (var dc in pnlDock.Contents)
{
if (!(dc is ConnectionWindow cw)) continue;
if (dc is not ConnectionWindow cw) continue;
if (cw.Controls.Count < 1) continue;
if (!(cw.Controls[0] is DockPanel dp)) continue;
if (cw.Controls[0] is not DockPanel dp) continue;
if (dp.Contents.Count > 0)
openConnections += dp.Contents.Count;
}
@@ -454,7 +453,7 @@ namespace mRemoteNG.UI.Forms
#region Timer
private void tmrAutoSave_Tick(object sender, EventArgs e)
private void TmrAutoSave_Tick(object sender, EventArgs e)
{
Runtime.MessageCollector.AddMessage(MessageClass.DebugMsg, "Doing AutoSave");
Runtime.ConnectionsService.SaveConnectionsAsync();
@@ -464,20 +463,17 @@ namespace mRemoteNG.UI.Forms
#region Window Overrides and DockPanel Stuff
private void frmMain_ResizeBegin(object sender, EventArgs e)
private void FrmMain_ResizeBegin(object sender, EventArgs e)
{
_inSizeMove = true;
}
private void frmMain_Resize(object sender, EventArgs e)
private void FrmMain_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
if (!Properties.OptionsAppearancePage.Default.MinimizeToTray) return;
if (Runtime.NotificationAreaIcon == null)
{
Runtime.NotificationAreaIcon = new NotificationAreaIcon();
}
Runtime.NotificationAreaIcon ??= new NotificationAreaIcon();
Hide();
}
@@ -487,7 +483,7 @@ namespace mRemoteNG.UI.Forms
}
}
private void frmMain_ResizeEnd(object sender, EventArgs e)
private void FrmMain_ResizeEnd(object sender, EventArgs e)
{
_inSizeMove = false;
// This handles activations from clicks that started a size/move operation
@@ -602,7 +598,7 @@ namespace mRemoteNG.UI.Forms
base.WndProc(ref m);
}
private void SimulateClick(Control control)
private static void SimulateClick(Control control)
{
var clientMousePosition = control.PointToClient(MousePosition);
var temp_wLow = clientMousePosition.X;
@@ -618,7 +614,7 @@ namespace mRemoteNG.UI.Forms
var cw = pnlDock.ActiveDocument as ConnectionWindow;
var dp = cw?.ActiveControl as DockPane;
if (!(dp?.ActiveContent is ConnectionTab tab)) return;
if (dp?.ActiveContent is not ConnectionTab tab) return;
var ifc = InterfaceControl.FindInterfaceControl(tab);
if (ifc == null) return;
@@ -627,7 +623,7 @@ namespace mRemoteNG.UI.Forms
((ConnectionTab)conFormWindow)?.RefreshInterfaceController();
}
private void pnlDock_ActiveDocumentChanged(object sender, EventArgs e)
private void PnlDock_ActiveDocumentChanged(object sender, EventArgs e)
{
ActivateConnection();
}
@@ -686,7 +682,7 @@ namespace mRemoteNG.UI.Forms
foreach (var dockContent in pnlDock.Documents)
{
var document = (DockContent)dockContent;
if ((closingDocument == null || document != closingDocument) && !(document is ConnectionWindow))
if ((closingDocument == null || document != closingDocument) && document is not ConnectionWindow)
{
nonConnectionPanelCount++;
}
@@ -834,12 +830,12 @@ namespace mRemoteNG.UI.Forms
viewMenu.mMenView_DropDownOpening(sender, e);
}
private void tsModeUser_Click(object sender, EventArgs e)
private void TsModeUser_Click(object sender, EventArgs e)
{
Properties.OptionsRbac.Default.ActiveRole = "UserRole";
}
private void tsModeAdmin_Click(object sender, EventArgs e)
private void TsModeAdmin_Click(object sender, EventArgs e)
{
Properties.OptionsRbac.Default.ActiveRole = "AdminRole";
}