CSharpMethodLine

This commit is contained in:
2023-08-20 15:46:32 -07:00
parent 3c86acdbda
commit a9d0f67227
7 changed files with 1637 additions and 1689 deletions

View File

@ -1,4 +1,4 @@
using CliWrap;
using CliWrap;
using Microsoft.Extensions.Configuration;
using Phares.Shared;
using Serilog;
@ -72,6 +72,115 @@ public class Rename
throw new NullReferenceException(nameof(_PropertyConfiguration));
}
private List<string> RenameFilesInDirectories(ILogger log)
{
List<string> results = new();
string message;
bool nefPresentCheck;
bool nefPresent = false;
ProgressBar progressBar;
List<Record> records = new();
const string fileSearchFilter = "*";
int offset = IDirectory.GetOffset();
const bool useCeilingAverage = false;
const string directorySearchFilter = "*";
List<string> distinctDirectories = new();
B_Metadata metadata = new(_PropertyConfiguration);
List<(FileHolder, string, string)> toDoCollection = new();
List<(FileHolder, string)> verifiedToDoCollection = new();
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
List<string[]> filesCollection = IDirectory.GetFilesCollection(_PropertyConfiguration.RootDirectory, directorySearchFilter, fileSearchFilter, useCeilingAverage);
int count = filesCollection.Select(l => l.Length).Sum();
foreach (string[] files in filesCollection)
{
if (!files.Any())
continue;
// foreach (string files[i] in files)
// {
// if (!files[i].EndsWith(".del"))
// continue;
// File.Move(files[i], files[i][..^4]);
// }
// continue;
distinctDirectories.Clear();
if (_AppSettings.RenameUndo)
{
message = $") Undo renaming files for <{files.FirstOrDefault()}>";
progressBar = new(files.Length, message, options);
toDoCollection.AddRange(GetRenameUndoToDoCollection(progressBar, files));
}
else
{
message = $"{records.Count:00000}) Gathering records for files next to <{files.FirstOrDefault()}>";
progressBar = new(files.Length, message, options);
nefPresentCheck = files.Any(l => l.EndsWith(".NEF"));
if (!nefPresentCheck)
records.AddRange(GetRecords(metadata, offset + records.Count, progressBar, files));
else
{
if (!nefPresent)
nefPresent = true;
records.AddRange(GetRecords(metadata, offset + records.Count, progressBar, (from l in files where l.EndsWith(".JPG") select l).ToArray()));
}
}
progressBar.Dispose();
}
if (records.Any())
{
int intMinValueLength = int.MinValue.ToString().Length;
foreach (Record record in records)
{
if (record.Id is null)
continue;
if (intMinValueLength < record.Id.Value.ToString().Length)
throw new NotSupportedException();
}
message = $"{intMinValueLength}) comparing records";
progressBar = new(records.Count, message, options);
toDoCollection.AddRange(GetToDoCollection(progressBar, nefPresent, records, intMinValueLength));
progressBar.Dispose();
}
foreach ((FileHolder fileHolder, string directory, string to) in toDoCollection)
{
if (distinctDirectories.Contains(directory))
continue;
distinctDirectories.Add(directory);
}
foreach (string distinctDirectory in distinctDirectories)
{
if (!Directory.Exists(distinctDirectory))
_ = Directory.CreateDirectory(distinctDirectory);
}
foreach ((FileHolder fileHolder, string directory, string to) in toDoCollection)
{
if (File.Exists(to))
continue;
verifiedToDoCollection.Add(new(fileHolder, to));
File.WriteAllText($"{to}.paddedId", $"{to}{Environment.NewLine}{fileHolder.FullName}");
}
ConsoleKey? consoleKey = null;
log.Information($"Ready to Move {verifiedToDoCollection.Count} files[i](s)?");
for (int y = 0; y < int.MaxValue; y++)
{
log.Information("Press \"Y\" key to move files[i](s), \"N\" key to log files[i](s) or close console to not move files");
consoleKey = System.Console.ReadKey().Key;
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
break;
}
log.Information(". . .");
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
log.Information("Nothing moved!");
else
{
message = ") Renaming files";
progressBar = new(count, message, options);
results.AddRange(Move(progressBar, verifiedToDoCollection));
progressBar.Dispose();
log.Information("Done Moving");
}
return results;
}
private static List<(FileHolder, string, string)> GetRenameUndoToDoCollection(ProgressBar progressBar, string[] files)
{
List<(FileHolder, string, string)> results = new();
@ -335,113 +444,4 @@ public class Rename
return results;
}
private List<string> RenameFilesInDirectories(ILogger log)
{
List<string> results = new();
string message;
bool nefPresentCheck;
bool nefPresent = false;
ProgressBar progressBar;
List<Record> records = new();
const string fileSearchFilter = "*";
int offset = IDirectory.GetOffset();
const bool useCeilingAverage = false;
const string directorySearchFilter = "*";
List<string> distinctDirectories = new();
B_Metadata metadata = new(_PropertyConfiguration);
List<(FileHolder, string, string)> toDoCollection = new();
List<(FileHolder, string)> verifiedToDoCollection = new();
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
List<string[]> filesCollection = IDirectory.GetFilesCollection(_PropertyConfiguration.RootDirectory, directorySearchFilter, fileSearchFilter, useCeilingAverage);
int count = filesCollection.Select(l => l.Length).Sum();
foreach (string[] files in filesCollection)
{
if (!files.Any())
continue;
// foreach (string files[i] in files)
// {
// if (!files[i].EndsWith(".del"))
// continue;
// File.Move(files[i], files[i][..^4]);
// }
// continue;
distinctDirectories.Clear();
if (_AppSettings.RenameUndo)
{
message = $") Undo renaming files for <{files.FirstOrDefault()}>";
progressBar = new(files.Length, message, options);
toDoCollection.AddRange(GetRenameUndoToDoCollection(progressBar, files));
}
else
{
message = $"{records.Count:00000}) Gathering records for files next to <{files.FirstOrDefault()}>";
progressBar = new(files.Length, message, options);
nefPresentCheck = files.Any(l => l.EndsWith(".NEF"));
if (!nefPresentCheck)
records.AddRange(GetRecords(metadata, offset + records.Count, progressBar, files));
else
{
if (!nefPresent)
nefPresent = true;
records.AddRange(GetRecords(metadata, offset + records.Count, progressBar, (from l in files where l.EndsWith(".JPG") select l).ToArray()));
}
}
progressBar.Dispose();
}
if (records.Any())
{
int intMinValueLength = int.MinValue.ToString().Length;
foreach (Record record in records)
{
if (record.Id is null)
continue;
if (intMinValueLength < record.Id.Value.ToString().Length)
throw new NotSupportedException();
}
message = $"{intMinValueLength}) comparing records";
progressBar = new(records.Count, message, options);
toDoCollection.AddRange(GetToDoCollection(progressBar, nefPresent, records, intMinValueLength));
progressBar.Dispose();
}
foreach ((FileHolder fileHolder, string directory, string to) in toDoCollection)
{
if (distinctDirectories.Contains(directory))
continue;
distinctDirectories.Add(directory);
}
foreach (string distinctDirectory in distinctDirectories)
{
if (!Directory.Exists(distinctDirectory))
_ = Directory.CreateDirectory(distinctDirectory);
}
foreach ((FileHolder fileHolder, string directory, string to) in toDoCollection)
{
if (File.Exists(to))
continue;
verifiedToDoCollection.Add(new(fileHolder, to));
File.WriteAllText($"{to}.paddedId", $"{to}{Environment.NewLine}{fileHolder.FullName}");
}
ConsoleKey? consoleKey = null;
log.Information($"Ready to Move {verifiedToDoCollection.Count} files[i](s)?");
for (int y = 0; y < int.MaxValue; y++)
{
log.Information("Press \"Y\" key to move files[i](s), \"N\" key to log files[i](s) or close console to not move files");
consoleKey = System.Console.ReadKey().Key;
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
break;
}
log.Information(". . .");
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
log.Information("Nothing moved!");
else
{
message = ") Renaming files";
progressBar = new(count, message, options);
results.AddRange(Move(progressBar, verifiedToDoCollection));
progressBar.Dispose();
log.Information("Done Moving");
}
return results;
}
}