Fix bug where DD would exit prematurely

pull/19/head
Netshroud 9 years ago
parent ab9ca2a7da
commit b17e343d0e

@ -3,12 +3,10 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Sockets;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using SteamKit2; using SteamKit2;
using System.Collections.Concurrent;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DepotDownloader namespace DepotDownloader
@ -442,7 +440,7 @@ namespace DepotDownloader
foreach (var depot in depotIDs) foreach (var depot in depotIDs)
{ {
DepotDownloadInfo info = GetDepotInfo(depot, appId, branch); var info = GetDepotInfo(depot, appId, branch);
if (info != null) if (info != null)
{ {
infos.Add(info); infos.Add(info);
@ -678,10 +676,15 @@ namespace DepotDownloader
}); });
var semaphore = new SemaphoreSlim(Config.MaxDownloads); var semaphore = new SemaphoreSlim(Config.MaxDownloads);
filesAfterExclusions.Where(f => !f.Flags.HasFlag(EDepotFileFlag.Directory)) var files = filesAfterExclusions.Where(f => !f.Flags.HasFlag(EDepotFileFlag.Directory)).ToArray();
.AsParallel().WithCancellation(cts.Token).WithDegreeOfParallelism(Config.MaxDownloads) var tasks = new Task[files.Length];
.ForAll(async file => for (var i = 0; i < files.Length; i++)
{ {
var file = files[i];
var task = Task.Run(async () =>
{
cts.Token.ThrowIfCancellationRequested();
try try
{ {
await semaphore.WaitAsync().ConfigureAwait(false); await semaphore.WaitAsync().ConfigureAwait(false);
@ -883,6 +886,11 @@ namespace DepotDownloader
} }
}); });
tasks[i] = task;
}
await Task.WhenAll(tasks).ConfigureAwait(false);;
ConfigStore.TheConfig.LastManifests[depot.id] = depot.manifestId; ConfigStore.TheConfig.LastManifests[depot.id] = depot.manifestId;
ConfigStore.Save(); ConfigStore.Save();

Loading…
Cancel
Save