protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var prefs = await client.GetPreferencesAsync();

                        var  currentTrackers = prefs.AdditinalTrackers ?? new List <string>();
                        bool modified        = false;

                        foreach (var tracker in Trackers)
                        {
                            if (!currentTrackers.Contains(tracker))
                            {
                                currentTrackers.Add(tracker);
                                modified = true;
                            }
                        }

                        if (modified)
                        {
                            prefs = new Preferences {
                                AdditinalTrackers = currentTrackers
                            };
                            await client.SetPreferencesAsync(prefs);
                        }

                        return(ExitCodes.Success);
                    }
                        protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                        {
                            var prefs = await client.GetPreferencesAsync();

                            var currentNetworks = (prefs.BypassAuthenticationSubnetWhitelist ?? Enumerable.Empty <string>())
                                                  .Select(IPNetwork.Parse)
                                                  .ToHashSet();
                            bool modified = false;

                            foreach (var network in Networks.Select(IPNetwork.Parse))
                            {
                                if (!currentNetworks.Contains(network))
                                {
                                    currentNetworks.Add(network);
                                    modified = true;
                                }
                            }

                            if (modified)
                            {
                                prefs = new Preferences
                                {
                                    BypassAuthenticationSubnetWhitelist = currentNetworks.Select(n => n.ToString()).ToList()
                                };
                                await client.SetPreferencesAsync(prefs);
                            }

                            return(ExitCodes.Success);
                        }
Exemple #3
0
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var prefs = await client.GetPreferencesAsync();

                        var  banList  = prefs.BannedIpAddresses ?? new List <string>();
                        bool modified = false;

                        foreach (var address in Addresses)
                        {
                            if (!banList.Contains(address))
                            {
                                banList.Add(address);
                                modified = true;
                            }
                        }

                        if (modified)
                        {
                            prefs = new Preferences {
                                BannedIpAddresses = banList
                            };
                            await client.SetPreferencesAsync(prefs);
                        }

                        return(ExitCodes.Success);
                    }
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var preferences = await client.GetPreferencesAsync();

                        var folders = preferences.ScanDirectories ?? new Dictionary <string, SaveLocation>();

                        Print(folders);
                        return(ExitCodes.Success);
                    }
