DvdKhl / AVDump3

Metadata Extraction Tool for Media Files
MIT License
32 stars 8 forks source link

Fix output redirection on windows + more #62

Closed revam closed 8 months ago

revam commented 1 year ago

Running AVDump3CL.exe on Windows in a sub-process with output redirection currently leads to AVDump3 erring out every time it tries to manipulate the cursor since the cursor manipulation on Windows uses WinAPIs and requires a console window to function, which is not available for sub-process ran in C# with output redirection enabled. I'll also note that this is not a problem on linux, just on windows.

This PR fixes the issue by just not trying to manipulate the cursor position if we cannot manipulate the cursor checking the pre-existing canManipulateCursor property before trying to do any cursor manipulation in the console class.

The error that is repeated over and over on standard output;

Unhandled exception. System.IO.IOException: The handle is invalid.
at System.ConsolePal.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
at System.ConsolePal.GetCursorPosition()
at AVDump3CL.AVD3Console.OnWriteProgress(Object _)
at System.Threading.TimerQueueTimer.<>c.<.cctor>b__27_0(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.TimerQueueTimer.CallCallback(Boolean isThreadPool)
at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool)
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.AppDomainTimerCallback(Int32 id)
Unhandled exception. System.IO.IOException: The handle is invalid.
at System.ConsolePal.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
at System.ConsolePal.GetCursorPosition()
at AVDump3CL.AVD3Console.OnWriteProgress(Object _)
at System.Threading.TimerQueueTimer.<>c.<.cctor>b__27_0(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.TimerQueueTimer.CallCallback(Boolean isThreadPool)
at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool)
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.AppDomainTimerCallback(Int32 id)
revam commented 1 year ago

Added another commit that fixes division by zero when the display width is 0 for whatever reason. This was only an issue when running it in a sub-process on linux, not on windows, and only on some systems, not all.