Undo Rename
This commit is contained in:
@ -7,25 +7,28 @@ public class AppSettings
|
||||
{
|
||||
|
||||
public string Company { init; get; }
|
||||
public string CopyTo { init; get; }
|
||||
public string ComparePathsFile { init; get; }
|
||||
public string CopyTo { init; get; }
|
||||
public int MaxDegreeOfParallelism { init; get; }
|
||||
public int MaxMinutesDelta { init; get; }
|
||||
public bool RenameUndo { init; get; }
|
||||
public string WorkingDirectoryName { init; get; }
|
||||
|
||||
[JsonConstructor]
|
||||
public AppSettings(string company,
|
||||
string copyTo,
|
||||
string comparePathsFile,
|
||||
string copyTo,
|
||||
int maxDegreeOfParallelism,
|
||||
int maxMinutesDelta,
|
||||
bool renameUndo,
|
||||
string workingDirectoryName)
|
||||
{
|
||||
Company = company;
|
||||
CopyTo = copyTo;
|
||||
ComparePathsFile = comparePathsFile;
|
||||
CopyTo = copyTo;
|
||||
MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
MaxMinutesDelta = maxMinutesDelta;
|
||||
RenameUndo = renameUndo;
|
||||
WorkingDirectoryName = workingDirectoryName;
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,11 @@ public class AppSettings
|
||||
#nullable disable
|
||||
|
||||
public string Company { get; set; }
|
||||
public string CopyTo { get; set; }
|
||||
public string ComparePathsFile { get; set; }
|
||||
public string CopyTo { get; set; }
|
||||
public int? MaxDegreeOfParallelism { get; set; }
|
||||
public int? MaxMinutesDelta { get; set; }
|
||||
public bool? RenameUndo { get; set; }
|
||||
public string WorkingDirectoryName { get; set; }
|
||||
|
||||
#nullable restore
|
||||
@ -30,12 +31,15 @@ public class AppSettings
|
||||
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
if (appSettings?.MaxMinutesDelta is null)
|
||||
throw new NullReferenceException(nameof(appSettings.MaxMinutesDelta));
|
||||
if (appSettings?.RenameUndo is null)
|
||||
throw new NullReferenceException(nameof(appSettings.RenameUndo));
|
||||
result = new(
|
||||
appSettings.Company,
|
||||
appSettings.CopyTo,
|
||||
appSettings.ComparePathsFile,
|
||||
appSettings.CopyTo,
|
||||
appSettings.MaxDegreeOfParallelism.Value,
|
||||
appSettings.MaxMinutesDelta.Value,
|
||||
appSettings.RenameUndo.Value,
|
||||
appSettings.WorkingDirectoryName
|
||||
);
|
||||
return result;
|
||||
|
@ -92,6 +92,27 @@ public class Rename
|
||||
}
|
||||
}
|
||||
|
||||
private static List<(FileHolder, string)> GetRenameUndoToDoCollection(ProgressBar progressBar, string[] files)
|
||||
{
|
||||
List<(FileHolder, string)> results = new();
|
||||
string[] lines;
|
||||
string fileName;
|
||||
FileHolder fileHolder;
|
||||
foreach (string file in files)
|
||||
{
|
||||
progressBar.Tick();
|
||||
fileName = Path.GetFileName(file);
|
||||
if (!fileName.EndsWith(".id"))
|
||||
continue;
|
||||
lines = File.ReadAllLines(file);
|
||||
if (lines.Length < 2)
|
||||
continue;
|
||||
fileHolder = new(lines[0]);
|
||||
results.Add(new(fileHolder, lines[1]));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<(FileHolder, string)> GetToDoCollection(ProgressBar progressBar, string[] files)
|
||||
{
|
||||
List<(FileHolder, string)> results = new();
|
||||
@ -346,12 +367,17 @@ public class Rename
|
||||
for (int i = 1; i < 3; i++)
|
||||
{
|
||||
message = $"{i}) Renaming files";
|
||||
if (_AppSettings.RenameUndo && i == 1)
|
||||
continue;
|
||||
files = i == 2 ? allFiles.ToArray() : (from l in allFiles where l.Contains("Rename") select l).ToArray();
|
||||
progressBar = new(files.Length, message, options);
|
||||
if (!files.Any())
|
||||
continue;
|
||||
distinctCollection.Clear();
|
||||
toDoCollection = GetToDoCollection(progressBar, files);
|
||||
if (!_AppSettings.RenameUndo)
|
||||
toDoCollection = GetToDoCollection(progressBar, files);
|
||||
else
|
||||
toDoCollection = GetRenameUndoToDoCollection(progressBar, files);
|
||||
foreach ((FileHolder fileHolder, string to) in toDoCollection)
|
||||
{
|
||||
if (distinctCollection.Contains(to))
|
||||
|
Reference in New Issue
Block a user