Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
f914fd3577 | |||
9ebfdc8af2 | |||
5b9e748ba4 | |||
9c253786a9 | |||
86b13dc00f | |||
665fb8ec06 | |||
365df1158a | |||
dca487deb3 | |||
7f8b09e66c | |||
9a772f8dcc | |||
99e3f29720 | |||
bf2d6849b3 | |||
c9dbce3b57 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -470,7 +470,4 @@ globalStorage/
|
||||
Shared/.kanbn
|
||||
|
||||
.Immich/immich-assets.json
|
||||
Tests/.vscode/.UserSecrets/*
|
||||
Instance/.vscode/.UserSecrets/*
|
||||
Drag-Drop-Set-Property-Item/.vscode/.UserSecrets/*
|
||||
TestsWithFaceRecognitionDotNet/.vscode/.UserSecrets/*
|
||||
|
80
.vscode/launch.json
vendored
80
.vscode/launch.json
vendored
@ -10,8 +10,8 @@
|
||||
"name": "Compare",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Compare/bin/Debug/net9.0/win-x64/Compare.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Compare/bin/Debug/net8.0/win-x64/Compare.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -27,8 +27,8 @@
|
||||
"name": "Copy-Distinct",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Copy-Distinct/bin/Debug/net9.0/win-x64/Copy-Distinct.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Copy-Distinct/bin/Debug/net8.0/win-x64/Copy-Distinct.dll",
|
||||
"args": [],
|
||||
"env": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
@ -42,8 +42,8 @@
|
||||
"name": "Duplicate-Search",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Duplicate-Search/bin/Debug/net9.0/win-x64/Duplicate-Search.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Duplicate-Search/bin/Debug/net8.0/win-x64/Duplicate-Search.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -59,8 +59,8 @@
|
||||
"name": "Date-Group",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Date-Group/bin/Debug/net9.0/win-x64/Date-Group.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Date-Group/bin/Debug/net8.0/win-x64/Date-Group.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -76,8 +76,8 @@
|
||||
"name": "Delete-By-Distinct",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Delete-By-Distinct/bin/Debug/net9.0/win-x64/Delete-By-Distinct.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Delete-By-Distinct/bin/Debug/net8.0/win-x64/Delete-By-Distinct.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -93,8 +93,8 @@
|
||||
"name": "Delete-By-Relative",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Delete-By-Relative/bin/Debug/net9.0/win-x64/Delete-By-Relative.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Delete-By-Relative/bin/Debug/net8.0/win-x64/Delete-By-Relative.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -110,8 +110,8 @@
|
||||
"name": "Drag-Drop",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Drag-Drop/bin/Debug/net9.0-windows/win-x64/Drag-Drop.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Drag-Drop/bin/Debug/net8.0-windows/win-x64/Drag-Drop.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -127,8 +127,8 @@
|
||||
"name": "Drag-Drop-Explorer",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Drag-Drop-Explorer/bin/Debug/net9.0-windows/win-x64/Drag-Drop-Explorer.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Drag-Drop-Explorer/bin/Debug/net8.0-windows/win-x64/Drag-Drop-Explorer.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -144,8 +144,8 @@
|
||||
"name": "Drag-Drop-Move",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Drag-Drop-Move/bin/Debug/net9.0-windows/win-x64/Drag-Drop-Move.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Drag-Drop-Move/bin/Debug/net8.0-windows/win-x64/Drag-Drop-Move.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -161,8 +161,8 @@
|
||||
"name": "Drag-Drop-Set-Property-Item",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Drag-Drop-Set-Property-Item/bin/Debug/net9.0-windows/win-x64/Drag-Drop-Set-Property-Item.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Drag-Drop-Set-Property-Item/bin/Debug/net8.0-windows/win-x64/Drag-Drop-Set-Property-Item.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -178,8 +178,8 @@
|
||||
"name": "Instance",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildInstance",
|
||||
"program": "${workspaceFolder}/Instance/bin/Debug/net9.0/win-x64/Instance.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Instance/bin/Debug/net8.0/win-x64/Instance.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -195,8 +195,8 @@
|
||||
"name": "Mirror-Length",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Mirror-Length/bin/Debug/net9.0/win-x64/Mirror-Length.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Mirror-Length/bin/Debug/net8.0/win-x64/Mirror-Length.dll",
|
||||
"args": [],
|
||||
"env": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
@ -210,8 +210,8 @@
|
||||
"name": "Metadata-Query",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Metadata-Query/bin/Debug/net9.0/win-x64/Metadata-Query.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Metadata-Query/bin/Debug/net8.0/win-x64/Metadata-Query.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -227,8 +227,8 @@
|
||||
"name": "Move-By-Id",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Move-By-Id/bin/Debug/net9.0/win-x64/Move-By-Id.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Move-By-Id/bin/Debug/net8.0/win-x64/Move-By-Id.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -244,8 +244,8 @@
|
||||
"name": "Not-Copy-Copy",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Not-Copy-Copy/bin/Debug/net9.0/win-x64/Not-Copy-Copy.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Not-Copy-Copy/bin/Debug/net8.0/win-x64/Not-Copy-Copy.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -261,8 +261,8 @@
|
||||
"name": "Offset-Date-Time-Original",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Offset-Date-Time-Original/bin/Debug/net9.0/win-x64/Offset-Date-Time-Original.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Offset-Date-Time-Original/bin/Debug/net8.0/win-x64/Offset-Date-Time-Original.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -278,8 +278,8 @@
|
||||
"name": "PrepareForOld",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/PrepareForOld/bin/Debug/net9.0/win-x64/PrepareForOld.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/PrepareForOld/bin/Debug/net8.0/win-x64/PrepareForOld.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -295,8 +295,8 @@
|
||||
"name": "Person",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Person/bin/Debug/net9.0/Person.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Person/bin/Debug/net8.0/Person.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -312,8 +312,8 @@
|
||||
"name": "Rename",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Rename/bin/Debug/net9.0/win-x64/Rename.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Rename/bin/Debug/net8.0/win-x64/Rename.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
@ -329,8 +329,8 @@
|
||||
"name": "Set-Created-Date",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildSolution",
|
||||
"program": "${workspaceFolder}/Set-Created-Date/bin/Debug/net9.0/win-x64/Set-Created-Date.dll",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Set-Created-Date/bin/Debug/net8.0/win-x64/Set-Created-Date.dll",
|
||||
"args": [
|
||||
"s"
|
||||
],
|
||||
|
16
.vscode/mklink.md
vendored
16
.vscode/mklink.md
vendored
@ -13,19 +13,3 @@ mklink /J "D:\1-Images-A\Images-4083e56a-Results\A2)People\4083e56a\{}\!" "D:\1-
|
||||
```bash
|
||||
mklink /J "L:\Git\View-by-Distance-MKLink-Console\.Immich" "D:\1-Images-A\Images-c9dbce3b-Results\F)Immich\c9dbce3b\{}"
|
||||
```
|
||||
|
||||
```bash 1740946894364 = 638765436943640000 = 2025-0.Winter = Sun Mar 02 2025 13:21:33 GMT-0700 (Mountain Standard Time)
|
||||
mklink /J "V:\Tmp\Phares\Pictures-Results" "V:\6-Other-Large-Z\Current-Results-Test"
|
||||
mklink /J "V:\1-Images-A\Images-0b793904-Results" "V:\6-Other-Large-Z\Current-Results"
|
||||
```
|
||||
|
||||
```bash 1742827407172 = 638784242071720000 = 2025-1.Spring = Mon Mar 24 2025 07:43:26 GMT-0700 (Mountain Standard Time)
|
||||
mkdir "L:\Git\View-by-Distance-MKLink-Console\Instance\.vscode"
|
||||
mklink /J "L:\Git\View-by-Distance-MKLink-Console\Instance\.vscode\.UserSecrets" "C:\Users\mikep\AppData\Roaming\Microsoft\UserSecrets\2999dda1-5329-4d9f-9d68-cccfabe0e47f"
|
||||
mkdir "L:\Git\View-by-Distance-MKLink-Console\Tests\.vscode"
|
||||
mklink /J "L:\Git\View-by-Distance-MKLink-Console\Tests\.vscode\.UserSecrets" "C:\Users\mikep\AppData\Roaming\Microsoft\UserSecrets\e8c3d25d-9715-4b35-9010-1cdc74840190"
|
||||
mkdir "L:\Git\View-by-Distance-MKLink-Console\TestsWithFaceRecognitionDotNet\.vscode"
|
||||
mklink /J "L:\Git\View-by-Distance-MKLink-Console\TestsWithFaceRecognitionDotNet\.vscode\.UserSecrets" "C:\Users\mikep\AppData\Roaming\Microsoft\UserSecrets\ecbdc76d-6037-4046-86a4-1a7626a3d342"
|
||||
mkdir "L:\Git\View-by-Distance-MKLink-Console\Drag-Drop-Set-Property-Item\.vscode"
|
||||
mklink /J "L:\Git\View-by-Distance-MKLink-Console\Drag-Drop-Set-Property-Item\.vscode\.UserSecrets" "C:\Users\mikep\AppData\Roaming\Microsoft\UserSecrets\c64a15ed-0ba3-4378-8f80-0c19d0531747"
|
||||
```
|
||||
|
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -23,9 +23,6 @@
|
||||
"Immich",
|
||||
"jfif",
|
||||
"JOSN",
|
||||
"makernote",
|
||||
"Makernote",
|
||||
"Makernotes",
|
||||
"mmod",
|
||||
"Nicéphore",
|
||||
"Niépce",
|
||||
@ -35,8 +32,6 @@
|
||||
"permyriad",
|
||||
"Phares",
|
||||
"Phgtv",
|
||||
"photoshop",
|
||||
"Photoshop",
|
||||
"RDHC",
|
||||
"Rects",
|
||||
"resnet",
|
||||
|
100
.vscode/tasks.json
vendored
100
.vscode/tasks.json
vendored
@ -53,7 +53,7 @@
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "buildSolution",
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
@ -63,104 +63,6 @@
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "buildInstance",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/Instance/Instance.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "buildShared",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/Shared/View-by-Distance.Shared.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "buildMetadata",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/Metadata/Metadata.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "buildTests",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/Tests/Tests.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "buildTestsWithFaceRecognitionDotNet",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/TestsWithFaceRecognitionDotNet/TestsWithFaceRecognitionDotNet.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "buildCopyDistinct",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/Copy-Distinct/Copy-Distinct.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "buildDragDropSetPropertyItem",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/Drag-Drop-Set-Property-Item/Drag-Drop-Set-Property-Item.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "File-Folder-Helper AOT s X Day-Helper-2025-03-20",
|
||||
"type": "shell",
|
||||
"command": "L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe",
|
||||
"args": [
|
||||
"s",
|
||||
"X",
|
||||
"L:/Git/View-by-Distance-MKLink-Console",
|
||||
"Day-Helper-2025-03-20",
|
||||
"false",
|
||||
"4"
|
||||
],
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>BlurHash.Core</PackageId>
|
||||
@ -18,6 +18,6 @@
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Memory" Version="4.6.0" />
|
||||
<PackageReference Include="System.Memory" Version="4.5.5" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -4,7 +4,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
@ -24,6 +24,6 @@
|
||||
<ProjectReference Include="..\BlurHash.Core\BlurHash.Core.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.BlurHash</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -33,8 +33,8 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
|
@ -10,29 +10,21 @@ namespace View_by_Distance.BlurHash.Models;
|
||||
public class C2_BlurHasher : IBlurHasher
|
||||
{
|
||||
|
||||
private readonly Dictionary<string, string[]> _FileGroups;
|
||||
private readonly IPropertyConfiguration _PropertyConfiguration;
|
||||
private readonly ReadOnlyDictionary<byte, ReadOnlyCollection<string>>[] _ResultContentFileGroups;
|
||||
private readonly ReadOnlyDictionary<byte, ReadOnlyCollection<string>>[] _ResultSingletonFileGroups;
|
||||
|
||||
public C2_BlurHasher(IPropertyConfiguration propertyConfiguration)
|
||||
{
|
||||
_FileGroups = [];
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
_ResultContentFileGroups = [new(new Dictionary<byte, ReadOnlyCollection<string>>())];
|
||||
_ResultSingletonFileGroups = [new(new Dictionary<byte, ReadOnlyCollection<string>>())];
|
||||
}
|
||||
|
||||
public void Update(string resultsFullGroupDirectory)
|
||||
{
|
||||
ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePairs = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(_PropertyConfiguration, resultsFullGroupDirectory, [_PropertyConfiguration.ResultContent, _PropertyConfiguration.ResultSingleton]);
|
||||
foreach (KeyValuePair<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
if (keyValuePair.Key == _PropertyConfiguration.ResultContent)
|
||||
_ResultContentFileGroups[0] = keyValuePair.Value;
|
||||
else if (keyValuePair.Key == _PropertyConfiguration.ResultSingleton)
|
||||
_ResultSingletonFileGroups[0] = keyValuePair.Value;
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
_FileGroups.Clear();
|
||||
ReadOnlyDictionary<string, string[]> keyValuePairs = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(_PropertyConfiguration, resultsFullGroupDirectory, [_PropertyConfiguration.ResultContent, _PropertyConfiguration.ResultSingleton]);
|
||||
foreach (KeyValuePair<string, string[]> keyValuePair in keyValuePairs)
|
||||
_FileGroups.Add(keyValuePair.Key, keyValuePair.Value);
|
||||
}
|
||||
|
||||
string IBlurHasher.Encode(FileHolder fileHolder)
|
||||
@ -48,39 +40,20 @@ public class C2_BlurHasher : IBlurHasher
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void MoveIf(string fileName, CombinedEnumAndIndex cei, string directory, string fullFileName)
|
||||
{
|
||||
string[] segments = directory.Split(cei.Combined);
|
||||
string? checkDirectory = segments.Length == 1 ?
|
||||
Path.Combine(segments[0], $"{cei.Combined[2..]}") :
|
||||
segments.Length == 2 ?
|
||||
$"{segments[0]}{cei.Combined[2..]}{segments[1]}" :
|
||||
null;
|
||||
if (checkDirectory is not null && Directory.Exists(checkDirectory))
|
||||
{
|
||||
string checkFile = Path.Combine(checkDirectory, fileName);
|
||||
if (File.Exists(checkFile))
|
||||
File.Move(checkFile, fullFileName);
|
||||
}
|
||||
}
|
||||
|
||||
string IBlurHasher.GetFile(FilePath filePath)
|
||||
{
|
||||
string result;
|
||||
if (_ResultSingletonFileGroups[0].Count == 0)
|
||||
if (_FileGroups.Count == 0)
|
||||
throw new Exception("Call Update first!");
|
||||
string fileName = $"{filePath.Name}.csv";
|
||||
CombinedEnumAndIndex cei = Shared.Models.Stateless.Methods.IPath.GetCombinedEnumAndIndex(_PropertyConfiguration, filePath);
|
||||
string directory = _ResultSingletonFileGroups[0][cei.Enum][cei.Index];
|
||||
result = Path.Combine(directory, fileName);
|
||||
MoveIf(fileName, cei, directory, result);
|
||||
(_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration, filePath);
|
||||
result = Path.Combine(_FileGroups[_PropertyConfiguration.ResultSingleton][directoryIndex], $"{filePath.Name}.csv");
|
||||
return result;
|
||||
}
|
||||
|
||||
string IBlurHasher.EncodeAndSave(FilePath filePath, FileHolder fileHolder)
|
||||
{
|
||||
string result;
|
||||
if (_ResultSingletonFileGroups[0].Count == 0)
|
||||
if (_FileGroups.Count == 0)
|
||||
throw new Exception("Call Update first!");
|
||||
int actualByte;
|
||||
string extension = ".png";
|
||||
@ -97,18 +70,15 @@ public class C2_BlurHasher : IBlurHasher
|
||||
byte[] blurHashBytes = Encoding.UTF8.GetBytes(result);
|
||||
string joined = string.Join(string.Empty, blurHashBytes.Select(l => l.ToString("000")));
|
||||
string fileNameWithoutExtension = $"{componentsX}x{componentsY}-{outputWidth}x{outputHeight}-{joined}";
|
||||
string fileName = $"{fileNameWithoutExtension}{extension}";
|
||||
string contents = string.Concat(result, Environment.NewLine, fileNameWithoutExtension, Environment.NewLine, extension);
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(file, contents, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
CombinedEnumAndIndex cei = Shared.Models.Stateless.Methods.IPath.GetCombinedEnumAndIndex(_PropertyConfiguration, filePath);
|
||||
string directory = _ResultContentFileGroups[0][cei.Enum][cei.Index];
|
||||
string fullFileName = Path.Combine(directory, fileName);
|
||||
MoveIf(fileName, cei, directory, fullFileName);
|
||||
if (!File.Exists(fullFileName))
|
||||
(_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration, filePath);
|
||||
file = Path.Combine(_FileGroups[_PropertyConfiguration.ResultContent][directoryIndex], $"{fileNameWithoutExtension}{extension}");
|
||||
if (!File.Exists(file))
|
||||
{
|
||||
try
|
||||
{
|
||||
using FileStream fileStream = new(fullFileName, FileMode.CreateNew);
|
||||
using FileStream fileStream = new(file, FileMode.CreateNew);
|
||||
actualImage.Save(fileStream, System.Drawing.Imaging.ImageFormat.Png);
|
||||
_ = fileStream.Seek(0, SeekOrigin.Begin);
|
||||
actualByte = fileStream.ReadByte();
|
||||
|
@ -160,7 +160,7 @@ public class Compare
|
||||
}
|
||||
if (_IsEnvironment.Development && propertyConfiguration.PopulatePropertyId)
|
||||
throw new Exception("Copy keyValuePairs-####.json file");
|
||||
(int j, int f, int t, Shared.Models.Container[] containers) = Container.Models.Stateless.Methods.IContainer.GetContainers(propertyConfiguration, propertyLogic);
|
||||
(int j, int f, int t, Shared.Models.Container[] containers) = Shared.Models.Stateless.Methods.IContainer.GetContainers(propertyConfiguration, propertyLogic);
|
||||
if (propertyLogic.ExceptionsDirectories.Any())
|
||||
throw new Exception();
|
||||
if (propertyConfiguration.PopulatePropertyId && Shared.Models.Stateless.Methods.IProperty.Any(containers))
|
||||
@ -211,7 +211,7 @@ public class Compare
|
||||
}
|
||||
_Logger?.LogInformation(". . .");
|
||||
}
|
||||
string aPropertyContentCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), propertyConfiguration.ResultContentCollection);
|
||||
string aPropertyContentCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), "[()]");
|
||||
ThirdPassToMove(propertyConfiguration, mapLogic, propertyLogic, containers, aPropertyContentCollectionDirectory);
|
||||
if (!isSilent)
|
||||
{
|
||||
@ -242,53 +242,6 @@ public class Compare
|
||||
_ = Directory.CreateDirectory(currentYearDirectory);
|
||||
}
|
||||
|
||||
private static void Verify(Models.Configuration configuration)
|
||||
{
|
||||
if (configuration.Spelling is null || !configuration.Spelling.Any())
|
||||
throw new NullReferenceException(nameof(configuration.Spelling));
|
||||
}
|
||||
|
||||
private A_Property GetPropertyLogic(bool reverse, string outputExtension, Map.Models.MapLogic mapLogic)
|
||||
{
|
||||
A_Property result;
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
result = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, outputExtension, reverse);
|
||||
string fromPrepareForOld = "34720-637858334555170379.tsv";
|
||||
string fromPrepareForOldFile = Path.Combine(_Configuration.PropertyConfiguration.RootDirectory, fromPrepareForOld);
|
||||
if (File.Exists(fromPrepareForOldFile))
|
||||
{
|
||||
string[] lines;
|
||||
string[] columns;
|
||||
List<string> debug = new();
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
lines = File.ReadAllLines(fromPrepareForOldFile);
|
||||
string resultsDirectory = $"{_Configuration.PropertyConfiguration.RootDirectory}-Results";
|
||||
int[]? zeros = (from l in mapLogic.IndicesFromNew where l.Value.Any() select l.Value[0]).ToArray();
|
||||
lines = (from l in mapLogic.IndicesFromNew select string.Concat(l.Key, '\t', string.Join('\t', l.Value))).ToArray();
|
||||
if (!Directory.Exists(resultsDirectory))
|
||||
_ = Directory.CreateDirectory(resultsDirectory);
|
||||
File.WriteAllLines(Path.Combine(resultsDirectory, $"{ticks}.tsv"), lines);
|
||||
string json = JsonSerializer.Serialize(mapLogic.IndicesFromNew, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(Path.Combine(resultsDirectory, $"{ticks}.json"), json);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
columns = line.Split('\t');
|
||||
// select $"{l.Index}\t{l.PropertyId}\t{l.RegexResult}\t{new DateTime(l.Ticks):yyyy-MM-dd_HH-mm-ss}\t{l.PropertyTicks}\t{l.RelativeDirectory}\t{l.FileName}"
|
||||
if (columns.Length != 7)
|
||||
continue;
|
||||
if (!int.TryParse(columns[1], out int propertyId))
|
||||
continue;
|
||||
if (!zeros.Contains(propertyId))
|
||||
debug.Add(line);
|
||||
else
|
||||
debug.Add(propertyId.ToString());
|
||||
}
|
||||
File.WriteAllLines(Path.Combine(resultsDirectory, $"{ticks}-{fromPrepareForOld}"), debug);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetRename(string renameA)
|
||||
{
|
||||
string result;
|
||||
@ -423,6 +376,12 @@ public class Compare
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void Verify(Models.Configuration configuration)
|
||||
{
|
||||
if (configuration.Spelling is null || !configuration.Spelling.Any())
|
||||
throw new NullReferenceException(nameof(configuration.Spelling));
|
||||
}
|
||||
|
||||
private long LogDelta(long ticks, string? methodName)
|
||||
{
|
||||
long result;
|
||||
@ -432,6 +391,121 @@ public class Compare
|
||||
return result;
|
||||
}
|
||||
|
||||
private A_Property GetPropertyLogic(bool reverse, string outputExtension, Map.Models.MapLogic mapLogic)
|
||||
{
|
||||
A_Property result;
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
result = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, outputExtension, reverse);
|
||||
string fromPrepareForOld = "34720-637858334555170379.tsv";
|
||||
string fromPrepareForOldFile = Path.Combine(_Configuration.PropertyConfiguration.RootDirectory, fromPrepareForOld);
|
||||
if (File.Exists(fromPrepareForOldFile))
|
||||
{
|
||||
string[] lines;
|
||||
string[] columns;
|
||||
List<string> debug = new();
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
lines = File.ReadAllLines(fromPrepareForOldFile);
|
||||
string resultsDirectory = $"{_Configuration.PropertyConfiguration.RootDirectory}-Results";
|
||||
int[]? zeros = (from l in mapLogic.IndicesFromNew where l.Value.Any() select l.Value[0]).ToArray();
|
||||
lines = (from l in mapLogic.IndicesFromNew select string.Concat(l.Key, '\t', string.Join('\t', l.Value))).ToArray();
|
||||
if (!Directory.Exists(resultsDirectory))
|
||||
_ = Directory.CreateDirectory(resultsDirectory);
|
||||
File.WriteAllLines(Path.Combine(resultsDirectory, $"{ticks}.tsv"), lines);
|
||||
string json = JsonSerializer.Serialize(mapLogic.IndicesFromNew, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(Path.Combine(resultsDirectory, $"{ticks}.json"), json);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
columns = line.Split('\t');
|
||||
// select $"{l.Index}\t{l.PropertyId}\t{l.RegexResult}\t{new DateTime(l.Ticks):yyyy-MM-dd_HH-mm-ss}\t{l.PropertyTicks}\t{l.RelativeDirectory}\t{l.FileName}"
|
||||
if (columns.Length != 7)
|
||||
continue;
|
||||
if (!int.TryParse(columns[1], out int propertyId))
|
||||
continue;
|
||||
if (!zeros.Contains(propertyId))
|
||||
debug.Add(line);
|
||||
else
|
||||
debug.Add(propertyId.ToString());
|
||||
}
|
||||
File.WriteAllLines(Path.Combine(resultsDirectory, $"{ticks}-{fromPrepareForOld}"), debug);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SaveDiffFilesOrSaveLogAndMoveFiles(Property.Models.Configuration configuration)
|
||||
{
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
||||
_Logger?.LogInformation(aPropertySingletonDirectory);
|
||||
_Logger?.LogInformation("to");
|
||||
_Logger?.LogInformation(_Configuration.DiffPropertyDirectory);
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
_Logger?.LogInformation("Press \"Y\" key to continue or close console if compare not needed");
|
||||
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||
break;
|
||||
}
|
||||
_Logger?.LogInformation(". . .");
|
||||
int loadLessThan = 7;
|
||||
string diffRootDirectory;
|
||||
ConsoleKey? consoleKey = null;
|
||||
List<PropertyCompare.Models.PropertyCompare>? duplicates = null;
|
||||
PropertyCompare.Models.PropertyCompare[] diffPropertyCompareCollection;
|
||||
if (string.IsNullOrEmpty(_Configuration.DiffPropertyDirectory))
|
||||
diffRootDirectory = string.Empty;
|
||||
else
|
||||
{
|
||||
if (!_Configuration.DiffPropertyDirectory.EndsWith("{}"))
|
||||
throw new Exception("Invalid directory should end with {}!");
|
||||
diffRootDirectory = Shared.Models.Stateless.Methods.IProperty.GetDiffRootDirectory(_Configuration.DiffPropertyDirectory);
|
||||
}
|
||||
PropertyCompare.Models.PropertyCompareLogic propertyCompareLogic = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _SpellingFindReplace, diffRootDirectory);
|
||||
if (string.IsNullOrEmpty(_Configuration.DiffPropertyDirectory) || !Directory.Exists(_Configuration.DiffPropertyDirectory))
|
||||
diffPropertyCompareCollection = Array.Empty<PropertyCompare.Models.PropertyCompare>();
|
||||
else
|
||||
{
|
||||
diffPropertyCompareCollection = propertyCompareLogic.Get(_Configuration.DiffPropertyDirectory, loadLessThan, duplicates, deleteExtension: false);
|
||||
if (!diffPropertyCompareCollection.Any())
|
||||
throw new Exception("Invalid directory!");
|
||||
}
|
||||
string aPropertyCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "[{}]");
|
||||
PropertyCompare.Models.PropertyCompare[] propertyCompareCollection = propertyCompareLogic.Get(aPropertySingletonDirectory, loadLessThan, duplicates, deleteExtension: false);
|
||||
{
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
string[] lines = (from l in propertyCompareCollection select l.GetSelect()).ToArray();
|
||||
File.WriteAllLines(Path.Join(aPropertyCollectionDirectory, $". . . Ids - {ticks}.txt"), lines);
|
||||
string json = JsonSerializer.Serialize(propertyCompareCollection, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(Path.Join(aPropertyCollectionDirectory, $". . . Ids - {ticks}.nosj"), json);
|
||||
}
|
||||
for (int x = 0; x < int.MaxValue; x++)
|
||||
{
|
||||
_Logger?.LogInformation($"Press \"D\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveDiffFiles)}");
|
||||
_Logger?.LogInformation($"Press \"M\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveLogAndMoveFiles)}");
|
||||
_Logger?.LogInformation("Press \"End\" key when ready to skip");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.D or ConsoleKey.M or ConsoleKey.End)
|
||||
break;
|
||||
}
|
||||
_Logger?.LogInformation(". . .");
|
||||
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.D)
|
||||
propertyCompareLogic.SaveDiffFiles(aPropertyCollectionDirectory, loadLessThan, propertyCompareCollection, diffPropertyCompareCollection);
|
||||
else if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.M)
|
||||
{
|
||||
for (int x = 0; x < int.MaxValue; x++)
|
||||
{
|
||||
_Logger?.LogInformation($"Press \"0 - {loadLessThan}\" key when ready to continue");
|
||||
_Logger?.LogInformation("Press \"End\" key when ready to skip");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
if (consoleKey.Value is ConsoleKey.D0 or ConsoleKey.D1 or ConsoleKey.D2 or ConsoleKey.D3 or ConsoleKey.D4 or ConsoleKey.D5 or ConsoleKey.D6 or ConsoleKey.End)
|
||||
break;
|
||||
}
|
||||
_Logger?.LogInformation(". . .");
|
||||
int i = int.Parse(consoleKey.Value.ToString()[1..]);
|
||||
propertyCompareLogic.SaveLogAndMoveFiles(aPropertyCollectionDirectory, loadLessThan, propertyCompareCollection, diffPropertyCompareCollection, i);
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangeExtensionFromDeleteToJson(string aPropertySingletonDirectory)
|
||||
{
|
||||
string searchPattern = "*.delete";
|
||||
@ -450,6 +524,227 @@ public class Compare
|
||||
}
|
||||
}
|
||||
|
||||
private bool PossiblyRename(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
||||
{
|
||||
bool result = false;
|
||||
string replaceFile;
|
||||
string replaceDirectory;
|
||||
int remainingDirectories = 0;
|
||||
IEnumerable<(string Find, string Replace)>? found;
|
||||
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
||||
{
|
||||
if (!topDirectories.Any())
|
||||
continue;
|
||||
found = from l in _RenameFindReplace where sourceDirectory == l.Find select l;
|
||||
if (!found.Any())
|
||||
continue;
|
||||
if (!result)
|
||||
result = true;
|
||||
replaceDirectory = found.First().Replace;
|
||||
if (!Directory.Exists(replaceDirectory))
|
||||
Directory.Move(sourceDirectory, replaceDirectory);
|
||||
else
|
||||
{
|
||||
if (Directory.EnumerateDirectories(sourceDirectory).Any())
|
||||
remainingDirectories += 1;
|
||||
else
|
||||
{
|
||||
foreach (string sourceDirectoryFile in sourceDirectoryFiles)
|
||||
{
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.GetFileName(sourceDirectoryFile));
|
||||
if (File.Exists(replaceFile))
|
||||
{
|
||||
if (replaceFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpeg"));
|
||||
else if (replaceFile.EndsWith(".jpeg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpg"));
|
||||
}
|
||||
if (File.Exists(replaceFile))
|
||||
continue;
|
||||
File.Move(sourceDirectoryFile, replaceFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private bool PossiblyRenameB(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
||||
{
|
||||
bool result = false;
|
||||
string replaceFile;
|
||||
string replaceDirectory;
|
||||
IEnumerable<(string Find, string Replace)>? found;
|
||||
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
||||
{
|
||||
if (!topDirectories.Any())
|
||||
continue;
|
||||
found = from l in _RenameBFindReplace where sourceDirectory == l.Find select l;
|
||||
if (!found.Any())
|
||||
continue;
|
||||
if (!result)
|
||||
result = true;
|
||||
replaceDirectory = found.First().Replace;
|
||||
if (!Directory.Exists(replaceDirectory))
|
||||
_ = Directory.CreateDirectory(replaceDirectory);
|
||||
foreach (string sourceDirectoryFile in sourceDirectoryFiles)
|
||||
{
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.GetFileName(sourceDirectoryFile));
|
||||
if (File.Exists(replaceFile))
|
||||
{
|
||||
if (replaceFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpeg"));
|
||||
else if (replaceFile.EndsWith(".jpeg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpg"));
|
||||
}
|
||||
if (File.Exists(replaceFile))
|
||||
continue;
|
||||
File.Move(sourceDirectoryFile, replaceFile);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private bool PossiblyRenameC(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
||||
{
|
||||
bool result = false;
|
||||
string replaceFile;
|
||||
string replaceDirectory;
|
||||
IEnumerable<(string Find, string Replace)>? found;
|
||||
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
||||
{
|
||||
if (!topDirectories.Any())
|
||||
continue;
|
||||
found = from l in _RenameCFindReplace where sourceDirectory == l.Find select l;
|
||||
if (!found.Any())
|
||||
continue;
|
||||
if (!result)
|
||||
result = true;
|
||||
replaceDirectory = found.First().Replace;
|
||||
if (!Directory.Exists(replaceDirectory))
|
||||
_ = Directory.CreateDirectory(replaceDirectory);
|
||||
foreach (string sourceDirectoryFile in sourceDirectoryFiles)
|
||||
{
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.GetFileName(sourceDirectoryFile));
|
||||
if (File.Exists(replaceFile))
|
||||
{
|
||||
if (replaceFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpeg"));
|
||||
else if (replaceFile.EndsWith(".jpeg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpg"));
|
||||
}
|
||||
if (File.Exists(replaceFile))
|
||||
continue;
|
||||
File.Move(sourceDirectoryFile, replaceFile);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private bool PossiblyCorrect(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
||||
{
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
bool result = false;
|
||||
string corrected;
|
||||
string correctedMoveTo;
|
||||
string? correctedDirectory;
|
||||
string filteredSourceDirectoryFile;
|
||||
string[] filteredSourceDirectoryFiles;
|
||||
(string Find, string Replace) findReplace;
|
||||
IEnumerable<(string Find, string Replace)>? found;
|
||||
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
||||
{
|
||||
if (!topDirectories.Any())
|
||||
continue;
|
||||
filteredSourceDirectoryFiles = (from l in sourceDirectoryFiles where !_Configuration.PropertyConfiguration.IgnoreExtensions.Contains(Path.GetExtension(l)) select l).ToArray();
|
||||
if (!filteredSourceDirectoryFiles.Any())
|
||||
continue;
|
||||
for (int i = 0; i < filteredSourceDirectoryFiles.Length; i++)
|
||||
{
|
||||
found = null;
|
||||
for (int z = 0; z < int.MaxValue; z++)
|
||||
{
|
||||
filteredSourceDirectoryFile = filteredSourceDirectoryFiles[i];
|
||||
found = from l in _SpellingFindReplace where filteredSourceDirectoryFile.Contains(l.Find) select l;
|
||||
if (!found.Any())
|
||||
break;
|
||||
findReplace = found.First();
|
||||
corrected = filteredSourceDirectoryFile.Replace(findReplace.Find, findReplace.Replace);
|
||||
correctedDirectory = Path.GetDirectoryName(corrected);
|
||||
if (string.IsNullOrEmpty(correctedDirectory))
|
||||
break;
|
||||
correctedMoveTo = Path.Combine(correctedDirectory, Path.GetFileName(corrected));
|
||||
if (File.Exists(correctedMoveTo))
|
||||
break;
|
||||
if (!Directory.Exists(correctedDirectory))
|
||||
_ = Directory.CreateDirectory(correctedDirectory);
|
||||
if (!result)
|
||||
result = true;
|
||||
File.Move(filteredSourceDirectoryFile, correctedMoveTo);
|
||||
filteredSourceDirectoryFiles[i] = corrected;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<string> GetMissingVerifyToSeasonCollection(List<string> _, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
||||
{
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
List<string> results = new();
|
||||
string check;
|
||||
foreach ((int _, string sourceDirectory, string[] _) in groupCollection)
|
||||
{
|
||||
if (sourceDirectory == _Configuration.PropertyConfiguration.RootDirectory)
|
||||
continue;
|
||||
check = sourceDirectory[(_Configuration.PropertyConfiguration.RootDirectory.Length + 1)..];
|
||||
if (check[0] is '=' || check.StartsWith("zzz ="))
|
||||
{
|
||||
if (!_Configuration.PropertyConfiguration.VerifyToSeason.Contains(check))
|
||||
results.Add(check);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private void CreateWindowsShortcuts((long Ticks, string FilteredSourceDirectoryFile, string PropertyDirectory, int PropertyId)[] collection, bool keepAll)
|
||||
{
|
||||
int z = 0;
|
||||
string fileName;
|
||||
WindowsShortcut windowsShortcut;
|
||||
foreach ((long ticks, string filteredSourceDirectoryFile, string propertyDirectory, int propertyId) in collection)
|
||||
{
|
||||
z += 1;
|
||||
if (z % 1000 == 0)
|
||||
_Log.Debug($"{z}) Loop {propertyDirectory}");
|
||||
if (!keepAll)
|
||||
{
|
||||
fileName = Path.Combine(propertyDirectory, $"{propertyId}.lnk");
|
||||
if (File.Exists(fileName))
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
fileName = string.Empty;
|
||||
for (short c = 65; c < short.MaxValue; c++)
|
||||
{
|
||||
if (c > 95)
|
||||
break;
|
||||
fileName = Path.Combine(propertyDirectory, $"{(char)c}", $"{propertyId}.lnk");
|
||||
if (File.Exists(fileName))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
continue;
|
||||
windowsShortcut = new() { Path = filteredSourceDirectoryFile };
|
||||
windowsShortcut.Save(fileName);
|
||||
windowsShortcut.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void ThirdPassToMove(Property.Models.Configuration configuration, Map.Models.MapLogic mapLogic, A_Property propertyLogic, Shared.Models.Container[] containers, string aPropertyContentCollectionDirectory)
|
||||
{
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
@ -570,299 +865,4 @@ public class Compare
|
||||
CreateWindowsShortcuts(collection, keepAll);
|
||||
}
|
||||
|
||||
private void CreateWindowsShortcuts((long Ticks, string FilteredSourceDirectoryFile, string PropertyDirectory, int PropertyId)[] collection, bool keepAll)
|
||||
{
|
||||
int z = 0;
|
||||
string fileName;
|
||||
WindowsShortcut windowsShortcut;
|
||||
foreach ((long ticks, string filteredSourceDirectoryFile, string propertyDirectory, int propertyId) in collection)
|
||||
{
|
||||
z += 1;
|
||||
if (z % 1000 == 0)
|
||||
_Log.Debug($"{z}) Loop {propertyDirectory}");
|
||||
if (!keepAll)
|
||||
{
|
||||
fileName = Path.Combine(propertyDirectory, $"{propertyId}.lnk");
|
||||
if (File.Exists(fileName))
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
fileName = string.Empty;
|
||||
for (short c = 65; c < short.MaxValue; c++)
|
||||
{
|
||||
if (c > 95)
|
||||
break;
|
||||
fileName = Path.Combine(propertyDirectory, $"{(char)c}", $"{propertyId}.lnk");
|
||||
if (File.Exists(fileName))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
continue;
|
||||
windowsShortcut = new() { Path = filteredSourceDirectoryFile };
|
||||
windowsShortcut.Save(fileName);
|
||||
windowsShortcut.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveDiffFilesOrSaveLogAndMoveFiles(Property.Models.Configuration configuration)
|
||||
{
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
||||
_Logger?.LogInformation(aPropertySingletonDirectory);
|
||||
_Logger?.LogInformation("to");
|
||||
_Logger?.LogInformation(_Configuration.DiffPropertyDirectory);
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
_Logger?.LogInformation("Press \"Y\" key to continue or close console if compare not needed");
|
||||
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||
break;
|
||||
}
|
||||
_Logger?.LogInformation(". . .");
|
||||
int loadLessThan = 7;
|
||||
string diffRootDirectory;
|
||||
ConsoleKey? consoleKey = null;
|
||||
List<PropertyCompare.Models.PropertyCompare>? duplicates = null;
|
||||
PropertyCompare.Models.PropertyCompare[] diffPropertyCompareCollection;
|
||||
if (string.IsNullOrEmpty(_Configuration.DiffPropertyDirectory))
|
||||
diffRootDirectory = string.Empty;
|
||||
else
|
||||
{
|
||||
if (!_Configuration.DiffPropertyDirectory.EndsWith("{}"))
|
||||
throw new Exception("Invalid directory should end with {}!");
|
||||
diffRootDirectory = Shared.Models.Stateless.Methods.IProperty.GetDiffRootDirectory(_Configuration.DiffPropertyDirectory);
|
||||
}
|
||||
PropertyCompare.Models.PropertyCompareLogic propertyCompareLogic = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _SpellingFindReplace, diffRootDirectory);
|
||||
if (string.IsNullOrEmpty(_Configuration.DiffPropertyDirectory) || !Directory.Exists(_Configuration.DiffPropertyDirectory))
|
||||
diffPropertyCompareCollection = Array.Empty<PropertyCompare.Models.PropertyCompare>();
|
||||
else
|
||||
{
|
||||
diffPropertyCompareCollection = propertyCompareLogic.Get(_Configuration.DiffPropertyDirectory, loadLessThan, duplicates, deleteExtension: false);
|
||||
if (!diffPropertyCompareCollection.Any())
|
||||
throw new Exception("Invalid directory!");
|
||||
}
|
||||
string aPropertyCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "[{}]");
|
||||
PropertyCompare.Models.PropertyCompare[] propertyCompareCollection = propertyCompareLogic.Get(aPropertySingletonDirectory, loadLessThan, duplicates, deleteExtension: false);
|
||||
{
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
string[] lines = (from l in propertyCompareCollection select l.GetSelect()).ToArray();
|
||||
File.WriteAllLines(Path.Join(aPropertyCollectionDirectory, $". . . Ids - {ticks}.txt"), lines);
|
||||
string json = JsonSerializer.Serialize(propertyCompareCollection, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(Path.Join(aPropertyCollectionDirectory, $". . . Ids - {ticks}.nosj"), json);
|
||||
}
|
||||
for (int x = 0; x < int.MaxValue; x++)
|
||||
{
|
||||
_Logger?.LogInformation($"Press \"D\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveDiffFiles)}");
|
||||
_Logger?.LogInformation($"Press \"M\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveLogAndMoveFiles)}");
|
||||
_Logger?.LogInformation("Press \"End\" key when ready to skip");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.D or ConsoleKey.M or ConsoleKey.End)
|
||||
break;
|
||||
}
|
||||
_Logger?.LogInformation(". . .");
|
||||
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.D)
|
||||
propertyCompareLogic.SaveDiffFiles(aPropertyCollectionDirectory, loadLessThan, propertyCompareCollection, diffPropertyCompareCollection);
|
||||
else if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.M)
|
||||
{
|
||||
for (int x = 0; x < int.MaxValue; x++)
|
||||
{
|
||||
_Logger?.LogInformation($"Press \"0 - {loadLessThan}\" key when ready to continue");
|
||||
_Logger?.LogInformation("Press \"End\" key when ready to skip");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
if (consoleKey.Value is ConsoleKey.D0 or ConsoleKey.D1 or ConsoleKey.D2 or ConsoleKey.D3 or ConsoleKey.D4 or ConsoleKey.D5 or ConsoleKey.D6 or ConsoleKey.End)
|
||||
break;
|
||||
}
|
||||
_Logger?.LogInformation(". . .");
|
||||
int i = int.Parse(consoleKey.Value.ToString()[1..]);
|
||||
propertyCompareLogic.SaveLogAndMoveFiles(aPropertyCollectionDirectory, loadLessThan, propertyCompareCollection, diffPropertyCompareCollection, i);
|
||||
}
|
||||
}
|
||||
|
||||
private bool PossiblyRename(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
||||
{
|
||||
bool result = false;
|
||||
string replaceFile;
|
||||
string replaceDirectory;
|
||||
int remainingDirectories = 0;
|
||||
IEnumerable<(string Find, string Replace)>? found;
|
||||
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
||||
{
|
||||
if (!topDirectories.Any())
|
||||
continue;
|
||||
found = from l in _RenameFindReplace where sourceDirectory == l.Find select l;
|
||||
if (!found.Any())
|
||||
continue;
|
||||
if (!result)
|
||||
result = true;
|
||||
replaceDirectory = found.First().Replace;
|
||||
if (!Directory.Exists(replaceDirectory))
|
||||
Directory.Move(sourceDirectory, replaceDirectory);
|
||||
else
|
||||
{
|
||||
if (Directory.EnumerateDirectories(sourceDirectory).Any())
|
||||
remainingDirectories += 1;
|
||||
else
|
||||
{
|
||||
foreach (string sourceDirectoryFile in sourceDirectoryFiles)
|
||||
{
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.GetFileName(sourceDirectoryFile));
|
||||
if (File.Exists(replaceFile))
|
||||
{
|
||||
if (replaceFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpeg"));
|
||||
else if (replaceFile.EndsWith(".jpeg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpg"));
|
||||
}
|
||||
if (File.Exists(replaceFile))
|
||||
continue;
|
||||
File.Move(sourceDirectoryFile, replaceFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private bool PossiblyCorrect(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
||||
{
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
bool result = false;
|
||||
string corrected;
|
||||
string correctedMoveTo;
|
||||
string? correctedDirectory;
|
||||
string filteredSourceDirectoryFile;
|
||||
string[] filteredSourceDirectoryFiles;
|
||||
(string Find, string Replace) findReplace;
|
||||
IEnumerable<(string Find, string Replace)>? found;
|
||||
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
||||
{
|
||||
if (!topDirectories.Any())
|
||||
continue;
|
||||
filteredSourceDirectoryFiles = (from l in sourceDirectoryFiles where !_Configuration.PropertyConfiguration.IgnoreExtensions.Contains(Path.GetExtension(l)) select l).ToArray();
|
||||
if (!filteredSourceDirectoryFiles.Any())
|
||||
continue;
|
||||
for (int i = 0; i < filteredSourceDirectoryFiles.Length; i++)
|
||||
{
|
||||
found = null;
|
||||
for (int z = 0; z < int.MaxValue; z++)
|
||||
{
|
||||
filteredSourceDirectoryFile = filteredSourceDirectoryFiles[i];
|
||||
found = from l in _SpellingFindReplace where filteredSourceDirectoryFile.Contains(l.Find) select l;
|
||||
if (!found.Any())
|
||||
break;
|
||||
findReplace = found.First();
|
||||
corrected = filteredSourceDirectoryFile.Replace(findReplace.Find, findReplace.Replace);
|
||||
correctedDirectory = Path.GetDirectoryName(corrected);
|
||||
if (string.IsNullOrEmpty(correctedDirectory))
|
||||
break;
|
||||
correctedMoveTo = Path.Combine(correctedDirectory, Path.GetFileName(corrected));
|
||||
if (File.Exists(correctedMoveTo))
|
||||
break;
|
||||
if (!Directory.Exists(correctedDirectory))
|
||||
_ = Directory.CreateDirectory(correctedDirectory);
|
||||
if (!result)
|
||||
result = true;
|
||||
File.Move(filteredSourceDirectoryFile, correctedMoveTo);
|
||||
filteredSourceDirectoryFiles[i] = corrected;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private bool PossiblyRenameB(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
||||
{
|
||||
bool result = false;
|
||||
string replaceFile;
|
||||
string replaceDirectory;
|
||||
IEnumerable<(string Find, string Replace)>? found;
|
||||
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
||||
{
|
||||
if (!topDirectories.Any())
|
||||
continue;
|
||||
found = from l in _RenameBFindReplace where sourceDirectory == l.Find select l;
|
||||
if (!found.Any())
|
||||
continue;
|
||||
if (!result)
|
||||
result = true;
|
||||
replaceDirectory = found.First().Replace;
|
||||
if (!Directory.Exists(replaceDirectory))
|
||||
_ = Directory.CreateDirectory(replaceDirectory);
|
||||
foreach (string sourceDirectoryFile in sourceDirectoryFiles)
|
||||
{
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.GetFileName(sourceDirectoryFile));
|
||||
if (File.Exists(replaceFile))
|
||||
{
|
||||
if (replaceFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpeg"));
|
||||
else if (replaceFile.EndsWith(".jpeg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpg"));
|
||||
}
|
||||
if (File.Exists(replaceFile))
|
||||
continue;
|
||||
File.Move(sourceDirectoryFile, replaceFile);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private bool PossiblyRenameC(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
||||
{
|
||||
bool result = false;
|
||||
string replaceFile;
|
||||
string replaceDirectory;
|
||||
IEnumerable<(string Find, string Replace)>? found;
|
||||
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
||||
{
|
||||
if (!topDirectories.Any())
|
||||
continue;
|
||||
found = from l in _RenameCFindReplace where sourceDirectory == l.Find select l;
|
||||
if (!found.Any())
|
||||
continue;
|
||||
if (!result)
|
||||
result = true;
|
||||
replaceDirectory = found.First().Replace;
|
||||
if (!Directory.Exists(replaceDirectory))
|
||||
_ = Directory.CreateDirectory(replaceDirectory);
|
||||
foreach (string sourceDirectoryFile in sourceDirectoryFiles)
|
||||
{
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.GetFileName(sourceDirectoryFile));
|
||||
if (File.Exists(replaceFile))
|
||||
{
|
||||
if (replaceFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpeg"));
|
||||
else if (replaceFile.EndsWith(".jpeg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpg"));
|
||||
}
|
||||
if (File.Exists(replaceFile))
|
||||
continue;
|
||||
File.Move(sourceDirectoryFile, replaceFile);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<string> GetMissingVerifyToSeasonCollection(List<string> _, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
||||
{
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
List<string> results = new();
|
||||
string check;
|
||||
foreach ((int _, string sourceDirectory, string[] _) in groupCollection)
|
||||
{
|
||||
if (sourceDirectory == _Configuration.PropertyConfiguration.RootDirectory)
|
||||
continue;
|
||||
check = sourceDirectory[(_Configuration.PropertyConfiguration.RootDirectory.Length + 1)..];
|
||||
if (check[0] is '=' || check.StartsWith("zzz ="))
|
||||
{
|
||||
if (!_Configuration.PropertyConfiguration.VerifyToSeason.Contains(check))
|
||||
results.Add(check);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Compare</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -33,14 +33,14 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Map\Map.csproj" />
|
||||
|
1
Container/.vscode/format-report.json
vendored
1
Container/.vscode/format-report.json
vendored
@ -1 +0,0 @@
|
||||
[]
|
8
Container/.vscode/settings.json
vendored
8
Container/.vscode/settings.json
vendored
@ -1,8 +0,0 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"dlib",
|
||||
"Exif",
|
||||
"nosj",
|
||||
"Serilog"
|
||||
]
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Container</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">
|
||||
true
|
||||
</IsWindows>
|
||||
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">
|
||||
true
|
||||
</IsOSX>
|
||||
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">
|
||||
true
|
||||
</IsLinux>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsWindows)'=='true'">
|
||||
<DefineConstants>Windows</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsOSX)'=='true'">
|
||||
<DefineConstants>OSX</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsLinux)'=='true'">
|
||||
<DefineConstants>Linux</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'browser-wasm'">
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,487 +0,0 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Properties;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
namespace View_by_Distance.Container.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Container
|
||||
{
|
||||
|
||||
private record FilePair(bool IsUnique,
|
||||
List<FilePath> Collection,
|
||||
FilePath FilePath,
|
||||
Item Item);
|
||||
|
||||
internal static ReadOnlyCollection<Item> GetValidImageItems(IPropertyConfiguration propertyConfiguration, Models.Container container)
|
||||
{
|
||||
List<Item> results = [];
|
||||
foreach (Item item in container.Items)
|
||||
{
|
||||
if (!item.IsValidImageFormatExtension || propertyConfiguration.IgnoreExtensions.Contains(item.FilePath.ExtensionLowered))
|
||||
continue;
|
||||
results.Add(item);
|
||||
}
|
||||
return container.Items.Count == results.Count ? container.Items : results.AsReadOnly();
|
||||
}
|
||||
|
||||
internal static DateTime[] GetContainerDateTimes(ReadOnlyCollection<Item> items)
|
||||
{
|
||||
DateTime[] results;
|
||||
long containerMinimumTicks = (from l in items select l.FilePath.LastWriteTicks).Min();
|
||||
long containerMaximumTicks = (from l in items select l.FilePath.LastWriteTicks).Max();
|
||||
results = [new(containerMinimumTicks), new(containerMaximumTicks)];
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static List<int> GetFilteredDistinctIds(IPropertyConfiguration propertyConfiguration, ReadOnlyCollection<Models.Container> readOnlyContainers)
|
||||
{
|
||||
List<int> results = [];
|
||||
ReadOnlyCollection<Item> filteredItems;
|
||||
foreach (Models.Container container in readOnlyContainers)
|
||||
{
|
||||
if (container.Items.Count == 0)
|
||||
continue;
|
||||
filteredItems = GetValidImageItems(propertyConfiguration, container);
|
||||
if (filteredItems.Count == 0)
|
||||
continue;
|
||||
foreach (Item item in filteredItems)
|
||||
{
|
||||
if (item.ExifDirectory?.FilePath.Id is null || item.ResizedFileHolder is null)
|
||||
continue;
|
||||
if (results.Contains(item.ExifDirectory.FilePath.Id.Value))
|
||||
continue;
|
||||
results.Add(item.ExifDirectory.FilePath.Id.Value);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static (int, Models.Container[]) GetContainers(IPropertyConfiguration propertyConfiguration, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, string _)
|
||||
{
|
||||
int count;
|
||||
Models.Container[] results;
|
||||
bool useIgnoreExtensions = true;
|
||||
const bool useCeilingAverage = true;
|
||||
const string fileSearchFilter = "*";
|
||||
IDlibDotNet dlibDotNet = GetDlibDotNet();
|
||||
const string directorySearchFilter = "*";
|
||||
ReadOnlyDictionary<int, ExifDirectory>? exifDirectoriesById = null;
|
||||
ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>>? keyValuePairs = null;
|
||||
ReadOnlyCollection<string[]> filesCollection = IDirectory.GetFilesCollection(propertyConfiguration.RootDirectory, directorySearchFilter, fileSearchFilter, useCeilingAverage);
|
||||
ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection = IDirectory.GetFilePathCollections(propertyConfiguration, filesCollection, useIgnoreExtensions);
|
||||
(count, results) = GetContainers(dlibDotNet, propertyConfiguration, propertyConfiguration.RootDirectory, keyValuePairs, splatNineIdentifiers, filePathsCollection, exifDirectoriesById, directorySearchFilter);
|
||||
return (count, results);
|
||||
}
|
||||
|
||||
private static IDlibDotNet GetDlibDotNet() =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
private static (int, Models.Container[]) GetContainers(IDlibDotNet dlibDotNet, IPropertyConfiguration propertyConfiguration, string filesCollectionDirectory, ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>>? keyValuePairs, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection, ReadOnlyDictionary<int, ExifDirectory>? exifDirectoriesById, string directorySearchFilter)
|
||||
{
|
||||
List<Models.Container> results = [];
|
||||
string directory;
|
||||
List<Item>? items;
|
||||
Models.Container container;
|
||||
List<string> directories = [];
|
||||
Dictionary<string, List<Item>> directoryToItems = [];
|
||||
foreach (ReadOnlyCollection<FilePath> filePaths in filePathsCollection)
|
||||
{
|
||||
if (filePaths.Count == 0)
|
||||
continue;
|
||||
directory = filePaths[0].DirectoryFullPath;
|
||||
if (directory is null)
|
||||
continue;
|
||||
if (!directories.Contains(directory))
|
||||
directories.Add(directory);
|
||||
if (!directoryToItems.TryGetValue(directory, out items))
|
||||
{
|
||||
directoryToItems.Add(directory, []);
|
||||
if (!directoryToItems.TryGetValue(directory, out items))
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
(string aResultsFullGroupDirectory, _) = dlibDotNet.GetResultsFullGroupDirectories();
|
||||
string aPropertySingletonDirectory = Path.Combine(aResultsFullGroupDirectory, propertyConfiguration.ResultSingleton);
|
||||
if (!Directory.Exists(aPropertySingletonDirectory))
|
||||
_ = Directory.CreateDirectory(aPropertySingletonDirectory);
|
||||
List<FilePair> filePairs = GetFilePairs(dlibDotNet, propertyConfiguration, aPropertySingletonDirectory, filesCollectionDirectory, keyValuePairs, splatNineIdentifiers, filePathsCollection, exifDirectoriesById, directorySearchFilter);
|
||||
foreach (FilePair filePair in filePairs)
|
||||
{
|
||||
if (!directoryToItems.TryGetValue(filePair.FilePath.DirectoryFullPath, out items))
|
||||
{
|
||||
directoryToItems.Add(filePair.FilePath.DirectoryFullPath, []);
|
||||
if (!directoryToItems.TryGetValue(filePair.FilePath.DirectoryFullPath, out items))
|
||||
throw new Exception();
|
||||
}
|
||||
items.Add(filePair.Item);
|
||||
}
|
||||
foreach (KeyValuePair<string, List<Item>> keyValuePair in directoryToItems)
|
||||
{
|
||||
if (keyValuePair.Value.Count == 0)
|
||||
continue;
|
||||
container = new(keyValuePair.Key, new(keyValuePair.Value));
|
||||
results.Add(container);
|
||||
}
|
||||
return (filePairs.Count, results.ToArray());
|
||||
}
|
||||
|
||||
private static List<FilePair> GetFilePairs(IDlibDotNet dlibDotNet, IPropertyConfiguration propertyConfiguration, string aPropertySingletonDirectory, string filesCollectionDirectory, ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>>? keyValuePairs, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection, ReadOnlyDictionary<int, ExifDirectory>? exifDirectoriesById, string directorySearchFilter)
|
||||
{
|
||||
List<FilePair> results = [];
|
||||
const string extension = ".json";
|
||||
ReadOnlyCollection<Shared.Models.FilePair> filePairs;
|
||||
string jsonGroupDirectory = aPropertySingletonDirectory;
|
||||
int maxDegreeOfParallelism = Environment.ProcessorCount;
|
||||
int filesCollectionDirectoryLength = filesCollectionDirectory.Length;
|
||||
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = maxDegreeOfParallelism };
|
||||
filePairs = IFilePair.GetFilePairs(propertyConfiguration, directorySearchFilter, extension, jsonGroupDirectory, filePathsCollection);
|
||||
_ = Parallel.For(0, filePairs.Count, parallelOptions, (i, state) =>
|
||||
ParallelFor(dlibDotNet, propertyConfiguration, jsonGroupDirectory, extension, keyValuePairs, splatNineIdentifiers, filesCollectionDirectoryLength, exifDirectoriesById, filePairs[i], results));
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void ParallelFor(IDlibDotNet dlibDotNet, IPropertyConfiguration propertyConfiguration, string jsonGroupDirectory, string extension, ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>>? keyValuePairs, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, int rootDirectoryLength, ReadOnlyDictionary<int, ExifDirectory>? exifDirectoriesById, Shared.Models.FilePair filePair, List<FilePair> results)
|
||||
{
|
||||
dlibDotNet?.Tick();
|
||||
bool abandoned = false;
|
||||
FileHolder sourceDirectoryFileHolder;
|
||||
if (exifDirectoriesById is null || filePair.FilePath.Id is null || !exifDirectoriesById.TryGetValue(filePair.FilePath.Id.Value, out ExifDirectory? exifDirectory))
|
||||
exifDirectory = Metadata.Models.Stateless.Methods.IMetadata.GetExifDirectory(filePair.FilePath);
|
||||
ReadOnlyCollection<string> keywords = IMetaBase.GetKeywords(exifDirectory?.ExifBaseDirectories);
|
||||
bool? shouldIgnore = propertyConfiguration.IgnoreRulesKeyWords.Any(keywords.Contains);
|
||||
bool? fileSizeChanged = exifDirectory is not null ? exifDirectory.FilePath.Length != filePair.FilePath.Length : null;
|
||||
bool isValidImageFormatExtension = propertyConfiguration.ValidImageFormatExtensions.Contains(filePair.FilePath.ExtensionLowered);
|
||||
bool? isArchive = filePair.FilePath.Id is null || splatNineIdentifiers is null ? null : splatNineIdentifiers.TryGetValue(filePair.FilePath.Id.Value, out Identifier? identifier);
|
||||
if (exifDirectory is not null && filePair.FilePath.Id is not null && filePair.FilePath.HasIgnoreKeyword is not null && filePair.FilePath.HasDateTimeOriginal is not null)
|
||||
{
|
||||
char? change;
|
||||
ReadOnlyCollection<FilePath>? filePaths = null;
|
||||
DateTime? dateTime = IDate.GetDateTimeOriginal(exifDirectory);
|
||||
char hasIgnoreKeyword = IId.GetHasIgnoreKeyword(filePair.FilePath).ToString()[0];
|
||||
char hasDateTimeOriginal = IId.GetHasDateTimeOriginal(propertyConfiguration, filePair.FilePath).ToString()[0];
|
||||
char missingDateTimeOriginal = IId.GetMissingDateTimeOriginal(propertyConfiguration, filePair.FilePath).ToString()[0];
|
||||
if (shouldIgnore is not null && shouldIgnore.Value)
|
||||
{
|
||||
if (filePair.FilePath.FileNameFirstSegment[^1] == hasIgnoreKeyword)
|
||||
change = null;
|
||||
else
|
||||
{
|
||||
change = hasIgnoreKeyword;
|
||||
if (keyValuePairs is null || !keyValuePairs.TryGetValue(filePair.FilePath.Id.Value, out filePaths) || filePaths is null)
|
||||
throw new NotSupportedException($"Rename File! <{filePair.FilePath.FileNameFirstSegment}>");
|
||||
}
|
||||
}
|
||||
else if ((shouldIgnore is null || !shouldIgnore.Value) && dateTime is null)
|
||||
{
|
||||
if (filePair.FilePath.FileNameFirstSegment[^1] == missingDateTimeOriginal)
|
||||
change = null;
|
||||
else
|
||||
{
|
||||
change = missingDateTimeOriginal;
|
||||
if (keyValuePairs is null || !keyValuePairs.TryGetValue(filePair.FilePath.Id.Value, out filePaths) || filePaths is null)
|
||||
throw new NotSupportedException($"Rename File! <{filePair.FilePath.FileNameFirstSegment}>");
|
||||
}
|
||||
}
|
||||
else if (filePair.FilePath.FileNameFirstSegment[^1] != hasDateTimeOriginal)
|
||||
{
|
||||
change = hasDateTimeOriginal;
|
||||
if (keyValuePairs is null || !keyValuePairs.TryGetValue(filePair.FilePath.Id.Value, out filePaths) || filePaths is null)
|
||||
throw new NotSupportedException($"Rename File! <{filePair.FilePath.FileNameFirstSegment}>");
|
||||
}
|
||||
else
|
||||
change = null;
|
||||
if (filePaths is not null && change is not null)
|
||||
RenameFile(filePair, filePair.FilePath, change.Value, filePaths);
|
||||
}
|
||||
string relativePath = Shared.Models.Stateless.Methods.IPath.GetRelativePath(filePair.FilePath.FullName, rootDirectoryLength, forceExtensionToLower: true);
|
||||
bool? lastWriteTimeChanged = exifDirectory is not null ? propertyConfiguration.PropertiesChangedForProperty || exifDirectory.FilePath.LastWriteTicks != filePair.FilePath.LastWriteTicks : null;
|
||||
if (filePair.Match is not null)
|
||||
sourceDirectoryFileHolder = IFileHolder.Get(filePair.Match);
|
||||
else if (!filePair.IsUnique)
|
||||
sourceDirectoryFileHolder = IFileHolder.Get(Path.GetFullPath(string.Concat(jsonGroupDirectory, relativePath, extension)));
|
||||
else
|
||||
{
|
||||
string fileName = Path.GetFileName(filePair.FilePath.FullName);
|
||||
CombinedEnumAndIndex cei = Shared.Models.Stateless.Methods.IPath.GetCombinedEnumAndIndex(propertyConfiguration, filePair.FilePath);
|
||||
string directory = Path.Combine(jsonGroupDirectory, cei.Combined);
|
||||
string jsonFileName = $"{fileName}{extension}";
|
||||
string fullFileName = Path.Combine(directory, jsonFileName);
|
||||
MoveIf(jsonFileName, cei, directory, fullFileName);
|
||||
sourceDirectoryFileHolder = IFileHolder.Get(fullFileName);
|
||||
}
|
||||
if (sourceDirectoryFileHolder.CreationTime is not null && sourceDirectoryFileHolder.LastWriteTime is not null && filePair.FilePath.LastWriteTicks != sourceDirectoryFileHolder.CreationTime.Value.Ticks)
|
||||
{
|
||||
File.SetCreationTime(sourceDirectoryFileHolder.FullName, new(filePair.FilePath.LastWriteTicks));
|
||||
File.SetLastWriteTime(sourceDirectoryFileHolder.FullName, sourceDirectoryFileHolder.LastWriteTime.Value);
|
||||
}
|
||||
Item item = Item.Get(filePair.FilePath, sourceDirectoryFileHolder, relativePath, isArchive, filePair.IsNotUniqueAndNeedsReview, filePair.IsUnique, isValidImageFormatExtension, exifDirectory, abandoned, fileSizeChanged, lastWriteTimeChanged);
|
||||
lock (results)
|
||||
results.Add(new(filePair.IsUnique, filePair.Collection, filePair.FilePath, item));
|
||||
}
|
||||
|
||||
private static void RenameFile(Shared.Models.FilePair filePair, FilePath filePath, char change, ReadOnlyCollection<FilePath> filePaths)
|
||||
{
|
||||
string checkFile;
|
||||
if (filePath.DirectoryFullPath.Contains("Results") && filePath.DirectoryFullPath.Contains("Resize"))
|
||||
File.Delete(filePath.FullName);
|
||||
if (filePair.Match is not null)
|
||||
{
|
||||
string fileNameWithoutExtensionSecond = Path.GetFileNameWithoutExtension(filePair.Match.NameWithoutExtension);
|
||||
string extensionSecond = Path.GetExtension(filePair.Match.Name);
|
||||
checkFile = Path.Combine(filePair.Match.DirectoryFullPath, $"{fileNameWithoutExtensionSecond[..^1]}{change}{extensionSecond}{filePair.Match.ExtensionLowered}");
|
||||
if (!File.Exists(checkFile))
|
||||
File.Move(filePair.Match.FullName, checkFile);
|
||||
}
|
||||
foreach (FilePath f in filePaths)
|
||||
{
|
||||
checkFile = Path.Combine(f.DirectoryFullPath, $"{f.NameWithoutExtension[..^1]}{change}{f.ExtensionLowered}");
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(f.FullName, checkFile);
|
||||
}
|
||||
}
|
||||
|
||||
private static void MoveIf(string fileName, CombinedEnumAndIndex cei, string directory, string fullFileName)
|
||||
{
|
||||
string[] segments = directory.Split(cei.Combined);
|
||||
string? checkDirectory = segments.Length == 1 ?
|
||||
Path.Combine(segments[0], $"{cei.Combined[2..]}") :
|
||||
segments.Length == 2 ?
|
||||
$"{segments[0]}{cei.Combined[2..]}{segments[1]}" :
|
||||
null;
|
||||
if (checkDirectory is not null && Directory.Exists(checkDirectory))
|
||||
{
|
||||
string checkFile = Path.Combine(checkDirectory, fileName);
|
||||
if (File.Exists(checkFile))
|
||||
File.Move(checkFile, fullFileName);
|
||||
}
|
||||
}
|
||||
|
||||
internal static List<string> GetFilteredDistinctFileNameFirstSegments(IPropertyConfiguration propertyConfiguration, ReadOnlyCollection<Models.Container> readOnlyContainers)
|
||||
{
|
||||
List<string> results = [];
|
||||
ReadOnlyCollection<Item> filteredItems;
|
||||
foreach (Models.Container container in readOnlyContainers)
|
||||
{
|
||||
if (container.Items.Count == 0)
|
||||
continue;
|
||||
filteredItems = GetValidImageItems(propertyConfiguration, container);
|
||||
if (filteredItems.Count == 0)
|
||||
continue;
|
||||
foreach (Item item in filteredItems)
|
||||
{
|
||||
if (item.ExifDirectory?.FilePath.Id is null || item.ResizedFileHolder is null)
|
||||
continue;
|
||||
if (results.Contains(item.FilePath.FileNameFirstSegment))
|
||||
continue;
|
||||
results.Add(item.FilePath.FileNameFirstSegment);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static ReadOnlyCollection<Item> GetValidImageItems(IPropertyConfiguration propertyConfiguration, ReadOnlyCollection<Models.Container> containers, bool distinctItems, bool filterItems)
|
||||
{
|
||||
List<Item> results = [];
|
||||
List<int> distinct = [];
|
||||
ReadOnlyCollection<Item> filteredItems;
|
||||
foreach (Models.Container container in containers)
|
||||
{
|
||||
if (container.Items.Count == 0)
|
||||
continue;
|
||||
if (!filterItems)
|
||||
filteredItems = container.Items;
|
||||
else
|
||||
{
|
||||
filteredItems = GetValidImageItems(propertyConfiguration, container);
|
||||
if (filteredItems.Count == 0)
|
||||
continue;
|
||||
}
|
||||
foreach (Item item in filteredItems)
|
||||
{
|
||||
if (item.ExifDirectory?.FilePath.Id is null || item.ResizedFileHolder is null)
|
||||
continue;
|
||||
if (distinctItems)
|
||||
{
|
||||
if (distinct.Contains(item.ExifDirectory.FilePath.Id.Value))
|
||||
continue;
|
||||
distinct.Add(item.ExifDirectory.FilePath.Id.Value);
|
||||
}
|
||||
results.Add(item);
|
||||
}
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
internal static ReadOnlyCollection<Models.Container> GetContainers(IDlibDotNet dlibDotNet, IPropertyConfiguration propertyConfiguration, string facesFileNameExtension, string facesHiddenFileNameExtension, string eDistanceContentDirectory, string filesCollectionDirectory, ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>>? keyValuePairs, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection, ReadOnlyDictionary<int, ExifDirectory> exifDirectoriesById)
|
||||
{
|
||||
Models.Container[] results;
|
||||
const string directorySearchFilter = "*";
|
||||
(_, results) = GetContainers(dlibDotNet, propertyConfiguration, filesCollectionDirectory, keyValuePairs, splatNineIdentifiers, filePathsCollection, exifDirectoriesById, directorySearchFilter);
|
||||
if (keyValuePairs is not null)
|
||||
DoGetFilePairsForRemaining(dlibDotNet, propertyConfiguration, facesFileNameExtension, facesHiddenFileNameExtension, eDistanceContentDirectory, filePathsCollection, directorySearchFilter);
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static void DoGetFilePairsForRemaining(IDlibDotNet dlibDotNet, IPropertyConfiguration propertyConfiguration, string facesFileNameExtension, string facesHiddenFileNameExtension, string eDistanceContentDirectory, ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection, string directorySearchFilter)
|
||||
{
|
||||
const string extension = ".json";
|
||||
(_, string bResultsFullGroupDirectory) = dlibDotNet.GetResultsFullGroupDirectories();
|
||||
ReadOnlyDictionary<int, List<FilePath>> fileNamesToFiles = FilePath.GetFilesKeyValuePairs(filePathsCollection);
|
||||
string bMetaSingletonDirectory = Path.Combine(bResultsFullGroupDirectory, propertyConfiguration.ResultSingleton);
|
||||
if (!Directory.Exists(bMetaSingletonDirectory))
|
||||
_ = Directory.CreateDirectory(bMetaSingletonDirectory);
|
||||
_ = IFilePair.GetFilePairs(propertyConfiguration, directorySearchFilter, extension, bMetaSingletonDirectory, filePathsCollection, fileNamesToFiles);
|
||||
(string cResultsFullGroupDirectory, _, string dResultsFullGroupDirectory, _) = dlibDotNet.GetResultsFullGroupDirectories("Original");
|
||||
string cResizeSingletonDirectory = Path.Combine(cResultsFullGroupDirectory, propertyConfiguration.ResultSingleton);
|
||||
if (!Directory.Exists(cResizeSingletonDirectory))
|
||||
_ = Directory.CreateDirectory(cResizeSingletonDirectory);
|
||||
_ = IFilePair.GetFilePairs(propertyConfiguration, directorySearchFilter, extension, cResizeSingletonDirectory, filePathsCollection, fileNamesToFiles);
|
||||
string dFaceCollectionDirectory = Path.Combine(dResultsFullGroupDirectory, propertyConfiguration.ResultCollection);
|
||||
if (!Directory.Exists(dFaceCollectionDirectory))
|
||||
_ = Directory.CreateDirectory(dFaceCollectionDirectory);
|
||||
_ = IFilePair.GetFilePairs(propertyConfiguration, directorySearchFilter, extension, dFaceCollectionDirectory, filePathsCollection, fileNamesToFiles);
|
||||
string dFaceContentDirectory = Path.Combine(dResultsFullGroupDirectory, propertyConfiguration.ResultContent);
|
||||
if (!Directory.Exists(dFaceContentDirectory))
|
||||
_ = Directory.CreateDirectory(dFaceContentDirectory);
|
||||
AnyMovedFace(propertyConfiguration, facesFileNameExtension, facesHiddenFileNameExtension, fileNamesToFiles, dFaceContentDirectory);
|
||||
AnyMovedDistance(propertyConfiguration, facesFileNameExtension, fileNamesToFiles, eDistanceContentDirectory);
|
||||
}
|
||||
|
||||
private static void AnyMovedFace(IPropertyConfiguration propertyConfiguration, string extension, string hiddenExtension, IReadOnlyDictionary<int, List<FilePath>> fileNamesToFiles, string jsonGroupDirectory)
|
||||
{
|
||||
string directory;
|
||||
string checkFile;
|
||||
string directoryName;
|
||||
List<string> files = [];
|
||||
string[] fileNameSegments;
|
||||
List<string> directories = [];
|
||||
files.AddRange(Directory.GetFiles(jsonGroupDirectory, $"*{extension}", SearchOption.AllDirectories));
|
||||
files.AddRange(Directory.GetFiles(jsonGroupDirectory, $"*{hiddenExtension}", SearchOption.AllDirectories));
|
||||
foreach (string file in files)
|
||||
{
|
||||
directory = Path.GetDirectoryName(file) ?? throw new Exception();
|
||||
if (!directories.Contains(directory))
|
||||
directories.Add(directory);
|
||||
directoryName = Path.GetFileName(directory);
|
||||
fileNameSegments = Path.GetFileName(file).Split('.');
|
||||
if (fileNameSegments[0] != directoryName)
|
||||
{
|
||||
fileNameSegments[0] = string.Empty;
|
||||
checkFile = Path.Combine(directory, $"{directoryName}{string.Join('.', fileNameSegments)}");
|
||||
if (!File.Exists(checkFile))
|
||||
File.Move(file, checkFile);
|
||||
else
|
||||
{
|
||||
if (new FileInfo(file).LastWriteTime > new FileInfo(checkFile).LastWriteTime)
|
||||
File.Delete(file);
|
||||
else
|
||||
File.Move(file, checkFile, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (directories.Count > 0)
|
||||
AnyMovedFace(propertyConfiguration, fileNamesToFiles, directories);
|
||||
}
|
||||
|
||||
private static void AnyMovedFace(IPropertyConfiguration propertyConfiguration, IReadOnlyDictionary<int, List<FilePath>> fileNamesToFiles, List<string> directories)
|
||||
{
|
||||
bool result = false;
|
||||
string checkFile;
|
||||
FilePath filePath;
|
||||
string subDirectory;
|
||||
string directoryName;
|
||||
string checkDirectory;
|
||||
FileHolder fileHolder;
|
||||
string directoryNameWith;
|
||||
List<FilePath>? collection;
|
||||
List<string> directoryNames = [];
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
fileHolder = IFileHolder.Get(Path.GetFileName(directory));
|
||||
filePath = FilePath.Get(propertyConfiguration, fileHolder, index: null);
|
||||
if (filePath.Id is null)
|
||||
continue;
|
||||
if (!fileNamesToFiles.TryGetValue(filePath.Id.Value, out collection))
|
||||
throw new Exception();
|
||||
directoryNames.Clear();
|
||||
foreach (FilePath f in collection)
|
||||
directoryNames.Add(Path.GetFileName(f.DirectoryFullPath) ?? throw new Exception());
|
||||
if (directoryNames.Count == 0 || directoryNames.Distinct().Count() != 1)
|
||||
continue;
|
||||
directoryName = Path.GetFileName(Path.GetDirectoryName(directory)) ?? throw new Exception();
|
||||
if (directoryName != directoryNames[0])
|
||||
{
|
||||
subDirectory = Path.GetDirectoryName(Path.GetDirectoryName(directory)) ?? throw new Exception();
|
||||
checkDirectory = Path.Combine(subDirectory, directoryNames[0]);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
directoryNameWith = collection.Count > 1 ? directoryName : $"{collection[0].NameWithoutExtension}";
|
||||
checkFile = Path.Combine(checkDirectory, directoryNameWith);
|
||||
if (!result)
|
||||
result = true;
|
||||
if (!Directory.Exists(checkFile))
|
||||
Directory.Move(directory, checkFile);
|
||||
else
|
||||
{
|
||||
if (new DirectoryInfo(directory).LastWriteTime > new DirectoryInfo(checkFile).LastWriteTime)
|
||||
Directory.Delete(directory, recursive: true);
|
||||
else
|
||||
{
|
||||
Directory.Delete(checkFile, recursive: true);
|
||||
Directory.Move(directory, checkFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AnyMovedDistance(IPropertyConfiguration propertyConfiguration, string extension, IReadOnlyDictionary<int, List<FilePath>> fileNamesToFiles, string jsonGroupDirectory)
|
||||
{
|
||||
bool result = false;
|
||||
string checkFile;
|
||||
string directory;
|
||||
FilePath filePath;
|
||||
FileHolder fileHolder;
|
||||
string[] fileNameSegments;
|
||||
List<FilePath>? collection;
|
||||
List<string> fileNames = [];
|
||||
string[] files = Directory.GetFiles(jsonGroupDirectory, $"*{extension}", SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileHolder = IFileHolder.Get(file);
|
||||
if (!fileHolder.Exists)
|
||||
continue;
|
||||
filePath = FilePath.Get(propertyConfiguration, fileHolder, index: null);
|
||||
if (filePath.Id is null)
|
||||
continue;
|
||||
fileNameSegments = filePath.Name.Split('.');
|
||||
if (!fileNamesToFiles.TryGetValue(filePath.Id.Value, out collection))
|
||||
continue;
|
||||
fileNames.Clear();
|
||||
foreach (FilePath f in collection)
|
||||
fileNames.Add(f.NameWithoutExtension ?? throw new Exception());
|
||||
if (fileNames.Count == 0 || fileNames.Distinct().Count() != 1)
|
||||
continue;
|
||||
if (filePath.FileNameFirstSegment != fileNames[0])
|
||||
{
|
||||
fileNameSegments[0] = string.Empty;
|
||||
directory = Path.GetDirectoryName(file) ?? throw new Exception();
|
||||
checkFile = Path.Combine(directory, $"{fileNames[0]}{string.Join('.', fileNameSegments)}");
|
||||
if (!result)
|
||||
result = true;
|
||||
if (!File.Exists(checkFile))
|
||||
File.Move(file, checkFile);
|
||||
else
|
||||
{
|
||||
if (new FileInfo(file).LastWriteTime > new FileInfo(checkFile).LastWriteTime)
|
||||
File.Delete(file);
|
||||
else
|
||||
File.Move(file, checkFile, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Properties;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
namespace View_by_Distance.Container.Models.Stateless.Methods;
|
||||
|
||||
public interface IContainer
|
||||
{
|
||||
|
||||
public static (int, Models.Container[]) GetContainers(IPropertyConfiguration propertyConfiguration, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, string aPropertySingletonDirectory) =>
|
||||
Container.GetContainers(propertyConfiguration, splatNineIdentifiers, aPropertySingletonDirectory);
|
||||
|
||||
public static DateTime[] GetContainerDateTimes(ReadOnlyCollection<Item> items) =>
|
||||
Container.GetContainerDateTimes(items);
|
||||
|
||||
public static ReadOnlyCollection<Item> GetValidImageItems(IPropertyConfiguration propertyConfiguration, Models.Container container) =>
|
||||
Container.GetValidImageItems(propertyConfiguration, container);
|
||||
|
||||
public static (int, Models.Container[]) GetContainers(IPropertyConfiguration propertyConfiguration, string aPropertySingletonDirectory) =>
|
||||
GetContainers(propertyConfiguration, null, aPropertySingletonDirectory);
|
||||
|
||||
public static List<int> GetFilteredDistinctIds(IPropertyConfiguration propertyConfiguration, ReadOnlyCollection<Models.Container> readOnlyContainers) =>
|
||||
Container.GetFilteredDistinctIds(propertyConfiguration, readOnlyContainers);
|
||||
|
||||
public static List<string> GetFilteredDistinctFileNameFirstSegments(IPropertyConfiguration propertyConfiguration, ReadOnlyCollection<Models.Container> readOnlyContainers) =>
|
||||
Container.GetFilteredDistinctFileNameFirstSegments(propertyConfiguration, readOnlyContainers);
|
||||
|
||||
public static ReadOnlyCollection<Item> GetValidImageItems(IPropertyConfiguration propertyConfiguration, ReadOnlyCollection<Models.Container> containers, bool distinctItems, bool filterItems) =>
|
||||
Container.GetValidImageItems(propertyConfiguration, containers, distinctItems, filterItems);
|
||||
|
||||
public static ReadOnlyCollection<Models.Container> GetContainers(IDlibDotNet dlibDotNet, IPropertyConfiguration propertyConfiguration, string facesFileNameExtension, string facesHiddenFileNameExtension, string eDistanceContentDirectory, string filesCollectionDirectory, ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>>? keyValuePairs, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection, ReadOnlyDictionary<int, ExifDirectory> exifDirectoriesById) =>
|
||||
Container.GetContainers(dlibDotNet, propertyConfiguration, facesFileNameExtension, facesHiddenFileNameExtension, eDistanceContentDirectory, filesCollectionDirectory, keyValuePairs, splatNineIdentifiers, filePathsCollection, exifDirectoriesById);
|
||||
|
||||
internal DateTime[] TestStatic_GetContainerDateTimes(ReadOnlyCollection<Item> items) =>
|
||||
GetContainerDateTimes(items);
|
||||
|
||||
internal ReadOnlyCollection<Item> TestStatic_GetValidImageItems(IPropertyConfiguration propertyConfiguration, Models.Container container) =>
|
||||
GetValidImageItems(propertyConfiguration, container);
|
||||
|
||||
internal (int, Models.Container[]) TestStatic_GetContainers(IPropertyConfiguration propertyConfiguration, string aPropertySingletonDirectory) =>
|
||||
GetContainers(propertyConfiguration, aPropertySingletonDirectory);
|
||||
|
||||
internal List<int> TestStatic_GetFilteredDistinctIds(IPropertyConfiguration propertyConfiguration, ReadOnlyCollection<Models.Container> readOnlyContainers) =>
|
||||
GetFilteredDistinctIds(propertyConfiguration, readOnlyContainers);
|
||||
|
||||
internal List<string> TestStatic_GetFilteredDistinctFileNameFirstSegments(IPropertyConfiguration propertyConfiguration, ReadOnlyCollection<Models.Container> readOnlyContainers) =>
|
||||
GetFilteredDistinctFileNameFirstSegments(propertyConfiguration, readOnlyContainers);
|
||||
|
||||
internal ReadOnlyCollection<Item> TestStatic_GetValidImageItems(IPropertyConfiguration propertyConfiguration, ReadOnlyCollection<Models.Container> containers, bool distinctItems, bool filterItems) =>
|
||||
GetValidImageItems(propertyConfiguration, containers, distinctItems, filterItems);
|
||||
|
||||
internal (int, Models.Container[]) TestStatic_GetContainers(IPropertyConfiguration propertyConfiguration, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, string aPropertySingletonDirectory) =>
|
||||
GetContainers(propertyConfiguration, splatNineIdentifiers, aPropertySingletonDirectory);
|
||||
|
||||
internal ReadOnlyCollection<Models.Container> TestStatic_GetContainers(IDlibDotNet dlibDotNet, IPropertyConfiguration propertyConfiguration, string facesFileNameExtension, string facesHiddenFileNameExtension, string eDistanceContentDirectory, string filesCollectionDirectory, ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>>? keyValuePairs, ReadOnlyDictionary<int, Identifier>? splatNineIdentifiers, ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection, ReadOnlyDictionary<int, ExifDirectory> exifDirectoriesById) =>
|
||||
GetContainers(dlibDotNet, propertyConfiguration, facesFileNameExtension, facesHiddenFileNameExtension, eDistanceContentDirectory, filesCollectionDirectory, keyValuePairs, splatNineIdentifiers, filePathsCollection, exifDirectoriesById);
|
||||
|
||||
}
|
@ -4,13 +4,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<UserSecretsId>d862524f-2b48-4f47-b4c3-5a8615814ec2</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Copy.Distinct</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -35,9 +35,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Phares.Shared;
|
||||
using ShellProgressBar;
|
||||
@ -18,8 +18,8 @@ public class CopyDistinct
|
||||
private readonly Configuration _Configuration;
|
||||
private readonly IsEnvironment _IsEnvironment;
|
||||
private readonly IConfigurationRoot _ConfigurationRoot;
|
||||
private readonly ReadOnlyDictionary<string, string[]> _FileGroups;
|
||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||
private readonly ReadOnlyDictionary<byte, ReadOnlyCollection<string>> _FileGroups;
|
||||
|
||||
public CopyDistinct(List<string> args, ILogger<Program> logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||
{
|
||||
@ -37,9 +37,7 @@ public class CopyDistinct
|
||||
_Configuration = configuration;
|
||||
logger?.LogInformation(propertyConfiguration.RootDirectory);
|
||||
(bool move, ReadOnlyCollection<string[]> filesCollection, bool anyLenFiles, bool moveBack) = Verify();
|
||||
ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePairs =
|
||||
Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, appSettings.CopyTo, [appSettings.ResultDirectoryKey]);
|
||||
_FileGroups = keyValuePairs[appSettings.ResultDirectoryKey];
|
||||
_FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, appSettings.CopyTo, [appSettings.ResultDirectoryKey]);
|
||||
List<string> lines = CopyDistinctFilesInDirectories(logger, move, filesCollection, anyLenFiles, moveBack);
|
||||
if (lines.Count != 0)
|
||||
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
|
||||
@ -95,76 +93,6 @@ public class CopyDistinct
|
||||
return (move, new(filesCollection), anyLenFiles, moveBack);
|
||||
}
|
||||
|
||||
private List<string> CopyDistinctFilesInDirectories(ILogger<Program>? logger, bool move, ReadOnlyCollection<string[]> filesCollection, bool anyLenFiles, bool moveBack)
|
||||
{
|
||||
List<string> results = [];
|
||||
ProgressBar progressBar;
|
||||
string[] distinctDirectories;
|
||||
ConsoleKey? consoleKey = null;
|
||||
string message = nameof(CopyDistinct);
|
||||
List<(FilePath, string)> toDoCollection;
|
||||
int count = filesCollection.Select(l => l.Length).Sum();
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
if (moveBack)
|
||||
{
|
||||
if (!anyLenFiles)
|
||||
throw new NotSupportedException();
|
||||
(distinctDirectories, toDoCollection) = GetMoveBackToDoCollection(_PropertyConfiguration, filesCollection);
|
||||
}
|
||||
else
|
||||
{
|
||||
progressBar = new(count, message, options);
|
||||
string key = string.IsNullOrEmpty(_AppSettings.ResultDirectoryKey) ? _PropertyConfiguration.ResultAllInOne : _AppSettings.ResultDirectoryKey;
|
||||
if (key != _PropertyConfiguration.ResultContent)
|
||||
throw new NotImplementedException("Changed but didn't update!");
|
||||
ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection = IDirectory.GetFilePathCollections(_Configuration.PropertyConfiguration, filesCollection, useIgnoreExtensions: true);
|
||||
(distinctDirectories, toDoCollection) = IDirectory.GetToDoCollection(_PropertyConfiguration, _AppSettings.CopyDuplicates, _AppSettings.IfCanUseId, filePathsCollection, _FileGroups, () => progressBar.Tick());
|
||||
progressBar.Dispose();
|
||||
}
|
||||
foreach (string distinctDirectory in distinctDirectories)
|
||||
{
|
||||
if (!Directory.Exists(distinctDirectory))
|
||||
_ = Directory.CreateDirectory(distinctDirectory);
|
||||
}
|
||||
if (move)
|
||||
logger?.LogInformation($"Ready to Move {toDoCollection.Count} file(s)?");
|
||||
else if (!moveBack)
|
||||
logger?.LogInformation($"Ready to Copy {toDoCollection.Count} file(s)?");
|
||||
else
|
||||
logger?.LogInformation($"Ready to Move back {toDoCollection.Count} file(s)?");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
if (move)
|
||||
logger?.LogInformation("Press \"Y\" key to move file(s), \"N\" key to log file(s) or close console to not move files");
|
||||
else if (!moveBack)
|
||||
logger?.LogInformation("Press \"Y\" key to copy file(s), \"N\" key to log file(s) or close console to not copy files");
|
||||
else
|
||||
logger?.LogInformation("Press \"Y\" key to move back file(s), \"N\" key to log file(s) or close console to not move back files");
|
||||
consoleKey = System.Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||
break;
|
||||
}
|
||||
logger?.LogInformation(". . .");
|
||||
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
||||
{
|
||||
if (move || moveBack)
|
||||
logger?.LogInformation("Nothing moved!");
|
||||
else
|
||||
logger?.LogInformation("Nothing copied!");
|
||||
}
|
||||
else
|
||||
{
|
||||
progressBar = new(count, message, options);
|
||||
results.AddRange(IDirectory.CopyOrMove(toDoCollection, move, moveBack, () => progressBar.Tick()));
|
||||
progressBar.Dispose();
|
||||
if (move || moveBack)
|
||||
logger?.LogInformation("Done moving");
|
||||
else
|
||||
logger?.LogInformation("Done copying");
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static (string[], List<(FilePath, string)>) GetMoveBackToDoCollection(Property.Models.Configuration propertyConfiguration, ReadOnlyCollection<string[]> filesCollection)
|
||||
{
|
||||
List<(FilePath, string)> results = [];
|
||||
@ -231,4 +159,73 @@ public class CopyDistinct
|
||||
return (distinctDirectories.ToArray(), results);
|
||||
}
|
||||
|
||||
private List<string> CopyDistinctFilesInDirectories(ILogger<Program>? logger, bool move, ReadOnlyCollection<string[]> filesCollection, bool anyLenFiles, bool moveBack)
|
||||
{
|
||||
List<string> results = [];
|
||||
ProgressBar progressBar;
|
||||
string[] distinctDirectories;
|
||||
ConsoleKey? consoleKey = null;
|
||||
string message = nameof(CopyDistinct);
|
||||
List<(FilePath, string)> toDoCollection;
|
||||
int count = filesCollection.Select(l => l.Length).Sum();
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
if (moveBack)
|
||||
{
|
||||
if (!anyLenFiles)
|
||||
throw new NotSupportedException();
|
||||
(distinctDirectories, toDoCollection) = GetMoveBackToDoCollection(_PropertyConfiguration, filesCollection);
|
||||
}
|
||||
else
|
||||
{
|
||||
progressBar = new(count, message, options);
|
||||
string key = string.IsNullOrEmpty(_AppSettings.ResultDirectoryKey) ? _PropertyConfiguration.ResultAllInOne : _AppSettings.ResultDirectoryKey;
|
||||
string[] directories = _FileGroups[key];
|
||||
ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection = IDirectory.GetFilePathCollections(_Configuration.PropertyConfiguration, filesCollection);
|
||||
(distinctDirectories, toDoCollection) = IDirectory.GetToDoCollection(_PropertyConfiguration, _AppSettings.CopyDuplicates, _AppSettings.IfCanUseId, filePathsCollection, directories, () => progressBar.Tick());
|
||||
progressBar.Dispose();
|
||||
}
|
||||
foreach (string distinctDirectory in distinctDirectories)
|
||||
{
|
||||
if (!Directory.Exists(distinctDirectory))
|
||||
_ = Directory.CreateDirectory(distinctDirectory);
|
||||
}
|
||||
if (move)
|
||||
logger?.LogInformation($"Ready to Move {toDoCollection.Count} file(s)?");
|
||||
else if (!moveBack)
|
||||
logger?.LogInformation($"Ready to Copy {toDoCollection.Count} file(s)?");
|
||||
else
|
||||
logger?.LogInformation($"Ready to Move back {toDoCollection.Count} file(s)?");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
if (move)
|
||||
logger?.LogInformation("Press \"Y\" key to move file(s), \"N\" key to log file(s) or close console to not move files");
|
||||
else if (!moveBack)
|
||||
logger?.LogInformation("Press \"Y\" key to copy file(s), \"N\" key to log file(s) or close console to not copy files");
|
||||
else
|
||||
logger?.LogInformation("Press \"Y\" key to move back file(s), \"N\" key to log file(s) or close console to not move back files");
|
||||
consoleKey = System.Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||
break;
|
||||
}
|
||||
logger?.LogInformation(". . .");
|
||||
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
||||
{
|
||||
if (move || moveBack)
|
||||
logger?.LogInformation("Nothing moved!");
|
||||
else
|
||||
logger?.LogInformation("Nothing copied!");
|
||||
}
|
||||
else
|
||||
{
|
||||
progressBar = new(count, message, options);
|
||||
results.AddRange(IDirectory.CopyOrMove(toDoCollection, move, moveBack, () => progressBar.Tick()));
|
||||
progressBar.Dispose();
|
||||
if (move || moveBack)
|
||||
logger?.LogInformation("Done moving");
|
||||
else
|
||||
logger?.LogInformation("Done copying");
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
@ -34,15 +34,17 @@ public class Configuration
|
||||
}
|
||||
}
|
||||
|
||||
private static Models.Configuration Get(Configuration? configuration, Property.Models.Configuration propertyConfiguration)
|
||||
private static Models.Configuration Get(Configuration? configuration)
|
||||
{
|
||||
Models.Configuration result;
|
||||
if (configuration is null) throw new NullReferenceException(nameof(configuration));
|
||||
if (configuration.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.PersonBirthdayFormat is null) throw new NullReferenceException(nameof(configuration.PersonBirthdayFormat));
|
||||
result = new(propertyConfiguration,
|
||||
if (configuration.PropertyConfiguration is null) throw new NullReferenceException(nameof(configuration.PropertyConfiguration));
|
||||
result = new(
|
||||
configuration.IgnoreExtensions,
|
||||
configuration.PersonBirthdayFormat);
|
||||
configuration.PersonBirthdayFormat,
|
||||
configuration.PropertyConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -64,7 +66,7 @@ public class Configuration
|
||||
#pragma warning restore IL3050, IL2026
|
||||
}
|
||||
PreVerify(configurationRoot, configuration);
|
||||
result = Get(configuration, propertyConfiguration);
|
||||
result = Get(configuration);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,10 @@ public class Configuration
|
||||
public Property.Models.Configuration PropertyConfiguration => _PropertyConfiguration;
|
||||
|
||||
[JsonConstructor]
|
||||
public Configuration(Property.Models.Configuration propertyConfiguration,
|
||||
public Configuration(
|
||||
string[] ignoreExtensions,
|
||||
string personBirthdayFormat)
|
||||
string personBirthdayFormat,
|
||||
Property.Models.Configuration propertyConfiguration)
|
||||
{
|
||||
IgnoreExtensions = ignoreExtensions;
|
||||
PersonBirthdayFormat = personBirthdayFormat;
|
||||
|
@ -4,13 +4,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<UserSecretsId>8004d966-1a9e-4545-a220-83f32b6a13e9</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Date.Group</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -34,15 +34,15 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Phares.Shared;
|
||||
using System.Globalization;
|
||||
@ -57,11 +57,11 @@ public class DateGroup
|
||||
string aPropertySingletonDirectory = Path.Combine(aResultsFullGroupDirectory, "{}");
|
||||
if (!Directory.Exists(aPropertySingletonDirectory))
|
||||
_ = Directory.CreateDirectory(aPropertySingletonDirectory);
|
||||
(int t, Container.Models.Container[] containers) = Container.Models.Stateless.Methods.IContainer.GetContainers(propertyConfiguration, aPropertySingletonDirectory);
|
||||
(int t, Container[] containers) = Shared.Models.Stateless.Methods.IContainer.GetContainers(propertyConfiguration, aPropertySingletonDirectory);
|
||||
A_Property propertyLogic = GetPropertyLogic(reverse, aResultsFullGroupDirectory, aResultsFullGroupDirectory);
|
||||
if (propertyLogic.ExceptionsDirectories.Count != 0)
|
||||
throw new Exception();
|
||||
if (propertyConfiguration.PopulatePropertyId && (configuration.ByCreateDateShortcut || configuration.ByHash) && Property.Models.Stateless.IProperty.Any(containers))
|
||||
if (propertyConfiguration.PopulatePropertyId && (configuration.ByCreateDateShortcut || configuration.ByHash) && Shared.Models.Stateless.Methods.IProperty.Any(containers))
|
||||
{
|
||||
propertyLogic.SavePropertyParallelWork(ticks, metadata, t, containers);
|
||||
if (propertyLogic.ExceptionsDirectories.Count != 0)
|
||||
@ -96,6 +96,203 @@ public class DateGroup
|
||||
throw new Exception("Change configuration!");
|
||||
}
|
||||
|
||||
private static bool WriteAllText(string path, string contents, bool compareBeforeWrite)
|
||||
{
|
||||
bool result;
|
||||
string text;
|
||||
if (!compareBeforeWrite)
|
||||
result = true;
|
||||
else
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
text = string.Empty;
|
||||
else
|
||||
text = File.ReadAllText(path);
|
||||
result = text != contents;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
if (path.Contains("()"))
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("{}") && !path.EndsWith(".json"))
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("[]") && !path.EndsWith(".json"))
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("{}") && path.EndsWith(".json") && contents[0] == '{')
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("[]") && path.EndsWith(".json") && contents[0] == '[')
|
||||
File.WriteAllText(path, contents);
|
||||
else
|
||||
File.WriteAllText(path, contents);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)> GetMoveFileCollection(string destinationDirectory, string topDirectory, Item[] filteredItems)
|
||||
{
|
||||
List<(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)> results = [];
|
||||
char flag;
|
||||
string day;
|
||||
int season;
|
||||
string year;
|
||||
string month;
|
||||
string? check;
|
||||
string fileName;
|
||||
string? pathRoot;
|
||||
DateTime dateTime;
|
||||
string seasonName;
|
||||
string weekOfYear;
|
||||
bool? isWrongYear;
|
||||
string seasonValue;
|
||||
string directoryName;
|
||||
string topDirectoryName;
|
||||
List<DateTime> dateTimes;
|
||||
string[]? matches = null;
|
||||
string[] directorySegments;
|
||||
List<string> destinationCollection;
|
||||
List<string> directoryNames = [];
|
||||
List<string> topDirectorySegments = [];
|
||||
StringBuilder destinationDirectoryName = new();
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
for (int z = 1; z < 3; z++)
|
||||
{
|
||||
if (z == 1)
|
||||
{
|
||||
check = Path.Combine(destinationDirectory, ".");
|
||||
pathRoot = Path.GetPathRoot(destinationDirectory);
|
||||
}
|
||||
else if (z == 2)
|
||||
{
|
||||
check = Path.Combine(topDirectory, ".");
|
||||
pathRoot = Path.GetPathRoot(topDirectory);
|
||||
}
|
||||
else
|
||||
throw new Exception();
|
||||
if (string.IsNullOrEmpty(pathRoot))
|
||||
continue;
|
||||
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(' ');
|
||||
topDirectorySegments.AddRange(directorySegments);
|
||||
(_, matches) = Shared.Models.Stateless.Methods.IProperty.IsWrongYear(directorySegments, string.Empty);
|
||||
if (matches.Length != 0)
|
||||
break;
|
||||
}
|
||||
if (matches is not null && matches.Length != 0)
|
||||
break;
|
||||
}
|
||||
foreach (Item item in filteredItems)
|
||||
{
|
||||
directoryNames.Clear();
|
||||
destinationCollection = [];
|
||||
_ = destinationDirectoryName.Clear();
|
||||
if (item.Property is not null)
|
||||
dateTimes = item.Property.GetDateTimes();
|
||||
else
|
||||
dateTimes = [new(item.FilePath.LastWriteTicks)];
|
||||
if (item.Property is not null && item.Property.DateTimeOriginal is not null)
|
||||
dateTime = item.Property.DateTimeOriginal.Value;
|
||||
else if (item.Property is null)
|
||||
dateTime = new(item.FilePath.LastWriteTicks);
|
||||
else
|
||||
dateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
||||
day = dateTime.ToString("MM-dd");
|
||||
month = dateTime.ToString("MMMM");
|
||||
if (item.Property?.Id is null)
|
||||
{
|
||||
flag = '#';
|
||||
isWrongYear = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
(isWrongYear, _) = Shared.Models.Stateless.Methods.IProperty.IsWrongYear(item.FilePath, item.Property.DateTimeOriginal, dateTimes);
|
||||
if (isWrongYear is null)
|
||||
flag = '#';
|
||||
else if (isWrongYear.Value)
|
||||
flag = '~';
|
||||
else
|
||||
{
|
||||
if (item.Property.DateTimeOriginal is not null && dateTime.DayOfYear != item.Property.DateTimeOriginal.Value.DayOfYear && Math.Abs(new TimeSpan(dateTime.Ticks - item.Property.DateTimeOriginal.Value.Ticks).TotalHours) > 8)
|
||||
flag = '^';
|
||||
else
|
||||
flag = '=';
|
||||
}
|
||||
}
|
||||
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
||||
if ((from l in topDirectorySegments where l == "Christmas" select true).Any())
|
||||
seasonValue = string.Empty;
|
||||
else
|
||||
seasonValue = $".{season}";
|
||||
if (isWrongYear is null || !isWrongYear.Value)
|
||||
year = $"{flag}{dateTime:yyyy}{seasonValue}";
|
||||
else if (matches is null || matches.Length < 3)
|
||||
year = "----";
|
||||
else
|
||||
{
|
||||
if (matches[0][0] != '~')
|
||||
year = $"{flag}{matches[0].Split('.')[0]}{seasonValue}";
|
||||
else
|
||||
year = $"{flag}{matches[0][1..].Split('.')[0]}{seasonValue}";
|
||||
}
|
||||
topDirectoryName = Path.GetFileName(topDirectory);
|
||||
weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
if (_Configuration.ByHash)
|
||||
directoryNames.Add($"{year} {seasonName}");
|
||||
else if (_Configuration.BySeason && topDirectoryName.Length == 1 && topDirectoryName[0] == '_')
|
||||
directoryNames.Add($"{year} {seasonName}");
|
||||
else
|
||||
{
|
||||
if (!_Configuration.KeepFullPath)
|
||||
{
|
||||
if (topDirectoryName.Length > 1)
|
||||
_ = destinationDirectoryName.Append(topDirectoryName);
|
||||
if (_Configuration.BySeason)
|
||||
directoryNames.AddRange(new string[] { $"{destinationDirectoryName} {year} {seasonName}" });
|
||||
else if (_Configuration.ByDay)
|
||||
directoryNames.AddRange(new string[] { $"{destinationDirectoryName} {year}", $"{weekOfYear}) {year}-{day}" });
|
||||
else if (_Configuration.ByWeek)
|
||||
directoryNames.AddRange(new string[] { $"{destinationDirectoryName} {year}", $"{weekOfYear}) {year} {month}" });
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (string sourceDirectoryNameSegment in topDirectorySegments)
|
||||
{
|
||||
if (matches is not null && matches.Contains(sourceDirectoryNameSegment))
|
||||
_ = destinationDirectoryName.Append(year);
|
||||
else
|
||||
_ = destinationDirectoryName.Append(sourceDirectoryNameSegment);
|
||||
}
|
||||
if (_Configuration.BySeason)
|
||||
directoryNames.Add($"{year} {seasonName}");
|
||||
else if (_Configuration.ByDay)
|
||||
directoryNames.Add($"{weekOfYear}) {year} {day}");
|
||||
else if (_Configuration.ByWeek)
|
||||
directoryNames.Add($"{weekOfYear}) {month} {year}");
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
if (!_Configuration.ByHash || item.Property?.Id is null)
|
||||
fileName = item.FilePath.Name;
|
||||
else
|
||||
fileName = $"{item.Property.Id.Value}{item.FilePath.ExtensionLowered}";
|
||||
destinationCollection.Add(destinationDirectory);
|
||||
destinationCollection.AddRange(directoryNames);
|
||||
destinationCollection.Add(fileName);
|
||||
if (item.Property is null)
|
||||
results.Add(new(item, item.FilePath.LastWriteTicks, dateTime.Ticks, destinationCollection.ToArray()));
|
||||
else
|
||||
results.Add(new(item, item.Property.LastWriteTime.Ticks, dateTime.Ticks, destinationCollection.ToArray()));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private A_Property GetPropertyLogic(bool reverse, string outputExtension, string aResultsFullGroupDirectory)
|
||||
{
|
||||
A_Property result;
|
||||
@ -105,67 +302,57 @@ public class DateGroup
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void CreateDateShortcut(Property.Models.Configuration configuration, Container.Models.Container[] containers)
|
||||
private static Item[] GetFilterItems(Container container)
|
||||
{
|
||||
string path;
|
||||
string fileName;
|
||||
string directory;
|
||||
DateTime dateTime;
|
||||
int selectedTotal;
|
||||
const int minimum = 3;
|
||||
List<DateTime> dateTimes;
|
||||
List<Item> selectedItems;
|
||||
const int maximumHours = 24;
|
||||
string? relativePathDirectory;
|
||||
WindowsShortcut windowsShortcut;
|
||||
TimeSpan threeStandardDeviationHigh;
|
||||
string aPropertyContentDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "()");
|
||||
foreach (Container.Models.Container container in containers)
|
||||
List<Item> results = [];
|
||||
foreach (Item item in container.Items)
|
||||
{
|
||||
if (item.FilePath is not null)
|
||||
results.Add(item);
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
private (Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)[] GetFileMoveCollectionAll(Property.Models.Configuration configuration, string destinationRoot, Container[] containers)
|
||||
{
|
||||
(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)[] results;
|
||||
Item[] filteredItems;
|
||||
string? topDirectory;
|
||||
string? checkDirectory;
|
||||
string destinationDirectory;
|
||||
List<(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)> fileMoveCollection = [];
|
||||
List<(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)> fileMoveCollectionDirectory;
|
||||
foreach (Container container in containers)
|
||||
{
|
||||
if (container.Items.Count == 0)
|
||||
continue;
|
||||
selectedTotal = 0;
|
||||
threeStandardDeviationHigh = Property.Models.Stateless.IProperty.GetThreeStandardDeviationHigh(minimum, container);
|
||||
if (threeStandardDeviationHigh.TotalHours > maximumHours)
|
||||
threeStandardDeviationHigh = new(maximumHours, 0, 0);
|
||||
for (int i = 0; i < container.Items.Count; i++)
|
||||
{
|
||||
(i, dateTimes, selectedItems) = Property.Models.Stateless.IProperty.Get(container, threeStandardDeviationHigh, i);
|
||||
selectedTotal += selectedItems.Count;
|
||||
foreach (Item item in selectedItems)
|
||||
{
|
||||
if (item.ExifDirectory is null)
|
||||
continue;
|
||||
relativePathDirectory = Path.GetDirectoryName(item.RelativePath);
|
||||
if (string.IsNullOrEmpty(relativePathDirectory))
|
||||
continue;
|
||||
if (item.ExifDirectory is null)
|
||||
dateTime = new(item.FilePath.LastWriteTicks);
|
||||
else if (item.ExifDirectory is not null && item.ExifDirectory.DateTimeOriginal is not null)
|
||||
dateTime = item.ExifDirectory.DateTimeOriginal.Value;
|
||||
if (!_Configuration.KeepFullPath)
|
||||
destinationDirectory = destinationRoot;
|
||||
else
|
||||
dateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.ExifDirectory);
|
||||
path = Path.GetFullPath($"{configuration.RootDirectory}{item.RelativePath[..^5]}");
|
||||
directory = Path.Combine($"{aPropertyContentDirectory}{relativePathDirectory}", $"{dateTimes.Min():yyyy-MM-dd_HH-mm-ss}---{dateTimes.Max():yyyy-MM-dd_HH-mm-ss}");
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
fileName = Path.Combine(directory, $"{Path.GetFileName(item.RelativePath[..^5])}.lnk");
|
||||
if (File.Exists(fileName))
|
||||
continue;
|
||||
windowsShortcut = new() { Path = path };
|
||||
windowsShortcut.Save(fileName);
|
||||
windowsShortcut.Dispose();
|
||||
if (!File.Exists(fileName))
|
||||
continue;
|
||||
File.SetLastWriteTime(fileName, dateTime);
|
||||
destinationDirectory = string.Concat(destinationRoot, container.SourceDirectory[configuration.RootDirectory.Length..]);
|
||||
checkDirectory = Path.GetFullPath(container.SourceDirectory);
|
||||
for (int z = 0; z < int.MaxValue; z++)
|
||||
{
|
||||
if (checkDirectory == configuration.RootDirectory)
|
||||
break;
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (selectedTotal < container.Items.Count && selectedTotal < (from l in container.Items where l.Property is not null select true).Count())
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
continue;
|
||||
topDirectory = checkDirectory;
|
||||
filteredItems = GetFilterItems(container);
|
||||
if (filteredItems.Length == 0)
|
||||
continue;
|
||||
fileMoveCollectionDirectory = GetMoveFileCollection(destinationDirectory, topDirectory, filteredItems);
|
||||
fileMoveCollection.AddRange(fileMoveCollectionDirectory);
|
||||
}
|
||||
results = (from l in fileMoveCollection orderby l.MinimumDateTimeTicks descending, l.LastWriteTimeTicks descending select l).ToArray();
|
||||
return results;
|
||||
}
|
||||
|
||||
private void MoveFiles(Property.Models.Configuration configuration, string destinationRoot, Container.Models.Container[] containers)
|
||||
private void MoveFiles(Property.Models.Configuration configuration, string destinationRoot, Container[] containers)
|
||||
{
|
||||
string checkDirectory;
|
||||
bool hasDuplicate;
|
||||
@ -235,7 +422,7 @@ public class DateGroup
|
||||
{
|
||||
try
|
||||
{
|
||||
windowsShortcut = new() { Path = item.FilePath.DirectoryFullPath, Description = item.FilePath.Name };
|
||||
windowsShortcut = new() { Path = item.FilePath.DirectoryName, Description = item.FilePath.Name };
|
||||
windowsShortcut.Save(string.Concat(fullFileName, ".lnk"));
|
||||
windowsShortcut.Dispose();
|
||||
}
|
||||
@ -266,251 +453,64 @@ public class DateGroup
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(configuration.RootDirectory);
|
||||
}
|
||||
|
||||
private (Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)[] GetFileMoveCollectionAll(Property.Models.Configuration configuration, string destinationRoot, Container.Models.Container[] containers)
|
||||
private static void CreateDateShortcut(Property.Models.Configuration configuration, Container[] containers)
|
||||
{
|
||||
(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)[] results;
|
||||
Item[] filteredItems;
|
||||
string? topDirectory;
|
||||
string? checkDirectory;
|
||||
string destinationDirectory;
|
||||
List<(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)> fileMoveCollection = [];
|
||||
List<(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)> fileMoveCollectionDirectory;
|
||||
foreach (Container.Models.Container container in containers)
|
||||
string path;
|
||||
string fileName;
|
||||
string directory;
|
||||
DateTime dateTime;
|
||||
int selectedTotal;
|
||||
const int minimum = 3;
|
||||
List<DateTime> dateTimes;
|
||||
List<Item> selectedItems;
|
||||
const int maximumHours = 24;
|
||||
string? relativePathDirectory;
|
||||
WindowsShortcut windowsShortcut;
|
||||
TimeSpan threeStandardDeviationHigh;
|
||||
string aPropertyContentDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "()");
|
||||
foreach (Container container in containers)
|
||||
{
|
||||
if (container.Items.Count == 0)
|
||||
continue;
|
||||
if (!_Configuration.KeepFullPath)
|
||||
destinationDirectory = destinationRoot;
|
||||
else
|
||||
destinationDirectory = string.Concat(destinationRoot, container.SourceDirectory[configuration.RootDirectory.Length..]);
|
||||
checkDirectory = Path.GetFullPath(container.SourceDirectory);
|
||||
for (int z = 0; z < int.MaxValue; z++)
|
||||
selectedTotal = 0;
|
||||
threeStandardDeviationHigh = Shared.Models.Stateless.Methods.IProperty.GetThreeStandardDeviationHigh(minimum, container);
|
||||
if (threeStandardDeviationHigh.TotalHours > maximumHours)
|
||||
threeStandardDeviationHigh = new(maximumHours, 0, 0);
|
||||
for (int i = 0; i < container.Items.Count; i++)
|
||||
{
|
||||
if (checkDirectory == configuration.RootDirectory)
|
||||
break;
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
break;
|
||||
}
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
(i, dateTimes, selectedItems) = Shared.Models.Stateless.Methods.IProperty.Get(container, threeStandardDeviationHigh, i);
|
||||
selectedTotal += selectedItems.Count;
|
||||
foreach (Item item in selectedItems)
|
||||
{
|
||||
if (item.Property is null)
|
||||
continue;
|
||||
topDirectory = checkDirectory;
|
||||
filteredItems = GetFilterItems(container);
|
||||
if (filteredItems.Length == 0)
|
||||
relativePathDirectory = Path.GetDirectoryName(item.RelativePath);
|
||||
if (string.IsNullOrEmpty(relativePathDirectory))
|
||||
continue;
|
||||
fileMoveCollectionDirectory = GetMoveFileCollection(destinationDirectory, topDirectory, filteredItems);
|
||||
fileMoveCollection.AddRange(fileMoveCollectionDirectory);
|
||||
}
|
||||
results = (from l in fileMoveCollection orderby l.MinimumDateTimeTicks descending, l.LastWriteTimeTicks descending select l).ToArray();
|
||||
return results;
|
||||
}
|
||||
|
||||
private static Item[] GetFilterItems(Container.Models.Container container)
|
||||
{
|
||||
List<Item> results = [];
|
||||
foreach (Item item in container.Items)
|
||||
{
|
||||
if (item.FilePath is not null)
|
||||
results.Add(item);
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
private List<(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)> GetMoveFileCollection(string destinationDirectory, string topDirectory, Item[] filteredItems)
|
||||
{
|
||||
List<(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)> results = [];
|
||||
char flag;
|
||||
string day;
|
||||
int season;
|
||||
string year;
|
||||
string month;
|
||||
string? check;
|
||||
string fileName;
|
||||
string? pathRoot;
|
||||
DateTime dateTime;
|
||||
string seasonName;
|
||||
string weekOfYear;
|
||||
bool? isWrongYear;
|
||||
string seasonValue;
|
||||
string directoryName;
|
||||
string topDirectoryName;
|
||||
List<DateTime> dateTimes;
|
||||
string[]? matches = null;
|
||||
string[] directorySegments;
|
||||
List<string> destinationCollection;
|
||||
List<string> directoryNames = [];
|
||||
List<string> topDirectorySegments = [];
|
||||
StringBuilder destinationDirectoryName = new();
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
for (int z = 1; z < 3; z++)
|
||||
{
|
||||
if (z == 1)
|
||||
{
|
||||
check = Path.Combine(destinationDirectory, ".");
|
||||
pathRoot = Path.GetPathRoot(destinationDirectory);
|
||||
}
|
||||
else if (z == 2)
|
||||
{
|
||||
check = Path.Combine(topDirectory, ".");
|
||||
pathRoot = Path.GetPathRoot(topDirectory);
|
||||
}
|
||||
else
|
||||
throw new Exception();
|
||||
if (string.IsNullOrEmpty(pathRoot))
|
||||
continue;
|
||||
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(' ');
|
||||
topDirectorySegments.AddRange(directorySegments);
|
||||
(_, matches) = Shared.Models.Stateless.Methods.IProperty.IsWrongYear(directorySegments, string.Empty);
|
||||
if (matches.Length != 0)
|
||||
break;
|
||||
}
|
||||
if (matches is not null && matches.Length != 0)
|
||||
break;
|
||||
}
|
||||
foreach (Item item in filteredItems)
|
||||
{
|
||||
directoryNames.Clear();
|
||||
destinationCollection = [];
|
||||
_ = destinationDirectoryName.Clear();
|
||||
if (item.ExifDirectory is not null)
|
||||
dateTimes = item.ExifDirectory.GetDateTimes();
|
||||
else
|
||||
dateTimes = [new(item.FilePath.LastWriteTicks)];
|
||||
if (item.ExifDirectory is not null && item.ExifDirectory.DateTimeOriginal is not null)
|
||||
dateTime = item.ExifDirectory.DateTimeOriginal.Value;
|
||||
else if (item.ExifDirectory is null)
|
||||
if (item.Property is null)
|
||||
dateTime = new(item.FilePath.LastWriteTicks);
|
||||
else if (item.Property is not null && item.Property.DateTimeOriginal is not null)
|
||||
dateTime = item.Property.DateTimeOriginal.Value;
|
||||
else
|
||||
dateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.ExifDirectory);
|
||||
day = dateTime.ToString("MM-dd");
|
||||
month = dateTime.ToString("MMMM");
|
||||
if (item.ExifDirectory?.FilePath.Id is null)
|
||||
{
|
||||
flag = '#';
|
||||
isWrongYear = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
(isWrongYear, _) = Shared.Models.Stateless.Methods.IProperty.IsWrongYear(item.FilePath, item.ExifDirectory.DateTimeOriginal, dateTimes);
|
||||
if (isWrongYear is null)
|
||||
flag = '#';
|
||||
else if (isWrongYear.Value)
|
||||
flag = '~';
|
||||
else
|
||||
{
|
||||
if (item.ExifDirectory.DateTimeOriginal is not null && dateTime.DayOfYear != item.ExifDirectory.DateTimeOriginal.Value.DayOfYear && Math.Abs(new TimeSpan(dateTime.Ticks - item.ExifDirectory.DateTimeOriginal.Value.Ticks).TotalHours) > 8)
|
||||
flag = '^';
|
||||
else
|
||||
flag = '=';
|
||||
dateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
||||
path = Path.GetFullPath($"{configuration.RootDirectory}{item.RelativePath[..^5]}");
|
||||
directory = Path.Combine($"{aPropertyContentDirectory}{relativePathDirectory}", $"{dateTimes.Min():yyyy-MM-dd_HH-mm-ss}---{dateTimes.Max():yyyy-MM-dd_HH-mm-ss}");
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
fileName = Path.Combine(directory, $"{Path.GetFileName(item.RelativePath[..^5])}.lnk");
|
||||
if (File.Exists(fileName))
|
||||
continue;
|
||||
windowsShortcut = new() { Path = path };
|
||||
windowsShortcut.Save(fileName);
|
||||
windowsShortcut.Dispose();
|
||||
if (!File.Exists(fileName))
|
||||
continue;
|
||||
File.SetLastWriteTime(fileName, dateTime);
|
||||
}
|
||||
}
|
||||
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
||||
if ((from l in topDirectorySegments where l == "Christmas" select true).Any())
|
||||
seasonValue = string.Empty;
|
||||
else
|
||||
seasonValue = $".{season}";
|
||||
if (isWrongYear is null || !isWrongYear.Value)
|
||||
year = $"{flag}{dateTime:yyyy}{seasonValue}";
|
||||
else if (matches is null || matches.Length < 3)
|
||||
year = "----";
|
||||
else
|
||||
{
|
||||
if (matches[0][0] != '~')
|
||||
year = $"{flag}{matches[0].Split('.')[0]}{seasonValue}";
|
||||
else
|
||||
year = $"{flag}{matches[0][1..].Split('.')[0]}{seasonValue}";
|
||||
if (selectedTotal < container.Items.Count && selectedTotal < (from l in container.Items where l.Property is not null select true).Count())
|
||||
continue;
|
||||
}
|
||||
topDirectoryName = Path.GetFileName(topDirectory);
|
||||
weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
if (_Configuration.ByHash)
|
||||
directoryNames.Add($"{year} {seasonName}");
|
||||
else if (_Configuration.BySeason && topDirectoryName.Length == 1 && topDirectoryName[0] == '_')
|
||||
directoryNames.Add($"{year} {seasonName}");
|
||||
else
|
||||
{
|
||||
if (!_Configuration.KeepFullPath)
|
||||
{
|
||||
if (topDirectoryName.Length > 1)
|
||||
_ = destinationDirectoryName.Append(topDirectoryName);
|
||||
if (_Configuration.BySeason)
|
||||
directoryNames.AddRange([$"{destinationDirectoryName} {year} {seasonName}"]);
|
||||
else if (_Configuration.ByDay)
|
||||
directoryNames.AddRange([$"{destinationDirectoryName} {year}", $"{weekOfYear}) {year}-{day}"]);
|
||||
else if (_Configuration.ByWeek)
|
||||
directoryNames.AddRange([$"{destinationDirectoryName} {year}", $"{weekOfYear}) {year} {month}"]);
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (string sourceDirectoryNameSegment in topDirectorySegments)
|
||||
{
|
||||
if (matches is not null && matches.Contains(sourceDirectoryNameSegment))
|
||||
_ = destinationDirectoryName.Append(year);
|
||||
else
|
||||
_ = destinationDirectoryName.Append(sourceDirectoryNameSegment);
|
||||
}
|
||||
if (_Configuration.BySeason)
|
||||
directoryNames.Add($"{year} {seasonName}");
|
||||
else if (_Configuration.ByDay)
|
||||
directoryNames.Add($"{weekOfYear}) {year} {day}");
|
||||
else if (_Configuration.ByWeek)
|
||||
directoryNames.Add($"{weekOfYear}) {month} {year}");
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
if (!_Configuration.ByHash || item.ExifDirectory?.FilePath.Id is null)
|
||||
fileName = item.FilePath.Name;
|
||||
else
|
||||
fileName = $"{item.ExifDirectory.FilePath.Id.Value}{item.FilePath.ExtensionLowered}";
|
||||
destinationCollection.Add(destinationDirectory);
|
||||
destinationCollection.AddRange(directoryNames);
|
||||
destinationCollection.Add(fileName);
|
||||
if (item.ExifDirectory is null)
|
||||
results.Add(new(item, item.FilePath.LastWriteTicks, dateTime.Ticks, destinationCollection.ToArray()));
|
||||
else
|
||||
results.Add(new(item, item.ExifDirectory.LastWriteTime.Ticks, dateTime.Ticks, destinationCollection.ToArray()));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static bool WriteAllText(string path, string contents, bool compareBeforeWrite)
|
||||
{
|
||||
bool result;
|
||||
string text;
|
||||
if (!compareBeforeWrite)
|
||||
result = true;
|
||||
else
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
text = string.Empty;
|
||||
else
|
||||
text = File.ReadAllText(path);
|
||||
result = text != contents;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
if (path.Contains("()"))
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("{}") && !path.EndsWith(".json"))
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("[]") && !path.EndsWith(".json"))
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("{}") && path.EndsWith(".json") && contents[0] == '{')
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("[]") && path.EndsWith(".json") && contents[0] == '[')
|
||||
File.WriteAllText(path, contents);
|
||||
else
|
||||
File.WriteAllText(path, contents);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -4,13 +4,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<UserSecretsId>0589ecff-b296-48be-a3f7-7bf27f453975</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Delete.By.Distinct</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -34,14 +34,14 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
|
@ -4,13 +4,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<UserSecretsId>ead2e5ee-5f40-4151-bdb6-31d630d94f28</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Delete.By.Relative</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -34,14 +34,14 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Distance</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -36,7 +36,7 @@
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FaceRecognitionDotNet\FaceRecognitionDotNet.csproj" />
|
||||
|
@ -21,7 +21,7 @@ public class DistanceLimits : IDistanceLimits
|
||||
int faceDistancePermyriad,
|
||||
int[] rangeDaysDeltaTolerance,
|
||||
float[] rangeDistanceTolerance,
|
||||
float[] rangeFaceAreaTolerance,
|
||||
float[] rangeFaceAreaPermyriadTolerance,
|
||||
float[] rangeFaceConfidence,
|
||||
int sortingMaximumPerFaceShouldBeHigh,
|
||||
int? useFiltersCounter = null)
|
||||
@ -33,7 +33,7 @@ public class DistanceLimits : IDistanceLimits
|
||||
{
|
||||
RangeDaysDeltaTolerance = rangeDaysDeltaTolerance[1];
|
||||
FaceConfidencePercent = faceConfidencePercent * rangeFaceConfidence[1];
|
||||
FaceAreaPermyriad = faceAreaPermyriad * rangeFaceAreaTolerance[1];
|
||||
FaceAreaPermyriad = faceAreaPermyriad * rangeFaceAreaPermyriadTolerance[1];
|
||||
FaceDistancePermyriad = faceDistancePermyriad * rangeDistanceTolerance[1];
|
||||
}
|
||||
else
|
||||
@ -41,7 +41,7 @@ public class DistanceLimits : IDistanceLimits
|
||||
RangeDaysDeltaTolerance = ((rangeDaysDeltaTolerance[2] - rangeDaysDeltaTolerance[0]) * 0.01 * useFiltersCounter.Value) + rangeDaysDeltaTolerance[1];
|
||||
FaceConfidencePercent = faceConfidencePercent * ((rangeFaceConfidence[2] - rangeFaceConfidence[0]) * 0.01 * useFiltersCounter.Value) + rangeFaceConfidence[1];
|
||||
FaceDistancePermyriad = faceDistancePermyriad * ((rangeDistanceTolerance[2] - rangeDistanceTolerance[0]) * 0.01 * useFiltersCounter.Value) + rangeDistanceTolerance[1];
|
||||
FaceAreaPermyriad = faceAreaPermyriad * ((rangeFaceAreaTolerance[2] - rangeFaceAreaTolerance[0]) * 0.01 * useFiltersCounter.Value) + rangeFaceAreaTolerance[1];
|
||||
FaceAreaPermyriad = faceAreaPermyriad * ((rangeFaceAreaPermyriadTolerance[2] - rangeFaceAreaPermyriadTolerance[0]) * 0.01 * useFiltersCounter.Value) + rangeFaceAreaPermyriadTolerance[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -358,7 +358,7 @@ public partial class E_Distance : IDistance
|
||||
}
|
||||
results.Add(keyValuePair.Key, new(keyValuePairs));
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
return new(results);
|
||||
}
|
||||
|
||||
public static List<LocationContainer> GetPreFilterLocationContainer(int maxDegreeOfParallelism, Configuration configuration, string focusDirectory, string focusModel, int? skipPersonWithMoreThen, long ticks, MapLogic mapLogic, long[] jLinkResolvedPersonKeys, ReadOnlyDictionary<int, ReadOnlyDictionary<int, LocationContainer>> mapped, List<LocationContainer> available)
|
||||
@ -400,7 +400,7 @@ public partial class E_Distance : IDistance
|
||||
}
|
||||
if (!string.IsNullOrEmpty(focusDirectory))
|
||||
{
|
||||
if (!locationContainer.FilePath.DirectoryFullPath.Contains(focusDirectory))
|
||||
if (!locationContainer.FilePath.DirectoryName.Contains(focusDirectory))
|
||||
continue;
|
||||
}
|
||||
json = Metadata.Models.Stateless.Methods.IMetadata.GetFaceEncoding(locationContainer.ExifDirectory);
|
||||
@ -426,10 +426,11 @@ public partial class E_Distance : IDistance
|
||||
continue;
|
||||
if (face.Mapping.MappingFromFilterPre.IsFocusRelativePath is not null && !face.Mapping.MappingFromFilterPre.IsFocusRelativePath.Value)
|
||||
continue;
|
||||
// if (!configuration.ReMap && face.Mapping.MappingFromPerson is not null)
|
||||
// continue;
|
||||
if (!configuration.ReMap && face.Mapping.MappingFromPerson is not null)
|
||||
continue;
|
||||
if (!configuration.ReMap && face.FaceEncoding is not null && face.FaceDistance?.Encoding is not null && face.FaceDistance.Encoding is FaceRecognitionDotNet.FaceEncoding)
|
||||
throw new NotSupportedException($"{face.FaceEncoding} should not be null!");
|
||||
// throw new NotSupportedException($"{face.FaceEncoding} should not be null!");
|
||||
continue;
|
||||
faces.Add(face);
|
||||
}
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
@ -509,7 +510,7 @@ public partial class E_Distance : IDistance
|
||||
faceDistanceContainer = new(face, faceDistance);
|
||||
collection.Add(faceDistanceContainer);
|
||||
}
|
||||
results = collection.AsReadOnly();
|
||||
results = new(collection.ToArray());
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -568,7 +569,7 @@ public partial class E_Distance : IDistance
|
||||
foreach (KeyValuePair<int, LocationContainer> keyValue in keyValuePair.Value)
|
||||
results.Add(keyValue.Value);
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
return new(results);
|
||||
}
|
||||
|
||||
public static ReadOnlyCollection<LocationContainer> GetMatrixLocationContainers(IDlibDotNet dlibDotNet, Configuration mapConfiguration, long ticks, MapLogic mapLogic, ReadOnlyDictionary<int, ReadOnlyDictionary<int, LocationContainer>> mappedWithEncoding, List<LocationContainer> preFiltered, DistanceLimits distanceLimits, List<LocationContainer> postFiltered)
|
||||
@ -624,7 +625,7 @@ public partial class E_Distance : IDistance
|
||||
results = ISortingContainer.Sort(results);
|
||||
else
|
||||
results = ISortingContainer.SortUsingDaysDelta(results);
|
||||
return results.AsReadOnly();
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<RelationContainer> GetRelationCollections(IDistanceLimits distanceLimits, int faceDistancePermyriad, int locationContainerDistanceTake, float distanceTolerance, List<Record> records)
|
||||
@ -672,7 +673,7 @@ public partial class E_Distance : IDistance
|
||||
mappedRelations = (from l in mappedRelations orderby l.DistancePermyriad select l).Take(locationContainerDistanceTake).ToList();
|
||||
results.Add(new(fileHolder, new(mappedRelations)));
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
return new(results);
|
||||
}
|
||||
|
||||
ReadOnlyCollection<RelationContainer> IDistance.GetRelationContainers(IDistanceLimits distanceLimits, int faceDistancePermyriad, int locationContainerDistanceTake, float locationContainerDistanceTolerance, ReadOnlyCollection<LocationContainer> locationContainers)
|
||||
|
@ -4,7 +4,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
@ -26,9 +26,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
|
@ -6,8 +6,10 @@ public class Program
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
private static void Main() =>
|
||||
// ApplicationConfiguration.Initialize();
|
||||
private static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new DragDropExplorer());
|
||||
}
|
||||
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
@ -26,9 +26,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -6,8 +6,10 @@ public class Program
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
private static void Main() =>
|
||||
// ApplicationConfiguration.Initialize();
|
||||
private static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new DragDropMove());
|
||||
}
|
||||
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<UserSecretsId>7b153e3d-672b-4f7a-888a-cb31645a2439</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
@ -27,14 +27,13 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FaceRecognitionDotNet\FaceRecognitionDotNet.csproj" />
|
||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||
<ProjectReference Include="..\Container\Container.csproj" />
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
<ProjectReference Include="..\Resize\Resize.csproj" />
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
|
@ -64,6 +64,63 @@ public partial class DragDropSearch : Form
|
||||
Controls.Add(_TextBox);
|
||||
}
|
||||
|
||||
private void Form1_Load(object? sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
AllowDrop = true;
|
||||
DragDrop += new DragEventHandler(Form1_DragDrop);
|
||||
DragEnter += new DragEventHandler(Form1_DragEnter);
|
||||
_TextBox.LostFocus += new EventHandler(TextBox_LostFocus);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_LostFocus(object? sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_TextBox.Text == "ps")
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void Form1_DragEnter(object? sender, DragEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (e.Data is not null && e.Data.GetDataPresent(DataFormats.FileDrop))
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
Container[] containers;
|
||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(_Configuration.PropertyConfiguration, nameof(A_Property), "{}");
|
||||
(_, containers) = IContainer.GetContainers(_Configuration.PropertyConfiguration, aPropertySingletonDirectory);
|
||||
List<Item> collection = Program.GetItemCollection(_Configuration, containers);
|
||||
foreach (Item item in collection)
|
||||
{
|
||||
if (item.Property?.Id is null)
|
||||
continue;
|
||||
if (_IdToItem.ContainsKey(item.Property.Id.Value))
|
||||
continue;
|
||||
_IdToItem.Add(item.Property.Id.Value, item);
|
||||
}
|
||||
}
|
||||
|
||||
public static string? GetFaceEncoding(string file)
|
||||
{
|
||||
string? result;
|
||||
@ -90,37 +147,6 @@ public partial class DragDropSearch : Form
|
||||
return result;
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
Container.Models.Container[] containers;
|
||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(_Configuration.PropertyConfiguration, nameof(A_Property), "{}");
|
||||
(_, containers) = View_by_Distance.Container.Models.Stateless.Methods.IContainer.GetContainers(_Configuration.PropertyConfiguration, aPropertySingletonDirectory);
|
||||
List<Item> collection = Program.GetItemCollection(_Configuration, containers);
|
||||
foreach (Item item in collection)
|
||||
{
|
||||
if (item.ExifDirectory?.FilePath.Id is null)
|
||||
continue;
|
||||
if (_IdToItem.ContainsKey(item.ExifDirectory.FilePath.Id.Value))
|
||||
continue;
|
||||
_IdToItem.Add(item.ExifDirectory.FilePath.Id.Value, item);
|
||||
}
|
||||
}
|
||||
|
||||
private void Form1_Load(object? sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
AllowDrop = true;
|
||||
DragDrop += new DragEventHandler(Form1_DragDrop);
|
||||
DragEnter += new DragEventHandler(Form1_DragEnter);
|
||||
_TextBox.LostFocus += new EventHandler(TextBox_LostFocus);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void GetDirectoriesOrDoDragDrop(string[] paths)
|
||||
{
|
||||
string name;
|
||||
@ -136,25 +162,12 @@ public partial class DragDropSearch : Form
|
||||
{
|
||||
Text = item.FilePath.Name;
|
||||
_TextBox.Text = item.FilePath.FullName;
|
||||
if (!string.IsNullOrEmpty(item.FilePath.DirectoryFullPath))
|
||||
_ = Process.Start("explorer.exe", string.Concat("\"", item.FilePath.DirectoryFullPath, "\""));
|
||||
if (!string.IsNullOrEmpty(item.FilePath.DirectoryName))
|
||||
_ = Process.Start("explorer.exe", string.Concat("\"", item.FilePath.DirectoryName, "\""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_LostFocus(object? sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_TextBox.Text == "ps")
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void Form1_DragDrop(object? sender, DragEventArgs e)
|
||||
{
|
||||
try
|
||||
@ -170,17 +183,4 @@ public partial class DragDropSearch : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void Form1_DragEnter(object? sender, DragEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (e.Data is not null && e.Data.GetDataPresent(DataFormats.FileDrop))
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -8,11 +8,13 @@ public class Program
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
private static void Main() =>
|
||||
// ApplicationConfiguration.Initialize();
|
||||
private static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new DragDropSearch());
|
||||
}
|
||||
|
||||
private static Item[] GetFilterItems(Models.Configuration configuration, Container.Models.Container container)
|
||||
private static Item[] GetFilterItems(Models.Configuration configuration, Container container)
|
||||
{
|
||||
List<Item> results = [];
|
||||
foreach (Item item in container.Items)
|
||||
@ -24,11 +26,11 @@ public class Program
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
public static List<Item> GetItemCollection(Models.Configuration configuration, Container.Models.Container[] containers)
|
||||
public static List<Item> GetItemCollection(Models.Configuration configuration, Container[] containers)
|
||||
{
|
||||
List<Item> results = [];
|
||||
Item[] filteredItems;
|
||||
foreach (Container.Models.Container container in containers)
|
||||
foreach (Container container in containers)
|
||||
{
|
||||
if (container.Items.Count == 0)
|
||||
continue;
|
||||
|
@ -4,7 +4,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<UserSecretsId>c64a15ed-0ba3-4378-8f80-0c19d0531747</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
@ -27,9 +27,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||
|
@ -6,8 +6,10 @@ public class Program
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
private static void Main() =>
|
||||
// ApplicationConfiguration.Initialize();
|
||||
private static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new DragDropSetPropertyItem());
|
||||
}
|
||||
|
||||
}
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Duplicate-Search</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -33,14 +33,14 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Phares.Shared;
|
||||
using ShellProgressBar;
|
||||
@ -30,7 +30,7 @@ public class DuplicateSearch
|
||||
else
|
||||
{
|
||||
Configuration.Verify(configuration, requireExist: false);
|
||||
Container.Models.Container[] containers = GetContainers(ticks, configuration);
|
||||
Container[] containers = GetContainers(ticks, configuration);
|
||||
string argZero = args.Count > 0 ? Path.GetFullPath(args[0]) : Path.GetFullPath(configuration.RootDirectory);
|
||||
bool argZeroIsConfigurationRootDirectory = configuration.RootDirectory == argZero;
|
||||
string destinationRoot = Property.Models.Stateless.IResult.GetResultsGroupDirectory(configuration, "Z) Moved");
|
||||
@ -61,144 +61,6 @@ public class DuplicateSearch
|
||||
File.WriteAllText(Path.Combine(alongSideDirectory, $"{directoryName}-{ticks}.json"), json);
|
||||
}
|
||||
|
||||
private static Container.Models.Container[] GetContainers(long ticks, Configuration configuration)
|
||||
{
|
||||
int f;
|
||||
Container.Models.Container[] containers;
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string message = $") Building Container(s) - {totalSeconds} total second(s)";
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
using (ProgressBar progressBar = new(1, message, options))
|
||||
{
|
||||
progressBar.Tick();
|
||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
||||
(f, containers) = Container.Models.Stateless.Methods.IContainer.GetContainers(configuration, aPropertySingletonDirectory);
|
||||
}
|
||||
return containers;
|
||||
}
|
||||
|
||||
private static List<int> GetPreloadIds(string destinationRoot)
|
||||
{
|
||||
List<int> results = [];
|
||||
string[] lines;
|
||||
string preloadDirectory = Path.Combine(destinationRoot, "Preload");
|
||||
if (!Directory.Exists(preloadDirectory))
|
||||
_ = Directory.CreateDirectory(preloadDirectory);
|
||||
string[] files = Directory.GetFiles(preloadDirectory, "*.lsv", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
lines = File.ReadAllLines(file);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (string.IsNullOrEmpty(line) || !int.TryParse(line, out int id) || id == 0)
|
||||
continue;
|
||||
results.Add(id);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static Dictionary<int, List<MappingFromItem?>> GetIdToCollection(string argZero, Configuration configuration, bool argZeroIsConfigurationRootDirectory, Container.Models.Container[] containers, string destinationRoot, List<int> preloadIds)
|
||||
{
|
||||
Dictionary<int, List<MappingFromItem?>> results = [];
|
||||
string directory;
|
||||
const int zero = 0;
|
||||
FileHolder resizedFileHolder;
|
||||
DateTime[] containerDateTimes;
|
||||
MappingFromItem? mappingFromItem;
|
||||
List<MappingFromItem?>? collection;
|
||||
ReadOnlyCollection<Item> validImageItems;
|
||||
const string duplicates = "-Duplicate(s)";
|
||||
if (containers.Length != 0)
|
||||
{
|
||||
foreach (int id in preloadIds)
|
||||
results.Add(id, [null]);
|
||||
}
|
||||
foreach (Container.Models.Container container in containers)
|
||||
{
|
||||
if (container.Items.Count == 0)
|
||||
continue;
|
||||
if (!argZeroIsConfigurationRootDirectory && !container.SourceDirectory.StartsWith(argZero))
|
||||
continue;
|
||||
validImageItems = Container.Models.Stateless.Methods.IContainer.GetValidImageItems(configuration, container);
|
||||
if (validImageItems.Count == 0)
|
||||
continue;
|
||||
containerDateTimes = Container.Models.Stateless.Methods.IContainer.GetContainerDateTimes(validImageItems);
|
||||
foreach (Item item in validImageItems)
|
||||
{
|
||||
if (item.ExifDirectory?.FilePath.Id is null)
|
||||
{
|
||||
if (int.TryParse(item.FilePath.NameWithoutExtension, out int id))
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
if (!results.TryGetValue(item.ExifDirectory.FilePath.Id.Value, out collection))
|
||||
results.Add(item.ExifDirectory.FilePath.Id.Value, []);
|
||||
if (collection is null && !results.TryGetValue(item.ExifDirectory.FilePath.Id.Value, out collection))
|
||||
continue;
|
||||
if (collection.Count == 0)
|
||||
directory = $"0{duplicates}";
|
||||
else
|
||||
directory = $"{collection.Count + 1}{duplicates}";
|
||||
if (collection.Count == 1)
|
||||
{
|
||||
mappingFromItem = collection[zero];
|
||||
if (mappingFromItem is not null)
|
||||
{
|
||||
resizedFileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(mappingFromItem.ResizedFileHolder.FullName.Replace($"0{duplicates}", $"1{duplicates}"));
|
||||
collection[0] = new(mappingFromItem.ContainerDateTimes, item.Property.DateTimeDigitized, item.Property.DateTimeOriginal, mappingFromItem.Id, mappingFromItem.IsArchive, mappingFromItem.FilePath, mappingFromItem.IsWrongYear, item.Property.Keywords ?? [], mappingFromItem.MinimumDateTime, item.Property.Model, mappingFromItem.RelativePath, resizedFileHolder);
|
||||
}
|
||||
}
|
||||
resizedFileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(string.Concat(Path.Combine(destinationRoot, directory), item.RelativePath));
|
||||
mappingFromItem = Shared.Models.Stateless.Methods.IMappingFromItem.GetMappingFromItem(containerDateTimes, item, resizedFileHolder);
|
||||
collection.Add(mappingFromItem);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void QuestionMove(long ticks, ILogger<Program>? logger, string destinationRoot, Dictionary<int, List<MappingFromItem?>> idToCollection, int duplicates)
|
||||
{
|
||||
int[] ids = (from l in idToCollection orderby l.Key where l.Value.Any(m => m is not null) select l.Key).ToArray();
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(destinationRoot, $"{ticks}-id(s).lsv"), string.Join(Environment.NewLine, ids), updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
string json = JsonSerializer.Serialize(idToCollection, new JsonSerializerOptions { WriteIndented = true });
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(destinationRoot, $"{ticks}.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
logger?.LogInformation($"Found {duplicates} duplicate file(s)");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
logger?.LogInformation("Press \"Y\" key to continue or close console to leave them moved");
|
||||
if (System.Console.ReadKey().Key != ConsoleKey.Y)
|
||||
continue;
|
||||
logger?.LogInformation(". . .");
|
||||
List<(FilePath FilePath, string Destination)> collection = GetCollectionAndCreateDirectories(idToCollection);
|
||||
Move(logger, ticks, destinationRoot, collection);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<(FilePath FilePath, string Destination)> GetCollectionAndCreateDirectories(Dictionary<int, List<MappingFromItem?>> idToCollection)
|
||||
{
|
||||
List<(FilePath FilePath, string Destination)> results = [];
|
||||
List<string> collection = [];
|
||||
foreach (KeyValuePair<int, List<MappingFromItem?>> keyValuePair in idToCollection)
|
||||
{
|
||||
foreach (MappingFromItem? mappingFromItem in keyValuePair.Value)
|
||||
{
|
||||
if (mappingFromItem?.ResizedFileHolder.DirectoryFullPath is null)
|
||||
continue;
|
||||
if (mappingFromItem.ResizedFileHolder.Exists)
|
||||
continue;
|
||||
collection.Add(mappingFromItem.ResizedFileHolder.DirectoryFullPath);
|
||||
results.Add(new(mappingFromItem.FilePath, mappingFromItem.ResizedFileHolder.FullName));
|
||||
}
|
||||
}
|
||||
foreach (string directory in collection.Distinct())
|
||||
{
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void Move(ILogger<Program>? logger, long ticks, string destinationRoot, List<(FilePath FilePath, string Destination)> collection)
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
@ -245,4 +107,142 @@ public class DuplicateSearch
|
||||
logger?.LogInformation(". . .");
|
||||
}
|
||||
|
||||
private static void QuestionMove(long ticks, ILogger<Program>? logger, string destinationRoot, Dictionary<int, List<MappingFromItem?>> idToCollection, int duplicates)
|
||||
{
|
||||
int[] ids = (from l in idToCollection orderby l.Key where l.Value.Any(m => m is not null) select l.Key).ToArray();
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(destinationRoot, $"{ticks}-id(s).lsv"), string.Join(Environment.NewLine, ids), updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
string json = JsonSerializer.Serialize(idToCollection, new JsonSerializerOptions { WriteIndented = true });
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(destinationRoot, $"{ticks}.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
logger?.LogInformation($"Found {duplicates} duplicate file(s)");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
logger?.LogInformation("Press \"Y\" key to continue or close console to leave them moved");
|
||||
if (System.Console.ReadKey().Key != ConsoleKey.Y)
|
||||
continue;
|
||||
logger?.LogInformation(". . .");
|
||||
List<(FilePath FilePath, string Destination)> collection = GetCollectionAndCreateDirectories(idToCollection);
|
||||
Move(logger, ticks, destinationRoot, collection);
|
||||
}
|
||||
}
|
||||
|
||||
private static Container[] GetContainers(long ticks, Configuration configuration)
|
||||
{
|
||||
int f;
|
||||
Container[] containers;
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string message = $") Building Container(s) - {totalSeconds} total second(s)";
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
using (ProgressBar progressBar = new(1, message, options))
|
||||
{
|
||||
progressBar.Tick();
|
||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
||||
(f, containers) = Shared.Models.Stateless.Methods.IContainer.GetContainers(configuration, aPropertySingletonDirectory);
|
||||
}
|
||||
return containers;
|
||||
}
|
||||
|
||||
private static Dictionary<int, List<MappingFromItem?>> GetIdToCollection(string argZero, Configuration configuration, bool argZeroIsConfigurationRootDirectory, Container[] containers, string destinationRoot, List<int> preloadIds)
|
||||
{
|
||||
Dictionary<int, List<MappingFromItem?>> results = [];
|
||||
string directory;
|
||||
const int zero = 0;
|
||||
FileHolder resizedFileHolder;
|
||||
DateTime[] containerDateTimes;
|
||||
MappingFromItem? mappingFromItem;
|
||||
List<MappingFromItem?>? collection;
|
||||
ReadOnlyCollection<Item> validImageItems;
|
||||
const string duplicates = "-Duplicate(s)";
|
||||
if (containers.Length != 0)
|
||||
{
|
||||
foreach (int id in preloadIds)
|
||||
results.Add(id, [null]);
|
||||
}
|
||||
foreach (Container container in containers)
|
||||
{
|
||||
if (container.Items.Count == 0)
|
||||
continue;
|
||||
if (!argZeroIsConfigurationRootDirectory && !container.SourceDirectory.StartsWith(argZero))
|
||||
continue;
|
||||
validImageItems = Shared.Models.Stateless.Methods.IContainer.GetValidImageItems(configuration, container);
|
||||
if (validImageItems.Count == 0)
|
||||
continue;
|
||||
containerDateTimes = Shared.Models.Stateless.Methods.IContainer.GetContainerDateTimes(validImageItems);
|
||||
foreach (Item item in validImageItems)
|
||||
{
|
||||
if (item.Property?.Id is null)
|
||||
{
|
||||
if (int.TryParse(item.FilePath.NameWithoutExtension, out int id))
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
if (!results.TryGetValue(item.Property.Id.Value, out collection))
|
||||
results.Add(item.Property.Id.Value, []);
|
||||
if (collection is null && !results.TryGetValue(item.Property.Id.Value, out collection))
|
||||
continue;
|
||||
if (collection.Count == 0)
|
||||
directory = $"0{duplicates}";
|
||||
else
|
||||
directory = $"{collection.Count + 1}{duplicates}";
|
||||
if (collection.Count == 1)
|
||||
{
|
||||
mappingFromItem = collection[zero];
|
||||
if (mappingFromItem is not null)
|
||||
{
|
||||
resizedFileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(mappingFromItem.ResizedFileHolder.FullName.Replace($"0{duplicates}", $"1{duplicates}"));
|
||||
collection[0] = new(mappingFromItem.ContainerDateTimes, item.Property.DateTimeDigitized, item.Property.DateTimeOriginal, mappingFromItem.Id, mappingFromItem.FilePath, mappingFromItem.IsWrongYear, item.Property.Keywords ?? [], mappingFromItem.MinimumDateTime, item.Property.Model, mappingFromItem.RelativePath, resizedFileHolder);
|
||||
}
|
||||
}
|
||||
resizedFileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(string.Concat(Path.Combine(destinationRoot, directory), item.RelativePath));
|
||||
mappingFromItem = Shared.Models.Stateless.Methods.IMappingFromItem.GetMappingFromItem(containerDateTimes, item, resizedFileHolder);
|
||||
collection.Add(mappingFromItem);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<(FilePath FilePath, string Destination)> GetCollectionAndCreateDirectories(Dictionary<int, List<MappingFromItem?>> idToCollection)
|
||||
{
|
||||
List<(FilePath FilePath, string Destination)> results = [];
|
||||
List<string> collection = [];
|
||||
foreach (KeyValuePair<int, List<MappingFromItem?>> keyValuePair in idToCollection)
|
||||
{
|
||||
foreach (MappingFromItem? mappingFromItem in keyValuePair.Value)
|
||||
{
|
||||
if (mappingFromItem?.ResizedFileHolder.DirectoryName is null)
|
||||
continue;
|
||||
if (mappingFromItem.ResizedFileHolder.Exists)
|
||||
continue;
|
||||
collection.Add(mappingFromItem.ResizedFileHolder.DirectoryName);
|
||||
results.Add(new(mappingFromItem.FilePath, mappingFromItem.ResizedFileHolder.FullName));
|
||||
}
|
||||
}
|
||||
foreach (string directory in collection.Distinct())
|
||||
{
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<int> GetPreloadIds(string destinationRoot)
|
||||
{
|
||||
List<int> results = [];
|
||||
string[] lines;
|
||||
string preloadDirectory = Path.Combine(destinationRoot, "Preload");
|
||||
if (!Directory.Exists(preloadDirectory))
|
||||
_ = Directory.CreateDirectory(preloadDirectory);
|
||||
string[] files = Directory.GetFiles(preloadDirectory, "*.lsv", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
lines = File.ReadAllLines(file);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (string.IsNullOrEmpty(line) || !int.TryParse(line, out int id) || id == 0)
|
||||
continue;
|
||||
results.Add(id);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Face</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -33,7 +33,7 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FaceRecognitionDotNet\FaceRecognitionDotNet.csproj" />
|
||||
|
@ -42,12 +42,11 @@ public class D_Face : IFaceD
|
||||
private readonly int _FaceDistanceHiddenImageFactor;
|
||||
private readonly EncoderParameters _EncoderParameters;
|
||||
private readonly ImageCodecInfo _HiddenImageCodecInfo;
|
||||
private readonly Dictionary<string, string[]> _FileGroups;
|
||||
private readonly bool _ForceFaceLastWriteTimeToCreationTime;
|
||||
private readonly EncoderParameters _HiddenEncoderParameters;
|
||||
private readonly IPropertyConfiguration _PropertyConfiguration;
|
||||
private readonly JsonSerializerOptions _WriteIndentedAndWhenWritingNull;
|
||||
private readonly ReadOnlyDictionary<byte, ReadOnlyCollection<string>>[] _ResultContentFileGroups;
|
||||
private readonly ReadOnlyDictionary<byte, ReadOnlyCollection<string>>[] _ResultCollectionFileGroups;
|
||||
|
||||
public D_Face(
|
||||
string argZero,
|
||||
@ -70,6 +69,7 @@ public class D_Face : IFaceD
|
||||
float[] rectangleIntersectMinimums)
|
||||
{
|
||||
_ArgZero = argZero;
|
||||
_FileGroups = [];
|
||||
_ImageCodecInfo = imageCodecInfo;
|
||||
_EncoderParameters = encoderParameters;
|
||||
_FileNameExtension = filenameExtension;
|
||||
@ -84,8 +84,6 @@ public class D_Face : IFaceD
|
||||
_RectangleIntersectMinimum = rectangleIntersectMinimums.Min();
|
||||
_FaceDistanceHiddenImageFactor = faceDistanceHiddenImageFactor;
|
||||
_ForceFaceLastWriteTimeToCreationTime = forceFaceLastWriteTimeToCreationTime;
|
||||
_ResultContentFileGroups = [new(new Dictionary<byte, ReadOnlyCollection<string>>())];
|
||||
_ResultCollectionFileGroups = [new(new Dictionary<byte, ReadOnlyCollection<string>>())];
|
||||
(Model model, PredictorModel predictorModel, ModelParameter modelParameter) = GetModel(modelDirectory, modelName, predictorModelName);
|
||||
_Model = model;
|
||||
_PredictorModel = predictorModel;
|
||||
@ -95,73 +93,6 @@ public class D_Face : IFaceD
|
||||
_WriteIndentedAndWhenWritingNull = new JsonSerializerOptions { WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull };
|
||||
}
|
||||
|
||||
void IFaceD.ReSaveFace(ExifDirectory exifDirectory, FilePath filePath, Shared.Models.Face face, bool mappedFile)
|
||||
{
|
||||
FileInfo fileInfo = new(filePath.FullName);
|
||||
if (fileInfo.Exists)
|
||||
{
|
||||
string? json;
|
||||
short type = 2;
|
||||
string? model;
|
||||
string? maker;
|
||||
string checkFile = $"{filePath.FullName}.exif";
|
||||
const int artist = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagArtist;
|
||||
// const int author = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagWinAuthor; // 40093
|
||||
if (mappedFile)
|
||||
{
|
||||
json = IMetadata.GetOutputResolution(exifDirectory);
|
||||
if (json is not null && json.Contains(nameof(DateTime)))
|
||||
return;
|
||||
(maker, model) = Get(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
maker = IMetadata.GetMaker(exifDirectory);
|
||||
model = IMetadata.GetModel(exifDirectory);
|
||||
ExifDirectory? faceExifDirectory = IMetadata.GetExifDirectory(filePath);
|
||||
json = IMetadata.GetOutputResolution(faceExifDirectory);
|
||||
if (json is not null && json.Contains(nameof(DateTime)))
|
||||
return;
|
||||
}
|
||||
MetadataExtractor.GeoLocation? geoLocation = IMetadata.GeoLocation(exifDirectory);
|
||||
FaceFile faceFile = new(face.Mapping?.MappingFromLocation?.AreaPermyriad,
|
||||
face.Mapping?.MappingFromLocation?.ConfidencePercent,
|
||||
geoLocation?.ToDmsString(),
|
||||
face.DateTime,
|
||||
null,
|
||||
face.FaceParts,
|
||||
face.Location,
|
||||
maker,
|
||||
null,
|
||||
model,
|
||||
face.OutputResolution);
|
||||
string faceFileJson = JsonSerializer.Serialize(faceFile, FaceFileGenerationContext.Default.FaceFile);
|
||||
ConstructorInfo? constructorInfo = typeof(PropertyItem).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, null, [], null) ?? throw new Exception();
|
||||
PropertyItem? propertyItem = Property.Models.Stateless.IProperty.GetPropertyItem(constructorInfo, artist, type, faceFileJson);
|
||||
#pragma warning disable CA1416
|
||||
Bitmap bitmap = new(fileInfo.FullName);
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
bitmap.Save(checkFile);
|
||||
bitmap.Dispose();
|
||||
#pragma warning restore CA1416
|
||||
File.SetLastWriteTime(checkFile, fileInfo.LastWriteTime);
|
||||
File.Delete(fileInfo.FullName);
|
||||
File.Move(checkFile, fileInfo.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
private static (string?, string?) Get(string? json)
|
||||
{
|
||||
string? model;
|
||||
string? maker;
|
||||
FaceFile? faceFile = json is null ? null : JsonSerializer.Deserialize(json, FaceFileGenerationContext.Default.FaceFile);
|
||||
if (faceFile is null || faceFile.Location is null)
|
||||
(maker, model) = (null, null);
|
||||
else
|
||||
(maker, model) = (faceFile.Maker, faceFile.Model);
|
||||
return (maker, model);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
@ -170,112 +101,209 @@ public class D_Face : IFaceD
|
||||
|
||||
public void Update(string dResultsFullGroupDirectory)
|
||||
{
|
||||
ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePairs = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(_PropertyConfiguration, dResultsFullGroupDirectory, [_PropertyConfiguration.ResultCollection, _PropertyConfiguration.ResultContent]);
|
||||
foreach (KeyValuePair<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePair in keyValuePairs)
|
||||
_FileGroups.Clear();
|
||||
ReadOnlyDictionary<string, string[]> keyValuePairs = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(_PropertyConfiguration, dResultsFullGroupDirectory, [_PropertyConfiguration.ResultCollection, _PropertyConfiguration.ResultContent]);
|
||||
foreach (KeyValuePair<string, string[]> keyValuePair in keyValuePairs)
|
||||
_FileGroups.Add(keyValuePair.Key, keyValuePair.Value);
|
||||
}
|
||||
|
||||
private static (Model model, PredictorModel predictorModel, ModelParameter modelParameter) GetModel(string modelDirectory, string modelName, string predictorModelName)
|
||||
{
|
||||
if (keyValuePair.Key == _PropertyConfiguration.ResultContent)
|
||||
_ResultContentFileGroups[0] = keyValuePair.Value;
|
||||
else if (keyValuePair.Key == _PropertyConfiguration.ResultCollection)
|
||||
_ResultCollectionFileGroups[0] = keyValuePair.Value;
|
||||
else
|
||||
throw new Exception();
|
||||
(Model, PredictorModel, ModelParameter) result;
|
||||
Array array;
|
||||
Model? model = null;
|
||||
PredictorModel? predictorModel = null;
|
||||
array = Enum.GetValues(typeof(Model));
|
||||
foreach (Model check in array)
|
||||
{
|
||||
if (modelName.Contains(check.ToString()))
|
||||
{
|
||||
model = check;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (model is null)
|
||||
throw new Exception("Destination directory must have Model name!");
|
||||
model = model.Value;
|
||||
array = Enum.GetValues(typeof(PredictorModel));
|
||||
foreach (PredictorModel check in array)
|
||||
{
|
||||
if (predictorModelName.Contains(check.ToString()))
|
||||
{
|
||||
predictorModel = check;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (predictorModel is null)
|
||||
throw new Exception("Destination directory must have Predictor Model name!");
|
||||
predictorModel = predictorModel.Value;
|
||||
ModelParameter modelParameter = new()
|
||||
{
|
||||
CnnFaceDetectorModel = File.ReadAllBytes(Path.Combine(modelDirectory, "mmod_human_face_detector.dat")),
|
||||
FaceRecognitionModel = File.ReadAllBytes(Path.Combine(modelDirectory, "dlib_face_recognition_resnet_model_v1.dat")),
|
||||
PosePredictor5FaceLandmarksModel = File.ReadAllBytes(Path.Combine(modelDirectory, "shape_predictor_5_face_landmarks.dat")),
|
||||
PosePredictor68FaceLandmarksModel = File.ReadAllBytes(Path.Combine(modelDirectory, "shape_predictor_68_face_landmarks.dat"))
|
||||
};
|
||||
result = new(model.Value, predictorModel.Value, modelParameter);
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma warning disable CA1416
|
||||
|
||||
private void SaveFaces(FileHolder resizedFileHolder, ExifDirectory exifDirectory, List<(Shared.Models.Face, FileHolder?, string, bool)> collection)
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
Bitmap bitmap;
|
||||
short type = 2;
|
||||
FaceFile faceFile;
|
||||
Graphics graphics;
|
||||
Location? location;
|
||||
Rectangle rectangle;
|
||||
string faceFileJson;
|
||||
string faceEncodingJson;
|
||||
PropertyItem? propertyItem;
|
||||
string? maker = IMetadata.GetMaker(exifDirectory);
|
||||
string? model = IMetadata.GetModel(exifDirectory);
|
||||
using Bitmap source = new(resizedFileHolder.FullName);
|
||||
MetadataExtractor.GeoLocation? geoLocation = IMetadata.GeoLocation(exifDirectory);
|
||||
const int artist = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagArtist; // 315
|
||||
const int userComment = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagUserComment;
|
||||
foreach ((Shared.Models.Face face, FileHolder? fileHolder, string fileName, bool save) in collection)
|
||||
{
|
||||
if (!save)
|
||||
continue;
|
||||
if (fileHolder is null)
|
||||
continue;
|
||||
if (face.FaceEncoding is null || face?.Location is null || face?.OutputResolution is null)
|
||||
continue;
|
||||
if (_OverrideForFaceImages && fileHolder.Exists)
|
||||
{
|
||||
IFaceD dFace = this;
|
||||
FilePath filePath = FilePath.Get(_PropertyConfiguration, fileHolder, index: null);
|
||||
dFace.ReSaveFace(exifDirectory, filePath, face, mappedFile: false);
|
||||
continue;
|
||||
}
|
||||
location = Shared.Models.Stateless.Methods.ILocation.GetLocation(face.Location, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, source.Height, source.Width, collection.Count);
|
||||
if (location is null)
|
||||
continue;
|
||||
width = location.Right - location.Left;
|
||||
height = location.Bottom - location.Top;
|
||||
faceEncodingJson = JsonSerializer.Serialize(face.FaceEncoding);
|
||||
rectangle = new Rectangle(location.Left, location.Top, width, height);
|
||||
faceFile = new(face.Mapping?.MappingFromLocation?.AreaPermyriad,
|
||||
face.Mapping?.MappingFromLocation?.ConfidencePercent,
|
||||
face.DateTime,
|
||||
geoLocation?.ToDmsString(),
|
||||
face.FaceParts,
|
||||
face.Location,
|
||||
maker,
|
||||
model,
|
||||
face.OutputResolution);
|
||||
faceFileJson = JsonSerializer.Serialize(faceFile, FaceFileGenerationContext.Default.FaceFile);
|
||||
using (bitmap = new(width, height))
|
||||
{
|
||||
using (graphics = Graphics.FromImage(bitmap))
|
||||
graphics.DrawImage(source, new Rectangle(0, 0, width, height), rectangle, GraphicsUnit.Pixel);
|
||||
propertyItem = Property.Models.Stateless.IProperty.GetPropertyItem(_ConstructorInfo, artist, type, faceFileJson);
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
propertyItem = Property.Models.Stateless.IProperty.GetPropertyItem(_ConstructorInfo, userComment, type, faceEncodingJson);
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
bitmap.Save(fileHolder.FullName, _ImageCodecInfo, _EncoderParameters);
|
||||
}
|
||||
if (File.Exists(fileName))
|
||||
File.Delete(fileName);
|
||||
location = Shared.Models.Stateless.Methods.ILocation.GetLocation(_FaceDistanceHiddenImageFactor, face.Location, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, source.Height, source.Width, collection.Count);
|
||||
if (location is null)
|
||||
continue;
|
||||
width = location.Right - location.Left;
|
||||
height = location.Bottom - location.Top;
|
||||
rectangle = new Rectangle(location.Left, location.Top, width, height);
|
||||
using (bitmap = new(width, height))
|
||||
{
|
||||
using (graphics = Graphics.FromImage(bitmap))
|
||||
graphics.DrawImage(source, new Rectangle(0, 0, width, height), rectangle, GraphicsUnit.Pixel);
|
||||
bitmap.Save(fileName, _HiddenImageCodecInfo, _HiddenEncoderParameters);
|
||||
}
|
||||
File.SetAttributes(fileName, FileAttributes.Hidden);
|
||||
}
|
||||
}
|
||||
|
||||
public List<(Shared.Models.Face, FileHolder?, string, bool)> SaveFaces(FilePath filePath, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, MappingFromItem mappingFromItem, ExifDirectory exifDirectory, List<Shared.Models.Face> faces)
|
||||
private List<Shared.Models.Face> GetFaces(string outputResolution, string cResultsFullGroupDirectory, Shared.Models.Property property, MappingFromItem mappingFromItem, Dictionary<string, int[]> outputResolutionToResize, List<Location> locations)
|
||||
{
|
||||
List<(Shared.Models.Face, FileHolder?, string, bool Save)> results = [];
|
||||
bool save;
|
||||
FileInfo fileInfo;
|
||||
FileHolder fileHolder;
|
||||
string deterministicHashCodeKey;
|
||||
string fileName = mappingFromItem.FilePath.NameWithoutExtension;
|
||||
string[] changesFrom = [nameof(A_Property), nameof(B_Metadata), nameof(C_Resize)];
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
CombinedEnumAndIndex cei = Shared.Models.Stateless.Methods.IPath.GetCombinedEnumAndIndex(_PropertyConfiguration, filePath);
|
||||
string directory = _ResultContentFileGroups[0][cei.Enum][cei.Index];
|
||||
DirectoryInfo directoryInfo = new(Path.Combine(directory, fileName));
|
||||
MoveIf(fileName, cei, directory, directoryInfo);
|
||||
foreach (Shared.Models.Face face in faces)
|
||||
if (_PropertyConfiguration.NumberOfJitters is null)
|
||||
throw new NullReferenceException(nameof(_PropertyConfiguration.NumberOfJitters));
|
||||
if (_PropertyConfiguration.NumberOfTimesToUpsample is null)
|
||||
throw new NullReferenceException(nameof(_PropertyConfiguration.NumberOfTimesToUpsample));
|
||||
List<Shared.Models.Face> results = [];
|
||||
FaceRecognitionDotNet.Image? unknownImage;
|
||||
try
|
||||
{
|
||||
save = false;
|
||||
if (face.FaceEncoding is null || face.Location is null || face.OutputResolution is null)
|
||||
if (mappingFromItem.ResizedFileHolder.ExtensionLowered != ".tif")
|
||||
unknownImage = FaceRecognition.LoadImageFile(mappingFromItem.ResizedFileHolder.FullName);
|
||||
else
|
||||
{
|
||||
results.Add(new(face, null, string.Empty, save));
|
||||
continue;
|
||||
int outputQuality = 100;
|
||||
string extension = ".png";
|
||||
string file = Path.Combine(cResultsFullGroupDirectory, $"{mappingFromItem.ResizedFileHolder.Name}{extension}");
|
||||
(ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) = C_Resize.GetTuple(extension, outputQuality);
|
||||
#pragma warning disable CA1416
|
||||
System.Drawing.Image image = System.Drawing.Image.FromFile(mappingFromItem.ResizedFileHolder.FullName);
|
||||
image.Save(Path.Combine(cResultsFullGroupDirectory, $"{mappingFromItem.ResizedFileHolder.Name}{filenameExtension}"), imageCodecInfo, encoderParameters);
|
||||
image.Dispose();
|
||||
#pragma warning restore CA1416
|
||||
unknownImage = FaceRecognition.LoadImageFile(file);
|
||||
File.Delete(file);
|
||||
}
|
||||
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(filePath, face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution);
|
||||
fileInfo = new FileInfo(Path.Combine(directoryInfo.FullName, $"{deterministicHashCodeKey}{mappingFromItem.FilePath.ExtensionLowered}{_FileNameExtension}"));
|
||||
fileHolder = FileHolder.Get(fileInfo);
|
||||
if (!directoryInfo.Exists)
|
||||
save = true;
|
||||
else if (_OverrideForFaceImages)
|
||||
save = true;
|
||||
else if (!fileHolder.Exists)
|
||||
save = true;
|
||||
else if (_CheckDFaceAndUpWriteDates && dateTimes.Count > 0 && dateTimes.Max() > fileInfo.LastWriteTime)
|
||||
save = true;
|
||||
results.Add(new(face, fileHolder, Path.Combine(directoryInfo.FullName, $"{deterministicHashCodeKey}{mappingFromItem.FilePath.ExtensionLowered}{_HiddenFileNameExtension}"), save));
|
||||
}
|
||||
if (results.Any(l => l.Save))
|
||||
catch (Exception)
|
||||
{ unknownImage = null; }
|
||||
if (unknownImage is not null)
|
||||
{
|
||||
if (!directoryInfo.Exists)
|
||||
_ = Directory.CreateDirectory(directoryInfo.FullName);
|
||||
SaveFaces(mappingFromItem.ResizedFileHolder, exifDirectory, results);
|
||||
(int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation) = Resize.Models.Stateless.Methods.IResize.Get(outputResolution, outputResolutionToResize);
|
||||
List<(Location Location, FaceRecognitionDotNet.FaceEncoding? FaceEncoding, Dictionary<FacePart, FacePoint[]>? FaceParts)> collection;
|
||||
FaceRecognition faceRecognition = new(_PropertyConfiguration.NumberOfJitters.Value, _PropertyConfiguration.NumberOfTimesToUpsample.Value, _Model, _ModelParameter, _PredictorModel);
|
||||
collection = faceRecognition.GetCollection(unknownImage, locations, includeFaceEncoding: true, includeFaceParts: true);
|
||||
if (collection.Count == 0)
|
||||
results.Add(new(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, location: null));
|
||||
else
|
||||
{
|
||||
double[] rawEncoding;
|
||||
Shared.Models.Face face;
|
||||
Shared.Models.FaceEncoding convertedFaceEncoding;
|
||||
foreach ((Location location, FaceRecognitionDotNet.FaceEncoding? faceEncoding, Dictionary<FacePart, FacePoint[]>? faceParts) in collection)
|
||||
{
|
||||
face = new(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, location);
|
||||
if (faceEncoding is not null)
|
||||
{
|
||||
rawEncoding = faceEncoding.GetRawEncoding();
|
||||
convertedFaceEncoding = new(rawEncoding, faceEncoding.Size);
|
||||
face.SetFaceEncoding(convertedFaceEncoding);
|
||||
}
|
||||
if (faceParts is not null)
|
||||
face.SetFaceParts(faceParts);
|
||||
results.Add(face);
|
||||
}
|
||||
}
|
||||
unknownImage.Dispose();
|
||||
faceRecognition.Dispose();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void MoveIf(string fileName, CombinedEnumAndIndex cei, string directory, FileInfo fileInfo)
|
||||
{
|
||||
string[] segments = directory.Split(cei.Combined);
|
||||
string? checkDirectory = segments.Length == 1 ?
|
||||
Path.Combine(segments[0], $"{cei.Combined[2..]}") :
|
||||
segments.Length == 2 ?
|
||||
$"{segments[0]}{cei.Combined[2..]}{segments[1]}" :
|
||||
null;
|
||||
if (checkDirectory is not null && Directory.Exists(checkDirectory))
|
||||
{
|
||||
string checkFile = Path.Combine(checkDirectory, fileName);
|
||||
if (File.Exists(checkFile))
|
||||
{
|
||||
File.Move(checkFile, fileInfo.FullName);
|
||||
fileInfo.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1416
|
||||
|
||||
private static void MoveIf(string fileName, CombinedEnumAndIndex cei, string directory, DirectoryInfo directoryInfo)
|
||||
{
|
||||
string[] segments = directory.Split(cei.Combined);
|
||||
string? checkDirectory = segments.Length == 1 ?
|
||||
Path.Combine(segments[0], $"{cei.Combined[2..]}") :
|
||||
segments.Length == 2 ?
|
||||
$"{segments[0]}{cei.Combined[2..]}{segments[1]}" :
|
||||
null;
|
||||
if (checkDirectory is not null && Directory.Exists(checkDirectory))
|
||||
{
|
||||
string checkFile = Path.Combine(checkDirectory, fileName);
|
||||
if (Directory.Exists(checkFile))
|
||||
{
|
||||
Directory.Move(checkFile, directoryInfo.FullName);
|
||||
directoryInfo.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Shared.Models.Face> GetFaces(string outputResolution, string cResultsFullGroupDirectory, FilePath filePath, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, ExifDirectory exifDirectory, MappingFromItem mappingFromItem, Dictionary<string, int[]> outputResolutionToResize, List<MappingFromPhotoPrism>? mappingFromPhotoPrismCollection)
|
||||
public List<Shared.Models.Face> GetFaces(string outputResolution, string cResultsFullGroupDirectory, string dResultsFullGroupDirectory, FilePath filePath, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Shared.Models.Property property, MappingFromItem mappingFromItem, Dictionary<string, int[]> outputResolutionToResize, List<MappingFromPhotoPrism>? mappingFromPhotoPrismCollection)
|
||||
{
|
||||
List<Shared.Models.Face>? results;
|
||||
if (string.IsNullOrEmpty(dResultsFullGroupDirectory))
|
||||
throw new NullReferenceException(nameof(dResultsFullGroupDirectory));
|
||||
string? json;
|
||||
List<Location> locations;
|
||||
string[] changesFrom = [nameof(A_Property), nameof(B_Metadata), nameof(C_Resize)];
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
string fileName = $"{mappingFromItem.FilePath.NameWithoutExtension}{mappingFromItem.FilePath.ExtensionLowered}.json";
|
||||
CombinedEnumAndIndex cei = Shared.Models.Stateless.Methods.IPath.GetCombinedEnumAndIndex(_PropertyConfiguration, filePath);
|
||||
string directory = _ResultCollectionFileGroups[0][cei.Enum][cei.Index];
|
||||
FileInfo fileInfo = new(Path.Combine(directory, fileName));
|
||||
MoveIf(fileName, cei, directory, fileInfo);
|
||||
(_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration, filePath);
|
||||
FileInfo fileInfo = new(Path.Combine(_FileGroups[_PropertyConfiguration.ResultCollection][directoryIndex], $"{mappingFromItem.FilePath.NameWithoutExtension}{mappingFromItem.FilePath.ExtensionLowered}.json"));
|
||||
if (_ForceFaceLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete")))
|
||||
{
|
||||
File.Move(Path.ChangeExtension(fileInfo.FullName, ".delete"), fileInfo.FullName);
|
||||
@ -314,7 +342,7 @@ public class D_Face : IFaceD
|
||||
locations = Shared.Models.Stateless.Methods.ILocation.GetLocations(results, mappingFromPhotoPrismCollection, _RectangleIntersectMinimum);
|
||||
if (results is null || locations.Count > 0)
|
||||
{
|
||||
results = GetFaces(outputResolution, cResultsFullGroupDirectory, exifDirectory, mappingFromItem, outputResolutionToResize, locations);
|
||||
results = GetFaces(outputResolution, cResultsFullGroupDirectory, property, mappingFromItem, outputResolutionToResize, locations);
|
||||
if (results.Count == 0)
|
||||
File.Move(mappingFromItem.ResizedFileHolder.FullName, $"{mappingFromItem.ResizedFileHolder.FullName}.err");
|
||||
else
|
||||
@ -338,190 +366,113 @@ public class D_Face : IFaceD
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<Shared.Models.Face> GetFaces(string outputResolution, string cResultsFullGroupDirectory, ExifDirectory exifDirectory, MappingFromItem mappingFromItem, Dictionary<string, int[]> outputResolutionToResize, List<Location> locations)
|
||||
public List<(Shared.Models.Face, FileHolder?, string, bool)> SaveFaces(string f, string dResultsFullGroupDirectory, FilePath filePath, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, MappingFromItem mappingFromItem, ExifDirectory exifDirectory, List<Shared.Models.Face> faces)
|
||||
{
|
||||
if (_PropertyConfiguration.NumberOfJitters is null)
|
||||
throw new NullReferenceException(nameof(_PropertyConfiguration.NumberOfJitters));
|
||||
if (_PropertyConfiguration.NumberOfTimesToUpsample is null)
|
||||
throw new NullReferenceException(nameof(_PropertyConfiguration.NumberOfTimesToUpsample));
|
||||
List<Shared.Models.Face> results = [];
|
||||
FaceRecognitionDotNet.Image? unknownImage;
|
||||
try
|
||||
List<(Shared.Models.Face, FileHolder?, string, bool Save)> results = [];
|
||||
bool save;
|
||||
FileInfo fileInfo;
|
||||
FileHolder fileHolder;
|
||||
string deterministicHashCodeKey;
|
||||
string[] changesFrom = [nameof(A_Property), nameof(B_Metadata), nameof(C_Resize)];
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
(_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration, filePath);
|
||||
string directory = Path.Combine(_FileGroups[_PropertyConfiguration.ResultContent][directoryIndex], mappingFromItem.FilePath.NameWithoutExtension);
|
||||
bool directoryExists = Directory.Exists(directory);
|
||||
foreach (Shared.Models.Face face in faces)
|
||||
{
|
||||
if (mappingFromItem.ResizedFileHolder.ExtensionLowered != ".tif")
|
||||
unknownImage = FaceRecognition.LoadImageFile(mappingFromItem.ResizedFileHolder.FullName);
|
||||
else
|
||||
save = false;
|
||||
if (face.FaceEncoding is null || face.Location is null || face.OutputResolution is null)
|
||||
{
|
||||
int outputQuality = 100;
|
||||
string extension = ".png";
|
||||
string file = Path.Combine(cResultsFullGroupDirectory, $"{mappingFromItem.ResizedFileHolder.Name}{extension}");
|
||||
(ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) = C_Resize.GetTuple(extension, outputQuality);
|
||||
#pragma warning disable CA1416
|
||||
System.Drawing.Image image = System.Drawing.Image.FromFile(mappingFromItem.ResizedFileHolder.FullName);
|
||||
image.Save(Path.Combine(cResultsFullGroupDirectory, $"{mappingFromItem.ResizedFileHolder.Name}{filenameExtension}"), imageCodecInfo, encoderParameters);
|
||||
image.Dispose();
|
||||
#pragma warning restore CA1416
|
||||
unknownImage = FaceRecognition.LoadImageFile(file);
|
||||
File.Delete(file);
|
||||
results.Add(new(face, null, string.Empty, save));
|
||||
continue;
|
||||
}
|
||||
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(filePath, face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution);
|
||||
fileInfo = new FileInfo(Path.Combine(directory, $"{deterministicHashCodeKey}{mappingFromItem.FilePath.ExtensionLowered}{_FileNameExtension}"));
|
||||
fileHolder = FileHolder.Get(fileInfo);
|
||||
if (!directoryExists)
|
||||
save = true;
|
||||
else if (_OverrideForFaceImages)
|
||||
save = true;
|
||||
else if (!fileHolder.Exists)
|
||||
save = true;
|
||||
else if (_CheckDFaceAndUpWriteDates && dateTimes.Count > 0 && dateTimes.Max() > fileInfo.LastWriteTime)
|
||||
save = true;
|
||||
results.Add(new(face, fileHolder, Path.Combine(directory, $"{deterministicHashCodeKey}{mappingFromItem.FilePath.ExtensionLowered}{_HiddenFileNameExtension}"), save));
|
||||
}
|
||||
catch (Exception)
|
||||
{ unknownImage = null; }
|
||||
if (unknownImage is not null)
|
||||
if (results.Any(l => l.Save))
|
||||
{
|
||||
(int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation) = Resize.Models.Stateless.Methods.IResize.Get(outputResolution, outputResolutionToResize);
|
||||
List<(Location Location, FaceRecognitionDotNet.FaceEncoding? FaceEncoding, Dictionary<FacePart, FacePoint[]>? FaceParts)> collection;
|
||||
FaceRecognition faceRecognition = new(_PropertyConfiguration.NumberOfJitters.Value, _PropertyConfiguration.NumberOfTimesToUpsample.Value, _Model, _ModelParameter, _PredictorModel);
|
||||
collection = faceRecognition.GetCollection(unknownImage, locations, includeFaceEncoding: true, includeFaceParts: true);
|
||||
if (collection.Count == 0)
|
||||
results.Add(new(exifDirectory, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, location: null));
|
||||
else
|
||||
{
|
||||
double[] rawEncoding;
|
||||
Shared.Models.Face face;
|
||||
Shared.Models.FaceEncoding convertedFaceEncoding;
|
||||
foreach ((Location location, FaceRecognitionDotNet.FaceEncoding? faceEncoding, Dictionary<FacePart, FacePoint[]>? faceParts) in collection)
|
||||
{
|
||||
face = new(exifDirectory, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, location);
|
||||
if (faceEncoding is not null)
|
||||
{
|
||||
rawEncoding = faceEncoding.GetRawEncoding();
|
||||
convertedFaceEncoding = new(rawEncoding, faceEncoding.Size);
|
||||
face.SetFaceEncoding(convertedFaceEncoding);
|
||||
}
|
||||
if (faceParts is not null)
|
||||
face.SetFaceParts(faceParts);
|
||||
results.Add(face);
|
||||
}
|
||||
}
|
||||
unknownImage.Dispose();
|
||||
faceRecognition.Dispose();
|
||||
if (!directoryExists)
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
SaveFaces(mappingFromItem.ResizedFileHolder, exifDirectory, results);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static (Model model, PredictorModel predictorModel, ModelParameter modelParameter) GetModel(string modelDirectory, string modelName, string predictorModelName)
|
||||
#pragma warning disable CA1416
|
||||
|
||||
private static (string?, string?) Get(string? json)
|
||||
{
|
||||
(Model, PredictorModel, ModelParameter) result;
|
||||
Array array;
|
||||
Model? model = null;
|
||||
array = Enum.GetValues<Model>();
|
||||
PredictorModel? predictorModel = null;
|
||||
foreach (Model check in array)
|
||||
{
|
||||
if (modelName.Contains(check.ToString()))
|
||||
{
|
||||
model = check;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (model is null)
|
||||
throw new Exception("Destination directory must have Model name!");
|
||||
model = model.Value;
|
||||
array = Enum.GetValues<PredictorModel>();
|
||||
foreach (PredictorModel check in array)
|
||||
{
|
||||
if (predictorModelName.Contains(check.ToString()))
|
||||
{
|
||||
predictorModel = check;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (predictorModel is null)
|
||||
throw new Exception("Destination directory must have Predictor Model name!");
|
||||
predictorModel = predictorModel.Value;
|
||||
ModelParameter modelParameter = new()
|
||||
{
|
||||
CnnFaceDetectorModel = File.ReadAllBytes(Path.Combine(modelDirectory, "mmod_human_face_detector.dat")),
|
||||
FaceRecognitionModel = File.ReadAllBytes(Path.Combine(modelDirectory, "dlib_face_recognition_resnet_model_v1.dat")),
|
||||
PosePredictor5FaceLandmarksModel = File.ReadAllBytes(Path.Combine(modelDirectory, "shape_predictor_5_face_landmarks.dat")),
|
||||
PosePredictor68FaceLandmarksModel = File.ReadAllBytes(Path.Combine(modelDirectory, "shape_predictor_68_face_landmarks.dat"))
|
||||
};
|
||||
result = new(model.Value, predictorModel.Value, modelParameter);
|
||||
return result;
|
||||
string? model;
|
||||
string? maker;
|
||||
FaceFile? faceFile = json is null ? null : JsonSerializer.Deserialize(json, FaceFileGenerationContext.Default.FaceFile);
|
||||
if (faceFile is null || faceFile.Location is null)
|
||||
(maker, model) = (null, null);
|
||||
else
|
||||
(maker, model) = (faceFile.Maker, faceFile.Model);
|
||||
return (maker, model);
|
||||
}
|
||||
|
||||
private void SaveFaces(FileHolder resizedFileHolder, ExifDirectory exifDirectory, List<(Shared.Models.Face, FileHolder?, string, bool)> collection)
|
||||
void IFaceD.ReSaveFace(ExifDirectory exifDirectory, FilePath filePath, Shared.Models.Face face, bool mappedFile)
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
Bitmap bitmap;
|
||||
FileInfo fileInfo = new(filePath.FullName);
|
||||
if (fileInfo.Exists)
|
||||
{
|
||||
string? json;
|
||||
short type = 2;
|
||||
FaceFile faceFile;
|
||||
Graphics graphics;
|
||||
Location? location;
|
||||
Rectangle rectangle;
|
||||
string faceFileJson;
|
||||
string faceEncodingJson;
|
||||
PropertyItem? propertyItem;
|
||||
string? maker = IMetadata.GetMaker(exifDirectory);
|
||||
string? model = IMetadata.GetModel(exifDirectory);
|
||||
#pragma warning disable CA1416
|
||||
using Bitmap source = new(resizedFileHolder.FullName);
|
||||
MetadataExtractor.GeoLocation? geoLocation = IMetadata.GeoLocation(exifDirectory);
|
||||
const int artist = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagArtist; // 315
|
||||
const int userComment = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagUserComment;
|
||||
foreach ((Shared.Models.Face face, FileHolder? fileHolder, string fileName, bool save) in collection)
|
||||
string? model;
|
||||
string? maker;
|
||||
string checkFile = $"{filePath.FullName}.exif";
|
||||
const int artist = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagArtist;
|
||||
// const int author = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagWinAuthor; // 40093
|
||||
if (mappedFile)
|
||||
{
|
||||
if (!save)
|
||||
continue;
|
||||
if (fileHolder is null)
|
||||
continue;
|
||||
if (face.FaceEncoding is null || face?.Location is null || face?.OutputResolution is null)
|
||||
continue;
|
||||
if (_OverrideForFaceImages && fileHolder.Exists)
|
||||
{
|
||||
IFaceD dFace = this;
|
||||
FilePath filePath = FilePath.Get(_PropertyConfiguration, fileHolder, index: null);
|
||||
dFace.ReSaveFace(exifDirectory, filePath, face, mappedFile: false);
|
||||
continue;
|
||||
json = IMetadata.GetOutputResolution(exifDirectory);
|
||||
if (json is not null && json.Contains(nameof(DateTime)))
|
||||
return;
|
||||
(maker, model) = Get(json);
|
||||
}
|
||||
location = Shared.Models.Stateless.Methods.ILocation.GetLocation(face.Location, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, source.Height, source.Width, collection.Count);
|
||||
if (location is null)
|
||||
continue;
|
||||
width = location.Right - location.Left;
|
||||
height = location.Bottom - location.Top;
|
||||
faceEncodingJson = JsonSerializer.Serialize(face.FaceEncoding);
|
||||
rectangle = new Rectangle(location.Left, location.Top, width, height);
|
||||
faceFile = new(face.Mapping?.MappingFromLocation?.AreaPermyriad,
|
||||
else
|
||||
{
|
||||
maker = IMetadata.GetMaker(exifDirectory);
|
||||
model = IMetadata.GetModel(exifDirectory);
|
||||
ExifDirectory? faceExifDirectory = IMetadata.GetExifDirectory(filePath);
|
||||
json = IMetadata.GetOutputResolution(faceExifDirectory);
|
||||
if (json is not null && json.Contains(nameof(DateTime)))
|
||||
return;
|
||||
}
|
||||
MetadataExtractor.GeoLocation? geoLocation = IMetadata.GeoLocation(exifDirectory);
|
||||
FaceFile faceFile = new(face.Mapping?.MappingFromLocation?.AreaPermyriad,
|
||||
face.Mapping?.MappingFromLocation?.ConfidencePercent,
|
||||
geoLocation?.ToDmsString(),
|
||||
face.DateTime,
|
||||
null,
|
||||
geoLocation?.ToDmsString(),
|
||||
face.FaceParts,
|
||||
face.Location,
|
||||
maker,
|
||||
null,
|
||||
model,
|
||||
face.OutputResolution);
|
||||
faceFileJson = JsonSerializer.Serialize(faceFile, FaceFileGenerationContext.Default.FaceFile);
|
||||
using (bitmap = new(width, height))
|
||||
{
|
||||
using (graphics = Graphics.FromImage(bitmap))
|
||||
graphics.DrawImage(source, new Rectangle(0, 0, width, height), rectangle, GraphicsUnit.Pixel);
|
||||
propertyItem = Property.Models.Stateless.IProperty.GetPropertyItem(_ConstructorInfo, artist, type, faceFileJson);
|
||||
string faceFileJson = JsonSerializer.Serialize(faceFile, FaceFileGenerationContext.Default.FaceFile);
|
||||
ConstructorInfo? constructorInfo = typeof(PropertyItem).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, null, [], null) ?? throw new Exception();
|
||||
PropertyItem? propertyItem = Property.Models.Stateless.IProperty.GetPropertyItem(constructorInfo, artist, type, faceFileJson);
|
||||
Bitmap bitmap = new(fileInfo.FullName);
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
propertyItem = Property.Models.Stateless.IProperty.GetPropertyItem(_ConstructorInfo, userComment, type, faceEncodingJson);
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
bitmap.Save(fileHolder.FullName, _ImageCodecInfo, _EncoderParameters);
|
||||
}
|
||||
if (File.Exists(fileName))
|
||||
File.Delete(fileName);
|
||||
location = Shared.Models.Stateless.Methods.ILocation.GetLocation(_FaceDistanceHiddenImageFactor, face.Location, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, source.Height, source.Width, collection.Count);
|
||||
if (location is null)
|
||||
continue;
|
||||
width = location.Right - location.Left;
|
||||
height = location.Bottom - location.Top;
|
||||
rectangle = new Rectangle(location.Left, location.Top, width, height);
|
||||
using (bitmap = new(width, height))
|
||||
{
|
||||
using (graphics = Graphics.FromImage(bitmap))
|
||||
graphics.DrawImage(source, new Rectangle(0, 0, width, height), rectangle, GraphicsUnit.Pixel);
|
||||
bitmap.Save(fileName, _HiddenImageCodecInfo, _HiddenEncoderParameters);
|
||||
}
|
||||
#pragma warning restore CA1416
|
||||
File.SetAttributes(fileName, FileAttributes.Hidden);
|
||||
bitmap.Save(checkFile);
|
||||
bitmap.Dispose();
|
||||
File.SetLastWriteTime(checkFile, fileInfo.LastWriteTime);
|
||||
File.Delete(fileInfo.FullName);
|
||||
File.Move(checkFile, fileInfo.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore CA1416
|
||||
|
||||
}
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.FaceParts</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -33,7 +33,7 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FaceRecognitionDotNet\FaceRecognitionDotNet.csproj" />
|
||||
|
@ -2,12 +2,9 @@ using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Face.Models;
|
||||
using View_by_Distance.Metadata.Models;
|
||||
using View_by_Distance.Metadata.Models.Stateless.Methods;
|
||||
using View_by_Distance.Property.Models;
|
||||
using View_by_Distance.Property.Models.Stateless;
|
||||
using View_by_Distance.Resize.Models;
|
||||
@ -28,23 +25,22 @@ public class D2_FaceParts
|
||||
|
||||
private readonly ImageCodecInfo _ImageCodecInfo;
|
||||
private readonly bool _CheckDFaceAndUpWriteDates;
|
||||
private readonly ConstructorInfo _ConstructorInfo;
|
||||
private readonly bool _OverrideForFaceLandmarkImages;
|
||||
private readonly EncoderParameters _EncoderParameters;
|
||||
private readonly List<string> _AngleBracketCollection;
|
||||
private readonly Dictionary<string, string[]> _FileGroups;
|
||||
private readonly IPropertyConfiguration _PropertyConfiguration;
|
||||
private readonly ReadOnlyDictionary<byte, ReadOnlyCollection<string>>[] _ResultContentFileGroups;
|
||||
|
||||
public D2_FaceParts(IPropertyConfiguration propertyConfiguration, ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension, bool checkDFaceAndUpWriteDates, bool overrideForFaceLandmarkImages)
|
||||
{
|
||||
_FileGroups = [];
|
||||
_ImageCodecInfo = imageCodecInfo;
|
||||
_EncoderParameters = encoderParameters;
|
||||
_FileNameExtension = filenameExtension;
|
||||
_AngleBracketCollection = [];
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
_CheckDFaceAndUpWriteDates = checkDFaceAndUpWriteDates;
|
||||
_OverrideForFaceLandmarkImages = overrideForFaceLandmarkImages;
|
||||
_ResultContentFileGroups = [new(new Dictionary<byte, ReadOnlyCollection<string>>())];
|
||||
ConstructorInfo? constructorInfo = typeof(PropertyItem).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, null, [], null) ?? throw new Exception();
|
||||
_ConstructorInfo = constructorInfo;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
@ -55,241 +51,67 @@ public class D2_FaceParts
|
||||
|
||||
public void Update(string dResultsFullGroupDirectory)
|
||||
{
|
||||
ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePairs = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(_PropertyConfiguration, dResultsFullGroupDirectory, [_PropertyConfiguration.ResultContent]);
|
||||
foreach (KeyValuePair<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
if (keyValuePair.Key == _PropertyConfiguration.ResultContent)
|
||||
_ResultContentFileGroups[0] = keyValuePair.Value;
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
_FileGroups.Clear();
|
||||
ReadOnlyDictionary<string, string[]> keyValuePairs = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(_PropertyConfiguration, dResultsFullGroupDirectory, [_PropertyConfiguration.ResultContent]);
|
||||
foreach (KeyValuePair<string, string[]> keyValuePair in keyValuePairs)
|
||||
_FileGroups.Add(keyValuePair.Key, keyValuePair.Value);
|
||||
}
|
||||
|
||||
public void SaveFaceLandmarkImages(string d2ResultsFullGroupDirectory, MappingFromItem mappingFromItem, ExifDirectory exifDirectory, List<Shared.Models.Face> faces)
|
||||
public void SetAngleBracketCollection(IPropertyConfiguration propertyConfiguration, string d2ResultsFullGroupDirectory, string sourceDirectory)
|
||||
{
|
||||
bool any = false;
|
||||
foreach (Shared.Models.Face face in faces)
|
||||
{
|
||||
if (face.Location is null || face.FaceEncoding is null || face.FaceParts is null || face.FaceParts.Count == 0)
|
||||
continue;
|
||||
if (!any)
|
||||
any = true;
|
||||
}
|
||||
if (any)
|
||||
SaveAllFaceParts(d2ResultsFullGroupDirectory, mappingFromItem, exifDirectory, faces);
|
||||
_AngleBracketCollection.Clear();
|
||||
_AngleBracketCollection.AddRange(IResult.GetDirectoryInfoCollection(propertyConfiguration,
|
||||
sourceDirectory,
|
||||
d2ResultsFullGroupDirectory,
|
||||
contentDescription: "n gif file(s) for each face found",
|
||||
singletonDescription: string.Empty,
|
||||
collectionDescription: string.Empty,
|
||||
converted: true));
|
||||
}
|
||||
|
||||
private void SaveAllFaceParts(string d2ResultsFullGroupDirectory, MappingFromItem mappingFromItem, ExifDirectory exifDirectory, List<Shared.Models.Face> faces)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
Brush brush;
|
||||
int pointSize;
|
||||
bool any = false;
|
||||
FaceFile faceFile;
|
||||
bool? isDefaultName;
|
||||
List<long> personKeys = [];
|
||||
List<FaceFile> faceFiles = [];
|
||||
StringBuilder stringBuilder = new();
|
||||
MappingFromPerson? mappingFromPerson;
|
||||
string? maker = IMetadata.GetMaker(exifDirectory);
|
||||
string? model = IMetadata.GetModel(exifDirectory);
|
||||
MetadataExtractor.GeoLocation? geoLocation = IMetadata.GeoLocation(exifDirectory);
|
||||
#pragma warning disable CA1416
|
||||
using Image image = Image.FromFile(mappingFromItem.ResizedFileHolder.FullName);
|
||||
using Graphics graphics = Graphics.FromImage(image);
|
||||
foreach (Shared.Models.Face face in faces)
|
||||
{
|
||||
if (face.Location is null || face.FaceEncoding is null || face.FaceParts is null || face.FaceParts.Count == 0)
|
||||
continue;
|
||||
if (!any && face.Mapping?.MappingFromPerson is null)
|
||||
any = true;
|
||||
mappingFromPerson = face.Mapping?.MappingFromPerson;
|
||||
brush = mappingFromPerson is null ? Brushes.Red : Brushes.GreenYellow;
|
||||
isDefaultName = mappingFromPerson is null ? null : Shared.Models.Stateless.Methods.IPerson.IsDefaultName(mappingFromPerson);
|
||||
if (mappingFromPerson is not null && isDefaultName is not null && !isDefaultName.Value)
|
||||
personKeys.Add(mappingFromPerson.PersonKey);
|
||||
faceFile = new(face.Mapping?.MappingFromLocation?.AreaPermyriad,
|
||||
face.Mapping?.MappingFromLocation?.ConfidencePercent,
|
||||
geoLocation?.ToDmsString(),
|
||||
face.DateTime,
|
||||
face.FaceEncoding,
|
||||
face.FaceParts,
|
||||
face.Location,
|
||||
maker,
|
||||
mappingFromPerson,
|
||||
model,
|
||||
face.OutputResolution);
|
||||
faceFiles.Add(faceFile);
|
||||
pointSize = GetPointSize(face.FaceParts, defaultPointSize: 2);
|
||||
foreach ((FacePart facePart, FacePoint[] facePoints) in face.FaceParts)
|
||||
{
|
||||
foreach (FacePoint facePoint in facePoints)
|
||||
graphics.FillEllipse(brush, facePoint.X - pointSize, facePoint.Y - pointSize, pointSize * 2, pointSize * 2);
|
||||
if (facePart == FacePart.Chin)
|
||||
continue;
|
||||
if (facePoints.Length < 3)
|
||||
continue;
|
||||
x = (int)(from l in facePoints select l.X).Average();
|
||||
y = (int)(from l in facePoints select l.Y).Average();
|
||||
graphics.FillEllipse(Brushes.Purple, x - pointSize, y - pointSize, pointSize * 2, pointSize * 2);
|
||||
}
|
||||
}
|
||||
_ = graphics.Save();
|
||||
#pragma warning restore CA1416
|
||||
string directory = GetSeasonDirectory(d2ResultsFullGroupDirectory, mappingFromItem, any);
|
||||
SaveImage(mappingFromItem, directory, image, faceFiles);
|
||||
}
|
||||
|
||||
private int GetPointSize(Dictionary<FacePart, FacePoint[]> faceParts, int defaultPointSize)
|
||||
{
|
||||
int result;
|
||||
FacePoint[]? facePoints;
|
||||
if (faceParts.TryGetValue(FacePart.LeftEye, out facePoints))
|
||||
result = (int)Math.Ceiling((facePoints.Max(l => l.X) - facePoints.Min(l => l.X)) * .05);
|
||||
else
|
||||
{
|
||||
if (faceParts.TryGetValue(FacePart.RightEye, out facePoints))
|
||||
result = (int)Math.Ceiling((facePoints.Max(l => l.X) - facePoints.Min(l => l.X)) * .05);
|
||||
else
|
||||
result = defaultPointSize;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetSeasonDirectory(string d2ResultsFullGroupDirectory, MappingFromItem mappingFromItem, bool any)
|
||||
public string GetFacePartsDirectory(IPropertyConfiguration propertyConfiguration, string dResultsFullGroupDirectory, Item item, bool includeNameWithoutExtension)
|
||||
{
|
||||
string result;
|
||||
string minimumDateYear = mappingFromItem.MinimumDateTime.ToString("yyyy");
|
||||
DateTime dateTime = mappingFromItem.DateTimeOriginal is null ? mappingFromItem.MinimumDateTime : mappingFromItem.DateTimeOriginal.Value;
|
||||
(int season, string seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
||||
string year = mappingFromItem.DateTimeOriginal is null ? $"{minimumDateYear[1..]}{minimumDateYear[0]}" : mappingFromItem.DateTimeOriginal.Value.ToString("yyyy");
|
||||
string directory = Path.Combine(d2ResultsFullGroupDirectory, $"[{_PropertyConfiguration.ResultContent}]", $"{year}.{season} {seasonName}");
|
||||
result = any ? Path.Combine(directory, "---") : Path.Combine(directory, "Complete");
|
||||
bool angleBracketCollectionAny = _AngleBracketCollection.Count != 0;
|
||||
if (!angleBracketCollectionAny)
|
||||
{
|
||||
if (item.FilePath.DirectoryName is null)
|
||||
throw new NullReferenceException(nameof(item.FilePath.DirectoryName));
|
||||
SetAngleBracketCollection(propertyConfiguration, dResultsFullGroupDirectory, item.FilePath.DirectoryName);
|
||||
}
|
||||
if (includeNameWithoutExtension)
|
||||
result = Path.Combine(_AngleBracketCollection[0].Replace("<>", _PropertyConfiguration.ResultContent), item.FilePath.NameWithoutExtension);
|
||||
else
|
||||
{
|
||||
result = _AngleBracketCollection[0].Replace("<>", $"[{_PropertyConfiguration.ResultContent}]");
|
||||
if (!Directory.Exists(result))
|
||||
_ = Directory.CreateDirectory(result);
|
||||
}
|
||||
if (!angleBracketCollectionAny)
|
||||
_AngleBracketCollection.Clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SaveImage(MappingFromItem mappingFromItem, string directory, Image image, List<FaceFile> faceFiles)
|
||||
private static void GetPointBounds(PointF[] points, out float xMinimum, out float xMaximum, out float yMinimum, out float yMaximum)
|
||||
{
|
||||
short type = 2;
|
||||
string faceFileJson;
|
||||
PropertyItem? propertyItem;
|
||||
const int artist = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagArtist; // 315
|
||||
string fileName = Path.Combine(directory, $"{mappingFromItem.FilePath.Name}{_FileNameExtension}");
|
||||
try
|
||||
xMinimum = points[0].X;
|
||||
xMaximum = xMinimum;
|
||||
yMinimum = points[0].Y;
|
||||
yMaximum = yMinimum;
|
||||
foreach (PointF point in points)
|
||||
{
|
||||
if (xMinimum > point.X)
|
||||
xMinimum = point.X;
|
||||
if (xMaximum < point.X)
|
||||
xMaximum = point.X;
|
||||
if (yMinimum > point.Y)
|
||||
yMinimum = point.Y;
|
||||
if (yMaximum < point.Y)
|
||||
yMaximum = point.Y;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable CA1416
|
||||
foreach (int propertyId in image.PropertyIdList)
|
||||
{
|
||||
if (propertyId == MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagOrientation)
|
||||
continue;
|
||||
image.RemovePropertyItem(propertyId);
|
||||
}
|
||||
faceFileJson = JsonSerializer.Serialize(faceFiles.ToArray(), FaceFileCollectionGenerationContext.Default.FaceFileArray);
|
||||
propertyItem = IProperty.GetPropertyItem(_ConstructorInfo, artist, type, faceFileJson);
|
||||
image.SetPropertyItem(propertyItem);
|
||||
image.Save(fileName, _ImageCodecInfo, _EncoderParameters);
|
||||
#pragma warning restore CA1416
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is not null && !string.IsNullOrEmpty(fileName) && File.Exists(fileName))
|
||||
File.Delete(fileName);
|
||||
faceFileJson = JsonSerializer.Serialize(faceFiles.ToArray(), FaceFileCollectionGenerationContext.Default.FaceFileArray);
|
||||
if (!string.IsNullOrEmpty(faceFileJson))
|
||||
File.WriteAllText($"{fileName}.json", faceFileJson);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveFaceLandmarkImages(Configuration configuration, string d2ResultsFullGroupDirectory, FilePath filePath, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, MappingFromItem mappingFromItem, ExifDirectory exifDirectory, List<Shared.Models.Face> faces, bool saveRotated)
|
||||
{
|
||||
FileInfo fileInfo;
|
||||
bool check = false;
|
||||
FileInfo rotatedFileInfo;
|
||||
DateTime? dateTime = null;
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
string deterministicHashCodeKey;
|
||||
bool updateDateWhenMatches = false;
|
||||
List<(Shared.Models.Face, string, string)> collection = [];
|
||||
string fileName = mappingFromItem.FilePath.NameWithoutExtension;
|
||||
string[] changesFrom = [nameof(A_Property), nameof(B_Metadata), nameof(C_Resize), nameof(D_Face)];
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
CombinedEnumAndIndex cei = Shared.Models.Stateless.Methods.IPath.GetCombinedEnumAndIndex(_PropertyConfiguration, filePath);
|
||||
string directory = _ResultContentFileGroups[0][cei.Enum][cei.Index];
|
||||
DirectoryInfo directoryInfo = new(Path.Combine(directory, mappingFromItem.FilePath.NameWithoutExtension));
|
||||
MoveIf(fileName, cei, directory, directoryInfo);
|
||||
foreach (Shared.Models.Face face in faces)
|
||||
{
|
||||
if (face.FaceEncoding is null || face.Location is null || face.OutputResolution is null)
|
||||
{
|
||||
collection.Add(new(face, string.Empty, string.Empty));
|
||||
continue;
|
||||
}
|
||||
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(filePath, face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution);
|
||||
fileInfo = new FileInfo(Path.Combine(directoryInfo.FullName, $"{deterministicHashCodeKey}{mappingFromItem.FilePath.ExtensionLowered}{_FileNameExtension}"));
|
||||
if (string.IsNullOrEmpty(fileInfo.DirectoryName))
|
||||
continue;
|
||||
rotatedFileInfo = new FileInfo(Path.Combine(fileInfo.DirectoryName, $"{deterministicHashCodeKey} - R{mappingFromItem.FilePath.ExtensionLowered}{_FileNameExtension}"));
|
||||
collection.Add(new(face, fileInfo.FullName, rotatedFileInfo.FullName));
|
||||
if (check)
|
||||
continue;
|
||||
else if (!directoryInfo.Exists)
|
||||
check = true;
|
||||
else if (_OverrideForFaceLandmarkImages)
|
||||
check = true;
|
||||
else if (!fileInfo.Exists)
|
||||
check = true;
|
||||
else if (saveRotated && !rotatedFileInfo.Exists)
|
||||
check = true;
|
||||
else if (_CheckDFaceAndUpWriteDates && dateTimes.Count != 0 && dateTimes.Max() > fileInfo.LastWriteTime)
|
||||
check = true;
|
||||
if (check && !updateDateWhenMatches)
|
||||
{
|
||||
updateDateWhenMatches = dateTimes.Count != 0 && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||
dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||
}
|
||||
}
|
||||
if (check)
|
||||
{
|
||||
if (!directoryInfo.Exists)
|
||||
_ = Directory.CreateDirectory(directoryInfo.FullName);
|
||||
SaveFaceParts(mappingFromItem, exifDirectory, collection);
|
||||
if (saveRotated)
|
||||
SaveRotated(mappingFromItem, collection);
|
||||
}
|
||||
}
|
||||
|
||||
private static void MoveIf(string fileName, CombinedEnumAndIndex cei, string directory, DirectoryInfo directoryInfo)
|
||||
{
|
||||
string[] segments = directory.Split(cei.Combined);
|
||||
string? checkDirectory = segments.Length == 1 ?
|
||||
Path.Combine(segments[0], $"{cei.Combined[2..]}") :
|
||||
segments.Length == 2 ?
|
||||
$"{segments[0]}{cei.Combined[2..]}{segments[1]}" :
|
||||
null;
|
||||
if (checkDirectory is not null && Directory.Exists(checkDirectory))
|
||||
{
|
||||
string checkFile = Path.Combine(checkDirectory, fileName);
|
||||
if (Directory.Exists(checkFile))
|
||||
{
|
||||
Directory.Move(checkFile, directoryInfo.FullName);
|
||||
directoryInfo.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Bitmap RotateBitmap(Image image, float angle)
|
||||
{
|
||||
Bitmap result;
|
||||
#pragma warning disable CA1416
|
||||
Bitmap bitmap = new(image);
|
||||
result = RotateBitmap(bitmap, angle);
|
||||
bitmap?.Dispose();
|
||||
#pragma warning restore CA1416
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Bitmap RotateBitmap(Bitmap bitmap, float angle)
|
||||
{
|
||||
@ -301,7 +123,6 @@ public class D2_FaceParts
|
||||
#elif Windows
|
||||
// Make save Matrix to represent rotation
|
||||
// by this angle.
|
||||
#pragma warning disable CA1416
|
||||
Matrix rotate_at_origin = new();
|
||||
rotate_at_origin.Rotate(angle);
|
||||
|
||||
@ -348,30 +169,163 @@ public class D2_FaceParts
|
||||
int y = (hgt - bitmap.Height) / 2;
|
||||
gr.DrawImage(bitmap, x, y);
|
||||
}
|
||||
#pragma warning restore CA1416
|
||||
#endif
|
||||
// Return the result bitmap.
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void GetPointBounds(PointF[] points, out float xMinimum, out float xMaximum, out float yMinimum, out float yMaximum)
|
||||
private static Bitmap RotateBitmap(Image image, float angle)
|
||||
{
|
||||
xMinimum = points[0].X;
|
||||
xMaximum = xMinimum;
|
||||
yMinimum = points[0].Y;
|
||||
yMaximum = yMinimum;
|
||||
foreach (PointF point in points)
|
||||
Bitmap result;
|
||||
Bitmap bitmap = new(image);
|
||||
result = RotateBitmap(bitmap, angle);
|
||||
bitmap?.Dispose();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SaveFaceParts(int pointSize, FileHolder resizedFileHolder, bool saveRotated, List<(Shared.Models.Face, string, string)> collection)
|
||||
{
|
||||
if (xMinimum > point.X)
|
||||
xMinimum = point.X;
|
||||
if (xMaximum < point.X)
|
||||
xMaximum = point.X;
|
||||
if (yMinimum > point.Y)
|
||||
yMinimum = point.Y;
|
||||
if (yMaximum < point.Y)
|
||||
yMaximum = point.Y;
|
||||
int x;
|
||||
int y;
|
||||
double? α;
|
||||
int width;
|
||||
int height;
|
||||
Bitmap rotated;
|
||||
foreach ((Shared.Models.Face face, string fileName, string rotatedFileName) in collection)
|
||||
{
|
||||
if (face.FaceEncoding is null)
|
||||
continue;
|
||||
try
|
||||
{
|
||||
using (Image image = Image.FromFile(resizedFileHolder.FullName))
|
||||
{
|
||||
using Graphics graphic = Graphics.FromImage(image);
|
||||
if (face.FaceParts is null || face.FaceParts.Count == 0)
|
||||
{
|
||||
if (face.Location is null)
|
||||
continue;
|
||||
width = face.Location.Right - face.Location.Left;
|
||||
height = face.Location.Bottom - face.Location.Top;
|
||||
graphic.DrawEllipse(Pens.Red, face.Location.Left, face.Location.Top, width, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ((FacePart facePart, FacePoint[] facePoints) in face.FaceParts)
|
||||
{
|
||||
foreach (FacePoint facePoint in facePoints)
|
||||
graphic.DrawEllipse(Pens.GreenYellow, facePoint.X - pointSize, facePoint.Y - pointSize, pointSize * 2, pointSize * 2);
|
||||
if (facePart == FacePart.Chin)
|
||||
continue;
|
||||
if (facePoints.Length < 3)
|
||||
continue;
|
||||
x = (int)(from l in facePoints select l.X).Average();
|
||||
y = (int)(from l in facePoints select l.Y).Average();
|
||||
graphic.DrawEllipse(Pens.Purple, x - pointSize, y - pointSize, pointSize * 2, pointSize * 2);
|
||||
}
|
||||
}
|
||||
image.Save(fileName, _ImageCodecInfo, _EncoderParameters);
|
||||
}
|
||||
if (saveRotated && face.FaceParts is not null)
|
||||
{
|
||||
(_, α) = Shared.Models.Stateless.Methods.IFace.GetEyeα(face.FaceParts);
|
||||
if (α is null)
|
||||
continue;
|
||||
using Image image = Image.FromFile(resizedFileHolder.FullName);
|
||||
rotated = RotateBitmap(image, (float)α.Value);
|
||||
if (rotated is not null)
|
||||
{
|
||||
rotated.Save(rotatedFileName, _ImageCodecInfo, _EncoderParameters);
|
||||
rotated.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore CA1416
|
||||
|
||||
public void SaveFaceLandmarkImages(Configuration configuration, FilePath filePath, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, MappingFromItem mappingFromItem, List<Shared.Models.Face> faces, bool saveRotated)
|
||||
{
|
||||
FileInfo fileInfo;
|
||||
bool check = false;
|
||||
const int pointSize = 2;
|
||||
FileInfo rotatedFileInfo;
|
||||
DateTime? dateTime = null;
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
string deterministicHashCodeKey;
|
||||
bool updateDateWhenMatches = false;
|
||||
List<(Shared.Models.Face, string, string)> collection = [];
|
||||
string[] changesFrom = [nameof(A_Property), nameof(B_Metadata), nameof(C_Resize), nameof(D_Face)];
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
(_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration, filePath);
|
||||
string directory = Path.Combine(_FileGroups[_PropertyConfiguration.ResultContent][directoryIndex], mappingFromItem.FilePath.NameWithoutExtension);
|
||||
bool directoryExists = Directory.Exists(directory);
|
||||
foreach (Shared.Models.Face face in faces)
|
||||
{
|
||||
if (face.FaceEncoding is null || face.Location is null || face.OutputResolution is null)
|
||||
{
|
||||
collection.Add(new(face, string.Empty, string.Empty));
|
||||
continue;
|
||||
}
|
||||
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(filePath, face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution);
|
||||
fileInfo = new FileInfo(Path.Combine(directory, $"{deterministicHashCodeKey}{mappingFromItem.FilePath.ExtensionLowered}{_FileNameExtension}"));
|
||||
if (string.IsNullOrEmpty(fileInfo.DirectoryName))
|
||||
continue;
|
||||
rotatedFileInfo = new FileInfo(Path.Combine(fileInfo.DirectoryName, $"{deterministicHashCodeKey} - R{mappingFromItem.FilePath.ExtensionLowered}{_FileNameExtension}"));
|
||||
collection.Add(new(face, fileInfo.FullName, rotatedFileInfo.FullName));
|
||||
if (check)
|
||||
continue;
|
||||
else if (!directoryExists)
|
||||
check = true;
|
||||
else if (_OverrideForFaceLandmarkImages)
|
||||
check = true;
|
||||
else if (!fileInfo.Exists)
|
||||
check = true;
|
||||
else if (saveRotated && !rotatedFileInfo.Exists)
|
||||
check = true;
|
||||
else if (_CheckDFaceAndUpWriteDates && dateTimes.Count != 0 && dateTimes.Max() > fileInfo.LastWriteTime)
|
||||
check = true;
|
||||
if (check && !updateDateWhenMatches)
|
||||
{
|
||||
updateDateWhenMatches = dateTimes.Count != 0 && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||
dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||
}
|
||||
}
|
||||
if (check)
|
||||
{
|
||||
if (!directoryExists)
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
SaveFaceParts(pointSize, mappingFromItem.ResizedFileHolder, saveRotated, collection);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable CA1416
|
||||
|
||||
private void SaveFaceLandmarkImage(MappingFromItem mappingFromItem, List<(Shared.Models.Face, FileHolder?, string, bool)> faceCollection, string fileName)
|
||||
{
|
||||
Pen pen;
|
||||
using Image image = Image.FromFile(mappingFromItem.ResizedFileHolder.FullName);
|
||||
using Graphics graphic = Graphics.FromImage(image);
|
||||
foreach ((Shared.Models.Face face, FileHolder? _, string _, bool _) in faceCollection)
|
||||
{
|
||||
if (face.FaceEncoding is null || face.Location is null || face.OutputResolution is null || face.FaceParts is null || face.FaceParts.Count == 0)
|
||||
continue;
|
||||
pen = face.Mapping?.MappingFromPerson is null ? Pens.Red : Pens.GreenYellow;
|
||||
try
|
||||
{
|
||||
foreach ((FacePart facePart, FacePoint[] facePoints) in face.FaceParts)
|
||||
{
|
||||
for (int i = 0; i < facePoints.Length - 1; i++)
|
||||
graphic.DrawLine(pen, new Point(facePoints[i].X, facePoints[i].Y), new Point(facePoints[i + 1].X, facePoints[i + 1].Y));
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
image.Save(fileName, _ImageCodecInfo, _EncoderParameters);
|
||||
}
|
||||
|
||||
#pragma warning restore CA1416
|
||||
|
||||
private static bool GetNotMapped(string facePartsCollectionDirectory, List<(Shared.Models.Face Face, FileHolder?, string, bool)> faceCollection)
|
||||
{
|
||||
@ -406,116 +360,19 @@ public class D2_FaceParts
|
||||
return results;
|
||||
}
|
||||
|
||||
private void SaveImage(string fileName, Image image, FaceFile faceFile)
|
||||
public void CopyFacesAndSaveFaceLandmarkImage(string facePartsCollectionDirectory, MappingFromItem mappingFromItem, List<(Shared.Models.Face Face, FileHolder?, string, bool)> faceCollection)
|
||||
{
|
||||
short type = 2;
|
||||
string faceFileJson;
|
||||
PropertyItem? propertyItem;
|
||||
const int artist = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagArtist; // 315
|
||||
try
|
||||
bool hasNotMapped = GetNotMapped(facePartsCollectionDirectory, faceCollection);
|
||||
string fileName = Path.Combine(facePartsCollectionDirectory, $"{mappingFromItem.FilePath.Name}{_FileNameExtension}");
|
||||
bool save = faceCollection.Any(l => l.Face.FaceEncoding is not null && l.Face.Location is not null && l.Face.OutputResolution is not null && l.Face.FaceParts is not null && l.Face.FaceParts.Count != 0);
|
||||
FileInfo fileInfo = new(fileName);
|
||||
if (save && (!fileInfo.Exists || new TimeSpan(DateTime.Now.Ticks - fileInfo.LastWriteTime.Ticks).TotalDays > 10))
|
||||
{
|
||||
#pragma warning disable CA1416
|
||||
foreach (int propertyId in image.PropertyIdList)
|
||||
{
|
||||
if (propertyId == MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagOrientation)
|
||||
continue;
|
||||
image.RemovePropertyItem(propertyId);
|
||||
}
|
||||
faceFileJson = JsonSerializer.Serialize(faceFile, FaceFileGenerationContext.Default.FaceFile);
|
||||
propertyItem = IProperty.GetPropertyItem(_ConstructorInfo, artist, type, faceFileJson);
|
||||
image.SetPropertyItem(propertyItem);
|
||||
image.Save(fileName, _ImageCodecInfo, _EncoderParameters);
|
||||
#pragma warning restore CA1416
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is not null && !string.IsNullOrEmpty(fileName) && File.Exists(fileName))
|
||||
File.Delete(fileName);
|
||||
faceFileJson = JsonSerializer.Serialize(faceFile, FaceFileGenerationContext.Default.FaceFile);
|
||||
if (!string.IsNullOrEmpty(faceFileJson))
|
||||
File.WriteAllText($"{fileName}.json", faceFileJson);
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveRotated(MappingFromItem mappingFromItem, List<(Shared.Models.Face, string, string)> collection)
|
||||
{
|
||||
double? α;
|
||||
Bitmap rotated;
|
||||
foreach ((Shared.Models.Face face, string _, string rotatedFileName) in collection)
|
||||
{
|
||||
#pragma warning disable CA1416
|
||||
if (face.FaceParts is null)
|
||||
continue;
|
||||
(_, α) = Shared.Models.Stateless.Methods.IFace.GetEyeα(face.FaceParts);
|
||||
if (α is null)
|
||||
continue;
|
||||
using Image image = Image.FromFile(mappingFromItem.ResizedFileHolder.FullName);
|
||||
rotated = RotateBitmap(image, (float)α.Value);
|
||||
if (rotated is not null)
|
||||
{
|
||||
rotated.Save(rotatedFileName, _ImageCodecInfo, _EncoderParameters);
|
||||
rotated.Dispose();
|
||||
}
|
||||
#pragma warning restore CA1416
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveFaceParts(MappingFromItem mappingFromItem, ExifDirectory exifDirectory, List<(Shared.Models.Face, string, string)> collection)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
Brush brush;
|
||||
int pointSize;
|
||||
FaceFile faceFile;
|
||||
MappingFromPerson? mappingFromPerson;
|
||||
string? maker = IMetadata.GetMaker(exifDirectory);
|
||||
string? model = IMetadata.GetModel(exifDirectory);
|
||||
MetadataExtractor.GeoLocation? geoLocation = IMetadata.GeoLocation(exifDirectory);
|
||||
foreach ((Shared.Models.Face face, string fileName, string _) in collection)
|
||||
{
|
||||
try
|
||||
{
|
||||
#pragma warning disable CA1416
|
||||
if (face.Location is null || face.FaceEncoding is null || face.FaceParts is null || face.FaceParts.Count == 0)
|
||||
continue;
|
||||
using Image image = Image.FromFile(mappingFromItem.ResizedFileHolder.FullName);
|
||||
mappingFromPerson = face.Mapping?.MappingFromPerson;
|
||||
brush = mappingFromPerson is null ? Brushes.Red : Brushes.GreenYellow;
|
||||
faceFile = new(face.Mapping?.MappingFromLocation?.AreaPermyriad,
|
||||
face.Mapping?.MappingFromLocation?.ConfidencePercent,
|
||||
geoLocation?.ToDmsString(),
|
||||
face.DateTime,
|
||||
face.FaceEncoding,
|
||||
face.FaceParts,
|
||||
face.Location,
|
||||
maker,
|
||||
mappingFromPerson,
|
||||
model,
|
||||
face.OutputResolution);
|
||||
using Graphics graphics = Graphics.FromImage(image);
|
||||
pointSize = GetPointSize(face.FaceParts, defaultPointSize: 2);
|
||||
foreach ((FacePart facePart, FacePoint[] facePoints) in face.FaceParts)
|
||||
{
|
||||
foreach (FacePoint facePoint in facePoints)
|
||||
graphics.FillEllipse(brush, facePoint.X - pointSize, facePoint.Y - pointSize, pointSize * 2, pointSize * 2);
|
||||
if (facePart == FacePart.Chin)
|
||||
continue;
|
||||
if (facePoints.Length < 3)
|
||||
continue;
|
||||
x = (int)(from l in facePoints select l.X).Average();
|
||||
y = (int)(from l in facePoints select l.Y).Average();
|
||||
graphics.FillEllipse(Brushes.Purple, x - pointSize, y - pointSize, pointSize * 2, pointSize * 2);
|
||||
}
|
||||
_ = graphics.Save();
|
||||
SaveImage(fileName, image, faceFile);
|
||||
#pragma warning restore CA1416
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (File.Exists(fileName))
|
||||
File.Delete(fileName);
|
||||
}
|
||||
SaveFaceLandmarkImage(mappingFromItem, faceCollection, fileName);
|
||||
fileInfo.Refresh();
|
||||
}
|
||||
if (!hasNotMapped && !fileInfo.Attributes.HasFlag(FileAttributes.Hidden) && (fileInfo.Exists || save))
|
||||
File.SetAttributes(fileName, FileAttributes.Hidden);
|
||||
}
|
||||
|
||||
}
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.FaceRecognitionDotNet</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,13 +4,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<UserSecretsId>2999dda1-5329-4d9f-9d68-cccfabe0e47f</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Instance</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -34,12 +34,12 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
|
||||
@ -51,10 +51,10 @@
|
||||
<ProjectReference Include="..\FaceParts\FaceParts.csproj" />
|
||||
<ProjectReference Include="..\FaceRecognitionDotNet\FaceRecognitionDotNet.csproj" />
|
||||
<ProjectReference Include="..\Map\Map.csproj" />
|
||||
<ProjectReference Include="..\Container\Container.csproj" />
|
||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||
<ProjectReference Include="..\PhotoPrism\PhotoPrism.csproj" />
|
||||
<ProjectReference Include="..\Property-Compare\Property-Compare.csproj" />
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
<ProjectReference Include="..\Resize\Resize.csproj" />
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -9,6 +9,7 @@ public class Configuration
|
||||
|
||||
public bool? CheckDFaceAndUpWriteDates { get; set; }
|
||||
public bool? CheckJsonForDistanceResults { get; set; }
|
||||
public string[]? CopyFacesAndSaveFaceLandmarkForOutputResolutions { get; set; }
|
||||
public int? CrossDirectoryMaxItemsInDistanceCollection { get; set; }
|
||||
public bool? DeletePossibleDuplicates { get; set; }
|
||||
public int? DistanceFactor { get; set; }
|
||||
@ -27,8 +28,6 @@ public class Configuration
|
||||
public bool? ForceResizeLastWriteTimeToCreationTime { get; set; }
|
||||
public string? GenealogicalDataCommunicationFile { get; set; }
|
||||
public string? ImmichAssetsFile { get; set; }
|
||||
public string? ImmichOwnerId { get; set; }
|
||||
public string? ImmichRoot { get; set; }
|
||||
public string[]? IgnoreExtensions { get; set; }
|
||||
public string[]? JLinks { get; set; }
|
||||
public string? LinkedAlpha { get; set; }
|
||||
@ -78,7 +77,6 @@ public class Configuration
|
||||
public string[]? SaveBlurHashForOutputResolutions { get; set; }
|
||||
public string[]? SaveFaceDistancesForOutputResolutions { get; set; }
|
||||
public string[]? SaveFaceLandmarkForOutputResolutions { get; set; }
|
||||
public string[]? SaveFaceLandmarkForOutputResolutionsV2 { get; set; }
|
||||
public string[]? SaveFilteredOriginalImagesFromJLinksForOutputResolutions { get; set; }
|
||||
public bool? SaveFullYearOfRandomFiles { get; set; }
|
||||
public bool? SaveIndividually { get; set; }
|
||||
@ -131,6 +129,7 @@ public class Configuration
|
||||
if (configuration.CheckDFaceAndUpWriteDates is null) throw new NullReferenceException(nameof(configuration.CheckDFaceAndUpWriteDates));
|
||||
if (configuration?.CheckDFaceAndUpWriteDates is null) throw new NullReferenceException(nameof(configuration.CheckDFaceAndUpWriteDates));
|
||||
if (configuration?.CheckJsonForDistanceResults is null) throw new NullReferenceException(nameof(configuration.CheckJsonForDistanceResults));
|
||||
// if (configuration?.CopyFacesAndSaveFaceLandmarkForOutputResolutions is null) throw new NullReferenceException(nameof(configuration.CopyFacesAndSaveFaceLandmarkForOutputResolutions));
|
||||
if (configuration?.CrossDirectoryMaxItemsInDistanceCollection is null) throw new NullReferenceException(nameof(configuration.CrossDirectoryMaxItemsInDistanceCollection));
|
||||
if (configuration?.DeletePossibleDuplicates is null) throw new NullReferenceException(nameof(configuration.DeletePossibleDuplicates));
|
||||
if (configuration?.DistanceFactor is null) throw new NullReferenceException(nameof(configuration.DistanceFactor));
|
||||
@ -149,8 +148,6 @@ public class Configuration
|
||||
if (configuration?.ForceResizeLastWriteTimeToCreationTime is null) throw new NullReferenceException(nameof(configuration.ForceResizeLastWriteTimeToCreationTime));
|
||||
if (configuration?.GenealogicalDataCommunicationFile is null) throw new NullReferenceException(nameof(configuration.GenealogicalDataCommunicationFile));
|
||||
if (configuration?.ImmichAssetsFile is null) throw new NullReferenceException(nameof(configuration.ImmichAssetsFile));
|
||||
if (configuration?.ImmichOwnerId is null) throw new NullReferenceException(nameof(configuration.ImmichOwnerId));
|
||||
if (configuration?.ImmichRoot is null) throw new NullReferenceException(nameof(configuration.ImmichRoot));
|
||||
// if (configuration?.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
// if (configuration?.JLinks is null) throw new NullReferenceException(nameof(configuration.JLinks));
|
||||
// if (configuration?.LinkedAlpha is null) throw new NullReferenceException(nameof(configuration.LinkedAlpha));
|
||||
@ -200,7 +197,6 @@ public class Configuration
|
||||
// if (configuration?.SaveBlurHashForOutputResolutions is null) throw new NullReferenceException(nameof(configuration.SaveBlurHashForOutputResolutions));
|
||||
// if (configuration?.SaveFaceDistancesForOutputResolutions is null) throw new NullReferenceException(nameof(configuration.SaveFaceDistancesForOutputResolutions));
|
||||
// if (configuration?.SaveFaceLandmarkForOutputResolutions is null) throw new NullReferenceException(nameof(configuration.SaveFaceLandmarkForOutputResolutions));
|
||||
// if (configuration?.SaveFaceLandmarkForOutputResolutionsV2 is null) throw new NullReferenceException(nameof(configuration.SaveFaceLandmarkForOutputResolutionsV2));
|
||||
// if (configuration?.SaveFilteredOriginalImagesFromJLinksForOutputResolutions is null) throw new NullReferenceException(nameof(configuration.SaveFilteredOriginalImagesFromJLinksForOutputResolutions));
|
||||
if (configuration?.SaveFullYearOfRandomFiles is null) throw new NullReferenceException(nameof(configuration.SaveFullYearOfRandomFiles));
|
||||
if (configuration?.SaveIndividually is null) throw new NullReferenceException(nameof(configuration.SaveIndividually));
|
||||
@ -225,6 +221,7 @@ public class Configuration
|
||||
result = new(propertyConfiguration,
|
||||
configuration.CheckDFaceAndUpWriteDates.Value,
|
||||
configuration.CheckJsonForDistanceResults.Value,
|
||||
configuration.CopyFacesAndSaveFaceLandmarkForOutputResolutions ?? [],
|
||||
configuration.CrossDirectoryMaxItemsInDistanceCollection.Value,
|
||||
configuration.DeletePossibleDuplicates.Value,
|
||||
configuration.DistanceFactor.Value,
|
||||
@ -243,8 +240,6 @@ public class Configuration
|
||||
configuration.ForceResizeLastWriteTimeToCreationTime.Value,
|
||||
configuration.GenealogicalDataCommunicationFile,
|
||||
configuration.ImmichAssetsFile,
|
||||
configuration.ImmichOwnerId,
|
||||
configuration.ImmichRoot,
|
||||
configuration.IgnoreExtensions ?? [],
|
||||
configuration.JLinks ?? [],
|
||||
configuration.LinkedAlpha,
|
||||
@ -294,7 +289,6 @@ public class Configuration
|
||||
configuration.SaveBlurHashForOutputResolutions ?? [],
|
||||
configuration.SaveFaceDistancesForOutputResolutions ?? [],
|
||||
configuration.SaveFaceLandmarkForOutputResolutions ?? [],
|
||||
configuration.SaveFaceLandmarkForOutputResolutionsV2 ?? [],
|
||||
configuration.SaveFilteredOriginalImagesFromJLinksForOutputResolutions ?? [],
|
||||
configuration.SaveFullYearOfRandomFiles.Value,
|
||||
configuration.SaveIndividually.Value,
|
||||
|
@ -54,7 +54,7 @@ public class Place
|
||||
results.Add(Get(place));
|
||||
}
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
return new(results);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ namespace View_by_Distance.Instance.Models;
|
||||
public record Configuration(Property.Models.Configuration PropertyConfiguration,
|
||||
bool CheckDFaceAndUpWriteDates,
|
||||
bool CheckJsonForDistanceResults,
|
||||
string[] CopyFacesAndSaveFaceLandmarkForOutputResolutions,
|
||||
int CrossDirectoryMaxItemsInDistanceCollection,
|
||||
bool DeletePossibleDuplicates,
|
||||
int DistanceFactor,
|
||||
@ -21,8 +22,6 @@ public record Configuration(Property.Models.Configuration PropertyConfiguration,
|
||||
bool ForceResizeLastWriteTimeToCreationTime,
|
||||
string GenealogicalDataCommunicationFile,
|
||||
string ImmichAssetsFile,
|
||||
string ImmichOwnerId,
|
||||
string ImmichRoot,
|
||||
string[] IgnoreExtensions,
|
||||
string[] JLinks,
|
||||
string? LinkedAlpha,
|
||||
@ -64,7 +63,7 @@ public record Configuration(Property.Models.Configuration PropertyConfiguration,
|
||||
int RadomUseBirthdayMinimum,
|
||||
int[] RangeDaysDeltaTolerance,
|
||||
float[] RangeDistanceTolerance,
|
||||
float[] RangeFaceAreaTolerance,
|
||||
float[] RangeFaceAreaPermyriadTolerance,
|
||||
float[] RangeFaceConfidence,
|
||||
float[] RectangleIntersectMinimums,
|
||||
bool ReMap,
|
||||
@ -72,7 +71,6 @@ public record Configuration(Property.Models.Configuration PropertyConfiguration,
|
||||
string[] SaveBlurHashForOutputResolutions,
|
||||
string[] SaveFaceDistancesForOutputResolutions,
|
||||
string[] SaveFaceLandmarkForOutputResolutions,
|
||||
string[] SaveFaceLandmarkForOutputResolutionsV2,
|
||||
string[] SaveFilteredOriginalImagesFromJLinksForOutputResolutions,
|
||||
bool SaveFullYearOfRandomFiles,
|
||||
bool SaveIndividually,
|
||||
|
27
Instance/Models/Identifier.cs
Normal file
27
Instance/Models/Identifier.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Instance.Models;
|
||||
|
||||
internal record Identifier(int Id, string PaddedId)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, IdentifierSourceGenerationContext.Default.Identifier);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Identifier))]
|
||||
internal partial class IdentifierSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Identifier[]))]
|
||||
internal partial class IdentifierCollectionSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
@ -25,7 +25,7 @@ internal class F_Random
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<string, List<string>> GetDayToRelativePaths(ReadOnlyCollection<Mapping> distinctValidImageMappingCollection, string dateFormat, string immichOwnerId, string immichRoot, Dictionary<string, ImmichAsset> immichAssets, ReadOnlyDictionary<int, List<long>> idToPersonKeys)
|
||||
private static ReadOnlyDictionary<string, List<string>> GetDayToRelativePaths(ReadOnlyCollection<Mapping> distinctValidImageMappingCollection, string dateFormat, Dictionary<string, ImmichAsset> immichAssets, ReadOnlyDictionary<int, List<long>> idToPersonKeys)
|
||||
{
|
||||
Dictionary<string, List<string>> results = [];
|
||||
string key;
|
||||
@ -36,7 +36,7 @@ internal class F_Random
|
||||
bool immichAssetsCountIsZero = immichAssets.Count == 0;
|
||||
foreach (Mapping mapping in distinctValidImageMappingCollection)
|
||||
{
|
||||
if (mapping.MappingFromItem.FilePath.DirectoryFullPath is null || mapping.MappingFromPerson is null)
|
||||
if (mapping.MappingFromItem.FilePath.DirectoryName is null || mapping.MappingFromPerson is null)
|
||||
continue;
|
||||
if (!idToPersonKeys.TryGetValue(mapping.MappingFromItem.Id, out personKeys))
|
||||
continue;
|
||||
@ -56,14 +56,12 @@ internal class F_Random
|
||||
relativePaths.Add(mapping.MappingFromItem.RelativePath);
|
||||
else
|
||||
{
|
||||
if (!immichAssets.TryGetValue($"{immichRoot}{mapping.MappingFromItem.RelativePath}", out immichAsset))
|
||||
if (!immichAssets.TryGetValue(mapping.MappingFromItem.RelativePath, out immichAsset))
|
||||
continue;
|
||||
if (!immichAsset.Path.Contains(immichOwnerId))
|
||||
continue;
|
||||
relativePaths.Add(immichAsset.Path.Split(immichOwnerId)[1]);
|
||||
relativePaths.Add(immichAsset.PreviewPath);
|
||||
}
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static Dictionary<string, ImmichAsset> GetImmichAssets(string immichAssetsFile)
|
||||
@ -82,7 +80,7 @@ internal class F_Random
|
||||
return results;
|
||||
}
|
||||
|
||||
internal void Random(Property.Models.Configuration configuration, string immichAssetsFile, string immichOwnerId, string immichRoot, int radomUseBirthdayMinimum, string[] validKeyWordsToIgnoreInRandom, ReadOnlyDictionary<long, List<int>> personKeyToIds, ReadOnlyDictionary<int, Identifier> splatNineIdentifiers, ReadOnlyCollection<Mapping> distinctValidImageMappingCollection)
|
||||
internal void Random(Property.Models.Configuration configuration, string immichAssetsFile, int radomUseBirthdayMinimum, string[] validKeyWordsToIgnoreInRandom, ReadOnlyDictionary<long, List<int>> personKeyToIds, ReadOnlyCollection<int>? notNineCollection, ReadOnlyCollection<Mapping> distinctValidImageMappingCollection)
|
||||
{
|
||||
string key;
|
||||
string json;
|
||||
@ -95,9 +93,8 @@ internal class F_Random
|
||||
List<int> distinctCollection = [];
|
||||
DateTime dateTime = new(2024, 1, 1); //Leap year
|
||||
Dictionary<string, ImmichAsset> immichAssets = GetImmichAssets(immichAssetsFile);
|
||||
int[] splatNineIdentifiersKeys = splatNineIdentifiers.Select(l => l.Key).ToArray();
|
||||
ReadOnlyDictionary<int, List<long>> idToPersonKeys = Map.Models.Stateless.Methods.IMapLogic.GetIdToPersonKeys(personKeyToIds);
|
||||
ReadOnlyDictionary<string, List<string>> dayToRelativePaths = GetDayToRelativePaths(distinctValidImageMappingCollection, dateFormat, immichOwnerId, immichRoot, immichAssets, idToPersonKeys);
|
||||
ReadOnlyDictionary<string, List<string>> dayToRelativePaths = GetDayToRelativePaths(distinctValidImageMappingCollection, dateFormat, immichAssets, idToPersonKeys);
|
||||
string fRandomCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(F_Random), "[]");
|
||||
string[] files = Directory.GetFiles(fRandomCollectionDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
@ -105,13 +102,11 @@ internal class F_Random
|
||||
bool immichAssetsCountIsZero = immichAssets.Count == 0;
|
||||
foreach (Mapping mapping in distinctValidImageMappingCollection)
|
||||
{
|
||||
if (mapping.MappingFromItem.IsArchive is not null && mapping.MappingFromItem.IsArchive.Value)
|
||||
continue;
|
||||
if (distinctCollection.Contains(mapping.MappingFromItem.Id))
|
||||
continue;
|
||||
if (mapping.MappingFromItem.FilePath.DirectoryFullPath is null)
|
||||
if (mapping.MappingFromItem.FilePath.DirectoryName is null)
|
||||
continue;
|
||||
if (!splatNineIdentifiersKeys.Contains(mapping.MappingFromItem.Id))
|
||||
if (notNineCollection is not null && notNineCollection.Contains(mapping.MappingFromItem.Id))
|
||||
continue;
|
||||
if (mapping.MappingFromItem.Keywords is not null && mapping.MappingFromItem.Keywords.Any(l => validKeyWordsToIgnoreInRandom.Contains(l)))
|
||||
continue;
|
||||
@ -119,11 +114,9 @@ internal class F_Random
|
||||
relativePaths.Add(mapping.MappingFromItem.RelativePath);
|
||||
else
|
||||
{
|
||||
if (!immichAssets.TryGetValue($"{immichRoot}{mapping.MappingFromItem.RelativePath}", out immichAsset))
|
||||
if (!immichAssets.TryGetValue(mapping.MappingFromItem.RelativePath, out immichAsset))
|
||||
continue;
|
||||
if (!immichAsset.Path.Contains(immichOwnerId))
|
||||
continue;
|
||||
relativePaths.Add(immichAsset.Path.Split(immichOwnerId)[1]);
|
||||
relativePaths.Add(immichAsset.PreviewPath);
|
||||
}
|
||||
distinctCollection.Add(mapping.MappingFromItem.Id);
|
||||
}
|
||||
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Map</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -37,12 +37,10 @@
|
||||
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
<ProjectReference Include="..\Container\Container.csproj" />
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
File diff suppressed because it is too large
Load Diff
@ -58,10 +58,10 @@ internal abstract class DecadeLogic
|
||||
string? personKeyFormattedDirectoryName;
|
||||
foreach (LocationContainer locationContainer in locationContainers)
|
||||
{
|
||||
if (string.IsNullOrEmpty(locationContainer.FilePath.DirectoryFullPath))
|
||||
if (string.IsNullOrEmpty(locationContainer.FilePath.DirectoryName))
|
||||
continue;
|
||||
personNameDirectoryName = Path.GetFileName(locationContainer.FilePath.DirectoryFullPath);
|
||||
yearDirectory = Path.GetDirectoryName(locationContainer.FilePath.DirectoryFullPath);
|
||||
personNameDirectoryName = Path.GetFileName(locationContainer.FilePath.DirectoryName);
|
||||
yearDirectory = Path.GetDirectoryName(locationContainer.FilePath.DirectoryName);
|
||||
if (string.IsNullOrEmpty(yearDirectory))
|
||||
continue;
|
||||
yearDirectoryName = Path.GetFileName(yearDirectory);
|
||||
|
@ -22,190 +22,62 @@ internal abstract class DistanceLogic
|
||||
internal record TicksDirectory(DateTime AlternateDirectoryDateTime,
|
||||
string Directory,
|
||||
DateTime DirectoryDateTime,
|
||||
string DirectoryName,
|
||||
bool? IsLocationContainerDebugDirectory,
|
||||
float? TotalDays);
|
||||
|
||||
internal static List<Record> DeleteEmptyDirectoriesAndGetCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, Configuration configuration, long ticks, string eDistanceContentDirectory, ReadOnlyDictionary<string, string> personKeyFormattedToNewestPersonKeyFormatted, ReadOnlyCollection<string> personKeyFormattedCollection)
|
||||
private static void MoveTo(string actionDirectory, TicksDirectory ticksDirectory, string directory, string personKeyFormatted, string yearDirectoryName, string alphaDirectoryName, string[] files, string[] facesFileNames)
|
||||
{
|
||||
List<Record> results = [];
|
||||
bool check;
|
||||
string message;
|
||||
string[] files;
|
||||
bool? isDefault;
|
||||
int? linksCount;
|
||||
int totalSeconds;
|
||||
DateTime dateTime;
|
||||
TimeSpan timeSpan;
|
||||
int directoryNumber;
|
||||
List<Record> records;
|
||||
string? checkDirectory;
|
||||
ProgressBar progressBar;
|
||||
string[] yearDirectories;
|
||||
string personKeyFormatted;
|
||||
List<string> distinct = [];
|
||||
string? personFirstInitial;
|
||||
bool isReservedDirectoryName;
|
||||
string[] personNameDirectories;
|
||||
string? newestPersonKeyFormatted;
|
||||
string? personDisplayDirectoryName;
|
||||
string[] personNameLinkDirectories;
|
||||
string? personFirstInitialDirectory;
|
||||
List<TicksDirectory> ticksDirectories;
|
||||
string[] personKeyFormattedDirectories;
|
||||
string manualCopyHumanized = nameof(Shared.Models.Stateless.IMapLogic.ManualCopy).Humanize(LetterCasing.Title);
|
||||
string forceSingleImageHumanized = nameof(Shared.Models.Stateless.IMapLogic.ForceSingleImage).Humanize(LetterCasing.Title);
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
for (int i = 1; i < 6; i++)
|
||||
{
|
||||
check = false;
|
||||
results.Clear();
|
||||
distinct.Clear();
|
||||
directoryNumber = 0;
|
||||
ticksDirectories = UpdateDateVerifyAndGetTicksDirectories(configuration, eDistanceContentDirectory);
|
||||
totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
message = $"{i}) {ticksDirectories.Count:000} compile from and clean ticks Director(ies) - B - {totalSeconds} total second(s)";
|
||||
progressBar = new(ticksDirectories.Count, message, options);
|
||||
foreach (TicksDirectory ticksDirectory in ticksDirectories)
|
||||
{
|
||||
progressBar.Tick();
|
||||
personKeyFormattedDirectories = Directory.GetDirectories(ticksDirectory.Directory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string personKeyFormattedDirectory in personKeyFormattedDirectories)
|
||||
{
|
||||
personKeyFormatted = Path.GetFileName(personKeyFormattedDirectory);
|
||||
isReservedDirectoryName = personKeyFormatted.StartsWith(nameof(Shared.Models.Stateless.IMapLogic.Sorting)) || personKeyFormatted.StartsWith(nameof(Shared.Models.Stateless.IMapLogic.Mapping)) || personKeyFormatted.StartsWith(nameof(Shared.Models.Stateless.IMapLogic.ManualCopy));
|
||||
if (!isReservedDirectoryName && personKeyFormatted.StartsWith(nameof(Shared.Models.Stateless.IMapLogic.Individually)))
|
||||
{
|
||||
Individually(configuration, ticksDirectory, personKeyFormattedDirectory);
|
||||
throw new Exception($"B) Move personKey directories up one from {nameof(Shared.Models.Stateless.IMapLogic.Sorting)} and delete {nameof(Shared.Models.Stateless.IMapLogic.Sorting)} directory!");
|
||||
}
|
||||
_ = personKeyFormattedToNewestPersonKeyFormatted.TryGetValue(personKeyFormatted, out newestPersonKeyFormatted);
|
||||
if (personKeyFormattedToNewestPersonKeyFormatted.Count > 0 && newestPersonKeyFormatted is null)
|
||||
{
|
||||
timeSpan = new TimeSpan(DateTime.Now.Ticks - ticksDirectory.DirectoryDateTime.Ticks);
|
||||
if (timeSpan.TotalDays > 6)
|
||||
throw new Exception($"{configuration.MappingDefaultName} <{ticksDirectory.DirectoryDateTime}> are only allowed within x days!");
|
||||
}
|
||||
yearDirectories = Directory.GetDirectories(personKeyFormattedDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string yearDirectory in yearDirectories)
|
||||
{
|
||||
if (check && !Directory.Exists(yearDirectory))
|
||||
continue;
|
||||
if (ticksDirectory.IsLocationContainerDebugDirectory is null || !ticksDirectory.IsLocationContainerDebugDirectory.Value)
|
||||
linksCount = null;
|
||||
else
|
||||
linksCount = GetLinksCount(yearDirectory);
|
||||
personNameDirectories = Directory.GetDirectories(yearDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (personNameDirectories.Length > 1)
|
||||
throw new NotSupportedException("Try deleting *.lnk files!");
|
||||
foreach (string personNameDirectory in personNameDirectories)
|
||||
{
|
||||
directoryNumber++;
|
||||
personDisplayDirectoryName = Path.GetFileName(personNameDirectory);
|
||||
isDefault = IPerson.IsDefaultName(personDisplayDirectoryName) && IPersonBirthday.IsCounterPersonYear(personKeyFormatted[..4]);
|
||||
if (isDefault.Value && personDisplayDirectoryName.Length == 1)
|
||||
{
|
||||
if (personKeyFormatted.Length != configuration.PersonBirthdayFormat.Length || !DateTime.TryParseExact(personKeyFormatted, configuration.PersonBirthdayFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||
continue;
|
||||
checkDirectory = Path.Combine(yearDirectory, $"X+{dateTime.Ticks}");
|
||||
if (Directory.Exists(checkDirectory))
|
||||
{
|
||||
Directory.Delete(yearDirectory, recursive: true);
|
||||
continue;
|
||||
}
|
||||
Directory.Move(personNameDirectory, checkDirectory);
|
||||
if (!check)
|
||||
check = true;
|
||||
continue;
|
||||
}
|
||||
if (isDefault.Value && (ticksDirectory.DirectoryDateTime.Hour != 0 || ticksDirectory.DirectoryDateTime.Minute != 0 || ticksDirectory.DirectoryDateTime.Second != 0))
|
||||
{
|
||||
checkDirectory = Path.GetDirectoryName(ticksDirectory.Directory);
|
||||
if (checkDirectory is null)
|
||||
continue;
|
||||
checkDirectory = Path.Combine(checkDirectory, ticksDirectory.AlternateDirectoryDateTime.Ticks.ToString());
|
||||
string checkFile;
|
||||
string actionDirectoryName = Path.GetFileName(actionDirectory);
|
||||
string checkDirectory = actionDirectoryName.StartsWith("y", StringComparison.CurrentCultureIgnoreCase) ? Path.Combine(ticksDirectory.Directory, personKeyFormatted, yearDirectoryName, alphaDirectoryName) : Path.Combine(directory, actionDirectoryName);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
checkDirectory = Path.Combine(checkDirectory, personKeyFormatted);
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (facesFileNames.Contains(file))
|
||||
{
|
||||
checkFile = Path.Combine(checkDirectory, Path.GetFileName(file));
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(file, checkFile);
|
||||
continue;
|
||||
}
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
|
||||
private static void MoveFiles(string personKeyFormatted, string personKeyDirectory, string newestPersonKeyFormatted, string newestPersonKeyDirectory)
|
||||
{
|
||||
string[] files;
|
||||
string checkFile;
|
||||
string? checkDirectory;
|
||||
string[] directories = Directory.GetDirectories(personKeyDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
checkDirectory = Path.Combine(newestPersonKeyDirectory, Path.GetFileName(directory));
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
{
|
||||
Directory.Move(personKeyFormattedDirectory, checkDirectory);
|
||||
if (!check)
|
||||
check = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
files = Directory.GetFiles(personNameDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (isReservedDirectoryName && files.Length > 0)
|
||||
throw new Exception($"Move personKey directories up one from {nameof(Shared.Models.Stateless.IMapLogic.Sorting)} and delete {nameof(Shared.Models.Stateless.IMapLogic.Sorting)} directory!");
|
||||
if (personKeyFormatted == manualCopyHumanized && files.Length > 0)
|
||||
throw new Exception($"Move personKey directories up one from {manualCopyHumanized} and delete {manualCopyHumanized} directory!");
|
||||
if (personKeyFormatted == forceSingleImageHumanized && files.Length > 0)
|
||||
throw new Exception($"Move personKey directories up one from {forceSingleImageHumanized} and delete {forceSingleImageHumanized} directory!");
|
||||
if (!isDefault.Value)
|
||||
{
|
||||
if (personKeyFormattedToNewestPersonKeyFormatted.Count > 0 && newestPersonKeyFormatted is null)
|
||||
files = RenameBirth(files);
|
||||
else if (newestPersonKeyFormatted is not null && personKeyFormatted != newestPersonKeyFormatted)
|
||||
{
|
||||
if (!check)
|
||||
check = true;
|
||||
MovedToNewestPersonKeyFormatted(personKeyFormatted, newestPersonKeyFormatted, ticksDirectory, personKeyFormattedDirectory);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (personKeyFormatted.Length != configuration.PersonBirthdayFormat.Length)
|
||||
continue;
|
||||
if (personDisplayDirectoryName.Length == 1 || isDefault.Value || !personKeyFormattedCollection.Contains(personKeyFormatted))
|
||||
personFirstInitialDirectory = personNameDirectory;
|
||||
Directory.Move(directory, checkDirectory);
|
||||
else
|
||||
{
|
||||
personFirstInitial = personDisplayDirectoryName[..1];
|
||||
if (personFirstInitial.All(char.IsDigit))
|
||||
{
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
files = Directory.GetFiles(personNameDirectory, "*", SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
_ = IPath.DeleteEmptyDirectories(personNameDirectory);
|
||||
continue;
|
||||
}
|
||||
personFirstInitialDirectory = Path.Combine(yearDirectory, personFirstInitial.ToString());
|
||||
if (Directory.Exists(personFirstInitialDirectory))
|
||||
throw new Exception("Forgot to ...");
|
||||
Directory.Move(personNameDirectory, personFirstInitialDirectory);
|
||||
files = Directory.GetFiles(personFirstInitialDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
}
|
||||
records = GetRecords(propertyConfiguration, configuration, ticksDirectory, isDefault, files, directoryNumber, personKeyFormatted, linksCount, distinct, personDisplayDirectoryName);
|
||||
if (records.Count > 0)
|
||||
results.AddRange(records);
|
||||
personNameLinkDirectories = Directory.GetDirectories(personFirstInitialDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string personNameLinkDirectory in personNameLinkDirectories)
|
||||
{
|
||||
files = Directory.GetFiles(personNameLinkDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
files = Directory.GetFiles(directory, "*", SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (!file.EndsWith(".lnk"))
|
||||
if (file.Split(personKeyFormatted).Length != 2 || file.Contains(newestPersonKeyFormatted))
|
||||
continue;
|
||||
File.Delete(file);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(personNameLinkDirectory);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(personFirstInitialDirectory);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(yearDirectory);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(personKeyFormattedDirectory);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(ticksDirectory.Directory);
|
||||
_ = IPath.DeleteEmptyDirectories(ticksDirectory.Directory);
|
||||
}
|
||||
progressBar.Dispose();
|
||||
if (check)
|
||||
checkFile = file.Replace(personKeyFormatted, newestPersonKeyFormatted);
|
||||
checkDirectory = Path.GetDirectoryName(checkFile);
|
||||
if (checkDirectory is null)
|
||||
continue;
|
||||
break;
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
File.Move(file, checkFile);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(personKeyDirectory);
|
||||
}
|
||||
|
||||
private static List<TicksDirectory> UpdateDateVerifyAndGetTicksDirectories(Configuration configuration, string eDistanceContentDirectory)
|
||||
@ -214,55 +86,53 @@ internal abstract class DistanceLogic
|
||||
float? totalDays;
|
||||
long? next = null;
|
||||
string? checkDirectory;
|
||||
string ticksDirectoryName;
|
||||
DateTime directoryDateTime;
|
||||
DirectoryInfo directoryInfo;
|
||||
TicksDirectory ticksDirectory;
|
||||
long? lastDirectoryTicks = null;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
DateTime alternateDirectoryDateTime;
|
||||
string ticksDirectoryNameFirstSegment;
|
||||
bool? isLocationContainerDebugDirectory;
|
||||
long month = dateTime.AddMonths(1).Ticks - dateTime.Ticks;
|
||||
for (int i = 1; i < 5; i++)
|
||||
_ = IPath.DeleteEmptyDirectories(eDistanceContentDirectory);
|
||||
if (!Directory.Exists(eDistanceContentDirectory))
|
||||
_ = Directory.CreateDirectory(eDistanceContentDirectory);
|
||||
string[] ticksFullPaths = Directory.GetDirectories(eDistanceContentDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string ticksFullPath in ticksFullPaths)
|
||||
string[] ticksDirectories = Directory.GetDirectories(eDistanceContentDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string ticksDirectory in ticksDirectories)
|
||||
{
|
||||
ticksDirectoryNameFirstSegment = Path.GetFileName(ticksFullPath).Split('.')[0];
|
||||
if (ticksDirectoryNameFirstSegment.Length < 3)
|
||||
ticksDirectoryName = Path.GetFileName(ticksDirectory);
|
||||
if (ticksDirectoryName.Length < 3)
|
||||
continue;
|
||||
if (!long.TryParse(ticksDirectoryNameFirstSegment, out long directoryTicks))
|
||||
if (!long.TryParse(ticksDirectoryName, out long directoryTicks))
|
||||
throw new NotSupportedException();
|
||||
if (next is null)
|
||||
next = new DateTime(directoryTicks).Ticks;
|
||||
else
|
||||
{
|
||||
next += month;
|
||||
checkDirectory = Path.GetDirectoryName(ticksFullPath);
|
||||
checkDirectory = Path.GetDirectoryName(ticksDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
{
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
continue;
|
||||
checkDirectory = Path.Combine(checkDirectory, next.Value.ToString());
|
||||
if (ticksFullPath == checkDirectory || !checkDirectory.EndsWith(configuration.LocationContainerDirectoryPattern))
|
||||
if (ticksDirectory == checkDirectory || !checkDirectory.EndsWith(configuration.LocationContainerDirectoryPattern))
|
||||
continue;
|
||||
Directory.Move(ticksFullPath, checkDirectory);
|
||||
Directory.Move(ticksDirectory, checkDirectory);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
directoryInfo = new(ticksFullPath);
|
||||
directoryInfo = new(ticksDirectory);
|
||||
directoryDateTime = new DateTime(directoryTicks);
|
||||
if (directoryInfo.CreationTime.Ticks != directoryTicks)
|
||||
Directory.SetCreationTime(ticksFullPath, new DateTime(directoryTicks));
|
||||
Directory.SetCreationTime(ticksDirectory, new DateTime(directoryTicks));
|
||||
if (directoryInfo.LastWriteTime.Ticks != directoryTicks)
|
||||
Directory.SetLastWriteTime(ticksFullPath, new DateTime(directoryTicks));
|
||||
Directory.SetLastWriteTime(ticksDirectory, new DateTime(directoryTicks));
|
||||
alternateDirectoryDateTime = new DateTime(directoryDateTime.Year, directoryDateTime.Month, directoryDateTime.Day).AddMonths(1);
|
||||
isLocationContainerDebugDirectory = configuration.LocationContainerDebugDirectory is null ? null : ticksDirectoryNameFirstSegment.EndsWith(configuration.LocationContainerDebugDirectory);
|
||||
isLocationContainerDebugDirectory = configuration.LocationContainerDebugDirectory is null ? null : ticksDirectoryName.EndsWith(configuration.LocationContainerDebugDirectory);
|
||||
totalDays = lastDirectoryTicks is null || new TimeSpan(dateTime.Ticks - directoryTicks).TotalDays < 1 ? null : (float)new TimeSpan(directoryTicks - lastDirectoryTicks.Value).TotalDays;
|
||||
ticksDirectory = new(alternateDirectoryDateTime, ticksFullPath, new(directoryTicks), isLocationContainerDebugDirectory, totalDays);
|
||||
results.Add(ticksDirectory);
|
||||
results.Add(new(alternateDirectoryDateTime, ticksDirectory, new(directoryTicks), ticksDirectoryName, isLocationContainerDebugDirectory, totalDays));
|
||||
if (directoryDateTime.Hour == 0 && directoryDateTime.Minute == 0 && directoryDateTime.Second == 0)
|
||||
continue;
|
||||
lastDirectoryTicks = directoryTicks;
|
||||
@ -346,42 +216,38 @@ internal abstract class DistanceLogic
|
||||
}
|
||||
}
|
||||
|
||||
private static void MoveTo(string actionDirectory, TicksDirectory ticksDirectory, string directory, string personKeyFormatted, string yearDirectoryName, string alphaDirectoryName, string[] files, string[] facesFileNames)
|
||||
private static List<Record> GetRecords(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, Configuration configuration, bool? isDefault, string[] files, int directoryNumber, string personKeyFormatted, int? linksCount, List<string> distinct, string? personDisplayDirectoryName)
|
||||
{
|
||||
List<Record> results = [];
|
||||
string fileName;
|
||||
string checkFile;
|
||||
string actionDirectoryName = Path.GetFileName(actionDirectory);
|
||||
string checkDirectory = actionDirectoryName.StartsWith("y", StringComparison.CurrentCultureIgnoreCase) ? Path.Combine(ticksDirectory.Directory, personKeyFormatted, yearDirectoryName, alphaDirectoryName) : Path.Combine(directory, actionDirectoryName);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
FilePath filePath;
|
||||
FileHolder fileHolder;
|
||||
int? wholePercentages;
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (facesFileNames.Contains(file))
|
||||
if (file.EndsWith(".lnk"))
|
||||
continue;
|
||||
fileHolder = IFileHolder.Get(file);
|
||||
filePath = FilePath.Get(propertyConfiguration, fileHolder, index: null);
|
||||
if (filePath.Id is null)
|
||||
continue;
|
||||
wholePercentages = IMapping.GetWholePercentages(configuration.FacesFileNameExtension, filePath);
|
||||
if (wholePercentages is null)
|
||||
continue;
|
||||
fileName = Path.GetFileName(file);
|
||||
if (distinct.Contains(fileName))
|
||||
{
|
||||
checkFile = Path.Combine(checkDirectory, Path.GetFileName(file));
|
||||
checkFile = $"{file}.dup";
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(file, checkFile);
|
||||
continue;
|
||||
}
|
||||
File.Delete(file);
|
||||
distinct.Add(fileName);
|
||||
results.Add(new(directoryNumber, isDefault, linksCount, filePath, personDisplayDirectoryName, personKeyFormatted));
|
||||
}
|
||||
}
|
||||
|
||||
private static int? GetLinksCount(string yearDirectory)
|
||||
{
|
||||
int? result;
|
||||
string[] yearDirectoryNameSegments = Path.GetFileName(yearDirectory).Split('-');
|
||||
if (yearDirectoryNameSegments.Length != 3)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
string lastSegment = yearDirectoryNameSegments[^1];
|
||||
if (lastSegment.Length != 3 || !lastSegment.All(l => l == lastSegment[0]))
|
||||
result = null;
|
||||
else
|
||||
result = lastSegment[0] - 65;
|
||||
}
|
||||
return result;
|
||||
return results;
|
||||
}
|
||||
|
||||
private static string[] RenameBirth(string[] files)
|
||||
@ -416,117 +282,219 @@ internal abstract class DistanceLogic
|
||||
Directory.Move(personKeyDirectory, newestPersonKeyDirectory);
|
||||
}
|
||||
|
||||
private static void MoveFiles(string personKeyFormatted, string personKeyDirectory, string newestPersonKeyFormatted, string newestPersonKeyDirectory)
|
||||
private static int? GetLinksCount(string yearDirectory)
|
||||
{
|
||||
string[] files;
|
||||
string checkFile;
|
||||
string? checkDirectory;
|
||||
string[] directories = Directory.GetDirectories(personKeyDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
checkDirectory = Path.Combine(newestPersonKeyDirectory, Path.GetFileName(directory));
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
Directory.Move(directory, checkDirectory);
|
||||
int? result;
|
||||
string[] yearDirectoryNameSegments = Path.GetFileName(yearDirectory).Split('-');
|
||||
if (yearDirectoryNameSegments.Length != 3)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
files = Directory.GetFiles(directory, "*", SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (file.Split(personKeyFormatted).Length != 2 || file.Contains(newestPersonKeyFormatted))
|
||||
continue;
|
||||
checkFile = file.Replace(personKeyFormatted, newestPersonKeyFormatted);
|
||||
checkDirectory = Path.GetDirectoryName(checkFile);
|
||||
if (checkDirectory is null)
|
||||
continue;
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
File.Move(file, checkFile);
|
||||
string lastSegment = yearDirectoryNameSegments[^1];
|
||||
if (lastSegment.Length != 3 || !lastSegment.All(l => l == lastSegment[0]))
|
||||
result = null;
|
||||
else
|
||||
result = lastSegment[0] - 65;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(personKeyDirectory);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Record> GetRecords(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, Configuration configuration, TicksDirectory ticksDirectory, bool? isDefault, string[] files, int directoryNumber, string personKeyFormatted, int? linksCount, List<string> distinct, string? personDisplayDirectoryName)
|
||||
internal static List<Record> DeleteEmptyDirectoriesAndGetCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, Configuration configuration, long ticks, string eDistanceContentDirectory, ReadOnlyDictionary<string, string> personKeyFormattedToNewestPersonKeyFormatted, ReadOnlyCollection<string> personKeyFormattedCollection)
|
||||
{
|
||||
List<Record> results = [];
|
||||
string @enum;
|
||||
Record record;
|
||||
string fileName;
|
||||
string checkFile;
|
||||
FilePath filePath;
|
||||
FileHolder fileHolder;
|
||||
int? wholePercentages;
|
||||
bool check;
|
||||
string message;
|
||||
string[] files;
|
||||
bool? isDefault;
|
||||
int? linksCount;
|
||||
int totalSeconds;
|
||||
DateTime dateTime;
|
||||
TimeSpan timeSpan;
|
||||
int directoryNumber;
|
||||
string? checkDirectory;
|
||||
ProgressBar progressBar;
|
||||
string[] yearDirectories;
|
||||
string personKeyFormatted;
|
||||
List<string> distinct = [];
|
||||
string? personFirstInitial;
|
||||
bool isReservedDirectoryName;
|
||||
string[] personNameDirectories;
|
||||
string? newestPersonKeyFormatted;
|
||||
string? personDisplayDirectoryName;
|
||||
string[] personNameLinkDirectories;
|
||||
string? personFirstInitialDirectory;
|
||||
List<TicksDirectory> ticksDirectories;
|
||||
string[] personKeyFormattedDirectories;
|
||||
string manualCopyHumanized = nameof(Shared.Models.Stateless.IMapLogic.ManualCopy).Humanize(LetterCasing.Title);
|
||||
string forceSingleImageHumanized = nameof(Shared.Models.Stateless.IMapLogic.ForceSingleImage).Humanize(LetterCasing.Title);
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
for (int i = 1; i < 6; i++)
|
||||
{
|
||||
check = false;
|
||||
results.Clear();
|
||||
distinct.Clear();
|
||||
directoryNumber = 0;
|
||||
ticksDirectories = UpdateDateVerifyAndGetTicksDirectories(configuration, eDistanceContentDirectory);
|
||||
totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
message = $"{i}) {ticksDirectories.Count:000} compile from and clean ticks Director(ies) - B - {totalSeconds} total second(s)";
|
||||
progressBar = new(ticksDirectories.Count, message, options);
|
||||
foreach (TicksDirectory ticksDirectory in ticksDirectories)
|
||||
{
|
||||
if (i == 1)
|
||||
progressBar.Tick();
|
||||
personKeyFormattedDirectories = Directory.GetDirectories(ticksDirectory.Directory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string personKeyFormattedDirectory in personKeyFormattedDirectories)
|
||||
{
|
||||
personKeyFormatted = Path.GetFileName(personKeyFormattedDirectory);
|
||||
isReservedDirectoryName = personKeyFormatted.StartsWith(nameof(Shared.Models.Stateless.IMapLogic.Sorting)) || personKeyFormatted.StartsWith(nameof(Shared.Models.Stateless.IMapLogic.Mapping)) || personKeyFormatted.StartsWith(nameof(Shared.Models.Stateless.IMapLogic.ManualCopy));
|
||||
if (!isReservedDirectoryName && personKeyFormatted.StartsWith(nameof(Shared.Models.Stateless.IMapLogic.Individually)))
|
||||
{
|
||||
Individually(configuration, ticksDirectory, personKeyFormattedDirectory);
|
||||
throw new Exception($"B) Move personKey directories up one from {nameof(Shared.Models.Stateless.IMapLogic.Sorting)} and delete {nameof(Shared.Models.Stateless.IMapLogic.Sorting)} directory!");
|
||||
}
|
||||
_ = personKeyFormattedToNewestPersonKeyFormatted.TryGetValue(personKeyFormatted, out newestPersonKeyFormatted);
|
||||
if (personKeyFormattedToNewestPersonKeyFormatted.Count > 0 && newestPersonKeyFormatted is null)
|
||||
{
|
||||
timeSpan = new TimeSpan(DateTime.Now.Ticks - ticksDirectory.DirectoryDateTime.Ticks);
|
||||
if (timeSpan.TotalDays > 6)
|
||||
throw new Exception($"{configuration.MappingDefaultName} <{ticksDirectory.DirectoryDateTime}> are only allowed within x days!");
|
||||
}
|
||||
yearDirectories = Directory.GetDirectories(personKeyFormattedDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string yearDirectory in yearDirectories)
|
||||
{
|
||||
if (check && !Directory.Exists(yearDirectory))
|
||||
continue;
|
||||
if (ticksDirectory.IsLocationContainerDebugDirectory is null || !ticksDirectory.IsLocationContainerDebugDirectory.Value)
|
||||
linksCount = null;
|
||||
else
|
||||
linksCount = GetLinksCount(yearDirectory);
|
||||
if (ticksDirectory.DirectoryName != configuration.LocationContainerDebugDirectory)
|
||||
{
|
||||
files = Directory.GetFiles(yearDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
}
|
||||
if (ticksDirectory.DirectoryName == configuration.LocationContainerDebugDirectory)
|
||||
{
|
||||
isDefault = null;
|
||||
personDisplayDirectoryName = null;
|
||||
files = Directory.GetFiles(yearDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
results.AddRange(GetRecords(propertyConfiguration, configuration, isDefault, files, directoryNumber, personKeyFormatted, linksCount, distinct, personDisplayDirectoryName));
|
||||
files = Directory.GetFiles(yearDirectory, "*.lnk", SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
continue;
|
||||
}
|
||||
personNameDirectories = Directory.GetDirectories(yearDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (personNameDirectories.Length > 1)
|
||||
throw new NotSupportedException("Try deleting *.lnk files!");
|
||||
foreach (string personNameDirectory in personNameDirectories)
|
||||
{
|
||||
directoryNumber++;
|
||||
personDisplayDirectoryName = Path.GetFileName(personNameDirectory);
|
||||
isDefault = IPerson.IsDefaultName(personDisplayDirectoryName) && IPersonBirthday.IsCounterPersonYear(personKeyFormatted[..4]);
|
||||
if (isDefault.Value && personDisplayDirectoryName.Length == 1)
|
||||
{
|
||||
if (personKeyFormatted.Length != configuration.PersonBirthdayFormat.Length || !DateTime.TryParseExact(personKeyFormatted, configuration.PersonBirthdayFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||
continue;
|
||||
checkDirectory = Path.Combine(yearDirectory, $"X+{dateTime.Ticks}");
|
||||
if (Directory.Exists(checkDirectory))
|
||||
{
|
||||
Directory.Delete(yearDirectory, recursive: true);
|
||||
continue;
|
||||
}
|
||||
Directory.Move(personNameDirectory, checkDirectory);
|
||||
if (!check)
|
||||
check = true;
|
||||
continue;
|
||||
}
|
||||
if (isDefault.Value && (ticksDirectory.DirectoryDateTime.Hour != 0 || ticksDirectory.DirectoryDateTime.Minute != 0 || ticksDirectory.DirectoryDateTime.Second != 0))
|
||||
{
|
||||
checkDirectory = Path.GetDirectoryName(ticksDirectory.Directory);
|
||||
if (checkDirectory is null)
|
||||
continue;
|
||||
checkDirectory = Path.Combine(checkDirectory, ticksDirectory.AlternateDirectoryDateTime.Ticks.ToString());
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
checkDirectory = Path.Combine(checkDirectory, personKeyFormatted);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
{
|
||||
Directory.Move(personKeyFormattedDirectory, checkDirectory);
|
||||
if (!check)
|
||||
check = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
files = Directory.GetFiles(personNameDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (isReservedDirectoryName && files.Length > 0)
|
||||
throw new Exception($"Move personKey directories up one from {nameof(Shared.Models.Stateless.IMapLogic.Sorting)} and delete {nameof(Shared.Models.Stateless.IMapLogic.Sorting)} directory!");
|
||||
if (personKeyFormatted == manualCopyHumanized && files.Length > 0)
|
||||
throw new Exception($"Move personKey directories up one from {manualCopyHumanized} and delete {manualCopyHumanized} directory!");
|
||||
if (personKeyFormatted == forceSingleImageHumanized && files.Length > 0)
|
||||
throw new Exception($"Move personKey directories up one from {forceSingleImageHumanized} and delete {forceSingleImageHumanized} directory!");
|
||||
if (!isDefault.Value)
|
||||
{
|
||||
if (personKeyFormattedToNewestPersonKeyFormatted.Count > 0 && newestPersonKeyFormatted is null)
|
||||
files = RenameBirth(files);
|
||||
else if (newestPersonKeyFormatted is not null && personKeyFormatted != newestPersonKeyFormatted)
|
||||
{
|
||||
if (!check)
|
||||
check = true;
|
||||
MovedToNewestPersonKeyFormatted(personKeyFormatted, newestPersonKeyFormatted, ticksDirectory, personKeyFormattedDirectory);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (personKeyFormatted.Length != configuration.PersonBirthdayFormat.Length)
|
||||
continue;
|
||||
if (personDisplayDirectoryName.Length == 1 || isDefault.Value || !personKeyFormattedCollection.Contains(personKeyFormatted))
|
||||
personFirstInitialDirectory = personNameDirectory;
|
||||
else
|
||||
{
|
||||
personFirstInitial = personDisplayDirectoryName[..1];
|
||||
if (personFirstInitial.All(char.IsDigit))
|
||||
{
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
files = Directory.GetFiles(personNameDirectory, "*", SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
_ = IPath.DeleteEmptyDirectories(personNameDirectory);
|
||||
continue;
|
||||
}
|
||||
personFirstInitialDirectory = Path.Combine(yearDirectory, personFirstInitial.ToString());
|
||||
if (Directory.Exists(personFirstInitialDirectory))
|
||||
throw new Exception("Forgot to ...");
|
||||
Directory.Move(personNameDirectory, personFirstInitialDirectory);
|
||||
files = Directory.GetFiles(personFirstInitialDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
}
|
||||
results.AddRange(GetRecords(propertyConfiguration, configuration, isDefault, files, directoryNumber, personKeyFormatted, linksCount, distinct, personDisplayDirectoryName));
|
||||
personNameLinkDirectories = Directory.GetDirectories(personFirstInitialDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string personNameLinkDirectory in personNameLinkDirectories)
|
||||
{
|
||||
files = Directory.GetFiles(personNameLinkDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (file.EndsWith(".lnk"))
|
||||
continue;
|
||||
fileHolder = IFileHolder.Get(file);
|
||||
filePath = FilePath.Get(propertyConfiguration, fileHolder, index: null);
|
||||
if (filePath.Id is null)
|
||||
continue;
|
||||
wholePercentages = IMapping.GetWholePercentages(configuration.FacesFileNameExtension, filePath);
|
||||
if (wholePercentages is null)
|
||||
continue;
|
||||
fileName = Path.GetFileName(file);
|
||||
if (distinct.Contains(fileName))
|
||||
{
|
||||
checkFile = $"{file}.dup";
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(file, checkFile);
|
||||
if (!file.EndsWith(".lnk"))
|
||||
continue;
|
||||
File.Delete(file);
|
||||
}
|
||||
if (file.StartsWith(ticksDirectory.Directory))
|
||||
{
|
||||
@enum = IPath.GetEnum(filePath).ToString();
|
||||
if (!ticksDirectory.Directory.EndsWith(@enum))
|
||||
{
|
||||
checkFile = GetCheckFile(ticksDirectory, @enum, fileName, file);
|
||||
fileHolder = IFileHolder.Get(checkFile);
|
||||
filePath = FilePath.Get(propertyConfiguration, fileHolder, index: null);
|
||||
if (filePath.Id is null)
|
||||
_ = IPath.DeleteEmptyDirectories(personNameLinkDirectory);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(personFirstInitialDirectory);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(yearDirectory);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(personKeyFormattedDirectory);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(ticksDirectory.Directory);
|
||||
_ = IPath.DeleteEmptyDirectories(ticksDirectory.Directory);
|
||||
}
|
||||
progressBar.Dispose();
|
||||
if (check)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
distinct.Add(fileName);
|
||||
record = new(DirectoryNumber: directoryNumber,
|
||||
IsDefault: isDefault,
|
||||
LinksCount: linksCount,
|
||||
MappedFaceFilePath: filePath,
|
||||
PersonDisplayDirectoryName: personDisplayDirectoryName,
|
||||
PersonKeyFormatted: personKeyFormatted);
|
||||
results.Add(record);
|
||||
break;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static string GetCheckFile(TicksDirectory ticksDirectory, string @enum, string fileName, string file)
|
||||
{
|
||||
string result;
|
||||
string checkDirectory;
|
||||
string directory = file;
|
||||
List<string> collection = [];
|
||||
for (int i = 0; i < file.Length; i++)
|
||||
{
|
||||
directory = Path.GetDirectoryName(directory) ?? throw new Exception();
|
||||
if (directory == ticksDirectory.Directory)
|
||||
break;
|
||||
collection.Add(Path.GetFileName(directory));
|
||||
}
|
||||
collection.Reverse();
|
||||
checkDirectory = $"{ticksDirectory.Directory}.{@enum}";
|
||||
foreach (string directoryName in collection)
|
||||
checkDirectory = Path.Combine(checkDirectory, directoryName);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
result = Path.Combine(checkDirectory, fileName);
|
||||
if (File.Exists(result))
|
||||
throw new Exception($"File <{fileName}> already exists!");
|
||||
File.Move(file, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -64,7 +64,8 @@ internal abstract class FaceFileLogic
|
||||
exifDirectory = Metadata.Models.Stateless.Methods.IMetadata.GetExifDirectory(mappedFile.FilePath);
|
||||
RectangleF? rectangle = ILocation.GetPercentagesRectangle(configuration.LocationDigits, wholePercentages.Value);
|
||||
personDisplayDirectoryName = mappedFile.PersonDisplayDirectoryName is null ? configuration.MappingDefaultName : mappedFile.PersonDisplayDirectoryName;
|
||||
LocationContainer locationContainer = new(dateOnly,
|
||||
lock (locationContainers)
|
||||
locationContainers.Add(new(dateOnly,
|
||||
exifDirectory,
|
||||
mappedFile.DirectoryNumber,
|
||||
personDisplayDirectoryName,
|
||||
@ -77,9 +78,7 @@ internal abstract class FaceFileLogic
|
||||
null,
|
||||
mappedFile.PersonKey,
|
||||
rectangle,
|
||||
wholePercentages.Value);
|
||||
lock (locationContainers)
|
||||
locationContainers.Add(locationContainer);
|
||||
wholePercentages.Value));
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<int, ReadOnlyDictionary<int, LocationContainer>> GetReadOnly(Dictionary<int, Dictionary<int, LocationContainer>> keyValuePairs)
|
||||
@ -87,33 +86,40 @@ internal abstract class FaceFileLogic
|
||||
Dictionary<int, ReadOnlyDictionary<int, LocationContainer>> results = [];
|
||||
foreach (KeyValuePair<int, Dictionary<int, LocationContainer>> keyValuePair in keyValuePairs)
|
||||
results.Add(keyValuePair.Key, new(keyValuePair.Value));
|
||||
return results.AsReadOnly();
|
||||
return new(results);
|
||||
}
|
||||
|
||||
internal static ReadOnlyDictionary<int, ReadOnlyDictionary<int, LocationContainer>> GetMapped(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, Configuration configuration, long ticks, ReadOnlyCollection<PersonContainer> personContainers, string a2PeopleSingletonDirectory, string eDistanceContentDirectory)
|
||||
{
|
||||
Dictionary<int, Dictionary<int, LocationContainer>> results = [];
|
||||
List<LocationContainer> locationContainers = [];
|
||||
List<string> personKeyFormattedCollection = [];
|
||||
Dictionary<int, LocationContainer>? keyValuePairs;
|
||||
Dictionary<int, List<(string, int)>> skipCollection = [];
|
||||
Dictionary<int, List<(string, int)>> skipNotSkipCollection = [];
|
||||
Dictionary<string, string> personKeyFormattedToNewestPersonKeyFormatted = [];
|
||||
ReadOnlyCollection<string> readOnlyPersonKeyFormattedCollection;
|
||||
ReadOnlyDictionary<string, string> readOnlyPersonKeyFormattedToNewestPersonKeyFormatted;
|
||||
SetSkipCollections(configuration, personContainers, a2PeopleSingletonDirectory, skipCollection, skipNotSkipCollection);
|
||||
SetPersonCollectionsAfterSetSkipCollections(configuration, personContainers, personKeyFormattedToNewestPersonKeyFormatted, personKeyFormattedCollection);
|
||||
List<Record> records = DistanceLogic.DeleteEmptyDirectoriesAndGetCollection(propertyConfiguration, configuration, ticks, eDistanceContentDirectory, personKeyFormattedToNewestPersonKeyFormatted.AsReadOnly(), personKeyFormattedCollection.AsReadOnly());
|
||||
{
|
||||
List<string> personKeyFormattedCollection = [];
|
||||
Dictionary<string, string> personKeyFormattedToNewestPersonKeyFormatted = [];
|
||||
SetPersonCollections(configuration, personContainers, personKeyFormattedToNewestPersonKeyFormatted, personKeyFormattedCollection);
|
||||
readOnlyPersonKeyFormattedCollection = new(personKeyFormattedCollection);
|
||||
readOnlyPersonKeyFormattedToNewestPersonKeyFormatted = new(personKeyFormattedToNewestPersonKeyFormatted);
|
||||
}
|
||||
List<Record> records = DistanceLogic.DeleteEmptyDirectoriesAndGetCollection(propertyConfiguration, configuration, ticks, eDistanceContentDirectory, readOnlyPersonKeyFormattedToNewestPersonKeyFormatted, readOnlyPersonKeyFormattedCollection);
|
||||
List<MappedFile> mappedFiles = GetMappedFiles(propertyConfiguration, configuration, personContainers, records);
|
||||
if (mappedFiles.Count > 0)
|
||||
{
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string message = $") Building Mapped Face Files Collection - {totalSeconds} total second(s)";
|
||||
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = maxDegreeOfParallelism };
|
||||
ReadOnlyDictionary<int, List<(string, int)>> readOnlySkipNotSkipCollection = new(skipCollection);
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
using ProgressBar progressBar = new(mappedFiles.Count, message, options);
|
||||
_ = Parallel.For(0, mappedFiles.Count, parallelOptions, (i, state) =>
|
||||
{
|
||||
progressBar.Tick();
|
||||
MappedParallelFor(propertyConfiguration, configuration, skipCollection.AsReadOnly(), locationContainers, mappedFiles[i]);
|
||||
MappedParallelFor(propertyConfiguration, configuration, readOnlySkipNotSkipCollection, locationContainers, mappedFiles[i]);
|
||||
});
|
||||
}
|
||||
foreach (LocationContainer locationContainer in locationContainers)
|
||||
@ -170,7 +176,8 @@ internal abstract class FaceFileLogic
|
||||
RectangleF? rectangle = ILocation.GetPercentagesRectangle(configuration.LocationDigits, wholePercentages.Value);
|
||||
if (rectangle is null)
|
||||
return;
|
||||
LocationContainer locationContainer = new(dateOnly,
|
||||
lock (locationContainers)
|
||||
locationContainers.Add(new(dateOnly,
|
||||
exifDirectory,
|
||||
null,
|
||||
null,
|
||||
@ -183,9 +190,7 @@ internal abstract class FaceFileLogic
|
||||
null,
|
||||
null,
|
||||
rectangle,
|
||||
wholePercentages.Value);
|
||||
lock (locationContainers)
|
||||
locationContainers.Add(locationContainer);
|
||||
wholePercentages.Value));
|
||||
}
|
||||
|
||||
internal static List<LocationContainer> GetAvailable(int maxDegreeOfParallelism, Configuration configuration, IFaceD dFace, long ticks, ReadOnlyCollection<FilePath> filePaths)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,93 +7,69 @@ namespace View_by_Distance.Map.Models.Stateless.Methods;
|
||||
public interface IMapLogic
|
||||
{
|
||||
|
||||
static string Get(bool saveIndividually, string forceSingleImageHumanized, int by, bool isDefaultName) =>
|
||||
$"{by switch
|
||||
{
|
||||
Shared.Models.Stateless.IMapLogic.Mapping => nameof(Shared.Models.Stateless.IMapLogic.Mapping),
|
||||
Shared.Models.Stateless.IMapLogic.Sorting => saveIndividually ?
|
||||
nameof(Shared.Models.Stateless.IMapLogic.Individually) :
|
||||
nameof(Shared.Models.Stateless.IMapLogic.Sorting),
|
||||
Shared.Models.Stateless.IMapLogic.ForceSingleImage => forceSingleImageHumanized,
|
||||
_ => throw new NotImplementedException()
|
||||
}}{(!isDefaultName ? "-A" : "-Z")}";
|
||||
|
||||
public static Mapping[] GetSelectedMappingCollection(ReadOnlyCollection<Item> items) =>
|
||||
MapLogic.GetSelectedMappingCollection(items);
|
||||
|
||||
public static Mapping[] GetSelectedMappingCollection(ReadOnlyCollection<Face> faces) =>
|
||||
MapLogic.GetSelectedMappingCollection(faces);
|
||||
|
||||
public static bool? CanReMap(long[] jLinkResolvedPersonKeys, ReadOnlyDictionary<int, ReadOnlyCollection<PersonContainer>>? wholePercentagesToPersonContainers, int wholePercentages) =>
|
||||
MapLogic.CanReMap(jLinkResolvedPersonKeys, wholePercentagesToPersonContainers, wholePercentages);
|
||||
|
||||
public static bool? CanReMap(long[] jLinkResolvedPersonKeys, ReadOnlyDictionary<int, ReadOnlyCollection<PersonContainer>>? wholePercentagesToPersonContainers, MappingFromLocation mappingFromLocation) =>
|
||||
MapLogic.CanReMap(jLinkResolvedPersonKeys, wholePercentagesToPersonContainers, mappingFromLocation.WholePercentages);
|
||||
|
||||
public static string GetDecade(MappingFromItem mappingFromItem) =>
|
||||
DecadeLogic.GetDecade(mappingFromItem, null);
|
||||
|
||||
public static ReadOnlyCollection<Face> GetFaces(ReadOnlyCollection<Item> items) =>
|
||||
MapLogic.GetFaces(items);
|
||||
|
||||
public static ReadOnlyDictionary<int, List<long>> GetIdToPersonKeys(ReadOnlyDictionary<long, List<int>> personKeyToIds) =>
|
||||
ReadOnlyDictionary<int, List<long>> TestStatic_GetIdToPersonKeys(ReadOnlyDictionary<long, List<int>> personKeyToIds) =>
|
||||
GetIdToPersonKeys(personKeyToIds);
|
||||
static ReadOnlyDictionary<int, List<long>> GetIdToPersonKeys(ReadOnlyDictionary<long, List<int>> personKeyToIds) =>
|
||||
MapLogic.GetIdToPersonKeys(personKeyToIds);
|
||||
|
||||
public static void SetCreationTime(MappingFromItem mappingFromItem, ReadOnlyCollection<LocationContainer> locationContainers) =>
|
||||
DecadeLogic.SetCreationTime(mappingFromItem, locationContainers);
|
||||
ReadOnlyCollection<Face> TestStatic_GetFaces(ReadOnlyCollection<Item> items) =>
|
||||
GetFaces(items);
|
||||
static ReadOnlyCollection<Face> GetFaces(ReadOnlyCollection<Item> items) =>
|
||||
MapLogic.GetFaces(items);
|
||||
|
||||
public static ReadOnlyDictionary<int, ReadOnlyDictionary<int, Mapping>> GetIdToWholePercentagesToFace(ReadOnlyCollection<Mapping> distinctValidImageMappingCollection) =>
|
||||
Mapping[] TestStatic_GetSelectedMappingCollection(ReadOnlyCollection<Item> items) =>
|
||||
GetSelectedMappingCollection(items);
|
||||
static Mapping[] GetSelectedMappingCollection(ReadOnlyCollection<Item> items) =>
|
||||
MapLogic.GetSelectedMappingCollection(items);
|
||||
|
||||
Mapping[] TestStatic_GetSelectedMappingCollection(ReadOnlyCollection<Face> faces) =>
|
||||
GetSelectedMappingCollection(faces);
|
||||
static Mapping[] GetSelectedMappingCollection(ReadOnlyCollection<Face> faces) =>
|
||||
MapLogic.GetSelectedMappingCollection(faces);
|
||||
|
||||
ReadOnlyDictionary<int, ReadOnlyDictionary<int, Mapping>> TestStatic_GetIdToWholePercentagesToFace(ReadOnlyCollection<Mapping> distinctValidImageMappingCollection) =>
|
||||
GetIdToWholePercentagesToFace(distinctValidImageMappingCollection);
|
||||
static ReadOnlyDictionary<int, ReadOnlyDictionary<int, Mapping>> GetIdToWholePercentagesToFace(ReadOnlyCollection<Mapping> distinctValidImageMappingCollection) =>
|
||||
MapLogic.GetIdToWholePercentagesToFace(distinctValidImageMappingCollection);
|
||||
|
||||
public static List<LocationContainer> GetAvailable(int maxDegreeOfParallelism, Configuration configuration, IFaceD dFace, long ticks, ReadOnlyCollection<FilePath> filePaths) =>
|
||||
FaceFileLogic.GetAvailable(maxDegreeOfParallelism, configuration, dFace, ticks, filePaths);
|
||||
|
||||
public static void MoveToDecade(Property.Models.Configuration propertyConfiguration, MappingFromItem mappingFromItem, ReadOnlyCollection<LocationContainer> locationContainers) =>
|
||||
DecadeLogic.MoveToDecade(propertyConfiguration, mappingFromItem, locationContainers);
|
||||
|
||||
public static List<(string, long)> GetJLinkDirectories(string genealogicalDataCommunicationFile, string[] jLinks, string personBirthdayFormat, char[] personCharacters, string a2PeopleSingletonDirectory, string a2PeopleContentDirectory) =>
|
||||
List<(string, long)> TestStatic_GetJLinkDirectories(string genealogicalDataCommunicationFile, string[] jLinks, string personBirthdayFormat, char[] personCharacters, string a2PeopleSingletonDirectory, string a2PeopleContentDirectory) =>
|
||||
GetJLinkDirectories(genealogicalDataCommunicationFile, jLinks, personBirthdayFormat, personCharacters, a2PeopleSingletonDirectory, a2PeopleContentDirectory);
|
||||
static List<(string, long)> GetJLinkDirectories(string genealogicalDataCommunicationFile, string[] jLinks, string personBirthdayFormat, char[] personCharacters, string a2PeopleSingletonDirectory, string a2PeopleContentDirectory) =>
|
||||
MapLogic.GetJLinkDirectories(genealogicalDataCommunicationFile, jLinks, personBirthdayFormat, personCharacters, a2PeopleSingletonDirectory, a2PeopleContentDirectory);
|
||||
|
||||
public static ReadOnlyDictionary<int, ReadOnlyDictionary<int, LocationContainer>> GetMapped(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, Configuration configuration, long ticks, ReadOnlyCollection<PersonContainer> personContainers, string a2PeopleSingletonDirectory, string eDistanceContentDirectory) =>
|
||||
void TestStatic_SetCreationTime(MappingFromItem mappingFromItem, ReadOnlyCollection<LocationContainer> locationContainers) =>
|
||||
SetCreationTime(mappingFromItem, locationContainers);
|
||||
static void SetCreationTime(MappingFromItem mappingFromItem, ReadOnlyCollection<LocationContainer> locationContainers) =>
|
||||
DecadeLogic.SetCreationTime(mappingFromItem, locationContainers);
|
||||
|
||||
void TestStatic_MoveToDecade(Property.Models.Configuration propertyConfiguration, MappingFromItem mappingFromItem, ReadOnlyCollection<LocationContainer> locationContainers) =>
|
||||
MoveToDecade(propertyConfiguration, mappingFromItem, locationContainers);
|
||||
static void MoveToDecade(Property.Models.Configuration propertyConfiguration, MappingFromItem mappingFromItem, ReadOnlyCollection<LocationContainer> locationContainers) =>
|
||||
DecadeLogic.MoveToDecade(propertyConfiguration, mappingFromItem, locationContainers);
|
||||
|
||||
bool? TestStatic_CanReMap(long[] jLinkResolvedPersonKeys, ReadOnlyDictionary<int, ReadOnlyCollection<PersonContainer>>? wholePercentagesToPersonContainers, MappingFromLocation mappingFromLocation) =>
|
||||
CanReMap(jLinkResolvedPersonKeys, wholePercentagesToPersonContainers, mappingFromLocation);
|
||||
static bool? CanReMap(long[] jLinkResolvedPersonKeys, ReadOnlyDictionary<int, ReadOnlyCollection<PersonContainer>>? wholePercentagesToPersonContainers, MappingFromLocation mappingFromLocation) =>
|
||||
MapLogic.CanReMap(jLinkResolvedPersonKeys, wholePercentagesToPersonContainers, mappingFromLocation.WholePercentages);
|
||||
|
||||
bool? TestStatic_CanReMap(long[] jLinkResolvedPersonKeys, ReadOnlyDictionary<int, ReadOnlyCollection<PersonContainer>>? wholePercentagesToPersonContainers, int wholePercentages) =>
|
||||
CanReMap(jLinkResolvedPersonKeys, wholePercentagesToPersonContainers, wholePercentages);
|
||||
static bool? CanReMap(long[] jLinkResolvedPersonKeys, ReadOnlyDictionary<int, ReadOnlyCollection<PersonContainer>>? wholePercentagesToPersonContainers, int wholePercentages) =>
|
||||
MapLogic.CanReMap(jLinkResolvedPersonKeys, wholePercentagesToPersonContainers, wholePercentages);
|
||||
|
||||
string TestStatic_GetDecade(MappingFromItem mappingFromItem) =>
|
||||
GetDecade(mappingFromItem);
|
||||
static string GetDecade(MappingFromItem mappingFromItem) =>
|
||||
DecadeLogic.GetDecade(mappingFromItem, null);
|
||||
|
||||
ReadOnlyDictionary<int, ReadOnlyDictionary<int, LocationContainer>> TestStatic_GetMappedFiles(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, Configuration configuration, long ticks, ReadOnlyCollection<PersonContainer> personContainers, string a2PeopleSingletonDirectory, string eDistanceContentDirectory) =>
|
||||
GetMapped(maxDegreeOfParallelism, propertyConfiguration, configuration, ticks, personContainers, a2PeopleSingletonDirectory, eDistanceContentDirectory);
|
||||
static ReadOnlyDictionary<int, ReadOnlyDictionary<int, LocationContainer>> GetMapped(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, Configuration configuration, long ticks, ReadOnlyCollection<PersonContainer> personContainers, string a2PeopleSingletonDirectory, string eDistanceContentDirectory) =>
|
||||
FaceFileLogic.GetMapped(maxDegreeOfParallelism, propertyConfiguration, configuration, ticks, personContainers, a2PeopleSingletonDirectory, eDistanceContentDirectory);
|
||||
|
||||
internal string TestStatic_GetDecade(MappingFromItem mappingFromItem) =>
|
||||
GetDecade(mappingFromItem);
|
||||
|
||||
internal ReadOnlyCollection<Face> TestStatic_GetFaces(ReadOnlyCollection<Item> items) =>
|
||||
GetFaces(items);
|
||||
|
||||
internal Mapping[] TestStatic_GetSelectedMappingCollection(ReadOnlyCollection<Item> items) =>
|
||||
GetSelectedMappingCollection(items);
|
||||
|
||||
internal Mapping[] TestStatic_GetSelectedMappingCollection(ReadOnlyCollection<Face> faces) =>
|
||||
GetSelectedMappingCollection(faces);
|
||||
|
||||
internal ReadOnlyDictionary<int, List<long>> TestStatic_GetIdToPersonKeys(ReadOnlyDictionary<long, List<int>> personKeyToIds) =>
|
||||
GetIdToPersonKeys(personKeyToIds);
|
||||
|
||||
internal void TestStatic_SetCreationTime(MappingFromItem mappingFromItem, ReadOnlyCollection<LocationContainer> locationContainers) =>
|
||||
SetCreationTime(mappingFromItem, locationContainers);
|
||||
|
||||
internal ReadOnlyDictionary<int, ReadOnlyDictionary<int, Mapping>> TestStatic_GetIdToWholePercentagesToFace(ReadOnlyCollection<Mapping> distinctValidImageMappingCollection) =>
|
||||
GetIdToWholePercentagesToFace(distinctValidImageMappingCollection);
|
||||
|
||||
internal List<LocationContainer> TestStatic_GetAvailable(int maxDegreeOfParallelism, Configuration configuration, IFaceD dFace, long ticks, ReadOnlyCollection<FilePath> filePaths) =>
|
||||
List<LocationContainer> TestStatic_GetAvailable(int maxDegreeOfParallelism, Configuration configuration, IFaceD dFace, long ticks, ReadOnlyCollection<FilePath> filePaths) =>
|
||||
GetAvailable(maxDegreeOfParallelism, configuration, dFace, ticks, filePaths);
|
||||
|
||||
internal void TestStatic_MoveToDecade(Property.Models.Configuration propertyConfiguration, MappingFromItem mappingFromItem, ReadOnlyCollection<LocationContainer> locationContainers) =>
|
||||
MoveToDecade(propertyConfiguration, mappingFromItem, locationContainers);
|
||||
|
||||
internal bool? TestStatic_CanReMap(long[] jLinkResolvedPersonKeys, ReadOnlyDictionary<int, ReadOnlyCollection<PersonContainer>>? wholePercentagesToPersonContainers, int wholePercentages) =>
|
||||
CanReMap(jLinkResolvedPersonKeys, wholePercentagesToPersonContainers, wholePercentages);
|
||||
|
||||
internal bool? TestStatic_CanReMap(long[] jLinkResolvedPersonKeys, ReadOnlyDictionary<int, ReadOnlyCollection<PersonContainer>>? wholePercentagesToPersonContainers, MappingFromLocation mappingFromLocation) =>
|
||||
CanReMap(jLinkResolvedPersonKeys, wholePercentagesToPersonContainers, mappingFromLocation);
|
||||
|
||||
internal List<(string, long)> TestStatic_GetJLinkDirectories(string genealogicalDataCommunicationFile, string[] jLinks, string personBirthdayFormat, char[] personCharacters, string a2PeopleSingletonDirectory, string a2PeopleContentDirectory) =>
|
||||
GetJLinkDirectories(genealogicalDataCommunicationFile, jLinks, personBirthdayFormat, personCharacters, a2PeopleSingletonDirectory, a2PeopleContentDirectory);
|
||||
|
||||
internal ReadOnlyDictionary<int, ReadOnlyDictionary<int, LocationContainer>> TestStatic_GetMappedFiles(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, Configuration configuration, long ticks, ReadOnlyCollection<PersonContainer> personContainers, string a2PeopleSingletonDirectory, string eDistanceContentDirectory) =>
|
||||
GetMapped(maxDegreeOfParallelism, propertyConfiguration, configuration, ticks, personContainers, a2PeopleSingletonDirectory, eDistanceContentDirectory);
|
||||
static List<LocationContainer> GetAvailable(int maxDegreeOfParallelism, Configuration configuration, IFaceD dFace, long ticks, ReadOnlyCollection<FilePath> filePaths) =>
|
||||
FaceFileLogic.GetAvailable(maxDegreeOfParallelism, configuration, dFace, ticks, filePaths);
|
||||
|
||||
}
|
@ -8,48 +8,36 @@ namespace View_by_Distance.Map.Models.Stateless;
|
||||
internal abstract class RelationLogic
|
||||
{
|
||||
|
||||
internal record Group(string Key,
|
||||
long PersonKey,
|
||||
ReadOnlyCollection<LocationContainer> RelationContainersCollection);
|
||||
internal record Group(string Key, long PersonKey, ReadOnlyCollection<LocationContainer> RelationContainersCollection);
|
||||
|
||||
internal static void SaveMappedRelations(Configuration configuration, Shared.Models.Methods.IDistance distance, string a2PeopleContentDirectory, string eDistanceContentDirectory, long ticks, List<LocationContainer> locationContainers, ReadOnlyDictionary<string, PersonContainer> readOnlyPersonKeyFormattedToPersonContainer, ReadOnlyDictionary<long, List<PersonContainer>> readOnlyPersonKeyToPersonContainerCollection)
|
||||
private static Dictionary<long, Dictionary<int, List<LocationContainer>>> GetPersonKeyTo(Configuration configuration, List<LocationContainer> locationContainers)
|
||||
{
|
||||
int take;
|
||||
string directory;
|
||||
bool isCounterPersonYear;
|
||||
string personKeyFormatted;
|
||||
string? displayDirectoryName;
|
||||
Uri uri = new(eDistanceContentDirectory);
|
||||
ReadOnlyDictionary<string, string> movedFiles;
|
||||
ReadOnlyCollection<RelationContainer> relationContainers;
|
||||
ReadOnlyCollection<Group> groups = GetGroups(configuration, locationContainers);
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string message = $") Save Mapped Relations - {totalSeconds} total second(s)";
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
using ProgressBar progressBar = new(groups.Count, message, options);
|
||||
foreach (Group group in groups)
|
||||
List<LocationContainer>? collection;
|
||||
Dictionary<int, List<LocationContainer>>? yearTo;
|
||||
Dictionary<long, Dictionary<int, List<LocationContainer>>> personKeyTo = [];
|
||||
foreach (LocationContainer locationContainer in locationContainers)
|
||||
{
|
||||
if (configuration.LocationContainerDistanceTolerance is null)
|
||||
break;
|
||||
progressBar.Tick();
|
||||
if (group.RelationContainersCollection.Count == 0)
|
||||
if (locationContainer.PersonKey is null)
|
||||
continue;
|
||||
take = GetTake(configuration.LocationContainerDistanceTake, group.RelationContainersCollection.Count);
|
||||
isCounterPersonYear = IPersonBirthday.IsCounterPersonYear(new DateTime(group.PersonKey).Year);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(configuration.PersonBirthdayFormat, group.PersonKey);
|
||||
displayDirectoryName = GetDisplayDirectoryName(readOnlyPersonKeyToPersonContainerCollection, readOnlyPersonKeyFormattedToPersonContainer, group.PersonKey, personKeyFormatted);
|
||||
directory = Path.Combine(a2PeopleContentDirectory, $"{ticks}-{configuration.LocationContainerDistanceTolerance.Value}", personKeyFormatted, group.Key);
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
WriteVsCodeFiles(eDistanceContentDirectory, displayDirectoryName, directory);
|
||||
relationContainers = distance.GetRelationContainers(configuration.DistanceLimits, configuration.FaceDistancePermyriad, configuration.LocationContainerDistanceTake, configuration.LocationContainerDistanceTolerance.Value, group.RelationContainersCollection);
|
||||
movedFiles = GetMoveFiles(configuration, group.Key, take, isCounterPersonYear, displayDirectoryName, relationContainers);
|
||||
WriteFile(take, group.PersonKey, isCounterPersonYear, personKeyFormatted, displayDirectoryName, directory, ticks, uri, relationContainers, movedFiles);
|
||||
if (!locationContainer.FromDistanceContent)
|
||||
continue;
|
||||
if (!locationContainer.FilePath.FullName.Contains(configuration.LocationContainerDirectoryPattern))
|
||||
continue;
|
||||
if (!personKeyTo.TryGetValue(locationContainer.PersonKey.Value, out yearTo))
|
||||
{
|
||||
personKeyTo.Add(locationContainer.PersonKey.Value, []);
|
||||
if (!personKeyTo.TryGetValue(locationContainer.PersonKey.Value, out yearTo))
|
||||
throw new Exception();
|
||||
}
|
||||
if (string.IsNullOrEmpty(configuration.LocationContainerDebugDirectory))
|
||||
_ = IPath.DeleteEmptyDirectories(eDistanceContentDirectory);
|
||||
else
|
||||
AddDisplayDirectoryNames(configuration, eDistanceContentDirectory, readOnlyPersonKeyFormattedToPersonContainer, readOnlyPersonKeyToPersonContainerCollection, groups);
|
||||
if (!yearTo.TryGetValue(locationContainer.CreationDateOnly.Year, out collection))
|
||||
{
|
||||
yearTo.Add(locationContainer.CreationDateOnly.Year, []);
|
||||
if (!yearTo.TryGetValue(locationContainer.CreationDateOnly.Year, out collection))
|
||||
throw new Exception();
|
||||
}
|
||||
collection.Add(locationContainer);
|
||||
}
|
||||
return personKeyTo;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<Group> GetGroups(Configuration configuration, List<LocationContainer> locationContainers)
|
||||
@ -94,127 +82,12 @@ internal abstract class RelationLogic
|
||||
locationContainer = collection[0];
|
||||
if (locationContainer.PersonKey is null)
|
||||
continue;
|
||||
results.Add(new(key, locationContainer.PersonKey.Value, collection.AsReadOnly()));
|
||||
results.Add(new(key, locationContainer.PersonKey.Value, new(collection)));
|
||||
collection = [];
|
||||
years.Clear();
|
||||
}
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static Dictionary<long, Dictionary<int, List<LocationContainer>>> GetPersonKeyTo(Configuration configuration, List<LocationContainer> locationContainers)
|
||||
{
|
||||
List<LocationContainer>? collection;
|
||||
Dictionary<int, List<LocationContainer>>? yearTo;
|
||||
Dictionary<long, Dictionary<int, List<LocationContainer>>> personKeyTo = [];
|
||||
foreach (LocationContainer locationContainer in locationContainers)
|
||||
{
|
||||
if (locationContainer.PersonKey is null)
|
||||
continue;
|
||||
if (!locationContainer.FromDistanceContent)
|
||||
continue;
|
||||
if (!locationContainer.FilePath.FullName.Contains(configuration.LocationContainerDirectoryPattern))
|
||||
continue;
|
||||
if (!personKeyTo.TryGetValue(locationContainer.PersonKey.Value, out yearTo))
|
||||
{
|
||||
personKeyTo.Add(locationContainer.PersonKey.Value, []);
|
||||
if (!personKeyTo.TryGetValue(locationContainer.PersonKey.Value, out yearTo))
|
||||
throw new Exception();
|
||||
}
|
||||
if (!yearTo.TryGetValue(locationContainer.CreationDateOnly.Year, out collection))
|
||||
{
|
||||
yearTo.Add(locationContainer.CreationDateOnly.Year, []);
|
||||
if (!yearTo.TryGetValue(locationContainer.CreationDateOnly.Year, out collection))
|
||||
throw new Exception();
|
||||
}
|
||||
collection.Add(locationContainer);
|
||||
}
|
||||
return personKeyTo;
|
||||
}
|
||||
|
||||
private static int GetTake(int locationContainerDistanceTake, int count)
|
||||
{
|
||||
int result = locationContainerDistanceTake;
|
||||
int subtract = (int)(locationContainerDistanceTake * .05);
|
||||
if (subtract < 1)
|
||||
subtract = 1;
|
||||
if (count > 9000)
|
||||
result -= subtract;
|
||||
if (count > 8000)
|
||||
result -= subtract;
|
||||
if (count > 7000)
|
||||
result -= subtract;
|
||||
if (count > 6000)
|
||||
result -= subtract;
|
||||
if (count > 5000)
|
||||
result -= subtract;
|
||||
if (count > 4000)
|
||||
result -= subtract;
|
||||
if (count > 3000)
|
||||
result -= subtract;
|
||||
if (count > 2000)
|
||||
result -= subtract;
|
||||
if (count > 1000)
|
||||
result -= subtract;
|
||||
if (result < 3)
|
||||
result = 3;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string? GetDisplayDirectoryName(ReadOnlyDictionary<long, List<PersonContainer>> readOnlyPersonKeyToPersonContainerCollection, ReadOnlyDictionary<string, PersonContainer> readOnlyPersonKeyFormattedToPersonContainer, long personKey, string personKeyFormatted)
|
||||
{
|
||||
string? result;
|
||||
PersonContainer? personContainer;
|
||||
List<PersonContainer>? collection;
|
||||
_ = readOnlyPersonKeyToPersonContainerCollection.TryGetValue(personKey, out collection);
|
||||
if (collection is not null)
|
||||
result = collection[0].DisplayDirectoryName;
|
||||
else
|
||||
{
|
||||
if (!readOnlyPersonKeyFormattedToPersonContainer.TryGetValue(personKeyFormatted, out personContainer))
|
||||
result = null;
|
||||
else
|
||||
result = personContainer.DisplayDirectoryName;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void WriteVsCodeFiles(string eDistanceContentDirectory, string? displayDirectoryName, string directory)
|
||||
{
|
||||
string json;
|
||||
string vsCodeDirectory = Path.Combine(directory, ".vscode");
|
||||
if (!Directory.Exists(vsCodeDirectory))
|
||||
_ = Directory.CreateDirectory(vsCodeDirectory);
|
||||
if (displayDirectoryName is not null)
|
||||
File.WriteAllText(Path.Combine(directory, $"_ {displayDirectoryName}.txt"), string.Empty);
|
||||
json = /*lang=json*/ """{ "[markdown]": { "editor.wordWrap": "off" }, "foam.links.hover.enable": false, "foam.graph.style": { "background": "#202020", "node": { "note": "#f2cb1d", "distance": "green", "image": "orange", "placeholder": "white", } } }""";
|
||||
_ = IPath.WriteAllText(Path.Combine(vsCodeDirectory, "settings.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
json = string.Concat("{ \"version\": \"2.0.0\", \"tasks\": [ { \"label\": \"MKLink\", \"type\": \"shell\", \"command\": \"New-Item\", \"args\": [ \"-ItemType\", \"Junction\", \"-Path\", \"'", directory.Replace('\\', '/'), "/()'\", \"-Target\", \"'", eDistanceContentDirectory.Replace('\\', '/'), "'\" ], \"problemMatcher\": [] } ] }");
|
||||
_ = IPath.WriteAllText(Path.Combine(vsCodeDirectory, "tasks.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<string, string> GetMoveFiles(Configuration configuration, string key, int take, bool isCounterPersonYear, string? displayDirectoryName, ReadOnlyCollection<RelationContainer> relationContainers)
|
||||
{
|
||||
ReadOnlyDictionary<string, string> results;
|
||||
List<List<string>> linked = [];
|
||||
for (int i = 0; i < 25; i++)
|
||||
linked.Add([]);
|
||||
foreach ((FileHolder fileHolder, ReadOnlyCollection<Relation> relations) in relationContainers)
|
||||
{
|
||||
foreach (Relation relation in relations.Take(take))
|
||||
{
|
||||
for (int i = 0; i < 25; i++)
|
||||
{
|
||||
if (!linked[i].Contains(relation.File))
|
||||
{
|
||||
linked[i].Add(relation.File);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
results = MoveFiles(configuration, key, isCounterPersonYear, displayDirectoryName, relationContainers, linked);
|
||||
return results;
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<string, string> MoveFiles(Configuration configuration, string key, bool isCounterPersonYear, string? displayDirectoryName, ReadOnlyCollection<RelationContainer> relationContainers, List<List<string>> linked)
|
||||
@ -231,7 +104,7 @@ internal abstract class RelationLogic
|
||||
string? personKeyFormattedDirectory;
|
||||
foreach ((FileHolder fileHolder, _) in relationContainers)
|
||||
{
|
||||
personNameDirectory = fileHolder.DirectoryFullPath;
|
||||
personNameDirectory = fileHolder.DirectoryName;
|
||||
yearDirectory = Path.GetDirectoryName(personNameDirectory);
|
||||
personNameDirectoryName = Path.GetFileName(personNameDirectory);
|
||||
personKeyFormattedDirectory = Path.GetDirectoryName(yearDirectory);
|
||||
@ -329,7 +202,92 @@ internal abstract class RelationLogic
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static string? GetDisplayDirectoryName(ReadOnlyDictionary<long, List<PersonContainer>> readOnlyPersonKeyToPersonContainerCollection, ReadOnlyDictionary<string, PersonContainer> readOnlyPersonKeyFormattedToPersonContainer, long personKey, string personKeyFormatted)
|
||||
{
|
||||
string? result;
|
||||
PersonContainer? personContainer;
|
||||
List<PersonContainer>? collection;
|
||||
_ = readOnlyPersonKeyToPersonContainerCollection.TryGetValue(personKey, out collection);
|
||||
if (collection is not null)
|
||||
result = collection[0].DisplayDirectoryName;
|
||||
else
|
||||
{
|
||||
if (!readOnlyPersonKeyFormattedToPersonContainer.TryGetValue(personKeyFormatted, out personContainer))
|
||||
result = null;
|
||||
else
|
||||
result = personContainer.DisplayDirectoryName;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int GetTake(int locationContainerDistanceTake, int count)
|
||||
{
|
||||
int result = locationContainerDistanceTake;
|
||||
int subtract = (int)(locationContainerDistanceTake * .05);
|
||||
if (subtract < 1)
|
||||
subtract = 1;
|
||||
if (count > 9000)
|
||||
result -= subtract;
|
||||
if (count > 8000)
|
||||
result -= subtract;
|
||||
if (count > 7000)
|
||||
result -= subtract;
|
||||
if (count > 6000)
|
||||
result -= subtract;
|
||||
if (count > 5000)
|
||||
result -= subtract;
|
||||
if (count > 4000)
|
||||
result -= subtract;
|
||||
if (count > 3000)
|
||||
result -= subtract;
|
||||
if (count > 2000)
|
||||
result -= subtract;
|
||||
if (count > 1000)
|
||||
result -= subtract;
|
||||
if (result < 3)
|
||||
result = 3;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void WriteVsCodeFiles(string eDistanceContentDirectory, string? displayDirectoryName, string directory)
|
||||
{
|
||||
string json;
|
||||
string vsCodeDirectory = Path.Combine(directory, ".vscode");
|
||||
if (!Directory.Exists(vsCodeDirectory))
|
||||
_ = Directory.CreateDirectory(vsCodeDirectory);
|
||||
if (displayDirectoryName is not null)
|
||||
File.WriteAllText(Path.Combine(directory, $"_ {displayDirectoryName}.txt"), string.Empty);
|
||||
json = /*lang=json*/ """{ "[markdown]": { "editor.wordWrap": "off" }, "foam.links.hover.enable": false, "foam.graph.style": { "background": "#202020", "node": { "note": "#f2cb1d", "distance": "green", "image": "orange", "placeholder": "white", } } }""";
|
||||
_ = IPath.WriteAllText(Path.Combine(vsCodeDirectory, "settings.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
json = string.Concat("{ \"version\": \"2.0.0\", \"tasks\": [ { \"label\": \"MKLink\", \"type\": \"shell\", \"command\": \"New-Item\", \"args\": [ \"-ItemType\", \"Junction\", \"-Path\", \"'", directory.Replace('\\', '/'), "/()'\", \"-Target\", \"'", eDistanceContentDirectory.Replace('\\', '/'), "'\" ], \"problemMatcher\": [] } ] }");
|
||||
_ = IPath.WriteAllText(Path.Combine(vsCodeDirectory, "tasks.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<string, string> GetMoveFiles(Configuration configuration, string key, int take, bool isCounterPersonYear, string? displayDirectoryName, ReadOnlyCollection<RelationContainer> relationContainers)
|
||||
{
|
||||
ReadOnlyDictionary<string, string> results;
|
||||
List<List<string>> linked = [];
|
||||
for (int i = 0; i < 25; i++)
|
||||
linked.Add([]);
|
||||
foreach ((FileHolder fileHolder, ReadOnlyCollection<Relation> relations) in relationContainers)
|
||||
{
|
||||
foreach (Relation relation in relations.Take(take))
|
||||
{
|
||||
for (int i = 0; i < 25; i++)
|
||||
{
|
||||
if (!linked[i].Contains(relation.File))
|
||||
{
|
||||
linked[i].Add(relation.File);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
results = MoveFiles(configuration, key, isCounterPersonYear, displayDirectoryName, relationContainers, linked);
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void WriteFile(int take, long personKey, bool isCounterPersonYear, string personKeyFormatted, string? displayDirectoryName, string directory, long ticks, Uri uri, ReadOnlyCollection<RelationContainer> relationContainers, ReadOnlyDictionary<string, string> movedFiles)
|
||||
@ -440,4 +398,44 @@ internal abstract class RelationLogic
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SaveMappedRelations(Configuration configuration, Shared.Models.Methods.IDistance distance, string a2PeopleContentDirectory, string eDistanceContentDirectory, long ticks, List<LocationContainer> locationContainers, ReadOnlyDictionary<string, PersonContainer> readOnlyPersonKeyFormattedToPersonContainer, ReadOnlyDictionary<long, List<PersonContainer>> readOnlyPersonKeyToPersonContainerCollection)
|
||||
{
|
||||
int take;
|
||||
string directory;
|
||||
bool isCounterPersonYear;
|
||||
string personKeyFormatted;
|
||||
string? displayDirectoryName;
|
||||
Uri uri = new(eDistanceContentDirectory);
|
||||
ReadOnlyDictionary<string, string> movedFiles;
|
||||
ReadOnlyCollection<RelationContainer> relationContainers;
|
||||
ReadOnlyCollection<Group> groups = GetGroups(configuration, locationContainers);
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string message = $") Save Mapped Relations - {totalSeconds} total second(s)";
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
using ProgressBar progressBar = new(groups.Count, message, options);
|
||||
foreach (Group group in groups)
|
||||
{
|
||||
if (configuration.LocationContainerDistanceTolerance is null)
|
||||
break;
|
||||
progressBar.Tick();
|
||||
if (group.RelationContainersCollection.Count == 0)
|
||||
continue;
|
||||
take = GetTake(configuration.LocationContainerDistanceTake, group.RelationContainersCollection.Count);
|
||||
isCounterPersonYear = IPersonBirthday.IsCounterPersonYear(new DateTime(group.PersonKey).Year);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(configuration.PersonBirthdayFormat, group.PersonKey);
|
||||
displayDirectoryName = GetDisplayDirectoryName(readOnlyPersonKeyToPersonContainerCollection, readOnlyPersonKeyFormattedToPersonContainer, group.PersonKey, personKeyFormatted);
|
||||
directory = Path.Combine(a2PeopleContentDirectory, $"{ticks}-{configuration.LocationContainerDistanceTolerance.Value}", personKeyFormatted, group.Key);
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
WriteVsCodeFiles(eDistanceContentDirectory, displayDirectoryName, directory);
|
||||
relationContainers = distance.GetRelationContainers(configuration.DistanceLimits, configuration.FaceDistancePermyriad, configuration.LocationContainerDistanceTake, configuration.LocationContainerDistanceTolerance.Value, group.RelationContainersCollection);
|
||||
movedFiles = GetMoveFiles(configuration, group.Key, take, isCounterPersonYear, displayDirectoryName, relationContainers);
|
||||
WriteFile(take, group.PersonKey, isCounterPersonYear, personKeyFormatted, displayDirectoryName, directory, ticks, uri, relationContainers, movedFiles);
|
||||
}
|
||||
if (string.IsNullOrEmpty(configuration.LocationContainerDebugDirectory))
|
||||
_ = IPath.DeleteEmptyDirectories(eDistanceContentDirectory);
|
||||
else
|
||||
AddDisplayDirectoryNames(configuration, eDistanceContentDirectory, readOnlyPersonKeyFormattedToPersonContainer, readOnlyPersonKeyToPersonContainerCollection, groups);
|
||||
}
|
||||
|
||||
}
|
@ -4,13 +4,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<UserSecretsId>f89b7242-dbb0-4349-b950-657eb8cf87ef</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Metadata.Query</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -35,10 +35,10 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
|
@ -34,15 +34,17 @@ public class Configuration
|
||||
}
|
||||
}
|
||||
|
||||
private static Models.Configuration Get(Configuration? configuration, Property.Models.Configuration propertyConfiguration)
|
||||
private static Models.Configuration Get(Configuration? configuration)
|
||||
{
|
||||
Models.Configuration result;
|
||||
if (configuration is null) throw new NullReferenceException(nameof(configuration));
|
||||
if (configuration.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.PersonBirthdayFormat is null) throw new NullReferenceException(nameof(configuration.PersonBirthdayFormat));
|
||||
result = new(propertyConfiguration,
|
||||
if (configuration.PropertyConfiguration is null) throw new NullReferenceException(nameof(configuration.PropertyConfiguration));
|
||||
result = new(
|
||||
configuration.IgnoreExtensions,
|
||||
configuration.PersonBirthdayFormat);
|
||||
configuration.PersonBirthdayFormat,
|
||||
configuration.PropertyConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -64,7 +66,7 @@ public class Configuration
|
||||
#pragma warning restore IL3050, IL2026
|
||||
}
|
||||
PreVerify(configurationRoot, configuration);
|
||||
result = Get(configuration, propertyConfiguration);
|
||||
result = Get(configuration);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,10 @@ public class Configuration
|
||||
public Property.Models.Configuration PropertyConfiguration => _PropertyConfiguration;
|
||||
|
||||
[JsonConstructor]
|
||||
public Configuration(Property.Models.Configuration propertyConfiguration,
|
||||
public Configuration(
|
||||
string[] ignoreExtensions,
|
||||
string personBirthdayFormat)
|
||||
string personBirthdayFormat,
|
||||
Property.Models.Configuration propertyConfiguration)
|
||||
{
|
||||
IgnoreExtensions = ignoreExtensions;
|
||||
PersonBirthdayFormat = personBirthdayFormat;
|
||||
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Metadata</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -34,10 +34,10 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -4,7 +4,6 @@ using System.Text.Json;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
using View_by_Distance.Shared.Models.Properties;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
namespace View_by_Distance.Metadata.Models;
|
||||
|
||||
@ -14,103 +13,33 @@ namespace View_by_Distance.Metadata.Models;
|
||||
public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
||||
{
|
||||
|
||||
public string DateGroupDirectory { get; init; }
|
||||
public ReadOnlyCollection<FilePath> Collection { get; private set; }
|
||||
public ReadOnlyDictionary<int, List<FilePath>> SingletonById { get; private set; }
|
||||
public ReadOnlyDictionary<int, ExifDirectory> ExifDirectoriesById { get; private set; }
|
||||
|
||||
// First
|
||||
// Set DateGroupDirectory
|
||||
// Create a directories for Singleton
|
||||
// Populate Collection
|
||||
// Populate Singleton
|
||||
// Populate existing ExifDirectories
|
||||
// Run similar for resize
|
||||
// Second
|
||||
// Populate needed ExifDirectories Dictionary can't be init only
|
||||
|
||||
private readonly bool _PropertiesChangedForMetadata;
|
||||
private readonly IPropertyConfiguration _PropertyConfiguration;
|
||||
private readonly bool _ForceMetadataLastWriteTimeToCreationTime;
|
||||
private readonly ReadOnlyDictionary<string, string[]> _FileGroups;
|
||||
private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions;
|
||||
private readonly ReadOnlyDictionary<byte, ReadOnlyCollection<string>>[] _ResultSingletonFileGroups;
|
||||
|
||||
public B_Metadata(IDlibDotNet? dlibDotNet, IPropertyConfiguration propertyConfiguration, bool forceMetadataLastWriteTimeToCreationTime, bool propertiesChangedForMetadata, long ticks, string bResultsFullGroupDirectory)
|
||||
public B_Metadata(IPropertyConfiguration propertyConfiguration)
|
||||
{
|
||||
_PropertiesChangedForMetadata = false;
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
_ForceMetadataLastWriteTimeToCreationTime = false;
|
||||
_WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||
_FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, null, [propertyConfiguration.ResultSingleton]);
|
||||
}
|
||||
|
||||
public B_Metadata(IPropertyConfiguration propertyConfiguration, bool forceMetadataLastWriteTimeToCreationTime, bool propertiesChangedForMetadata, string bResultsFullGroupDirectory)
|
||||
{
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
_PropertiesChangedForMetadata = propertiesChangedForMetadata;
|
||||
_ForceMetadataLastWriteTimeToCreationTime = forceMetadataLastWriteTimeToCreationTime;
|
||||
_ResultSingletonFileGroups = [new(new Dictionary<byte, ReadOnlyCollection<string>>())];
|
||||
_WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||
ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePairs = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, bResultsFullGroupDirectory, [propertyConfiguration.ResultSingleton]);
|
||||
foreach (KeyValuePair<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
if (keyValuePair.Key == _PropertyConfiguration.ResultSingleton)
|
||||
_ResultSingletonFileGroups[0] = keyValuePair.Value;
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
List<ExifDirectory> results = [];
|
||||
string jsonGroupDirectory;
|
||||
const string extension = ".json";
|
||||
const string fileSearchFilter = "*";
|
||||
string filesCollectionRootDirectory;
|
||||
const string directorySearchFilter = "*";
|
||||
int maxDegreeOfParallelism = Environment.ProcessorCount;
|
||||
filesCollectionRootDirectory = propertyConfiguration.RootDirectory;
|
||||
Dictionary<int, ExifDirectory> exifDirectoriesById = [];
|
||||
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = maxDegreeOfParallelism };
|
||||
string jsonGroupSingletonDirectory = Path.Combine(bResultsFullGroupDirectory, propertyConfiguration.ResultSingleton);
|
||||
string jsonGroupCollectionDirectory = Path.Combine(bResultsFullGroupDirectory, propertyConfiguration.ResultCollection);
|
||||
ReadOnlyCollection<string> directories = new([jsonGroupSingletonDirectory, jsonGroupCollectionDirectory]);
|
||||
Shared.Models.Stateless.Methods.IPath.CreateDirectories(directories);
|
||||
ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection = IDirectory.GetFilePathCollections(propertyConfiguration, directorySearchFilter, fileSearchFilter, filesCollectionRootDirectory, useIgnoreExtensions: true, useCeilingAverage: false);
|
||||
ReadOnlyDictionary<int, List<FilePath>> fileNamesToFiles = FilePath.GetFilesKeyValuePairs(filePathsCollection);
|
||||
ReadOnlyCollection<FilePair> filePairs = IFilePair.GetFilePairs(propertyConfiguration, directorySearchFilter, extension, jsonGroupSingletonDirectory, filePathsCollection, fileNamesToFiles);
|
||||
string message = $") Preloading ExifDirectory Dictionary - {(int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds)} total second(s)";
|
||||
dlibDotNet?.ConstructProgressBar(filePairs.Count, message);
|
||||
_ = Parallel.For(0, filePairs.Count, parallelOptions, (i, state) => ParallelFor(dlibDotNet, filePairs[i], results));
|
||||
jsonGroupDirectory = Path.Combine(bResultsFullGroupDirectory, propertyConfiguration.ResultCollection);
|
||||
foreach (ExifDirectory exifDirectory in results)
|
||||
{
|
||||
if (exifDirectory.FilePath.Id is null || exifDirectoriesById.ContainsKey(exifDirectory.FilePath.Id.Value))
|
||||
continue;
|
||||
exifDirectoriesById.Add(exifDirectory.FilePath.Id.Value, exifDirectory);
|
||||
}
|
||||
ExifDirectoriesById = new(exifDirectoriesById);
|
||||
DateGroupDirectory = bResultsFullGroupDirectory;
|
||||
SingletonById = fileNamesToFiles;
|
||||
filesCollectionRootDirectory = jsonGroupCollectionDirectory;
|
||||
ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsSingletonCollection = IDirectory.GetFilePathCollections(propertyConfiguration, directorySearchFilter, fileSearchFilter, filesCollectionRootDirectory,
|
||||
useIgnoreExtensions: false, useCeilingAverage: false);
|
||||
Collection = filePathsSingletonCollection[0];
|
||||
_FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, bResultsFullGroupDirectory, [propertyConfiguration.ResultSingleton]);
|
||||
}
|
||||
|
||||
private void ParallelFor(IDlibDotNet? dlibDotNet, FilePair filePair, List<ExifDirectory> results)
|
||||
public override string ToString()
|
||||
{
|
||||
dlibDotNet?.Tick();
|
||||
if (filePair.FilePath.Id is null)
|
||||
return;
|
||||
ExifDirectory? exifDirectory = GetExifDirectory(filePair);
|
||||
if (exifDirectory is null)
|
||||
return;
|
||||
lock (results)
|
||||
results.Add(exifDirectory);
|
||||
}
|
||||
|
||||
private static ExifDirectory? GetExifDirectory(FilePair filePair)
|
||||
{
|
||||
ExifDirectory? result;
|
||||
if (filePair.Match is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
string json = File.ReadAllText(filePair.Match.FullName);
|
||||
if (string.IsNullOrEmpty(json))
|
||||
result = null;
|
||||
else
|
||||
result = JsonSerializer.Deserialize(json, ExifDirectorySourceGenerationContext.Default.ExifDirectory);
|
||||
}
|
||||
string result = JsonSerializer.Serialize(this, _WriteIndentedJsonSerializerOptions);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -118,11 +47,8 @@ public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
||||
{
|
||||
ExifDirectory? result = null;
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
CombinedEnumAndIndex cei = Shared.Models.Stateless.Methods.IPath.GetCombinedEnumAndIndex(_PropertyConfiguration, filePath);
|
||||
string fileName = $"{mappingFromItem.FilePath.NameWithoutExtension}{mappingFromItem.FilePath.ExtensionLowered}.json";
|
||||
string directory = _ResultSingletonFileGroups[0][cei.Enum][cei.Index];
|
||||
FileInfo fileInfo = new(Path.Combine(directory, fileName));
|
||||
MoveIf(fileName, cei, directory, fileInfo);
|
||||
(_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration, filePath);
|
||||
FileInfo fileInfo = new(Path.Combine(_FileGroups[_PropertyConfiguration.ResultSingleton][directoryIndex], $"{mappingFromItem.FilePath.NameWithoutExtension}{mappingFromItem.FilePath.ExtensionLowered}.json"));
|
||||
if (_ForceMetadataLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete")))
|
||||
{
|
||||
File.Move(Path.ChangeExtension(fileInfo.FullName, ".delete"), fileInfo.FullName);
|
||||
@ -178,32 +104,13 @@ public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void MoveIf(string fileName, CombinedEnumAndIndex cei, string directory, FileInfo fileInfo)
|
||||
{
|
||||
string[] segments = directory.Split(cei.Combined);
|
||||
string? checkDirectory = segments.Length == 1 ?
|
||||
Path.Combine(segments[0], $"{cei.Combined[2..]}") :
|
||||
segments.Length == 2 ?
|
||||
$"{segments[0]}{cei.Combined[2..]}{segments[1]}" :
|
||||
null;
|
||||
if (checkDirectory is not null && System.IO.Directory.Exists(checkDirectory))
|
||||
{
|
||||
string checkFile = Path.Combine(checkDirectory, fileName);
|
||||
if (File.Exists(checkFile))
|
||||
{
|
||||
File.Move(checkFile, fileInfo.FullName);
|
||||
fileInfo.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(DateTime?, DateTime?[]) IMetadata<MetadataExtractor.Directory>.GetDateTimes(FilePath filePath, IReadOnlyList<MetadataExtractor.Directory> directories)
|
||||
{
|
||||
List<DateTime?> results = [];
|
||||
DateTime? result = null;
|
||||
DateTime? dateTime;
|
||||
DateTime checkDateTime;
|
||||
string dateTimeFormat = Stateless.Methods.IMetadata.DateTimeFormat();
|
||||
string dateTimeFormat = Property.Models.Stateless.IProperty.DateTimeFormat();
|
||||
MetadataExtractor.Formats.Exif.ExifDirectoryBase? exifDirectoryBase = directories.OfType<MetadataExtractor.Formats.Exif.ExifDirectoryBase>().FirstOrDefault();
|
||||
results.Add(new DateTime(filePath.CreationTicks));
|
||||
results.Add(new DateTime(filePath.LastWriteTicks));
|
||||
@ -213,7 +120,7 @@ public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
||||
results.Add(checkDateTime);
|
||||
else
|
||||
{
|
||||
dateTime = Stateless.Methods.IMetadata.GetDateTime(dateTimeFormat, exifDirectoryBase.GetString(MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagDateTime));
|
||||
dateTime = Property.Models.Stateless.IProperty.GetDateTime(dateTimeFormat, exifDirectoryBase.GetString(MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagDateTime));
|
||||
if (dateTime is not null)
|
||||
results.Add(dateTime.Value);
|
||||
}
|
||||
@ -221,7 +128,7 @@ public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
||||
results.Add(checkDateTime);
|
||||
else
|
||||
{
|
||||
dateTime = Stateless.Methods.IMetadata.GetDateTime(dateTimeFormat, exifDirectoryBase.GetString(MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagDateTimeDigitized));
|
||||
dateTime = Property.Models.Stateless.IProperty.GetDateTime(dateTimeFormat, exifDirectoryBase.GetString(MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagDateTimeDigitized));
|
||||
if (dateTime is not null)
|
||||
results.Add(dateTime.Value);
|
||||
}
|
||||
@ -232,7 +139,7 @@ public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
||||
}
|
||||
else
|
||||
{
|
||||
dateTime = Stateless.Methods.IMetadata.GetDateTime(dateTimeFormat, exifDirectoryBase.GetString(MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagDateTimeOriginal));
|
||||
dateTime = Property.Models.Stateless.IProperty.GetDateTime(dateTimeFormat, exifDirectoryBase.GetString(MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagDateTimeOriginal));
|
||||
if (dateTime is not null)
|
||||
{
|
||||
result ??= dateTime.Value;
|
||||
@ -250,7 +157,7 @@ public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
||||
}
|
||||
else
|
||||
{
|
||||
dateTime = Stateless.Methods.IMetadata.GetDateTime(dateTimeFormat, aviDirectory.GetString(MetadataExtractor.Formats.Avi.AviDirectory.TagDateTimeOriginal));
|
||||
dateTime = Property.Models.Stateless.IProperty.GetDateTime(dateTimeFormat, aviDirectory.GetString(MetadataExtractor.Formats.Avi.AviDirectory.TagDateTimeOriginal));
|
||||
if (dateTime is not null)
|
||||
{
|
||||
result ??= dateTime.Value;
|
||||
@ -268,7 +175,7 @@ public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
||||
}
|
||||
else
|
||||
{
|
||||
dateTime = Stateless.Methods.IMetadata.GetDateTime(dateTimeFormat, quickTimeMovieHeaderDirectory.GetString(MetadataExtractor.Formats.QuickTime.QuickTimeMovieHeaderDirectory.TagCreated));
|
||||
dateTime = Property.Models.Stateless.IProperty.GetDateTime(dateTimeFormat, quickTimeMovieHeaderDirectory.GetString(MetadataExtractor.Formats.QuickTime.QuickTimeMovieHeaderDirectory.TagCreated));
|
||||
if (dateTime is not null)
|
||||
{
|
||||
result ??= dateTime.Value;
|
||||
@ -286,7 +193,7 @@ public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
||||
}
|
||||
else
|
||||
{
|
||||
dateTime = Stateless.Methods.IMetadata.GetDateTime(dateTimeFormat, quickTimeTrackHeaderDirectory.GetString(MetadataExtractor.Formats.QuickTime.QuickTimeTrackHeaderDirectory.TagCreated));
|
||||
dateTime = Property.Models.Stateless.IProperty.GetDateTime(dateTimeFormat, quickTimeTrackHeaderDirectory.GetString(MetadataExtractor.Formats.QuickTime.QuickTimeTrackHeaderDirectory.TagCreated));
|
||||
if (dateTime is not null)
|
||||
{
|
||||
result ??= dateTime.Value;
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System.Globalization;
|
||||
using View_by_Distance.Shared.Models;
|
||||
|
||||
namespace View_by_Distance.Metadata.Models.Stateless.Methods;
|
||||
@ -48,23 +47,4 @@ internal static class Base
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma warning restore CA1416
|
||||
|
||||
internal static DateTime? GetDateTime(string dateTimeFormat, string? value)
|
||||
{
|
||||
DateTime? result;
|
||||
string alternateFormat = "ddd MMM dd HH:mm:ss yyyy";
|
||||
if (value is not null && DateTime.TryParse(value, out DateTime dateTime))
|
||||
result = dateTime;
|
||||
else if (value is not null && value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||
result = dateTime;
|
||||
else if (value is not null && value.Length == alternateFormat.Length && DateTime.TryParseExact(value, alternateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||
result = dateTime;
|
||||
else
|
||||
result = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma warning disable CA1416
|
||||
|
||||
}
|
@ -8,16 +8,16 @@ internal static class Dimensions
|
||||
#pragma warning disable IDE0230
|
||||
private static readonly Dictionary<byte[], Func<BinaryReader, Size?>> _ImageFormatDecoders = new()
|
||||
{
|
||||
{ new byte[] { 0xff, 0xd8 }, DecodeJfif },
|
||||
{ new byte[] { 0x42, 0x4D }, DecodeBitmap },
|
||||
{ new byte[] { 0x52, 0x49, 0x46, 0x46 }, DecodeWebP },
|
||||
{ new byte[] { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 }, DecodeGif },
|
||||
{ new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 }, DecodeGif },
|
||||
{ new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }, DecodePng },
|
||||
{ new byte[] { 0xff, 0xd8 }, DecodeJfif },
|
||||
{ new byte[] { 0x52, 0x49, 0x46, 0x46 }, DecodeWebP },
|
||||
};
|
||||
#pragma warning restore IDE0230
|
||||
|
||||
private static bool StartsWith(List<byte> thisBytes, byte[] thatBytes)
|
||||
private static bool StartsWith(byte[] thisBytes, byte[] thatBytes)
|
||||
{
|
||||
for (int i = 0; i < thatBytes.Length; i += 1)
|
||||
{
|
||||
@ -103,41 +103,24 @@ internal static class Dimensions
|
||||
|
||||
internal static Size? GetDimensions(BinaryReader binaryReader)
|
||||
{
|
||||
Size? result;
|
||||
List<byte> magicBytes = [];
|
||||
int[] magicBytesLengths = (from l in _ImageFormatDecoders.Keys where l.Length <= binaryReader.BaseStream.Length orderby l.Length descending select l.Length).ToArray();
|
||||
if (magicBytesLengths.Length == 0)
|
||||
result = null;
|
||||
else
|
||||
int maxMagicBytesLength = _ImageFormatDecoders.Keys.OrderByDescending(x => x.Length).First().Length;
|
||||
byte[] magicBytes = new byte[maxMagicBytesLength];
|
||||
for (int i = 0; i < maxMagicBytesLength; i += 1)
|
||||
{
|
||||
result = null;
|
||||
if (binaryReader.BaseStream.Length == binaryReader.BaseStream.Position)
|
||||
_ = binaryReader.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
for (int i = 0; i < magicBytesLengths[0]; i++)
|
||||
{
|
||||
magicBytes.Add(binaryReader.ReadByte());
|
||||
magicBytes[i] = binaryReader.ReadByte();
|
||||
foreach (KeyValuePair<byte[], Func<BinaryReader, Size?>> kvPair in _ImageFormatDecoders)
|
||||
{
|
||||
if (StartsWith(magicBytes, kvPair.Key))
|
||||
{
|
||||
result = kvPair.Value(binaryReader);
|
||||
break;
|
||||
return kvPair.Value(binaryReader);
|
||||
}
|
||||
}
|
||||
if (result is not null)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static Size? GetDimensions(string path)
|
||||
{
|
||||
Size? result;
|
||||
using FileStream fileStream = File.OpenRead(path);
|
||||
using BinaryReader binaryReader = new(fileStream);
|
||||
result = GetDimensions(binaryReader);
|
||||
return result;
|
||||
using BinaryReader binaryReader = new(File.OpenRead(path));
|
||||
return GetDimensions(binaryReader);
|
||||
}
|
||||
|
||||
}
|
@ -484,7 +484,7 @@ internal abstract class Exif
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
private static Shared.Models.ExifDirectory Covert(Shared.Models.FilePath filePath, IReadOnlyList<MetadataExtractor.Directory> directories, System.Drawing.Size? size)
|
||||
private static Shared.Models.ExifDirectory Covert(Shared.Models.FilePath filePath, System.Drawing.Size? size, IReadOnlyList<MetadataExtractor.Directory> directories)
|
||||
{
|
||||
Shared.Models.ExifDirectory result;
|
||||
Shared.Models.AviDirectory[] aviDirectories = GetAviDirectories(directories);
|
||||
@ -502,12 +502,12 @@ internal abstract class Exif
|
||||
result = new(aviDirectories,
|
||||
exifBaseDirectories,
|
||||
fileMetadataDirectories,
|
||||
filePath,
|
||||
gifHeaderDirectories,
|
||||
gpsDirectories,
|
||||
size?.Height,
|
||||
jpegDirectories,
|
||||
makernoteDirectories,
|
||||
filePath.Name,
|
||||
photoshopDirectories,
|
||||
pngDirectories,
|
||||
quickTimeMovieHeaderDirectories,
|
||||
@ -520,13 +520,13 @@ internal abstract class Exif
|
||||
internal static Shared.Models.ExifDirectory GetExifDirectory(Shared.Models.FilePath filePath)
|
||||
{
|
||||
Shared.Models.ExifDirectory result;
|
||||
IReadOnlyList<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(filePath.FullName);
|
||||
System.Drawing.Size? size;
|
||||
try
|
||||
{ size = Dimensions.GetDimensions(filePath.FullName); }
|
||||
catch (Exception)
|
||||
{ size = null; }
|
||||
result = Covert(filePath, directories, size);
|
||||
IReadOnlyList<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(filePath.FullName);
|
||||
result = Covert(filePath, size, directories);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -64,14 +64,4 @@ public interface IMetadata
|
||||
// static Dictionary<string, MetadataExtractorDirectory> GetMetadataCollection(FileInfo fileInfo, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions) =>
|
||||
// Metadata.GetMetadataCollection(fileInfo, subFileTuples, parseExceptions);
|
||||
|
||||
string TestStatic_DateTimeFormat() =>
|
||||
DateTimeFormat();
|
||||
static string DateTimeFormat() =>
|
||||
"yyyy:MM:dd HH:mm:ss";
|
||||
|
||||
DateTime? TestStatic_GetDateTime(string dateTimeFormat, string? value) =>
|
||||
GetDateTime(dateTimeFormat, value);
|
||||
static DateTime? GetDateTime(string dateTimeFormat, string? value) =>
|
||||
Base.GetDateTime(dateTimeFormat, value);
|
||||
|
||||
}
|
@ -4,13 +4,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<UserSecretsId>fa06c6db-0226-42ca-8728-68b1e336184d</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Mirror.Length</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -35,10 +35,10 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
|
@ -193,7 +193,6 @@ public class MirrorLength
|
||||
{
|
||||
string message = nameof(MirrorLength);
|
||||
List<(string, string, int)> collectionForMarkDown;
|
||||
logger?.LogDebug("{method}", nameof(MirrorLengthFilesInDirectories));
|
||||
bool inPlaceSave = _PropertyConfiguration.RootDirectory.First() == _AppSettings.Destination;
|
||||
if (!inPlaceSave)
|
||||
collectionForMarkDown = [];
|
||||
|
@ -34,15 +34,17 @@ public class Configuration
|
||||
}
|
||||
}
|
||||
|
||||
private static Models.Configuration Get(Configuration? configuration, Property.Models.Configuration propertyConfiguration)
|
||||
private static Models.Configuration Get(Configuration? configuration)
|
||||
{
|
||||
Models.Configuration result;
|
||||
if (configuration is null) throw new NullReferenceException(nameof(configuration));
|
||||
if (configuration.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.PersonBirthdayFormat is null) throw new NullReferenceException(nameof(configuration.PersonBirthdayFormat));
|
||||
result = new(propertyConfiguration,
|
||||
if (configuration.PropertyConfiguration is null) throw new NullReferenceException(nameof(configuration.PropertyConfiguration));
|
||||
result = new(
|
||||
configuration.IgnoreExtensions,
|
||||
configuration.PersonBirthdayFormat);
|
||||
configuration.PersonBirthdayFormat,
|
||||
configuration.PropertyConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -64,7 +66,7 @@ public class Configuration
|
||||
#pragma warning restore IL3050, IL2026
|
||||
}
|
||||
PreVerify(configurationRoot, configuration);
|
||||
result = Get(configuration, propertyConfiguration);
|
||||
result = Get(configuration);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,10 @@ public class Configuration
|
||||
public Property.Models.Configuration PropertyConfiguration => _PropertyConfiguration;
|
||||
|
||||
[JsonConstructor]
|
||||
public Configuration(Property.Models.Configuration propertyConfiguration,
|
||||
public Configuration(
|
||||
string[] ignoreExtensions,
|
||||
string personBirthdayFormat)
|
||||
string personBirthdayFormat,
|
||||
Property.Models.Configuration propertyConfiguration)
|
||||
{
|
||||
IgnoreExtensions = ignoreExtensions;
|
||||
PersonBirthdayFormat = personBirthdayFormat;
|
||||
|
@ -34,15 +34,17 @@ public class Configuration
|
||||
}
|
||||
}
|
||||
|
||||
private static Models.Configuration Get(Configuration? configuration, Property.Models.Configuration propertyConfiguration)
|
||||
private static Models.Configuration Get(Configuration? configuration)
|
||||
{
|
||||
Models.Configuration result;
|
||||
if (configuration is null) throw new NullReferenceException(nameof(configuration));
|
||||
if (configuration.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.PersonBirthdayFormat is null) throw new NullReferenceException(nameof(configuration.PersonBirthdayFormat));
|
||||
result = new(propertyConfiguration,
|
||||
if (configuration.PropertyConfiguration is null) throw new NullReferenceException(nameof(configuration.PropertyConfiguration));
|
||||
result = new(
|
||||
configuration.IgnoreExtensions,
|
||||
configuration.PersonBirthdayFormat);
|
||||
configuration.PersonBirthdayFormat,
|
||||
configuration.PropertyConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -64,7 +66,7 @@ public class Configuration
|
||||
#pragma warning restore IL3050, IL2026
|
||||
}
|
||||
PreVerify(configurationRoot, configuration);
|
||||
result = Get(configuration, propertyConfiguration);
|
||||
result = Get(configuration);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,10 @@ public class Configuration
|
||||
public Property.Models.Configuration PropertyConfiguration => _PropertyConfiguration;
|
||||
|
||||
[JsonConstructor]
|
||||
public Configuration(Property.Models.Configuration propertyConfiguration,
|
||||
public Configuration(
|
||||
string[] ignoreExtensions,
|
||||
string personBirthdayFormat)
|
||||
string personBirthdayFormat,
|
||||
Property.Models.Configuration propertyConfiguration)
|
||||
{
|
||||
IgnoreExtensions = ignoreExtensions;
|
||||
PersonBirthdayFormat = personBirthdayFormat;
|
||||
|
@ -4,13 +4,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<UserSecretsId>ce31220e-ef92-4e68-89c5-91b027a94dca</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Move.By.Id</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -35,9 +35,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
|
@ -115,7 +115,7 @@ public class MoveById
|
||||
progressBar.Tick();
|
||||
fileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(file);
|
||||
filePath = FilePath.Get(_Configuration.PropertyConfiguration, fileHolder, index: null);
|
||||
if (fileHolder.ExtensionLowered == ".id" || fileHolder.DirectoryFullPath is null)
|
||||
if (fileHolder.ExtensionLowered == ".id" || fileHolder.DirectoryName is null)
|
||||
continue;
|
||||
if (allFiles.Contains($"{fileHolder.FullName}.id"))
|
||||
continue;
|
||||
|
@ -34,15 +34,17 @@ public class Configuration
|
||||
}
|
||||
}
|
||||
|
||||
private static Models.Configuration Get(Configuration? configuration, Property.Models.Configuration propertyConfiguration)
|
||||
private static Models.Configuration Get(Configuration? configuration)
|
||||
{
|
||||
Models.Configuration result;
|
||||
if (configuration is null) throw new NullReferenceException(nameof(configuration));
|
||||
if (configuration.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.PersonBirthdayFormat is null) throw new NullReferenceException(nameof(configuration.PersonBirthdayFormat));
|
||||
result = new(propertyConfiguration,
|
||||
if (configuration.PropertyConfiguration is null) throw new NullReferenceException(nameof(configuration.PropertyConfiguration));
|
||||
result = new(
|
||||
configuration.IgnoreExtensions,
|
||||
configuration.PersonBirthdayFormat);
|
||||
configuration.PersonBirthdayFormat,
|
||||
configuration.PropertyConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -64,7 +66,7 @@ public class Configuration
|
||||
#pragma warning restore IL3050, IL2026
|
||||
}
|
||||
PreVerify(configurationRoot, configuration);
|
||||
result = Get(configuration, propertyConfiguration);
|
||||
result = Get(configuration);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,10 @@ public class Configuration
|
||||
public Property.Models.Configuration PropertyConfiguration => _PropertyConfiguration;
|
||||
|
||||
[JsonConstructor]
|
||||
public Configuration(Property.Models.Configuration propertyConfiguration,
|
||||
public Configuration(
|
||||
string[] ignoreExtensions,
|
||||
string personBirthdayFormat)
|
||||
string personBirthdayFormat,
|
||||
Property.Models.Configuration propertyConfiguration)
|
||||
{
|
||||
IgnoreExtensions = ignoreExtensions;
|
||||
PersonBirthdayFormat = personBirthdayFormat;
|
||||
|
@ -4,13 +4,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<UserSecretsId>ae069946-d0c0-4e4f-94f6-9c526e4ae4e7</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Offset.Date.Time.Original</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -35,10 +35,10 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
|
@ -216,17 +216,6 @@ public class OffsetDateTimeOriginal
|
||||
{
|
||||
TimeSpan timeSpan = new(targetDateTimeOriginal.Value.Ticks - badDateTimeOriginal.Value.Ticks);
|
||||
DateFix(sourceDirectory, asciiEncoding, checkDirectory, minimumDateTime, maximumDateTime, timeSpan.Ticks);
|
||||
// DateTime a = new(2020, 01, 04, 02, 12, 51, 32);
|
||||
// // DateTime a = new(2020, 01, 05, 18, 17, 15, 97);
|
||||
// DateTime b = new(2020, 01, 05, 19, 52, 30, 17);
|
||||
// DateTime c = new(2024, 12, 07, 11, 19, 06, 13);
|
||||
// // DateTime d = new(2024, 12, 07, 12, 07, 30, 38);
|
||||
// long e = new DateTime(c.Ticks - b.Ticks).AddMinutes(-5).Ticks;
|
||||
// if (a != DateTime.MinValue)
|
||||
// minimumDateTime = a.AddTicks(e).AddHours(-1);
|
||||
// if (c != DateTime.MinValue)
|
||||
// maximumDateTime = c;
|
||||
// DateFix(sourceDirectory, asciiEncoding, checkDirectory, minimumDateTime, maximumDateTime, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.PhotoPrism</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -37,7 +37,7 @@
|
||||
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.PrepareForOld</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -33,14 +33,14 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Property.Compare</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -34,8 +34,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
|
@ -1,3 +1,4 @@
|
||||
using ShellProgressBar;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
@ -21,27 +22,19 @@ public class A_Property
|
||||
private readonly Configuration _Configuration;
|
||||
private readonly List<string> _AngleBracketCollection;
|
||||
private readonly IPropertyConfiguration _PropertyConfiguration;
|
||||
private readonly ReadOnlyDictionary<byte, ReadOnlyCollection<string>>[] _ResultSingletonFileGroups;
|
||||
private readonly ReadOnlyDictionary<string, string[]> _FileGroups;
|
||||
|
||||
public A_Property(int maxDegreeOfParallelism, Configuration propertyConfiguration, string outputExtension, bool reverse, string aResultsFullGroupDirectory)
|
||||
{
|
||||
Reverse = reverse;
|
||||
_ExceptionsDirectories = [];
|
||||
_AngleBracketCollection = [];
|
||||
_OutputExtension = outputExtension;
|
||||
_ASCIIEncoding = new ASCIIEncoding();
|
||||
_Configuration = propertyConfiguration;
|
||||
_AngleBracketCollection = [];
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
_MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
_ResultSingletonFileGroups = [new(new Dictionary<byte, ReadOnlyCollection<string>>())];
|
||||
ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePairs = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, aResultsFullGroupDirectory, [propertyConfiguration.ResultSingleton]);
|
||||
foreach (KeyValuePair<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
if (keyValuePair.Key == _PropertyConfiguration.ResultSingleton)
|
||||
_ResultSingletonFileGroups[0] = keyValuePair.Value;
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
_FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, aResultsFullGroupDirectory, [propertyConfiguration.ResultSingleton]);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
@ -50,11 +43,132 @@ public class A_Property
|
||||
return result;
|
||||
}
|
||||
|
||||
private Shared.Models.Property GetImageProperty(Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, Item item, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<string> parseExceptions, bool isIgnoreExtension)
|
||||
{
|
||||
Shared.Models.Property? result;
|
||||
int? id = null;
|
||||
FileInfo fileInfo;
|
||||
string? json = null;
|
||||
bool hasWrongYearProperty = false;
|
||||
string[] changesFrom = [];
|
||||
string angleBracket = _AngleBracketCollection[0];
|
||||
bool populateId = _Configuration.PopulatePropertyId;
|
||||
if (!item.IsUniqueFileName)
|
||||
fileInfo = new(Path.Combine(angleBracket.Replace("<>", _PropertyConfiguration.ResultSingleton), $"{item.FilePath.NameWithoutExtension}{item.FilePath.ExtensionLowered}.json"));
|
||||
else
|
||||
{
|
||||
(_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration, item.FilePath);
|
||||
fileInfo = new(Path.Combine(_FileGroups[_PropertyConfiguration.ResultSingleton][directoryIndex], $"{item.FilePath.NameWithoutExtension}{item.FilePath.ExtensionLowered}.json"));
|
||||
}
|
||||
List<DateTime> dateTimes = (from l in sourceDirectoryFileTuples where l is not null && changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
if (_Configuration.ForcePropertyLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete")))
|
||||
{
|
||||
File.Move(Path.ChangeExtension(fileInfo.FullName, ".delete"), fileInfo.FullName);
|
||||
fileInfo.Refresh();
|
||||
}
|
||||
if (_Configuration.ForcePropertyLastWriteTimeToCreationTime && fileInfo.Exists && fileInfo.LastWriteTime != fileInfo.CreationTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
|
||||
fileInfo.Refresh();
|
||||
}
|
||||
if (_Configuration.PropertiesChangedForProperty)
|
||||
result = null;
|
||||
else if (!fileInfo.Exists)
|
||||
result = null;
|
||||
else if (!fileInfo.FullName.EndsWith(".json") && !fileInfo.FullName.EndsWith(".old"))
|
||||
throw new ArgumentException("must be a *.json file");
|
||||
else if (dateTimes.Count != 0 && dateTimes.Max() > fileInfo.LastWriteTime)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
json = File.ReadAllText(fileInfo.FullName);
|
||||
try
|
||||
{
|
||||
if (item.Property is not null)
|
||||
result = item.Property;
|
||||
else
|
||||
result = JsonSerializer.Deserialize(json, PropertyGenerationContext.Default.Property);
|
||||
if (result is not null && json.Contains("WrongYear"))
|
||||
{
|
||||
id = result.Id;
|
||||
hasWrongYearProperty = true;
|
||||
result = null;
|
||||
}
|
||||
if (!isIgnoreExtension && item.IsValidImageFormatExtension && ((populateId && result?.Id is null) || result?.Width is null || result.Height is null))
|
||||
{
|
||||
id = result?.Id;
|
||||
result = null;
|
||||
}
|
||||
if (!isIgnoreExtension && item.IsValidImageFormatExtension && populateId && result is not null && result.LastWriteTime.Ticks != item.FilePath.LastWriteTicks)
|
||||
{
|
||||
id = null;
|
||||
result = null;
|
||||
}
|
||||
if (!isIgnoreExtension && item.IsValidImageFormatExtension && result?.Width is not null && result.Height is not null && result.Width.Value == result.Height.Value)
|
||||
{
|
||||
id = result.Id;
|
||||
result = null;
|
||||
if (result?.Width is not null && result.Height is not null && result.Width.Value != result.Height.Value)
|
||||
throw new Exception("Was square!");
|
||||
}
|
||||
if (!isIgnoreExtension && item.IsValidImageFormatExtension && result is not null && result.FileSize != item.FilePath.Length)
|
||||
{
|
||||
id = result.Id;
|
||||
result = null;
|
||||
}
|
||||
if (result is not null)
|
||||
{
|
||||
sourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), fileInfo.LastWriteTime));
|
||||
if (fileInfo.CreationTime != result.LastWriteTime)
|
||||
{
|
||||
File.SetCreationTime(fileInfo.FullName, result.LastWriteTime);
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.LastWriteTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
result = null;
|
||||
parseExceptions.Add(nameof(A_Property));
|
||||
}
|
||||
}
|
||||
if (result is null)
|
||||
{
|
||||
id ??= item.FilePath.Id;
|
||||
(_, _, result) = Stateless.Property.GetProperty(populateId, metadata, item.FilePath, result, isIgnoreExtension, item.IsValidImageFormatExtension, id, _ASCIIEncoding);
|
||||
json = JsonSerializer.Serialize(result, PropertyGenerationContext.Default.Property);
|
||||
if (populateId && Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||
{
|
||||
File.SetCreationTime(fileInfo.FullName, result.LastWriteTime);
|
||||
if (!_Configuration.ForcePropertyLastWriteTimeToCreationTime)
|
||||
sourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), DateTime.Now));
|
||||
else
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
|
||||
fileInfo.Refresh();
|
||||
sourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), fileInfo.CreationTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (hasWrongYearProperty)
|
||||
{
|
||||
json = JsonSerializer.Serialize(result, PropertyGenerationContext.Default.Property);
|
||||
if (Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||
{
|
||||
File.SetCreationTime(fileInfo.FullName, result.LastWriteTime);
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
|
||||
fileInfo.Refresh();
|
||||
sourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), fileInfo.CreationTime));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetAngleBracketCollection(string aResultsFullGroupDirectory, string sourceDirectory, bool anyNullOrNoIsUniqueFileName = true)
|
||||
{
|
||||
_AngleBracketCollection.Clear();
|
||||
if (!anyNullOrNoIsUniqueFileName)
|
||||
_AngleBracketCollection.AddRange([Path.Combine(aResultsFullGroupDirectory, "<>")]);
|
||||
_AngleBracketCollection.AddRange(new[] { Path.Combine(aResultsFullGroupDirectory, "<>") });
|
||||
else
|
||||
_AngleBracketCollection.AddRange(IResult.GetDirectoryInfoCollection(_PropertyConfiguration,
|
||||
sourceDirectory,
|
||||
@ -65,6 +179,24 @@ public class A_Property
|
||||
converted: false));
|
||||
}
|
||||
|
||||
private void SavePropertyParallelForWork(Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, string sourceDirectory, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<Tuple<string, DateTime>> sourceDirectoryChanges, Item item)
|
||||
{
|
||||
Shared.Models.Property property;
|
||||
List<string> parseExceptions = [];
|
||||
bool isIgnoreExtension = item.IsValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(item.FilePath.ExtensionLowered);
|
||||
string filteredSourceDirectoryFileExtensionLowered = Path.Combine(sourceDirectory, $"{item.FilePath.NameWithoutExtension}{item.FilePath.ExtensionLowered}");
|
||||
if (item.IsValidImageFormatExtension && item.FilePath.FullName.Length == filteredSourceDirectoryFileExtensionLowered.Length && item.FilePath.FullName != filteredSourceDirectoryFileExtensionLowered)
|
||||
File.Move(item.FilePath.FullName, filteredSourceDirectoryFileExtensionLowered);
|
||||
if (item.FileSizeChanged is null || item.FileSizeChanged.Value || item.LastWriteTimeChanged is null || item.LastWriteTimeChanged.Value || item.Property is null)
|
||||
{
|
||||
property = GetImageProperty(metadata, item, sourceDirectoryFileTuples, parseExceptions, isIgnoreExtension);
|
||||
lock (sourceDirectoryChanges)
|
||||
sourceDirectoryChanges.Add(new Tuple<string, DateTime>(nameof(A_Property), DateTime.Now));
|
||||
lock (item)
|
||||
item.Update(property);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetAngleBracketCollection(string sourceDirectory, bool anyNullOrNoIsUniqueFileName)
|
||||
{
|
||||
_AngleBracketCollection.Clear();
|
||||
@ -77,23 +209,83 @@ public class A_Property
|
||||
SetAngleBracketCollection(aResultsFullGroupDirectory, sourceDirectory, anyNullOrNoIsUniqueFileName);
|
||||
}
|
||||
|
||||
private static void MoveIf(string fileName, CombinedEnumAndIndex cei, string directory, FileInfo fileInfo)
|
||||
private void SavePropertyParallelWork(int maxDegreeOfParallelism, Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, List<Exception> exceptions, List<Tuple<string, DateTime>> sourceDirectoryChanges, Container container, ReadOnlyCollection<Item> items, string message)
|
||||
{
|
||||
string[] segments = directory.Split(cei.Combined);
|
||||
string? checkDirectory = segments.Length == 1 ?
|
||||
Path.Combine(segments[0], $"{cei.Combined[2..]}") :
|
||||
segments.Length == 2 ?
|
||||
$"{segments[0]}{cei.Combined[2..]}{segments[1]}" :
|
||||
null;
|
||||
if (checkDirectory is not null && Directory.Exists(checkDirectory))
|
||||
List<Tuple<string, DateTime>> sourceDirectoryFileTuples = [];
|
||||
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = maxDegreeOfParallelism };
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
using ProgressBar progressBar = new(items.Count, message, options);
|
||||
_ = Parallel.For(0, items.Count, parallelOptions, (i, state) =>
|
||||
{
|
||||
string checkFile = Path.Combine(checkDirectory, fileName);
|
||||
if (File.Exists(checkFile))
|
||||
try
|
||||
{
|
||||
File.Move(checkFile, fileInfo.FullName);
|
||||
fileInfo.Refresh();
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
List<Tuple<string, DateTime>> collection;
|
||||
SavePropertyParallelForWork(metadata, container.SourceDirectory, sourceDirectoryChanges, sourceDirectoryFileTuples, items[i]);
|
||||
if (i == 0 || sourceDirectoryChanges.Count != 0)
|
||||
progressBar.Tick();
|
||||
lock (sourceDirectoryFileTuples)
|
||||
collection = (from l in sourceDirectoryFileTuples where l.Item2 > dateTime select l).ToList();
|
||||
lock (sourceDirectoryChanges)
|
||||
sourceDirectoryChanges.AddRange(collection);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
lock (exceptions)
|
||||
exceptions.Add(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void SavePropertyParallelWork(long ticks, Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, int t, Container[] containers)
|
||||
{
|
||||
int total = 0;
|
||||
string message;
|
||||
int totalSeconds;
|
||||
Container container;
|
||||
bool anyNullOrNoIsUniqueFileName;
|
||||
List<Exception> exceptions = [];
|
||||
int containersLength = containers.Length;
|
||||
const string outputResolution = "Original";
|
||||
List<Tuple<string, DateTime>> sourceDirectoryChanges = [];
|
||||
string propertyRoot = IResult.GetResultsGroupDirectory(_PropertyConfiguration, nameof(A_Property));
|
||||
for (int i = 0; i < containers.Length; i++)
|
||||
{
|
||||
container = containers[i];
|
||||
if (container.Items.Count == 0)
|
||||
continue;
|
||||
sourceDirectoryChanges.Clear();
|
||||
if (container.Items.Count == 0)
|
||||
continue;
|
||||
anyNullOrNoIsUniqueFileName = container.Items.Any(l => !l.IsUniqueFileName);
|
||||
SetAngleBracketCollection(container.SourceDirectory, anyNullOrNoIsUniqueFileName);
|
||||
totalSeconds = (int)Math.Truncate(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
message = $"{i + 1:000} [{container.Items.Count:000}] / {containersLength:000} - {total} / {t} total - {totalSeconds} total second(s) - {outputResolution} - {container.SourceDirectory}";
|
||||
SavePropertyParallelWork(_MaxDegreeOfParallelism, metadata, exceptions, sourceDirectoryChanges, container, container.Items, message);
|
||||
if (exceptions.Count == container.Items.Count)
|
||||
throw new Exception(string.Concat("All in [", container.SourceDirectory, "]failed!"));
|
||||
if (exceptions.Count != 0)
|
||||
_ExceptionsDirectories.Add(container.SourceDirectory);
|
||||
total += container.Items.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public Shared.Models.Property GetProperty(Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, Item item, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<string> parseExceptions)
|
||||
{
|
||||
Shared.Models.Property result;
|
||||
bool angleBracketCollectionAny = _AngleBracketCollection.Count != 0;
|
||||
if (!angleBracketCollectionAny)
|
||||
{
|
||||
if (item.FilePath.DirectoryName is null)
|
||||
throw new NullReferenceException(nameof(item.FilePath.DirectoryName));
|
||||
SetAngleBracketCollection(item.FilePath.DirectoryName, !item.IsUniqueFileName);
|
||||
}
|
||||
bool isIgnoreExtension = item.IsValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(item.FilePath.ExtensionLowered);
|
||||
result = GetImageProperty(metadata, item, sourceDirectoryFileTuples, parseExceptions, isIgnoreExtension);
|
||||
if (!angleBracketCollectionAny)
|
||||
_AngleBracketCollection.Clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -28,11 +28,9 @@ public class Configuration
|
||||
public int? ResultAllInOneSubdirectoryLength { get; set; }
|
||||
public string? ResultCollection { get; set; }
|
||||
public string? ResultContent { get; set; }
|
||||
public string? ResultContentCollection { get; set; }
|
||||
public string? ResultSingleton { get; set; }
|
||||
public string? RootDirectory { get; set; }
|
||||
public string[]? ValidImageFormatExtensions { get; set; }
|
||||
public string[]? ValidVideoFormatExtensions { get; set; }
|
||||
public string[]? VerifyToSeason { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
@ -83,11 +81,9 @@ public class Configuration
|
||||
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.ResultContentCollection is null) throw new NullReferenceException(nameof(configuration.ResultContentCollection));
|
||||
if (configuration.ResultSingleton is null) throw new NullReferenceException(nameof(configuration.ResultSingleton));
|
||||
if (configuration.RootDirectory is null) throw new NullReferenceException(nameof(configuration.RootDirectory));
|
||||
if (configuration.ValidImageFormatExtensions is null) throw new NullReferenceException(nameof(configuration.ValidImageFormatExtensions));
|
||||
if (configuration.ValidVideoFormatExtensions is null) throw new NullReferenceException(nameof(configuration.ValidVideoFormatExtensions));
|
||||
// if (configuration.VerifyToSeason is null) throw new NullReferenceException(nameof(configuration.VerifyToSeason));
|
||||
result = new(configuration.DateGroup,
|
||||
configuration.FileNameDirectorySeparator,
|
||||
@ -110,11 +106,9 @@ public class Configuration
|
||||
configuration.ResultAllInOneSubdirectoryLength.Value,
|
||||
configuration.ResultCollection,
|
||||
configuration.ResultContent,
|
||||
configuration.ResultContentCollection,
|
||||
configuration.ResultSingleton,
|
||||
Path.GetFullPath(configuration.RootDirectory),
|
||||
configuration.ValidImageFormatExtensions,
|
||||
configuration.ValidVideoFormatExtensions,
|
||||
configuration.VerifyToSeason ?? []);
|
||||
return result;
|
||||
}
|
||||
|
@ -31,10 +31,8 @@ public class Configuration : Shared.Models.Properties.IPropertyConfiguration
|
||||
public int ResultAllInOneSubdirectoryLength { init; get; }
|
||||
public string ResultCollection { init; get; }
|
||||
public string ResultContent { init; get; }
|
||||
public string ResultContentCollection { init; get; }
|
||||
public string ResultSingleton { init; get; }
|
||||
public string[] ValidImageFormatExtensions { init; get; }
|
||||
public string[] ValidVideoFormatExtensions { init; get; }
|
||||
|
||||
[JsonConstructor]
|
||||
public Configuration(string dateGroup,
|
||||
@ -58,11 +56,9 @@ public class Configuration : Shared.Models.Properties.IPropertyConfiguration
|
||||
int resultAllInOneSubdirectoryLength,
|
||||
string resultCollection,
|
||||
string resultContent,
|
||||
string resultContentCollection,
|
||||
string resultSingleton,
|
||||
string rootDirectory,
|
||||
string[] validImageFormatExtensions,
|
||||
string[] validVideoFormatExtensions,
|
||||
string[] verifyToSeason)
|
||||
{
|
||||
DateGroup = dateGroup;
|
||||
@ -86,11 +82,9 @@ public class Configuration : Shared.Models.Properties.IPropertyConfiguration
|
||||
ResultAllInOneSubdirectoryLength = resultAllInOneSubdirectoryLength;
|
||||
ResultCollection = resultCollection;
|
||||
ResultContent = resultContent;
|
||||
ResultContentCollection = resultContentCollection;
|
||||
ResultSingleton = resultSingleton;
|
||||
_RootDirectory = rootDirectory;
|
||||
ValidImageFormatExtensions = validImageFormatExtensions;
|
||||
ValidVideoFormatExtensions = validVideoFormatExtensions;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@ -10,80 +10,49 @@ namespace View_by_Distance.Property.Models.Stateless;
|
||||
public interface IProperty
|
||||
{
|
||||
|
||||
const string DateTimeFormat = "yyyy:MM:dd HH:mm:ss";
|
||||
string TestStatic_DateTimeFormat() =>
|
||||
DateTimeFormat();
|
||||
static string DateTimeFormat() =>
|
||||
"yyyy:MM:dd HH:mm:ss";
|
||||
|
||||
// public
|
||||
static (DateTime?, DateTime[], int?, string?) Get(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FilePath filePath, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Property.Get(populateId, metadata, filePath, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
byte[] TestStatic_GetBytes(string value) =>
|
||||
GetBytes(value);
|
||||
static byte[] GetBytes(string value) =>
|
||||
Property.GetBytes(value);
|
||||
|
||||
// public
|
||||
DateTime? TestStatic_GetDateTime(string dateTimeFormat, string? value) =>
|
||||
GetDateTime(dateTimeFormat, value);
|
||||
static DateTime? GetDateTime(string dateTimeFormat, string? value) =>
|
||||
Property.GetDateTime(dateTimeFormat, value);
|
||||
|
||||
PropertyItem TestStatic_GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value) =>
|
||||
GetPropertyItem(constructorInfo, id, type, value);
|
||||
static PropertyItem GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value) =>
|
||||
Property.GetPropertyItem(constructorInfo, id, type, value);
|
||||
|
||||
(string?, DateTime[], Shared.Models.Property) TestStatic_GetProperty(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FilePath filePath, Shared.Models.Property? property, bool isIgnoreExtension, bool isValidImageFormatExtension, int? id, ASCIIEncoding asciiEncoding) =>
|
||||
GetProperty(populateId, metadata, filePath, property, isIgnoreExtension, isValidImageFormatExtension, id, asciiEncoding);
|
||||
static (string?, DateTime[], Shared.Models.Property) GetProperty(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FilePath filePath, Shared.Models.Property? property, bool isIgnoreExtension, bool isValidImageFormatExtension, int? id, ASCIIEncoding asciiEncoding) =>
|
||||
Property.GetProperty(populateId, metadata, filePath, property, isIgnoreExtension, isValidImageFormatExtension, id, asciiEncoding);
|
||||
|
||||
(DateTime?, DateTime[], int?, string?) TestStatic_Get(IPropertyConfiguration propertyConfiguration, bool populateId, FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Get(propertyConfiguration, populateId, fileHolder, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
static (DateTime?, DateTime[], int?, string?) Get(IPropertyConfiguration propertyConfiguration, bool populateId, FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Property.Get(populateId, null, FilePath.Get(propertyConfiguration, fileHolder, index: null), isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
|
||||
public static byte[] GetBytes(string value) =>
|
||||
Property.GetBytes(value);
|
||||
|
||||
public static DateTime? GetDateTime(string dateTimeFormat, string? value) =>
|
||||
Property.GetDateTime(dateTimeFormat, value);
|
||||
|
||||
public static double GetStandardDeviation(List<long> values, double average) =>
|
||||
Property.GetStandardDeviation(values, average);
|
||||
|
||||
public static bool Any(Container.Models.Container[] propertyHolderCollections) =>
|
||||
Property.Any(propertyHolderCollections);
|
||||
|
||||
public static TimeSpan GetThreeStandardDeviationHigh(int minimum, Container.Models.Container container) =>
|
||||
Property.GetThreeStandardDeviationHigh(minimum, container);
|
||||
|
||||
public static PropertyItem GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value) =>
|
||||
Property.GetPropertyItem(constructorInfo, id, type, value);
|
||||
|
||||
public static (int, List<DateTime>, List<Item>) Get(Container.Models.Container container, TimeSpan threeStandardDeviationHigh, int i) =>
|
||||
Property.Get(container, threeStandardDeviationHigh, i);
|
||||
|
||||
public static (DateTime?, DateTime[], int?, string?) Get(bool populateId, FilePath filePath, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
(DateTime?, DateTime[], int?, string?) TestStatic_Get(bool populateId, FilePath filePath, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Get(populateId, filePath, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
static (DateTime?, DateTime[], int?, string?) Get(bool populateId, FilePath filePath, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Property.Get(populateId, null, filePath, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
|
||||
public static (DateTime?, DateTime[], int?, string?) Get(IPropertyConfiguration propertyConfiguration, bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
(DateTime?, DateTime[], int?, string?) TestStatic_Get(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FilePath filePath, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Get(populateId, metadata, filePath, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
static (DateTime?, DateTime[], int?, string?) Get(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FilePath filePath, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Property.Get(populateId, metadata, filePath, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
|
||||
(DateTime?, DateTime[], int?, string?) TestStatic_Get(IPropertyConfiguration propertyConfiguration, bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Get(propertyConfiguration, populateId, metadata, fileHolder, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
static (DateTime?, DateTime[], int?, string?) Get(IPropertyConfiguration propertyConfiguration, bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Property.Get(populateId, metadata, FilePath.Get(propertyConfiguration, fileHolder, index: null), isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
|
||||
public static (string?, DateTime[], Shared.Models.Property) GetProperty(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FilePath filePath, Shared.Models.Property? property, bool isIgnoreExtension, bool isValidImageFormatExtension, int? id, ASCIIEncoding asciiEncoding) =>
|
||||
Property.GetProperty(populateId, metadata, filePath, property, isIgnoreExtension, isValidImageFormatExtension, id, asciiEncoding);
|
||||
|
||||
internal byte[] TestStatic_GetBytes(string value) =>
|
||||
GetBytes(value);
|
||||
|
||||
internal DateTime? TestStatic_GetDateTime(string dateTimeFormat, string? value) =>
|
||||
GetDateTime(dateTimeFormat, value);
|
||||
|
||||
internal double TestStatic_GetStandardDeviation(List<long> values, double average) =>
|
||||
GetStandardDeviation(values, average);
|
||||
|
||||
internal bool TestStatic_Any(Container.Models.Container[] propertyHolderCollections) =>
|
||||
Any(propertyHolderCollections);
|
||||
|
||||
internal TimeSpan TestStatic_GetThreeStandardDeviationHigh(int minimum, Container.Models.Container container) =>
|
||||
GetThreeStandardDeviationHigh(minimum, container);
|
||||
|
||||
internal PropertyItem TestStatic_GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value) =>
|
||||
GetPropertyItem(constructorInfo, id, type, value);
|
||||
|
||||
internal (int, List<DateTime>, List<Item>) TestStatic_Get(Container.Models.Container container, TimeSpan threeStandardDeviationHigh, int i) =>
|
||||
Get(container, threeStandardDeviationHigh, i);
|
||||
|
||||
internal (DateTime?, DateTime[], int?, string?) TestStatic_Get(bool populateId, FilePath filePath, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Get(populateId, filePath, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
|
||||
internal (DateTime?, DateTime[], int?, string?) TestStatic_Get(IPropertyConfiguration propertyConfiguration, bool populateId, FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Get(propertyConfiguration, populateId, fileHolder, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
|
||||
internal (DateTime?, DateTime[], int?, string?) TestStatic_Get(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FilePath filePath, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Get(populateId, metadata, filePath, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
|
||||
internal (DateTime?, DateTime[], int?, string?) TestStatic_Get(IPropertyConfiguration propertyConfiguration, bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding) =>
|
||||
Get(propertyConfiguration, populateId, metadata, fileHolder, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
|
||||
internal (string?, DateTime[], Shared.Models.Property) TestStatic_GetProperty(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FilePath filePath, Shared.Models.Property? property, bool isIgnoreExtension, bool isValidImageFormatExtension, int? id, ASCIIEncoding asciiEncoding) =>
|
||||
GetProperty(populateId, metadata, filePath, property, isIgnoreExtension, isValidImageFormatExtension, id, asciiEncoding);
|
||||
|
||||
}
|
@ -3,52 +3,44 @@ namespace View_by_Distance.Property.Models.Stateless;
|
||||
public interface IResult
|
||||
{
|
||||
|
||||
public static string GetRelativePath(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string path) =>
|
||||
string TestStatic_GetRelativePath(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string path) =>
|
||||
GetRelativePath(propertyConfiguration, path);
|
||||
static string GetRelativePath(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string path) =>
|
||||
Result.GetRelativePath(propertyConfiguration, path);
|
||||
|
||||
public static string GetResultsGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description) =>
|
||||
Result.GetResultsGroupDirectory(propertyConfiguration, description, create: true);
|
||||
|
||||
public static string GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description) =>
|
||||
Result.GetResultsDateGroupDirectory(propertyConfiguration, description);
|
||||
|
||||
public static string GetResultsGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, bool create) =>
|
||||
string TestStatic_GetResultsGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, bool create) =>
|
||||
GetResultsGroupDirectory(propertyConfiguration, description, create);
|
||||
static string GetResultsGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, bool create) =>
|
||||
Result.GetResultsGroupDirectory(propertyConfiguration, description, create);
|
||||
|
||||
public static string GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string jsonGroup) =>
|
||||
string TestStatic_GetResultsGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description) =>
|
||||
GetResultsGroupDirectory(propertyConfiguration, description);
|
||||
static string GetResultsGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description) =>
|
||||
Result.GetResultsGroupDirectory(propertyConfiguration, description, create: true);
|
||||
|
||||
string TestStatic_GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description) =>
|
||||
GetResultsDateGroupDirectory(propertyConfiguration, description);
|
||||
static string GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description) =>
|
||||
Result.GetResultsDateGroupDirectory(propertyConfiguration, description);
|
||||
|
||||
string TestStatic_GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string jsonGroup) =>
|
||||
GetResultsDateGroupDirectory(propertyConfiguration, description, jsonGroup);
|
||||
static string GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string jsonGroup) =>
|
||||
Result.GetResultsDateGroupDirectory(propertyConfiguration, description, jsonGroup);
|
||||
|
||||
public static string GetResultsFullGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel) =>
|
||||
Result.GetResultsFullGroupDirectory(propertyConfiguration, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel);
|
||||
|
||||
public static List<string> GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted) =>
|
||||
List<string> TestStatic_GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted) =>
|
||||
GetDirectoryInfoCollection(propertyConfiguration, sourceDirectory, dateGroupDirectory, contentDescription, singletonDescription, collectionDescription, converted);
|
||||
static List<string> GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted) =>
|
||||
Result.GetDirectoryInfoCollection(propertyConfiguration, sourceDirectory, dateGroupDirectory, contentDescription, singletonDescription, collectionDescription, converted);
|
||||
|
||||
public static List<string> GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription) =>
|
||||
string TestStatic_GetResultsFullGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel) =>
|
||||
GetResultsFullGroupDirectory(propertyConfiguration, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel);
|
||||
static string GetResultsFullGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel) =>
|
||||
Result.GetResultsFullGroupDirectory(propertyConfiguration, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel);
|
||||
|
||||
List<string> TestStatic_GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription) =>
|
||||
GetDirectoryInfoCollection(propertyConfiguration, sourceDirectory, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel, contentDescription, singletonDescription, collectionDescription);
|
||||
static List<string> GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription) =>
|
||||
Result.GetDirectoryInfoCollection(propertyConfiguration, sourceDirectory, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel, contentDescription, singletonDescription, collectionDescription);
|
||||
|
||||
internal string TestStatic_GetRelativePath(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string path) =>
|
||||
GetRelativePath(propertyConfiguration, path);
|
||||
|
||||
internal string TestStatic_GetResultsGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description) =>
|
||||
GetResultsGroupDirectory(propertyConfiguration, description);
|
||||
|
||||
internal string TestStatic_GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description) =>
|
||||
GetResultsDateGroupDirectory(propertyConfiguration, description);
|
||||
|
||||
internal string TestStatic_GetResultsGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, bool create) =>
|
||||
GetResultsGroupDirectory(propertyConfiguration, description, create);
|
||||
|
||||
internal string TestStatic_GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string jsonGroup) =>
|
||||
GetResultsDateGroupDirectory(propertyConfiguration, description, jsonGroup);
|
||||
|
||||
internal string TestStatic_GetResultsFullGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel) =>
|
||||
GetResultsFullGroupDirectory(propertyConfiguration, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel);
|
||||
|
||||
internal List<string> TestStatic_GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted) =>
|
||||
GetDirectoryInfoCollection(propertyConfiguration, sourceDirectory, dateGroupDirectory, contentDescription, singletonDescription, collectionDescription, converted);
|
||||
|
||||
internal List<string> TestStatic_GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription) =>
|
||||
GetDirectoryInfoCollection(propertyConfiguration, sourceDirectory, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel, contentDescription, singletonDescription, collectionDescription);
|
||||
|
||||
}
|
@ -14,53 +14,56 @@ namespace View_by_Distance.Property.Models.Stateless;
|
||||
internal partial class Property
|
||||
{
|
||||
|
||||
internal static TimeSpan GetThreeStandardDeviationHigh(int minimum, Container.Models.Container container)
|
||||
[GeneratedRegex(@"\D+")]
|
||||
private static partial Regex Digit();
|
||||
|
||||
private static List<DateTime> GetDateTimes(DateTime dateTimeFromName, DateTime?[] dateTimes)
|
||||
{
|
||||
TimeSpan result;
|
||||
DateTime? minimumDateTime;
|
||||
List<long> ticksCollection = [];
|
||||
foreach (Item item in container.Items)
|
||||
List<DateTime> results = [dateTimeFromName];
|
||||
foreach (DateTime? dateTime in dateTimes)
|
||||
{
|
||||
if (item.ExifDirectory is null)
|
||||
if (dateTime is null)
|
||||
continue;
|
||||
minimumDateTime = Shared.Models.Stateless.Methods.IDate.GetMinimum(item.ExifDirectory);
|
||||
if (minimumDateTime is null)
|
||||
continue;
|
||||
ticksCollection.Add(minimumDateTime.Value.Ticks);
|
||||
results.Add(dateTime.Value);
|
||||
}
|
||||
long threeStandardDeviationHigh;
|
||||
long min;
|
||||
if (ticksCollection.Count == 0)
|
||||
min = 0;
|
||||
else
|
||||
min = ticksCollection.Min();
|
||||
if (ticksCollection.Count < minimum)
|
||||
threeStandardDeviationHigh = long.MaxValue;
|
||||
else
|
||||
threeStandardDeviationHigh = GetThreeStandardDeviationHigh(ref ticksCollection, min);
|
||||
result = new TimeSpan(threeStandardDeviationHigh - min);
|
||||
return result;
|
||||
return results;
|
||||
}
|
||||
|
||||
private static long GetThreeStandardDeviationHigh(ref List<long> ticksCollection, long min)
|
||||
private static List<DateTime> GetDateTimes(DateTime?[] dateTimes, DateTime?[] metadataDateTimes)
|
||||
{
|
||||
long result;
|
||||
ticksCollection = (from l in ticksCollection select l - min).ToList();
|
||||
double sum = ticksCollection.Sum();
|
||||
double average = sum / ticksCollection.Count;
|
||||
double standardDeviation = GetStandardDeviation(ticksCollection, average);
|
||||
result = (long)Math.Ceiling(average + min + (standardDeviation * 3));
|
||||
return result;
|
||||
List<DateTime> results = [];
|
||||
foreach (DateTime? dateTime in metadataDateTimes)
|
||||
{
|
||||
if (dateTime is null || results.Contains(dateTime.Value))
|
||||
continue;
|
||||
results.Add(dateTime.Value);
|
||||
}
|
||||
foreach (DateTime? dateTime in dateTimes)
|
||||
{
|
||||
if (dateTime is null || results.Contains(dateTime.Value))
|
||||
continue;
|
||||
results.Add(dateTime.Value);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static double GetStandardDeviation(List<long> values, double average)
|
||||
private static List<DateTime> GetDateTimes(FilePath filePath, DateTime?[] dateTimes)
|
||||
{
|
||||
double result = 0;
|
||||
if (values.Count == 0)
|
||||
throw new Exception("Collection must have at least one value!");
|
||||
double sum = values.Sum(l => (l - average) * (l - average));
|
||||
result = Math.Sqrt(sum / values.Count);
|
||||
return result;
|
||||
List<DateTime> results = [];
|
||||
string[] digits = Digit().Split(filePath.FullName);
|
||||
foreach (string digit in digits)
|
||||
{
|
||||
if (digit.Length != 4 || digit[..2] is not "19" and not "20" || !int.TryParse(digit, out int year))
|
||||
continue;
|
||||
results.Add(new(year, 1, 1));
|
||||
}
|
||||
foreach (DateTime? dateTime in dateTimes)
|
||||
{
|
||||
if (dateTime is null)
|
||||
continue;
|
||||
results.Add(dateTime.Value);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static byte[] GetBytes(string value)
|
||||
@ -108,12 +111,12 @@ internal partial class Property
|
||||
format = dateFormat[1];
|
||||
length = dateFormat[0].Length + dateFormat[1].Length;
|
||||
for (int i = dateFormat[0].Length; i < length; i++)
|
||||
_ = value.Append(filePath.FileNameFirstSegment[i]);
|
||||
_ = value.Append(filePath.NameWithoutExtension[i]);
|
||||
if (value.Length != format.Length)
|
||||
continue;
|
||||
if (DateTime.TryParseExact(value.ToString(), format, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime checkDateTime))
|
||||
{
|
||||
if (filePath.NameWithoutExtension.Length < ticksExample.Length || !long.TryParse(filePath.FileNameFirstSegment[^ticksExample.Length..], out long ticks))
|
||||
if (filePath.NameWithoutExtension.Length < ticksExample.Length || !long.TryParse(filePath.NameWithoutExtension[^ticksExample.Length..], out long ticks))
|
||||
result = checkDateTime;
|
||||
else
|
||||
result = new DateTime(ticks);
|
||||
@ -123,40 +126,22 @@ internal partial class Property
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static bool Any(Container.Models.Container[] containers)
|
||||
private static List<DateTime> GetDateTimes(DateTime?[] metadataDateTimes)
|
||||
{
|
||||
bool result = false;
|
||||
foreach (Container.Models.Container container in containers)
|
||||
List<DateTime> results = [];
|
||||
foreach (DateTime? dateTime in metadataDateTimes)
|
||||
{
|
||||
if (container.Items.Count == 0)
|
||||
if (dateTime is null || results.Contains(dateTime.Value))
|
||||
continue;
|
||||
if ((from l in container.Items where l.Any() select true).Any())
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
results.Add(dateTime.Value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static DateTime? GetDateTime(string dateTimeFormat, string? value)
|
||||
{
|
||||
DateTime? result;
|
||||
string alternateFormat = "ddd MMM dd HH:mm:ss yyyy";
|
||||
if (value is not null && DateTime.TryParse(value, out DateTime dateTime))
|
||||
result = dateTime;
|
||||
else if (value is not null && value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||
result = dateTime;
|
||||
else if (value is not null && value.Length == alternateFormat.Length && DateTime.TryParseExact(value, alternateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||
result = dateTime;
|
||||
else
|
||||
result = null;
|
||||
return result;
|
||||
}
|
||||
#pragma warning disable CA1416
|
||||
|
||||
internal static PropertyItem GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value)
|
||||
{
|
||||
#pragma warning disable CA1416
|
||||
PropertyItem result = (PropertyItem)constructorInfo.Invoke(null);
|
||||
int length;
|
||||
byte[] bytes;
|
||||
@ -176,65 +161,27 @@ internal partial class Property
|
||||
result.Len = length;
|
||||
result.Type = type;
|
||||
result.Value = bytes;
|
||||
#pragma warning restore CA1416
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static (int, List<DateTime>, List<Item>) Get(Container.Models.Container container, TimeSpan threeStandardDeviationHigh, int i)
|
||||
#pragma warning restore CA1416
|
||||
|
||||
internal static DateTime? GetDateTime(string dateTimeFormat, string? value)
|
||||
{
|
||||
List<Item> results = [];
|
||||
int j = i;
|
||||
long? ticks;
|
||||
TimeSpan timeSpan;
|
||||
Item item;
|
||||
DateTime? minimumDateTime;
|
||||
Item nextItem;
|
||||
DateTime? nextMinimumDateTime;
|
||||
List<DateTime> dateTimes = [];
|
||||
for (; j < container.Items.Count; j++)
|
||||
{
|
||||
ticks = null;
|
||||
item = container.Items[j];
|
||||
if (item.ExifDirectory is null)
|
||||
continue;
|
||||
minimumDateTime = Shared.Models.Stateless.Methods.IDate.GetMinimum(item.ExifDirectory);
|
||||
if (minimumDateTime is null)
|
||||
continue;
|
||||
for (int k = j + 1; k < container.Items.Count; k++)
|
||||
{
|
||||
nextItem = container.Items[k];
|
||||
if (nextItem.ExifDirectory is null)
|
||||
continue;
|
||||
nextMinimumDateTime = Shared.Models.Stateless.Methods.IDate.GetMinimum(nextItem.ExifDirectory);
|
||||
if (nextMinimumDateTime is null)
|
||||
continue;
|
||||
ticks = nextMinimumDateTime.Value.Ticks;
|
||||
break;
|
||||
}
|
||||
results.Add(item);
|
||||
dateTimes.Add(minimumDateTime.Value);
|
||||
if (ticks.HasValue)
|
||||
{
|
||||
timeSpan = new(ticks.Value - minimumDateTime.Value.Ticks);
|
||||
if (timeSpan > threeStandardDeviationHigh)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new(j, dateTimes, results);
|
||||
DateTime? result;
|
||||
string alternateFormat = "ddd MMM dd HH:mm:ss yyyy";
|
||||
if (value is not null && DateTime.TryParse(value, out DateTime dateTime))
|
||||
result = dateTime;
|
||||
else if (value is not null && value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||
result = dateTime;
|
||||
else if (value is not null && value.Length == alternateFormat.Length && DateTime.TryParseExact(value, alternateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||
result = dateTime;
|
||||
else
|
||||
result = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static (DateTime?, DateTime[], int?, string?) Get(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FilePath filePath, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding)
|
||||
{
|
||||
int? id = null;
|
||||
string? message;
|
||||
DateTime[] dateTimes;
|
||||
Shared.Models.Property? property = null;
|
||||
if (isIgnoreExtension || !isValidImageFormatExtension)
|
||||
(message, dateTimes, property) = (null, [], null);
|
||||
else
|
||||
(message, dateTimes, property) = GetProperty(populateId, metadata, filePath, property, isIgnoreExtension, isValidImageFormatExtension, id, asciiEncoding);
|
||||
return new(property?.DateTimeOriginal, dateTimes, property?.Id, message);
|
||||
}
|
||||
#pragma warning disable CA1416
|
||||
|
||||
internal static (string?, DateTime[], Shared.Models.Property) GetProperty(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FilePath filePath, Shared.Models.Property? property, bool isIgnoreExtension, bool isValidImageFormatExtension, int? id, ASCIIEncoding asciiEncoding)
|
||||
{
|
||||
@ -278,7 +225,6 @@ internal partial class Property
|
||||
{
|
||||
try
|
||||
{
|
||||
#pragma warning disable CA1416
|
||||
using Image image = Image.FromFile(filePath.FullName);
|
||||
width = image.Width;
|
||||
height = image.Height;
|
||||
@ -294,7 +240,7 @@ internal partial class Property
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
id ??= Shared.Models.Stateless.Methods.IId.GetDeterministicHashCode(bytes);
|
||||
}
|
||||
dateTimeFormat = IProperty.DateTimeFormat;
|
||||
dateTimeFormat = IProperty.DateTimeFormat();
|
||||
if (image.PropertyIdList.Contains(MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagDateTime))
|
||||
{
|
||||
propertyItem = image.GetPropertyItem(MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagDateTime);
|
||||
@ -372,7 +318,6 @@ internal partial class Property
|
||||
keywords = Encoding.Unicode.GetString(propertyItem.Value).Trim('\0', ' ').Split(';');
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1416
|
||||
message = null;
|
||||
dateTimes = [new(filePath.LastWriteTicks), new(filePath.CreationTicks), dateTime, dateTimeDigitized, dateTimeOriginal, gpsDateStamp];
|
||||
}
|
||||
@ -406,68 +351,19 @@ internal partial class Property
|
||||
return (message, dateTimesByLogic.ToArray(), result);
|
||||
}
|
||||
|
||||
private static List<DateTime> GetDateTimes(DateTime?[] metadataDateTimes)
|
||||
{
|
||||
List<DateTime> results = [];
|
||||
foreach (DateTime? dateTime in metadataDateTimes)
|
||||
{
|
||||
if (dateTime is null || results.Contains(dateTime.Value))
|
||||
continue;
|
||||
results.Add(dateTime.Value);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
#pragma warning restore CA1416
|
||||
|
||||
private static List<DateTime> GetDateTimes(FilePath filePath, DateTime?[] dateTimes)
|
||||
internal static (DateTime?, DateTime[], int?, string?) Get(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FilePath filePath, bool isIgnoreExtension, bool isValidImageFormatExtension, ASCIIEncoding asciiEncoding)
|
||||
{
|
||||
List<DateTime> results = [];
|
||||
string[] digits = Digit().Split(filePath.FullName);
|
||||
foreach (string digit in digits)
|
||||
{
|
||||
if (digit.Length != 4 || digit[..2] is not "19" and not "20" || !int.TryParse(digit, out int year))
|
||||
continue;
|
||||
results.Add(new(year, 1, 1));
|
||||
int? id = null;
|
||||
string? message;
|
||||
DateTime[] dateTimes;
|
||||
Shared.Models.Property? property = null;
|
||||
if (isIgnoreExtension || !isValidImageFormatExtension)
|
||||
(message, dateTimes, property) = (null, [], null);
|
||||
else
|
||||
(message, dateTimes, property) = GetProperty(populateId, metadata, filePath, property, isIgnoreExtension, isValidImageFormatExtension, id, asciiEncoding);
|
||||
return new(property?.DateTimeOriginal, dateTimes, property?.Id, message);
|
||||
}
|
||||
foreach (DateTime? dateTime in dateTimes)
|
||||
{
|
||||
if (dateTime is null)
|
||||
continue;
|
||||
results.Add(dateTime.Value);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<DateTime> GetDateTimes(DateTime dateTimeFromName, DateTime?[] dateTimes)
|
||||
{
|
||||
List<DateTime> results = [dateTimeFromName];
|
||||
foreach (DateTime? dateTime in dateTimes)
|
||||
{
|
||||
if (dateTime is null)
|
||||
continue;
|
||||
results.Add(dateTime.Value);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<DateTime> GetDateTimes(DateTime?[] dateTimes, DateTime?[] metadataDateTimes)
|
||||
{
|
||||
List<DateTime> results = [];
|
||||
foreach (DateTime? dateTime in metadataDateTimes)
|
||||
{
|
||||
if (dateTime is null || results.Contains(dateTime.Value))
|
||||
continue;
|
||||
results.Add(dateTime.Value);
|
||||
}
|
||||
foreach (DateTime? dateTime in dateTimes)
|
||||
{
|
||||
if (dateTime is null || results.Contains(dateTime.Value))
|
||||
continue;
|
||||
results.Add(dateTime.Value);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"\D+")]
|
||||
private static partial Regex Digit();
|
||||
|
||||
}
|
@ -5,25 +5,6 @@ namespace View_by_Distance.Property.Models.Stateless;
|
||||
internal class Result
|
||||
{
|
||||
|
||||
internal static string GetRelativePath(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string path) =>
|
||||
Shared.Models.Stateless.Methods.IPath.GetRelativePath(path, propertyConfiguration.RootDirectory.Length);
|
||||
|
||||
internal static string GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description)
|
||||
{
|
||||
string result = Path.Combine(GetResultsGroupDirectory(propertyConfiguration, description, create: true), propertyConfiguration.DateGroup);
|
||||
if (!Directory.Exists(result))
|
||||
_ = Directory.CreateDirectory(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetResultsGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, bool create)
|
||||
{
|
||||
string result = Path.Combine($"{propertyConfiguration.RootDirectory}-Results", description.Replace('_', ')'));
|
||||
if (create && !Directory.Exists(result))
|
||||
_ = Directory.CreateDirectory(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string jsonGroup)
|
||||
{
|
||||
string result = Path.Combine(GetResultsDateGroupDirectory(propertyConfiguration, description), jsonGroup);
|
||||
@ -32,48 +13,18 @@ internal class Result
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetResultsFullGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel)
|
||||
internal static string GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description)
|
||||
{
|
||||
string result = GetResultsDateGroupDirectory(propertyConfiguration, description);
|
||||
if (includeResizeGroup)
|
||||
result = Path.Combine(result, outputResolution);
|
||||
if (includeModel && includePredictorModel)
|
||||
{
|
||||
string modelName;
|
||||
string predictorModelName;
|
||||
if (propertyConfiguration.ModelName is null)
|
||||
modelName = Model.Hog.ToString();
|
||||
else
|
||||
modelName = propertyConfiguration.ModelName;
|
||||
if (propertyConfiguration.PredictorModelName is null)
|
||||
predictorModelName = PredictorModel.Large.ToString();
|
||||
else
|
||||
predictorModelName = propertyConfiguration.PredictorModelName;
|
||||
string dateGroupDirectory = string.Concat(outputResolution.Replace(" ", string.Empty), "-", modelName, "-", predictorModelName, "-", propertyConfiguration.NumberOfJitters, "-", propertyConfiguration.NumberOfTimesToUpsample);
|
||||
result = Path.Combine(result, dateGroupDirectory);
|
||||
}
|
||||
else if (includeModel)
|
||||
throw new Exception();
|
||||
else if (includePredictorModel)
|
||||
throw new Exception();
|
||||
string result = Path.Combine(GetResultsGroupDirectory(propertyConfiguration, description, create: true), propertyConfiguration.DateGroup);
|
||||
if (!Directory.Exists(result))
|
||||
_ = Directory.CreateDirectory(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static List<string> GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted)
|
||||
internal static string GetRelativePath(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string path)
|
||||
{
|
||||
List<string> results = [];
|
||||
string sourceDirectorySegment = GetRelativePath(propertyConfiguration, sourceDirectory);
|
||||
string result = string.Concat(Path.Combine(dateGroupDirectory, "<>"), sourceDirectorySegment);
|
||||
if (!string.IsNullOrEmpty(contentDescription))
|
||||
CheckContent(propertyConfiguration, dateGroupDirectory, contentDescription, result);
|
||||
if (!string.IsNullOrEmpty(singletonDescription))
|
||||
CheckSingleton(propertyConfiguration, dateGroupDirectory, singletonDescription, converted, result);
|
||||
if (!string.IsNullOrEmpty(collectionDescription))
|
||||
CheckCollection(propertyConfiguration, dateGroupDirectory, collectionDescription, converted, result);
|
||||
results.Add(result);
|
||||
return results;
|
||||
string result = Shared.Models.Stateless.Methods.IPath.GetRelativePath(path, propertyConfiguration.RootDirectory.Length);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void CheckContent(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string dateGroupDirectory, string contentDescription, string result)
|
||||
@ -123,6 +74,58 @@ internal class Result
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
|
||||
internal static string GetResultsFullGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel)
|
||||
{
|
||||
string result = GetResultsDateGroupDirectory(propertyConfiguration, description);
|
||||
if (includeResizeGroup)
|
||||
result = Path.Combine(result, outputResolution);
|
||||
if (includeModel && includePredictorModel)
|
||||
{
|
||||
string modelName;
|
||||
string predictorModelName;
|
||||
if (propertyConfiguration.ModelName is null)
|
||||
modelName = Model.Hog.ToString();
|
||||
else
|
||||
modelName = propertyConfiguration.ModelName;
|
||||
if (propertyConfiguration.PredictorModelName is null)
|
||||
predictorModelName = PredictorModel.Large.ToString();
|
||||
else
|
||||
predictorModelName = propertyConfiguration.PredictorModelName;
|
||||
string dateGroupDirectory = string.Concat(outputResolution.Replace(" ", string.Empty), "-", modelName, "-", predictorModelName, "-", propertyConfiguration.NumberOfJitters, "-", propertyConfiguration.NumberOfTimesToUpsample);
|
||||
result = Path.Combine(result, dateGroupDirectory);
|
||||
}
|
||||
else if (includeModel)
|
||||
throw new Exception();
|
||||
else if (includePredictorModel)
|
||||
throw new Exception();
|
||||
if (!Directory.Exists(result))
|
||||
_ = Directory.CreateDirectory(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static List<string> GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted)
|
||||
{
|
||||
List<string> results = [];
|
||||
string sourceDirectorySegment = GetRelativePath(propertyConfiguration, sourceDirectory);
|
||||
string result = string.Concat(Path.Combine(dateGroupDirectory, "<>"), sourceDirectorySegment);
|
||||
if (!string.IsNullOrEmpty(contentDescription))
|
||||
CheckContent(propertyConfiguration, dateGroupDirectory, contentDescription, result);
|
||||
if (!string.IsNullOrEmpty(singletonDescription))
|
||||
CheckSingleton(propertyConfiguration, dateGroupDirectory, singletonDescription, converted, result);
|
||||
if (!string.IsNullOrEmpty(collectionDescription))
|
||||
CheckCollection(propertyConfiguration, dateGroupDirectory, collectionDescription, converted, result);
|
||||
results.Add(result);
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static string GetResultsGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, bool create)
|
||||
{
|
||||
string result = Path.Combine($"{propertyConfiguration.RootDirectory}-Results", description.Replace('_', ')'));
|
||||
if (create && !Directory.Exists(result))
|
||||
_ = Directory.CreateDirectory(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static List<string> GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription)
|
||||
{
|
||||
List<string> results;
|
||||
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Property</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -40,13 +40,12 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Container\Container.csproj" />
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -20,7 +20,7 @@ public class Rename
|
||||
bool IsIgnoreExtension,
|
||||
bool IsValidImageFormatExtension,
|
||||
List<FileHolder> FileHolders,
|
||||
bool FastForwardMovingPictureExpertsGroupFilesPresent,
|
||||
bool FfmpegFilesPresent,
|
||||
DateTime? DateTimeOriginal,
|
||||
DateTime[] DateTimes,
|
||||
int? Id);
|
||||
@ -218,11 +218,11 @@ public class Rename
|
||||
FilePath filePath;
|
||||
DateTime[] dateTimes;
|
||||
FileHolder fileHolder;
|
||||
string[]? ffmpegFiles;
|
||||
bool isIgnoreExtension;
|
||||
DateTime? dateTimeOriginal;
|
||||
bool isValidImageFormatExtension;
|
||||
ASCIIEncoding asciiEncoding = new();
|
||||
string[]? fastForwardMovingPictureExpertsGroupFiles;
|
||||
IReadOnlyList<MetadataExtractor.Directory> directories;
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
@ -234,7 +234,7 @@ public class Rename
|
||||
if (string.IsNullOrEmpty(directory))
|
||||
continue;
|
||||
filePath = FilePath.Get(_Configuration.PropertyConfiguration, fileHolder, index: i);
|
||||
if (fileHolder.ExtensionLowered == ".paddedId" || fileHolder.ExtensionLowered == ".lsv" || fileHolder.DirectoryFullPath is null)
|
||||
if (fileHolder.ExtensionLowered == ".paddedId" || fileHolder.ExtensionLowered == ".lsv" || fileHolder.DirectoryName is null)
|
||||
continue;
|
||||
if (files.Contains($"{fileHolder.FullName}.paddedId"))
|
||||
continue;
|
||||
@ -243,7 +243,7 @@ public class Rename
|
||||
isValidImageFormatExtension = _PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
isIgnoreExtension = isValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
if (!isIgnoreExtension && isValidImageFormatExtension)
|
||||
fastForwardMovingPictureExpertsGroupFiles = null;
|
||||
ffmpegFiles = null;
|
||||
else
|
||||
{
|
||||
try
|
||||
@ -251,33 +251,33 @@ public class Rename
|
||||
catch (Exception) { continue; }
|
||||
CommandTask<CommandResult> result = Cli.Wrap("ffmpeg.exe")
|
||||
// .WithArguments(new[] { "-ss", "00:00:00", "-t", "00:00:00", "-i", files[i], "-qscale:v", "2", "-r", "0.01", $"{fileHolder.Name}-%4d.jpg" })
|
||||
.WithArguments(["-i", files[i], "-vframes", "1", $"{fileHolder.Name}-%4d.jpg"])
|
||||
.WithWorkingDirectory(fileHolder.DirectoryFullPath)
|
||||
.WithArguments(new[] { "-i", files[i], "-vframes", "1", $"{fileHolder.Name}-%4d.jpg" })
|
||||
.WithWorkingDirectory(fileHolder.DirectoryName)
|
||||
.ExecuteAsync();
|
||||
result.Task.Wait();
|
||||
fastForwardMovingPictureExpertsGroupFiles = Directory.GetFiles(fileHolder.DirectoryFullPath, $"{fileHolder.Name}-*.jpg", SearchOption.TopDirectoryOnly);
|
||||
if (fastForwardMovingPictureExpertsGroupFiles.Length == 0)
|
||||
ffmpegFiles = Directory.GetFiles(fileHolder.DirectoryName, $"{fileHolder.Name}-*.jpg", SearchOption.TopDirectoryOnly);
|
||||
if (ffmpegFiles.Length == 0)
|
||||
continue;
|
||||
fileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(fastForwardMovingPictureExpertsGroupFiles.First());
|
||||
fileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(ffmpegFiles.First());
|
||||
if (!fileHolder.Name.EndsWith("-0001.jpg"))
|
||||
throw new Exception();
|
||||
isValidImageFormatExtension = _PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
isIgnoreExtension = isValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
if (isIgnoreExtension || !isValidImageFormatExtension)
|
||||
continue;
|
||||
if (fileHolder.DirectoryFullPath is null)
|
||||
if (fileHolder.DirectoryName is null)
|
||||
continue;
|
||||
}
|
||||
(dateTimeOriginal, dateTimes, id, message) = Property.Models.Stateless.IProperty.Get(_PropertyConfiguration, _PropertyConfiguration.PopulatePropertyId, metadata, fileHolder, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
if (fastForwardMovingPictureExpertsGroupFiles is not null)
|
||||
if (ffmpegFiles is not null)
|
||||
{
|
||||
fileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(files[i]);
|
||||
foreach (string fastForwardMovingPictureExpertsGroupFile in fastForwardMovingPictureExpertsGroupFiles)
|
||||
File.Delete(fastForwardMovingPictureExpertsGroupFile);
|
||||
foreach (string ffmpegFile in ffmpegFiles)
|
||||
File.Delete(ffmpegFile);
|
||||
}
|
||||
if (message is not null)
|
||||
throw new Exception(message);
|
||||
results.Add(new(i + offset, isIgnoreExtension, isValidImageFormatExtension, [fileHolder], fastForwardMovingPictureExpertsGroupFiles is null, dateTimeOriginal, dateTimes, id));
|
||||
results.Add(new(i + offset, isIgnoreExtension, isValidImageFormatExtension, [fileHolder], ffmpegFiles is null, dateTimeOriginal, dateTimes, id));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
@ -311,7 +311,7 @@ public class Rename
|
||||
fileHolder = record.FileHolders.First();
|
||||
if (!fileHolder.Exists)
|
||||
continue;
|
||||
if (string.IsNullOrEmpty(fileHolder.DirectoryFullPath))
|
||||
if (string.IsNullOrEmpty(fileHolder.DirectoryName))
|
||||
continue;
|
||||
dateTimeFromName = record.DateTimes.Length == 0 ? null : record.DateTimes.First();
|
||||
if (fileHolder.ExtensionLowered == jpeg)
|
||||
@ -320,30 +320,30 @@ public class Rename
|
||||
{
|
||||
if (File.Exists($"{fileHolder.FullName}.paddedId"))
|
||||
{
|
||||
checkFile = Path.Combine(fileHolder.DirectoryFullPath, $"{fileHolder.NameWithoutExtension}{jpg}.paddedId");
|
||||
checkFile = Path.Combine(fileHolder.DirectoryName, $"{fileHolder.NameWithoutExtension}{jpg}.paddedId");
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
if (distinct.Contains(checkFile))
|
||||
continue;
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(Shared.Models.Stateless.Methods.IFileHolder.Get($"{fileHolder.FullName}.paddedId"), fileHolder.DirectoryFullPath, checkFile));
|
||||
results.Add(new(Shared.Models.Stateless.Methods.IFileHolder.Get($"{fileHolder.FullName}.paddedId"), fileHolder.DirectoryName, checkFile));
|
||||
}
|
||||
checkFile = Path.Combine(fileHolder.DirectoryFullPath, $"{fileHolder.NameWithoutExtension}{jpg}");
|
||||
checkFile = Path.Combine(fileHolder.DirectoryName, $"{fileHolder.NameWithoutExtension}{jpg}");
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
if (distinct.Contains(checkFile))
|
||||
continue;
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(fileHolder, fileHolder.DirectoryFullPath, checkFile));
|
||||
results.Add(new(fileHolder, fileHolder.DirectoryName, checkFile));
|
||||
if (nefPresent)
|
||||
results.Add(new(Shared.Models.Stateless.Methods.IFileHolder.Get($"{fileHolder.FullName[..^4]}.tif"), fileHolder.DirectoryFullPath, $"{checkFile[..^4]}.tif"));
|
||||
results.Add(new(Shared.Models.Stateless.Methods.IFileHolder.Get($"{fileHolder.FullName[..^4]}.tif"), fileHolder.DirectoryName, $"{checkFile[..^4]}.tif"));
|
||||
if (nefPresent)
|
||||
results.Add(new(Shared.Models.Stateless.Methods.IFileHolder.Get($"{fileHolder.FullName[..^4]}.nef"), fileHolder.DirectoryFullPath, $"{checkFile[..^4]}.nef"));
|
||||
results.Add(new(Shared.Models.Stateless.Methods.IFileHolder.Get($"{fileHolder.FullName[..^4]}.nef"), fileHolder.DirectoryName, $"{checkFile[..^4]}.nef"));
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(fileHolder.FullName, checkFile);
|
||||
fileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(checkFile);
|
||||
if (fileHolder.DirectoryFullPath is null)
|
||||
if (fileHolder.DirectoryName is null)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -361,13 +361,13 @@ public class Rename
|
||||
if (timeSpan is null || timeSpan.Value.TotalMinutes > _AppSettings.MaxMinutesDelta)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_AppSettings.DefaultUnknownDirectoryName))
|
||||
(isWrongYear, seasonDirectory) = (null, !_AppSettings.ForceIdName ? null : fileHolder.DirectoryFullPath);
|
||||
(isWrongYear, seasonDirectory) = (null, !_AppSettings.ForceIdName ? null : fileHolder.DirectoryName);
|
||||
else
|
||||
(isWrongYear, seasonDirectory) = (null, !_AppSettings.ForceIdName ? null : Path.Combine(fileHolder.DirectoryFullPath, _AppSettings.DefaultUnknownDirectoryName));
|
||||
(isWrongYear, seasonDirectory) = (null, !_AppSettings.ForceIdName ? null : Path.Combine(fileHolder.DirectoryName, _AppSettings.DefaultUnknownDirectoryName));
|
||||
}
|
||||
else
|
||||
{
|
||||
directoryName = Path.GetFileName(fileHolder.DirectoryFullPath);
|
||||
directoryName = Path.GetFileName(fileHolder.DirectoryName);
|
||||
directoryNameSegments = directoryName.Split(' ');
|
||||
if (dateTimeFromName is null)
|
||||
isWrongYear = null;
|
||||
@ -375,7 +375,7 @@ public class Rename
|
||||
(isWrongYear, _) = Shared.Models.Stateless.Methods.IProperty.IsWrongYear(directoryNameSegments, dateTimeFromName.Value.ToString("yyyy"));
|
||||
dateTime = minimumDateTime.Value.AddTicks(timeSpan.Value.Ticks);
|
||||
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
||||
seasonDirectory = Path.Combine(fileHolder.DirectoryFullPath, $"{dateTime.Year}.{season} {seasonName}");
|
||||
seasonDirectory = Path.Combine(fileHolder.DirectoryName, $"{dateTime.Year}.{season} {seasonName}");
|
||||
}
|
||||
if (seasonDirectory is null || (isWrongYear is not null && isWrongYear.Value))
|
||||
{
|
||||
@ -386,17 +386,17 @@ public class Rename
|
||||
if (minimumDateTime is null)
|
||||
continue;
|
||||
checkFileExtension = fileHolder.ExtensionLowered == jpeg ? jpg : fileHolder.ExtensionLowered;
|
||||
checkFile = Path.Combine(fileHolder.DirectoryFullPath, $"{minimumDateTime.Value:yyyy-MM-dd}.{minimumDateTime.Value.Ticks}.{fileHolder.Length}{checkFileExtension}");
|
||||
checkFile = Path.Combine(fileHolder.DirectoryName, $"{minimumDateTime.Value:yyyy-MM-dd}.{minimumDateTime.Value.Ticks}.{fileHolder.Length}{checkFileExtension}");
|
||||
if (checkFile == fileHolder.FullName)
|
||||
continue;
|
||||
if (distinct.Contains(checkFile))
|
||||
continue;
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(fileHolder, fileHolder.DirectoryFullPath, checkFile));
|
||||
results.Add(new(fileHolder, fileHolder.DirectoryName, checkFile));
|
||||
if (nefPresent)
|
||||
results.Add(new(Shared.Models.Stateless.Methods.IFileHolder.Get($"{fileHolder.FullName[..^4]}.tif"), fileHolder.DirectoryFullPath, $"{checkFile[..^4]}.tif"));
|
||||
results.Add(new(Shared.Models.Stateless.Methods.IFileHolder.Get($"{fileHolder.FullName[..^4]}.tif"), fileHolder.DirectoryName, $"{checkFile[..^4]}.tif"));
|
||||
if (nefPresent)
|
||||
results.Add(new(Shared.Models.Stateless.Methods.IFileHolder.Get($"{fileHolder.FullName[..^4]}.nef"), fileHolder.DirectoryFullPath, $"{checkFile[..^4]}.nef"));
|
||||
results.Add(new(Shared.Models.Stateless.Methods.IFileHolder.Get($"{fileHolder.FullName[..^4]}.nef"), fileHolder.DirectoryName, $"{checkFile[..^4]}.nef"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4,13 +4,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<UserSecretsId>6e026d2f-9edf-4c6c-a042-162758114e9a</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Rename</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -34,11 +34,11 @@
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CliWrap" Version="3.8.1" />
|
||||
<PackageReference Include="CliWrap" Version="3.6.6" />
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||
|
@ -37,13 +37,14 @@ public class C_Resize
|
||||
private readonly int _OutputResolutionHeightIndex;
|
||||
private readonly EncoderParameters _EncoderParameters;
|
||||
private readonly int _OutputResolutionOrientationIndex;
|
||||
private readonly Dictionary<string, string[]> _FileGroups;
|
||||
private readonly bool _ForceResizeLastWriteTimeToCreationTime;
|
||||
private readonly IPropertyConfiguration _PropertyConfiguration;
|
||||
private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions;
|
||||
private readonly ReadOnlyDictionary<byte, ReadOnlyCollection<string>>[] _ResultSingletonFileGroups;
|
||||
|
||||
public C_Resize(IPropertyConfiguration propertyConfiguration, bool forceResizeLastWriteTimeToCreationTime, bool overrideForResizeImages, bool propertiesChangedForResize, string[] validResolutions, ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension)
|
||||
{
|
||||
_FileGroups = [];
|
||||
_Original = "Original";
|
||||
_TempResolutionWidth = 3;
|
||||
_TempResolutionHeight = 4;
|
||||
@ -60,104 +61,11 @@ public class C_Resize
|
||||
_OverrideForResizeImages = overrideForResizeImages;
|
||||
_PropertiesChangedForResize = propertiesChangedForResize;
|
||||
_ForceResizeLastWriteTimeToCreationTime = forceResizeLastWriteTimeToCreationTime;
|
||||
_ResultSingletonFileGroups = [new(new Dictionary<byte, ReadOnlyCollection<string>>())];
|
||||
_WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||
ConstructorInfo? constructorInfo = typeof(PropertyItem).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, null, [], null) ?? throw new Exception();
|
||||
_ConstructorInfo = constructorInfo;
|
||||
}
|
||||
|
||||
public static byte[] GetBitmapData(Bitmap bitmap)
|
||||
{
|
||||
byte[] results;
|
||||
#pragma warning disable CA1416
|
||||
Rectangle rectangle = new(0, 0, bitmap.Width, bitmap.Height);
|
||||
BitmapData bitmapData = bitmap.LockBits(rectangle, ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
IntPtr intPtr = bitmapData.Scan0;
|
||||
int length = bitmapData.Stride * bitmap.Height;
|
||||
results = new byte[length];
|
||||
Marshal.Copy(intPtr, results, 0, length);
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
#pragma warning restore CA1416
|
||||
return results;
|
||||
}
|
||||
|
||||
public static (ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) GetPngLowQuality()
|
||||
{
|
||||
(ImageCodecInfo, EncoderParameters, string) result;
|
||||
#pragma warning disable CA1416
|
||||
ImageFormat imageFormat = ImageFormat.Png;
|
||||
ImageCodecInfo[] imageCodecInfoCollection = ImageCodecInfo.GetImageEncoders();
|
||||
ImageCodecInfo imageCodecInfo = (from l in imageCodecInfoCollection where l.FormatID == imageFormat.Guid select l).First();
|
||||
EncoderParameters encoderParameters = new(1);
|
||||
encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 75L);
|
||||
if (string.IsNullOrEmpty(imageCodecInfo.FilenameExtension))
|
||||
throw new NullReferenceException(nameof(imageCodecInfo.FilenameExtension));
|
||||
result = new(imageCodecInfo, encoderParameters, imageCodecInfo.FilenameExtension.Split(';')[0].ToLower()[1..]);
|
||||
#pragma warning restore CA1416
|
||||
return result;
|
||||
}
|
||||
|
||||
public static (ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) GetJpegLowQuality()
|
||||
{
|
||||
(ImageCodecInfo, EncoderParameters, string) result;
|
||||
#pragma warning disable CA1416
|
||||
ImageFormat imageFormat = ImageFormat.Jpeg;
|
||||
ImageCodecInfo[] imageCodecInfoCollection = ImageCodecInfo.GetImageEncoders();
|
||||
ImageCodecInfo imageCodecInfo = (from l in imageCodecInfoCollection where l.FormatID == imageFormat.Guid select l).First();
|
||||
EncoderParameters encoderParameters = new(1);
|
||||
encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 75L);
|
||||
if (string.IsNullOrEmpty(imageCodecInfo.FilenameExtension))
|
||||
throw new NullReferenceException(nameof(imageCodecInfo.FilenameExtension));
|
||||
result = new(imageCodecInfo, encoderParameters, imageCodecInfo.FilenameExtension.Split(';')[0].ToLower()[1..]);
|
||||
#pragma warning restore CA1416
|
||||
return result;
|
||||
}
|
||||
|
||||
public static (ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) GetTuple(string outputExtension, int outputQuality)
|
||||
{
|
||||
(ImageCodecInfo, EncoderParameters, string) result;
|
||||
#pragma warning disable CA1416
|
||||
ImageFormat imageFormat = outputExtension switch
|
||||
{
|
||||
".gif" => ImageFormat.Gif,
|
||||
".jfif" => ImageFormat.Jpeg,
|
||||
".jpe" => ImageFormat.Jpeg,
|
||||
".jpeg" => ImageFormat.Jpeg,
|
||||
".jpg" => ImageFormat.Jpeg,
|
||||
".png" => ImageFormat.Png,
|
||||
".tif" => ImageFormat.Tiff,
|
||||
".tiff" => ImageFormat.Tiff,
|
||||
_ => throw new Exception(),
|
||||
};
|
||||
ImageCodecInfo[] imageCodecInfoCollection = ImageCodecInfo.GetImageEncoders();
|
||||
ImageCodecInfo imageCodecInfo = (from l in imageCodecInfoCollection where l.FormatID == imageFormat.Guid select l).First();
|
||||
EncoderParameters encoderParameters = new(1);
|
||||
// encoderParameters.Param[0] = New EncoderParameter(Encoder.Quality, CType(75L, Int32)) 'Default
|
||||
// encoderParameters.Param[0] = New EncoderParameter(Encoder.Quality, CType(95L, Int32)) 'Paint
|
||||
encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, outputQuality);
|
||||
if (string.IsNullOrEmpty(imageCodecInfo.FilenameExtension))
|
||||
throw new NullReferenceException(nameof(imageCodecInfo.FilenameExtension));
|
||||
result = new(imageCodecInfo, encoderParameters, imageCodecInfo.FilenameExtension.Split(';')[0].ToLower()[1..]);
|
||||
#pragma warning restore CA1416
|
||||
return result;
|
||||
}
|
||||
|
||||
public FileHolder GetResizedFileHolder(string cResultsFullGroupDirectory, Item item, bool outputResolutionHasNumber, int id) =>
|
||||
GetResizedFileHolder(cResultsFullGroupDirectory, item.FilePath, outputResolutionHasNumber, $"{id}{item.FilePath.ExtensionLowered}");
|
||||
|
||||
private FileHolder GetResizedFileHolder(string cResultsFullGroupDirectory, FilePath filePath, bool outputResolutionHasNumber, string fileName)
|
||||
{
|
||||
FileHolder result;
|
||||
if (outputResolutionHasNumber)
|
||||
result = Shared.Models.Stateless.Methods.IFileHolder.Get(Path.Combine(AngleBracketCollection[0].Replace("<>", _PropertyConfiguration.ResultContent), fileName));
|
||||
else
|
||||
{
|
||||
CombinedEnumAndIndex cei = Shared.Models.Stateless.Methods.IPath.GetCombinedEnumAndIndex(_PropertyConfiguration, filePath);
|
||||
result = Shared.Models.Stateless.Methods.IFileHolder.Get(Path.Combine(cResultsFullGroupDirectory, _PropertyConfiguration.ResultContent, cei.Combined, fileName));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
@ -166,14 +74,10 @@ public class C_Resize
|
||||
|
||||
public void Update(string cResultsFullGroupDirectory)
|
||||
{
|
||||
ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePairs = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(_PropertyConfiguration, cResultsFullGroupDirectory, [_PropertyConfiguration.ResultSingleton]);
|
||||
foreach (KeyValuePair<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
if (keyValuePair.Key == _PropertyConfiguration.ResultSingleton)
|
||||
_ResultSingletonFileGroups[0] = keyValuePair.Value;
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
_FileGroups.Clear();
|
||||
ReadOnlyDictionary<string, string[]> keyValuePairs = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(_PropertyConfiguration, cResultsFullGroupDirectory, [_PropertyConfiguration.ResultSingleton]);
|
||||
foreach (KeyValuePair<string, string[]> keyValuePair in keyValuePairs)
|
||||
_FileGroups.Add(keyValuePair.Key, keyValuePair.Value);
|
||||
}
|
||||
|
||||
public void SetAngleBracketCollection(string cResultsFullGroupDirectory, string sourceDirectory)
|
||||
@ -188,224 +92,106 @@ public class C_Resize
|
||||
converted: true));
|
||||
}
|
||||
|
||||
public FileHolder GetResizedFileHolder(string cResultsFullGroupDirectory, Item item, bool outputResolutionHasNumber) =>
|
||||
GetResizedFileHolder(cResultsFullGroupDirectory, item.FilePath, outputResolutionHasNumber, item.FilePath.Name);
|
||||
#pragma warning disable CA1416
|
||||
|
||||
public Dictionary<string, int[]> GetResizeKeyValuePairs(Configuration configuration, string cResultsFullGroupDirectory, FilePath filePath, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, ExifDirectory exifDirectory, MappingFromItem mappingFromItem)
|
||||
public static (ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) GetGifLowQuality()
|
||||
{
|
||||
Dictionary<string, int[]>? results;
|
||||
string json;
|
||||
string[] changesFrom = [nameof(A_Property), nameof(B_Metadata)];
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
CombinedEnumAndIndex cei = Shared.Models.Stateless.Methods.IPath.GetCombinedEnumAndIndex(_PropertyConfiguration, filePath);
|
||||
string fileName = $"{mappingFromItem.FilePath.NameWithoutExtension}{mappingFromItem.FilePath.ExtensionLowered}.json";
|
||||
string directory = _ResultSingletonFileGroups[0][cei.Enum][cei.Index];
|
||||
FileInfo fileInfo = new(Path.Combine(directory, fileName));
|
||||
MoveIf(fileName, cei, directory, fileInfo);
|
||||
if (_ForceResizeLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete")))
|
||||
{
|
||||
File.Move(Path.ChangeExtension(fileInfo.FullName, ".delete"), fileInfo.FullName);
|
||||
fileInfo.Refresh();
|
||||
(ImageCodecInfo, EncoderParameters, string) result;
|
||||
ImageFormat imageFormat = ImageFormat.Gif;
|
||||
ImageCodecInfo imageCodecInfo = (from l in ImageCodecInfo.GetImageEncoders() where l.FormatID == imageFormat.Guid select l).First();
|
||||
EncoderParameters encoderParameters = new(1);
|
||||
encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 75L);
|
||||
if (string.IsNullOrEmpty(imageCodecInfo.FilenameExtension))
|
||||
throw new NullReferenceException(nameof(imageCodecInfo.FilenameExtension));
|
||||
result = new(imageCodecInfo, encoderParameters, imageCodecInfo.FilenameExtension.Split(';')[0].ToLower()[1..]);
|
||||
return result;
|
||||
}
|
||||
if (_ForceResizeLastWriteTimeToCreationTime && fileInfo.Exists && fileInfo.LastWriteTime != fileInfo.CreationTime)
|
||||
|
||||
public static (ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) GetPngLowQuality()
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
|
||||
fileInfo.Refresh();
|
||||
(ImageCodecInfo, EncoderParameters, string) result;
|
||||
ImageFormat imageFormat = ImageFormat.Png;
|
||||
ImageCodecInfo imageCodecInfo = (from l in ImageCodecInfo.GetImageEncoders() where l.FormatID == imageFormat.Guid select l).First();
|
||||
EncoderParameters encoderParameters = new(1);
|
||||
encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 75L);
|
||||
if (string.IsNullOrEmpty(imageCodecInfo.FilenameExtension))
|
||||
throw new NullReferenceException(nameof(imageCodecInfo.FilenameExtension));
|
||||
result = new(imageCodecInfo, encoderParameters, imageCodecInfo.FilenameExtension.Split(';')[0].ToLower()[1..]);
|
||||
return result;
|
||||
}
|
||||
if (_PropertiesChangedForResize)
|
||||
results = null;
|
||||
else if (!fileInfo.Exists)
|
||||
results = null;
|
||||
else if (!fileInfo.FullName.EndsWith(".json") && !fileInfo.FullName.EndsWith(".old"))
|
||||
throw new ArgumentException("must be a *.json file");
|
||||
else if (dateTimes.Count != 0 && dateTimes.Max() > fileInfo.LastWriteTime)
|
||||
results = null;
|
||||
else
|
||||
|
||||
public static (ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) GetTuple(string outputExtension, int outputQuality)
|
||||
{
|
||||
json = File.ReadAllText(fileInfo.FullName);
|
||||
try
|
||||
(ImageCodecInfo, EncoderParameters, string) result;
|
||||
ImageFormat imageFormat = outputExtension switch
|
||||
{
|
||||
results = JsonSerializer.Deserialize<Dictionary<string, int[]>>(json);
|
||||
if (results is null)
|
||||
throw new Exception();
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), fileInfo.LastWriteTime));
|
||||
".gif" => ImageFormat.Gif,
|
||||
".jfif" => ImageFormat.Jpeg,
|
||||
".jpe" => ImageFormat.Jpeg,
|
||||
".jpeg" => ImageFormat.Jpeg,
|
||||
".jpg" => ImageFormat.Jpeg,
|
||||
".png" => ImageFormat.Png,
|
||||
".tif" => ImageFormat.Tiff,
|
||||
".tiff" => ImageFormat.Tiff,
|
||||
_ => throw new Exception(),
|
||||
};
|
||||
ImageCodecInfo imageCodecInfo = (from l in ImageCodecInfo.GetImageEncoders() where l.FormatID == imageFormat.Guid select l).First();
|
||||
EncoderParameters encoderParameters = new(1);
|
||||
// encoderParameters.Param[0] = New EncoderParameter(Encoder.Quality, CType(75L, Int32)) 'Default
|
||||
// encoderParameters.Param[0] = New EncoderParameter(Encoder.Quality, CType(95L, Int32)) 'Paint
|
||||
encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, outputQuality);
|
||||
if (string.IsNullOrEmpty(imageCodecInfo.FilenameExtension))
|
||||
throw new NullReferenceException(nameof(imageCodecInfo.FilenameExtension));
|
||||
result = new(imageCodecInfo, encoderParameters, imageCodecInfo.FilenameExtension.Split(';')[0].ToLower()[1..]);
|
||||
return result;
|
||||
}
|
||||
catch (Exception)
|
||||
|
||||
public static byte[] GetBitmapData(Bitmap bitmap)
|
||||
{
|
||||
results = null;
|
||||
parseExceptions.Add(nameof(C_Resize));
|
||||
}
|
||||
}
|
||||
if (results is null)
|
||||
{
|
||||
results = GetImageResizes(exifDirectory);
|
||||
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
|
||||
bool updateDateWhenMatches = dateTimes.Count != 0 && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||
if (Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches, compareBeforeWrite: true, updateToWhenMatches: dateTime))
|
||||
{
|
||||
if (!_ForceResizeLastWriteTimeToCreationTime)
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
||||
else
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
|
||||
fileInfo.Refresh();
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), fileInfo.CreationTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
byte[] results;
|
||||
Rectangle rectangle = new(0, 0, bitmap.Width, bitmap.Height);
|
||||
BitmapData bitmapData = bitmap.LockBits(rectangle, ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
IntPtr intPtr = bitmapData.Scan0;
|
||||
int length = bitmapData.Stride * bitmap.Height;
|
||||
results = new byte[length];
|
||||
Marshal.Copy(intPtr, results, 0, length);
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void MoveIf(string fileName, CombinedEnumAndIndex cei, string directory, FileInfo fileInfo)
|
||||
private void CopyPropertyItems(byte[] bytes, PropertyItem[] propertyItems, Bitmap bitmap)
|
||||
{
|
||||
string[] segments = directory.Split(cei.Combined);
|
||||
string? checkDirectory = segments.Length == 1 ?
|
||||
Path.Combine(segments[0], $"{cei.Combined[2..]}") :
|
||||
segments.Length == 2 ?
|
||||
$"{segments[0]}{cei.Combined[2..]}{segments[1]}" :
|
||||
null;
|
||||
if (checkDirectory is not null && Directory.Exists(checkDirectory))
|
||||
bool hasId = false;
|
||||
int id = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagDateTimeDigitized;
|
||||
int imageWidth = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagImageWidth;
|
||||
int imageHeight = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagImageHeight;
|
||||
int orientation = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagOrientation;
|
||||
foreach (PropertyItem propertyItem in propertyItems)
|
||||
{
|
||||
string checkFile = Path.Combine(checkDirectory, fileName);
|
||||
if (File.Exists(checkFile))
|
||||
{
|
||||
File.Move(checkFile, fileInfo.FullName);
|
||||
fileInfo.Refresh();
|
||||
if (propertyItem.Id == id)
|
||||
hasId = true;
|
||||
else if (propertyItem.Id == imageWidth)
|
||||
continue;
|
||||
else if (propertyItem.Id == imageHeight)
|
||||
continue;
|
||||
else if (propertyItem.Id == orientation)
|
||||
continue;
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<string, int[]> GetImageResizes(ExifDirectory exifDirectory)
|
||||
if (!hasId)
|
||||
{
|
||||
Dictionary<string, int[]> results = [];
|
||||
int[] desired;
|
||||
int checkWidth;
|
||||
int checkHeight;
|
||||
int desiredWidth;
|
||||
int desiredHeight;
|
||||
int? orientation = Shared.Models.Stateless.Methods.IMetaBase.GetOrientation(exifDirectory.ExifBaseDirectories);
|
||||
if (exifDirectory is null || orientation is null || exifDirectory.Width is null || exifDirectory.Height is null)
|
||||
throw new NotSupportedException();
|
||||
checkWidth = exifDirectory.Width.Value;
|
||||
checkHeight = exifDirectory.Height.Value;
|
||||
if (!_ValidResolutions.Contains(_Original))
|
||||
results.Add(_Original, [checkWidth, checkHeight, orientation.Value]);
|
||||
foreach (string validResolution in _ValidResolutions)
|
||||
{
|
||||
if (validResolution == _Original)
|
||||
{
|
||||
desiredWidth = checkWidth;
|
||||
desiredHeight = checkHeight;
|
||||
PropertyItem propertyItem = (PropertyItem)_ConstructorInfo.Invoke(null);
|
||||
propertyItem.Id = id;
|
||||
propertyItem.Len = bytes.Length;
|
||||
propertyItem.Type = 2;
|
||||
propertyItem.Value = bytes;
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
desired = GetCollection(validResolution);
|
||||
desiredWidth = desired[0];
|
||||
desiredHeight = desired[1];
|
||||
}
|
||||
if (checkWidth <= desiredWidth && checkHeight <= desiredHeight)
|
||||
results.Add(validResolution, [checkWidth, checkHeight, orientation.Value]);
|
||||
else
|
||||
{
|
||||
if (desiredWidth != desiredHeight)
|
||||
{
|
||||
if (checkWidth * desiredHeight > desiredWidth * checkHeight)
|
||||
results.Add(validResolution, [desiredWidth, Convert.ToInt32(desiredWidth * checkHeight / (double)checkWidth), orientation.Value]);
|
||||
else
|
||||
results.Add(validResolution, [Convert.ToInt32(desiredHeight * checkWidth / (double)checkHeight), desiredHeight, orientation.Value]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (checkWidth * desiredHeight <= desiredWidth * checkHeight)
|
||||
results.Add(validResolution, [desiredWidth, desiredHeight, orientation.Value, desiredWidth, Convert.ToInt32(desiredWidth * checkHeight / (double)checkWidth)]);
|
||||
else
|
||||
results.Add(validResolution, [desiredWidth, desiredHeight, orientation.Value, Convert.ToInt32(desiredHeight * checkWidth / (double)checkHeight), desiredHeight]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static int[] GetCollection(string outputResolution)
|
||||
{
|
||||
List<int> results = [];
|
||||
string[] segments = outputResolution.Split('x');
|
||||
results.Add(int.Parse(segments[0]));
|
||||
results.Add(int.Parse(segments[1]));
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
public void SaveResizedSubfile(Configuration configuration, string outputResolution, string cResultsFullGroupDirectory, List<Tuple<string, DateTime>> subFileTuples, Item item, ExifDirectory exifDirectory, MappingFromItem mappingFromItem, Dictionary<string, int[]> outputResolutionToResize)
|
||||
{
|
||||
if (mappingFromItem.ResizedFileHolder is null)
|
||||
throw new NullReferenceException(nameof(mappingFromItem.ResizedFileHolder));
|
||||
#pragma warning disable CA1854
|
||||
if (!outputResolutionToResize.ContainsKey(_Original))
|
||||
throw new Exception();
|
||||
if (!outputResolutionToResize.ContainsKey(outputResolution))
|
||||
throw new Exception();
|
||||
#pragma warning restore CA1854
|
||||
FileInfo fileInfo = new(mappingFromItem.ResizedFileHolder.FullName);
|
||||
bool check = false;
|
||||
int[] resize = outputResolutionToResize[outputResolution];
|
||||
int outputResolutionWidth = resize[_OutputResolutionWidthIndex];
|
||||
int outputResolutionHeight = resize[_OutputResolutionHeightIndex];
|
||||
int outputResolutionOrientation = resize[_OutputResolutionOrientationIndex];
|
||||
int[] originalCollection = outputResolutionToResize[_Original];
|
||||
string[] changesFrom = [nameof(A_Property), nameof(B_Metadata), nameof(C_Resize)];
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
if (_OverrideForResizeImages)
|
||||
check = true;
|
||||
else if (!fileInfo.Exists)
|
||||
check = true;
|
||||
if (outputResolutionWidth == originalCollection[_OutputResolutionWidthIndex] && outputResolutionHeight == originalCollection[_OutputResolutionHeightIndex] && outputResolutionOrientation == originalCollection[_OutputResolutionOrientationIndex])
|
||||
{
|
||||
if (!check && dateTimes.Count != 0 && dateTimes.Max() > fileInfo.CreationTime.AddDays(1))
|
||||
check = true;
|
||||
if (check)
|
||||
{
|
||||
// if (fileInfo.Exists)
|
||||
// File.Delete(fileInfo.FullName);
|
||||
// File.Copy(mappingFromItem.FilePath.FullName, fileInfo.FullName);
|
||||
// item.SetResizedFileHolder(_FileNameExtension, Shared.Models.Stateless.Methods.IFileHolder.Refresh(mappingFromItem.ResizedFileHolder));
|
||||
// subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!check && dateTimes.Count != 0 && dateTimes.Max() > fileInfo.LastWriteTime)
|
||||
check = true;
|
||||
if (check)
|
||||
{
|
||||
SaveResizedSubfile(exifDirectory, mappingFromItem, resize);
|
||||
item.SetResizedFileHolder(_FileNameExtension, Shared.Models.Stateless.Methods.IFileHolder.Refresh(mappingFromItem.ResizedFileHolder));
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveResizedSubfile(ExifDirectory exifDirectory, MappingFromItem mappingFromItem, int[] resize)
|
||||
{
|
||||
string dateTimeFormat = IProperty.DateTimeFormat;
|
||||
DateTime? dateTime = Shared.Models.Stateless.Methods.IDate.GetDateTimeOriginal(exifDirectory);
|
||||
dateTime ??= Shared.Models.Stateless.Methods.IDate.GetMinimum(exifDirectory);
|
||||
string dateTimeValue = dateTime.Value.ToString(dateTimeFormat);
|
||||
byte[] bytes = _ASCIIEncoding.GetBytes(dateTimeValue);
|
||||
if (_ASCIIEncoding.GetString(bytes, 0, bytes.Length) != dateTimeValue)
|
||||
throw new Exception();
|
||||
if (resize.Length == 3)
|
||||
SaveResizedSubfile3(mappingFromItem, resize, bytes);
|
||||
else if (resize.Length == 5)
|
||||
SaveResizedSubfile5(mappingFromItem, resize, bytes);
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
private void SaveResizedSubfile3(MappingFromItem mappingFromItem, int[] resize, byte[] bytes)
|
||||
{
|
||||
Bitmap bitmap;
|
||||
#pragma warning disable CA1416
|
||||
int outputResolutionWidth = resize[_OutputResolutionWidthIndex];
|
||||
using Bitmap temp = new(mappingFromItem.FilePath.FullName, useIcm: false);
|
||||
int outputResolutionHeight = resize[_OutputResolutionHeightIndex];
|
||||
@ -445,45 +231,11 @@ public class C_Resize
|
||||
CopyPropertyItems(bytes, propertyItems, bitmap);
|
||||
bitmap.Save(mappingFromItem.ResizedFileHolder.FullName, _ImageCodecInfo, _EncoderParameters);
|
||||
bitmap.Dispose();
|
||||
#pragma warning restore CA1416
|
||||
}
|
||||
|
||||
private void CopyPropertyItems(byte[] bytes, PropertyItem[] propertyItems, Bitmap bitmap)
|
||||
{
|
||||
bool hasId = false;
|
||||
int id = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagDateTimeDigitized;
|
||||
int imageWidth = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagImageWidth;
|
||||
int imageHeight = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagImageHeight;
|
||||
int orientation = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagOrientation;
|
||||
#pragma warning disable CA1416
|
||||
foreach (PropertyItem propertyItem in propertyItems)
|
||||
{
|
||||
if (propertyItem.Id == id)
|
||||
hasId = true;
|
||||
else if (propertyItem.Id == imageWidth)
|
||||
continue;
|
||||
else if (propertyItem.Id == imageHeight)
|
||||
continue;
|
||||
else if (propertyItem.Id == orientation)
|
||||
continue;
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
}
|
||||
if (!hasId)
|
||||
{
|
||||
PropertyItem propertyItem = (PropertyItem)_ConstructorInfo.Invoke(null);
|
||||
propertyItem.Id = id;
|
||||
propertyItem.Len = bytes.Length;
|
||||
propertyItem.Type = 2;
|
||||
propertyItem.Value = bytes;
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
}
|
||||
#pragma warning restore CA1416
|
||||
}
|
||||
|
||||
private void SaveResizedSubfile5(MappingFromItem mappingFromItem, int[] resize, byte[] bytes)
|
||||
{
|
||||
Bitmap bitmap;
|
||||
#pragma warning disable CA1416
|
||||
using Bitmap temp = new(mappingFromItem.FilePath.FullName, useIcm: false);
|
||||
PropertyItem[] propertyItems = temp.PropertyItems;
|
||||
int tempResolutionWidth = resize[_TempResolutionWidth];
|
||||
@ -536,7 +288,215 @@ public class C_Resize
|
||||
bitmap.Save(mappingFromItem.ResizedFileHolder.FullName, _ImageCodecInfo, _EncoderParameters);
|
||||
}
|
||||
bitmap.Dispose();
|
||||
}
|
||||
|
||||
#pragma warning restore CA1416
|
||||
|
||||
private void SaveResizedSubfile(Shared.Models.Property property, MappingFromItem mappingFromItem, int[] resize)
|
||||
{
|
||||
string dateTimeFormat = IProperty.DateTimeFormat();
|
||||
DateTime dateTime = property.DateTimeOriginal is not null ? property.DateTimeOriginal.Value : Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(property);
|
||||
string dateTimeValue = dateTime.ToString(dateTimeFormat);
|
||||
byte[] bytes = _ASCIIEncoding.GetBytes(dateTimeValue);
|
||||
if (_ASCIIEncoding.GetString(bytes, 0, bytes.Length) != dateTimeValue)
|
||||
throw new Exception();
|
||||
if (resize.Length == 3)
|
||||
SaveResizedSubfile3(mappingFromItem, resize, bytes);
|
||||
else if (resize.Length == 5)
|
||||
SaveResizedSubfile5(mappingFromItem, resize, bytes);
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
public void SaveResizedSubfile(Configuration configuration, string outputResolution, string cResultsFullGroupDirectory, List<Tuple<string, DateTime>> subFileTuples, Item item, Shared.Models.Property property, MappingFromItem mappingFromItem, Dictionary<string, int[]> outputResolutionToResize)
|
||||
{
|
||||
if (mappingFromItem.ResizedFileHolder is null)
|
||||
throw new NullReferenceException(nameof(mappingFromItem.ResizedFileHolder));
|
||||
#pragma warning disable CA1854
|
||||
if (!outputResolutionToResize.ContainsKey(_Original))
|
||||
throw new Exception();
|
||||
if (!outputResolutionToResize.ContainsKey(outputResolution))
|
||||
throw new Exception();
|
||||
#pragma warning restore CA1854
|
||||
FileInfo fileInfo = new(mappingFromItem.ResizedFileHolder.FullName);
|
||||
bool check = false;
|
||||
int[] resize = outputResolutionToResize[outputResolution];
|
||||
int outputResolutionWidth = resize[_OutputResolutionWidthIndex];
|
||||
int outputResolutionHeight = resize[_OutputResolutionHeightIndex];
|
||||
int outputResolutionOrientation = resize[_OutputResolutionOrientationIndex];
|
||||
int[] originalCollection = outputResolutionToResize[_Original];
|
||||
string[] changesFrom = [nameof(A_Property), nameof(B_Metadata), nameof(C_Resize)];
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
if (_OverrideForResizeImages)
|
||||
check = true;
|
||||
else if (!fileInfo.Exists)
|
||||
check = true;
|
||||
if (outputResolutionWidth == originalCollection[_OutputResolutionWidthIndex] && outputResolutionHeight == originalCollection[_OutputResolutionHeightIndex] && outputResolutionOrientation == originalCollection[_OutputResolutionOrientationIndex])
|
||||
{
|
||||
if (!check && dateTimes.Count != 0 && dateTimes.Max() > fileInfo.CreationTime.AddDays(1))
|
||||
check = true;
|
||||
if (check)
|
||||
{
|
||||
// if (fileInfo.Exists)
|
||||
// File.Delete(fileInfo.FullName);
|
||||
// File.Copy(mappingFromItem.FilePath.FullName, fileInfo.FullName);
|
||||
// item.SetResizedFileHolder(_FileNameExtension, Shared.Models.Stateless.Methods.IFileHolder.Refresh(mappingFromItem.ResizedFileHolder));
|
||||
// subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!check && dateTimes.Count != 0 && dateTimes.Max() > fileInfo.LastWriteTime)
|
||||
check = true;
|
||||
if (check)
|
||||
{
|
||||
SaveResizedSubfile(property, mappingFromItem, resize);
|
||||
item.SetResizedFileHolder(_FileNameExtension, Shared.Models.Stateless.Methods.IFileHolder.Refresh(mappingFromItem.ResizedFileHolder));
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] GetCollection(string outputResolution)
|
||||
{
|
||||
List<int> results = [];
|
||||
string[] segments = outputResolution.Split('x');
|
||||
results.Add(int.Parse(segments[0]));
|
||||
results.Add(int.Parse(segments[1]));
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
private Dictionary<string, int[]> GetImageResizes(Shared.Models.Property property)
|
||||
{
|
||||
Dictionary<string, int[]> results = [];
|
||||
int[] desired;
|
||||
int checkWidth;
|
||||
int checkHeight;
|
||||
int desiredWidth;
|
||||
int desiredHeight;
|
||||
int orientation = property.Orientation is null || string.IsNullOrEmpty(property.Orientation) || !int.TryParse(property.Orientation, out int propertyOrientation) ? 0 : propertyOrientation;
|
||||
if (property is null || property.Width is null || property.Height is null)
|
||||
throw new NotSupportedException();
|
||||
checkWidth = property.Width.Value;
|
||||
checkHeight = property.Height.Value;
|
||||
if (!_ValidResolutions.Contains(_Original))
|
||||
results.Add(_Original, [checkWidth, checkHeight, orientation]);
|
||||
foreach (string validResolution in _ValidResolutions)
|
||||
{
|
||||
if (validResolution == _Original)
|
||||
{
|
||||
desiredWidth = checkWidth;
|
||||
desiredHeight = checkHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
desired = GetCollection(validResolution);
|
||||
desiredWidth = desired[0];
|
||||
desiredHeight = desired[1];
|
||||
}
|
||||
if (checkWidth <= desiredWidth && checkHeight <= desiredHeight)
|
||||
results.Add(validResolution, [checkWidth, checkHeight, orientation]);
|
||||
else
|
||||
{
|
||||
if (desiredWidth != desiredHeight)
|
||||
{
|
||||
if (checkWidth * desiredHeight > desiredWidth * checkHeight)
|
||||
results.Add(validResolution, [desiredWidth, Convert.ToInt32(desiredWidth * checkHeight / (double)checkWidth), orientation]);
|
||||
else
|
||||
results.Add(validResolution, [Convert.ToInt32(desiredHeight * checkWidth / (double)checkHeight), desiredHeight, orientation]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (checkWidth * desiredHeight <= desiredWidth * checkHeight)
|
||||
results.Add(validResolution, [desiredWidth, desiredHeight, orientation, desiredWidth, Convert.ToInt32(desiredWidth * checkHeight / (double)checkWidth)]);
|
||||
else
|
||||
results.Add(validResolution, [desiredWidth, desiredHeight, orientation, Convert.ToInt32(desiredHeight * checkWidth / (double)checkHeight), desiredHeight]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private FileHolder GetResizedFileHolder(string cResultsFullGroupDirectory, FilePath filePath, bool outputResolutionHasNumber, string fileName)
|
||||
{
|
||||
FileHolder result;
|
||||
if (outputResolutionHasNumber)
|
||||
result = Shared.Models.Stateless.Methods.IFileHolder.Get(Path.Combine(AngleBracketCollection[0].Replace("<>", _PropertyConfiguration.ResultContent), fileName));
|
||||
else
|
||||
{
|
||||
(string directoryName, _) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration, filePath);
|
||||
result = Shared.Models.Stateless.Methods.IFileHolder.Get(Path.Combine(cResultsFullGroupDirectory, _PropertyConfiguration.ResultContent, directoryName, fileName));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public FileHolder GetResizedFileHolder(string cResultsFullGroupDirectory, Item item, bool outputResolutionHasNumber) =>
|
||||
GetResizedFileHolder(cResultsFullGroupDirectory, item.FilePath, outputResolutionHasNumber, item.FilePath.Name);
|
||||
|
||||
public FileHolder GetResizedFileHolder(string cResultsFullGroupDirectory, Item item, bool outputResolutionHasNumber, int id) =>
|
||||
GetResizedFileHolder(cResultsFullGroupDirectory, item.FilePath, outputResolutionHasNumber, $"{id}{item.FilePath.ExtensionLowered}");
|
||||
|
||||
public Dictionary<string, int[]> GetResizeKeyValuePairs(Configuration configuration, string cResultsFullGroupDirectory, FilePath filePath, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Shared.Models.Property property, MappingFromItem mappingFromItem)
|
||||
{
|
||||
Dictionary<string, int[]>? results;
|
||||
string json;
|
||||
string[] changesFrom = [nameof(A_Property), nameof(B_Metadata)];
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
(_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration, filePath);
|
||||
FileInfo fileInfo = new(Path.Combine(_FileGroups[_PropertyConfiguration.ResultSingleton][directoryIndex], $"{mappingFromItem.FilePath.NameWithoutExtension}{mappingFromItem.FilePath.ExtensionLowered}.json"));
|
||||
if (_ForceResizeLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete")))
|
||||
{
|
||||
File.Move(Path.ChangeExtension(fileInfo.FullName, ".delete"), fileInfo.FullName);
|
||||
fileInfo.Refresh();
|
||||
}
|
||||
if (_ForceResizeLastWriteTimeToCreationTime && fileInfo.Exists && fileInfo.LastWriteTime != fileInfo.CreationTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
|
||||
fileInfo.Refresh();
|
||||
}
|
||||
if (_PropertiesChangedForResize)
|
||||
results = null;
|
||||
else if (!fileInfo.Exists)
|
||||
results = null;
|
||||
else if (!fileInfo.FullName.EndsWith(".json") && !fileInfo.FullName.EndsWith(".old"))
|
||||
throw new ArgumentException("must be a *.json file");
|
||||
else if (dateTimes.Count != 0 && dateTimes.Max() > fileInfo.LastWriteTime)
|
||||
results = null;
|
||||
else
|
||||
{
|
||||
json = File.ReadAllText(fileInfo.FullName);
|
||||
try
|
||||
{
|
||||
results = JsonSerializer.Deserialize<Dictionary<string, int[]>>(json);
|
||||
if (results is null)
|
||||
throw new Exception();
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), fileInfo.LastWriteTime));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
results = null;
|
||||
parseExceptions.Add(nameof(C_Resize));
|
||||
}
|
||||
}
|
||||
if (results is null)
|
||||
{
|
||||
results = GetImageResizes(property);
|
||||
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
|
||||
bool updateDateWhenMatches = dateTimes.Count != 0 && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||
if (Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches, compareBeforeWrite: true, updateToWhenMatches: dateTime))
|
||||
{
|
||||
if (!_ForceResizeLastWriteTimeToCreationTime)
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
||||
else
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
|
||||
fileInfo.Refresh();
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), fileInfo.CreationTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
@ -4,12 +4,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>library</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Resize</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -34,8 +34,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
|
@ -34,15 +34,17 @@ public class Configuration
|
||||
}
|
||||
}
|
||||
|
||||
private static Models.Configuration Get(Configuration? configuration, Property.Models.Configuration propertyConfiguration)
|
||||
private static Models.Configuration Get(Configuration? configuration)
|
||||
{
|
||||
Models.Configuration result;
|
||||
if (configuration is null) throw new NullReferenceException(nameof(configuration));
|
||||
if (configuration.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.PersonBirthdayFormat is null) throw new NullReferenceException(nameof(configuration.PersonBirthdayFormat));
|
||||
result = new(propertyConfiguration,
|
||||
if (configuration.PropertyConfiguration is null) throw new NullReferenceException(nameof(configuration.PropertyConfiguration));
|
||||
result = new(
|
||||
configuration.IgnoreExtensions,
|
||||
configuration.PersonBirthdayFormat);
|
||||
configuration.PersonBirthdayFormat,
|
||||
configuration.PropertyConfiguration);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -64,7 +66,7 @@ public class Configuration
|
||||
#pragma warning restore IL3050, IL2026
|
||||
}
|
||||
PreVerify(configurationRoot, configuration);
|
||||
result = Get(configuration, propertyConfiguration);
|
||||
result = Get(configuration);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,10 @@ public class Configuration
|
||||
public Property.Models.Configuration PropertyConfiguration => _PropertyConfiguration;
|
||||
|
||||
[JsonConstructor]
|
||||
public Configuration(Property.Models.Configuration propertyConfiguration,
|
||||
public Configuration(
|
||||
string[] ignoreExtensions,
|
||||
string personBirthdayFormat)
|
||||
string personBirthdayFormat,
|
||||
Property.Models.Configuration propertyConfiguration)
|
||||
{
|
||||
IgnoreExtensions = ignoreExtensions;
|
||||
PersonBirthdayFormat = personBirthdayFormat;
|
||||
|
@ -4,13 +4,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<UserSecretsId>b3bbcc69-1439-4e86-9bbf-75c8e8839cc0</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Set.Created.Date</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>9.0.100.1</Version>
|
||||
<Version>8.0.101.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
@ -35,9 +35,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||
|
@ -21,8 +21,8 @@ public class SetCreatedDate
|
||||
private readonly Configuration _Configuration;
|
||||
private readonly IsEnvironment _IsEnvironment;
|
||||
private readonly IConfigurationRoot _ConfigurationRoot;
|
||||
private readonly ReadOnlyDictionary<string, string[]> _FileGroups;
|
||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||
private readonly ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> _FileGroups;
|
||||
|
||||
public SetCreatedDate(List<string> args, ILogger<Program> logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||
{
|
||||
@ -78,7 +78,7 @@ public class SetCreatedDate
|
||||
{
|
||||
progressBar.Tick();
|
||||
fileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(file);
|
||||
if (fileHolder.ExtensionLowered == ".id" || fileHolder.ExtensionLowered == ".lsv" || fileHolder.DirectoryFullPath is null)
|
||||
if (fileHolder.ExtensionLowered == ".id" || fileHolder.ExtensionLowered == ".lsv" || fileHolder.DirectoryName is null)
|
||||
continue;
|
||||
if (_PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered))
|
||||
continue;
|
||||
|
@ -1,34 +0,0 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public record C_ResizeX(ReadOnlyDictionary<int, List<FilePath>> Amazon,
|
||||
ReadOnlyDictionary<int, List<FilePath>> Content,
|
||||
string OutputResolutionDirectory,
|
||||
ReadOnlyDictionary<int, ReadOnlyDictionary<string, int[]>> OutputResolutionToResize,
|
||||
ReadOnlyDictionary<int, List<FilePath>> Singleton)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, C_ResizeXSourceGenerationContext.Default.C_ResizeX);
|
||||
return result;
|
||||
}
|
||||
|
||||
// If first
|
||||
// Set OutputResolutionDirectory
|
||||
// Create a directories for Amazon, Content and Singleton
|
||||
// Populate Amazon
|
||||
// Populate Content
|
||||
// Populate Singleton
|
||||
// Populate existing OutputResolutionToResize
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(C_ResizeX))]
|
||||
public partial class C_ResizeXSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public record CombinedEnumAndIndex(string Combined,
|
||||
byte Enum,
|
||||
int Index)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, CombinedEnumAndIndexSourceGenerationContext.Default.CombinedEnumAndIndex);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(CombinedEnumAndIndex))]
|
||||
internal partial class CombinedEnumAndIndexSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user