Relative path enhancement

Switch to Card
Not Mapped
This commit is contained in:
2023-09-28 11:42:29 -07:00
parent f810af3ebe
commit b1e63df70b
5 changed files with 369 additions and 334 deletions

View File

@ -10,31 +10,22 @@ internal static class HelperPdfStripperWrapper
string? Key,
char? Parser);
private static Input GetInput(List<string> args)
private static string GetTextFromPDF(string pdfTextStripperFileName, string sourceFileNamePdf, string destinationFileName)
{
string? d = null;
string? k = null;
string? p = null;
for (int i = 1; i < args.Count; i++)
string result;
ProcessStartInfo processStartInfo = new(pdfTextStripperFileName, $"s \"{sourceFileNamePdf}\"")
{
if (args[i].Length == 2 && i + 1 < args.Count)
{
if (args[i][1] == 'd')
d = Path.GetFullPath(args[i + 1]);
else if (args[i][1] == 'k')
k = args[i + 1].Trim();
else if (args[i][1] == 'p')
p = args[i + 1];
i++;
}
}
string directoryName = Path.GetFileName(args[0]);
if (!string.IsNullOrEmpty(d) && !d.EndsWith(directoryName))
d = Path.Combine(d, directoryName);
if (!string.IsNullOrEmpty(d) && !Directory.Exists(d))
_ = Directory.CreateDirectory(d);
char? parser = p is null ? null : p == "S" ? 'S' : p == "G" ? 'G' : p == "K" ? 'K' : null;
return new(d, k, parser);
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
};
Process? process = Process.Start(processStartInfo);
_ = process?.WaitForExit(30000);
if (!File.Exists(destinationFileName))
result = string.Empty;
else
result = File.ReadAllText(destinationFileName);
return result;
}
private static string GetGhostTextFromPDF(string ghostPCLFileName, string sourceFileNamePdf, string destinationFileName)
@ -69,22 +60,31 @@ internal static class HelperPdfStripperWrapper
return result;
}
private static string GetTextFromPDF(string pdfTextStripperFileName, string sourceFileNamePdf, string destinationFileName)
private static Input GetInput(List<string> args)
{
string result;
ProcessStartInfo processStartInfo = new(pdfTextStripperFileName, $"s \"{sourceFileNamePdf}\"")
string? d = null;
string? k = null;
string? p = null;
for (int i = 1; i < args.Count; i++)
{
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
};
Process? process = Process.Start(processStartInfo);
_ = process?.WaitForExit(30000);
if (!File.Exists(destinationFileName))
result = string.Empty;
else
result = File.ReadAllText(destinationFileName);
return result;
if (args[i].Length == 2 && i + 1 < args.Count)
{
if (args[i][1] == 'd')
d = Path.GetFullPath(args[i + 1]);
else if (args[i][1] == 'k')
k = args[i + 1].Trim();
else if (args[i][1] == 'p')
p = args[i + 1];
i++;
}
}
string directoryName = Path.GetFileName(args[0]);
if (!string.IsNullOrEmpty(d) && !d.EndsWith(directoryName))
d = Path.Combine(d, directoryName);
if (!string.IsNullOrEmpty(d) && !Directory.Exists(d))
_ = Directory.CreateDirectory(d);
char? parser = p is null ? null : p == "S" ? 'S' : p == "G" ? 'G' : p == "K" ? 'K' : null;
return new(d, k, parser);
}
private static void ParseSave(ILogger log, string pdfTextStripperFileName, string ghostPCLFileName, string kofaxFileName, string destinationDirectory, char parser, string[] files)
@ -108,6 +108,31 @@ internal static class HelperPdfStripperWrapper
}
}
private static void ParseStrip(ILogger log, string destinationDirectory, string key, string[] files)
{
string[] lines;
string fileName;
string[] segments;
List<string> collection = new();
foreach (string file in files)
{
lines = File.ReadAllLines(file);
fileName = Path.GetFileName(file);
foreach (string line in lines)
{
segments = line.Split(':');
if (segments.Length < 2)
continue;
if (segments[0].Trim() != key)
continue;
collection.Add($"{fileName}\t{line}");
}
log.LogInformation("<{fileName}>", fileName);
}
if (collection.Count > 0)
File.WriteAllLines(Path.Combine(destinationDirectory, $"{key}.txt"), collection);
}
internal static void ParseSave(ILogger log, List<string> args)
{
string pdfTextStripperFileName = Path.Combine(AppContext.BaseDirectory, "PDF-Text-Stripper.exe");
@ -146,31 +171,6 @@ internal static class HelperPdfStripperWrapper
}
}
private static void ParseStrip(ILogger log, string destinationDirectory, string key, string[] files)
{
string[] lines;
string fileName;
string[] segments;
List<string> collection = new();
foreach (string file in files)
{
lines = File.ReadAllLines(file);
fileName = Path.GetFileName(file);
foreach (string line in lines)
{
segments = line.Split(':');
if (segments.Length < 2)
continue;
if (segments[0].Trim() != key)
continue;
collection.Add($"{fileName}\t{line}");
}
log.LogInformation("<{fileName}>", fileName);
}
if (collection.Count > 0)
File.WriteAllLines(Path.Combine(destinationDirectory, $"{key}.txt"), collection);
}
internal static void ParseStrip(ILogger log, List<string> args)
{
if (DateTime.Now > new DateTime(2023, 9, 15))