mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 19:22:53 +01:00
Check if subtitle file contains only binary zeroes
This commit is contained in:
parent
3b19c51073
commit
36d2aefba8
@ -1278,6 +1278,9 @@ Continue?</SubtitleAppendPrompt>
|
||||
<ErrorLoadPng>This file seems to be a PNG image file. Subtitle Edit cannot open PNG files.</ErrorLoadPng>
|
||||
<ErrorLoadSrr>This file seems to be a ReScene .srr file - not a subtitle file.</ErrorLoadSrr>
|
||||
<ErrorLoadTorrent>This file seems to be a BitTorrent file - not a subtitle file.</ErrorLoadTorrent>
|
||||
<ErrorLoadBinaryZeroes>Sorry, this file contains only binary zeroes!
|
||||
|
||||
If you have edited this file with Subtitle Edit you might be alble to find a backup via the menu item File -> Restore auto-backup...</ErrorLoadBinaryZeroes>
|
||||
<NoSupportEncryptedVobSub>Encrypted VobSub content is not supported.</NoSupportEncryptedVobSub>
|
||||
<NoSupportHereBluRaySup>Blu-ray sup files are not supported here.</NoSupportHereBluRaySup>
|
||||
<NoSupportHereDvdSup>DVD sup files are not supported here.</NoSupportHereDvdSup>
|
||||
|
@ -292,5 +292,29 @@ namespace Nikse.SubtitleEdit.Core
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsSubtitleFileAllBinaryZeroes(string fileName)
|
||||
{
|
||||
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
if (fs.Length < 10)
|
||||
return false; // too short to be a proper subtitle file
|
||||
|
||||
int numberOfBytes = 1;
|
||||
var buffer = new byte[1024];
|
||||
while (numberOfBytes > 0)
|
||||
{
|
||||
numberOfBytes = fs.Read(buffer, 0, buffer.Length);
|
||||
for (int i = 0; i < numberOfBytes; i++)
|
||||
{
|
||||
if (buffer[i] > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2357,6 +2357,13 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
return;
|
||||
}
|
||||
|
||||
// check for all binary zeroes (I've heard about this a few times... perhaps related to crashes?)
|
||||
if (format == null && fi.Length > 50 && FileUtil.IsSubtitleFileAllBinaryZeroes(fileName))
|
||||
{
|
||||
MessageBox.Show(_language.ErrorLoadBinaryZeroes);
|
||||
return;
|
||||
}
|
||||
|
||||
if (format == null && fi.Length < 100 * 1000000 && TransportStreamParser.IsDvbSup(fileName))
|
||||
{
|
||||
ImportSubtitleFromDvbSupFile(fileName);
|
||||
|
@ -1181,6 +1181,7 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
ErrorLoadPng = "This file seems to be a PNG image file. Subtitle Edit cannot open PNG files.",
|
||||
ErrorLoadSrr = "This file seems to be a ReScene .srr file - not a subtitle file.",
|
||||
ErrorLoadTorrent = "This file seems to be a BitTorrent file - not a subtitle file.",
|
||||
ErrorLoadBinaryZeroes = "Sorry, this file contains only binary zeroes!\r\n\r\nIf you have edited this file with Subtitle Edit you might be alble to find a backup via the menu item File -> Restore auto-backup...",
|
||||
NoSupportEncryptedVobSub = "Encrypted VobSub content is not supported.",
|
||||
NoSupportHereBluRaySup = "Blu-ray sup files are not supported here.",
|
||||
NoSupportHereDvdSup = "DVD sup files are not supported here.",
|
||||
|
@ -2622,6 +2622,9 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
case "Main/ErrorLoadTorrent":
|
||||
language.Main.ErrorLoadTorrent = reader.Value;
|
||||
break;
|
||||
case "Main/ErrorLoadBinaryZeroes":
|
||||
language.Main.ErrorLoadBinaryZeroes = reader.Value;
|
||||
break;
|
||||
case "Main/NoSupportEncryptedVobSub":
|
||||
language.Main.NoSupportEncryptedVobSub = reader.Value;
|
||||
break;
|
||||
|
@ -1057,6 +1057,7 @@
|
||||
public string ErrorLoadPng { get; set; }
|
||||
public string ErrorLoadSrr { get; set; }
|
||||
public string ErrorLoadTorrent { get; set; }
|
||||
public string ErrorLoadBinaryZeroes { get; set; }
|
||||
public string NoSupportEncryptedVobSub { get; set; }
|
||||
public string NoSupportHereBluRaySup { get; set; }
|
||||
public string NoSupportHereDvdSup { get; set; }
|
||||
|
Loading…
Reference in New Issue
Block a user