diff --git a/LanguageBaseEnglish.xml b/LanguageBaseEnglish.xml
index e66c358aa..703f8b566 100644
--- a/LanguageBaseEnglish.xml
+++ b/LanguageBaseEnglish.xml
@@ -1542,6 +1542,7 @@ To use an API key, go to "Options -> Settings -> Tools" to enter your Goog
Loaded empty or very short subtitle {0}
File is empty or very short!
File not found: {0}
+ Unable to open file as it is in use by another program: {0}
Saved subtitle {0}
Saved original subtitle {0}
File on disk modified
diff --git a/src/libse/Common/FileUtil.cs b/src/libse/Common/FileUtil.cs
index dfad9850d..d2a4a3fb6 100644
--- a/src/libse/Common/FileUtil.cs
+++ b/src/libse/Common/FileUtil.cs
@@ -609,5 +609,22 @@ namespace Nikse.SubtitleEdit.Core.Common
return validator.IsValid;
}
}
+
+ public static bool IsFileLocked(string fileName)
+ {
+ try
+ {
+ using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None))
+ {
+ stream.Close();
+ }
+ }
+ catch (IOException)
+ {
+ return true;
+ }
+
+ return false;
+ }
}
}
diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs
index f60387d01..59b089f3f 100644
--- a/src/ui/Forms/Main.cs
+++ b/src/ui/Forms/Main.cs
@@ -2756,6 +2756,12 @@ namespace Nikse.SubtitleEdit.Forms
return;
}
+ if (FileUtil.IsFileLocked(fileName))
+ {
+ MessageBox.Show(string.Format(_language.FileLocked, fileName));
+ return;
+ }
+
_lastAutoSave = DateTime.UtcNow.Ticks;
bool videoFileLoaded = false;
_formatManuallyChanged = false;
diff --git a/src/ui/Logic/Language.cs b/src/ui/Logic/Language.cs
index e03016e5c..09879ceeb 100644
--- a/src/ui/Logic/Language.cs
+++ b/src/ui/Logic/Language.cs
@@ -1447,6 +1447,7 @@ namespace Nikse.SubtitleEdit.Logic
LoadedEmptyOrShort = "Loaded empty or very short subtitle {0}",
FileIsEmptyOrShort = "File is empty or very short!",
FileNotFound = "File not found: {0}",
+ FileLocked = "Unable to open file as it is in use by another program: {0}",
SavedSubtitleX = "Saved subtitle {0}",
SavedOriginalSubtitleX = "Saved original subtitle {0}",
FileOnDiskModified = "File on disk modified",
diff --git a/src/ui/Logic/LanguageDeserializer.cs b/src/ui/Logic/LanguageDeserializer.cs
index 07f04ee28..2ef1bcd01 100644
--- a/src/ui/Logic/LanguageDeserializer.cs
+++ b/src/ui/Logic/LanguageDeserializer.cs
@@ -3190,6 +3190,9 @@ namespace Nikse.SubtitleEdit.Logic
case "Main/FileNotFound":
language.Main.FileNotFound = reader.Value;
break;
+ case "Main/FileLocked":
+ language.Main.FileLocked = reader.Value;
+ break;
case "Main/SavedSubtitleX":
language.Main.SavedSubtitleX = reader.Value;
break;
diff --git a/src/ui/Logic/LanguageStructure.cs b/src/ui/Logic/LanguageStructure.cs
index dc69ecb33..71583d7dc 100644
--- a/src/ui/Logic/LanguageStructure.cs
+++ b/src/ui/Logic/LanguageStructure.cs
@@ -1307,6 +1307,7 @@ namespace Nikse.SubtitleEdit.Logic
public string LoadedEmptyOrShort { get; set; }
public string FileIsEmptyOrShort { get; set; }
public string FileNotFound { get; set; }
+ public string FileLocked { get; set; }
public string SavedSubtitleX { get; set; }
public string SavedOriginalSubtitleX { get; set; }
public string FileOnDiskModified { get; set; }