Fixing small issues

This commit is contained in:
Zoe Roux 2021-03-25 00:07:59 +01:00
parent adb6bdb3f2
commit 9b6aa68472
3 changed files with 27 additions and 32 deletions

View File

@ -12,7 +12,7 @@
<Company>SDG</Company>
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageVersion>1.0.23</PackageVersion>
<PackageVersion>1.0.24</PackageVersion>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<LangVersion>default</LangVersion>

View File

@ -91,18 +91,18 @@ namespace Kyoo
}
}
public static IEnumerable<T> MergeLists<T>(IEnumerable<T> first,
public static T[] MergeLists<T>(IEnumerable<T> first,
IEnumerable<T> second,
Func<T, T, bool> isEqual = null)
{
if (first == null)
return second;
return second.ToArray();
if (second == null)
return first;
return first.ToArray();
if (isEqual == null)
return first.Concat(second).ToList();
return first.Concat(second).ToArray();
List<T> list = first.ToList();
return list.Concat(second.Where(x => !list.Any(y => isEqual(x, y))));
return list.Concat(second.Where(x => !list.Any(y => isEqual(x, y)))).ToArray();
}
public static T Assign<T>(T first, T second)
@ -183,7 +183,7 @@ namespace Kyoo
{
property.SetValue(first, RunGenericMethod<object>(
typeof(Utility),
"MergeLists",
nameof(MergeLists),
GetEnumerableType(property.PropertyType),
oldValue, newValue, null));
}
@ -384,18 +384,21 @@ namespace Kyoo
.IfEmpty(() => throw new NullReferenceException($"A method named {name} with " +
$"{args.Length} arguments and {generics.Length} generic " +
$"types could not be found on {type.Name}."))
.Where(x =>
{
int i = 0;
return x.GetGenericArguments().All(y => y.IsAssignableFrom(generics[i++]));
})
.IfEmpty(() => throw new NullReferenceException($"No method {name} match the generics specified."))
.Where(x =>
{
int i = 0;
return x.GetParameters().All(y => y.ParameterType == args[i++].GetType());
})
.IfEmpty(() => throw new NullReferenceException($"No method {name} match the parameters's types."))
// TODO this won't work but I don't know why.
// .Where(x =>
// {
// int i = 0;
// return x.GetGenericArguments().All(y => y.IsAssignableFrom(generics[i++]));
// })
// .IfEmpty(() => throw new NullReferenceException($"No method {name} match the generics specified."))
// TODO this won't work for Type<T> because T is specified in arguments but not in the parameters type.
// .Where(x =>
// {
// int i = 0;
// return x.GetParameters().All(y => y.ParameterType.IsInstanceOfType(args[i++]));
// })
// .IfEmpty(() => throw new NullReferenceException($"No method {name} match the parameters's types."))
.Take(2)
.ToArray();

View File

@ -10,14 +10,12 @@ namespace Kyoo.Controllers
{
public class ThumbnailsManager : IThumbnailsManager
{
private readonly IConfiguration _config;
private readonly IFileManager _files;
private readonly string _peoplePath;
private readonly string _providerPath;
public ThumbnailsManager(IConfiguration configuration, IFileManager files)
{
_config = configuration;
_files = files;
_peoplePath = Path.GetFullPath(configuration.GetValue<string>("peoplePath"));
_providerPath = Path.GetFullPath(configuration.GetValue<string>("providerPath"));
@ -67,10 +65,9 @@ namespace Kyoo.Controllers
{
if (people == null)
throw new ArgumentNullException(nameof(people));
string root = _config.GetValue<string>("peoplePath");
string localPath = Path.Combine(root, people.Slug + ".jpg");
Directory.CreateDirectory(root);
if (people.Poster == null)
return;
string localPath = await GetPeoplePoster(people);
if (alwaysDownload || !File.Exists(localPath))
await DownloadImage(people.Poster, localPath, $"The profile picture of {people.Name}");
}
@ -100,10 +97,7 @@ namespace Kyoo.Controllers
if (provider.Logo == null)
return;
string root = _config.GetValue<string>("providerPath");
string localPath = Path.Combine(root, provider.Slug + ".jpg");
Directory.CreateDirectory(root);
string localPath = await GetProviderLogo(provider);
if (alwaysDownload || !File.Exists(localPath))
await DownloadImage(provider.Logo, localPath, $"The logo of {provider.Slug}");
}
@ -157,9 +151,7 @@ namespace Kyoo.Controllers
{
if (provider == null)
throw new ArgumentNullException(nameof(provider));
string thumbPath = Path.GetFullPath(Path.Combine(_providerPath, $"{provider.Slug}.jpg"));
if (!thumbPath.StartsWith(_providerPath))
return Task.FromResult<string>(null);
string thumbPath = Path.GetFullPath(Path.Combine(_providerPath, $"{provider.Slug}.png"));
return Task.FromResult(thumbPath.StartsWith(_providerPath) ? thumbPath : null);
}
}