Skip to content

Commit

Permalink
Finish up for 2.0.5 release
Browse files Browse the repository at this point in the history
  • Loading branch information
FakeDomi committed May 25, 2017
1 parent 4f3977b commit 499f1ff
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 62 deletions.
18 changes: 16 additions & 2 deletions domi1819.DarkControls/DarkForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@

namespace domi1819.DarkControls
{
/// <summary>
/// A window that has some values set for a dark themed environment.
/// Also allows selected components to glow.
/// </summary>
public class DarkForm : Form
{
private IGlowComponent focus, hover;

/// <summary>
/// Whether glow for focused/hovered components should be disabled.
/// </summary>
public bool DisableGlow { get; set; }

public DarkForm()
Expand Down Expand Up @@ -41,13 +48,20 @@ protected override void OnPaint(PaintEventArgs e)
}
}

internal static void UpdateGlow(bool focus, Control control, bool active)
/// <summary>
/// Called when a child control changes hover/focus state.
/// Updates the form's glow information and then re-draws the window.
/// </summary>
/// <param name="focused">Whether the updating control is/was focused or hovered over.</param>
/// <param name="control">The control that's updating.</param>
/// <param name="active">The focus/hover state.</param>
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;
}
Expand Down
4 changes: 1 addition & 3 deletions domi1819.UpClient/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");

Expand Down
41 changes: 35 additions & 6 deletions domi1819.UpClient/Address.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,56 @@
namespace domi1819.UpClient
{
/// <summary>
/// A type designed to hold a full address to some TCP/UDP server.
/// </summary>
internal struct Address
{
internal static Address Invalid = default(Address);
/// <summary>
/// The default value of the Address type that marks an invalid Address.
/// </summary>
internal static readonly Address Invalid = default(Address);

internal string Host;
/// <summary>
/// The host part of this Address. Can be an IP number, a hostname or a DNS name.
/// </summary>
internal string Host { get; }

internal int Port;
/// <summary>
/// The port of this Address. Ranges from 1 - 65535.
/// </summary>
internal int Port { get; }

internal Address(string host, int port)
/// <summary>
/// Creates a new Address with the given parameters.
/// </summary>
/// <param name="host">The host part.</param>
/// <param name="port">The port.</param>
private Address(string host, int port)
{
this.Host = host;
this.Port = port;
}

/// <summary>
/// Checks two Addresses for equality in terms of host part and port.
/// </summary>
/// <param name="other">The other Address to use for comparing.</param>
/// <returns>True if both Addresses are equal, false otherwise.</returns>
internal bool Equals(Address other)
{
return this.Host == other.Host && this.Port == other.Port;
}

internal static Address Parse(string address, int defaultPort)
/// <summary>
/// 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
/// </summary>
/// <param name="fullAddress">The address input string.</param>
/// <param name="defaultPort">The default port to use if none is specified in the input string.</param>
/// <returns>An Address or Address.Invalid when parsing failed.</returns>
internal static Address Parse(string fullAddress, int defaultPort)
{
string[] addressSplit = address.Split(':');
string[] addressSplit = fullAddress.Split(':');

if (addressSplit.Length == 1)
{
Expand Down
6 changes: 3 additions & 3 deletions domi1819.UpClient/Forms/FileDropForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 5 additions & 5 deletions domi1819.UpClient/Forms/InfoForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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);

Expand Down
17 changes: 7 additions & 10 deletions domi1819.UpClient/Forms/ScreenshotForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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)
Expand Down
27 changes: 12 additions & 15 deletions domi1819.UpClient/Forms/UploadQueueForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using domi1819.DarkControls;
using domi1819.UpClient.Uploads;
using domi1819.UpCore.Utilities;
using domi1819.UpCore.Windows;

namespace domi1819.UpClient.Forms
{
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions domi1819.UpClient/StorageExplorer/FileItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 17 additions & 13 deletions domi1819.UpCore.Windows/WinConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 5 additions & 0 deletions domi1819.UpCore/Utilities/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}";
}
}
}
2 changes: 1 addition & 1 deletion domi1819.UpServer/Console/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal List<string> AutoComplete(List<string> input)
return new List<string>();
}

protected virtual Result Run(List<string> input)
protected virtual Result Run(IEnumerable<string> input)
{
System.Console.WriteLine($"Usage: {string.Join(" ", input)} <{string.Join("/", this.SubCommands.Keys)}>");
return Result.ReuseCommand;
Expand Down
2 changes: 1 addition & 1 deletion domi1819.UpServer/Console/Commands/CommandStop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public CommandStop(BaseCommand parent) : base(parent)
{
}

protected override Result Run(List<string> input)
protected override Result Run(IEnumerable<string> input)
{
return Result.Shutdown;
}
Expand Down
2 changes: 1 addition & 1 deletion domi1819.UpServer/Console/Commands/CommandUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public CommandUserAdd(BaseCommand parent, UserManager users) : base(parent)
this.users = users;
}

protected override Result Run(List<string> input)
protected override Result Run(IEnumerable<string> input)
{
if (Feedback.ReadString("User name?", x => this.users.IsValidName(x), "Invalid name (too short or too long).", out string userName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public CommandUserSetPassword(BaseCommand parent, UserManager users) : base(pare
this.users = users;
}

protected override Result Run(List<string> input)
protected override Result Run(IEnumerable<string> input)
{
if (Feedback.ReadString("User name?", x => this.users.HasUser(x), "User not found.", out string userName))
{
Expand Down
2 changes: 1 addition & 1 deletion domi1819.UpServer/Console/Commands/RootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public RootCommand(UpServer server) : base(null)
this.SubCommands.Add("user", new CommandUser(this, server.Users));
}

protected override Result Run(List<string> input)
protected override Result Run(IEnumerable<string> input)
{
System.Console.WriteLine("Unknown command \"\"");

Expand Down

0 comments on commit 499f1ff

Please sign in to comment.