Exemple #5
0
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var prefs = await client.GetPreferencesAsync();

                        foreach (var address in prefs.BannedIpAddresses ?? Enumerable.Empty <string>())
                        {
                            console.WriteLineColored(address, ColorScheme.Current.Normal);
                        }
                        return(ExitCodes.Success);
                    }
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var prefs = await client.GetPreferencesAsync();

                        var dirs = prefs?.ScanDirectories ?? new Dictionary <string, SaveLocation>();

                        dirs.Remove(Folder);
                        prefs = new Preferences {
                            ScanDirectories = dirs
                        };
                        await client.SetPreferencesAsync(prefs);

                        return(ExitCodes.Success);
                    }
                        protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                        {
                            var prefs = await client.GetPreferencesAsync();

                            if (prefs.BypassAuthenticationSubnetWhitelist != null)
                            {
                                foreach (var network in prefs.BypassAuthenticationSubnetWhitelist ?? Enumerable.Empty <string>())
                                {
                                    console.WriteLine(network);
                                }
                            }

                            return(ExitCodes.Success);
                        }
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var saveLocation = GetSaveLocation();
                        var prefs        = await client.GetPreferencesAsync();

                        var dirs = prefs?.ScanDirectories ?? new Dictionary <string, SaveLocation>();

                        dirs[Folder] = saveLocation;
                        prefs        = new Preferences {
                            ScanDirectories = dirs
                        };
                        await client.SetPreferencesAsync(prefs);

                        return(ExitCodes.Success);

                        SaveLocation GetSaveLocation()
                        {
                            if (SaveToDefault && SaveToMonitoredFolder)
                            {
                                throw new InvalidOperationException("Only single of the options --save-to-default or --save-to-monitored can be used simultaneously.");
                            }
                            if (SaveToDefault && SaveToCustom)
                            {
                                throw new InvalidOperationException("Only single of the options --save-to-default or --save-to can be used simultaneously.");
                            }
                            if (SaveToCustom && SaveToMonitoredFolder)
                            {
                                throw new InvalidOperationException("Only single of the options --save-to or --save-to-monitored can be used simultaneously.");
                            }

                            if (SaveToCustom)
                            {
                                return(new SaveLocation(SaveTo));
                            }
                            if (SaveToMonitoredFolder)
                            {
                                return(new SaveLocation(StandardSaveLocation.MonitoredFolder));
                            }
                            return(new SaveLocation(StandardSaveLocation.Default));
                        }
                    }
            protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var partialData = await client.GetPartialDataAsync();

                if (!partialData.TorrentsChanged.TryGetValue(Hash, out var info))
                {
                    console.WriteLineColored($"No torrent matching hash {Hash} is found.", ColorScheme.Current.Warning);
                    return(ExitCodes.NotFound);
                }

                var ratioLimit       = GetRatioLimit();
                var seedingTimeLimit = GetSeedingTimeLimit();

                if (ratioLimit != null || seedingTimeLimit != null)
                {
                    await client.SetShareLimitsAsync(Hash,
                                                     ratioLimit ?? info.RatioLimit ?? ShareLimits.Ratio.Global,
                                                     seedingTimeLimit ?? info.SeedingTimeLimit ?? ShareLimits.SeedingTime.Global);

                    return(ExitCodes.Success);
                }

                var(properties, global) = await TaskHelper.WhenAll(
                    client.GetTorrentPropertiesAsync(Hash),
                    client.GetPreferencesAsync());

                var viewModel = new TorrentShareViewModel(properties, info);

                _customFormatters = new Dictionary <string, Func <object, object> >
                {
                    [nameof(viewModel.RatioLimit)]       = FormatRatioLimit,
                    [nameof(viewModel.SeedingTimeLimit)] = FormatSeedingTimeLimit
                };
                Print(viewModel);

                return(ExitCodes.Success);

                object FormatRatioLimit(object arg)
                {
                    switch (arg)
                    {
                    case double value when Math.Abs(value - ShareLimits.Ratio.Global) < 0.0001:
                        var globalValue = global.MaxRatio >= 0 ? global.MaxRatio.Value.ToString("F3") : "None";

                        return($"Global ({globalValue})");

                    case double value when Math.Abs(value - ShareLimits.Ratio.Unlimited) < 0.0001:
                        return("None");

                    case double value:
                        return(value.ToString("F3"));

                    default:
                        return(null);
                    }
                }

                object FormatSeedingTimeLimit(object arg)
                {
                    var time = arg as TimeSpan?;

                    if (time == ShareLimits.SeedingTime.Global)
                    {
                        var globalValue = global.MaxSeedingTime >= 0 ? global.MaxSeedingTime.Value.ToString() : "None";
                        return($"Global ({globalValue})");
                    }

                    return(time == ShareLimits.SeedingTime.Unlimited ? "None" : time?.ToString());
                }
            }
                protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    await Prepare(client, app, console);

                    var props =
                        (from prop in GetType().GetTypeInfo().DeclaredProperties
                         let option = prop.GetCustomAttribute <OptionAttribute>()
                                      where option != null
                                      where prop.GetCustomAttribute <IgnoreAttribute>() == null
                                      let value = prop.GetValue(this)
                                                  where value != null && (option.OptionType != CommandOptionType.NoValue || !false.Equals(value))
                                                  let autoSet = prop.GetCustomAttribute <NoAutoSetAttribute>() == null
                                                                let minApiVersion = prop.GetCustomAttribute <MinApiVersionAttribute>()
                                                                                    let maxApiVersion = prop.GetCustomAttribute <MaxApiVersionAttribute>()
                                                                                                        select(prop.Name, value, autoSet, minApiVersion, maxApiVersion))
                        .ToList();

                    var minVersionProps = props
                                          .Where(p => p.minApiVersion != null)
                                          .ToLookup(
                        p => (p.minApiVersion.MinVersion, p.minApiVersion.Message),
                        p => p.value);

                    foreach (var pair in minVersionProps)
                    {
                        var(minVersion, message) = pair.Key;
                        var values = pair.ToArray();
                        await WarnIfNotSupported(client, console, minVersion, message, false, values);
                    }

                    var maxVersionProps = props
                                          .Where(p => p.maxApiVersion != null)
                                          .ToLookup(
                        p => (MaxVersion: p.maxApiVersion.MaxVersionExclusive, p.maxApiVersion.Message),
                        p => p.value);

                    foreach (var pair in maxVersionProps)
                    {
                        var(maxVersion, message) = pair.Key;
                        var values = pair.ToArray();
                        await WarnIfNotSupported(client, console, maxVersion, message, true, values);
                    }

                    if (props.Any())
                    {
                        var prefs = new Preferences();
                        foreach (var prop in props.Where(p => p.autoSet))
                        {
                            typeof(Preferences).GetProperty(prop.Name).SetValue(prefs, prop.value);
                        }

                        CustomFillPreferences(prefs);
                        await client.SetPreferencesAsync(prefs);
                    }
                    else
                    {
                        var prefs = await client.GetPreferencesAsync();

                        PrintPreferences(client, prefs);
                    }

                    return(ExitCodes.Success);
                }