From 44247f411d18a6e74e829b2277dc571ac7747fe0 Mon Sep 17 00:00:00 2001 From: Taicanium Date: Tue, 5 Mar 2024 21:05:28 -0600 Subject: [PATCH] 1.1.3.3 Changes --- ByteCount.cs | 130 +++++++++++++++++++++++++++++++++++++++++++++ CHANGELOG.md | 5 +- Common.cs | 138 ------------------------------------------------ FLogS.csproj | 2 +- KNOWN.md | 3 +- MainWindow.xaml | 8 +-- MessagePool.cs | 33 ++++++++---- 7 files changed, 162 insertions(+), 157 deletions(-) create mode 100644 ByteCount.cs diff --git a/ByteCount.cs b/ByteCount.cs new file mode 100644 index 0000000..ff13d4f --- /dev/null +++ b/ByteCount.cs @@ -0,0 +1,130 @@ +using System; + +namespace FLogS +{ + struct ByteCount + { + public ByteCount() { bytes = 0.0; prefix = -1; } + public ByteCount(double b, short p) { bytes = b; prefix = p; } + + public double bytes; + public short prefix; + + public void Adjust(int factor, bool absolute = true) + { + if (!absolute) + factor = (short)(prefix - factor); + while (prefix < factor) + Magnitude(-1); + while (prefix > factor) + Magnitude(1); + return; + } + + public void Magnitude(int factor) + { + bytes *= Math.Pow(1024, factor); + prefix -= (short)factor; + } + + public void Simplify() + { + while (bytes >= 921.6 && prefix < Common.prefixes.Length) + Magnitude(-1); + while (bytes < 0.9 && prefix > -1) + Magnitude(1); + return; + } + + public static ByteCount operator -(ByteCount a, ByteCount b) + { + ByteCount o; + ByteCount o2; + + if (Math.Abs(a.prefix - b.prefix) > 3) // Special accommodations must be made if the disparity in magnitude would normally result in an int overflow. + { + o = new(a.bytes, a.prefix); + o2 = new(b.bytes, b.prefix); + o.Adjust(Math.Abs(a.prefix - b.prefix) / 2); + o2.Adjust(o.prefix); + o.bytes -= o2.bytes; + o.Simplify(); + return o; + } + + o = new(a.bytes, a.prefix); + o.Adjust(b.prefix); + o.bytes -= b.bytes; + o.Simplify(); + return o; + } + + public static ByteCount operator +(ByteCount a, ByteCount b) + { + ByteCount o; + ByteCount o2; + + if (Math.Abs(a.prefix - b.prefix) > 3) + { + o = new(a.bytes, a.prefix); + o2 = new(b.bytes, b.prefix); + o.Adjust(Math.Abs(a.prefix - b.prefix) / 2); + o2.Adjust(o.prefix); + o.bytes += o2.bytes; + o.Simplify(); + return o; + } + + o = new(a.bytes, a.prefix); + o.Adjust(b.prefix); + o.bytes += b.bytes; + o.Simplify(); + return o; + } + + public static ByteCount operator +(ByteCount a, int b) + { + ByteCount o = new(a.bytes, a.prefix); + ByteCount o2 = new(b, -1); + o.Adjust((o.prefix + 1) / 2); + o2.Adjust(o.prefix); + o.bytes += o2.bytes; + o.Simplify(); + return o; + } + + public static ByteCount operator +(ByteCount a, uint b) + { + ByteCount o = new(a.bytes, a.prefix); + ByteCount o2 = new(b, -1); + o.Adjust((o.prefix + 1) / 2); + o2.Adjust(o.prefix); + o.bytes += o2.bytes; + o.Simplify(); + return o; + } + + public static ByteCount operator +(ByteCount a, long b) + { + ByteCount o = new(a.bytes, a.prefix); + ByteCount o2 = new(b, -1); + o.Adjust((o.prefix + 1) / 2); + o2.Adjust(o.prefix); + o.bytes += o2.bytes; + o.Simplify(); + return o; + } + + /// + /// Return the size of this byte counter, formatted with the most appropriate metric prefix. This function does not preserve manual adjustments to the counter's magnitude. + /// + /// The byte counter size, in the format "0.0 xB", where 'x' is a metric prefix. + public override string ToString() + { + Simplify(); + if (prefix == -1) + return $"{bytes:N0} B"; + return $"{bytes:N1} {Common.prefixes[prefix]}B"; + } + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 251ac33..3cf0c76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ -# 1.1.3.1 - 03/03/2024 +# 1.1.3.3 - 05/03/2024 +- HTML output now features small character avatars next to each message, as seen in the F-Chat Rising client. These are especially useful for FLogS as they allow easier visual differentiation of profile names. + +# 1.1.3.2 - 03/03/2024 - Fixed a niche error that occurred when 'anchor' tags, such as user and url, mistakenly contain other similar tags. # 1.1.3.1 - 03/03/2024 diff --git a/Common.cs b/Common.cs index 4e0668f..2af10c0 100644 --- a/Common.cs +++ b/Common.cs @@ -4,144 +4,6 @@ namespace FLogS { - struct ByteCount - { - public ByteCount() { bytes = 0.0; prefix = -1; } - public ByteCount(double b, short p) { bytes = b; prefix = p; } - - public double bytes; - public short prefix; - - public void Adjust(int factor, bool absolute = true) - { - if (!absolute) - factor = (short)(prefix - factor); - while (prefix < factor) - Magnitude(-1); - while (prefix > factor) - Magnitude(1); - return; - } - - public void Magnitude(int factor) - { - bytes *= Math.Pow(1024, factor); - prefix -= (short)factor; - } - - public void Simplify() - { - while (bytes >= 921.6 && prefix < Common.prefixes.Length) - Magnitude(-1); - while (bytes < 0.9 && prefix > -1) - Magnitude(1); - return; - } - - public static ByteCount operator -(ByteCount a, ByteCount b) - { - ByteCount o; - ByteCount o2; - - if (Math.Abs(a.prefix - b.prefix) > 3) // Special accommodations must be made if the disparity in magnitude would normally result in an int overflow. - { - o = new(a.bytes, a.prefix); - o2 = new(b.bytes, b.prefix); - o.Adjust(Math.Abs(a.prefix - b.prefix) / 2); - o2.Adjust(o.prefix); - o.bytes -= o2.bytes; - o.Simplify(); - return o; - } - - o = new(a.bytes, a.prefix); - o.Adjust(b.prefix); - o.bytes -= b.bytes; - o.Simplify(); - return o; - } - - public static ByteCount operator +(ByteCount a, ByteCount b) - { - ByteCount o; - ByteCount o2; - - if (Math.Abs(a.prefix - b.prefix) > 3) - { - o = new(a.bytes, a.prefix); - o2 = new(b.bytes, b.prefix); - o.Adjust(Math.Abs(a.prefix - b.prefix) / 2); - o2.Adjust(o.prefix); - o.bytes += o2.bytes; - o.Simplify(); - return o; - } - - o = new(a.bytes, a.prefix); - o.Adjust(b.prefix); - o.bytes += b.bytes; - o.Simplify(); - return o; - } - - public static ByteCount operator +(ByteCount a, int b) - { - ByteCount o = new(a.bytes, a.prefix); - ByteCount o2 = new(b, -1); - o.Adjust((o.prefix + 1) / 2); - o2.Adjust(o.prefix); - o.bytes += o2.bytes; - o.Simplify(); - return o; - } - - public static ByteCount operator +(ByteCount a, uint b) - { - ByteCount o = new(a.bytes, a.prefix); - ByteCount o2 = new(b, -1); - o.Adjust((o.prefix + 1) / 2); - o2.Adjust(o.prefix); - o.bytes += o2.bytes; - o.Simplify(); - return o; - } - - public static ByteCount operator +(ByteCount a, long b) - { - ByteCount o = new(a.bytes, a.prefix); - ByteCount o2 = new(b, -1); - o.Adjust((o.prefix + 1) / 2); - o2.Adjust(o.prefix); - o.bytes += o2.bytes; - o.Simplify(); - return o; - } - - /// - /// Return the size of this byte counter, formatted with the most appropriate metric prefix. This function does not preserve manual adjustments to the counter's magnitude. - /// - /// The byte counter size, in the format "0.0 xB", where 'x' is a metric prefix. - public override string ToString() - { - Simplify(); - if (prefix == -1) - return $"{bytes:N0} B"; - return $"{bytes:N1} {Common.prefixes[prefix]}B"; - } - } - - enum MessageType - { - EOF = -1, - Regular = 0, - Me = 1, - Ad = 2, - DiceRoll = 3, - Warning = 4, - Headless = 5, - Announcement = 6, - } - /// /// Static helper functions serving purely logical purposes in either the front- or backend. /// diff --git a/FLogS.csproj b/FLogS.csproj index 6068ed0..351ef4c 100644 --- a/FLogS.csproj +++ b/FLogS.csproj @@ -7,7 +7,7 @@ true False FLogS - 1.1.3.2 + 1.1.3.3 True none True diff --git a/KNOWN.md b/KNOWN.md index 55d6a19..2ff1ab5 100644 --- a/KNOWN.md +++ b/KNOWN.md @@ -1,3 +1,2 @@ # Known Issues -- Ads are read correctly as they are in later versions, but much older clients didn't record ads as uniquely ID'd messages - they appear to have just been plaintext, with no delimiter. Reading them causes patches of garbage. -- Consider including 10x10 profile avatars in messages as F-Chat Rising does. They're useful for differentiating similar names since we don't/can't color according to gender. \ No newline at end of file +- Ads are read correctly as they are in later versions, but much older clients didn't record ads as uniquely ID'd messages - they appear to have just been plaintext, with no delimiter. Reading them causes patches of garbage. \ No newline at end of file diff --git a/MainWindow.xaml b/MainWindow.xaml index e7ff682..d4579d5 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -94,7 +94,7 @@ -