mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-21 18:52:36 +01:00
Merge pull request #8899 from ivandrofly/feature/file-util
Refactor directory writable check to FileUtil
This commit is contained in:
commit
8ff7b7abf5
@ -935,5 +935,23 @@ namespace Nikse.SubtitleEdit.Core.Common
|
|||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if a directory is writable by attempting to create and delete a temporary file within it.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dirPath">The directory path to check for write access.</param>
|
||||||
|
/// <returns>True if the directory is writable, false otherwise.</returns>
|
||||||
|
public static bool IsDirectoryWritable(string dirPath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (File.Create(Path.Combine(dirPath, Path.GetRandomFileName()), 1, FileOptions.DeleteOnClose)) { }
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
|||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
var dir = Path.GetDirectoryName(fileName);
|
var dir = Path.GetDirectoryName(fileName);
|
||||||
if (!WhisperAudioToText.IsDirectoryWritable(dir))
|
if (!FileUtil.IsDirectoryWritable(dir))
|
||||||
{
|
{
|
||||||
MessageBox.Show($"SE does not have write access to the folder '{dir}'", MessageBoxIcon.Error);
|
MessageBox.Show($"SE does not have write access to the folder '{dir}'", MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
|
@ -843,7 +843,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
|||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
var dir = Path.GetDirectoryName(fileName);
|
var dir = Path.GetDirectoryName(fileName);
|
||||||
if (!IsDirectoryWritable(dir))
|
if (!FileUtil.IsDirectoryWritable(dir))
|
||||||
{
|
{
|
||||||
MessageBox.Show($"SE does not have write access to the folder '{dir}'", MessageBoxIcon.Error);
|
MessageBox.Show($"SE does not have write access to the folder '{dir}'", MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
@ -852,20 +852,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsDirectoryWritable(string dirPath)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (FileStream fs = File.Create(Path.Combine(dirPath, Path.GetRandomFileName()), 1, FileOptions.DeleteOnClose))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string GetLanguage(string name)
|
internal static string GetLanguage(string name)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user