Add application arguments instead of constant file names
This commit is contained in:
parent
3990ca72d9
commit
596fc81ec5
@ -1,3 +1,11 @@
|
|||||||
using ResticLogParser.src;
|
using ResticLogParser.src;
|
||||||
|
|
||||||
new LogParser(@"C:\Users\warrence\Documents\My Documents\restic\restic-logfile.txt").Run();
|
if (args.Length < 3 || string.IsNullOrEmpty(args[0]) || string.IsNullOrEmpty(args[1]) || string.IsNullOrEmpty(args[2]))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Invalid parameters.");
|
||||||
|
Console.WriteLine($" ResticLogParser <log-file-name> <files-output-file-name> <directories-output-file-name>");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
new LogParser(args[0], args[1], args[2]).Run();
|
||||||
|
return 0;
|
||||||
|
@ -14,33 +14,45 @@ namespace ResticLogParser.src
|
|||||||
new(@"modified\s+(.+), saved in \d+\.\d+s \((\d+(?:\.\d+)? .+) added, (\d+(?:\.\d+)? .+) stored\)");
|
new(@"modified\s+(.+), saved in \d+\.\d+s \((\d+(?:\.\d+)? .+) added, (\d+(?:\.\d+)? .+) stored\)");
|
||||||
|
|
||||||
private string _logFileName;
|
private string _logFileName;
|
||||||
|
private string _filesOutputFileName;
|
||||||
|
private string _directoriesOutputFileName;
|
||||||
private readonly List<FileLogEntry> _files = new();
|
private readonly List<FileLogEntry> _files = new();
|
||||||
private readonly List<DirectoryNode> _directories = new();
|
private readonly List<DirectoryNode> _directories = new();
|
||||||
private readonly DirectoryNode _root = new(null, "/", "/");
|
private readonly DirectoryNode _root = new(null, "/", "/");
|
||||||
|
|
||||||
public LogParser(string logFileName)
|
public LogParser(string logFileName, string filesOutputFileName, string directoriesOutputFileName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(logFileName))
|
if (string.IsNullOrEmpty(logFileName))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(logFileName));
|
throw new ArgumentNullException(nameof(logFileName));
|
||||||
}
|
}
|
||||||
|
if (string.IsNullOrEmpty(filesOutputFileName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(filesOutputFileName));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(directoriesOutputFileName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(directoriesOutputFileName));
|
||||||
|
}
|
||||||
|
|
||||||
_logFileName = logFileName;
|
_logFileName = logFileName;
|
||||||
|
_filesOutputFileName = filesOutputFileName;
|
||||||
|
_directoriesOutputFileName = directoriesOutputFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Running restic log parser for '{_logFileName}'...");
|
Console.WriteLine($"Running restic log parser for '{_logFileName}'...");
|
||||||
ParseLogFile();
|
ParseLogFile(_logFileName);
|
||||||
WriteFileInformation();
|
WriteFileInformation(_filesOutputFileName);
|
||||||
WriteDirectoryInformation();
|
WriteDirectoryInformation(_directoriesOutputFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParseLogFile()
|
private void ParseLogFile(string fileName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using StreamReader reader = new(_logFileName);
|
using StreamReader reader = new(fileName);
|
||||||
while (!reader.EndOfStream)
|
while (!reader.EndOfStream)
|
||||||
{
|
{
|
||||||
string line = reader.ReadLine()!;
|
string line = reader.ReadLine()!;
|
||||||
@ -97,9 +109,8 @@ namespace ResticLogParser.src
|
|||||||
parent.FileCount++;
|
parent.FileCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteFileInformation()
|
private void WriteFileInformation(string outputFileName)
|
||||||
{
|
{
|
||||||
string outputFileName = Path.Combine(Path.GetDirectoryName(_logFileName)!, "restic-added-data-files.txt");
|
|
||||||
Console.WriteLine($"Writing added files to '{outputFileName}'...");
|
Console.WriteLine($"Writing added files to '{outputFileName}'...");
|
||||||
|
|
||||||
_files.Sort();
|
_files.Sort();
|
||||||
@ -113,9 +124,8 @@ namespace ResticLogParser.src
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteDirectoryInformation()
|
private void WriteDirectoryInformation(string outputFileName)
|
||||||
{
|
{
|
||||||
string outputFileName = Path.Combine(Path.GetDirectoryName(_logFileName)!, "restic-added-data-dirs.txt");
|
|
||||||
Console.WriteLine($"Writing directory infos to '{outputFileName}'...");
|
Console.WriteLine($"Writing directory infos to '{outputFileName}'...");
|
||||||
|
|
||||||
_directories.Sort();
|
_directories.Sort();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user