net7.0
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>10.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
@ -26,14 +26,16 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.13.14" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft-WindowsAPICodePack-Core" Version="1.1.4" />
|
||||
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="Serilog" Version="2.10.0" />
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.WindowsAPICodePack.Shell;
|
||||
using Phares.Shared;
|
||||
using Serilog;
|
||||
using System.Diagnostics;
|
||||
@ -15,7 +16,9 @@ public partial class Form : System.Windows.Forms.Form
|
||||
|
||||
private readonly ILogger _Logger;
|
||||
private readonly TextBox _TextBox;
|
||||
private readonly List<string> _Lines;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly ProgressBar _ProgressBar;
|
||||
private readonly string _WorkingDirectory;
|
||||
private readonly Configuration _Configuration;
|
||||
private readonly IsEnvironment _IsEnvironment;
|
||||
@ -27,6 +30,7 @@ public partial class Form : System.Windows.Forms.Form
|
||||
public Form()
|
||||
{
|
||||
InitializeComponent();
|
||||
_Lines = new();
|
||||
ILogger logger;
|
||||
AppSettings appSettings;
|
||||
string workingDirectory;
|
||||
@ -62,7 +66,9 @@ public partial class Form : System.Windows.Forms.Form
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
_ResizeFileNameExtension = resizeFileNameExtension;
|
||||
_TextBox = new() { Location = new(5, 5), Dock = DockStyle.Top };
|
||||
_ProgressBar = new() { Location = new(5, 5), Dock = DockStyle.Top, Visible = false };
|
||||
Load += new EventHandler(Form1_Load);
|
||||
Controls.Add(_ProgressBar);
|
||||
Controls.Add(_TextBox);
|
||||
}
|
||||
|
||||
@ -70,30 +76,23 @@ public partial class Form : System.Windows.Forms.Form
|
||||
{
|
||||
try
|
||||
{
|
||||
int j;
|
||||
int f;
|
||||
int t;
|
||||
AllowDrop = true;
|
||||
Container[] containers;
|
||||
DragDrop += new DragEventHandler(Form1_DragDrop);
|
||||
DragEnter += new DragEventHandler(Form1_DragEnter);
|
||||
Property.Models.A_Property propertyLogic = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _ResizeFileNameExtension, _Configuration.Reverse);
|
||||
(j, f, t, containers) = Property.Models.Stateless.Container.GetContainers(_Configuration.PropertyConfiguration, propertyLogic);
|
||||
List<MappingFromItem> collection = Program.GetMappingFromItemCollection(_Configuration, containers);
|
||||
foreach (MappingFromItem mappingFromItem in collection)
|
||||
{
|
||||
if (_IdToMappingFromItem.ContainsKey(mappingFromItem.Id))
|
||||
continue;
|
||||
_IdToMappingFromItem.Add(mappingFromItem.Id, mappingFromItem);
|
||||
}
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
_Logger.Debug((_AppSettings is null).ToString());
|
||||
_Logger.Debug((_Configuration is null).ToString());
|
||||
_Logger.Debug((_IsEnvironment is null).ToString());
|
||||
_Logger.Debug((_WorkingDirectory is null).ToString());
|
||||
_Logger.Debug((_ConfigurationRoot is null).ToString());
|
||||
_Logger.Debug((_PropertyConfiguration is null).ToString());
|
||||
_TextBox.LostFocus += new EventHandler(TextBox_LostFocus);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox_LostFocus(object? sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_TextBox.Text == "ps")
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@ -114,29 +113,166 @@ public partial class Form : System.Windows.Forms.Form
|
||||
}
|
||||
}
|
||||
|
||||
void LoadData()
|
||||
{
|
||||
Container[] containers;
|
||||
Property.Models.A_Property propertyLogic = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _ResizeFileNameExtension, _Configuration.Reverse);
|
||||
(_, _, _, containers) = Property.Models.Stateless.Container.GetContainers(_Configuration.PropertyConfiguration, propertyLogic);
|
||||
List<MappingFromItem> collection = Program.GetMappingFromItemCollection(_Configuration, containers);
|
||||
foreach (MappingFromItem mappingFromItem in collection)
|
||||
{
|
||||
if (_IdToMappingFromItem.ContainsKey(mappingFromItem.Id))
|
||||
continue;
|
||||
_IdToMappingFromItem.Add(mappingFromItem.Id, mappingFromItem);
|
||||
}
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
_Logger.Debug((_AppSettings is null).ToString());
|
||||
_Logger.Debug((_Configuration is null).ToString());
|
||||
_Logger.Debug((_IsEnvironment is null).ToString());
|
||||
_Logger.Debug((_WorkingDirectory is null).ToString());
|
||||
_Logger.Debug((_ConfigurationRoot is null).ToString());
|
||||
_Logger.Debug((_PropertyConfiguration is null).ToString());
|
||||
}
|
||||
|
||||
private void RenameDirectory(string path, string searchPattern)
|
||||
{
|
||||
string[] directories = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string directory in directories)
|
||||
RenameDirectory(directory, searchPattern);
|
||||
int? id;
|
||||
string? message;
|
||||
string checkFile;
|
||||
DateTime? dateTime;
|
||||
FileHolder fileHolder;
|
||||
_ProgressBar.Step = 1;
|
||||
bool isIgnoreExtension;
|
||||
_ProgressBar.Value = 0;
|
||||
DateTime? minimumDateTime;
|
||||
_ProgressBar.Visible = true;
|
||||
bool isValidImageFormatExtension;
|
||||
string? extraLargeBitmapThumbnail;
|
||||
string[] files = Directory.GetFiles(path, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
_ProgressBar.Maximum = files.Length;
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileHolder = new(file);
|
||||
_Lines.Add(fileHolder.NameWithoutExtension);
|
||||
isValidImageFormatExtension = _Configuration.PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
isIgnoreExtension = isValidImageFormatExtension && _Configuration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
if (fileHolder.CreationTime is null || fileHolder.Name.Contains(fileHolder.CreationTime.Value.ToString("yy")))
|
||||
continue;
|
||||
if (fileHolder.LastWriteTime is null || fileHolder.Name.Contains(fileHolder.LastWriteTime.Value.ToString("yy")))
|
||||
continue;
|
||||
if (fileHolder.NameWithoutExtension.Length == 1 || fileHolder.NameWithoutExtension[1..].All(l => char.IsNumber(l)))
|
||||
continue;
|
||||
if (fileHolder.NameWithoutExtension.Length == 1 || fileHolder.NameWithoutExtension[1..].All(l => char.IsNumber(l)))
|
||||
continue;
|
||||
if (!isIgnoreExtension && isValidImageFormatExtension)
|
||||
extraLargeBitmapThumbnail = null;
|
||||
else
|
||||
{
|
||||
extraLargeBitmapThumbnail = SaveExtraLargeBitmapThumbnail(fileHolder);
|
||||
if (extraLargeBitmapThumbnail is null)
|
||||
continue;
|
||||
fileHolder = new(extraLargeBitmapThumbnail);
|
||||
isValidImageFormatExtension = _Configuration.PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
isIgnoreExtension = isValidImageFormatExtension && _Configuration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
if (isIgnoreExtension || !isValidImageFormatExtension)
|
||||
continue;
|
||||
}
|
||||
if (fileHolder.DirectoryName is null)
|
||||
continue;
|
||||
dateTime = IProperty.GetDateTimeFromName(fileHolder);
|
||||
if (dateTime is not null && fileHolder.Name.Contains(dateTime.Value.ToString("yy")))
|
||||
continue;
|
||||
(minimumDateTime, id, message) = IProperty.Get(fileHolder);
|
||||
if (id is null)
|
||||
continue;
|
||||
if (minimumDateTime is not null && fileHolder.Name.Contains(minimumDateTime.Value.ToString("yy")))
|
||||
continue;
|
||||
if (dateTime is not null && minimumDateTime is not null && minimumDateTime.Value != dateTime.Value)
|
||||
continue;
|
||||
if (extraLargeBitmapThumbnail is not null)
|
||||
{
|
||||
File.Delete(fileHolder.FullName);
|
||||
fileHolder = new(file);
|
||||
if (fileHolder.DirectoryName is null)
|
||||
continue;
|
||||
}
|
||||
checkFile = Path.Combine(fileHolder.DirectoryName, $"{id}{fileHolder.ExtensionLowered}");
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(fileHolder.FullName, checkFile);
|
||||
_ProgressBar.PerformStep();
|
||||
}
|
||||
_ProgressBar.Visible = false;
|
||||
}
|
||||
|
||||
private string? SaveExtraLargeBitmapThumbnail(FileHolder fileHolder)
|
||||
{
|
||||
string? result;
|
||||
ShellFile shellFile = ShellFile.FromFilePath(fileHolder.FullName);
|
||||
if (shellFile is null || shellFile.Thumbnail is null || shellFile.Thumbnail.ExtraLargeBitmap.Clone() is not Bitmap bitmap || bitmap.Width == 0)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
result = $"{fileHolder.FullName}{_ResizeFileNameExtension}";
|
||||
bitmap.Save(result);
|
||||
bitmap.Dispose();
|
||||
shellFile.Dispose();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Form1_DragDrop(object? sender, DragEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (e.Data is not null)
|
||||
if (e.Data is null)
|
||||
_TextBox.Text = string.Empty;
|
||||
else
|
||||
{
|
||||
string fileName;
|
||||
string name;
|
||||
string[] segments;
|
||||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
foreach (string file in files)
|
||||
for (int i = 1; i < 3; i++)
|
||||
{
|
||||
fileName = Path.GetFileNameWithoutExtension(file);
|
||||
Text = fileName;
|
||||
segments = fileName.Split('.');
|
||||
if (int.TryParse(segments[0], out int id) && _IdToMappingFromItem.ContainsKey(id))
|
||||
if (e.Data.GetData(DataFormats.FileDrop) is not string[] paths)
|
||||
continue;
|
||||
foreach (string path in paths)
|
||||
{
|
||||
MappingFromItem mappingFromItem = _IdToMappingFromItem[id];
|
||||
Text = mappingFromItem.ImageFileHolder.Name;
|
||||
_TextBox.Text = mappingFromItem.ImageFileHolder.FullName;
|
||||
_Logger.Information(mappingFromItem.ImageFileHolder.DirectoryName);
|
||||
if (!string.IsNullOrEmpty(mappingFromItem.ImageFileHolder.DirectoryName))
|
||||
_ = Process.Start("explorer.exe", string.Concat("\"", mappingFromItem.ImageFileHolder.DirectoryName, "\""));
|
||||
name = Path.GetFileNameWithoutExtension(path);
|
||||
Text = name;
|
||||
segments = name.Split('.');
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
if (i == 1)
|
||||
RenameDirectory(path, "*Rename*");
|
||||
else if (i == 2)
|
||||
RenameDirectory(path, "*");
|
||||
else
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i != 1)
|
||||
continue;
|
||||
if (!_IdToMappingFromItem.Any())
|
||||
LoadData();
|
||||
if (int.TryParse(segments[0], out int id) && _IdToMappingFromItem.TryGetValue(id, out MappingFromItem? value))
|
||||
{
|
||||
MappingFromItem mappingFromItem = value;
|
||||
Text = mappingFromItem.ImageFileHolder.Name;
|
||||
_TextBox.Text = mappingFromItem.ImageFileHolder.FullName;
|
||||
if (mappingFromItem.ImageFileHolder.DirectoryName is not null)
|
||||
_Logger.Information(mappingFromItem.ImageFileHolder.DirectoryName);
|
||||
if (!string.IsNullOrEmpty(mappingFromItem.ImageFileHolder.DirectoryName))
|
||||
_ = Process.Start("explorer.exe", string.Concat("\"", mappingFromItem.ImageFileHolder.DirectoryName, "\""));
|
||||
}
|
||||
}
|
||||
}
|
||||
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", _Lines);
|
||||
_Lines.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,10 @@ public class AppSettings
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Models.AppSettings Get(AppSettings appSettings)
|
||||
private static Models.AppSettings Get(AppSettings? appSettings)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
if (appSettings.MaxDegreeOfParallelism is null)
|
||||
if (appSettings?.MaxDegreeOfParallelism is null)
|
||||
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
result = new(
|
||||
appSettings.Company,
|
||||
@ -36,7 +36,7 @@ public class AppSettings
|
||||
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
AppSettings appSettings = configurationRoot.Get<AppSettings>();
|
||||
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
|
||||
result = Get(appSettings);
|
||||
return result;
|
||||
}
|
||||
|
@ -60,9 +60,11 @@ public class Configuration
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Models.Configuration Get(Configuration configuration)
|
||||
private static Models.Configuration Get(Configuration? configuration)
|
||||
{
|
||||
Models.Configuration result;
|
||||
if (configuration is null)
|
||||
throw new NullReferenceException(nameof(configuration));
|
||||
if (configuration.CheckDFaceAndUpWriteDates is null)
|
||||
throw new NullReferenceException(nameof(configuration.CheckDFaceAndUpWriteDates));
|
||||
if (configuration.CheckJsonForDistanceResults is null)
|
||||
@ -81,10 +83,8 @@ public class Configuration
|
||||
throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.IgnoreRelativePaths is null)
|
||||
throw new NullReferenceException(nameof(configuration.IgnoreRelativePaths));
|
||||
if (configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions is null)
|
||||
configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions = Array.Empty<string>();
|
||||
if (configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions is null)
|
||||
configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions = Array.Empty<string>();
|
||||
configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions ??= Array.Empty<string>();
|
||||
configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions ??= Array.Empty<string>();
|
||||
if (configuration.LoadOrCreateThenSaveIndex is null)
|
||||
throw new NullReferenceException(nameof(configuration.LoadOrCreateThenSaveIndex));
|
||||
if (configuration.MixedYearRelativePaths is null)
|
||||
@ -115,16 +115,13 @@ public class Configuration
|
||||
throw new NullReferenceException(nameof(configuration.PropertiesChangedForResize));
|
||||
if (configuration.Reverse is null)
|
||||
throw new NullReferenceException(nameof(configuration.Reverse));
|
||||
if (configuration.SaveFaceLandmarkForOutputResolutions is null)
|
||||
configuration.SaveFaceLandmarkForOutputResolutions = Array.Empty<string>();
|
||||
configuration.SaveFaceLandmarkForOutputResolutions ??= Array.Empty<string>();
|
||||
if (configuration.SaveFullYearOfRandomFiles is null)
|
||||
throw new NullReferenceException(nameof(configuration.SaveFullYearOfRandomFiles));
|
||||
if (configuration.SaveResizedImagesByPersonKeyFormattedForOutputResolutions is null)
|
||||
configuration.SaveResizedImagesByPersonKeyFormattedForOutputResolutions = Array.Empty<string>();
|
||||
configuration.SaveResizedImagesByPersonKeyFormattedForOutputResolutions ??= Array.Empty<string>();
|
||||
if (configuration.SaveResizedSubfiles is null)
|
||||
throw new NullReferenceException(nameof(configuration.SaveResizedSubfiles));
|
||||
if (configuration.SaveShortcutsForOutputResolutions is null)
|
||||
configuration.SaveShortcutsForOutputResolutions = Array.Empty<string>();
|
||||
configuration.SaveShortcutsForOutputResolutions ??= Array.Empty<string>();
|
||||
if (configuration.SkipSearch is null)
|
||||
throw new NullReferenceException(nameof(configuration.SkipSearch));
|
||||
if (configuration.TestDistanceResults is null)
|
||||
@ -178,7 +175,7 @@ public class Configuration
|
||||
public static Models.Configuration Get(IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, Property.Models.Configuration propertyConfiguration)
|
||||
{
|
||||
Models.Configuration result;
|
||||
Configuration configuration;
|
||||
Configuration? configuration;
|
||||
if (isEnvironment is null)
|
||||
configuration = configurationRoot.Get<Configuration>();
|
||||
else
|
||||
|
@ -50,9 +50,7 @@ static class Program
|
||||
public static List<MappingFromItem> GetMappingFromItemCollection(Models.Configuration configuration, Container[] containers)
|
||||
{
|
||||
List<MappingFromItem> results = new();
|
||||
bool? isWrongYear;
|
||||
Item[] filteredItems;
|
||||
DateTime minimumDateTime;
|
||||
MappingFromItem mappingFromItem;
|
||||
foreach (Container container in containers)
|
||||
{
|
||||
@ -65,11 +63,9 @@ static class Program
|
||||
continue;
|
||||
foreach (Item item in filteredItems)
|
||||
{
|
||||
if (item.Property?.Id is null || item.ImageFileHolder is null)
|
||||
if (item.Property?.Id is null)
|
||||
continue;
|
||||
minimumDateTime = IProperty.GetMinimumDateTime(item.Property);
|
||||
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder, minimumDateTime);
|
||||
mappingFromItem = new(item.Property.Id.Value, item.ImageFileHolder, isWrongYear, minimumDateTime, item.RelativePath, item.ImageFileHolder);
|
||||
mappingFromItem = IMappingFromItem.GetMappingFromItem(item);
|
||||
results.Add(mappingFromItem);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user