File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed
src/Snap.Hutao.Remastered/Snap.Hutao.Remastered/Core/IO/Hashing Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 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 ;
46using System . IO ;
57using System . Security . Cryptography ;
68using 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+ }
You can’t perform that action at this time.
0 commit comments