Skip to content

Commit 23de05f

Browse files
committed
Report download errors for correct modules, don't re-download
1 parent 6bfb1e9 commit 23de05f

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

Core/Extensions/EnumerableExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public static void RemoveWhere<K, V>(this Dictionary<K, V> source,
6060
}
6161
}
6262

63+
public static bool IntersectsWith<T>(this IEnumerable<T> source,
64+
IEnumerable<T> other)
65+
=> source.Intersect(other).Any();
66+
6367
/// <summary>
6468
/// Sum a sequence of TimeSpans.
6569
/// Mysteriously not defined standardly.

GUI/Main/MainDownload.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77

88
using CKAN.GUI.Attributes;
9+
using CKAN.Extensions;
910

1011
namespace CKAN.GUI
1112
{
@@ -59,7 +60,8 @@ private void CacheMods(object? sender, DoWorkEventArgs? e)
5960
{
6061
try
6162
{
62-
downloader.DownloadModules(modules.Select(m => m.Module));
63+
downloader.DownloadModules(modules.Where(m => !m.IsCached)
64+
.Select(m => m.Module));
6365
done = true;
6466
}
6567
catch (ModuleDownloadErrorsKraken k)
@@ -72,7 +74,11 @@ private void CacheMods(object? sender, DoWorkEventArgs? e)
7274
Properties.Resources.ModDownloadsFailedColHdr,
7375
Properties.Resources.ModDownloadsFailedAbortBtnNotInstalling,
7476
k.Exceptions.Select(kvp => new KeyValuePair<object[], Exception>(
75-
modules.Select(m => m.Module).ToArray(), kvp.Value)),
77+
modules.Select(m => m.Module)
78+
.Where(m => (m.download ?? Enumerable.Empty<Uri>())
79+
.IntersectsWith(kvp.Key?.download ?? Enumerable.Empty<Uri>()))
80+
.ToArray(),
81+
kvp.Value)),
7682
(m1, m2) => (m1 as CkanModule)?.download == (m2 as CkanModule)?.download);
7783
dfd.ShowDialog(this);
7884
});

GUI/Main/MainInstall.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using CKAN.IO;
1515
using CKAN.GUI.Attributes;
1616
using CKAN.Configuration;
17+
using CKAN.Extensions;
1718

1819
// Don't warn if we use our own obsolete properties
1920
#pragma warning disable 0618
@@ -286,7 +287,9 @@ private void InstallMods(object? sender, DoWorkEventArgs? e)
286287
Properties.Resources.ModDownloadsFailedColHdr,
287288
Properties.Resources.ModDownloadsFailedAbortBtn,
288289
k.Exceptions.Select(kvp => new KeyValuePair<object[], Exception>(
289-
fullChangeset.Where(m => m.download == kvp.Key.download).ToArray(),
290+
fullChangeset.Where(m => (m.download ?? Enumerable.Empty<Uri>())
291+
.IntersectsWith(kvp.Key.download ?? Enumerable.Empty<Uri>()))
292+
.ToArray(),
290293
kvp.Value)),
291294
(m1, m2) => (m1 as CkanModule)?.download == (m2 as CkanModule)?.download);
292295
dfd.ShowDialog(this);

Tests/Core/Extensions/EnumerableExtensionsTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ namespace Tests.Core.Extensions
1010
[TestFixture]
1111
public class EnumerableExtensionsTests
1212
{
13+
[TestCase(new string[] { "A", "B", "C", "D" },
14+
new string[] { "A", "S", "D", "F" },
15+
ExpectedResult = true),
16+
TestCase(new string[] { "A", "B", "C", "D" },
17+
new string[] { "E", "F", "G", "H" },
18+
ExpectedResult = false)]
19+
public bool IntersectsWith_Examples_Works(string[] a, string[] b)
20+
=> a.IntersectsWith(b);
21+
1322
[TestCaseSource(nameof(TimeSpanCases))]
1423
public TimeSpan Sum_Timespans_Works(TimeSpan[] spans)
1524
=> spans.Sum();

0 commit comments

Comments
 (0)