Merge Kristy Files
This commit is contained in:
@ -3,6 +3,8 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
internal abstract partial class XDirectory
|
||||
{
|
||||
|
||||
private record SortedRecord(int? Id, Models.FileHolder FileHolder);
|
||||
|
||||
private static int GetCeilingAverage(List<string[]> fileCollection)
|
||||
{
|
||||
List<int> counts = new();
|
||||
@ -278,15 +280,59 @@ internal abstract partial class XDirectory
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Models.FileHolder> GetFileHolders(List<string[]> filesCollection)
|
||||
private static (bool, SortedRecord[]) GetSortedRecords(List<string[]> filesCollection)
|
||||
{
|
||||
List<Models.FileHolder> results = new();
|
||||
bool result = true;
|
||||
List<SortedRecord> results = new();
|
||||
int? id;
|
||||
short? multiplier;
|
||||
char negativeMarker;
|
||||
int absoluteValueOfId;
|
||||
Models.FileHolder fileHolder;
|
||||
int offset = IDirectory.GetOffset();
|
||||
int offsetLength = offset.ToString().Length;
|
||||
int sortOrderOnlyLengthIndex = offsetLength + 3;
|
||||
foreach (string[] files in filesCollection)
|
||||
results.AddRange(files.Select(l => new Models.FileHolder(l)));
|
||||
return results;
|
||||
{
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileHolder = new Models.FileHolder(file);
|
||||
if (!result)
|
||||
multiplier = null;
|
||||
else
|
||||
{
|
||||
if (fileHolder.NameWithoutExtension.Length < sortOrderOnlyLengthIndex)
|
||||
{
|
||||
result = false;
|
||||
multiplier = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
negativeMarker = fileHolder.NameWithoutExtension[sortOrderOnlyLengthIndex - 2];
|
||||
if (negativeMarker == '7')
|
||||
multiplier = 1;
|
||||
else if (negativeMarker == '3')
|
||||
multiplier = -1;
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
multiplier = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!result)
|
||||
id = null;
|
||||
else if (!int.TryParse(fileHolder.NameWithoutExtension[sortOrderOnlyLengthIndex..], out absoluteValueOfId))
|
||||
id = null;
|
||||
else
|
||||
id = absoluteValueOfId * multiplier;
|
||||
results.Add(new(id, fileHolder));
|
||||
}
|
||||
}
|
||||
return new(result, (from l in results orderby l.FileHolder.LastWriteTime, l.FileHolder.FullName.Length descending select l).ToArray());
|
||||
}
|
||||
|
||||
internal static (string[], List<(Models.FileHolder, string)>) GetToDoCollection(Properties.IPropertyConfiguration propertyConfiguration, bool copyDuplicates, List<string[]> filesCollection, string[] directories, Action? tick)
|
||||
internal static (string[], List<(Models.FileHolder, string)>) GetToDoCollection(Properties.IPropertyConfiguration propertyConfiguration, bool copyDuplicates, bool ifCanUseId, List<string[]> filesCollection, string[] directories, Action? tick)
|
||||
{
|
||||
List<(Models.FileHolder, string)> results = new();
|
||||
string checkFile;
|
||||
@ -295,18 +341,18 @@ internal abstract partial class XDirectory
|
||||
int directoryIndex;
|
||||
string directoryName;
|
||||
bool wrapped = false;
|
||||
List<int> distinctIds = new();
|
||||
List<string> distinct = new();
|
||||
List<string> distinctDirectories = new();
|
||||
List<Models.FileHolder> fileHolders = GetFileHolders(filesCollection);
|
||||
Models.FileHolder[] sortedFileHolders = (from l in fileHolders orderby l.LastWriteTime, l.FullName.Length descending select l).ToArray();
|
||||
foreach (Models.FileHolder fileHolder in sortedFileHolders)
|
||||
(bool all, SortedRecord[] sortedRecords) = GetSortedRecords(filesCollection);
|
||||
foreach (SortedRecord sortedRecord in sortedRecords)
|
||||
{
|
||||
tick?.Invoke();
|
||||
if (fileHolder.Name.EndsWith("len") || fileHolder.ExtensionLowered == ".id" || fileHolder.ExtensionLowered == ".lsv" || fileHolder.DirectoryName is null)
|
||||
if (sortedRecord.FileHolder.Name.EndsWith("len") || sortedRecord.FileHolder.ExtensionLowered == ".id" || sortedRecord.FileHolder.ExtensionLowered == ".lsv" || sortedRecord.FileHolder.DirectoryName is null)
|
||||
continue;
|
||||
(_, directoryIndex) = IPath.GetDirectoryNameAndIndex(propertyConfiguration.ResultAllInOneSubdirectoryLength, fileHolder.NameWithoutExtension);
|
||||
directoryName = Path.GetFileName(fileHolder.DirectoryName);
|
||||
if (directoryName.Length < propertyConfiguration.ResultAllInOneSubdirectoryLength + 3 || !fileHolder.Name.StartsWith(directoryName))
|
||||
(_, directoryIndex) = IPath.GetDirectoryNameAndIndex(propertyConfiguration.ResultAllInOneSubdirectoryLength, sortedRecord.FileHolder.NameWithoutExtension);
|
||||
directoryName = Path.GetFileName(sortedRecord.FileHolder.DirectoryName);
|
||||
if (directoryName.Length < propertyConfiguration.ResultAllInOneSubdirectoryLength + 3 || !sortedRecord.FileHolder.Name.StartsWith(directoryName))
|
||||
{
|
||||
if (wrapped)
|
||||
continue;
|
||||
@ -318,22 +364,38 @@ internal abstract partial class XDirectory
|
||||
wrapped = true;
|
||||
directory = Path.Combine(directories[directoryIndex], directoryName);
|
||||
}
|
||||
checkFile = Path.Combine(directory, $"{fileHolder.NameWithoutExtension}{fileHolder.ExtensionLowered}");
|
||||
if (distinct.Contains(checkFile))
|
||||
if (all)
|
||||
{
|
||||
if (sortedRecord.Id is null || !sortedRecord.FileHolder.NameWithoutExtension.EndsWith(sortedRecord.Id.Value.ToString()[1..]))
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
if (all && ifCanUseId)
|
||||
checkFile = Path.Combine(directory, $"{sortedRecord.Id}{sortedRecord.FileHolder.ExtensionLowered}");
|
||||
else
|
||||
checkFile = Path.Combine(directory, $"{sortedRecord.FileHolder.NameWithoutExtension}{sortedRecord.FileHolder.ExtensionLowered}");
|
||||
if ((sortedRecord.Id is not null && distinctIds.Contains(sortedRecord.Id.Value)) || distinct.Contains(checkFile))
|
||||
{
|
||||
if (string.IsNullOrEmpty(sortedRecord.FileHolder.DirectoryName))
|
||||
continue;
|
||||
if (!copyDuplicates)
|
||||
continue;
|
||||
for (int i = 1; i < int.MaxValue; i++)
|
||||
{
|
||||
fileInfo = new(checkFile);
|
||||
if (!fileInfo.Exists || fileHolder.Length == fileInfo.Length && fileHolder.LastWriteTime == fileInfo.LastWriteTime)
|
||||
checkFile = Path.Combine(directory, $"{fileHolder.NameWithoutExtension}.{i}dup{fileHolder.ExtensionLowered}");
|
||||
if (!fileInfo.Exists || sortedRecord.FileHolder.Length == fileInfo.Length && sortedRecord.FileHolder.LastWriteTime == fileInfo.LastWriteTime)
|
||||
checkFile = Path.Combine(directory, $"{sortedRecord.FileHolder.NameWithoutExtension}.{i}dup{sortedRecord.FileHolder.ExtensionLowered}");
|
||||
else
|
||||
checkFile = Path.Combine(directory, $"{fileHolder.NameWithoutExtension}.{i}why{fileHolder.ExtensionLowered}");
|
||||
checkFile = Path.Combine(directory, $"{sortedRecord.FileHolder.NameWithoutExtension}.{i}why{sortedRecord.FileHolder.ExtensionLowered}");
|
||||
if (sortedRecord.Id is not null)
|
||||
{
|
||||
if (distinctIds.Contains(sortedRecord.Id.Value))
|
||||
continue;
|
||||
distinctIds.Add(sortedRecord.Id.Value);
|
||||
}
|
||||
if (distinct.Contains(checkFile))
|
||||
continue;
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(fileHolder, checkFile));
|
||||
results.Add(new(sortedRecord.FileHolder, checkFile));
|
||||
if (!distinctDirectories.Contains(directory))
|
||||
distinctDirectories.Add(directory);
|
||||
break;
|
||||
@ -341,7 +403,9 @@ internal abstract partial class XDirectory
|
||||
continue;
|
||||
}
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(fileHolder, checkFile));
|
||||
if (sortedRecord.Id is not null)
|
||||
distinctIds.Add(sortedRecord.Id.Value);
|
||||
results.Add(new(sortedRecord.FileHolder, checkFile));
|
||||
if (!distinctDirectories.Contains(directory))
|
||||
distinctDirectories.Add(directory);
|
||||
}
|
||||
|
Reference in New Issue
Block a user