Skip to content

Commit

Permalink
完善下载进度
Browse files Browse the repository at this point in the history
  • Loading branch information
dylech30th committed Mar 10, 2020
1 parent 6aadf2c commit 5d46cc4
Show file tree
Hide file tree
Showing 34 changed files with 392 additions and 290 deletions.
10 changes: 6 additions & 4 deletions App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.-->

along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<Application
x:Class="Pixeval.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Expand Down Expand Up @@ -136,10 +136,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.-->
</Grid>
<ControlTemplate.Triggers>
<Trigger SourceName="Thumb" Property="IsMouseOver" Value="true">
<Setter TargetName="Thumb" Property="Background" Value="{DynamicResource ButtonSelectBrush}" />
<Setter TargetName="Thumb" Property="Background"
Value="{DynamicResource ButtonSelectBrush}" />
</Trigger>
<Trigger SourceName="Thumb" Property="IsDragging" Value="true">
<Setter TargetName="Thumb" Property="Background" Value="{DynamicResource DarkBrush}" />
<Setter TargetName="Thumb" Property="Background"
Value="{DynamicResource DarkBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Thumb" Property="Visibility" Value="Collapsed" />
Expand Down
37 changes: 28 additions & 9 deletions AppContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
using System;
using System.Collections.Generic;
// Pixeval - A Strong, Fast and Flexible Pixiv Client
// Copyright (C) 2019 Dylech30th
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -22,22 +37,26 @@ public static class AppContext

internal static bool LogoutExit = false;

public static IDownloadPathProvider DownloadPathProvider = new DefaultDownloadPathProvider();

public static IIllustrationFileNameFormatter FileNameFormatter = new DefaultIllustrationFileNameFormatter();

public static ObservableCollection<DownloadableIllustrationViewModel> Downloading = new ObservableCollection<DownloadableIllustrationViewModel>();

static AppContext()
{
Directory.CreateDirectory(ProjectFolder);
Directory.CreateDirectory(SettingsFolder);
Directory.CreateDirectory(ExceptionReportFolder);
}

public static IDownloadPathProvider DownloadPathProvider = new DefaultDownloadPathProvider();

public static IIllustrationFileNameFormatter FileNameFormatter = new DefaultIllustrationFileNameFormatter();

public static ObservableCollection<DownloadableIllustrationViewModel> Downloading = new ObservableCollection<DownloadableIllustrationViewModel>();

public static void EnqueueDownloadItem(Illustration illustration)
{
static void RemoveAction(DownloadableIllustrationViewModel d) => Downloading.Remove(d);
static void RemoveAction(DownloadableIllustrationViewModel d)
{
Downloading.Remove(d);
}

if (illustration.IsManga)
{
for (var j = 0; j < illustration.MangaMetadata.Length; j++)
Expand Down
18 changes: 17 additions & 1 deletion Core/AbstractPixivAsyncEnumerable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
using System.Collections.Generic;
// Pixeval - A Strong, Fast and Flexible Pixiv Client
// Copyright (C) 2019 Dylech30th
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System.Collections.Generic;
using System.Threading;

namespace Pixeval.Core
Expand Down
21 changes: 18 additions & 3 deletions Core/AbstractPixivAsyncEnumerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
using System;
// Pixeval - A Strong, Fast and Flexible Pixiv Client
// Copyright (C) 2019 Dylech30th
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System.Collections.Generic;
using System.Threading.Tasks;

Expand All @@ -18,10 +33,10 @@ public ValueTask DisposeAsync()
return default;
}

protected abstract void UpdateEnumerator();

public abstract ValueTask<bool> MoveNextAsync();

public abstract T Current { get; }

protected abstract void UpdateEnumerator();
}
}
19 changes: 17 additions & 2 deletions Core/DefaultDownloadPathProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
using System.IO;
using Pixeval.Data.ViewModel;
// Pixeval - A Strong, Fast and Flexible Pixiv Client
// Copyright (C) 2019 Dylech30th
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System.IO;
using Pixeval.Objects;
using Pixeval.Persisting;

Expand Down
18 changes: 17 additions & 1 deletion Core/DefaultIllustrationFileNameFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
using Pixeval.Data.ViewModel;
// Pixeval - A Strong, Fast and Flexible Pixiv Client
// Copyright (C) 2019 Dylech30th
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using Pixeval.Data.ViewModel;
using Pixeval.Objects;

