Allow import plain text even if file is in use - thx darnn :)

Fix #2642
This commit is contained in:
Nikolaj Olsson 2017-11-23 22:16:12 +01:00
parent 5b97f42f51
commit ca6d9d54fd
2 changed files with 12 additions and 2 deletions

View File

@ -39,6 +39,16 @@ namespace Nikse.SubtitleEdit.Core
}
}
public static string[] ReadAllLinesShared(string path, Encoding encoding)
{
return encoding.GetString(ReadAllBytesShared(path)).SplitToLines();
}
public static string ReadAllTextShared(string path, Encoding encoding)
{
return encoding.GetString(ReadAllBytesShared(path));
}
public static bool IsZip(string fileName)
{
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))

View File

@ -150,7 +150,7 @@ namespace Nikse.SubtitleEdit.Forms
ext = extension.ToLowerInvariant();
var fd = new FinalDraftTemplate2();
var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
var list = new List<string>(FileUtil.ReadAllLinesShared(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
bool isFinalDraft = fd.IsMine(list, fileName);
if (ext == ".astx")
@ -694,7 +694,7 @@ namespace Nikse.SubtitleEdit.Forms
try
{
Encoding encoding = LanguageAutoDetect.GetEncodingFromFile(fileName);
var text = File.ReadAllText(fileName, encoding);
var text = FileUtil.ReadAllTextShared(fileName, encoding);
if (fileName.EndsWith(".htm", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".htm", StringComparison.OrdinalIgnoreCase))
text = HtmlToPlainText(text);
return text;