Skip to content

Commit

Permalink
Merge pull request #1818 from DGP-Studio/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx authored Jul 17, 2024
2 parents ab20aa1 + 4e7f8e2 commit a259750
Show file tree
Hide file tree
Showing 200 changed files with 3,833 additions and 2,733 deletions.
1 change: 0 additions & 1 deletion src/Snap.Hutao/Snap.Hutao/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Snap.Hutao.Core.LifeCycle;
using Snap.Hutao.Core.LifeCycle.InterProcess;
using Snap.Hutao.Core.Logging;
using Snap.Hutao.UI.Xaml;
using System.Diagnostics;

namespace Snap.Hutao;
Expand Down
28 changes: 0 additions & 28 deletions src/Snap.Hutao/Snap.Hutao/AppResourceProvider.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal sealed class AdvancedDbCollectionView<TEntity> : AdvancedCollectionView
private bool savingToDatabase = true;

public AdvancedDbCollectionView(IList<TEntity> source, IServiceProvider serviceProvider)
: base(source, true)
: base(source)
{
this.serviceProvider = serviceProvider;
}
Expand All @@ -30,14 +30,14 @@ public IDisposable SuppressChangeCurrentItem()

protected override void OnCurrentChangedOverride()
{
if (serviceProvider is null || !savingToDatabase)
if (!savingToDatabase)
{
return;
}

TEntity? currentItem = CurrentItem;

foreach (TEntity item in Source)
foreach (TEntity item in SourceCollection)
{
item.IsSelected = ReferenceEquals(item, currentItem);
}
Expand Down Expand Up @@ -85,7 +85,7 @@ internal sealed class AdvancedDbCollectionView<TEntityAccess, TEntity> : Advance
private bool savingToDatabase = true;

public AdvancedDbCollectionView(IList<TEntityAccess> source, IServiceProvider serviceProvider)
: base(source, true)
: base(source)
{
this.serviceProvider = serviceProvider;
}
Expand All @@ -97,14 +97,14 @@ public IDisposable SuppressChangeCurrentItem()

protected override void OnCurrentChangedOverride()
{
if (serviceProvider is null || !savingToDatabase)
if (!savingToDatabase)
{
return;
}

TEntityAccess? currentItem = CurrentItem;

foreach (TEntityAccess item in Source)
foreach (TEntityAccess item in SourceCollection)
{
item.Entity.IsSelected = ReferenceEquals(item, currentItem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ internal static class SelectableExtension
{
return source.SingleOrDefault(i => i.IsSelected);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TSource? SelectedOrFirstOrDefault<TSource>(this IEnumerable<TSource> source)
where TSource : ISelectable
{
return source.SingleOrDefault(i => i.IsSelected) ?? source.FirstOrDefault();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ public static NotSupportedException NotSupported(string? message = default, Exce
throw new NotSupportedException(message, innerException);
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void NotSupportedIf(bool condition, string? message = default, Exception? innerException = default)
{
if (condition)
{
throw new NotSupportedException(message, innerException);
}
}

[DoesNotReturn]
[MethodImpl(MethodImplOptions.NoInlining)]
public static OperationCanceledException OperationCanceled(string message, Exception? innerException = default)
Expand Down
3 changes: 1 addition & 2 deletions src/Snap.Hutao/Snap.Hutao/Core/IO/ValueFileExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ internal static class ValueFileExtension
return new(true, t);
}
}
catch (Exception ex)
catch (Exception)
{
_ = ex;
return new(false, null);
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/Core/Json/Converter/DateTimeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using System.Globalization;

namespace Snap.Hutao.Core.Json.Converter;

internal sealed class DateTimeConverter : JsonConverter<DateTime>
{
private const string Format = "yyyy-MM-dd HH:mm:ss";

public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.GetString() is { } dataTimeString)
{
return DateTime.ParseExact(dataTimeString, Format, CultureInfo.InvariantCulture);
}

return default;
}

public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString(Format, CultureInfo.InvariantCulture));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Snap.Hutao.Core.Json.Converter;

// 此转换器无法实现无损往返 必须在反序列化后调整 Offset
internal class DateTimeOffsetConverter : JsonConverter<DateTimeOffset>
internal sealed class DateTimeOffsetConverter : JsonConverter<DateTimeOffset>
{
private const string Format = "yyyy-MM-dd HH:mm:ss";

Expand Down
7 changes: 7 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi

private readonly ICurrentXamlWindowReference currentWindowReference;
private readonly IServiceProvider serviceProvider;
private readonly RuntimeOptions runtimeOptions;
private readonly ILogger<AppActivation> logger;
private readonly ITaskContext taskContext;

Expand Down Expand Up @@ -257,6 +258,12 @@ private async ValueTask HandleLaunchActivationAsync(bool isRedirectTo)
guideWindow.BringToForeground();
return;
}

if (Version.Parse(LocalSetting.Get(SettingKeys.LastVersion, "0.0.0.0")) < runtimeOptions.Version)
{
XamlApplicationLifetime.IsFirstRunAfterUpdate = true;
LocalSetting.Set(SettingKeys.LastVersion, $"{runtimeOptions.Version}");
}
}

await WaitMainWindowOrCurrentAsync().ConfigureAwait(false);
Expand Down
2 changes: 2 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/Core/Setting/SettingKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal static class SettingKeys
#endregion

#region Application
public const string LastVersion = "LastVersion";
public const string LaunchTimes = "LaunchTimes";
public const string DataFolderPath = "DataFolderPath";
public const string Major1Minor10Revision0GuideState = "Major1Minor10Revision0GuideState1";
Expand Down Expand Up @@ -63,6 +64,7 @@ internal static class SettingKeys
public const string OverrideElevationRequirement = "OverrideElevationRequirement";
public const string OverrideUpdateVersionComparison = "OverrideUpdateVersionComparison";
public const string OverridePackageConvertDirectoryPermissionsRequirement = "OverridePackageConvertDirectoryPermissionsRequirement";
public const string AlwaysIsFirstRunAfterUpdate = "AlwaysIsFirstRunAfterUpdate";
#endregion

#region Obsolete
Expand Down
19 changes: 0 additions & 19 deletions src/Snap.Hutao/Snap.Hutao/Core/Threading/Abstraction/IAwaitable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,14 @@

namespace Snap.Hutao.Core.Threading.Abstraction;

/// <summary>
/// 表示一个可等待对象,如果一个方法返回此类型的实例,则此方法可以使用 <see langword="await"/> 异步等待。
/// </summary>
/// <typeparam name="TAwaiter">用于给 await 确定返回时机的 IAwaiter 的实例。</typeparam>
internal interface IAwaitable<out TAwaiter>
where TAwaiter : IAwaiter
{
/// <summary>
/// 获取一个可用于 await 关键字异步等待的异步等待对象。
/// 此方法会被编译器自动调用。
/// </summary>
/// <returns>等待器</returns>
TAwaiter GetAwaiter();
}

/// <summary>
/// 表示一个包含返回值的可等待对象,如果一个方法返回此类型的实例,则此方法可以使用 <see langword="await"/> 异步等待返回值。
/// </summary>
/// <typeparam name="TAwaiter">用于给 await 确定返回时机的 <see cref="IAwaiter{TResult}"/> 的实例。</typeparam>
/// <typeparam name="TResult">异步返回的返回值类型。</typeparam>
internal interface IAwaitable<out TAwaiter, out TResult>
where TAwaiter : IAwaiter<TResult>
{
/// <summary>
/// 获取一个可用于 await 关键字异步等待的异步等待对象。
/// 此方法会被编译器自动调用。
/// </summary>
/// <returns>等待器</returns>
TAwaiter GetAwaiter();
}
22 changes: 0 additions & 22 deletions src/Snap.Hutao/Snap.Hutao/Core/Threading/Abstraction/IAwaiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,16 @@

namespace Snap.Hutao.Core.Threading.Abstraction;

/// <summary>
/// 用于给 await 确定异步返回的时机。
/// </summary>
internal interface IAwaiter : INotifyCompletion
{
/// <summary>
/// 获取一个状态,该状态表示正在异步等待的操作已经完成(成功完成或发生了异常);此状态会被编译器自动调用。
/// 在实现中,为了达到各种效果,可以灵活应用其值:可以始终为 true,或者始终为 false。
/// </summary>
bool IsCompleted { get; }

/// <summary>
/// 此方法会被编译器在 await 结束时自动调用以获取返回状态(包括异常)。
/// </summary>
void GetResult();
}

/// <summary>
/// 用于给 await 确定异步返回的时机,并获取到返回值。
/// </summary>
/// <typeparam name="TResult">异步返回的返回值类型。</typeparam>
internal interface IAwaiter<out TResult> : INotifyCompletion
{
/// <summary>
/// 获取一个状态,该状态表示正在异步等待的操作已经完成(成功完成或发生了异常);此状态会被编译器自动调用。
/// 在实现中,为了达到各种效果,可以灵活应用其值:可以始终为 true,或者始终为 false。
/// </summary>
bool IsCompleted { get; }

/// <summary>
/// 获取此异步等待操作的返回值,此方法会被编译器在 await 结束时自动调用以获取返回值(包括异常)。
/// </summary>
/// <returns>异步操作的返回值。</returns>
TResult GetResult();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@

namespace Snap.Hutao.Core.Threading.Abstraction;

/// <summary>
/// 当执行关键代码(此代码中的错误可能给应用程序中的其他状态造成负面影响)时,
/// 用于给 await 确定异步返回的时机。
/// </summary>
internal interface ICriticalAwaiter : IAwaiter, ICriticalNotifyCompletion
{
}

/// <summary>
/// 当执行关键代码(此代码中的错误可能给应用程序中的其他状态造成负面影响)时,
/// 用于给 await 确定异步返回的时机,并获取到返回值。
/// </summary>
/// <typeparam name="TResult">异步返回的返回值类型。</typeparam>
internal interface ICriticalAwaiter<out TResult> : IAwaiter<TResult>, ICriticalNotifyCompletion
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public DispatcherQueueSwitchOperation(DispatcherQueue dispatherQueue)

public bool IsCompleted
{
// Only yields when we are not on the DispatcherQueue thread.
get => dispatherQueue.HasThreadAccess;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ThreadPoolSwitchOperation(DispatcherQueue dispatherQueue)

public bool IsCompleted
{
// 如果已经处于后台就不再切换新的线程
// Only yields when we are on the DispatcherQueue thread.
get => !dispatherQueue.HasThreadAccess;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Extension/CollectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Snap.Hutao.Extension;
internal static class CollectionExtension
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNullOrEmpty<TSource>([NotNullWhen(false)][MaybeNullWhen(true)] this Collection<TSource>? source)
public static bool IsNullOrEmpty<TSource>([NotNullWhen(false)][MaybeNullWhen(true)] this ICollection<TSource>? source)
{
if (source is { Count: > 0 })
{
Expand Down
11 changes: 0 additions & 11 deletions src/Snap.Hutao/Snap.Hutao/Extension/ListExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ public static List<T> GetRange<T>(this List<T> list, in Range range)
return list.GetRange(start, length);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNullOrEmpty<TSource>([NotNullWhen(false)][MaybeNullWhen(true)] this List<TSource>? source)
{
if (source is { Count: > 0 })
{
return false;
}

return true;
}

public static void RemoveLast<T>(this IList<T> collection)
{
collection.RemoveAt(collection.Count - 1);
Expand Down
18 changes: 0 additions & 18 deletions src/Snap.Hutao/Snap.Hutao/IAppResourceProvider.cs

This file was deleted.

14 changes: 0 additions & 14 deletions src/Snap.Hutao/Snap.Hutao/Model/Calculable/CalculableOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,12 @@

namespace Snap.Hutao.Model.Calculable;

/// <summary>
/// 可计算物品选项
/// </summary>
internal readonly struct CalculableOptions
{
/// <summary>
/// 角色
/// </summary>
public readonly ICalculableAvatar? Avatar;

/// <summary>
/// 武器
/// </summary>
public readonly ICalculableWeapon? Weapon;

/// <summary>
/// 构造一个新的可计算物品选项
/// </summary>
/// <param name="avatar">角色</param>
/// <param name="weapon">武器</param>
public CalculableOptions(ICalculableAvatar? avatar, ICalculableWeapon? weapon)
{
Avatar = avatar;
Expand Down
Loading

0 comments on commit a259750

Please sign in to comment.