namespace Pixeval.Core
Expand Down
27 changes: 12 additions & 15 deletions Core/GalleryAsyncEnumerable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public class GalleryAsyncEnumerable : AbstractPixivAsyncEnumerable<Illustration>
{
private readonly string uid;

public override int RequestedPages { get; protected set; }

public GalleryAsyncEnumerable(string uid)
{
this.uid = uid;
}

public override int RequestedPages { get; protected set; }

public override SortOption SortOption { get; } = SortOption.None;

public override IAsyncEnumerator<Illustration> GetAsyncEnumerator(CancellationToken cancellationToken = default)
Expand All @@ -47,40 +47,42 @@ public override IAsyncEnumerator<Illustration> GetAsyncEnumerator(CancellationTo

private class GalleryAsyncEnumerator : AbstractPixivAsyncEnumerator<Illustration>
{
private readonly string uid;
private GalleryResponse entity;

private IEnumerator<Illustration> illustrationsEnumerator;

private readonly string uid;

public GalleryAsyncEnumerator(string uid, IPixivAsyncEnumerable<Illustration> outerInstance) : base(outerInstance)
{
this.uid = uid;
}

public override Illustration Current => illustrationsEnumerator.Current;

protected override void UpdateEnumerator()
{
illustrationsEnumerator = entity.Illusts.NonNull().Select(_ => _.Parse()).GetEnumerator();
}

public override async ValueTask<bool> MoveNextAsync()
{
await Task.Delay(500);
if (entity == null)
{
if (await TryGetResponse($"/v1/user/bookmarks/illust?user_id={uid}&restrict=public&filter=for_ios") is (true, var model))
{
entity = model;
UpdateEnumerator();
}
else throw new QueryNotRespondingException();
else
{
throw new QueryNotRespondingException();
}

Enumerable.ReportRequestedPages();
}

if (illustrationsEnumerator.MoveNext())
{
return true;
}
if (illustrationsEnumerator.MoveNext()) return true;

if (entity.NextUrl.IsNullOrEmpty()) return false;

Expand All @@ -95,16 +97,11 @@ public override async ValueTask<bool> MoveNextAsync()
return false;
}

public override Illustration Current => illustrationsEnumerator.Current;

private static async Task<HttpResponse<GalleryResponse>> TryGetResponse(string url)
{
var result = (await HttpClientFactory.AppApiHttpClient.GetStringAsync(url)).FromJson<GalleryResponse>();

if (result is { } response && !response.Illusts.IsNullOrEmpty())
{
return HttpResponse<GalleryResponse>.Wrap(true, response);
}
if (result is { } response && !response.Illusts.IsNullOrEmpty()) return HttpResponse<GalleryResponse>.Wrap(true, response);
return HttpResponse<GalleryResponse>.Wrap(false);
}
}
Expand Down
18 changes: 17 additions & 1 deletion Core/IDownloadPathProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
using Pixeval.Data.ViewModel;
// Pixeval - A Strong, Fast and Flexible Pixiv Client
// Copyright (C) 2019 Dylech30th
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using Pixeval.Data.ViewModel;

namespace Pixeval.Core
{
Expand Down
1 change: 0 additions & 1 deletion Core/IPixivAsyncEnumerable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System.Collections.Generic;
using System.Threading.Tasks;

namespace Pixeval.Core
{
Expand Down
44 changes: 0 additions & 44 deletions Core/PixevalDownloadTask.cs

This file was deleted.

7 changes: 2 additions & 5 deletions Core/PixivHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ internal static async void Iterate<T>(IPixivAsyncEnumerable<T> pixivIterator, IC

await foreach (T illust in IteratingSchedule.CurrentItr)
{
if (IteratingSchedule.CurrentItr.IsCancellationRequested() || limit != -1 && pixivIterator.RequestedPages > limit)
{
break;
}
if (IteratingSchedule.CurrentItr.IsCancellationRequested() || limit != -1 && pixivIterator.RequestedPages > limit) break;

if (illust is Illustration i)
{
Expand All @@ -116,7 +113,7 @@ await foreach (T illust in IteratingSchedule.CurrentItr)
}
else
{
container.Add(illust);
if (illust != null) container.Add(illust);
}
}
}
Expand Down

0 comments on commit 5d46cc4

Please sign in to comment.