@@ -14653,20 +14653,20 @@ private async Task<bool> LoadMatroskaSubtitle(
1465314653
1465414654 if (matroskaSubtitleInfo.CodecId.Equals("S_HDMV/TEXTST", StringComparison.OrdinalIgnoreCase))
1465514655 {
14656- return LoadTextSTFromMatroska(matroskaSubtitleInfo, matroska);
14656+ return await LoadTextSTFromMatroska(matroskaSubtitleInfo, matroska);
1465714657 }
1465814658
1465914659 if (matroskaSubtitleInfo.CodecId.Equals("S_DVBSUB", StringComparison.OrdinalIgnoreCase))
1466014660 {
14661- return LoadDvbFromMatroska(matroskaSubtitleInfo, matroska, fileName);
14661+ return await LoadDvbFromMatroska(matroskaSubtitleInfo, matroska, fileName);
1466214662 }
1466314663
1466414664 if (matroskaSubtitleInfo.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase))
1466514665 {
1466614666 return await LoadVobSubFromMatroska(matroskaSubtitleInfo, matroska, fileName);
1466714667 }
1466814668
14669- var sub = matroska.GetSubtitle( matroskaSubtitleInfo.TrackNumber, null );
14669+ var sub = await ExtractMatroskaSubtitleAsync(matroska, matroskaSubtitleInfo.TrackNumber);
1467014670 var subtitle = new Subtitle();
1467114671 var format = Utilities.LoadMatroskaTextSubtitle(matroskaSubtitleInfo, matroska, sub, subtitle);
1467214672 VideoCloseFile();
@@ -14684,10 +14684,10 @@ private static bool IsImageSubtitleTrack(MatroskaTrackInfo track) =>
1468414684 track.CodecId.Equals("S_DVBSUB", StringComparison.OrdinalIgnoreCase) ||
1468514685 track.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase);
1468614686
14687- private bool LoadDvbFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska, string fileName)
14687+ private async Task< bool> LoadDvbFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska, string fileName)
1468814688 {
1468914689 ShowStatus(Se.Language.Main.ParsingMatroskaFile);
14690- var sub = matroska.GetSubtitle( matroskaSubtitleInfo.TrackNumber, MatroskaProgress );
14690+ var sub = await ExtractMatroskaSubtitleAsync(matroska, matroskaSubtitleInfo.TrackNumber);
1469114691
1469214692 _subtitle.Paragraphs.Clear();
1469314693 var subtitleImages = new List<DvbSubPes>();
@@ -14805,7 +14805,7 @@ await MessageBox.Show(Window!, Se.Language.General.Error, message, MessageBoxBut
1480514805 return false;
1480614806 }
1480714807
14808- var sub = matroska.GetSubtitle( matroskaSubtitleInfo.TrackNumber, MatroskaProgress );
14808+ var sub = await ExtractMatroskaSubtitleAsync(matroska, matroskaSubtitleInfo.TrackNumber);
1480914809 _subtitle.Paragraphs.Clear();
1481014810
1481114811 List<VobSubMergedPack> mergedVobSubPacks = [];
@@ -14863,15 +14863,49 @@ await MessageBox.Show(Window!, Se.Language.General.Error, message, MessageBoxBut
1486314863 return false;
1486414864 }
1486514865
14866- private void MatroskaProgress(long position, long total)
14866+ // Files smaller than this parse fast enough that a progress window would only
14867+ // flash; above it the extraction can take long enough to warrant feedback.
14868+ private const long MatroskaProgressWindowMinFileSize = 25 * 1024 * 1024; // 25 MB
14869+
14870+ /// <summary>
14871+ /// Extracts a Matroska track's blocks on a background thread so the UI stays
14872+ /// responsive, showing a determinate "Please wait..." window with percentage
14873+ /// progress for large files. Must be called on the UI thread.
14874+ /// </summary>
14875+ private async Task<List<MatroskaSubtitle>> ExtractMatroskaSubtitleAsync(MatroskaFile matroska, int trackNumber)
1486714876 {
14868- // UpdateProgress(position, total, _language.ParsingMatroskaFile);
14877+ PleaseWaitViewModel? pleaseWaitVm = null;
14878+ long fileSize = 0;
14879+ try
14880+ {
14881+ fileSize = new FileInfo(matroska.Path).Length;
14882+ }
14883+ catch
14884+ {
14885+ // ignore - just means no size-based gating
14886+ }
14887+
14888+ if (fileSize >= MatroskaProgressWindowMinFileSize)
14889+ {
14890+ pleaseWaitVm = _windowService.ShowWindow<PleaseWaitWindow, PleaseWaitViewModel>(Window!);
14891+ pleaseWaitVm.StatusText = Se.Language.Main.ParsingMatroskaFile;
14892+ }
14893+
14894+ try
14895+ {
14896+ var vm = pleaseWaitVm;
14897+ return await Task.Run(() => matroska.GetSubtitle(trackNumber, (pos, total) => vm?.ReportProgress(pos, total)));
14898+ }
14899+ finally
14900+ {
14901+ pleaseWaitVm?.Close();
14902+ }
1486914903 }
1487014904
14871- private bool LoadTextSTFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska)
14905+ private async Task< bool> LoadTextSTFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska)
1487214906 {
1487314907 ShowStatus(Se.Language.Main.ParsingMatroskaFile);
14874- var sub = matroska.GetSubtitle( matroskaSubtitleInfo.TrackNumber, MatroskaProgress );
14908+ var sub = await ExtractMatroskaSubtitleAsync(matroska, matroskaSubtitleInfo.TrackNumber);
1487514909
1487614910 VideoCloseFile();
1487714911 _subtitle.Paragraphs.Clear();
0 commit comments