Some fixes -- DirHandle isn't behaving as expected.
This commit is contained in:
parent
60de762c8b
commit
83d4717be2
@ -8,6 +8,12 @@ function header () {
|
|||||||
function errorheader () {
|
function errorheader () {
|
||||||
tput setaf 1 1>&2; tput bold 1>&2; echo "ERROR:" $@ 1>&2; tput sgr0 1>&2; return
|
tput setaf 1 1>&2; tput bold 1>&2; echo "ERROR:" $@ 1>&2; tput sgr0 1>&2; return
|
||||||
}
|
}
|
||||||
|
function infoheader() {
|
||||||
|
tput setaf 3; tput bold; echo $@; tput sgr0; return
|
||||||
|
}
|
||||||
|
function colorstrip() {
|
||||||
|
perl -e 'use strict; use warnings; while(<>) { s/\e\[[\d;]*m//g; print; }'
|
||||||
|
}
|
||||||
|
|
||||||
## Configuration reading ##
|
## Configuration reading ##
|
||||||
function param() {
|
function param() {
|
||||||
|
@ -88,7 +88,8 @@ namespace AniNIX.Shared {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < lines.Count; i++) {
|
for (i = 0; i < lines.Count; i++) {
|
||||||
if (lines[i].Length > 5 && lines[i][0] == '[' && lines[i][lines[i].Length-1] == ']') {
|
if (lines[i].Length > 5 && lines[i][0] == '[' && lines[i][lines[i].Length-1] == ']') {
|
||||||
foundHeaders.Add(lines[i].Substring(2,lines[i].Length-4));
|
string foundHeader = lines[i].Substring(2,lines[i].Length-4);
|
||||||
|
if (!foundHeaders.Contains(foundHeader)) foundHeaders.Add(foundHeader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return foundHeaders;
|
return foundHeaders;
|
||||||
|
@ -42,6 +42,42 @@ namespace AniNIX.Shared {
|
|||||||
return new List<String>(Directory.GetFiles(@_path));
|
return new List<String>(Directory.GetFiles(@_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the path of the newest file.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A List of strings</returns>
|
||||||
|
public String GetNewest() {
|
||||||
|
try {
|
||||||
|
return this.SortedListOfFiles()[0].FullName.Trim();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.ToString();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the path of the oldest file
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A List of strings</returns>
|
||||||
|
public String GetOldest() {
|
||||||
|
try {
|
||||||
|
FileInfo[] files = this.SortedListOfFiles();
|
||||||
|
return files[files.Length-1].FullName.Trim();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.ToString();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sorts the list of files from newest to oldest.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A List of strings</returns>
|
||||||
|
private FileInfo[] SortedListOfFiles() {
|
||||||
|
return (new DirectoryInfo(@_path)).GetFiles().OrderByDescending(p => p.CreationTime).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
/* IDisposable */
|
/* IDisposable */
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -24,21 +24,26 @@ namespace AniNIX.Shared {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read the next line. If already reached EOF, block until line is added.
|
/// Read the next line.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Next line</returns>
|
/// <returns>Next line</returns>
|
||||||
public String NextLine() {
|
public String NextLine() {
|
||||||
String nextLine = _fileHandle.ReadLine();
|
return _fileHandle.ReadLine();
|
||||||
if (nextLine != null) {
|
}
|
||||||
return nextLine;
|
|
||||||
} else {
|
/// <summary>
|
||||||
|
/// Get the next new line added to the file.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Next new line</returns>
|
||||||
|
public string NextNewLine() {
|
||||||
FileSystemWatcher fsw = new FileSystemWatcher(_directory);
|
FileSystemWatcher fsw = new FileSystemWatcher(_directory);
|
||||||
fsw.Path = _directory;
|
fsw.Path = _directory;
|
||||||
fsw.Filter = _file;
|
fsw.Filter = _file;
|
||||||
fsw.NotifyFilter = NotifyFilters.LastWrite;
|
fsw.NotifyFilter = NotifyFilters.LastWrite;
|
||||||
fsw.WaitForChanged(WatcherChangeTypes.Changed);
|
fsw.WaitForChanged(WatcherChangeTypes.Changed);
|
||||||
return _fileHandle.ReadLine();
|
// 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>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user