Updated accessible-directory

This commit is contained in:
Ray 2021-11-25 10:35:35 +00:00
parent 7680b969ed
commit 5b9a6d4633

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace RyzStudio.IO
{
@ -214,16 +215,66 @@ namespace RyzStudio.IO
string filename = Path.GetFileName(filepath);
if (string.IsNullOrWhiteSpace(filename)) return null;
List<string> fileList = AccessibleDirectory.GetFiles(path, pattern, true);
if (fileList == null) return null;
if (fileList.Count <= 0) return null;
if (fileList.Count(x => (Path.GetFileName(x).Equals(filename))) < 0) return null;
bool returnNext = false;
foreach (string item in Directory.EnumerateFiles(path, "*", SearchOption.TopDirectoryOnly))
{
if (!MatchFileSearchPattern(pattern, Path.GetFileName(item)))
{
continue;
}
int pos = fileList.FindIndex(x => Path.GetFileName(x).Equals(filename));
if (pos < 0) return null;
if (pos >= (fileList.Count - 1)) return null;
if (!IsFileAccessible(item))
{
continue;
}
return fileList[(pos + 1)];
if (returnNext)
{
return item;
}
if (Path.GetFileName(item).Equals(filename))
{
returnNext = true;
}
}
return null;
}
public static string GetPreviousFile(string filepath, string pattern)
{
if (string.IsNullOrWhiteSpace(filepath)) return null;
string path = Path.GetDirectoryName(filepath);
if (string.IsNullOrWhiteSpace(path)) return null;
string filename = Path.GetFileName(filepath);
if (string.IsNullOrWhiteSpace(filename)) return null;
StringBuilder sb = new StringBuilder();
foreach (string item in Directory.EnumerateFiles(path, "*", SearchOption.TopDirectoryOnly))
{
if (!MatchFileSearchPattern(pattern, Path.GetFileName(item)))
{
continue;
}
if (!IsFileAccessible(item))
{
continue;
}
sb.Clear();
sb.Append(item);
if (Path.GetFileName(item).Equals(filename))
{
return (sb.Length <= 0) ? null : sb.ToString();
}
}
return null;
}
public static bool IsAccessible(string path)