Skip to content

Commit 4e4c881

Browse files
authored
Merge branch 'develop' into develop
2 parents 6b445d0 + 3d4219a commit 4e4c881

22 files changed

+160
-579
lines changed

src/Snap.Hutao/Snap.Hutao/Core/DependencyInjection/Abstraction/DriverMediaTypeAwareFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal abstract partial class DriverMediaTypeAwareFactory<TService, TServiceSS
1515

1616
public virtual TService Create(string path)
1717
{
18-
return (PhysicalDriver.GetIsSolidState(path) ?? false)
18+
return (PhysicalDrive.GetIsSolidState(path) ?? false)
1919
? serviceProvider.GetRequiredService<TServiceSSD>()
2020
: serviceProvider.GetRequiredService<TServiceHDD>();
2121
}

src/Snap.Hutao/Snap.Hutao/Core/DependencyInjection/DependencyInjection.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using CommunityToolkit.Mvvm.Messaging;
55
using Microsoft.EntityFrameworkCore;
66
using Quartz;
7-
using Snap.Hutao.Core.ExceptionService;
87
using Snap.Hutao.Core.Logging;
98
using Snap.Hutao.Service;
109
using Snap.Hutao.Service.Notification;
@@ -52,7 +51,6 @@ public static Implementation.ServiceProvider Initialize()
5251

5352
Ioc.Default.ConfigureServices(serviceProvider);
5453

55-
serviceProvider.InitializeConsoleWindow();
5654
serviceProvider.InitializeCulture();
5755
serviceProvider.InitializeNotification();
5856

@@ -89,12 +87,6 @@ private static void InitializeCulture(this IServiceProvider serviceProvider)
8987
logger.LogDebug("Current Culture: \e[1m\e[36m{Current}\e[37m", cultureInfo);
9088
}
9189

