InPlace
This commit is contained in:
parent
b9ed5ee159
commit
9521aee8c6
@ -1,2 +0,0 @@
|
||||
[*.cs]
|
||||
csharp_preserve_single_line_statements = true
|
@ -1,82 +0,0 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Metadata.Models.Binder;
|
||||
|
||||
public class MetadataConfiguration
|
||||
{
|
||||
|
||||
public bool? ForceMetadataLastWriteTimeToCreationTime { get; set; }
|
||||
public string[]? IgnoreRulesKeyWords { get; set; }
|
||||
public int? IntMinValueLength { get; set; }
|
||||
public int? Offset { get; set; }
|
||||
public bool? PropertiesChangedForMetadata { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, BinderMetadataConfigurationSourceGenerationContext.Default.MetadataConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void PreVerify(IConfigurationRoot configurationRoot, MetadataConfiguration? configuration)
|
||||
{
|
||||
if (configuration?.ForceMetadataLastWriteTimeToCreationTime is null)
|
||||
{
|
||||
List<string> paths = [];
|
||||
foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers)
|
||||
{
|
||||
if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider)
|
||||
continue;
|
||||
if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider)
|
||||
continue;
|
||||
paths.Add(physicalFileProvider.Root);
|
||||
}
|
||||
throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void Verify(MetadataConfiguration configuration)
|
||||
{
|
||||
if (configuration.IntMinValueLength is null || configuration.IntMinValueLength != int.MinValue.ToString().Length) throw new NotSupportedException(nameof(configuration.IgnoreRulesKeyWords));
|
||||
if (configuration.IgnoreRulesKeyWords is null || configuration.IgnoreRulesKeyWords.Length == 0) throw new NullReferenceException(nameof(configuration.IgnoreRulesKeyWords));
|
||||
}
|
||||
|
||||
private static Shared.Models.MetadataConfiguration Get(MetadataConfiguration? configuration, Shared.Models.ResultConfiguration resultConfiguration)
|
||||
{
|
||||
Shared.Models.MetadataConfiguration result;
|
||||
if (configuration is null) throw new NullReferenceException(nameof(configuration));
|
||||
if (configuration.ForceMetadataLastWriteTimeToCreationTime is null) throw new NullReferenceException(nameof(configuration.ForceMetadataLastWriteTimeToCreationTime));
|
||||
if (configuration.IntMinValueLength is null) throw new NullReferenceException(nameof(configuration.IntMinValueLength));
|
||||
if (configuration.IgnoreRulesKeyWords is null) throw new NullReferenceException(nameof(configuration.IgnoreRulesKeyWords));
|
||||
if (configuration.Offset is null) throw new NullReferenceException(nameof(configuration.Offset));
|
||||
if (configuration.PropertiesChangedForMetadata is null) throw new NullReferenceException(nameof(configuration.PropertiesChangedForMetadata));
|
||||
Verify(configuration);
|
||||
result = new(resultConfiguration,
|
||||
configuration.ForceMetadataLastWriteTimeToCreationTime.Value,
|
||||
configuration.IgnoreRulesKeyWords,
|
||||
configuration.IntMinValueLength.Value,
|
||||
configuration.Offset.Value,
|
||||
configuration.PropertiesChangedForMetadata.Value);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Shared.Models.MetadataConfiguration Get(IConfigurationRoot configurationRoot, Shared.Models.ResultConfiguration resultConfiguration)
|
||||
{
|
||||
Shared.Models.MetadataConfiguration result;
|
||||
IConfigurationSection configurationSection = configurationRoot.GetSection(nameof(Shared.Models.MetadataConfiguration));
|
||||
#pragma warning disable IL3050, IL2026
|
||||
MetadataConfiguration? configuration = configurationSection.Get<MetadataConfiguration>();
|
||||
#pragma warning restore IL3050, IL2026
|
||||
PreVerify(configurationRoot, configuration);
|
||||
result = Get(configuration, resultConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(MetadataConfiguration))]
|
||||
internal partial class BinderMetadataConfigurationSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Metadata.Models.Binder;
|
||||
|
||||
public class ResultConfiguration
|
||||
{
|
||||
|
||||
public string? DateGroup { get; set; }
|
||||
public int? EpicYear { get; set; }
|
||||
public string? ModelName { get; set; }
|
||||
public int? NumberOfJitters { get; set; }
|
||||
public int? NumberOfTimesToUpsample { get; set; }
|
||||
public string? PredictorModelName { get; set; }
|
||||
public int? ResultAllInOneSubdirectoryLength { get; set; }
|
||||
public string? ResultCollection { get; set; }
|
||||
public string? ResultContent { get; set; }
|
||||
public string? ResultSingleton { get; set; }
|
||||
public string? RootDirectory { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, BinderResultConfigurationSourceGenerationContext.Default.ResultConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void PreVerify(IConfigurationRoot configurationRoot, ResultConfiguration? configuration)
|
||||
{
|
||||
if (configuration?.DateGroup is null)
|
||||
{
|
||||
List<string> paths = [];
|
||||
foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers)
|
||||
{
|
||||
if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider)
|
||||
continue;
|
||||
if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider)
|
||||
continue;
|
||||
paths.Add(physicalFileProvider.Root);
|
||||
}
|
||||
throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void Verify(ResultConfiguration configuration, bool requireRootDirectoryExists)
|
||||
{
|
||||
if (string.IsNullOrEmpty(configuration.DateGroup)) throw new NullReferenceException(nameof(configuration.DateGroup));
|
||||
if (string.IsNullOrEmpty(configuration.RootDirectory) || (requireRootDirectoryExists && !Directory.Exists(configuration.RootDirectory))) throw new NullReferenceException(nameof(configuration.RootDirectory));
|
||||
}
|
||||
|
||||
private static Shared.Models.ResultConfiguration Get(ResultConfiguration? configuration, bool requireRootDirectoryExists)
|
||||
{
|
||||
Shared.Models.ResultConfiguration result;
|
||||
if (configuration is null) throw new NullReferenceException(nameof(configuration));
|
||||
if (configuration.DateGroup is null) throw new NullReferenceException(nameof(configuration.DateGroup));
|
||||
if (configuration.EpicYear is null) throw new NullReferenceException(nameof(configuration.EpicYear));
|
||||
// if (configuration.ModelName is null) throw new NullReferenceException(nameof(configuration.ModelName));
|
||||
// if (configuration.NumberOfJitters is null) throw new NullReferenceException(nameof(configuration.NumberOfJitters));
|
||||
// if (configuration.NumberOfTimesToUpsample is null) throw new NullReferenceException(nameof(configuration.NumberOfTimesToUpsample));
|
||||
// if (configuration.PredictorModelName is null) throw new NullReferenceException(nameof(configuration.PredictorModelName));
|
||||
if (configuration.ResultAllInOneSubdirectoryLength is null) throw new NullReferenceException(nameof(configuration.ResultAllInOneSubdirectoryLength));
|
||||
if (configuration.ResultCollection is null) throw new NullReferenceException(nameof(configuration.ResultCollection));
|
||||
if (configuration.ResultContent is null) throw new NullReferenceException(nameof(configuration.ResultContent));
|
||||
if (configuration.ResultSingleton is null) throw new NullReferenceException(nameof(configuration.ResultSingleton));
|
||||
if (configuration.RootDirectory is null) throw new NullReferenceException(nameof(configuration.RootDirectory));
|
||||
Verify(configuration, requireRootDirectoryExists);
|
||||
result = new(configuration.DateGroup,
|
||||
configuration.EpicYear.Value,
|
||||
configuration.ModelName,
|
||||
configuration.NumberOfJitters,
|
||||
configuration.NumberOfTimesToUpsample,
|
||||
configuration.PredictorModelName,
|
||||
configuration.ResultAllInOneSubdirectoryLength.Value,
|
||||
configuration.ResultCollection,
|
||||
configuration.ResultContent,
|
||||
configuration.ResultSingleton,
|
||||
Path.GetFullPath(configuration.RootDirectory));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Shared.Models.ResultConfiguration Get(IConfigurationRoot configurationRoot, bool requireRootDirectoryExists)
|
||||
{
|
||||
Shared.Models.ResultConfiguration result;
|
||||
IConfigurationSection configurationSection = configurationRoot.GetSection(nameof(Shared.Models.ResultConfiguration));
|
||||
#pragma warning disable IL3050, IL2026
|
||||
ResultConfiguration? configuration = configurationSection.Get<ResultConfiguration>();
|
||||
#pragma warning restore IL3050, IL2026
|
||||
PreVerify(configurationRoot, configuration);
|
||||
result = Get(configuration, requireRootDirectoryExists);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(ResultConfiguration))]
|
||||
internal partial class BinderResultConfigurationSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
@ -1,12 +1,9 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models;
|
||||
|
||||
namespace View_by_Distance.Rename.Models;
|
||||
|
||||
public record AppSettings(MetadataConfiguration MetadataConfiguration,
|
||||
RenameConfiguration RenameConfiguration,
|
||||
ResultConfiguration ResultConfiguration,
|
||||
public record AppSettings(RenameConfiguration RenameConfiguration,
|
||||
string Company,
|
||||
int MaxDegreeOfParallelism,
|
||||
bool RequireRootDirectoryExists)
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models;
|
||||
|
||||
namespace View_by_Distance.Rename.Models.Binder;
|
||||
|
||||
@ -38,33 +37,30 @@ public class AppSettings
|
||||
}
|
||||
}
|
||||
|
||||
private static void Verify(AppSettings _)
|
||||
private static void Verify(Models.AppSettings appSettings)
|
||||
{
|
||||
if (appSettings.MaxDegreeOfParallelism > 1 && appSettings.RenameConfiguration.InPlace)
|
||||
throw new NotSupportedException($"Change configuration: {nameof(appSettings.RenameConfiguration.InPlace)} or {nameof(appSettings.MaxDegreeOfParallelism)}");
|
||||
}
|
||||
|
||||
private static Models.AppSettings Get(AppSettings? appSettings,
|
||||
MetadataConfiguration metadataConfiguration,
|
||||
Models.RenameConfiguration renameConfiguration,
|
||||
ResultConfiguration resultConfiguration)
|
||||
private static Models.AppSettings Get(AppSettings? appSettings, RenameConfiguration renameConfiguration)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
if (appSettings is null) throw new NullReferenceException(nameof(appSettings));
|
||||
if (appSettings.Company is null) throw new NullReferenceException(nameof(appSettings.Company));
|
||||
if (appSettings.MaxDegreeOfParallelism is null) throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
if (appSettings.RequireRootDirectoryExists is null) throw new NullReferenceException(nameof(appSettings.RequireRootDirectoryExists));
|
||||
Verify(appSettings);
|
||||
result = new(metadataConfiguration,
|
||||
renameConfiguration,
|
||||
resultConfiguration,
|
||||
result = new(renameConfiguration,
|
||||
appSettings.Company,
|
||||
appSettings.MaxDegreeOfParallelism.Value,
|
||||
appSettings.RequireRootDirectoryExists.Value);
|
||||
Verify(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Models.AppSettings Get(AppSettings? appSettings)
|
||||
{
|
||||
Models.AppSettings? results;
|
||||
Models.AppSettings? result;
|
||||
string? json;
|
||||
if (appSettings is null || appSettings.ConfigurationFileName is null)
|
||||
throw new NotSupportedException($"{nameof(appSettings.ConfigurationFileName)} must be set!");
|
||||
@ -84,13 +80,10 @@ public class AppSettings
|
||||
}
|
||||
if (string.IsNullOrEmpty(json) && File.Exists(jsonFile))
|
||||
json = File.ReadAllText(jsonFile);
|
||||
results = (string.IsNullOrEmpty(json) ? null : results = JsonSerializer.Deserialize(json, AppSettingsSourceGenerationContext.Default.AppSettings)) ??
|
||||
result = (string.IsNullOrEmpty(json) ? null : result = JsonSerializer.Deserialize(json, AppSettingsSourceGenerationContext.Default.AppSettings)) ??
|
||||
throw new NullReferenceException(nameof(Models.AppSettings));
|
||||
results = Get(appSettings,
|
||||
results.MetadataConfiguration,
|
||||
results.RenameConfiguration,
|
||||
results.ResultConfiguration);
|
||||
return results;
|
||||
result = Get(appSettings, result.RenameConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
||||
|
@ -1,95 +0,0 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Rename.Models.Binder;
|
||||
|
||||
public class RenameConfiguration
|
||||
{
|
||||
|
||||
public string? DefaultMaker { get; set; }
|
||||
public bool? ForceNewId { get; set; }
|
||||
public string[]? IgnoreExtensions { get; set; }
|
||||
public bool? OnlySaveIdentifiersToDisk { get; set; }
|
||||
public string? RelativePropertyCollectionFile { get; set; }
|
||||
public string[]? SidecarExtensions { get; set; }
|
||||
public bool? SkipIdFiles { get; set; }
|
||||
public string[]? ValidImageFormatExtensions { get; set; }
|
||||
public string[]? ValidVideoFormatExtensions { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, BinderConfigurationSourceGenerationContext.Default.RenameConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void PreVerify(IConfigurationRoot configurationRoot, RenameConfiguration? configuration)
|
||||
{
|
||||
if (configuration?.DefaultMaker is null)
|
||||
{
|
||||
List<string> paths = [];
|
||||
foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers)
|
||||
{
|
||||
if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider)
|
||||
continue;
|
||||
if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider)
|
||||
continue;
|
||||
paths.Add(physicalFileProvider.Root);
|
||||
}
|
||||
throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void Verify(RenameConfiguration configuration)
|
||||
{
|
||||
if (configuration.IgnoreExtensions is null || configuration.IgnoreExtensions.Length == 0) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.ValidImageFormatExtensions is null || configuration.ValidImageFormatExtensions.Length == 0) throw new NullReferenceException(nameof(configuration.ValidImageFormatExtensions));
|
||||
if (configuration.ValidVideoFormatExtensions is null || configuration.ValidVideoFormatExtensions.Length == 0) throw new NullReferenceException(nameof(configuration.ValidVideoFormatExtensions));
|
||||
}
|
||||
|
||||
private static Models.RenameConfiguration Get(RenameConfiguration? configuration, Shared.Models.MetadataConfiguration metadataConfiguration)
|
||||
{
|
||||
Models.RenameConfiguration result;
|
||||
if (configuration is null) throw new NullReferenceException(nameof(configuration));
|
||||
if (configuration.DefaultMaker is null) throw new NullReferenceException(nameof(configuration.DefaultMaker));
|
||||
if (configuration.ForceNewId is null) throw new NullReferenceException(nameof(configuration.ForceNewId));
|
||||
if (configuration.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.OnlySaveIdentifiersToDisk is null) throw new NullReferenceException(nameof(configuration.OnlySaveIdentifiersToDisk));
|
||||
if (configuration.RelativePropertyCollectionFile is null) throw new NullReferenceException(nameof(configuration.RelativePropertyCollectionFile));
|
||||
if (configuration.SidecarExtensions is null) throw new NullReferenceException(nameof(configuration.SidecarExtensions));
|
||||
if (configuration.SkipIdFiles is null) throw new NullReferenceException(nameof(configuration.SkipIdFiles));
|
||||
if (configuration.ValidImageFormatExtensions is null) throw new NullReferenceException(nameof(configuration.ValidImageFormatExtensions));
|
||||
if (configuration.ValidVideoFormatExtensions is null) throw new NullReferenceException(nameof(configuration.ValidVideoFormatExtensions));
|
||||
Verify(configuration);
|
||||
result = new(metadataConfiguration,
|
||||
configuration.DefaultMaker,
|
||||
configuration.ForceNewId.Value,
|
||||
configuration.IgnoreExtensions,
|
||||
configuration.OnlySaveIdentifiersToDisk.Value,
|
||||
configuration.RelativePropertyCollectionFile,
|
||||
configuration.SidecarExtensions,
|
||||
configuration.SkipIdFiles.Value,
|
||||
configuration.ValidImageFormatExtensions,
|
||||
configuration.ValidVideoFormatExtensions);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Models.RenameConfiguration Get(IConfigurationRoot configurationRoot, Shared.Models.MetadataConfiguration metadataConfiguration)
|
||||
{
|
||||
Models.RenameConfiguration result;
|
||||
IConfigurationSection configurationSection = configurationRoot.GetSection(nameof(RenameConfiguration));
|
||||
#pragma warning disable IL3050, IL2026
|
||||
RenameConfiguration? configuration = configurationSection.Get<RenameConfiguration>();
|
||||
#pragma warning restore IL3050, IL2026
|
||||
PreVerify(configurationRoot, configuration);
|
||||
result = Get(configuration, metadataConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(RenameConfiguration))]
|
||||
internal partial class BinderConfigurationSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
@ -8,6 +8,7 @@ public record RenameConfiguration(Shared.Models.MetadataConfiguration MetadataCo
|
||||
string DefaultMaker,
|
||||
bool ForceNewId,
|
||||
string[] IgnoreExtensions,
|
||||
bool InPlace,
|
||||
bool OnlySaveIdentifiersToDisk,
|
||||
string RelativePropertyCollectionFile,
|
||||
string[] SidecarExtensions,
|
||||
|
@ -117,26 +117,42 @@ public partial class Rename : IRename, IDisposable
|
||||
|
||||
#pragma warning restore CA1416
|
||||
|
||||
private static void RenameUrl(FilePath filePath)
|
||||
private void NonParallelismAndInPlace(MetadataConfiguration metadataConfiguration, ExifDirectory exifDirectory, FileInfo fileInfo, FilePath filePath, ReadOnlyCollection<FileHolder> sidecarFiles)
|
||||
{
|
||||
FileHolder fileHolder;
|
||||
string[] lines = File.ReadAllLines(filePath.FullName);
|
||||
if (lines.Length == 1)
|
||||
if (exifDirectory.Id is null)
|
||||
throw new NotImplementedException();
|
||||
int i = 0;
|
||||
DateTime? dateTime;
|
||||
const string jpg = ".jpg";
|
||||
const string jpeg = ".jpeg";
|
||||
List<ToDo> toDoCollection = [];
|
||||
ReadOnlyCollection<string> keywords = IMetadata.GetKeywords(exifDirectory);
|
||||
bool hasIgnoreKeyword = metadataConfiguration.IgnoreRulesKeyWords.Any(keywords.Contains);
|
||||
string checkDirectory = Path.Combine(filePath.DirectoryName, filePath.FileNameFirstSegment);
|
||||
string checkFileExtension = filePath.ExtensionLowered == jpeg ? jpg : filePath.ExtensionLowered;
|
||||
string paddedId = IId.GetPaddedId(metadataConfiguration, exifDirectory.Id.Value, hasIgnoreKeyword, i);
|
||||
string checkFile = Path.Combine(checkDirectory, $"{paddedId}{checkFileExtension}");
|
||||
if (File.Exists(checkFile))
|
||||
{
|
||||
fileHolder = FileHolder.Get(lines[0]);
|
||||
if (fileHolder.Exists)
|
||||
{
|
||||
string checkFile;
|
||||
checkFile = IId.GetIgnoreFullPath(filePath, fileHolder);
|
||||
if (lines[0] == checkFile || lines[0].Length != checkFile.Length)
|
||||
throw new NotSupportedException();
|
||||
File.Move(lines[0], checkFile);
|
||||
checkFile = string.Concat(checkFile, ".del");
|
||||
if (File.Exists(checkFile))
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
File.Delete(filePath.FullName);
|
||||
toDoCollection.Add(new(checkDirectory, filePath, checkFile, JsonFile: false));
|
||||
if (sidecarFiles.Count != 0)
|
||||
{
|
||||
dateTime = IDate.GetDateTimeOriginal(exifDirectory);
|
||||
bool hasDateTimeOriginal = dateTime is not null;
|
||||
dateTime ??= IDate.GetMinimum(exifDirectory);
|
||||
RecordB recordB = new(dateTime.Value, exifDirectory, filePath, sidecarFiles, hasDateTimeOriginal, hasIgnoreKeyword, fileInfo.FullName);
|
||||
toDoCollection.AddRange(GetSidecarFiles(metadataConfiguration, recordB, [], checkDirectory, paddedId));
|
||||
}
|
||||
_ = RenameFilesInDirectories(new(toDoCollection));
|
||||
string jsonFile = Path.Combine(checkDirectory, $"{paddedId}{checkFileExtension}.json");
|
||||
File.Move(fileInfo.FullName, jsonFile);
|
||||
}
|
||||
|
||||
private static List<RecordA> GetRecordACollection(ILogger<Program>? logger, IRename rename, RenameConfiguration renameConfiguration, IEnumerable<string> files, A_Metadata metadata)
|
||||
private List<RecordA> GetRecordACollection(ILogger<Program>? logger, RenameConfiguration renameConfiguration, IRename rename, IEnumerable<string> files, A_Metadata metadata)
|
||||
{
|
||||
List<RecordA> results = [];
|
||||
int index = -1;
|
||||
@ -163,17 +179,14 @@ public partial class Rename : IRename, IDisposable
|
||||
if (renameConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered))
|
||||
continue;
|
||||
filePath = FilePath.Get(renameConfiguration.MetadataConfiguration, fileHolder, index);
|
||||
if (filePath.ExtensionLowered == ".url" && filePath.Id is not null)
|
||||
{
|
||||
RenameUrl(filePath);
|
||||
continue;
|
||||
}
|
||||
if (renameConfiguration.SkipIdFiles && filePath.Id is not null && (filePath.IsIntelligentIdFormat || filePath.SortOrder is not null))
|
||||
continue;
|
||||
if (!renameConfiguration.ForceNewId && filePath.Id is not null)
|
||||
{
|
||||
ffmpegFiles = null;
|
||||
deterministicHashCode = new(null, filePath.Id, null);
|
||||
if (renameConfiguration.InPlace)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -195,12 +208,14 @@ public partial class Rename : IRename, IDisposable
|
||||
logger?.LogWarning("<{filePath}>", filePath.FullName);
|
||||
continue;
|
||||
}
|
||||
results.Add(new(exifDirectory, fileInfo, filePath, new(sidecarFiles)));
|
||||
if (ffmpegFiles is not null)
|
||||
{
|
||||
foreach (string ffmpegFile in ffmpegFiles)
|
||||
File.Delete(ffmpegFile);
|
||||
}
|
||||
if (renameConfiguration.InPlace)
|
||||
NonParallelismAndInPlace(renameConfiguration.MetadataConfiguration, exifDirectory, fileInfo, filePath, new(sidecarFiles));
|
||||
results.Add(new(exifDirectory, fileInfo, filePath, new(sidecarFiles)));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
@ -225,17 +240,18 @@ public partial class Rename : IRename, IDisposable
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private ReadOnlyCollection<RecordB> GetRecordBCollection(ILogger<Program>? logger, IRename rename, AppSettings appSettings, RenameConfiguration renameConfiguration, DirectoryInfo directoryInfo)
|
||||
private ReadOnlyCollection<RecordB> GetRecordBCollection(ILogger<Program>? logger, AppSettings appSettings, IRename rename, DirectoryInfo directoryInfo)
|
||||
{
|
||||
ReadOnlyCollection<RecordB> results;
|
||||
List<RecordA> recordACollection = [];
|
||||
RenameConfiguration renameConfiguration = appSettings.RenameConfiguration;
|
||||
A_Metadata metadata = new(renameConfiguration.MetadataConfiguration);
|
||||
int appSettingsMaxDegreeOfParallelism = appSettings.MaxDegreeOfParallelism;
|
||||
IEnumerable<string> files = appSettingsMaxDegreeOfParallelism == 1 ? Directory.GetFiles(directoryInfo.FullName, "*", SearchOption.AllDirectories) : Directory.EnumerateFiles(directoryInfo.FullName, "*", SearchOption.AllDirectories);
|
||||
int filesCount = appSettingsMaxDegreeOfParallelism == 1 ? files.Count() : 123000;
|
||||
_ProgressBar = new(filesCount, "EnumerateFiles load", new ProgressBarOptions() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true });
|
||||
if (appSettingsMaxDegreeOfParallelism == 1)
|
||||
recordACollection.AddRange(GetRecordACollection(logger, rename, renameConfiguration, files, metadata));
|
||||
recordACollection.AddRange(GetRecordACollection(logger, renameConfiguration, rename, files, metadata));
|
||||
else
|
||||
{
|
||||
List<string> distinct = [];
|
||||
@ -347,9 +363,9 @@ public partial class Rename : IRename, IDisposable
|
||||
const string jpeg = ".jpeg";
|
||||
string jsonFileSubDirectory;
|
||||
bool? directoryCheck = GetDirectoryCheck(renameConfiguration);
|
||||
VerifyIntMinValueLength(renameConfiguration.MetadataConfiguration, recordBCollection);
|
||||
MetadataConfiguration metadataConfiguration = renameConfiguration.MetadataConfiguration;
|
||||
VerifyIntMinValueLength(metadataConfiguration, recordBCollection);
|
||||
bool multipleDirectoriesWithFiles = directoryCheck is not null && directoryCheck.Value;
|
||||
ResultConfiguration resultConfiguration = renameConfiguration.MetadataConfiguration.ResultConfiguration;
|
||||
ReadOnlyCollection<int> ids = identifiers is null ? new([]) : new((from l in identifiers select l.Id).ToArray());
|
||||
ReadOnlyCollection<RecordB> sorted = new((from l in recordBCollection orderby l.DateTime select l).ToArray());
|
||||
for (int i = 0; i < sorted.Count; i++)
|
||||
@ -363,7 +379,7 @@ public partial class Rename : IRename, IDisposable
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
continue;
|
||||
checkFileExtension = record.FilePath.ExtensionLowered == jpeg ? jpg : record.FilePath.ExtensionLowered;
|
||||
paddedId = IId.GetPaddedId(renameConfiguration.MetadataConfiguration, record.ExifDirectory.Id.Value, record.HasIgnoreKeyword, i);
|
||||
paddedId = IId.GetPaddedId(metadataConfiguration, record.ExifDirectory.Id.Value, record.HasIgnoreKeyword, i);
|
||||
jsonFileSubDirectory = Path.GetDirectoryName(Path.GetDirectoryName(record.JsonFile)) ?? throw new Exception();
|
||||
checkFile = Path.Combine(checkDirectory, $"{paddedId}{checkFileExtension}");
|
||||
if (checkFile == record.FilePath.FullName)
|
||||
@ -374,12 +390,12 @@ public partial class Rename : IRename, IDisposable
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
}
|
||||
(directoryName, _) = IPath.GetDirectoryNameAndIndex(resultConfiguration, record.ExifDirectory.Id.Value);
|
||||
(directoryName, _) = IPath.GetDirectoryNameAndIndex(metadataConfiguration.ResultConfiguration, record.ExifDirectory.Id.Value);
|
||||
jsonFile = Path.Combine(jsonFileSubDirectory, directoryName, $"{record.ExifDirectory.Id.Value}{checkFileExtension}.json");
|
||||
if (record.JsonFile != jsonFile)
|
||||
{
|
||||
fileHolder = FileHolder.Get(record.JsonFile);
|
||||
filePath = FilePath.Get(renameConfiguration.MetadataConfiguration, fileHolder, index: null);
|
||||
filePath = FilePath.Get(metadataConfiguration, fileHolder, index: null);
|
||||
results.Add(new(null, filePath, jsonFile, JsonFile: true));
|
||||
}
|
||||
if (distinct.Contains(checkFile))
|
||||
@ -388,7 +404,7 @@ public partial class Rename : IRename, IDisposable
|
||||
results.Add(new(checkDirectory, record.FilePath, checkFile, JsonFile: false));
|
||||
if (record.SidecarFiles.Count == 0)
|
||||
continue;
|
||||
results.AddRange(GetSidecarFiles(renameConfiguration.MetadataConfiguration, record, distinct, checkDirectory, paddedId));
|
||||
results.AddRange(GetSidecarFiles(metadataConfiguration, record, distinct, checkDirectory, paddedId));
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
@ -464,8 +480,15 @@ public partial class Rename : IRename, IDisposable
|
||||
throw new Exception($"Invalid {nameof(renameConfiguration.RelativePropertyCollectionFile)}");
|
||||
DirectoryInfo directoryInfo = new(Path.GetFullPath(metadataConfiguration.ResultConfiguration.RootDirectory));
|
||||
logger?.LogInformation("{Ticks} {RootDirectory}", ticks, directoryInfo.FullName);
|
||||
ReadOnlyCollection<RecordB> recordBCollection = GetRecordBCollection(logger, rename, appSettings, renameConfiguration, directoryInfo);
|
||||
ReadOnlyCollection<RecordB> recordBCollection = GetRecordBCollection(logger, appSettings, rename, directoryInfo);
|
||||
SaveIdentifiersToDisk(ticks, renameConfiguration, aMetadataCollectionDirectory, recordBCollection);
|
||||
if (renameConfiguration.InPlace)
|
||||
{
|
||||
if (recordBCollection.Count > 0)
|
||||
recordBCollection = new([]);
|
||||
string aMetadataSingletonDirectory = IResult.GetResultsGroupDirectory(metadataConfiguration.ResultConfiguration, nameof(A_Metadata));
|
||||
_ = IPath.DeleteEmptyDirectories(aMetadataSingletonDirectory);
|
||||
}
|
||||
if (!renameConfiguration.OnlySaveIdentifiersToDisk)
|
||||
{
|
||||
ReadOnlyCollection<ToDo> toDoCollection = GetToDoCollection(renameConfiguration, identifiers, recordBCollection);
|
||||
|
Loading…
x
Reference in New Issue
Block a user