You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB
C#

namespace CommanderApp
{
public class FileSystemService : IFileSystemService
{
public string GetRootPath()
{
#if ANDROID || IOS || MACCATALYST
return FileSystem.Current.AppDataDirectory;
#else
return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
#endif
}
public IEnumerable<FileSystemItem> GetDirectoryContents(string path)
{
if (!Directory.Exists(path))
return Enumerable.Empty<FileSystemItem>();
var items = new List<FileSystemItem>();
// Добавляем ".." если не корень
var parent = Directory.GetParent(path);
if (parent != null)
{
items.Add(new FileSystemItem
{
Name = "..",
FullName = parent.FullName,
IsDirectory = true
});
}
var dirs = Directory.GetDirectories(path)
.Select(d => new FileSystemItem
{
Name = Path.GetFileName(d),
FullName = d,
IsDirectory = true
});
var files = Directory.GetFiles(path)
.Select(f => new FileSystemItem
{
Name = Path.GetFileName(f),
FullName = f,
IsDirectory = false
});
items.AddRange(dirs.OrderBy(d => d.Name));
items.AddRange(files.OrderBy(f => f.Name));
return items;
}
}
}