92-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
93-
private static void InitializeConsoleWindow(this IServiceProvider serviceProvider)
94-
{
95-
_ = serviceProvider.GetRequiredService<ConsoleWindowLifeTime>();
96-
}
97-
9890
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9991
private static void InitializeNotification(this IServiceProvider serviceProvider)
10092
{

src/Snap.Hutao/Snap.Hutao/Core/IO/LogicalDriver.cs renamed to src/Snap.Hutao/Snap.Hutao/Core/IO/LogicalDrive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Snap.Hutao.Core.IO;
77

8-
internal static class LogicalDriver
8+
internal static class LogicalDrive
99
{
1010
public static long GetAvailableFreeSpace(string path)
1111
{
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) DGP Studio. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using Snap.Hutao.Core.Setting;
5+
using Snap.Hutao.Win32;
6+
using System.IO;
7+
8+
namespace Snap.Hutao.Core.IO;
9+
10+
internal static class PhysicalDrive
11+
{
12+
/// <summary>
13+
/// Safely get the SSD information of the physical driver.
14+
/// </summary>
15+
/// <param name="path">path in a driver</param>
16+
/// <returns>
17+
/// <see langword="null"/> if any exception occurs,
18+
/// <see langword="true"/> if it's a SSD,
19+
/// otherwise <see langword="false"/>
20+
/// </returns>
21+
public static bool? GetIsSolidState(string path)
22+
{
23+
try
24+
{
25+
return DangerousGetIsSolidState(path);
26+
}
27+
catch (Exception)
28+
{
29+
return null;
30+
}
31+
}
32+
33+
public static bool DangerousGetIsSolidState(string path)
34+
{
35+
if (LocalSetting.Get(SettingKeys.OverridePhysicalDriverType, false))
36+
{
37+
return LocalSetting.Get(SettingKeys.PhysicalDriverIsAlwaysSolidState, false);
38+
}
39+
40+
string? root = Path.GetPathRoot(path);
41+
ArgumentException.ThrowIfNullOrWhiteSpace(root, "The path does not contain a root.");
42+
return HutaoNative.Instance.MakePhysicalDrive().IsPathOnSolidStateDrive(root);
43+
}
44+
}

src/Snap.Hutao/Snap.Hutao/Core/IO/PhysicalDriver.cs

Lines changed: 0 additions & 173 deletions
This file was deleted.

src/Snap.Hutao/Snap.Hutao/Core/Logging/ConsoleWindowLifeTime.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/Snap.Hutao/Snap.Hutao/Core/Logging/LoggerFactoryExtension.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ internal static class LoggerFactoryExtension
1111
{
1212
public static ILoggingBuilder AddConsoleWindow(this ILoggingBuilder builder)
1313
{
14-
builder.Services.AddSingleton<ConsoleWindowLifeTime>();
15-
1614
builder.AddSimpleConsole(options =>
1715
{
1816
options.TimestampFormat = "yyyy-MM-dd HH:mm:ss.fff ";

src/Snap.Hutao/Snap.Hutao/Service/Game/LaunchOptions.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
using Snap.Hutao.Service.Game.Launching;
1111
using Snap.Hutao.Service.Game.Launching.Handler;
1212
using Snap.Hutao.Service.Game.PathAbstraction;
13-
using Snap.Hutao.Win32.Graphics.Gdi;
13+
using Snap.Hutao.Win32;
1414
using System.Collections.Immutable;
1515
using System.Globalization;
1616
using System.Runtime.InteropServices;
17-
using static Snap.Hutao.Win32.Gdi32;
18-
using static Snap.Hutao.Win32.User32;
1917

2018
namespace Snap.Hutao.Service.Game;
2119

@@ -358,16 +356,7 @@ public void Receive(LaunchExecutionProcessStatusChangedMessage message)
358356

359357
private static int InitializeScreenFps()
360358
{
361-
HDC dc = default;
362-
try
363-
{
364-
dc = GetDC();
365-
return GetDeviceCaps(dc, GET_DEVICE_CAPS_INDEX.VREFRESH);
366-
}
367-
finally
368-
{
369-
_ = ReleaseDC(default, dc);
370-
}
359+
return HutaoNative.Instance.MakeDeviceCapabilities().GetPrimaryScreenVerticalRefreshRate();
371360
}
372361

373362
private static ImmutableArray<NameValue<int>> InitializeMonitors()

src/Snap.Hutao/Snap.Hutao/Service/Game/Package/Advanced/GamePackageServiceOperationInformationTraits.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal sealed partial class GamePackageServiceOperationInformationTraits
4343
};
4444

4545
long actualTotalBytes = installTotalBytes + (1024L * 1024L * 1024L); // 1 GB for temp files
46-
long availableBytes = LogicalDriver.GetAvailableFreeSpace(context.EffectiveGameDirectory);
46+
long availableBytes = LogicalDrive.GetAvailableFreeSpace(context.EffectiveGameDirectory);
4747

4848
string formattedDownloadTotalBytes = Converters.ToFileSizeString(downloadTotalBytes);
4949
string formattedTotalBytes = Converters.ToFileSizeString(actualTotalBytes);

src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@
356356
<PrivateAssets>all</PrivateAssets>
357357
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
358358
</PackageReference>
359-
<PackageReference Include="Snap.Hutao.Native" Version="0.0.2">
359+
<PackageReference Include="Snap.Hutao.Native" Version="0.0.3">
360360
<PrivateAssets>all</PrivateAssets>
361361
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
362362
</PackageReference>

src/Snap.Hutao/Snap.Hutao/UI/Xaml/View/Dialog/LaunchGameInstallGameDialog.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public async ValueTask<ValueResult<bool, GameInstallOptions>> GetGameInstallOpti
7272

7373
private static void OnGameDirectoryChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
7474
{
75-
((LaunchGameInstallGameDialog)sender).IsParallelSupported = PhysicalDriver.GetIsSolidState((string)args.NewValue) ?? false;
75+
((LaunchGameInstallGameDialog)sender).IsParallelSupported = PhysicalDrive.GetIsSolidState((string)args.NewValue) ?? false;
7676
}
7777

7878
[Command("PickGameDirectoryCommand")]

src/Snap.Hutao/Snap.Hutao/ViewModel/TestViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private void CheckPathBelongsToSSD()
300300
(bool isOk, ValueFile file) = fileSystemPickerInteraction.PickFile("Pick any file!", default);
301301
if (isOk)
302302
{
303-
bool isSolidState = PhysicalDriver.DangerousGetIsSolidState(file);
303+
bool isSolidState = PhysicalDrive.DangerousGetIsSolidState(file);
304304
infoBarService.Success($"The path '{file}' belongs to a {(isSolidState ? "solid state" : "hard disk")} drive.");
305305
}
306306
}

0 commit comments

Comments
 (0)