Skip to content

Commit

Permalink
Open SRC
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostySo authored and FrostySo committed Aug 18, 2020
1 parent a73a440 commit a3b8044
Show file tree
Hide file tree
Showing 32 changed files with 4,046 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bld/
[Bb]in/
[Oo]bj/
[Ll]og/
dlls/

# Visual Studio 2015 cache/options directory
.vs/
Expand Down
10 changes: 9 additions & 1 deletion Ps4-Pkg-Sender/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
79 changes: 79 additions & 0 deletions Ps4-Pkg-Sender/Controls/CustomProgressBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ps4_Pkg_Sender.Controls {
public class CustomProgressBar : ProgressBar{


[Category("ProgressBar")]
[Description("The color of the progress bar")]
public Color Color {
get { return progressColor; }
set {
progressColor = value;
if(_brush != null) {
_brush.Dispose();
}
_brush = new SolidBrush(progressColor);
Invalidate();
}
}

[Description("The Font of the text")]
public Font Font {
get { return font; }
set {
if(font != null) {
font.Dispose();
}
font = value;
Invalidate();
}
}

private Color progressColor = Color.Green;

private Font font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
private Brush _brush = Brushes.Green;

public long SecondsRemaining { get; set; } = 0;

public string ExtraText { get; set; } = null;

public CustomProgressBar() {
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}

public void ResetProgressBar() {
this.Value = 0;
this.SecondsRemaining = 0;
}

protected override void OnPaint(PaintEventArgs e) {
Rectangle rec = e.ClipRectangle;

rec.Width = (int)(rec.Width * ((double)Value / Maximum)) - 4;
if (ProgressBarRenderer.IsSupported)
ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle);
Rectangle rect = new Rectangle(new Point(0, 0), new Size(Maximum, rec.Height));
e.Graphics.FillRectangle(Brushes.Gray, 0, 0, Width, rect.Height);
e.Graphics.FillRectangle(_brush, 0, 0, rec.Width, rec.Height);
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
String estimatedTime = SecondsRemaining > 0 ? $"- Time left: {Utilities.TimeFormatUtil.GetCountdownFormat(SecondsRemaining,false)}" : "";
if (ExtraText != null) {
estimatedTime += ExtraText;
}
e.Graphics.DrawString($"{this.Value}% {estimatedTime}", this.font, Brushes.White,this.Width / 2, this.Height / 2,sf);
}
}
}
255 changes: 255 additions & 0 deletions Ps4-Pkg-Sender/Controls/Sorting/ListViewColumnSorter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
using System;
using System.Collections;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace Ps4_Pkg_Sender.Controls.Sorting {
//https://www.codeproject.com/Articles/5332/ListView-Column-Sorter
public class ListViewColumnSorter : IComparer {
public enum SortModifiers {
SortByImage,
SortByCheckbox,
SortByText
}

/// <summary>
/// Specifies the column to be sorted
/// </summary>
public int ColumnToSort;
/// <summary>
/// Specifies the order in which to sort (i.e. 'Ascending').
/// </summary>
public SortOrder OrderOfSort;
/// <summary>
/// Case insensitive comparer object
/// </summary>

private NumberCaseInsensitiveComparer ObjectCompare;
private ImageTextComparer FirstObjectCompare;
private CheckboxTextComparer FirstObjectCompare2;

private SortModifiers mySortModifier = SortModifiers.SortByText;
public SortModifiers _SortModifier {
set {
mySortModifier = value;
}
get {
return mySortModifier;
}
}

/// <summary>
/// Class constructor. Initializes various elements
/// </summary>
public ListViewColumnSorter() {
// Initialize the column to '0'
ColumnToSort = 0;
this.Order = SortOrder.Ascending;
// Initialize the CaseInsensitiveComparer object
ObjectCompare = new NumberCaseInsensitiveComparer();
FirstObjectCompare = new ImageTextComparer();
FirstObjectCompare2 = new CheckboxTextComparer();
}

/// <summary>
/// This method is inherited from the IComparer interface. It compares the two objects passed using a case insensitive comparison.
/// </summary>
/// <param name="x">First object to be compared</param>
/// <param name="y">Second object to be compared</param>
/// <returns>The result of the comparison. "0" if equal, negative if 'x' is less than 'y' and positive if 'x' is greater than 'y'</returns>
public int Compare(object x, object y) {
int compareResult = 0;
ListViewItem listviewX, listviewY;

// Cast the objects to be compared to ListViewItem objects
listviewX = (ListViewItem)x;
listviewY = (ListViewItem)y;

ListView listViewMain = listviewX.ListView;

// Calculate correct return value based on object comparison
if (listViewMain.Sorting != SortOrder.Ascending &&
listViewMain.Sorting != SortOrder.Descending) {
// Return '0' to indicate they are equal
return compareResult;
}

if (mySortModifier.Equals(SortModifiers.SortByText) || ColumnToSort > 0) {
// Compare the two items

if (listviewX.SubItems.Count <= ColumnToSort &&
listviewY.SubItems.Count <= ColumnToSort) {
compareResult = ObjectCompare.Compare(null, null);
} else if (listviewX.SubItems.Count <= ColumnToSort &&
listviewY.SubItems.Count > ColumnToSort) {
compareResult = ObjectCompare.Compare(null, listviewY.SubItems[ColumnToSort].Text.Trim());
} else if (listviewX.SubItems.Count > ColumnToSort && listviewY.SubItems.Count <= ColumnToSort) {
compareResult = ObjectCompare.Compare(listviewX.SubItems[ColumnToSort].Text.Trim(), null);
} else {
compareResult = ObjectCompare.Compare(listviewX.SubItems[ColumnToSort].Text.Trim(), listviewY.SubItems[ColumnToSort].Text.Trim());
}
} else {
switch (mySortModifier) {
case SortModifiers.SortByCheckbox:
compareResult = FirstObjectCompare2.Compare(x, y);
break;
case SortModifiers.SortByImage:
compareResult = FirstObjectCompare.Compare(x, y);
break;
default:
compareResult = FirstObjectCompare.Compare(x, y);
break;
}
}

// Calculate correct return value based on object comparison
if (OrderOfSort == SortOrder.Ascending) {
// Ascending sort is selected, return normal result of compare operation
return compareResult;
} else if (OrderOfSort == SortOrder.Descending) {
// Descending sort is selected, return negative result of compare operation
return (-compareResult);
} else {
// Return '0' to indicate they are equal
return 0;
}
}

/// <summary>
/// Gets or sets the number of the column to which to apply the sorting operation (Defaults to '0').
/// </summary>
public int SortColumn {
set {
ColumnToSort = value;
}
get {
return ColumnToSort;
}
}

/// <summary>
/// Gets or sets the order of sorting to apply (for example, 'Ascending' or 'Descending').
/// </summary>
public SortOrder Order {
set {
OrderOfSort = value;
}
get {
return OrderOfSort;
}
}

}

public class ImageTextComparer : IComparer {
//private CaseInsensitiveComparer ObjectCompare;
private NumberCaseInsensitiveComparer ObjectCompare;

public ImageTextComparer() {
// Initialize the CaseInsensitiveComparer object
ObjectCompare = new NumberCaseInsensitiveComparer();
}

public int Compare(object x, object y) {
//int compareResult;
int image1, image2;
ListViewItem listviewX, listviewY;

// Cast the objects to be compared to ListViewItem objects
listviewX = (ListViewItem)x;
image1 = listviewX.ImageIndex;
listviewY = (ListViewItem)y;
image2 = listviewY.ImageIndex;

if (image1 < image2) {
return -1;
} else if (image1 == image2) {
return ObjectCompare.Compare(listviewX.Text.Trim(), listviewY.Text.Trim());
} else {
return 1;
}
}
}

public class CheckboxTextComparer : IComparer {
private NumberCaseInsensitiveComparer ObjectCompare;

public CheckboxTextComparer() {
// Initialize the CaseInsensitiveComparer object
ObjectCompare = new NumberCaseInsensitiveComparer();
}

public int Compare(object x, object y) {
// Cast the objects to be compared to ListViewItem objects
ListViewItem listviewX = (ListViewItem)x;
ListViewItem listviewY = (ListViewItem)y;

if (listviewX.Checked && !listviewY.Checked) {
return -1;
} else if (listviewX.Checked.Equals(listviewY.Checked)) {
if (listviewX.ImageIndex < listviewY.ImageIndex) {
return -1;
} else if (listviewX.ImageIndex == listviewY.ImageIndex) {
return ObjectCompare.Compare(listviewX.Text.Trim(), listviewY.Text.Trim());
} else {
return 1;
}
} else {
return 1;
}
}
}

public class NumberCaseInsensitiveComparer : CaseInsensitiveComparer {
public NumberCaseInsensitiveComparer() {

}

public new int Compare(object x, object y) {
if (x == null && y == null) {
return 0;
} else if (x == null && y != null) {
return -1;
} else if (x != null && y == null) {
return 1;
}

if ((x is System.String) && IsDecimalNumber((string)x) && (y is System.String) && IsDecimalNumber((string)y)) {
try {
decimal xx = Decimal.Parse(((string)x).Trim());
decimal yy = Decimal.Parse(((string)y).Trim());

return base.Compare(xx, yy);
} catch {
return -1;
}
} else {
return base.Compare(x, y);
}
}

// deprecated
//private bool IsWholeNumber(string strNumber)
//{
// Regex wholePattern = new Regex(@"^\d+$");
// return wholePattern.IsMatch(strNumber);
//}

private string GetNumberDecimalSeparator() {
return System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
}

// http://stackoverflow.com/questions/4246077/matching-numbers-with-regular-expressions-only-digits-and-commas/4247184#4247184
// https://www.debuggex.com/r/Lyx0F0y1LORvNhwA
private bool IsDecimalNumber(string strNumber) {
//@"^-?(\d+|(\d{1,3}((,|\.)\d{3})*))((,|\.)\d+)?$"

//string regex = @"^-?(?:(?:0|[1-9][0-9]*)(?:" + GetNumberDecimalSeparator() + @"[0-9]+)?|[1-9][0-9]{1,2}(?:,[0-9]{3})+)$";

string regex = @"^-?(\d+|(\d{1,3}((,|\.)\d{3})*))((,|\.)\d+)?$";

Regex wholePattern = new Regex(regex);
return wholePattern.IsMatch(strNumber);
}
}
}
Loading

0 comments on commit a3b8044

Please sign in to comment.