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