Skip to content

Commit

Permalink
1.1.3.3 Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Taicanium committed Mar 6, 2024
1 parent 45e12f6 commit 44247f4
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 157 deletions.
130 changes: 130 additions & 0 deletions ByteCount.cs
Original file line number Diff line number Diff line change
@@ -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;
}

/// <summary>
/// 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.
/// </summary>
/// <returns>The byte counter size, in the format "0.0 xB", where 'x' is a metric prefix.</returns>
public override string ToString()
{
Simplify();
if (prefix == -1)
return $"{bytes:N0} B";
return $"{bytes:N1} {Common.prefixes[prefix]}B";
}
}
}
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
138 changes: 0 additions & 138 deletions Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
/// 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.
/// </summary>
/// <returns>The byte counter size, in the format "0.0 xB", where 'x' is a metric prefix.</returns>
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,
}

/// <summary>
/// Static helper functions serving purely logical purposes in either the front- or backend.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion FLogS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<UseWPF>true</UseWPF>
<SignAssembly>False</SignAssembly>
<Title>FLogS</Title>
<Version>1.1.3.2</Version>
<Version>1.1.3.3</Version>
<IncludeSymbols>True</IncludeSymbols>
<ErrorReport>none</ErrorReport>
<UseWindowsForms>True</UseWindowsForms>
Expand Down
3 changes: 1 addition & 2 deletions KNOWN.md
Original file line number Diff line number Diff line change
@@ -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.
- 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.
8 changes: 4 additions & 4 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<ProgressBar x:Name="FileProgress" Width="600" Height="25" HorizontalAlignment="Center" Minimum="0" Maximum="100"/>
</StackPanel>
</Grid>
<Label x:Name="FileVersionNumber" Content="FLogS — Version 1.1.3.2 © Taica, 2024" HorizontalAlignment="Right" FontStyle="Italic" Margin="10,30" FontWeight="Thin"/>
<Label x:Name="FileVersionNumber" Content="FLogS — Version 1.1.3.3 © Taica, 2024" HorizontalAlignment="Right" FontStyle="Italic" Margin="10,30" FontWeight="Thin"/>
</StackPanel>
</Grid>
</Grid>
Expand Down Expand Up @@ -184,7 +184,7 @@
<ProgressBar x:Name="DirectoryProgress" Width="600" Height="25" HorizontalAlignment="Center" Minimum="0" Maximum="100"/>
</StackPanel>
</Grid>
<Label x:Name="DirectoryVersionNumber" Content="FLogS — Version 1.1.3.2 © Taica, 2024" HorizontalAlignment="Right" FontStyle="Italic" Margin="10,30" FontWeight="Thin"/>
<Label x:Name="DirectoryVersionNumber" Content="FLogS — Version 1.1.3.3 © Taica, 2024" HorizontalAlignment="Right" FontStyle="Italic" Margin="10,30" FontWeight="Thin"/>
</StackPanel>
</Grid>
</Grid>
Expand Down Expand Up @@ -279,7 +279,7 @@
<ProgressBar x:Name="PhraseProgress" Width="600" Height="25" HorizontalAlignment="Center" Minimum="0" Maximum="100"/>
</StackPanel>
</Grid>
<Label x:Name="PhraseVersionNumber" Content="FLogS — Version 1.1.3.2 © Taica, 2024" HorizontalAlignment="Right" FontStyle="Italic" Margin="10,30" FontWeight="Thin"/>
<Label x:Name="PhraseVersionNumber" Content="FLogS — Version 1.1.3.3 © Taica, 2024" HorizontalAlignment="Right" FontStyle="Italic" Margin="10,30" FontWeight="Thin"/>
</StackPanel>
</Grid>
</Grid>
Expand Down Expand Up @@ -335,7 +335,7 @@
</Grid>
<Grid Grid.Row="1" Grid.Column="1" VerticalAlignment="Bottom" Margin="2,2">
<StackPanel Background="LightGray" Margin="2,2">
<Label x:Name="HelpVersionNumber" Content="FLogS — Version 1.1.3.2 © Taica, 2024" HorizontalAlignment="Right" FontStyle="Italic" Margin="10,3" FontWeight="Thin"/>
<Label x:Name="HelpVersionNumber" Content="FLogS — Version 1.1.3.3 © Taica, 2024" HorizontalAlignment="Right" FontStyle="Italic" Margin="10,3" FontWeight="Thin"/>
</StackPanel>
</Grid>
</Grid>
Expand Down
Loading

0 comments on commit 44247f4

Please sign in to comment.