Some fixes -- DirHandle isn't behaving as expected.

This commit is contained in:
DarkFeather
2017-03-30 19:14:29 -05:00
parent 60de762c8b
commit 83d4717be2
4 changed files with 62 additions and 14 deletions

View File

@@ -24,21 +24,26 @@ namespace AniNIX.Shared {
}
/// <summary>
/// Read the next line. If already reached EOF, block until line is added.
/// Read the next line.
/// </summary>
/// <returns>Next line</returns>
public String NextLine() {
String nextLine = _fileHandle.ReadLine();
if (nextLine != null) {
return nextLine;
} else {
FileSystemWatcher fsw = new FileSystemWatcher(_directory);
fsw.Path = _directory;
fsw.Filter = _file;
fsw.NotifyFilter = NotifyFilters.LastWrite;
fsw.WaitForChanged(WatcherChangeTypes.Changed);
return _fileHandle.ReadLine();
}
return _fileHandle.ReadLine();
}
/// <summary>
/// Get the next new line added to the file.
/// </summary>
/// <returns>Next new line</returns>
public string NextNewLine() {
FileSystemWatcher fsw = new FileSystemWatcher(_directory);
fsw.Path = _directory;
fsw.Filter = _file;
fsw.NotifyFilter = NotifyFilters.LastWrite;
fsw.WaitForChanged(WatcherChangeTypes.Changed);
// Optionally, this could be accomplished with http://stackoverflow.com/questions/452902/how-to-read-a-text-file-reversely-with-iterator-in-c-sharp
// Instead, we are using a syscall for sake of codespace and testing.
return ExecuteCommand.Run(String.Format("tail -n 1 {0}",this._path));
}
/// <summary>
@@ -61,7 +66,7 @@ namespace AniNIX.Shared {
}
/* IDisposable */
/// <summary>
/// Clean up this FileStream, implementing IDisposable
/// </summary>