Rename files to padded number string
This commit is contained in:
@ -37,6 +37,7 @@
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -7,6 +7,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Drag.Drop.Set.Item.Models;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Stateless;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
@ -15,6 +16,14 @@ namespace View_by_Distance.Drag.Drop.Set.Item;
|
||||
public partial class DragDropSetPropertyItem : Form
|
||||
{
|
||||
|
||||
private record Record(FileHolder FileHolder,
|
||||
bool IsIgnoreExtension,
|
||||
bool IsValidImageFormatExtension,
|
||||
int Id,
|
||||
DateTime? DateTimeOriginal,
|
||||
short? PropertyItemType,
|
||||
string? Value);
|
||||
|
||||
private readonly ILogger _Logger;
|
||||
private readonly TextBox _PathTextBox;
|
||||
private readonly TextBox _JsonTextBox;
|
||||
@ -23,6 +32,7 @@ public partial class DragDropSetPropertyItem : Form
|
||||
private readonly ProgressBar _ProgressBar;
|
||||
private readonly string _WorkingDirectory;
|
||||
private readonly IsEnvironment _IsEnvironment;
|
||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||
|
||||
public DragDropSetPropertyItem()
|
||||
{
|
||||
@ -50,6 +60,9 @@ public partial class DragDropSetPropertyItem : Form
|
||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
||||
Log.Logger = loggerConfiguration.CreateLogger();
|
||||
logger = Log.ForContext<DragDropSetPropertyItem>();
|
||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
propertyConfiguration.Update();
|
||||
logger.Information("Complete");
|
||||
_Logger = logger;
|
||||
_AppSettings = appSettings;
|
||||
@ -102,18 +115,28 @@ public partial class DragDropSetPropertyItem : Form
|
||||
_JsonTextBox.Text = message;
|
||||
}
|
||||
|
||||
private static List<(string, int, DateTime?, short?, string?)> GetCollection(ASCIIEncoding asciiEncoding, int tagId, List<string> files)
|
||||
private List<Record> GetRecords(ASCIIEncoding asciiEncoding, int tagId, List<string> files)
|
||||
{
|
||||
List<(string, int, DateTime?, short?, string?)> results = new();
|
||||
List<Record> results = new();
|
||||
int? id;
|
||||
string? value;
|
||||
string? message;
|
||||
FileHolder fileHolder;
|
||||
bool isIgnoreExtension;
|
||||
DateTime? dateTimeOriginal;
|
||||
PropertyItem? propertyItem;
|
||||
Shared.Models.Property property;
|
||||
bool isValidImageFormatExtension;
|
||||
foreach (string file in files)
|
||||
{
|
||||
property = Property.Models.A_Property.GetImageProperty(file);
|
||||
if (property.Id is null)
|
||||
fileHolder = new(file);
|
||||
isValidImageFormatExtension = _PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
isIgnoreExtension = isValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
(dateTimeOriginal, _, id, message) = Property.Models.Stateless.IProperty.Get(_PropertyConfiguration.PopulatePropertyId, fileHolder, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
if (message is not null)
|
||||
throw new Exception(message);
|
||||
if (id is null)
|
||||
continue;
|
||||
using Image image = Image.FromFile(file);
|
||||
using Image image = Image.FromFile(fileHolder.FullName);
|
||||
if (!image.PropertyIdList.Contains(tagId))
|
||||
(propertyItem, value) = (null, null);
|
||||
else
|
||||
@ -131,36 +154,37 @@ public partial class DragDropSetPropertyItem : Form
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
results.Add((file, property.Id.Value, property.DateTimeOriginal, propertyItem?.Type, value));
|
||||
results.Add(new(fileHolder, isIgnoreExtension, isValidImageFormatExtension, id.Value, dateTimeOriginal, propertyItem?.Type, value));
|
||||
}
|
||||
if (files.Count != results.Count)
|
||||
throw new NotSupportedException();
|
||||
return results;
|
||||
}
|
||||
|
||||
private void SetPropertyItem(string setTo, int tagId, short type, ConstructorInfo constructorInfo, List<(string, int, DateTime?, short?, string?)> collection)
|
||||
private void SetPropertyItem(string setTo, int tagId, short type, ASCIIEncoding asciiEncoding, ConstructorInfo constructorInfo, List<Record> records)
|
||||
{
|
||||
int? id;
|
||||
Bitmap bitmap;
|
||||
string? message;
|
||||
string checkFile;
|
||||
PropertyItem? propertyItem;
|
||||
Shared.Models.Property property;
|
||||
foreach ((string file, int id, DateTime? dateTimeOriginal, short? propertyItemType, string? value) in collection)
|
||||
foreach (Record record in records)
|
||||
{
|
||||
if (propertyItemType is not null && propertyItemType.Value != type)
|
||||
if (record.PropertyItemType is not null && record.PropertyItemType.Value != type)
|
||||
throw new NotSupportedException();
|
||||
if ((dateTimeOriginal is null || !string.IsNullOrEmpty(value) || value == setTo) && !_AppSettings.IgnoreRulesKeyWords.Contains(setTo))
|
||||
if ((record.DateTimeOriginal is null || !string.IsNullOrEmpty(record.Value) || record.Value == setTo) && !_AppSettings.IgnoreRulesKeyWords.Contains(setTo))
|
||||
continue;
|
||||
checkFile = $"{file}.exif";
|
||||
propertyItem = IProperty.GetPropertyItem(constructorInfo, tagId, type, setTo);
|
||||
bitmap = new(file);
|
||||
checkFile = $"{record.FileHolder.FullName}.exif";
|
||||
propertyItem = Property.Models.Stateless.IProperty.GetPropertyItem(constructorInfo, tagId, type, setTo);
|
||||
bitmap = new(record.FileHolder.FullName);
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
bitmap.Save(checkFile);
|
||||
bitmap.Dispose();
|
||||
property = Property.Models.A_Property.GetImageProperty(checkFile);
|
||||
if (property.Id is null || property.Id.Value != id)
|
||||
(_, _, id, message) = Property.Models.Stateless.IProperty.Get(_PropertyConfiguration.PopulatePropertyId, record.FileHolder, record.IsIgnoreExtension, record.IsValidImageFormatExtension, asciiEncoding);
|
||||
if (id is null || id.Value != record.Id)
|
||||
throw new NotSupportedException();
|
||||
File.Delete(file);
|
||||
File.Move(checkFile, file);
|
||||
File.Delete(record.FileHolder.FullName);
|
||||
File.Move(checkFile, record.FileHolder.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,11 +194,11 @@ public partial class DragDropSetPropertyItem : Form
|
||||
ASCIIEncoding asciiEncoding = new();
|
||||
int xpKeywords = (int)IExif.Tags.XPKeywords;
|
||||
ConstructorInfo? constructorInfo = typeof(PropertyItem).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, null, Array.Empty<Type>(), null) ?? throw new Exception();
|
||||
List<(string, int, DateTime?, short?, string?)> collection = GetCollection(asciiEncoding, xpKeywords, files);
|
||||
if (!collection.Any())
|
||||
List<Record> records = GetRecords(asciiEncoding, xpKeywords, files);
|
||||
if (!records.Any())
|
||||
SetMessage("No data");
|
||||
else
|
||||
SetPropertyItem(setTo, xpKeywords, type, constructorInfo, collection);
|
||||
SetPropertyItem(setTo, xpKeywords, type, asciiEncoding, constructorInfo, records);
|
||||
}
|
||||
|
||||
private void SetPropertyItem(string[] paths, string setTo)
|
||||
|
@ -50,5 +50,48 @@
|
||||
"ValidKeyWords": [
|
||||
"Review"
|
||||
],
|
||||
"WorkingDirectoryName": "PharesApps"
|
||||
"WorkingDirectoryName": "PharesApps",
|
||||
"Windows": {
|
||||
"Configuration": {
|
||||
"DateGroup": "dd514b88",
|
||||
"DiffPropertyDirectory": "",
|
||||
"FileNameDirectorySeparator": ".Z.",
|
||||
"ForcePropertyLastWriteTimeToCreationTime": false,
|
||||
"MaxImagesInDirectoryForTopLevelFirstPass": 10,
|
||||
"OutputExtension": ".jpg",
|
||||
"Pattern": "[^ABCDEFGHIJKLMNOPQRSTUVWXYZbcdfghjklmnpqrstvwxyz0-9]",
|
||||
"PopulatePropertyId": true,
|
||||
"PropertiesChangedForProperty": false,
|
||||
"ResultAllInOne": "_ _ _",
|
||||
"ResultAllInOneSubdirectoryLength": 2,
|
||||
"ResultCollection": "[]",
|
||||
"ResultContent": "()",
|
||||
"ResultSingleton": "{}",
|
||||
"RootDirectory": "C:/Tmp/Phares/Compare/Images-dd514b88",
|
||||
"IgnoreExtensions": [
|
||||
".gif",
|
||||
".GIF",
|
||||
".nef",
|
||||
".NEF",
|
||||
".pdf",
|
||||
".PDF"
|
||||
],
|
||||
"ValidImageFormatExtensions": [
|
||||
".bmp",
|
||||
".BMP",
|
||||
".gif",
|
||||
".GIF",
|
||||
".jpeg",
|
||||
".JPEG",
|
||||
".jpg",
|
||||
".JPG",
|
||||
".png",
|
||||
".PNG",
|
||||
".tiff",
|
||||
".TIFF",
|
||||
".tif",
|
||||
".TIF"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user