@@ -17,6 +17,9 @@ public static async Task<bool> DecryptAsync(DecryptEngine decryptEngine, string
1717 var keyPairs = keys . ToList ( ) ;
1818 string ? keyPair = null ;
1919 string ? trackId = null ;
20+ string ? tmpEncFile = null ;
21+ string ? tmpDecFile = null ;
22+ string ? workDir = null ;
2023
2124 if ( isMultiDRM )
2225 {
@@ -79,7 +82,12 @@ public static async Task<bool> DecryptAsync(DecryptEngine decryptEngine, string
7982 {
8083 cmd += $ " --fragments-info \" { init } \" ";
8184 }
82- cmd += $ " \" { source } \" \" { dest } \" ";
85+ // 解决mp4decrypt中文问题 切换到源文件所在目录并改名再解密
86+ workDir = Path . GetDirectoryName ( source ) ! ;
87+ tmpEncFile = Path . Combine ( workDir , $ "{ Guid . NewGuid ( ) } { Path . GetExtension ( source ) } ") ;
88+ tmpDecFile = Path . Combine ( workDir , $ "{ Path . GetFileNameWithoutExtension ( tmpEncFile ) } _dec{ Path . GetExtension ( tmpEncFile ) } ") ;
89+ File . Move ( source , tmpEncFile ) ;
90+ cmd += $ " \" { Path . GetFileName ( tmpEncFile ) } \" \" { Path . GetFileName ( tmpDecFile ) } \" ";
8391 }
8492 else
8593 {
@@ -95,30 +103,41 @@ public static async Task<bool> DecryptAsync(DecryptEngine decryptEngine, string
95103 cmd = $ "-loglevel error -nostdin -decryption_key { keyPair . Split ( ':' ) [ 1 ] } -i \" { enc } \" -c copy \" { dest } \" ";
96104 }
97105
98- await RunCommandAsync ( bin , cmd ) ;
106+ var isSuccess = await RunCommandAsync ( bin , cmd , workDir ) ;
107+
108+ // mp4decrypt 还原文件改名操作
109+ if ( workDir is not null )
110+ {
111+ if ( File . Exists ( tmpEncFile ) ) File . Move ( tmpEncFile , source ) ;
112+ if ( File . Exists ( tmpDecFile ) ) File . Move ( tmpDecFile , dest ) ;
113+ }
99114
100- if ( File . Exists ( dest ) && new FileInfo ( dest ) . Length > 0 )
115+ if ( isSuccess )
101116 {
102117 if ( tmpFile != "" && File . Exists ( tmpFile ) ) File . Delete ( tmpFile ) ;
103118 return true ;
104119 }
105-
120+
121+ Logger . Error ( ResString . decryptionFailed ) ;
106122 return false ;
107123 }
108124
109- private static async Task RunCommandAsync ( string name , string arg )
125+ private static async Task < bool > RunCommandAsync ( string name , string arg , string ? workDir = null )
110126 {
111127 Logger . DebugMarkUp ( $ "FileName: { name } ") ;
112128 Logger . DebugMarkUp ( $ "Arguments: { arg } ") ;
113- await Process . Start ( new ProcessStartInfo ( )
129+ var process = Process . Start ( new ProcessStartInfo ( )
114130 {
115131 FileName = name ,
116132 Arguments = arg ,
117133 // RedirectStandardOutput = true,
118134 // RedirectStandardError = true,
119135 CreateNoWindow = true ,
120- UseShellExecute = false
121- } ) ! . WaitForExitAsync ( ) ;
136+ UseShellExecute = false ,
137+ WorkingDirectory = workDir
138+ } ) ;
139+ await process ! . WaitForExitAsync ( ) ;
140+ return process . ExitCode == 0 ;
122141 }
123142
124143 /// <summary>
0 commit comments