fixed maxParallel downloads default value not being automatically selected at first boot

This commit is contained in:
2024-05-09 22:17:53 +03:00
parent 9525394a6e
commit dc787ac130

View File

@@ -2,12 +2,15 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using DiscordBot.Utilities; using DiscordBot.Utilities;
using PluginManager; using PluginManager;
using PluginManager.Interfaces; using PluginManager.Interfaces;
using PluginManager.Loaders; using PluginManager.Loaders;
using PluginManager.Online; using PluginManager.Online;
using PluginManager.Others; using PluginManager.Others;
using Spectre.Console; using Spectre.Console;
namespace DiscordBot.Bot.Actions.Extra; namespace DiscordBot.Bot.Actions.Extra;
@@ -109,17 +112,15 @@ internal static class PluginMethods
downloadTasks.Add(new Tuple<ProgressTask, IProgress<float>, string, string>(task, progress, dependency.DownloadLink, dependency.DownloadLocation)); downloadTasks.Add(new Tuple<ProgressTask, IProgress<float>, string, string>(task, progress, dependency.DownloadLink, dependency.DownloadLocation));
} }
if (!int.TryParse(Config.AppSettings["MaxParallelDownloads"], out var maxParallelDownloads)) int maxParallelDownloads = 5;
{
maxParallelDownloads = 5; if (Config.AppSettings.ContainsKey("MaxParallelDownloads"))
Config.AppSettings.Add("MaxParallelDownloads", "5"); maxParallelDownloads = int.Parse(Config.AppSettings["MaxParallelDownloads"]);
await Config.AppSettings.SaveToFile();
}
var options = new ParallelOptions() var options = new ParallelOptions()
{ {
MaxDegreeOfParallelism = maxParallelDownloads, MaxDegreeOfParallelism = maxParallelDownloads,
TaskScheduler = TaskScheduler.Default TaskScheduler = TaskScheduler.Default
}; };
await Parallel.ForEachAsync(downloadTasks, options, async (tuple, token) => await Parallel.ForEachAsync(downloadTasks, options, async (tuple, token) =>
@@ -202,7 +203,7 @@ internal static class PluginMethods
Console.ForegroundColor = cc; Console.ForegroundColor = cc;
}; };
await loader. LoadPlugins(); await loader.LoadPlugins();
Console.ForegroundColor = cc; Console.ForegroundColor = cc;
return true; return true;
} }