feature: settings download threads count

This commit is contained in:
2020-05-25 01:35:00 +08:00
parent ce31834733
commit ee0c6130a8
9 changed files with 32 additions and 8 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0.525" package="org.tsanie.pixiview" android:versionCode="18"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0.525" package="org.tsanie.pixiview" android:versionCode="20">
<uses-sdk android:minSdkVersion="25" android:targetSdkVersion="28" /> <uses-sdk android:minSdkVersion="25" android:targetSdkVersion="28" />
<application android:label="Pixiview" android:icon="@mipmap/icon" android:roundIcon="@mipmap/icon_round"></application> <application android:label="Pixiview" android:icon="@mipmap/icon" android:roundIcon="@mipmap/icon_round"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

View File

@ -31,6 +31,6 @@
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.0.525</string> <string>1.0.525</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>18</string> <string>20</string>
</dict> </dict>
</plist> </plist>

View File

@ -81,7 +81,7 @@
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.0.525</string> <string>1.0.525</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>18</string> <string>20</string>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>China</string> <string>China</string>
</dict> </dict>

View File

@ -36,6 +36,7 @@ namespace Pixiview
Configs.SetCookie(Preferences.Get(Configs.CookieKey, null)); Configs.SetCookie(Preferences.Get(Configs.CookieKey, null));
Configs.SetUserId(Preferences.Get(Configs.UserIdKey, null)); Configs.SetUserId(Preferences.Get(Configs.UserIdKey, null));
Configs.DownloadIllustThreads = Preferences.Get(Configs.DownloadIllustThreadsKey, 1);
Configs.IsOnR18 = Preferences.Get(Configs.IsOnR18Key, false); Configs.IsOnR18 = Preferences.Get(Configs.IsOnR18Key, false);
Configs.SyncFavType = (SyncType)Preferences.Get(Configs.SyncFavTypeKey, 0); Configs.SyncFavType = (SyncType)Preferences.Get(Configs.SyncFavTypeKey, 0);
var isProxied = Preferences.Get(Configs.IsProxiedKey, false); var isProxied = Preferences.Get(Configs.IsProxiedKey, false);

View File

@ -20,6 +20,9 @@
IsToggled="{Binding IsOnR18, Mode=TwoWay}"/> IsToggled="{Binding IsOnR18, Mode=TwoWay}"/>
<u:OptionDropCell x:Name="optionFavSync" Title="{r:Text SyncType}" <u:OptionDropCell x:Name="optionFavSync" Title="{r:Text SyncType}"
SelectedIndex="{Binding SyncFavType, Mode=TwoWay}"/> SelectedIndex="{Binding SyncFavType, Mode=TwoWay}"/>
<u:OptionEntryCell Title="{r:Text DownloadIllustThreads}"
Text="{Binding DownloadIllustThreads, Mode=TwoWay}"
Keyboard="Numeric" Placeholder="1~10"/>
</TableSection> </TableSection>
<TableSection Title="{r:Text Proxy}"> <TableSection Title="{r:Text Proxy}">
<u:OptionSwitchCell Title="{r:Text Enabled}" <u:OptionSwitchCell Title="{r:Text Enabled}"

View File

