From 499f1ffefe2a1d4a039df90ebfc2b58b6e1ca87f Mon Sep 17 00:00:00 2001 From: domi1819 Date: Thu, 25 May 2017 13:09:15 +0200 Subject: [PATCH] Finish up for 2.0.5 release --- domi1819.DarkControls/DarkForm.cs | 18 +++++++- domi1819.UpClient/ActionManager.cs | 4 +- domi1819.UpClient/Address.cs | 41 ++++++++++++++++--- domi1819.UpClient/Forms/FileDropForm.cs | 6 +-- domi1819.UpClient/Forms/InfoForm.cs | 10 ++--- domi1819.UpClient/Forms/ScreenshotForm.cs | 17 ++++---- domi1819.UpClient/Forms/UploadQueueForm.cs | 27 ++++++------ domi1819.UpClient/StorageExplorer/FileItem.cs | 2 + domi1819.UpCore.Windows/WinConsts.cs | 30 ++++++++------ domi1819.UpCore/Utilities/Util.cs | 5 +++ .../Console/Commands/BaseCommand.cs | 2 +- .../Console/Commands/CommandStop.cs | 2 +- .../Console/Commands/CommandUser.cs | 2 +- .../Commands/CommandUserSetPassword.cs | 2 +- .../Console/Commands/RootCommand.cs | 2 +- 15 files changed, 108 insertions(+), 62 deletions(-) diff --git a/domi1819.DarkControls/DarkForm.cs b/domi1819.DarkControls/DarkForm.cs index 0f74df9..4607995 100644 --- a/domi1819.DarkControls/DarkForm.cs +++ b/domi1819.DarkControls/DarkForm.cs @@ -3,10 +3,17 @@ namespace domi1819.DarkControls { + /// + /// A window that has some values set for a dark themed environment. + /// Also allows selected components to glow. + /// public class DarkForm : Form { private IGlowComponent focus, hover; + /// + /// Whether glow for focused/hovered components should be disabled. + /// public bool DisableGlow { get; set; } public DarkForm() @@ -41,13 +48,20 @@ protected override void OnPaint(PaintEventArgs e) } } - internal static void UpdateGlow(bool focus, Control control, bool active) + /// + /// Called when a child control changes hover/focus state. + /// Updates the form's glow information and then re-draws the window. + /// + /// Whether the updating control is/was focused or hovered over. + /// The control that's updating. + /// The focus/hover state. + internal static void UpdateGlow(bool focused, Control control, bool active) { if (control.Parent is DarkForm parent) { IGlowComponent glowComponent = (IGlowComponent)(active ? control : null); - if (focus) + if (focused) { parent.focus = glowComponent; } diff --git a/domi1819.UpClient/ActionManager.cs b/domi1819.UpClient/ActionManager.cs index a3a12ee..3a652b2 100644 --- a/domi1819.UpClient/ActionManager.cs +++ b/domi1819.UpClient/ActionManager.cs @@ -40,10 +40,8 @@ internal void UploadClipboard(bool local = false) { if (Clipboard.ContainsImage() || Clipboard.ContainsText()) { - DateTime now = DateTime.Now; - string tempFolderPath = Util.CreateTempFolder(); - string fileName = $"clip_{now.Year}-{now.Month.Pad(2)}-{now.Day.Pad(2)}_{now.Hour.Pad(2)}-{now.Minute.Pad(2)}-{now.Second.Pad(2)}"; + string fileName = $"clip_{Util.GetTimestampString(DateTime.Now)}"; string fileExt = Clipboard.ContainsImage() ? ".png" : ".txt"; string fileFullPath = Path.Combine(tempFolderPath, $"{fileName}{fileExt}"); diff --git a/domi1819.UpClient/Address.cs b/domi1819.UpClient/Address.cs index 77f7ed8..e5e0ae0 100644 --- a/domi1819.UpClient/Address.cs +++ b/domi1819.UpClient/Address.cs @@ -1,27 +1,56 @@ namespace domi1819.UpClient { + /// + /// A type designed to hold a full address to some TCP/UDP server. + /// internal struct Address { - internal static Address Invalid = default(Address); + /// + /// The default value of the Address type that marks an invalid Address. + /// + internal static readonly Address Invalid = default(Address); - internal string Host; + /// + /// The host part of this Address. Can be an IP number, a hostname or a DNS name. + /// + internal string Host { get; } - internal int Port; + /// + /// The port of this Address. Ranges from 1 - 65535. + /// + internal int Port { get; } - internal Address(string host, int port) + /// + /// Creates a new Address with the given parameters. + /// + /// The host part. + /// The port. + private Address(string host, int port) { this.Host = host; this.Port = port; } + /// + /// Checks two Addresses for equality in terms of host part and port. + /// + /// The other Address to use for comparing. + /// True if both Addresses are equal, false otherwise. internal bool Equals(Address other) { return this.Host == other.Host && this.Port == other.Port; } - internal static Address Parse(string address, int defaultPort) + /// + /// Parses a full address string into an Address, with a default port if none is found in the address string. + /// Examples: google.com; 172.16.0.1:8080 + /// + /// The address input string. + /// The default port to use if none is specified in the input string. + /// An Address or Address.Invalid when parsing failed. + internal static Address Parse(string fullAddress, int defaultPort) { - string[] addressSplit = address.Split(':'); + string[] addressSplit = fullAddress.Split(':'); if (addressSplit.Length == 1) { diff --git a/domi1819.UpClient/Forms/FileDropForm.cs b/domi1819.UpClient/Forms/FileDropForm.cs index 8076c16..0836abb 100644 --- a/domi1819.UpClient/Forms/FileDropForm.cs +++ b/domi1819.UpClient/Forms/FileDropForm.cs @@ -82,14 +82,14 @@ internal void Resnap(Point? p = null) protected override void WndProc(ref Message m) { - switch ((uint)m.Msg) + switch (m.Msg) { case WinConsts.WM_NCHITTEST: - m.Result = new IntPtr((int)WinConsts.HTCLIENT); + m.Result = new IntPtr(WinConsts.HTCLIENT); return; case WinConsts.WM_NCACTIVATE: - m.WParam = new IntPtr((int)WinConsts.TRUE); + m.WParam = new IntPtr(WinConsts.TRUE); break; } diff --git a/domi1819.UpClient/Forms/InfoForm.cs b/domi1819.UpClient/Forms/InfoForm.cs index efe0612..0b556ae 100644 --- a/domi1819.UpClient/Forms/InfoForm.cs +++ b/domi1819.UpClient/Forms/InfoForm.cs @@ -24,7 +24,7 @@ protected override CreateParams CreateParams get { CreateParams createParams = base.CreateParams; - createParams.ExStyle |= (int)WinConsts.WS_EX_TOPMOST; + createParams.ExStyle |= WinConsts.WS_EX_TOPMOST; return createParams; } @@ -48,14 +48,14 @@ internal InfoForm(string title, string text, int timeout) protected override void WndProc(ref Message m) { - switch ((uint)m.Msg) + switch (m.Msg) { case WinConsts.WM_NCHITTEST: - m.Result = new IntPtr((int)WinConsts.HTCLIENT); + m.Result = new IntPtr(WinConsts.HTCLIENT); return; case WinConsts.WM_NCACTIVATE: - m.WParam = new IntPtr((int)WinConsts.TRUE); + m.WParam = new IntPtr(WinConsts.TRUE); break; } @@ -66,7 +66,7 @@ private void InfoTimerTick(object sender, EventArgs e) { if (!this.showing) { - Message m = new Message { HWnd = this.Handle, Msg = (int)WinConsts.WM_NCACTIVATE }; + Message m = new Message { HWnd = this.Handle, Msg = WinConsts.WM_NCACTIVATE }; this.WndProc(ref m); diff --git a/domi1819.UpClient/Forms/ScreenshotForm.cs b/domi1819.UpClient/Forms/ScreenshotForm.cs index 5e48066..c61fb01 100644 --- a/domi1819.UpClient/Forms/ScreenshotForm.cs +++ b/domi1819.UpClient/Forms/ScreenshotForm.cs @@ -15,7 +15,7 @@ namespace domi1819.UpClient.Forms { internal partial class ScreenshotForm : Form { - private readonly Brush brush = new SolidBrush(Color.FromArgb(80, 128, 128, 128)); + private readonly Brush inactiveRegion = new SolidBrush(Color.FromArgb(80, 128, 128, 128)); private readonly UpClient upClient; @@ -118,18 +118,18 @@ protected override void OnPaint(PaintEventArgs e) if (this.drawSelection) { - e.Graphics.FillRectangle(this.brush, 0, 0, this.Width, this.drawStartY); - e.Graphics.FillRectangle(this.brush, 0, this.drawEndY, this.Width, this.Height - this.drawEndY); + e.Graphics.FillRectangle(this.inactiveRegion, 0, 0, this.Width, this.drawStartY); + e.Graphics.FillRectangle(this.inactiveRegion, 0, this.drawEndY, this.Width, this.Height - this.drawEndY); - e.Graphics.FillRectangle(this.brush, 0, this.drawStartY, this.drawStartX, this.drawEndY - this.drawStartY); - e.Graphics.FillRectangle(this.brush, this.drawEndX, this.drawStartY, this.Width - this.drawEndX, this.drawEndY - this.drawStartY); + e.Graphics.FillRectangle(this.inactiveRegion, 0, this.drawStartY, this.drawStartX, this.drawEndY - this.drawStartY); + e.Graphics.FillRectangle(this.inactiveRegion, this.drawEndX, this.drawStartY, this.Width - this.drawEndX, this.drawEndY - this.drawStartY); ControlPaint.DrawBorder(e.Graphics, new Rectangle(this.drawStartX - 1, this.drawStartY - 1, this.drawEndX - this.drawStartX + 2, this.drawEndY - this.drawStartY + 2), DarkPainting.PaleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(e.Graphics, new Rectangle(this.drawStartX, this.drawStartY, this.drawEndX - this.drawStartX, this.drawEndY - this.drawStartY), DarkPainting.StrongColor, ButtonBorderStyle.Solid); } else if (this.drawBackground) { - e.Graphics.FillRectangle(this.brush, 0, 0, this.Width, this.Height); + e.Graphics.FillRectangle(this.inactiveRegion, 0, 0, this.Width, this.Height); } } @@ -205,11 +205,8 @@ private void FinalizeScreenshot(bool cancel) } string tempFolderPath = Util.CreateTempFolder(); - - DateTime now = DateTime.Now; - string fileExtension = settings.PngScreenshots ? ".png" : ".jpeg"; - string fileName = $"ss_{now.Year}-{now.Month.Pad(2)}-{now.Day.Pad(2)}_{now.Hour.Pad(2)}-{now.Minute.Pad(2)}-{now.Second.Pad(2)}"; + string fileName = $"ss_{Util.GetTimestampString(DateTime.Now)}"; string fileFullPath = Path.Combine(tempFolderPath, $"{fileName}{fileExtension}"); if (settings.PngScreenshots) diff --git a/domi1819.UpClient/Forms/UploadQueueForm.cs b/domi1819.UpClient/Forms/UploadQueueForm.cs index 33410ac..e8d6867 100644 --- a/domi1819.UpClient/Forms/UploadQueueForm.cs +++ b/domi1819.UpClient/Forms/UploadQueueForm.cs @@ -7,6 +7,7 @@ using domi1819.DarkControls; using domi1819.UpClient.Uploads; using domi1819.UpCore.Utilities; +using domi1819.UpCore.Windows; namespace domi1819.UpClient.Forms { @@ -127,25 +128,21 @@ protected override void WndProc(ref Message m) { switch (m.Msg) { - case 0x0084: // WM_NCHITTEST + case WinConsts.WM_NCHITTEST: + m.Result = new IntPtr(WinConsts.HTCLIENT); + return; + + case WinConsts.WM_NCACTIVATE: + m.WParam = new IntPtr(WinConsts.TRUE); + break; + + case WinConsts.WM_SYSCOMMAND: + if ((m.WParam.ToInt32() & WinConsts.SC_MASK) == WinConsts.SC_MOVE) { - m.Result = new IntPtr(0x01); // HTCLIENT return; } - case 0x0086: // WM_NCACTIVATE - { - m.WParam = new IntPtr(0x01); // TRUE - break; - } - case 0x0112: // WM_SYSCOMMAND - { - if ((m.WParam.ToInt32() & 0xfff0) == 0xF010) // SC_MOVE - { - return; - } - break; - } + break; } base.WndProc(ref m); diff --git a/domi1819.UpClient/StorageExplorer/FileItem.cs b/domi1819.UpClient/StorageExplorer/FileItem.cs index 2ebbd5c..d2bcf5e 100644 --- a/domi1819.UpClient/StorageExplorer/FileItem.cs +++ b/domi1819.UpClient/StorageExplorer/FileItem.cs @@ -4,6 +4,8 @@ using System.IO; using domi1819.UpCore.Utilities; +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global namespace domi1819.UpClient.StorageExplorer { internal class FileItem diff --git a/domi1819.UpCore.Windows/WinConsts.cs b/domi1819.UpCore.Windows/WinConsts.cs index 982c838..828fe30 100644 --- a/domi1819.UpCore.Windows/WinConsts.cs +++ b/domi1819.UpCore.Windows/WinConsts.cs @@ -3,24 +3,28 @@ namespace domi1819.UpCore.Windows { public static class WinConsts { - public const uint TRUE = 0x01; + public const int TRUE = 0x01; - public const uint FILE_ATTRIBUTE_NORMAL = 0x80; + public const int FILE_ATTRIBUTE_NORMAL = 0x80; - public const uint HTCLIENT = 0x01; + public const int HTCLIENT = 0x01; - public const uint MA_NOACTIVATE = 0x03; + public const int MA_NOACTIVATE = 0x03; - public const uint SHGFI_SMALLICON = 0x0001; - public const uint SHGFI_USEFILEATTRIBUTES = 0x0010; - public const uint SHGFI_ICON = 0x0100; + public const int SC_MOVE = 0xF010; + public const int SC_MASK = 0xFFF0; - public const uint WM_ACTIVATE = 0x0006; - public const uint WM_MOUSEACTIVATE = 0x0021; - public const uint WM_NCHITTEST = 0x0084; - public const uint WM_NCACTIVATE = 0x0086; - public const uint WM_HOTKEY = 0x0312; + public const int SHGFI_SMALLICON = 0x0001; + public const int SHGFI_USEFILEATTRIBUTES = 0x0010; + public const int SHGFI_ICON = 0x0100; - public const uint WS_EX_TOPMOST = 0x0008; + public const int WM_ACTIVATE = 0x0006; + public const int WM_MOUSEACTIVATE = 0x0021; + public const int WM_NCHITTEST = 0x0084; + public const int WM_NCACTIVATE = 0x0086; + public const int WM_SYSCOMMAND = 0x0112; + public const int WM_HOTKEY = 0x0312; + + public const int WS_EX_TOPMOST = 0x0008; } } diff --git a/domi1819.UpCore/Utilities/Util.cs b/domi1819.UpCore/Utilities/Util.cs index f74d98c..4427541 100644 --- a/domi1819.UpCore/Utilities/Util.cs +++ b/domi1819.UpCore/Utilities/Util.cs @@ -154,5 +154,10 @@ public static char GetHexChar(int value) return (char)(loNibble + (loNibble < 10 ? '0' : 'A' - 10)); } + + public static string GetTimestampString(DateTime dateTime) + { + return $"{dateTime.Year}-{dateTime.Month.Pad(2)}-{dateTime.Day.Pad(2)}_{dateTime.Hour.Pad(2)}-{dateTime.Minute.Pad(2)}-{dateTime.Second.Pad(2)}"; + } } } diff --git a/domi1819.UpServer/Console/Commands/BaseCommand.cs b/domi1819.UpServer/Console/Commands/BaseCommand.cs index aa42f84..f40c1c4 100644 --- a/domi1819.UpServer/Console/Commands/BaseCommand.cs +++ b/domi1819.UpServer/Console/Commands/BaseCommand.cs @@ -58,7 +58,7 @@ internal List AutoComplete(List input) return new List(); } - protected virtual Result Run(List input) + protected virtual Result Run(IEnumerable input) { System.Console.WriteLine($"Usage: {string.Join(" ", input)} <{string.Join("/", this.SubCommands.Keys)}>"); return Result.ReuseCommand; diff --git a/domi1819.UpServer/Console/Commands/CommandStop.cs b/domi1819.UpServer/Console/Commands/CommandStop.cs index 4dae1bc..ffa1724 100644 --- a/domi1819.UpServer/Console/Commands/CommandStop.cs +++ b/domi1819.UpServer/Console/Commands/CommandStop.cs @@ -8,7 +8,7 @@ public CommandStop(BaseCommand parent) : base(parent) { } - protected override Result Run(List input) + protected override Result Run(IEnumerable input) { return Result.Shutdown; } diff --git a/domi1819.UpServer/Console/Commands/CommandUser.cs b/domi1819.UpServer/Console/Commands/CommandUser.cs index 087440a..b7d1203 100644 --- a/domi1819.UpServer/Console/Commands/CommandUser.cs +++ b/domi1819.UpServer/Console/Commands/CommandUser.cs @@ -20,7 +20,7 @@ public CommandUserAdd(BaseCommand parent, UserManager users) : base(parent) this.users = users; } - protected override Result Run(List input) + protected override Result Run(IEnumerable input) { if (Feedback.ReadString("User name?", x => this.users.IsValidName(x), "Invalid name (too short or too long).", out string userName)) { diff --git a/domi1819.UpServer/Console/Commands/CommandUserSetPassword.cs b/domi1819.UpServer/Console/Commands/CommandUserSetPassword.cs index db205b3..c2716d1 100644 --- a/domi1819.UpServer/Console/Commands/CommandUserSetPassword.cs +++ b/domi1819.UpServer/Console/Commands/CommandUserSetPassword.cs @@ -11,7 +11,7 @@ public CommandUserSetPassword(BaseCommand parent, UserManager users) : base(pare this.users = users; } - protected override Result Run(List input) + protected override Result Run(IEnumerable input) { if (Feedback.ReadString("User name?", x => this.users.HasUser(x), "User not found.", out string userName)) { diff --git a/domi1819.UpServer/Console/Commands/RootCommand.cs b/domi1819.UpServer/Console/Commands/RootCommand.cs index b6bcee3..4895f0a 100644 --- a/domi1819.UpServer/Console/Commands/RootCommand.cs +++ b/domi1819.UpServer/Console/Commands/RootCommand.cs @@ -10,7 +10,7 @@ public RootCommand(UpServer server) : base(null) this.SubCommands.Add("user", new CommandUser(this, server.Users)); } - protected override Result Run(List input) + protected override Result Run(IEnumerable input) { System.Console.WriteLine("Unknown command \"\"");