mirror of
https://github.com/Pixeval/Pixeval.git
synced 2025-01-07 03:06:53 +08:00
修复搜索日期问题 (#584)
This commit is contained in:
parent
e6c0d79975
commit
d8b491af3d
@ -134,7 +134,6 @@ namespace Pixeval.CoreApi;
|
||||
|
||||
[JsonSerializable(typeof(PrivacyPolicy))]
|
||||
[JsonSerializable(typeof(RankOption))]
|
||||
[JsonSerializable(typeof(SearchDuration))]
|
||||
[JsonSerializable(typeof(SearchIllustrationTagMatchOption))]
|
||||
[JsonSerializable(typeof(SearchNovelTagMatchOption))]
|
||||
[JsonSerializable(typeof(TargetFilter))]
|
||||
|
@ -35,7 +35,6 @@ namespace Pixeval.CoreApi.Engine.Implements;
|
||||
/// <param name="matchOption"></param>
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="sortOption"></param>
|
||||
/// <param name="searchDuration"></param>
|
||||
/// <param name="targetFilter"></param>
|
||||
/// <param name="startDate"></param>
|
||||
/// <param name="endDate"></param>
|
||||
@ -46,7 +45,6 @@ internal class IllustrationSearchEngine(
|
||||
SearchIllustrationTagMatchOption matchOption,
|
||||
string tag,
|
||||
WorkSortOption sortOption,
|
||||
SearchDuration searchDuration,
|
||||
TargetFilter targetFilter,
|
||||
DateTimeOffset? startDate,
|
||||
DateTimeOffset? endDate,
|
||||
@ -65,10 +63,7 @@ internal class IllustrationSearchEngine(
|
||||
? null
|
||||
: $"&sort={sortOption.GetDescription()}")
|
||||
+ startDate?.Let(dn => $"&start_date={dn:yyyy-MM-dd}")
|
||||
+ endDate?.Let(dn => $"&start_date={dn:yyyy-MM-dd}")
|
||||
+ (searchDuration is SearchDuration.Undecided
|
||||
? null
|
||||
: $"&duration={searchDuration.GetDescription()}")
|
||||
+ endDate?.Let(dn => $"&end_date={dn:yyyy-MM-dd}")
|
||||
+ aiType?.Let(t => $"&search_ai_type={(t ? 1 : 0)}"));
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ internal class NovelSearchEngine(
|
||||
SearchNovelTagMatchOption matchOption,
|
||||
string tag,
|
||||
WorkSortOption sortOption,
|
||||
SearchDuration searchDuration,
|
||||
TargetFilter targetFilter,
|
||||
DateTimeOffset? startDate,
|
||||
DateTimeOffset? endDate,
|
||||
@ -73,10 +72,7 @@ internal class NovelSearchEngine(
|
||||
? null
|
||||
: $"&sort={sortOption.GetDescription()}")
|
||||
+ startDate?.Let(dn => $"&start_date={dn:yyyy-MM-dd}")
|
||||
+ endDate?.Let(dn => $"&start_date={dn:yyyy-MM-dd}")
|
||||
+ (searchDuration is SearchDuration.Undecided
|
||||
? null
|
||||
: $"&duration={searchDuration.GetDescription()}")
|
||||
+ endDate?.Let(dn => $"&end_date={dn:yyyy-MM-dd}")
|
||||
+ aiType?.Let(t => $"&search_ai_type={(t ? 1 : 0)}"));
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
#region Copyright (c) Pixeval/Pixeval.CoreApi
|
||||
// GPL v3 License
|
||||
//
|
||||
// Pixeval/Pixeval.CoreApi
|
||||
// Copyright (c) 2023 Pixeval.CoreApi/SearchDuration.cs
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#endregion
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Pixeval.CoreApi.Global.Enum;
|
||||
|
||||
public enum SearchDuration
|
||||
{
|
||||
Undecided,
|
||||
|
||||
[Description("within_last_day")]
|
||||
WithinLastDay,
|
||||
|
||||
[Description("within_last_week")]
|
||||
WithinLastWeek,
|
||||
|
||||
[Description("within_last_month")]
|
||||
WithinLastMonth,
|
||||
|
||||
[Description("within_last_half_year")]
|
||||
WithinLastHalfYear,
|
||||
|
||||
[Description("within_last_year")]
|
||||
WithinLastYear
|
||||
}
|
@ -86,7 +86,6 @@ public partial class MakoClient
|
||||
/// matching
|
||||
/// </param>
|
||||
/// <param name="sortOption">The <see cref="WorkSortOption" /> option for sorting method</param>
|
||||
/// <param name="searchDuration">The <see cref="SearchDuration" /> option for the duration of this search</param>
|
||||
/// <param name="targetFilter">The <see cref="TargetFilter" /> option targeting android or ios</param>
|
||||
/// <param name="startDate">The starting date filtering the search results</param>
|
||||
/// <param name="endDate">The ending date filtering the searching results</param>
|
||||
@ -98,7 +97,6 @@ public partial class MakoClient
|
||||
string tag,
|
||||
SearchIllustrationTagMatchOption matchOption = SearchIllustrationTagMatchOption.TitleAndCaption,
|
||||
WorkSortOption sortOption = WorkSortOption.DoNotSort,
|
||||
SearchDuration searchDuration = SearchDuration.Undecided,
|
||||
TargetFilter targetFilter = TargetFilter.ForAndroid,
|
||||
DateTimeOffset? startDate = null,
|
||||
DateTimeOffset? endDate = null,
|
||||
@ -108,14 +106,13 @@ public partial class MakoClient
|
||||
if (sortOption is WorkSortOption.PopularityDescending && !Session.IsPremium)
|
||||
sortOption = WorkSortOption.DoNotSort;
|
||||
|
||||
return new IllustrationSearchEngine(this, new EngineHandle(CancelInstance), matchOption, tag, sortOption, searchDuration, targetFilter, startDate, endDate, aiType);
|
||||
return new IllustrationSearchEngine(this, new EngineHandle(CancelInstance), matchOption, tag, sortOption, targetFilter, startDate, endDate, aiType);
|
||||
}
|
||||
|
||||
public IFetchEngine<Novel> SearchNovels(
|
||||
string tag,
|
||||
SearchNovelTagMatchOption matchOption = SearchNovelTagMatchOption.Text,
|
||||
WorkSortOption sortOption = WorkSortOption.DoNotSort,
|
||||
SearchDuration searchDuration = SearchDuration.Undecided,
|
||||
TargetFilter targetFilter = TargetFilter.ForAndroid,
|
||||
DateTimeOffset? startDate = null,
|
||||
DateTimeOffset? endDate = null,
|
||||
@ -127,7 +124,7 @@ public partial class MakoClient
|
||||
if (sortOption is WorkSortOption.PopularityDescending && !Session.IsPremium)
|
||||
sortOption = WorkSortOption.DoNotSort;
|
||||
|
||||
return new NovelSearchEngine(this, new EngineHandle(CancelInstance), matchOption, tag, sortOption, searchDuration, targetFilter, startDate, endDate, mergePlainKeywordResults, includeTranslatedTagResults, aiType);
|
||||
return new NovelSearchEngine(this, new EngineHandle(CancelInstance), matchOption, tag, sortOption, targetFilter, startDate, endDate, mergePlainKeywordResults, includeTranslatedTagResults, aiType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -121,12 +121,6 @@ public partial record AppSettings() : IWindowSettings
|
||||
[SettingsEntry(Symbol.History, nameof(MaximumSearchHistoryRecordsEntryHeader), nameof(MaximumSearchHistoryRecordsEntryDescription))]
|
||||
public int MaximumSearchHistoryRecords { get; set; } = 50;
|
||||
|
||||
[SettingsEntry(Symbol.Clock, nameof(SearchDurationEntryHeader), nameof(SearchDurationEntryDescription))]
|
||||
public SearchDuration SearchDuration { get; set; } = SearchDuration.Undecided;
|
||||
|
||||
[SettingsEntry(Symbol.Timer, nameof(UsePreciseRangeForSearchEntryHeader), nameof(UsePreciseRangeForSearchEntryDescription))]
|
||||
public bool UsePreciseRangeForSearch { get; set; }
|
||||
|
||||
[SettingsEntry(Symbol.Key, nameof(ReverseSearchApiKeyEntryHeader), nameof(ReverseSearchApiKeyEntryDescriptionHyperlinkButtonContent))]
|
||||
public string ReverseSearchApiKey { get; set; } = "";
|
||||
|
||||
@ -170,8 +164,14 @@ public partial record AppSettings() : IWindowSettings
|
||||
[SettingsEntry(Symbol.History, nameof(MaximumBrowseHistoryRecordsEntryHeader), nameof(MaximumBrowseHistoryRecordsEntryDescription))]
|
||||
public int MaximumBrowseHistoryRecords { get; set; } = 100;
|
||||
|
||||
[SettingsEntry(Symbol.ArrowCircleLeft, nameof(UseSearchStartDateEntryHeader), nameof(UseSearchStartDateEntryDescription))]
|
||||
public bool UseSearchStartDate { get; set; }
|
||||
|
||||
public DateTimeOffset SearchStartDate { get; set; } = DateTimeOffset.Now - TimeSpan.FromDays(1);
|
||||
|
||||
[SettingsEntry(Symbol.ArrowCircleRight, nameof(UseSearchEndDateEntryHeader), nameof(UseSearchEndDateEntryDescription))]
|
||||
public bool UseSearchEndDate { get; set; }
|
||||
|
||||
public DateTimeOffset SearchEndDate { get; set; } = DateTimeOffset.Now;
|
||||
|
||||
[SettingsEntry(Symbol.ImageSparkle, nameof(BrowseOriginalImageEntryHeader), nameof(BrowseOriginalImageEntryDescription))]
|
||||
|
@ -1,32 +0,0 @@
|
||||
<controls:SettingsExpander
|
||||
x:Class="Pixeval.Controls.Settings.DateRangeWithSwitchSettingsExpander"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:fluent="using:FluentIcons.WinUI"
|
||||
xmlns:local="using:Pixeval.Settings"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
Description="{x:Bind Entry.DescriptionControl}"
|
||||
Header="{x:Bind Entry.Header}"
|
||||
Tag="{x:Bind Entry.Attribute}"
|
||||
mc:Ignorable="d">
|
||||
<controls:SettingsExpander.HeaderIcon>
|
||||
<fluent:SymbolIcon Symbol="{x:Bind Entry.HeaderIcon}" />
|
||||
</controls:SettingsExpander.HeaderIcon>
|
||||
<ToggleSwitch IsOn="{x:Bind Entry.Value, Mode=TwoWay}" Toggled="ToggleSwitch_OnToggled" />
|
||||
<controls:SettingsExpander.Items>
|
||||
<controls:SettingsCard
|
||||
x:Uid="/SettingsPage/SearchStartDateEntry"
|
||||
HeaderIcon="{fluent:SymbolIcon Symbol=ArrowCircleLeft}"
|
||||
IsEnabled="{x:Bind Entry.Value, Mode=OneWay}">
|
||||
<CalendarDatePicker x:Uid="/SettingsPage/SearchStartCalendarDatePicker" Date="{x:Bind Entry.SearchStartDate, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
<controls:SettingsCard
|
||||
x:Uid="/SettingsPage/SearchEndDateEntry"
|
||||
HeaderIcon="{fluent:SymbolIcon Symbol=ArrowCircleRight}"
|
||||
IsEnabled="{x:Bind Entry.Value, Mode=OneWay}">
|
||||
<CalendarDatePicker x:Uid="/SettingsPage/SearchEndCalendarDatePicker" Date="{x:Bind Entry.SearchEndDate, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
</controls:SettingsExpander.Items>
|
||||
</controls:SettingsExpander>
|
@ -0,0 +1,31 @@
|
||||
<controls:SettingsCard
|
||||
x:Class="Pixeval.Controls.Settings.DateWithSwitchSettingsCard"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:fluent="using:FluentIcons.WinUI"
|
||||
xmlns:local="using:Pixeval.Settings"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
Description="{x:Bind Entry.DescriptionControl}"
|
||||
Header="{x:Bind Entry.Header}"
|
||||
Tag="{x:Bind Entry.Attribute}"
|
||||
mc:Ignorable="d">
|
||||
<controls:SettingsCard.HeaderIcon>
|
||||
<fluent:SymbolIcon Symbol="{x:Bind Entry.HeaderIcon}" />
|
||||
</controls:SettingsCard.HeaderIcon>
|
||||
<Grid ColumnSpacing="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ToggleSwitch
|
||||
Grid.Column="0"
|
||||
IsOn="{x:Bind Entry.Value, Mode=TwoWay}"
|
||||
Toggled="ToggleSwitch_OnToggled" />
|
||||
<CalendarDatePicker
|
||||
Grid.Column="1"
|
||||
Date="{x:Bind Entry.Date, Mode=TwoWay}"
|
||||
IsEnabled="{x:Bind Entry.Value, Mode=OneWay}" />
|
||||
</Grid>
|
||||
</controls:SettingsCard>
|
@ -5,11 +5,11 @@ using WinUI3Utilities;
|
||||
|
||||
namespace Pixeval.Controls.Settings;
|
||||
|
||||
public sealed partial class DateRangeWithSwitchSettingsExpander
|
||||
public sealed partial class DateWithSwitchSettingsCard
|
||||
{
|
||||
public DateRangeWithSwitchAppSettingsEntry Entry { get; set; } = null!;
|
||||
public DateWithSwitchAppSettingsEntry Entry { get; set; } = null!;
|
||||
|
||||
public DateRangeWithSwitchSettingsExpander() => InitializeComponent();
|
||||
public DateWithSwitchSettingsCard() => InitializeComponent();
|
||||
|
||||
private void ToggleSwitch_OnToggled(object sender, RoutedEventArgs e)
|
||||
{
|
@ -51,18 +51,16 @@ public sealed partial class SearchWorksPage : IScrollViewHost
|
||||
_searchText,
|
||||
settings.SearchIllustrationTagMatchOption,
|
||||
settings.WorkSortOption,
|
||||
settings.SearchDuration,
|
||||
settings.TargetFilter,
|
||||
settings.UsePreciseRangeForSearch ? settings.SearchStartDate : null,
|
||||
settings.UsePreciseRangeForSearch ? settings.SearchEndDate : null)
|
||||
settings.UseSearchStartDate ? settings.SearchStartDate : null,
|
||||
settings.UseSearchEndDate ? settings.SearchEndDate : null)
|
||||
: App.AppViewModel.MakoClient.SearchNovels(
|
||||
_searchText,
|
||||
settings.SearchNovelTagMatchOption,
|
||||
settings.WorkSortOption,
|
||||
settings.SearchDuration,
|
||||
settings.TargetFilter,
|
||||
settings.UsePreciseRangeForSearch ? settings.SearchStartDate : null,
|
||||
settings.UsePreciseRangeForSearch ? settings.SearchEndDate : null));
|
||||
settings.UseSearchStartDate ? settings.SearchStartDate : null,
|
||||
settings.UseSearchEndDate ? settings.SearchEndDate : null));
|
||||
}
|
||||
|
||||
public ScrollView ScrollView => WorkContainer.ScrollView;
|
||||
|
@ -112,7 +112,7 @@ public partial class SettingsPageViewModel : UiObservableObject, IDisposable
|
||||
new EnumAppSettingsEntry(AppSettings,
|
||||
t => t.DefaultSelectedTabItem,
|
||||
MainPageTabItemExtension.GetItems()),
|
||||
new StringAppSettingsEntry(AppSettings,
|
||||
new StringAppSettingsEntry(AppSettings,
|
||||
t => t.WebCookie)
|
||||
{
|
||||
Placeholder = SettingsPageResources.WebCookieTextBoxPlaceholderText
|
||||
@ -141,7 +141,7 @@ public partial class SettingsPageViewModel : UiObservableObject, IDisposable
|
||||
|
||||
new (SettingsEntryCategory.AiUpscaler)
|
||||
{
|
||||
new EnumAppSettingsEntry(AppSettings,
|
||||
new EnumAppSettingsEntry(AppSettings,
|
||||
t => t.UpscalerModel,
|
||||
RealESRGANModelExtension.GetItems())
|
||||
{
|
||||
@ -218,10 +218,12 @@ public partial class SettingsPageViewModel : UiObservableObject, IDisposable
|
||||
t => t.SearchNovelTagMatchOption,
|
||||
SearchNovelTagMatchOptionExtension.GetItems())
|
||||
]),
|
||||
new EnumAppSettingsEntry(AppSettings,
|
||||
t => t.SearchDuration,
|
||||
SearchDurationExtension.GetItems()),
|
||||
new DateRangeWithSwitchAppSettingsEntry(AppSettings)
|
||||
new DateWithSwitchAppSettingsEntry(AppSettings,
|
||||
t => t.UseSearchStartDate,
|
||||
t => t.SearchStartDate),
|
||||
new DateWithSwitchAppSettingsEntry(AppSettings,
|
||||
t => t.UseSearchEndDate,
|
||||
t => t.SearchEndDate)
|
||||
},
|
||||
new(SettingsEntryCategory.Download)
|
||||
{
|
||||
@ -287,8 +289,8 @@ public partial class SettingsPageViewModel : UiObservableObject, IDisposable
|
||||
_ => SettingsPageResources.UnknownUpdateState
|
||||
};
|
||||
|
||||
public string? NewestVersion => AppInfo.AppVersion.UpdateAvailable
|
||||
? AppInfo.AppVersion.NewestVersion?.Let(t => $"{t.Major}.{t.Minor}.{t.Build}.{t.Revision}")
|
||||
public string? NewestVersion => AppInfo.AppVersion.UpdateAvailable
|
||||
? AppInfo.AppVersion.NewestVersion?.Let(t => $"{t.Major}.{t.Minor}.{t.Build}.{t.Revision}")
|
||||
: null;
|
||||
|
||||
public InfoBarSeverity UpdateInfoSeverity => AppInfo.AppVersion.UpdateState switch
|
||||
|
@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using Pixeval.AppManagement;
|
||||
using Pixeval.Controls.Settings;
|
||||
|
||||
namespace Pixeval.Settings.Models;
|
||||
|
||||
public partial class DateRangeWithSwitchAppSettingsEntry(
|
||||
AppSettings appSettings)
|
||||
: BoolAppSettingsEntry(appSettings, t => t.UsePreciseRangeForSearch)
|
||||
{
|
||||
public override DateRangeWithSwitchSettingsExpander Element => new() { Entry = this };
|
||||
|
||||
public DateTimeOffset SearchStartDate
|
||||
{
|
||||
get => Settings.SearchStartDate;
|
||||
set
|
||||
{
|
||||
if (Settings.SearchStartDate != value)
|
||||
return;
|
||||
Settings.SearchStartDate = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public DateTimeOffset SearchEndDate
|
||||
{
|
||||
get => Settings.SearchEndDate;
|
||||
set
|
||||
{
|
||||
if (Settings.SearchEndDate != value)
|
||||
return;
|
||||
Settings.SearchEndDate = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public override void ValueReset()
|
||||
{
|
||||
base.ValueReset();
|
||||
OnPropertyChanged(nameof(SearchStartDate));
|
||||
OnPropertyChanged(nameof(SearchEndDate));
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Pixeval.AppManagement;
|
||||
using Pixeval.Controls.Settings;
|
||||
|
||||
namespace Pixeval.Settings.Models;
|
||||
|
||||
public partial class DateWithSwitchAppSettingsEntry : BoolAppSettingsEntry
|
||||
{
|
||||
public DateWithSwitchAppSettingsEntry(AppSettings appSettings,
|
||||
Expression<Func<AppSettings, bool>> switchProperty,
|
||||
Expression<Func<AppSettings, DateTimeOffset>> dateProperty) : base(appSettings, switchProperty)
|
||||
{
|
||||
(_getter, _setter, _) = GetSettingsEntryInfo(dateProperty);
|
||||
}
|
||||
|
||||
public override DateWithSwitchSettingsCard Element => new() { Entry = this };
|
||||
|
||||
private readonly Func<AppSettings, DateTimeOffset> _getter;
|
||||
|
||||
private readonly Action<AppSettings, DateTimeOffset> _setter;
|
||||
|
||||
public Action<DateTimeOffset>? DateChanged { get; set; }
|
||||
|
||||
public DateTimeOffset Date
|
||||
{
|
||||
get => _getter(Settings);
|
||||
set
|
||||
{
|
||||
if (Equals(Date, value))
|
||||
return;
|
||||
_setter(Settings, value);
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public override void ValueReset()
|
||||
{
|
||||
// 顺序很重要,因为base.ValueReset()最后会触发ValueChanged
|
||||
OnPropertyChanged(nameof(Date));
|
||||
base.ValueReset();
|
||||
DateChanged?.Invoke(Date);
|
||||
}
|
||||
}
|
@ -34,41 +34,7 @@ public abstract class SingleValueSettingsEntry<TSettings, TValue> : SingleValueS
|
||||
protected SingleValueSettingsEntry(TSettings settings,
|
||||
Expression<Func<TSettings, TValue>> property) : base(settings)
|
||||
{
|
||||
if (property is not { Parameters: [{ } parameter] })
|
||||
{
|
||||
ThrowHelper.Argument(property);
|
||||
return;
|
||||
}
|
||||
|
||||
var propertyValue = Expression.Parameter(typeof(TValue));
|
||||
BinaryExpression setPropertyValue;
|
||||
Expression getPropertyValue;
|
||||
MemberExpression member;
|
||||
switch (property.Body)
|
||||
{
|
||||
case UnaryExpression
|
||||
{
|
||||
Operand: MemberExpression member1
|
||||
} body:
|
||||
{
|
||||
getPropertyValue = body;
|
||||
setPropertyValue = Expression.Assign(member1, Expression.Convert(propertyValue, member1.Type));
|
||||
member = member1;
|
||||
break;
|
||||
}
|
||||
case MemberExpression member2:
|
||||
{
|
||||
getPropertyValue = member = member2;
|
||||
setPropertyValue = Expression.Assign(member2, propertyValue);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ThrowHelper.Argument(property);
|
||||
return;
|
||||
}
|
||||
|
||||
_getter = Expression.Lambda<Func<TSettings, TValue>>(getPropertyValue, parameter).Compile();
|
||||
_setter = Expression.Lambda<Action<TSettings, TValue>>(setPropertyValue, parameter, propertyValue).Compile();
|
||||
(_getter, _setter, var member) = GetSettingsEntryInfo(property);
|
||||
Attribute = member.Member.GetCustomAttribute<SettingsEntryAttribute>();
|
||||
|
||||
if (Attribute is { } attribute)
|
||||
@ -104,4 +70,50 @@ public abstract class SingleValueSettingsEntry<TSettings, TValue> : SingleValueS
|
||||
private readonly Func<TSettings, TValue> _getter;
|
||||
|
||||
private readonly Action<TSettings, TValue> _setter;
|
||||
|
||||
protected SettingsEntryInfo<TSettings1, TValue1> GetSettingsEntryInfo<TSettings1, TValue1>(
|
||||
Expression<Func<TSettings1, TValue1>> property)
|
||||
{
|
||||
if (property is not { Parameters: [{ } parameter] })
|
||||
{
|
||||
return ThrowHelper
|
||||
.Argument<Expression<Func<TSettings1, TValue1>>, SettingsEntryInfo<TSettings1, TValue1>>(property);
|
||||
}
|
||||
|
||||
var propertyValue = Expression.Parameter(typeof(TValue1));
|
||||
BinaryExpression setPropertyValue;
|
||||
Expression getPropertyValue;
|
||||
MemberExpression member;
|
||||
switch (property.Body)
|
||||
{
|
||||
case UnaryExpression
|
||||
{
|
||||
Operand: MemberExpression member1
|
||||
} body:
|
||||
{
|
||||
getPropertyValue = body;
|
||||
setPropertyValue = Expression.Assign(member1, Expression.Convert(propertyValue, member1.Type));
|
||||
member = member1;
|
||||
break;
|
||||
}
|
||||
case MemberExpression member2:
|
||||
{
|
||||
getPropertyValue = member = member2;
|
||||
setPropertyValue = Expression.Assign(member2, propertyValue);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return ThrowHelper
|
||||
.Argument<Expression<Func<TSettings1, TValue1>>, SettingsEntryInfo<TSettings1, TValue1>>(property);
|
||||
}
|
||||
|
||||
var getter = Expression.Lambda<Func<TSettings1, TValue1>>(getPropertyValue, parameter).Compile();
|
||||
var setter = Expression.Lambda<Action<TSettings1, TValue1>>(setPropertyValue, parameter, propertyValue).Compile();
|
||||
return new (getter, setter, member);
|
||||
}
|
||||
|
||||
public record SettingsEntryInfo<TSettings1, TValue1>(
|
||||
Func<TSettings1, TValue1> Getter,
|
||||
Action<TSettings1, TValue1> Setter,
|
||||
MemberExpression Member);
|
||||
}
|
||||
|
@ -186,24 +186,6 @@
|
||||
<data name="MicaAltBackdrop" xml:space="preserve">
|
||||
<value>Mica Alt(更鲜艳的云母)材质</value>
|
||||
</data>
|
||||
<data name="SearchDurationUndecided" xml:space="preserve">
|
||||
<value>默认</value>
|
||||
</data>
|
||||
<data name="SearchDurationWithinLastDay" xml:space="preserve">
|
||||
<value>一天内</value>
|
||||
</data>
|
||||
<data name="SearchDurationWithinLastWeek" xml:space="preserve">
|
||||
<value>一周内</value>
|
||||
</data>
|
||||
<data name="SearchDurationWithinLastMonth" xml:space="preserve">
|
||||
<value>一月内</value>
|
||||
</data>
|
||||
<data name="SearchDurationWithinLastHalfYear" xml:space="preserve">
|
||||
<value>半年内</value>
|
||||
</data>
|
||||
<data name="SearchDurationWithinLastYear" xml:space="preserve">
|
||||
<value>一年内</value>
|
||||
</data>
|
||||
<data name="PrivacyPolicyPublic" xml:space="preserve">
|
||||
<value>公开</value>
|
||||
</data>
|
||||
@ -381,4 +363,4 @@
|
||||
<data name="GoToPageFormatted" xml:space="preserve">
|
||||
<value>去{0}页</value>
|
||||
</data>
|
||||
</root>
|
||||
</root>
|
@ -525,18 +525,6 @@
|
||||
<data name="ReverseSearchResultSimilarityThresholdEntry.Header" xml:space="preserve">
|
||||
<value>逆向搜索阈值</value>
|
||||
</data>
|
||||
<data name="SearchDurationEntry.Description" xml:space="preserve">
|
||||
<value>搜索结果将会被限制在指定的时间区间内,如果”使用更精确的搜索范围限制“启用则此项被忽略</value>
|
||||
</data>
|
||||
<data name="SearchDurationEntry.Header" xml:space="preserve">
|
||||
<value>搜索范围限制</value>
|
||||
</data>
|
||||
<data name="SearchEndDateEntry.Description" xml:space="preserve">
|
||||
<value>搜索结果只会包含该日期以前提交的作品,该设置项的值必须比起始日期的值大至少1</value>
|
||||
</data>
|
||||
<data name="SearchEndDateEntry.Header" xml:space="preserve">
|
||||
<value>设置搜索的结束日期</value>
|
||||
</data>
|
||||
<data name="BrowseOriginalImageEntry.Description" xml:space="preserve">
|
||||
<value>浏览原图需要更多流量和时间加载,但也可以获得更好的浏览体验和更快的下载速度</value>
|
||||
</data>
|
||||
@ -546,15 +534,6 @@
|
||||
<data name="SearchSettingsGroup.Text" xml:space="preserve">
|
||||
<value>搜索设置</value>
|
||||
</data>
|
||||
<data name="SearchStartCalendarDatePicker.PlaceholderText" xml:space="preserve">
|
||||
<value>起始日期</value>
|
||||
</data>
|
||||
<data name="SearchStartDateEntry.Description" xml:space="preserve">
|
||||
<value>搜索结果只会包含该日期以后提交的作品</value>
|
||||
</data>
|
||||
<data name="SearchStartDateEntry.Header" xml:space="preserve">
|
||||
<value>设置搜索的起始日期</value>
|
||||
</data>
|
||||
<data name="SessionSettingsGroup.Text" xml:space="preserve">
|
||||
<value>会话设置</value>
|
||||
</data>
|
||||
@ -615,12 +594,6 @@
|
||||
<data name="UseFileCacheEntry.Header" xml:space="preserve">
|
||||
<value>使用文件缓存</value>
|
||||
</data>
|
||||
<data name="UsePreciseRangeForSearchEntry.Description" xml:space="preserve">
|
||||
<value>使用更精确的(基于准确日期)的搜索范围限制,搜索结果将会被限制在指定的时间区间内,如果该项被启用则“搜索范围限制”一栏将会被忽略</value>
|
||||
</data>
|
||||
<data name="UsePreciseRangeForSearchEntry.Header" xml:space="preserve">
|
||||
<value>使用更精确的搜索范围限制</value>
|
||||
</data>
|
||||
<data name="VersionSettingsGroup.Text" xml:space="preserve">
|
||||
<value>版本</value>
|
||||
</data>
|
||||
@ -753,4 +726,16 @@
|
||||
<data name="UpscalerOutputTypeEntry.Description" xml:space="preserve">
|
||||
<value>默认为PNG</value>
|
||||
</data>
|
||||
</root>
|
||||
<data name="UseSearchEndDateEntry.Header" xml:space="preserve">
|
||||
<value>启用搜索结束日期</value>
|
||||
</data>
|
||||
<data name="UseSearchStartDateEntry.Header" xml:space="preserve">
|
||||
<value>启用搜索开始日期</value>
|
||||
</data>
|
||||
<data name="UseSearchStartDateEntry.Description" xml:space="preserve">
|
||||
<value>启用后搜索作品的投稿日期将从此日期开始</value>
|
||||
</data>
|
||||
<data name="UseSearchEndDateEntry.Description" xml:space="preserve">
|
||||
<value>启用后搜索作品的投稿日期将到此日期结束</value>
|
||||
</data>
|
||||
</root>
|
@ -122,15 +122,6 @@ public static partial class ElementThemeExtension;
|
||||
[AttachedLocalizedResource(nameof(WorkSortOption.DoNotSort), nameof(MiscResources.WorkSortOptionDoNotSort))]
|
||||
public static partial class WorkSortOptionExtension;
|
||||
|
||||
[AttachedLocalizationMetadata<SearchDuration>(typeof(MiscResources))]
|
||||
[AttachedLocalizedResource(nameof(SearchDuration.Undecided), nameof(MiscResources.SearchDurationUndecided))]
|
||||
[AttachedLocalizedResource(nameof(SearchDuration.WithinLastDay), nameof(MiscResources.SearchDurationWithinLastDay))]
|
||||
[AttachedLocalizedResource(nameof(SearchDuration.WithinLastWeek), nameof(MiscResources.SearchDurationWithinLastWeek))]
|
||||
[AttachedLocalizedResource(nameof(SearchDuration.WithinLastMonth), nameof(MiscResources.SearchDurationWithinLastMonth))]
|
||||
[AttachedLocalizedResource(nameof(SearchDuration.WithinLastHalfYear), nameof(MiscResources.SearchDurationWithinLastHalfYear))]
|
||||
[AttachedLocalizedResource(nameof(SearchDuration.WithinLastYear), nameof(MiscResources.SearchDurationWithinLastYear))]
|
||||
public static partial class SearchDurationExtension;
|
||||
|
||||
[AttachedLocalizationMetadata<PrivacyPolicy>(typeof(MiscResources))]
|
||||
[AttachedLocalizedResource(nameof(PrivacyPolicy.Public), nameof(MiscResources.PrivacyPolicyPublic))]
|
||||
[AttachedLocalizedResource(nameof(PrivacyPolicy.Private), nameof(MiscResources.PrivacyPolicyPrivate))]
|
||||
|
Loading…
Reference in New Issue
Block a user