mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2025-06-10 12:22:16 +03:00
Fix negative numbers & exception with very large numbers in attachment size limit
This commit is contained in:
parent
053ab5b091
commit
9ae5ece24b
@ -9,7 +9,7 @@ using DHT.Utils.Tasks;
|
|||||||
|
|
||||||
namespace DHT.Desktop.Main.Controls {
|
namespace DHT.Desktop.Main.Controls {
|
||||||
sealed class AttachmentFilterPanelModel : BaseModel, IDisposable {
|
sealed class AttachmentFilterPanelModel : BaseModel, IDisposable {
|
||||||
public sealed record Unit(string Name, int Scale);
|
public sealed record Unit(string Name, uint Scale);
|
||||||
|
|
||||||
private static readonly Unit[] AllUnits = {
|
private static readonly Unit[] AllUnits = {
|
||||||
new ("B", 1),
|
new ("B", 1),
|
||||||
@ -26,7 +26,7 @@ namespace DHT.Desktop.Main.Controls {
|
|||||||
public string FilterStatisticsText { get; private set; } = "";
|
public string FilterStatisticsText { get; private set; } = "";
|
||||||
|
|
||||||
private bool limitSize = false;
|
private bool limitSize = false;
|
||||||
private int maximumSize = 0;
|
private ulong maximumSize = 0L;
|
||||||
private Unit maximumSizeUnit = AllUnits[0];
|
private Unit maximumSizeUnit = AllUnits[0];
|
||||||
|
|
||||||
public bool LimitSize {
|
public bool LimitSize {
|
||||||
@ -34,7 +34,7 @@ namespace DHT.Desktop.Main.Controls {
|
|||||||
set => Change(ref limitSize, value);
|
set => Change(ref limitSize, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int MaximumSize {
|
public ulong MaximumSize {
|
||||||
get => maximumSize;
|
get => maximumSize;
|
||||||
set => Change(ref maximumSize, value);
|
set => Change(ref maximumSize, value);
|
||||||
}
|
}
|
||||||
@ -116,7 +116,11 @@ namespace DHT.Desktop.Main.Controls {
|
|||||||
AttachmentFilter filter = new();
|
AttachmentFilter filter = new();
|
||||||
|
|
||||||
if (LimitSize) {
|
if (LimitSize) {
|
||||||
filter.MaxBytes = maximumSize * maximumSizeUnit.Scale;
|
try {
|
||||||
|
filter.MaxBytes = maximumSize * maximumSizeUnit.Scale;
|
||||||
|
} catch (ArithmeticException) {
|
||||||
|
// set no size limit, because the overflown size is larger than any file could possibly be
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return filter;
|
return filter;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace DHT.Server.Data.Filters {
|
namespace DHT.Server.Data.Filters {
|
||||||
public sealed class AttachmentFilter {
|
public sealed class AttachmentFilter {
|
||||||
public long? MaxBytes { get; set; } = null;
|
public ulong? MaxBytes { get; set; } = null;
|
||||||
|
|
||||||
public DownloadItemRules? DownloadItemRule { get; set; } = null;
|
public DownloadItemRules? DownloadItemRule { get; set; } = null;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user