mirror of
https://github.com/lantean-code/qbtmud.git
synced 2025-10-22 20:42:24 +00:00
Remove other v4 logic
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
<MudNumericField T="int" Label="Ignore Subsequent Matches for (0 to Disable)" Value="IgnoreDays" ValueChanged="IgnoreDaysChanged" Disabled="@(SelectedRuleName is null)" Variant="Variant.Outlined" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudSelect T="string" Label="Add paused" Value="AddPaused" ValueChanged="AddPausedChanged" Disabled="@(SelectedRuleName is null)" Variant="Variant.Outlined">
|
||||
<MudSelect T="string" Label="Add stopped" Value="AddStopped" ValueChanged="AddStoppedChanged" Disabled="@(SelectedRuleName is null)" Variant="Variant.Outlined">
|
||||
<MudSelectItem Value="@("default")">Use global settings</MudSelectItem>
|
||||
<MudSelectItem Value="@("always")">Always</MudSelectItem>
|
||||
<MudSelectItem Value="@("never")">Never</MudSelectItem>
|
||||
@@ -103,4 +103,4 @@
|
||||
<MudButton OnClick="Cancel">Close</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="Submit">Save</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
</MudDialog>
|
||||
|
@@ -114,11 +114,11 @@ namespace Lantean.QBTMud.Components.Dialogs
|
||||
SelectedRule.IgnoreDays = value;
|
||||
}
|
||||
|
||||
protected string? AddPaused { get; set; }
|
||||
protected string? AddStopped { get; set; }
|
||||
|
||||
protected void AddPausedChanged(string value)
|
||||
protected void AddStoppedChanged(string value)
|
||||
{
|
||||
AddPaused = value;
|
||||
AddStopped = value;
|
||||
switch (value)
|
||||
{
|
||||
case "default":
|
||||
@@ -273,15 +273,15 @@ namespace Lantean.QBTMud.Components.Dialogs
|
||||
switch (SelectedRule.TorrentParams.Stopped)
|
||||
{
|
||||
case null:
|
||||
AddPaused = "default";
|
||||
AddStopped = "default";
|
||||
break;
|
||||
|
||||
case true:
|
||||
AddPaused = "always";
|
||||
AddStopped = "always";
|
||||
break;
|
||||
|
||||
case false:
|
||||
AddPaused = "never";
|
||||
AddStopped = "never";
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -66,8 +66,8 @@
|
||||
return __builder =>
|
||||
{
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.PlayArrow" IconColor="Color.Success" OnClick="@(e => StartTorrents(type))">Start torrents</MudMenuItem>
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.Pause" IconColor="Color.Warning" OnClick="@(e => StopTorrents(type))">Stop torrents</MudMenuItem>
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.Stop" IconColor="Color.Warning" OnClick="@(e => StopTorrents(type))">Stop torrents</MudMenuItem>
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.Delete" IconColor="Color.Error" OnClick="@(e => RemoveTorrents(type))">Remove torrents</MudMenuItem>
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -38,9 +38,6 @@ namespace Lantean.QBTMud.Components
|
||||
[Inject]
|
||||
protected IKeyboardService KeyboardService { get; set; } = default!;
|
||||
|
||||
[CascadingParameter(Name = "Version")]
|
||||
public string? Version { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
public IEnumerable<string> Hashes { get; set; } = default!;
|
||||
@@ -72,8 +69,6 @@ namespace Lantean.QBTMud.Components
|
||||
|
||||
protected bool OverlayVisible { get; set; }
|
||||
|
||||
protected int MajorVersion => VersionHelper.GetMajorVersion(Version);
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_actions =
|
||||
@@ -150,13 +145,13 @@ namespace Lantean.QBTMud.Components
|
||||
protected async Task Stop()
|
||||
{
|
||||
await ApiClient.StopTorrents(hashes: Hashes.ToArray());
|
||||
Snackbar.Add(MajorVersion < 5 ? "Torrent paused." : "Torrent stopped.");
|
||||
Snackbar.Add("Torrent stopped.");
|
||||
}
|
||||
|
||||
protected async Task Start()
|
||||
{
|
||||
await ApiClient.StartTorrents(hashes: Hashes.ToArray());
|
||||
Snackbar.Add(MajorVersion < 5 ? "Torrent resumed." : "Torrent started.");
|
||||
Snackbar.Add("Torrent started.");
|
||||
}
|
||||
|
||||
protected async Task ForceStart()
|
||||
@@ -370,8 +365,8 @@ namespace Lantean.QBTMud.Components
|
||||
var allAreFirstLastPiecePrio = true;
|
||||
var thereAreFirstLastPiecePrio = false;
|
||||
var allAreDownloaded = true;
|
||||
var allArePaused = true;
|
||||
var thereArePaused = false;
|
||||
var allAreStopped = true;
|
||||
var thereAreStopped = false;
|
||||
var allAreForceStart = true;
|
||||
var thereAreForceStart = false;
|
||||
var allAreSuperSeeding = true;
|
||||
@@ -409,27 +404,13 @@ namespace Lantean.QBTMud.Components
|
||||
allAreSuperSeeding = false;
|
||||
}
|
||||
|
||||
if (MajorVersion < 5)
|
||||
if (torrent.State != "stoppedUP" && torrent.State != "stoppedDL")
|
||||
{
|
||||
if (torrent.State != "pausedUP" && torrent.State != "pausedDL")
|
||||
{
|
||||
allArePaused = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
thereArePaused = true;
|
||||
}
|
||||
allAreStopped = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (torrent.State != "stoppedUP" && torrent.State != "stoppedDL")
|
||||
{
|
||||
allArePaused = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
thereArePaused = true;
|
||||
}
|
||||
thereAreStopped = true;
|
||||
}
|
||||
|
||||
if (!torrent.ForceStart)
|
||||
@@ -517,7 +498,7 @@ namespace Lantean.QBTMud.Components
|
||||
actionStates["superSeeding"] = ActionState.Hidden;
|
||||
}
|
||||
|
||||
if (allArePaused)
|
||||
if (allAreStopped)
|
||||
{
|
||||
actionStates["pause"] = ActionState.Hidden;
|
||||
}
|
||||
@@ -525,13 +506,11 @@ namespace Lantean.QBTMud.Components
|
||||
{
|
||||
actionStates["forceStart"] = ActionState.Hidden;
|
||||
}
|
||||
else if (!thereArePaused && !thereAreForceStart)
|
||||
else if (!thereAreStopped && !thereAreForceStart)
|
||||
{
|
||||
actionStates["start"] = ActionState.Hidden;
|
||||
}
|
||||
|
||||
if (MajorVersion >= 5)
|
||||
{
|
||||
if (actionStates.TryGetValue("start", out ActionState? startActionState))
|
||||
{
|
||||
startActionState.TextOverride = "Start";
|
||||
@@ -549,7 +528,6 @@ namespace Lantean.QBTMud.Components
|
||||
{
|
||||
actionStates["pause"] = new ActionState { TextOverride = "Stop" };
|
||||
}
|
||||
}
|
||||
|
||||
if (!allAreAutoTmm && thereAreAutoTmm)
|
||||
{
|
||||
|
@@ -404,8 +404,6 @@ namespace Lantean.QBTMud.Helpers
|
||||
Status.Downloading => (Icons.Material.Filled.Downloading, Color.Success),
|
||||
Status.Seeding => (Icons.Material.Filled.Upload, Color.Info),
|
||||
Status.Completed => (Icons.Material.Filled.Check, Color.Default),
|
||||
Status.Resumed => (Icons.Material.Filled.PlayArrow, Color.Success),
|
||||
Status.Paused => (Icons.Material.Filled.Pause, Color.Default),
|
||||
Status.Stopped => (Icons.Material.Filled.Stop, Color.Default),
|
||||
Status.Active => (Icons.Material.Filled.Sort, Color.Success),
|
||||
Status.Inactive => (Icons.Material.Filled.Sort, Color.Error),
|
||||
@@ -418,4 +416,4 @@ namespace Lantean.QBTMud.Helpers
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -200,15 +200,8 @@ namespace Lantean.QBTMud.Helpers
|
||||
|
||||
break;
|
||||
|
||||
case Status.Resumed:
|
||||
if (!state.Contains("resumed"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case Status.Paused:
|
||||
if (!state.Contains("paused") && !state.Contains("stopped"))
|
||||
case Status.Stopped:
|
||||
if (state != "stoppedDL" && state != "stoppedUP")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -285,4 +278,4 @@ namespace Lantean.QBTMud.Helpers
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,33 +0,0 @@
|
||||
namespace Lantean.QBTMud.Helpers
|
||||
{
|
||||
internal static class VersionHelper
|
||||
{
|
||||
private static int? _version;
|
||||
|
||||
private const int _defaultVersion = 5;
|
||||
|
||||
public static int DefaultVersion => _defaultVersion;
|
||||
|
||||
public static int GetMajorVersion(string? version)
|
||||
{
|
||||
if (_version is not null)
|
||||
{
|
||||
return _version.Value;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(version))
|
||||
{
|
||||
return _defaultVersion;
|
||||
}
|
||||
|
||||
if (!Version.TryParse(version?.Replace("v", ""), out var theVersion))
|
||||
{
|
||||
return _defaultVersion;
|
||||
}
|
||||
|
||||
_version = theVersion.Major;
|
||||
|
||||
return _version.Value;
|
||||
}
|
||||
}
|
||||
}
|
@@ -97,7 +97,7 @@ namespace Lantean.QBTMud.Layout
|
||||
Preferences = await ApiClient.GetApplicationPreferences();
|
||||
Version = await ApiClient.GetApplicationVersion();
|
||||
var data = await ApiClient.GetMainData(_requestId);
|
||||
MainData = DataManager.CreateMainData(data, Version);
|
||||
MainData = DataManager.CreateMainData(data);
|
||||
MarkTorrentsDirty();
|
||||
|
||||
_requestId = data.ResponseId;
|
||||
@@ -145,7 +145,7 @@ namespace Lantean.QBTMud.Layout
|
||||
|
||||
if (MainData is null || data.FullUpdate)
|
||||
{
|
||||
MainData = DataManager.CreateMainData(data, Version);
|
||||
MainData = DataManager.CreateMainData(data);
|
||||
MarkTorrentsDirty();
|
||||
shouldRender = true;
|
||||
}
|
||||
@@ -291,4 +291,4 @@ namespace Lantean.QBTMud.Layout
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,8 +11,7 @@
|
||||
Dictionary<string, HashSet<string>> tagState,
|
||||
Dictionary<string, HashSet<string>> categoriesState,
|
||||
Dictionary<string, HashSet<string>> statusState,
|
||||
Dictionary<string, HashSet<string>> trackersState,
|
||||
int majorVersion)
|
||||
Dictionary<string, HashSet<string>> trackersState)
|
||||
{
|
||||
Torrents = torrents.ToDictionary();
|
||||
Tags = tags.ToHashSet();
|
||||
@@ -23,7 +22,6 @@
|
||||
CategoriesState = categoriesState;
|
||||
StatusState = statusState;
|
||||
TrackersState = trackersState;
|
||||
MajorVersion = majorVersion;
|
||||
}
|
||||
|
||||
public Dictionary<string, Torrent> Torrents { get; }
|
||||
@@ -38,6 +36,5 @@
|
||||
public Dictionary<string, HashSet<string>> TrackersState { get; }
|
||||
public string? SelectedTorrentHash { get; set; }
|
||||
public bool LostConnection { get; set; }
|
||||
public int MajorVersion { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@
|
||||
Downloading,
|
||||
Seeding,
|
||||
Completed,
|
||||
Resumed,
|
||||
Paused,
|
||||
Stopped,
|
||||
Active,
|
||||
@@ -17,4 +16,4 @@
|
||||
Checking,
|
||||
Errored,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,9 +25,8 @@ namespace Lantean.QBTMud.Services
|
||||
return peerList;
|
||||
}
|
||||
|
||||
public MainData CreateMainData(QBitTorrentClient.Models.MainData mainData, string version)
|
||||
public MainData CreateMainData(QBitTorrentClient.Models.MainData mainData)
|
||||
{
|
||||
var majorVersion = VersionHelper.GetMajorVersion(version);
|
||||
var torrents = new Dictionary<string, Torrent>(mainData.Torrents?.Count ?? 0);
|
||||
if (mainData.Torrents is not null)
|
||||
{
|
||||
@@ -95,7 +94,7 @@ namespace Lantean.QBTMud.Services
|
||||
categoriesState.Add(category, torrents.Values.Where(t => FilterHelper.FilterCategory(t, category, serverState.UseSubcategories)).ToHashesHashSet());
|
||||
}
|
||||
|
||||
var statuses = GetStatuses(majorVersion).ToArray();
|
||||
var statuses = GetStatuses().ToArray();
|
||||
var statusState = new Dictionary<string, HashSet<string>>(statuses.Length + 2);
|
||||
foreach (var status in statuses)
|
||||
{
|
||||
@@ -110,7 +109,7 @@ namespace Lantean.QBTMud.Services
|
||||
trackersState.Add(tracker, torrents.Values.Where(t => FilterHelper.FilterTracker(t, tracker)).ToHashesHashSet());
|
||||
}
|
||||
|
||||
var torrentList = new MainData(torrents, tags, categories, trackers, serverState, tagState, categoriesState, statusState, trackersState, majorVersion);
|
||||
var torrentList = new MainData(torrents, tags, categories, trackers, serverState, tagState, categoriesState, statusState, trackersState);
|
||||
|
||||
return torrentList;
|
||||
}
|
||||
@@ -284,7 +283,7 @@ namespace Lantean.QBTMud.Services
|
||||
{
|
||||
var newTorrent = CreateTorrent(hash, torrent);
|
||||
torrentList.Torrents.Add(hash, newTorrent);
|
||||
AddTorrentToStates(torrentList, hash, torrentList.MajorVersion);
|
||||
AddTorrentToStates(torrentList, hash);
|
||||
dataChanged = true;
|
||||
filterChanged = true;
|
||||
}
|
||||
@@ -316,7 +315,7 @@ namespace Lantean.QBTMud.Services
|
||||
return dataChanged;
|
||||
}
|
||||
|
||||
private static void AddTorrentToStates(MainData torrentList, string hash, int version)
|
||||
private static void AddTorrentToStates(MainData torrentList, string hash)
|
||||
{
|
||||
if (!torrentList.Torrents.TryGetValue(hash, out var torrent))
|
||||
{
|
||||
@@ -329,7 +328,7 @@ namespace Lantean.QBTMud.Services
|
||||
torrentList.CategoriesState[FilterHelper.CATEGORY_ALL].Add(hash);
|
||||
UpdateCategoryState(torrentList, torrent, hash, previousCategory: null);
|
||||
|
||||
foreach (var status in GetStatuses(version))
|
||||
foreach (var status in GetStatuses())
|
||||
{
|
||||
if (!torrentList.StatusState.TryGetValue(status.ToString(), out var statusSet))
|
||||
{
|
||||
@@ -346,21 +345,16 @@ namespace Lantean.QBTMud.Services
|
||||
UpdateTrackerState(torrentList, torrent, hash, previousTracker: null);
|
||||
}
|
||||
|
||||
private static Status[] GetStatuses(int version)
|
||||
private static Status[] GetStatuses()
|
||||
{
|
||||
if (_statusArray is not null)
|
||||
{
|
||||
return _statusArray;
|
||||
}
|
||||
|
||||
if (version == 5)
|
||||
{
|
||||
_statusArray = Enum.GetValues<Status>().Where(s => s != Status.Paused).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
_statusArray = Enum.GetValues<Status>().Where(s => s != Status.Stopped).ToArray();
|
||||
}
|
||||
_statusArray = Enum.GetValues<Status>()
|
||||
.Where(s => s != Status.Paused)
|
||||
.ToArray();
|
||||
|
||||
return _statusArray;
|
||||
}
|
||||
@@ -388,7 +382,7 @@ namespace Lantean.QBTMud.Services
|
||||
torrentList.CategoriesState[FilterHelper.CATEGORY_ALL].Remove(hash);
|
||||
UpdateCategoryStateForRemoval(torrentList, hash, snapshot.Category);
|
||||
|
||||
foreach (var status in GetStatuses(torrentList.MajorVersion))
|
||||
foreach (var status in GetStatuses())
|
||||
{
|
||||
if (!torrentList.StatusState.TryGetValue(status.ToString(), out var statusState))
|
||||
{
|
||||
@@ -852,7 +846,7 @@ namespace Lantean.QBTMud.Services
|
||||
|
||||
private static void UpdateStatusState(MainData torrentList, string hash, string previousState, long previousUploadSpeed, string newState, long newUploadSpeed)
|
||||
{
|
||||
foreach (var status in GetStatuses(torrentList.MajorVersion))
|
||||
foreach (var status in GetStatuses())
|
||||
{
|
||||
if (!torrentList.StatusState.TryGetValue(status.ToString(), out var statusSet))
|
||||
{
|
||||
|
@@ -4,7 +4,7 @@ namespace Lantean.QBTMud.Services
|
||||
{
|
||||
public interface IDataManager
|
||||
{
|
||||
MainData CreateMainData(QBitTorrentClient.Models.MainData mainData, string version);
|
||||
MainData CreateMainData(QBitTorrentClient.Models.MainData mainData);
|
||||
|
||||
Torrent CreateTorrent(string hash, QBitTorrentClient.Models.Torrent torrent);
|
||||
|
||||
@@ -22,4 +22,4 @@ namespace Lantean.QBTMud.Services
|
||||
|
||||
RssList CreateRssList(IReadOnlyDictionary<string, QBitTorrentClient.Models.RssItem> rssItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user