Skip to content

Commit ea4873c

Browse files
committed
换到国际服后无法正常换回官服 #24 #33
1 parent 66820ac commit ea4873c

File tree

1 file changed

+17
-3
lines changed
  • src/Snap.Hutao.Remastered/Snap.Hutao.Remastered/Core/IO/Hashing

1 file changed

+17
-3
lines changed

src/Snap.Hutao.Remastered/Snap.Hutao.Remastered/Core/IO/Hashing/Hash.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) DGP Studio. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using Snap.Hutao.Remastered.Win32;
5+
using Snap.Hutao.Remastered.Win32.Foundation;
46
using System.IO;
57
using System.Security.Cryptography;
68
using System.Text;
@@ -31,9 +33,21 @@ public static async ValueTask<string> ToHexStringAsync(HashAlgorithmName hashAlg
3133

3234
public static async ValueTask<string> FileToHexStringAsync(HashAlgorithmName hashAlgorithm, string filePath, CancellationToken token = default)
3335
{
34-
using (FileStream stream = File.OpenRead(filePath))
36+
// First try to open the file directly
37+
try
3538
{
36-
return await ToHexStringAsync(hashAlgorithm, stream, token).ConfigureAwait(false);
39+
using (FileStream stream = File.OpenRead(filePath))
40+
{
41+
return await ToHexStringAsync(hashAlgorithm, stream, token).ConfigureAwait(false);
42+
}
43+
}
44+
catch (IOException ex) when (HutaoNative.IsWin32(ex.HResult, WIN32_ERROR.ERROR_ENCRYPTION_FAILED))
45+
{
46+
// File is encrypted, copy to temp file and hash
47+
using (TempFileStream tempStream = TempFileStream.CopyFrom(filePath, FileMode.Open, FileAccess.Read))
48+
{
49+
return await ToHexStringAsync(hashAlgorithm, tempStream, token).ConfigureAwait(false);
50+
}
3751
}
3852
}
39-
}
53+
}

0 commit comments

Comments
 (0)