hide-splat-nine-and-get-moved-duplicates-with-same-splat-nine
This commit is contained in:
parent
e728838d25
commit
d9d55d9e4c
@ -636,57 +636,100 @@ public partial class DlibDotNet : IDlibDotNet, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<int, Identifier> GetSplatNineIdentifiersAndHideSplatNine(Property.Models.Configuration propertyConfiguration, string bResultsFullGroupDirectory, ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection)
|
||||
private static ReadOnlyCollection<FilePath> HideSplatNineAndGetMovedDuplicatesWithSameSplatNine(Property.Models.Configuration propertyConfiguration, ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>> keyValuePairs)
|
||||
{
|
||||
Dictionary<int, Identifier> results = [];
|
||||
ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>> keyValuePairs = FilePath.GetKeyValuePairs(filePathsCollection);
|
||||
if (keyValuePairs.Count > 0)
|
||||
List<FilePath> results = [];
|
||||
string checkFile;
|
||||
FileInfo fileInfo;
|
||||
FilePath? filePath;
|
||||
string checkDirectory;
|
||||
List<FilePath> collection = [];
|
||||
foreach (KeyValuePair<int, ReadOnlyCollection<FilePath>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
string json;
|
||||
string paddedId;
|
||||
FileInfo fileInfo;
|
||||
FilePath filePath;
|
||||
FileHolder fileHolder;
|
||||
Identifier identifier;
|
||||
string[] directoryNames;
|
||||
List<int> distinct = [];
|
||||
List<Identifier> identifiers = [];
|
||||
string rootDirectory = propertyConfiguration.RootDirectory.Replace('\\', '/');
|
||||
string bMetadataCollectionDirectory = Path.Combine(bResultsFullGroupDirectory, propertyConfiguration.ResultCollection);
|
||||
if (!Directory.Exists(bMetadataCollectionDirectory))
|
||||
_ = Directory.CreateDirectory(bMetadataCollectionDirectory);
|
||||
foreach (KeyValuePair<int, ReadOnlyCollection<FilePath>> keyValuePair in keyValuePairs)
|
||||
collection.Clear();
|
||||
for (int i = 0; i < keyValuePair.Value.Count; i++)
|
||||
{
|
||||
for (int i = 0; i < keyValuePair.Value.Count; i++)
|
||||
filePath = keyValuePair.Value[i];
|
||||
if (!filePath.FullName.Contains(" !9"))
|
||||
collection.Add(filePath);
|
||||
else
|
||||
{
|
||||
filePath = keyValuePair.Value[0];
|
||||
if (filePath.Id is null)
|
||||
continue;
|
||||
directoryNames = keyValuePair.Value.Select(l => l.DirectoryFullPath.Replace('\\', '/')).ToArray();
|
||||
paddedId = IId.GetPaddedId(propertyConfiguration, filePath.Id.Value, filePath.HasIgnoreKeyword, filePath.HasDateTimeOriginal, index: null);
|
||||
identifier = new(directoryNames, filePath.ExtensionLowered, filePath.HasDateTimeOriginal, filePath.Id.Value, filePath.Length, paddedId, filePath.LastWriteTicks);
|
||||
if (i == 0)
|
||||
identifiers.Add(identifier);
|
||||
if (!filePath.FullName.Contains(" !9"))
|
||||
continue;
|
||||
fileInfo = new(filePath.FullName);
|
||||
fileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(fileInfo);
|
||||
if (!fileInfo.Attributes.HasFlag(FileAttributes.Hidden))
|
||||
File.SetAttributes(fileHolder.FullName, FileAttributes.Hidden);
|
||||
if (distinct.Contains(keyValuePair.Key))
|
||||
continue;
|
||||
distinct.Add(keyValuePair.Key);
|
||||
results.Add(keyValuePair.Key, identifier);
|
||||
File.SetAttributes(fileInfo.FullName, FileAttributes.Hidden);
|
||||
}
|
||||
}
|
||||
json = JsonSerializer.Serialize(results.Values.ToArray(), IdentifierCollectionSourceGenerationContext.Default.IdentifierArray);
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(bMetadataCollectionDirectory, "!9.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
json = JsonSerializer.Serialize((from l in identifiers orderby l.DirectoryNames.Length descending, l.Id select l).ToArray(), IdentifierCollectionSourceGenerationContext.Default.IdentifierArray);
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(bMetadataCollectionDirectory, ".json"), json.Replace(rootDirectory, string.Empty), updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
if (keyValuePair.Value.Count == 1 || collection.Count == keyValuePair.Value.Count)
|
||||
continue;
|
||||
foreach (FilePath fp in collection)
|
||||
{
|
||||
if (fp.HasDateTimeOriginal is null || !fp.HasDateTimeOriginal.Value)
|
||||
break;
|
||||
checkDirectory = Path.Combine(propertyConfiguration.RootDirectory, $"{new DateTime(fp.LastWriteTicks):yyyy MM} Already in Splat Nine");
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
checkFile = Path.Combine(checkDirectory, fp.Name);
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(fp.FullName, checkFile);
|
||||
results.Add(fp);
|
||||
}
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<int, Identifier> GetSplatNineIdentifiers(Property.Models.Configuration propertyConfiguration, string bResultsFullGroupDirectory, ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>> keyValuePairs)
|
||||
{
|
||||
Dictionary<int, Identifier> results = [];
|
||||
string json;
|
||||
string paddedId;
|
||||
FilePath? filePath;
|
||||
Identifier identifier;
|
||||
string[] directoryNames;
|
||||
string rootDirectory = propertyConfiguration.RootDirectory.Replace('\\', '/');
|
||||
string bMetadataCollectionDirectory = Path.Combine(bResultsFullGroupDirectory, propertyConfiguration.ResultCollection);
|
||||
if (!Directory.Exists(bMetadataCollectionDirectory))
|
||||
_ = Directory.CreateDirectory(bMetadataCollectionDirectory);
|
||||
foreach (KeyValuePair<int, ReadOnlyCollection<FilePath>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
filePath = null;
|
||||
for (int i = 0; i < keyValuePair.Value.Count; i++)
|
||||
{
|
||||
filePath = keyValuePair.Value[i];
|
||||
if (filePath.FullName.Contains(" !9"))
|
||||
break;
|
||||
filePath = null;
|
||||
}
|
||||
if (filePath?.Id is null)
|
||||
continue;
|
||||
directoryNames = keyValuePair.Value.Select(l => l.DirectoryFullPath.Replace('\\', '/')).ToArray();
|
||||
paddedId = IId.GetPaddedId(propertyConfiguration, filePath.Id.Value, filePath.HasIgnoreKeyword, filePath.HasDateTimeOriginal, index: null);
|
||||
identifier = new(directoryNames, filePath.ExtensionLowered, filePath.HasDateTimeOriginal, filePath.Id.Value, filePath.Length, paddedId, filePath.LastWriteTicks);
|
||||
results.Add(keyValuePair.Key, identifier);
|
||||
}
|
||||
json = JsonSerializer.Serialize(results.Values.ToArray(), IdentifierCollectionSourceGenerationContext.Default.IdentifierArray);
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(bMetadataCollectionDirectory, "!9.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
json = JsonSerializer.Serialize((from l in results orderby l.Value.PaddedId select l.Value).ToArray(), IdentifierCollectionSourceGenerationContext.Default.IdentifierArray);
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(bMetadataCollectionDirectory, ".json"), json.Replace(rootDirectory, string.Empty), updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<int, Identifier> GetSplatNineIdentifiersAndHideSplatNine(Property.Models.Configuration propertyConfiguration, string bResultsFullGroupDirectory, ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection)
|
||||
{
|
||||
ReadOnlyDictionary<int, Identifier> results;
|
||||
ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>> keyValuePairs = FilePath.GetKeyValuePairs(filePathsCollection);
|
||||
if (keyValuePairs.Count == 0)
|
||||
results = new(new Dictionary<int, Identifier>());
|
||||
else
|
||||
{
|
||||
ReadOnlyCollection<FilePath> moved = HideSplatNineAndGetMovedDuplicatesWithSameSplatNine(propertyConfiguration, keyValuePairs);
|
||||
if (moved.Count > 0)
|
||||
throw new Exception($"House cleaning needed!{Environment.NewLine}{string.Join(Environment.NewLine, moved.Select(l => l.Id))}");
|
||||
results = GetSplatNineIdentifiers(propertyConfiguration, bResultsFullGroupDirectory, keyValuePairs);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private ReadOnlyCollection<Mapping> GetMappings(Property.Models.Configuration propertyConfiguration, string eDistanceContentDirectory, ReadOnlyCollection<Container> readOnlyContainers, MapLogic mapLogic, bool distinctItems)
|
||||
{
|
||||
List<Mapping> results = [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user