Browse Source

Fixes from Cerberus and other development

main
DarkFeather 5 years ago
parent
commit
60de762c8b
6 changed files with 190 additions and 13 deletions
  1. +1
    -1
      Bash/header
  2. +1
    -0
      CSharp/Configure.csharp
  3. +82
    -0
      CSharp/DirHandle.csharp
  4. +2
    -3
      CSharp/ExecuteCommand.csharp
  5. +103
    -0
      CSharp/FileHandle.csharp
  6. +1
    -9
      CSharp/ReportMessage.csharp

+ 1
- 1
Bash/header View File

@ -227,7 +227,7 @@ function getmagnetlink {
searchstring="$(echo "$1" | sed "s/ /$searchunifier/g")"
searchlink="$(printf "$torrentengine" "$searchstring")"
searchresult="$(wget --timeout=5 -q -O - "$searchlink" | bash -c "$torrentterms")"
magnetlink="$(wget --timeout=5 -q -O - "$searchresult" | grep 'magnet:?' | cut -f $magnetposition -d \")"
magnetlink="$(wget --timeout=5 -q -O - "$searchresult" | grep 'magnet:?' | cut -f "$magnetposition" -d \"| head -n 1)"
if [ $torrentdebugging == "true" ]; then
echo '<'$searchstring'>'
echo '<'$searchlink'>'


+ 1
- 0
CSharp/Configure.csharp View File

@ -15,6 +15,7 @@ namespace AniNIX.Shared {
/// </summary>
/// <param name="filename">The Config file</param>
public Configure(String filename) {
if (!File.Exists(filename)) throw new Exception("File not found.");
StreamReader fileReader = new StreamReader(filename);
String line;
while (true) {


+ 82
- 0
CSharp/DirHandle.csharp View File

@ -0,0 +1,82 @@
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
namespace AniNIX.Shared {
public class DirHandle : IDisposable {
// Internal representations of the directory.
private FileSystemWatcher _dirHandle = new FileSystemWatcher();
private String _path;
/// <summary>
/// Create a new DirHandle
/// </summary>
/// <param name=path>The path to watch</param>
/// <param name=filter>Optional filter to control files by -- accepts regex</param>
public DirHandle(String path, String filter = "*.*") {
this._path=path;
_dirHandle.Path = path;
_dirHandle.NotifyFilter = NotifyFilters.LastWrite;
_dirHandle.Filter = filter;
_dirHandle.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.Size;
_dirHandle.EnableRaisingEvents = false;
}
/// <summary>
/// Wait until the directory changes
/// </summary>
public void HoldForChange() {
_dirHandle.WaitForChanged(WatcherChangeTypes.Changed);
return;
}
/// <summary>
/// Get a list of files in the path.
/// </summary>
/// <returns>A List of strings</returns>
public List<String> ListContents() {
return new List<String>(Directory.GetFiles(@_path));
}
/* IDisposable */
/// <summary>
/// Clean up this FileStream, implementing IDisposable
/// </summary>
public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Force the GarbageCollector to Dispose if programmer does not
/// </summary>
~DirHandle() {
Dispose(false);
ReportMessage.Log(Verbosity.Error,"Programmer forgot to dispose of DirHandle. Marking for Garbage Collector");
}
// This bool indicates whether we have disposed of this Raven
public bool _isDisposed = false;
/// <summary>
/// Dispose of this FileHandle's resources responsibly.
/// </summary>
private void Dispose(bool disposing) {
if (!_isDisposed) {
if (disposing) {
_path = null;
}
if ( _dirHandle != null) {
_dirHandle.Dispose();
}
}
this._isDisposed = true;
}
}
}

+ 2
- 3
CSharp/ExecuteCommand.csharp View File

@ -20,9 +20,8 @@ namespace AniNIX.Shared {
/// </summary>
public static String Run(String command, String input) {
//Sanitize inputs.
if (command.Contains("\'")) {
throw new Exception("Command strings cannot include \'.");
}
command = command.Replace("\\'","'").Replace("'","\\'");
//Create process.
Process proc = new Process();


+ 103
- 0
CSharp/FileHandle.csharp View File

@ -0,0 +1,103 @@
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace AniNIX.Shared {
public class FileHandle : IDisposable {
//Private variables
private StreamReader _fileHandle = null;
private String _path = null;
private String _directory = null;
private String _file = null;
/// <summary>
/// Create an object to bundle my usual file operations.
/// <summary>
public FileHandle(String path) {
this._path = path;
this._directory = Path.GetDirectoryName(path);
this._file = Path.GetFileName(path);
this.Reset();
}
/// <summary>
/// Read the next line. If already reached EOF, block until line is added.
/// </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();
}
}
/// <summary>
/// Read all contents of the file.
/// </summary>
/// <returns>File contents</returns>
public String ReadAll() {
return _fileHandle.ReadToEnd();
}
/// <summary>
/// Close the old handle, if applicable, and open new one.
/// </summary>
public void Reset() {
if (this._fileHandle != null) {
this._fileHandle.Close();
this._fileHandle.Dispose();
}
this._fileHandle = new StreamReader(_path);
}
/* IDisposable */
/// <summary>
/// Clean up this FileStream, implementing IDisposable
/// </summary>
public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Force the GarbageCollector to Dispose if programmer does not
/// </summary>
~FileHandle() {
Dispose(false);
ReportMessage.Log(Verbosity.Error,"Programmer forgot to dispose of FileHandle. Marking for Garbage Collector");
}
// This bool indicates whether we have disposed of this Raven
public bool _isDisposed = false;
/// <summary>
/// Dispose of this FileHandle's resources responsibly.
/// </summary>
private void Dispose(bool disposing) {
if (!_isDisposed) {
if (disposing) {
_path = null;
_file = null;
_directory = null;
}
if ( _fileHandle != null) {
_fileHandle.Close();
_fileHandle.Dispose();
}
}
this._isDisposed = true;
}
}
}

+ 1
- 9
CSharp/ReportMessage.csharp View File

@ -26,15 +26,7 @@ namespace AniNIX.Shared {
return;
}
if (ReportMessage.verbosity == Verbosity.Quiet) {
return;
}
if (level == Verbosity.Always
|| (ReportMessage.verbosity == Verbosity.Verbose && level == Verbosity.Verbose)
|| (ReportMessage.verbosity == Verbosity.VeryVerbose && (level == Verbosity.Verbose || level == Verbosity.VeryVerbose))
|| (ReportMessage.verbosity == Verbosity.Explicit && (level == Verbosity.Verbose || level == Verbosity.VeryVerbose || level == Verbosity.Explicit))
) {
if ( level <= ReportMessage.verbosity) {
Console.WriteLine(message);
}


Loading…
Cancel
Save