@ -19,6 +19,8 @@ namespace Pixiview
set => SetValue(VersionProperty, value); set => SetValue(VersionProperty, value);
} }
public static readonly BindableProperty DownloadIllustThreadsProperty = BindableProperty.Create(
nameof(DownloadIllustThreads), typeof(string), typeof(OptionPage));
public static readonly BindableProperty IsOnR18Property = BindableProperty.Create( public static readonly BindableProperty IsOnR18Property = BindableProperty.Create(
nameof(IsOnR18), typeof(bool), typeof(OptionPage)); nameof(IsOnR18), typeof(bool), typeof(OptionPage));
public static readonly BindableProperty SyncFavTypeProperty = BindableProperty.Create( public static readonly BindableProperty SyncFavTypeProperty = BindableProperty.Create(
@ -32,6 +34,11 @@ namespace Pixiview
public static readonly BindableProperty CookieProperty = BindableProperty.Create( public static readonly BindableProperty CookieProperty = BindableProperty.Create(
nameof(Cookie), typeof(string), typeof(OptionPage)); nameof(Cookie), typeof(string), typeof(OptionPage));
public string DownloadIllustThreads
{
get => (string)GetValue(DownloadIllustThreadsProperty);
set => SetValue(DownloadIllustThreadsProperty, value);
}
public bool IsOnR18 public bool IsOnR18
{ {
get => (bool)GetValue(IsOnR18Property); get => (bool)GetValue(IsOnR18Property);
@ -98,6 +105,7 @@ namespace Pixiview
Version = $"{AppInfo.VersionString} ({AppInfo.BuildString})"; Version = $"{AppInfo.VersionString} ({AppInfo.BuildString})";
IsOnR18 = Configs.IsOnR18; IsOnR18 = Configs.IsOnR18;
SyncFavType = (int)Configs.SyncFavType; SyncFavType = (int)Configs.SyncFavType;
DownloadIllustThreads = Configs.DownloadIllustThreads.ToString();
var proxy = Configs.Proxy; var proxy = Configs.Proxy;
if (proxy != null) if (proxy != null)
{ {
@ -141,6 +149,15 @@ namespace Pixiview
#endif #endif
} }
if (int.TryParse(DownloadIllustThreads, out int threads) && threads > 0 && threads <= 10 && threads != Configs.DownloadIllustThreads)
{
Preferences.Set(Configs.DownloadIllustThreadsKey, threads);
Configs.DownloadIllustThreads = threads;
#if LOG
App.DebugPrint($"will use {threads} threads to download illust");
#endif
}
var proxy = Configs.Proxy; var proxy = Configs.Proxy;
var h = Host?.Trim(); var h = Host?.Trim();
_ = int.TryParse(Port, out int pt); _ = int.TryParse(Port, out int pt);

View File

@ -35,6 +35,7 @@
<SyncNo>不同步</SyncNo> <SyncNo>不同步</SyncNo>
<SyncPrompt>提示同步</SyncPrompt> <SyncPrompt>提示同步</SyncPrompt>
<SyncAuto>自动同步</SyncAuto> <SyncAuto>自动同步</SyncAuto>
<DownloadIllustThreads>下载线程数</DownloadIllustThreads>
<Follow>已关注</Follow> <Follow>已关注</Follow>
<Recommends>推荐</Recommends> <Recommends>推荐</Recommends>
<ByUser>按用户</ByUser> <ByUser>按用户</ByUser>

View File

@ -217,7 +217,7 @@ namespace Pixiview.Utils
} }
var file = Path.Combine(directory, Path.GetFileName(url)); var file = Path.Combine(directory, Path.GetFileName(url));
var proxy = Configs.Proxy; var proxy = Configs.Proxy;
var referer = new Uri(string.Format(Configs.UrlIllust, id)); var referer = new Uri(string.Format(Configs.RefererIllust, id));
var handler = new HttpClientHandler var handler = new HttpClientHandler
{ {
UseCookies = false UseCookies = false
@ -251,7 +251,7 @@ namespace Pixiview.Utils
} }
// segments // segments
const int SIZE = 50000; const int SIZE = 150000;
var list = new List<(long from, long to)>(); var list = new List<(long from, long to)>();
for (var i = 0L; i < size; i += SIZE) for (var i = 0L; i < size; i += SIZE)
{ {
@ -270,7 +270,7 @@ namespace Pixiview.Utils
var data = new byte[size]; var data = new byte[size];
var task = new TaskCompletionSource<string>(); var task = new TaskCompletionSource<string>();
ParallelTask.Start($"download.async.{id}", 0, list.Count, 6, i => ParallelTask.Start($"download.async.{id}", 0, list.Count, Configs.DownloadIllustThreads, i =>
{ {
var (from, to) = list[i]; var (from, to) = list[i];
using (var request = new HttpRequestMessage(HttpMethod.Get, url)) using (var request = new HttpRequestMessage(HttpMethod.Get, url))
@ -279,9 +279,9 @@ namespace Pixiview.Utils
headers.Add("Accept", Configs.AcceptPureImage); headers.Add("Accept", Configs.AcceptPureImage);
headers.Add("Accept-Language", Configs.AcceptLanguage); headers.Add("Accept-Language", Configs.AcceptLanguage);
headers.Add("Accept-Encoding", "identity"); headers.Add("Accept-Encoding", "identity");
headers.Referrer = referer;
headers.IfRange = new RangeConditionHeaderValue(lastModified); headers.IfRange = new RangeConditionHeaderValue(lastModified);
headers.Range = new RangeHeaderValue(from, to); headers.Range = new RangeHeaderValue(from, to);
headers.Referrer = referer;
headers.Add("User-Agent", Configs.UserAgent); headers.Add("User-Agent", Configs.UserAgent);
using (var response = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).Result) using (var response = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).Result)
using (var ms = new MemoryStream(data, (int)from, (int)(to - from + 1))) using (var ms = new MemoryStream(data, (int)from, (int)(to - from + 1)))

View File

@ -593,7 +593,7 @@ namespace Pixiview.Utils
public static ImageSource LoadPreviewImage(string url, bool downloading, string id = null, bool force = false) public static ImageSource LoadPreviewImage(string url, bool downloading, string id = null, bool force = false)
{ {
if (downloading) if (downloading && Configs.DownloadIllustThreads > 1)
{ {
return LoadImageAsync(url, id, PersonalFolder, previewFolder, force).Result; return LoadImageAsync(url, id, PersonalFolder, previewFolder, force).Result;
} }
@ -746,6 +746,7 @@ namespace Pixiview.Utils
public const string ProfileImageKey = "profile_img"; public const string ProfileImageKey = "profile_img";
public const string CookieKey = "cookies"; public const string CookieKey = "cookies";
public const string UserIdKey = "user_id"; public const string UserIdKey = "user_id";
public const string DownloadIllustThreadsKey = "download_illust_threads";
public const string IsOnR18Key = "is_on_r18"; public const string IsOnR18Key = "is_on_r18";
public const string SyncFavTypeKey = "sync_fav_type"; public const string SyncFavTypeKey = "sync_fav_type";
public const string IsProxiedKey = "is_proxied"; public const string IsProxiedKey = "is_proxied";
@ -763,6 +764,7 @@ namespace Pixiview.Utils
public const string RefererIllustRanking = "https://www.pixiv.net/ranking.php?{0}"; public const string RefererIllustRanking = "https://www.pixiv.net/ranking.php?{0}";
public const string RefererIllustUser = "https://www.pixiv.net/users/{0}/illustrations"; public const string RefererIllustUser = "https://www.pixiv.net/users/{0}/illustrations";
public static int DownloadIllustThreads;
public static bool IsOnR18; public static bool IsOnR18;
public static SyncType SyncFavType; public static SyncType SyncFavType;
public static WebProxy Proxy; public static WebProxy Proxy;