Fixed race condition.
This commit is contained in:
parent
3c1db55a95
commit
9de85b649b
@ -170,6 +170,8 @@ namespace FileLiberator
|
|||||||
File.Move(f.FullName, dest);
|
File.Move(f.FullName, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudibleFileStorage.Audio.Refresh();
|
||||||
|
|
||||||
return destinationDir;
|
return destinationDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -57,6 +57,11 @@ namespace FileManager
|
|||||||
extAggr = extensions_noDots.Aggregate((a, b) => $"{a}|{b}");
|
extAggr = extensions_noDots.Aggregate((a, b) => $"{a}|{b}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Refresh()
|
||||||
|
{
|
||||||
|
BookDirectoryFiles.RefreshFiles();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Example for full books:
|
/// Example for full books:
|
||||||
/// Search recursively in _books directory. Full book exists if either are true
|
/// Search recursively in _books directory. Full book exists if either are true
|
||||||
|
|||||||
@ -28,6 +28,17 @@ namespace FileManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RefreshFiles()
|
||||||
|
{
|
||||||
|
if (fsCache is null) return;
|
||||||
|
|
||||||
|
lock (fsCache)
|
||||||
|
{
|
||||||
|
fsCache.Clear();
|
||||||
|
fsCache.AddRange(Directory.EnumerateFiles(RootDirectory, SearchPattern, SearchOption));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Init(string rootDirectory, string searchPattern, SearchOption searchOptions)
|
public void Init(string rootDirectory, string searchPattern, SearchOption searchOptions)
|
||||||
{
|
{
|
||||||
RootDirectory = rootDirectory;
|
RootDirectory = rootDirectory;
|
||||||
@ -57,6 +68,19 @@ namespace FileManager
|
|||||||
backgroundScanner.Start();
|
backgroundScanner.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AddUniqueFiles(IEnumerable<string> newFiles)
|
||||||
|
{
|
||||||
|
foreach (var file in newFiles)
|
||||||
|
{
|
||||||
|
AddUniqueFile(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void AddUniqueFile(string newFile)
|
||||||
|
{
|
||||||
|
if (!fsCache.Contains(newFile))
|
||||||
|
fsCache.Add(newFile);
|
||||||
|
}
|
||||||
|
|
||||||
private void FileSystemWatcher_Error(object sender, ErrorEventArgs e)
|
private void FileSystemWatcher_Error(object sender, ErrorEventArgs e)
|
||||||
{
|
{
|
||||||
Init(RootDirectory, SearchPattern, SearchOption);
|
Init(RootDirectory, SearchPattern, SearchOption);
|
||||||
@ -107,11 +131,10 @@ namespace FileManager
|
|||||||
private void AddPath(string path)
|
private void AddPath(string path)
|
||||||
{
|
{
|
||||||
if (File.GetAttributes(path).HasFlag(FileAttributes.Directory))
|
if (File.GetAttributes(path).HasFlag(FileAttributes.Directory))
|
||||||
fsCache.AddRange(Directory.EnumerateFiles(path, SearchPattern, SearchOption));
|
AddUniqueFiles(Directory.EnumerateFiles(path, SearchPattern, SearchOption));
|
||||||
else
|
else
|
||||||
fsCache.Add(path);
|
AddUniqueFile(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user