InPlaceMoveDirectory
DirectoryName => DirectoryFullPath
This commit is contained in:
parent
2f75667f20
commit
368390b353
@ -17,9 +17,9 @@ internal static class Get
|
|||||||
foreach (string file in files)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
fileHolder = FileHolder.Get(file);
|
fileHolder = FileHolder.Get(file);
|
||||||
if (fileHolder.DirectoryName is null)
|
if (fileHolder.DirectoryFullPath is null)
|
||||||
continue;
|
continue;
|
||||||
key = $"{Path.Combine(fileHolder.DirectoryName, fileHolder.NameWithoutExtension)}";
|
key = $"{Path.Combine(fileHolder.DirectoryFullPath, fileHolder.NameWithoutExtension)}";
|
||||||
if (!results.TryGetValue(key, out fileHolders))
|
if (!results.TryGetValue(key, out fileHolders))
|
||||||
{
|
{
|
||||||
results.Add(key, []);
|
results.Add(key, []);
|
||||||
@ -44,7 +44,7 @@ internal static class Get
|
|||||||
FilePath? fastForwardMovingPictureExpertsGroupFilePath;
|
FilePath? fastForwardMovingPictureExpertsGroupFilePath;
|
||||||
ReadOnlyCollection<string>? fastForwardMovingPictureExpertsGroupFiles;
|
ReadOnlyCollection<string>? fastForwardMovingPictureExpertsGroupFiles;
|
||||||
FilePath filePath = FilePath.Get(renameConfiguration.MetadataConfiguration, fileHolder, index: null);
|
FilePath filePath = FilePath.Get(renameConfiguration.MetadataConfiguration, fileHolder, index: null);
|
||||||
string key = $"{Path.Combine(fileHolder.DirectoryName ?? throw new NotSupportedException(), fileHolder.NameWithoutExtension)}";
|
string key = $"{Path.Combine(fileHolder.DirectoryFullPath ?? throw new NotSupportedException(), fileHolder.NameWithoutExtension)}";
|
||||||
if (distinct.Contains(key))
|
if (distinct.Contains(key))
|
||||||
throw new NotSupportedException("Turn off parallelism when sidecar files are present!");
|
throw new NotSupportedException("Turn off parallelism when sidecar files are present!");
|
||||||
if (!renameConfiguration.SkipIdFiles || filePath.Id is null || (!filePath.IsIntelligentIdFormat && filePath.SortOrder is not null))
|
if (!renameConfiguration.SkipIdFiles || filePath.Id is null || (!filePath.IsIntelligentIdFormat && filePath.SortOrder is not null))
|
||||||
|
@ -39,10 +39,10 @@ public class AppSettings
|
|||||||
|
|
||||||
private static void Verify(Models.AppSettings appSettings)
|
private static void Verify(Models.AppSettings appSettings)
|
||||||
{
|
{
|
||||||
if (appSettings.MaxDegreeOfParallelism > 1 && (appSettings.RenameConfiguration.InPlaceWithOriginalName || appSettings.RenameConfiguration.InPlace))
|
if (appSettings.MaxDegreeOfParallelism > 1 && (appSettings.RenameConfiguration.InPlace || appSettings.RenameConfiguration.InPlaceMoveDirectory || appSettings.RenameConfiguration.InPlaceWithOriginalName))
|
||||||
throw new NotSupportedException($"Change configuration: {nameof(appSettings.RenameConfiguration.InPlace)} or {nameof(appSettings.MaxDegreeOfParallelism)}");
|
throw new NotSupportedException($"Change configuration: {nameof(appSettings.RenameConfiguration.InPlace)} or {nameof(appSettings.RenameConfiguration.InPlaceMoveDirectory)} or {nameof(appSettings.MaxDegreeOfParallelism)}");
|
||||||
if (appSettings.RenameConfiguration.InPlaceWithOriginalName && appSettings.RenameConfiguration.InPlace)
|
if (appSettings.RenameConfiguration.InPlace && appSettings.RenameConfiguration.InPlaceMoveDirectory && appSettings.RenameConfiguration.InPlaceWithOriginalName)
|
||||||
throw new NotSupportedException($"Change configuration: {nameof(appSettings.RenameConfiguration.InPlace)} or {nameof(appSettings.RenameConfiguration.InPlaceWithOriginalName)}");
|
throw new NotSupportedException($"Change configuration: {nameof(appSettings.RenameConfiguration.InPlace)} or {nameof(appSettings.RenameConfiguration.InPlaceMoveDirectory)} or {nameof(appSettings.RenameConfiguration.InPlaceWithOriginalName)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Models.AppSettings Get(AppSettings? appSettings, RenameConfiguration renameConfiguration)
|
private static Models.AppSettings Get(AppSettings? appSettings, RenameConfiguration renameConfiguration)
|
||||||
|
@ -9,6 +9,7 @@ public record RenameConfiguration(Shared.Models.MetadataConfiguration MetadataCo
|
|||||||
bool ForceNewId,
|
bool ForceNewId,
|
||||||
string[] IgnoreExtensions,
|
string[] IgnoreExtensions,
|
||||||
bool InPlace,
|
bool InPlace,
|
||||||
|
bool InPlaceMoveDirectory,
|
||||||
bool InPlaceWithOriginalName,
|
bool InPlaceWithOriginalName,
|
||||||
bool OnlySaveIdentifiersToDisk,
|
bool OnlySaveIdentifiersToDisk,
|
||||||
string RelativePropertyCollectionFile,
|
string RelativePropertyCollectionFile,
|
||||||
|
@ -60,7 +60,7 @@ public partial class Rename : IRename, IDisposable
|
|||||||
{
|
{
|
||||||
CommandTask<CommandResult> commandTask = Cli.Wrap("L:/Git/ffmpeg-2024-10-02-git-358fdf3083-full_build/bin/ffmpeg.exe")
|
CommandTask<CommandResult> commandTask = Cli.Wrap("L:/Git/ffmpeg-2024-10-02-git-358fdf3083-full_build/bin/ffmpeg.exe")
|
||||||
.WithArguments(new[] { "-i", filePath.FullName, "-vf", "select=eq(n\\,0)", "-q:v", "1", $"{filePath.Name}-%4d.jpg" })
|
.WithArguments(new[] { "-i", filePath.FullName, "-vf", "select=eq(n\\,0)", "-q:v", "1", $"{filePath.Name}-%4d.jpg" })
|
||||||
.WithWorkingDirectory(filePath.DirectoryName)
|
.WithWorkingDirectory(filePath.DirectoryFullPath)
|
||||||
.ExecuteAsync();
|
.ExecuteAsync();
|
||||||
commandTask.Task.Wait();
|
commandTask.Task.Wait();
|
||||||
check = true;
|
check = true;
|
||||||
@ -71,7 +71,7 @@ public partial class Rename : IRename, IDisposable
|
|||||||
}
|
}
|
||||||
if (check)
|
if (check)
|
||||||
{
|
{
|
||||||
results.AddRange(Directory.GetFiles(filePath.DirectoryName, $"{filePath.Name}-*.jpg", SearchOption.TopDirectoryOnly));
|
results.AddRange(Directory.GetFiles(filePath.DirectoryFullPath, $"{filePath.Name}-*.jpg", SearchOption.TopDirectoryOnly));
|
||||||
if (results.Count == 0)
|
if (results.Count == 0)
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
File.SetCreationTime(results[0], new(filePath.CreationTicks));
|
File.SetCreationTime(results[0], new(filePath.CreationTicks));
|
||||||
@ -132,7 +132,7 @@ public partial class Rename : IRename, IDisposable
|
|||||||
string checkFileExtension = filePath.ExtensionLowered == jpeg ? jpg : filePath.ExtensionLowered;
|
string checkFileExtension = filePath.ExtensionLowered == jpeg ? jpg : filePath.ExtensionLowered;
|
||||||
bool hasDateTimeOriginal = dateTime is not null;
|
bool hasDateTimeOriginal = dateTime is not null;
|
||||||
string paddedId = IId.GetPaddedId(metadataConfiguration, exifDirectory.Id.Value, hasIgnoreKeyword, hasDateTimeOriginal, i);
|
string paddedId = IId.GetPaddedId(metadataConfiguration, exifDirectory.Id.Value, hasIgnoreKeyword, hasDateTimeOriginal, i);
|
||||||
string checkDirectory = renameConfiguration.InPlaceWithOriginalName ? Path.Combine(filePath.DirectoryName, filePath.FileNameFirstSegment) : filePath.DirectoryName;
|
string checkDirectory = renameConfiguration.InPlaceWithOriginalName ? Path.Combine(filePath.DirectoryFullPath, filePath.FileNameFirstSegment) : filePath.DirectoryFullPath;
|
||||||
string checkFile = Path.Combine(checkDirectory, $"{paddedId}{checkFileExtension}");
|
string checkFile = Path.Combine(checkDirectory, $"{paddedId}{checkFileExtension}");
|
||||||
if (checkFile != filePath.FullName)
|
if (checkFile != filePath.FullName)
|
||||||
{
|
{
|
||||||
@ -170,6 +170,7 @@ public partial class Rename : IRename, IDisposable
|
|||||||
int index = -1;
|
int index = -1;
|
||||||
FileInfo fileInfo;
|
FileInfo fileInfo;
|
||||||
FilePath filePath;
|
FilePath filePath;
|
||||||
|
string directoryName;
|
||||||
ExifDirectory exifDirectory;
|
ExifDirectory exifDirectory;
|
||||||
List<FileHolder> sidecarFiles;
|
List<FileHolder> sidecarFiles;
|
||||||
DeterministicHashCode deterministicHashCode;
|
DeterministicHashCode deterministicHashCode;
|
||||||
@ -182,7 +183,11 @@ public partial class Rename : IRename, IDisposable
|
|||||||
index += 1;
|
index += 1;
|
||||||
rename.Tick();
|
rename.Tick();
|
||||||
if (keyValuePair.Value.Count > 1 && !renameConfiguration.ForceNewId)
|
if (keyValuePair.Value.Count > 1 && !renameConfiguration.ForceNewId)
|
||||||
|
{
|
||||||
|
if (renameConfiguration.InPlaceMoveDirectory)
|
||||||
|
continue;
|
||||||
throw new NotSupportedException($"When sidecar files are present {nameof(renameConfiguration.ForceNewId)} must be true!");
|
throw new NotSupportedException($"When sidecar files are present {nameof(renameConfiguration.ForceNewId)} must be true!");
|
||||||
|
}
|
||||||
if (keyValuePair.Value.Count > 2)
|
if (keyValuePair.Value.Count > 2)
|
||||||
throw new NotSupportedException("Too many sidecar files!");
|
throw new NotSupportedException("Too many sidecar files!");
|
||||||
foreach (FileHolder fileHolder in keyValuePair.Value)
|
foreach (FileHolder fileHolder in keyValuePair.Value)
|
||||||
@ -198,7 +203,8 @@ public partial class Rename : IRename, IDisposable
|
|||||||
{
|
{
|
||||||
fastForwardMovingPictureExpertsGroupFiles = null;
|
fastForwardMovingPictureExpertsGroupFiles = null;
|
||||||
deterministicHashCode = new(null, filePath.Id, null);
|
deterministicHashCode = new(null, filePath.Id, null);
|
||||||
if (renameConfiguration.InPlaceWithOriginalName || (renameConfiguration.InPlace && filePath.DirectoryName.EndsWith(filePath.Id.Value.ToString())))
|
directoryName = Path.GetFileName(filePath.DirectoryFullPath);
|
||||||
|
if (renameConfiguration.InPlaceWithOriginalName || (renameConfiguration.InPlace && directoryName.EndsWith(filePath.Id.Value.ToString())))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -293,27 +299,37 @@ public partial class Rename : IRename, IDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? GetCheckDirectory(RenameConfiguration renameConfiguration, RecordB record, ReadOnlyCollection<int> ids, bool multipleDirectoriesWithFiles)
|
private static string GetTFW(RecordB record, bool? isWrongYear) =>
|
||||||
|
string.Concat(record.HasDateTimeOriginal ? "T" : "F", isWrongYear is not null && isWrongYear.Value ? "W" : record.FastForwardMovingPictureExpertsGroupUsed ? "V" : "I");
|
||||||
|
|
||||||
|
private static string GetDirectoryName(string year, string tfw, string prefix, string? splat, int seasonValue, string seasonName, string makerSplit) =>
|
||||||
|
splat is null ? $"{prefix}{year} {tfw}{year}.{seasonValue} {seasonName}{makerSplit}" : $"{prefix}{year} {tfw}{year}{splat}";
|
||||||
|
|
||||||
|
private static string? GetCheckDirectory(RenameConfiguration renameConfiguration, RecordB record, ReadOnlyCollection<int> ids, bool multipleDirectoriesWithFiles, string paddedId)
|
||||||
{
|
{
|
||||||
string? result;
|
string? result;
|
||||||
if (record.FilePath.DirectoryName is null)
|
|
||||||
throw new NullReferenceException(nameof(record.FilePath.DirectoryName));
|
|
||||||
string year = record.DateTime.Year.ToString();
|
string year = record.DateTime.Year.ToString();
|
||||||
string checkDirectoryName = Path.GetFileName(record.FilePath.DirectoryName);
|
string checkDirectoryName = Path.GetFileName(record.FilePath.DirectoryFullPath);
|
||||||
if (multipleDirectoriesWithFiles && !checkDirectoryName.Contains(year))
|
if (multipleDirectoriesWithFiles && !checkDirectoryName.Contains(year))
|
||||||
result = null;
|
result = null;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
(bool? isWrongYear, string[] years) = IDate.IsWrongYear(record.FilePath, record.ExifDirectory);
|
||||||
|
if (renameConfiguration.InPlaceMoveDirectory && !record.FilePath.FileNameFirstSegment.Contains(paddedId))
|
||||||
|
result = null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string tfw = GetTFW(record, isWrongYear);
|
||||||
string? maker = IMetadata.GetMaker(record.ExifDirectory);
|
string? maker = IMetadata.GetMaker(record.ExifDirectory);
|
||||||
string hasDateTimeOriginal = record.HasDateTimeOriginal ? "Has" : "Not";
|
string[] segments = checkDirectoryName.Split(years, StringSplitOptions.None);
|
||||||
|
string? splat = checkDirectoryName[^3..][1] == '!' ? checkDirectoryName[^3..] : null;
|
||||||
(int seasonValue, string seasonName) = IDate.GetSeason(record.DateTime.DayOfYear);
|
(int seasonValue, string seasonName) = IDate.GetSeason(record.DateTime.DayOfYear);
|
||||||
string rootDirectory = renameConfiguration.MetadataConfiguration.ResultConfiguration.RootDirectory;
|
string rootDirectory = renameConfiguration.MetadataConfiguration.ResultConfiguration.RootDirectory;
|
||||||
string splat = record.FilePath.DirectoryName[^3..][1] == '!' ? record.FilePath.DirectoryName[^3..] : string.Empty;
|
|
||||||
string fastForwardMovingPictureExpertsGroupUsed = record.FastForwardMovingPictureExpertsGroupUsed ? "Video" : "Image";
|
|
||||||
string contains = record.ExifDirectory.Id is null || ids.Contains(record.ExifDirectory.Id.Value) ? "_ Exists _" : "_ New-Destination _";
|
string contains = record.ExifDirectory.Id is null || ids.Contains(record.ExifDirectory.Id.Value) ? "_ Exists _" : "_ New-Destination _";
|
||||||
string makerSplit = string.IsNullOrEmpty(maker) ? string.IsNullOrEmpty(renameConfiguration.DefaultMaker) ? string.Empty : renameConfiguration.DefaultMaker : $" {maker.Split(' ')[0]}";
|
string makerSplit = string.IsNullOrEmpty(maker) ? string.IsNullOrEmpty(renameConfiguration.DefaultMaker) ? string.Empty : renameConfiguration.DefaultMaker : $" {maker.Split(' ')[0]}";
|
||||||
string directoryName = $"{year}.{seasonValue} {seasonName}{makerSplit}{splat}";
|
string directoryName = GetDirectoryName(year, tfw, segments[0], splat, seasonValue, seasonName, makerSplit);
|
||||||
result = Path.Combine(rootDirectory, contains, fastForwardMovingPictureExpertsGroupUsed, hasDateTimeOriginal, directoryName);
|
result = Path.GetFullPath(Path.Combine(rootDirectory, contains, directoryName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -348,9 +364,12 @@ public partial class Rename : IRename, IDisposable
|
|||||||
private static bool? GetDirectoryCheck(RenameConfiguration renameConfiguration)
|
private static bool? GetDirectoryCheck(RenameConfiguration renameConfiguration)
|
||||||
{
|
{
|
||||||
bool? result = null;
|
bool? result = null;
|
||||||
foreach (string directory in Directory.GetDirectories(renameConfiguration.MetadataConfiguration.ResultConfiguration.RootDirectory, "*", SearchOption.TopDirectoryOnly))
|
IEnumerable<string> files;
|
||||||
|
string[] directories = Directory.GetDirectories(renameConfiguration.MetadataConfiguration.ResultConfiguration.RootDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||||
|
foreach (string directory in directories)
|
||||||
{
|
{
|
||||||
foreach (string _ in Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories))
|
files = Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories);
|
||||||
|
foreach (string _ in files)
|
||||||
{
|
{
|
||||||
if (result is null)
|
if (result is null)
|
||||||
result = false;
|
result = false;
|
||||||
@ -390,13 +409,11 @@ public partial class Rename : IRename, IDisposable
|
|||||||
record = sorted[i];
|
record = sorted[i];
|
||||||
if (record.ExifDirectory.Id is null)
|
if (record.ExifDirectory.Id is null)
|
||||||
continue;
|
continue;
|
||||||
if (record.FilePath.DirectoryName is null)
|
paddedId = IId.GetPaddedId(metadataConfiguration, record.ExifDirectory.Id.Value, record.HasIgnoreKeyword, record.HasDateTimeOriginal, i);
|
||||||
continue;
|
checkDirectory = GetCheckDirectory(renameConfiguration, record, ids, multipleDirectoriesWithFiles, paddedId);
|
||||||
checkDirectory = GetCheckDirectory(renameConfiguration, record, ids, multipleDirectoriesWithFiles);
|
|
||||||
if (string.IsNullOrEmpty(checkDirectory))
|
if (string.IsNullOrEmpty(checkDirectory))
|
||||||
continue;
|
continue;
|
||||||
checkFileExtension = record.FilePath.ExtensionLowered == jpeg ? jpg : record.FilePath.ExtensionLowered;
|
checkFileExtension = record.FilePath.ExtensionLowered == jpeg ? jpg : record.FilePath.ExtensionLowered;
|
||||||
paddedId = IId.GetPaddedId(metadataConfiguration, record.ExifDirectory.Id.Value, record.HasIgnoreKeyword, record.HasDateTimeOriginal, i);
|
|
||||||
jsonFileSubDirectory = Path.GetDirectoryName(Path.GetDirectoryName(record.JsonFile)) ?? throw new Exception();
|
jsonFileSubDirectory = Path.GetDirectoryName(Path.GetDirectoryName(record.JsonFile)) ?? throw new Exception();
|
||||||
checkFile = Path.Combine(checkDirectory, $"{paddedId}{checkFileExtension}");
|
checkFile = Path.Combine(checkDirectory, $"{paddedId}{checkFileExtension}");
|
||||||
if (checkFile == record.FilePath.FullName)
|
if (checkFile == record.FilePath.FullName)
|
||||||
|
@ -4,7 +4,7 @@ using System.Text.Json.Serialization;
|
|||||||
namespace View_by_Distance.Shared.Models;
|
namespace View_by_Distance.Shared.Models;
|
||||||
|
|
||||||
public record FileHolder(DateTime? CreationTime,
|
public record FileHolder(DateTime? CreationTime,
|
||||||
string? DirectoryName,
|
string? DirectoryFullPath,
|
||||||
bool Exists,
|
bool Exists,
|
||||||
string ExtensionLowered,
|
string ExtensionLowered,
|
||||||
string FullName,
|
string FullName,
|
||||||
@ -52,7 +52,7 @@ public record FileHolder(DateTime? CreationTime,
|
|||||||
{
|
{
|
||||||
FileHolder result;
|
FileHolder result;
|
||||||
result = new(new(filePath.CreationTicks),
|
result = new(new(filePath.CreationTicks),
|
||||||
filePath.DirectoryName,
|
filePath.DirectoryFullPath,
|
||||||
true,
|
true,
|
||||||
filePath.ExtensionLowered,
|
filePath.ExtensionLowered,
|
||||||
filePath.FullName,
|
filePath.FullName,
|
||||||
@ -66,7 +66,7 @@ public record FileHolder(DateTime? CreationTime,
|
|||||||
|
|
||||||
private static FileHolder GetExisting(FileHolder fileHolder) =>
|
private static FileHolder GetExisting(FileHolder fileHolder) =>
|
||||||
new(fileHolder.CreationTime,
|
new(fileHolder.CreationTime,
|
||||||
fileHolder.DirectoryName,
|
fileHolder.DirectoryFullPath,
|
||||||
fileHolder.Exists,
|
fileHolder.Exists,
|
||||||
fileHolder.ExtensionLowered,
|
fileHolder.ExtensionLowered,
|
||||||
fileHolder.FullName,
|
fileHolder.FullName,
|
||||||
@ -78,7 +78,7 @@ public record FileHolder(DateTime? CreationTime,
|
|||||||
|
|
||||||
private static FileHolder GetNonExisting(FileHolder fileHolder) =>
|
private static FileHolder GetNonExisting(FileHolder fileHolder) =>
|
||||||
new(null,
|
new(null,
|
||||||
fileHolder.DirectoryName,
|
fileHolder.DirectoryFullPath,
|
||||||
fileHolder.Exists,
|
fileHolder.Exists,
|
||||||
fileHolder.ExtensionLowered,
|
fileHolder.ExtensionLowered,
|
||||||
fileHolder.FullName,
|
fileHolder.FullName,
|
||||||
|
@ -5,7 +5,7 @@ using View_by_Distance.Shared.Models.Stateless.Methods;
|
|||||||
namespace View_by_Distance.Shared.Models;
|
namespace View_by_Distance.Shared.Models;
|
||||||
|
|
||||||
public record FilePath(long CreationTicks,
|
public record FilePath(long CreationTicks,
|
||||||
string DirectoryName,
|
string DirectoryFullPath,
|
||||||
string ExtensionLowered,
|
string ExtensionLowered,
|
||||||
string FileNameFirstSegment,
|
string FileNameFirstSegment,
|
||||||
string FullName,
|
string FullName,
|
||||||
@ -41,7 +41,7 @@ public record FilePath(long CreationTicks,
|
|||||||
int? sortOder;
|
int? sortOder;
|
||||||
string fileNameFirstSegment = fileHolder.Name.Split('.')[0];
|
string fileNameFirstSegment = fileHolder.Name.Split('.')[0];
|
||||||
int sortOrderOnlyLengthIndex = metadataConfiguration.Offset.ToString().Length;
|
int sortOrderOnlyLengthIndex = metadataConfiguration.Offset.ToString().Length;
|
||||||
string fileDirectoryName = fileHolder.DirectoryName ?? throw new NullReferenceException();
|
string fileDirectoryFullPath = fileHolder.DirectoryFullPath ?? throw new NullReferenceException();
|
||||||
bool isIntelligentIdFormat = IId.NameWithoutExtensionIsIntelligentIdFormat(metadataConfiguration, fileNameFirstSegment);
|
bool isIntelligentIdFormat = IId.NameWithoutExtensionIsIntelligentIdFormat(metadataConfiguration, fileNameFirstSegment);
|
||||||
bool isPaddedIntelligentIdFormat = IId.NameWithoutExtensionIsPaddedIntelligentIdFormat(metadataConfiguration, sortOrderOnlyLengthIndex, fileNameFirstSegment);
|
bool isPaddedIntelligentIdFormat = IId.NameWithoutExtensionIsPaddedIntelligentIdFormat(metadataConfiguration, sortOrderOnlyLengthIndex, fileNameFirstSegment);
|
||||||
bool fileNameFirstSegmentIsIdFormat = !isPaddedIntelligentIdFormat && !isIntelligentIdFormat && IId.NameWithoutExtensionIsIdFormat(metadataConfiguration, fileHolder);
|
bool fileNameFirstSegmentIsIdFormat = !isPaddedIntelligentIdFormat && !isIntelligentIdFormat && IId.NameWithoutExtensionIsIdFormat(metadataConfiguration, fileHolder);
|
||||||
@ -69,7 +69,7 @@ public record FilePath(long CreationTicks,
|
|||||||
else
|
else
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
result = new(fileHolder.CreationTime.Value.Ticks,
|
result = new(fileHolder.CreationTime.Value.Ticks,
|
||||||
fileDirectoryName,
|
fileDirectoryFullPath,
|
||||||
fileHolder.ExtensionLowered,
|
fileHolder.ExtensionLowered,
|
||||||
fileNameFirstSegment,
|
fileNameFirstSegment,
|
||||||
fileHolder.FullName,
|
fileHolder.FullName,
|
||||||
|
@ -3,21 +3,16 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
|||||||
public interface IDate
|
public interface IDate
|
||||||
{
|
{
|
||||||
|
|
||||||
(bool?, string[]) TestStatic_IsWrongYear(string[] segments, string year) =>
|
(bool?, string[]) TestStatic_IsWrongYear(FilePath filePath, ExifDirectory exifDirectory) =>
|
||||||
IsWrongYear(segments, year);
|
IsWrongYear(filePath, exifDirectory);
|
||||||
static (bool?, string[]) IsWrongYear(string[] segments, string year) =>
|
static (bool?, string[]) IsWrongYear(FilePath filePath, ExifDirectory exifDirectory) =>
|
||||||
XDate.IsWrongYear(segments, year);
|
XDate.IsWrongYear(filePath, exifDirectory);
|
||||||
|
|
||||||
(int Season, string seasonName) TestStatic_GetSeason(int dayOfYear) =>
|
(int Season, string seasonName) TestStatic_GetSeason(int dayOfYear) =>
|
||||||
GetSeason(dayOfYear);
|
GetSeason(dayOfYear);
|
||||||
static (int Season, string seasonName) GetSeason(int dayOfYear) =>
|
static (int Season, string seasonName) GetSeason(int dayOfYear) =>
|
||||||
XDate.GetSeason(dayOfYear);
|
XDate.GetSeason(dayOfYear);
|
||||||
|
|
||||||
(int Season, string seasonName) TestStatic_GetSeasonAB(int dayOfYear) =>
|
|
||||||
GetSeasonAB(dayOfYear);
|
|
||||||
static (int Season, string seasonName) GetSeasonAB(int dayOfYear) =>
|
|
||||||
XDate.GetSeasonAB(dayOfYear);
|
|
||||||
|
|
||||||
DateTime? TestStatic_GetDateTimeOriginal(ExifDirectory exifDirectory) =>
|
DateTime? TestStatic_GetDateTimeOriginal(ExifDirectory exifDirectory) =>
|
||||||
GetDateTimeOriginal(exifDirectory);
|
GetDateTimeOriginal(exifDirectory);
|
||||||
static DateTime? GetDateTimeOriginal(ExifDirectory exifDirectory) =>
|
static DateTime? GetDateTimeOriginal(ExifDirectory exifDirectory) =>
|
||||||
|
@ -26,14 +26,14 @@ public interface IId
|
|||||||
string TestStatic_GetIgnoreFullPath(FilePath filePath, FileHolder fileHolder) =>
|
string TestStatic_GetIgnoreFullPath(FilePath filePath, FileHolder fileHolder) =>
|
||||||
GetIgnoreFullPath(filePath, fileHolder);
|
GetIgnoreFullPath(filePath, fileHolder);
|
||||||
static string GetIgnoreFullPath(FilePath filePath, FileHolder fileHolder) =>
|
static string GetIgnoreFullPath(FilePath filePath, FileHolder fileHolder) =>
|
||||||
fileHolder.DirectoryName is null ?
|
fileHolder.DirectoryFullPath is null ?
|
||||||
throw new NotSupportedException() :
|
throw new NotSupportedException() :
|
||||||
filePath.Id > -1 ?
|
filePath.Id > -1 ?
|
||||||
fileHolder.NameWithoutExtension[^1] == '9' ?
|
fileHolder.NameWithoutExtension[^1] == '9' ?
|
||||||
Path.Combine(fileHolder.DirectoryName, $"{fileHolder.NameWithoutExtension[..^1]}8{fileHolder.ExtensionLowered}") :
|
Path.Combine(fileHolder.DirectoryFullPath, $"{fileHolder.NameWithoutExtension[..^1]}8{fileHolder.ExtensionLowered}") :
|
||||||
throw new NotSupportedException("High") :
|
throw new NotSupportedException("High") :
|
||||||
fileHolder.NameWithoutExtension[^1] == '1' ?
|
fileHolder.NameWithoutExtension[^1] == '1' ?
|
||||||
Path.Combine(fileHolder.DirectoryName, $"{fileHolder.NameWithoutExtension[..^1]}2{fileHolder.ExtensionLowered}") :
|
Path.Combine(fileHolder.DirectoryFullPath, $"{fileHolder.NameWithoutExtension[..^1]}2{fileHolder.ExtensionLowered}") :
|
||||||
throw new NotSupportedException("Low");
|
throw new NotSupportedException("Low");
|
||||||
|
|
||||||
bool TestStatic_NameWithoutExtensionIsIntelligentIdFormat(MetadataConfiguration metadataConfiguration, string fileNameFirstSegment) =>
|
bool TestStatic_NameWithoutExtensionIsIntelligentIdFormat(MetadataConfiguration metadataConfiguration, string fileNameFirstSegment) =>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@ -11,31 +12,18 @@ internal abstract class XDate
|
|||||||
(int Season, string seasonName) result = dayOfYear switch
|
(int Season, string seasonName) result = dayOfYear switch
|
||||||
{
|
{
|
||||||
< 78 => new(0, "Winter"),
|
< 78 => new(0, "Winter"),
|
||||||
< 171 => new(1, "Spring"),
|
< 124 => new(1, "Spring"),
|
||||||
< 264 => new(2, "Summer"),
|
< 171 => new(2, "Spring"),
|
||||||
< 354 => new(3, "Fall"),
|
< 217 => new(3, "Summer"),
|
||||||
_ => new(4, "Winter")
|
< 264 => new(4, "Summer"),
|
||||||
|
< 309 => new(5, "Fall"),
|
||||||
|
< 354 => new(6, "Fall"),
|
||||||
|
_ => new(7, "Winter")
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static (int Season, string seasonName) GetSeasonAB(int dayOfYear)
|
private static (bool?, string[]) IsWrongYear(string[] segments, string year)
|
||||||
{
|
|
||||||
(int Season, string seasonName) result = dayOfYear switch
|
|
||||||
{
|
|
||||||
< 78 => new(0, "WinterA"),
|
|
||||||
< 124 => new(1, "SpringA"),
|
|
||||||
< 171 => new(1, "SpringB"),
|
|
||||||
< 217 => new(2, "SummerA"),
|
|
||||||
< 264 => new(2, "SummerB"),
|
|
||||||
< 309 => new(3, "FallA"),
|
|
||||||
< 354 => new(3, "FallB"),
|
|
||||||
_ => new(4, "WinterB")
|
|
||||||
};
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static (bool?, string[]) IsWrongYear(string[] segments, string year)
|
|
||||||
{
|
{
|
||||||
bool? result;
|
bool? result;
|
||||||
string[] results = (
|
string[] results = (
|
||||||
@ -66,6 +54,47 @@ internal abstract class XDate
|
|||||||
return new(result, results);
|
return new(result, results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static (bool?, string[]) IsWrongYear(FilePath filePath, ExifDirectory exifDirectory)
|
||||||
|
{
|
||||||
|
string[] results = [];
|
||||||
|
bool? result = null;
|
||||||
|
string year;
|
||||||
|
string directoryName;
|
||||||
|
string[] directorySegments;
|
||||||
|
List<DateTime> collection = [];
|
||||||
|
string? check = Path.GetFullPath(filePath.FullName);
|
||||||
|
string? pathRoot = Path.GetPathRoot(filePath.FullName);
|
||||||
|
if (string.IsNullOrEmpty(pathRoot))
|
||||||
|
throw new Exception();
|
||||||
|
DateTime? dateTimeOriginal = GetDateTimeOriginal(exifDirectory);
|
||||||
|
if (dateTimeOriginal is not null)
|
||||||
|
collection.Add(dateTimeOriginal.Value);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ReadOnlyCollection<DateTime> dateTimes = GetDateTimes(exifDirectory);
|
||||||
|
foreach (DateTime dateTime in dateTimes)
|
||||||
|
collection.Add(dateTime);
|
||||||
|
}
|
||||||
|
foreach (DateTime dateTime in collection)
|
||||||
|
{
|
||||||
|
year = dateTime.ToString("yyyy");
|
||||||
|
for (int i = 0; i < int.MaxValue; i++)
|
||||||
|
{
|
||||||
|
check = Path.GetDirectoryName(check);
|
||||||
|
if (string.IsNullOrEmpty(check) || check == pathRoot)
|
||||||
|
break;
|
||||||
|
directoryName = Path.GetFileName(check);
|
||||||
|
directorySegments = directoryName.Split(' ');
|
||||||
|
(result, results) = IsWrongYear(directorySegments, year);
|
||||||
|
if (result is not null)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (result is not null && !result.Value)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return new(result, results);
|
||||||
|
}
|
||||||
|
|
||||||
internal static DateTime? GetDateTimeOriginal(ExifDirectory exifDirectory)
|
internal static DateTime? GetDateTimeOriginal(ExifDirectory exifDirectory)
|
||||||
{
|
{
|
||||||
DateTime? result;
|
DateTime? result;
|
||||||
@ -153,9 +182,8 @@ internal abstract class XDate
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static DateTime GetMinimum(ExifDirectory exifDirectory)
|
private static ReadOnlyCollection<DateTime> GetDateTimes(ExifDirectory exifDirectory)
|
||||||
{
|
{
|
||||||
DateTime result;
|
|
||||||
List<DateTime> results = [];
|
List<DateTime> results = [];
|
||||||
foreach (ExifDirectoryBase exifDirectoryBase in exifDirectory.ExifBaseDirectories)
|
foreach (ExifDirectoryBase exifDirectoryBase in exifDirectory.ExifBaseDirectories)
|
||||||
{
|
{
|
||||||
@ -207,6 +235,13 @@ internal abstract class XDate
|
|||||||
results.Add(fileMetadataDirectory.FileModifiedDate.Value);
|
results.Add(fileMetadataDirectory.FileModifiedDate.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return new(results);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static DateTime GetMinimum(ExifDirectory exifDirectory)
|
||||||
|
{
|
||||||
|
DateTime result;
|
||||||
|
ReadOnlyCollection<DateTime> results = GetDateTimes(exifDirectory);
|
||||||
result = results.Count == 0 ? DateTime.MinValue : results.Min();
|
result = results.Count == 0 ? DateTime.MinValue : results.Min();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user