From 9ce3f2213e8c4e8a067bc0640c184a82f73a3dc2 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 3 Sep 2020 01:58:08 +0100 Subject: [PATCH] Move reading root directory to VFS. --- RomRepoMgr.Core/Filesystem/Fuse.cs | 22 +--------------------- RomRepoMgr.Core/Filesystem/Vfs.cs | 8 ++++++++ 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/RomRepoMgr.Core/Filesystem/Fuse.cs b/RomRepoMgr.Core/Filesystem/Fuse.cs index 140cb36..0ba0626 100644 --- a/RomRepoMgr.Core/Filesystem/Fuse.cs +++ b/RomRepoMgr.Core/Filesystem/Fuse.cs @@ -520,33 +520,13 @@ namespace RomRepoMgr.Core.Filesystem { if(directory == "/") { - using var ctx = Context.Create(Settings.Settings.Current.DatabasePath); - List entries = new List { new DirectoryEntry("."), new DirectoryEntry("..") }; - ConcurrentDictionary rootCache = new ConcurrentDictionary(); - - foreach(RomSet set in ctx.RomSets) - { - string name = set.Name.Replace('/', '∕'); - - if(entries.Any(e => e.Name == name)) - name = Path.GetFileNameWithoutExtension(set.Filename)?.Replace('/', '∕'); - - if(entries.Any(e => e.Name == name) || - name == null) - name = Path.GetFileNameWithoutExtension(set.Sha384); - - if(name == null) - continue; - - entries.Add(new DirectoryEntry(name)); - rootCache[name] = set.Id; - } + entries.AddRange(_vfs.GetRootEntries().Select(e => new DirectoryEntry(e))); _lastHandle++; info.Handle = new IntPtr(_lastHandle); diff --git a/RomRepoMgr.Core/Filesystem/Vfs.cs b/RomRepoMgr.Core/Filesystem/Vfs.cs index 230b241..128d0e9 100644 --- a/RomRepoMgr.Core/Filesystem/Vfs.cs +++ b/RomRepoMgr.Core/Filesystem/Vfs.cs @@ -330,6 +330,14 @@ namespace RomRepoMgr.Core.Filesystem return true; } + + internal IEnumerable GetRootEntries() + { + if(_rootDirectoryCache.Count == 0) + FillRootDirectoryCache(); + + return _rootDirectoryCache.Keys.ToArray(); + } } internal sealed class CachedMachine