Body Changes Only

This commit is contained in:
Mike Phares 2024-08-31 08:17:11 -07:00
parent 3b63279545
commit f458af776a
11 changed files with 97 additions and 48 deletions

View File

@ -59,7 +59,7 @@ public partial class DragDropExplorer : Form
Controls.Add(_FirstTextBox);
}
void Form1_Load(object? sender, EventArgs e)
private void Form1_Load(object? sender, EventArgs e)
{
try
{
@ -81,7 +81,7 @@ public partial class DragDropExplorer : Form
return result;
}
void TextBox_LostFocus(object? sender, EventArgs e)
private void TextBox_LostFocus(object? sender, EventArgs e)
{
try
{
@ -99,7 +99,7 @@ public partial class DragDropExplorer : Form
}
}
void Form1_DragEnter(object? sender, DragEventArgs e)
private void Form1_DragEnter(object? sender, DragEventArgs e)
{
try
{
@ -112,7 +112,7 @@ public partial class DragDropExplorer : Form
}
}
void Form1_DragDrop(object? sender, DragEventArgs e)
private void Form1_DragDrop(object? sender, DragEventArgs e)
{
try
{

View File

@ -64,7 +64,7 @@ public partial class DragDropSearch : Form
Controls.Add(_TextBox);
}
void Form1_Load(object? sender, EventArgs e)
private void Form1_Load(object? sender, EventArgs e)
{
try
{
@ -79,7 +79,7 @@ public partial class DragDropSearch : Form
}
}
void TextBox_LostFocus(object? sender, EventArgs e)
private void TextBox_LostFocus(object? sender, EventArgs e)
{
try
{
@ -92,7 +92,7 @@ public partial class DragDropSearch : Form
}
}
void Form1_DragEnter(object? sender, DragEventArgs e)
private void Form1_DragEnter(object? sender, DragEventArgs e)
{
try
{
@ -105,7 +105,7 @@ public partial class DragDropSearch : Form
}
}
void LoadData()
private void LoadData()
{
Container[] containers;
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(_Configuration.PropertyConfiguration, nameof(A_Property), "{}");
@ -168,7 +168,7 @@ public partial class DragDropSearch : Form
}
}
void Form1_DragDrop(object? sender, DragEventArgs e)
private void Form1_DragDrop(object? sender, DragEventArgs e)
{
try
{

View File

@ -26,16 +26,15 @@ public abstract class DisposableObject : IDisposable
/// <summary>
/// If this object is disposed, then <see cref="ObjectDisposedException"/> is thrown.
/// </summary>
public void ThrowIfDisposed()
{
if (IsDisposed)
throw new ObjectDisposedException(GetType().FullName);
}
public void ThrowIfDisposed() =>
ObjectDisposedException.ThrowIf(IsDisposed, this);
internal void ThrowIfDisposed(string objectName)
{
#pragma warning disable CA1513
if (IsDisposed)
throw new ObjectDisposedException(objectName);
#pragma warning restore CA1513
}
#region Overrides

View File

@ -519,8 +519,12 @@ internal abstract class Exif
internal static Shared.Models.ExifDirectory GetExifDirectory(Shared.Models.FilePath filePath)
{
Shared.Models.ExifDirectory? result;
System.Drawing.Size? size = Dimensions.GetDimensions(filePath.FullName);
Shared.Models.ExifDirectory result;
System.Drawing.Size? size;
try
{ size = Dimensions.GetDimensions(filePath.FullName); }
catch (Exception)
{ size = null; }
IReadOnlyList<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(filePath.FullName);
result = Covert(filePath, size, directories);
return result;

View File

@ -35,6 +35,17 @@ internal static class Face
result = pngDirectory.TextualData[artist.Length..];
break;
}
if (result is null)
{
const string author = "Author:";
foreach (PngDirectory pngDirectory in pngDirectories)
{
if (pngDirectory.TextualData is null || !pngDirectory.TextualData.StartsWith(author))
continue;
result = pngDirectory.TextualData[author.Length..];
break;
}
}
}
return result;
}

View File

@ -112,7 +112,7 @@ public class OffsetDateTimeOriginal
string checkFile;
PropertyItem? propertyItem;
string? ticksDirectory = null;
int dateTimeOriginal = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagDateTimeOriginal;
const int dateTimeOriginal = MetadataExtractor.Formats.Exif.ExifDirectoryBase.TagDateTimeOriginal; // 36867
for (int i = 0; i < int.MaxValue; i++)
{
ticksDirectory = Path.Combine(sourceDirectory, ticks.ToString());

View File

@ -312,10 +312,12 @@ public class C_Resize
{
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];

View File

@ -81,6 +81,7 @@ internal abstract class ImageHelper
internal static Size GetDimensions(BinaryReader binaryReader, int? faceRight, int? faceBottom)
{
Size? result = null;
#pragma warning disable IDE0230
Dictionary<byte[], Func<BinaryReader, Size>> _ImageFormatDecoders = new()
{
{ new byte[] { 0x42, 0x4D }, DecodeBitmap },
@ -89,6 +90,7 @@ internal abstract class ImageHelper
{ new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }, DecodePng },
{ new byte[] { 0xff, 0xd8 }, DecodeJfif },
};
#pragma warning restore IDE0230
int maxMagicBytesLength = _ImageFormatDecoders.Keys.OrderByDescending(x => x.Length).First().Length;
byte[] magicBytes = new byte[maxMagicBytesLength];
for (int i = 0; i < maxMagicBytesLength; i += 1)

View File

@ -9,25 +9,28 @@ namespace Phares.Shared;
public static class RijndaelEncryption
{
/// <summary>
/// Change the Inputkey GUID when you use this code in your own program.
/// Keep this inputkey very safe and prevent someone from decoding it some way!!
/// Change the input key GUID when you use this code in your own program.
/// Keep this input key very safe and prevent someone from decoding it some way!!
/// Generated 2021-08-10
/// </summary>
internal const string _Inputkey = "970CCEF6-4307-4F6A-9AC8-377DADB889BD";
internal const string _InputKey = "970CCEF6-4307-4F6A-9AC8-377DADB889BD";
/// <summary>
/// Encrypt the given text and give the byte array back as a BASE64 string
/// </summary>
/// <param name="text">The text to encrypt</param>
/// <param name="salt">The pasword salt</param>
/// <param name="salt">The password salt</param>
/// <returns>The encrypted text</returns>
public static string Encrypt(string text, string salt)
{
string result;
if (string.IsNullOrEmpty(text))
throw new NullReferenceException(nameof(text));
throw new ArgumentNullException(nameof(text));
#pragma warning disable
RijndaelManaged aesAlg = NewRijndaelManaged(salt);
#pragma warning restore
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
MemoryStream msEncrypt = new();
using (CryptoStream csEncrypt = new(msEncrypt, encryptor, CryptoStreamMode.Write))
@ -46,7 +49,9 @@ public static class RijndaelEncryption
{
bool result;
base64String = base64String.Trim();
#pragma warning disable
result = (base64String.Length % 4 == 0) && Regex.IsMatch(base64String, @"^[a-zA-Z0-9\+/]*={0,3}$", RegexOptions.None);
#pragma warning restore
return result;
}
@ -54,16 +59,18 @@ public static class RijndaelEncryption
/// Decrypts the given text
/// </summary>
/// <param name="cipherText">The encrypted BASE64 text</param>
/// <param name="salt">The pasword salt</param>
/// <param name="salt">The password salt</param>
/// <returns>De gedecrypte text</returns>
public static string Decrypt(string cipherText, string salt)
{
if (string.IsNullOrEmpty(cipherText))
throw new NullReferenceException(nameof(cipherText));
throw new ArgumentNullException(nameof(cipherText));
if (!IsBase64String(cipherText))
throw new Exception("The cipherText input parameter is not base64 encoded");
string text;
#pragma warning disable
RijndaelManaged aesAlg = NewRijndaelManaged(salt);
#pragma warning restore
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
byte[] cipher = Convert.FromBase64String(cipherText);
using (MemoryStream msDecrypt = new(cipher))
@ -76,19 +83,22 @@ public static class RijndaelEncryption
}
/// <summary>
/// GetPersonName a new RijndaelManaged class and initialize it
/// Create a new RijndaelManaged class and initialize it
/// </summary>
/// <param name="salt">The pasword salt</param>
/// <param name="salt">The password salt</param>
/// <returns></returns>
#pragma warning disable
private static RijndaelManaged NewRijndaelManaged(string salt)
{
if (salt == null)
throw new NullReferenceException(nameof(salt));
throw new ArgumentNullException(nameof(salt));
byte[] saltBytes = Encoding.ASCII.GetBytes(salt);
Rfc2898DeriveBytes key = new(_Inputkey, saltBytes);
Rfc2898DeriveBytes key = new(_InputKey, saltBytes);
RijndaelManaged aesAlg = new();
#pragma warning restore
aesAlg.Key = key.GetBytes(aesAlg.KeySize / 8);
aesAlg.IV = key.GetBytes(aesAlg.BlockSize / 8);
return aesAlg;
}
}

View File

@ -4,6 +4,7 @@ using Phares.Shared;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Text.Json;
using View_by_Distance.Shared.Models;
using View_by_Distance.Shared.Models.Stateless.Methods;
using View_by_Distance.Tests.Models;
@ -14,6 +15,7 @@ namespace View_by_Distance.Tests;
public partial class UnitTestHardCoded
{
private readonly string _Git;
private readonly AppSettings _AppSettings;
private readonly string _WorkingDirectory;
private readonly Configuration _Configuration;
@ -43,6 +45,7 @@ public partial class UnitTestHardCoded
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
_Git = "c9dbce3b";
_AppSettings = appSettings;
_Configuration = configuration;
_IsEnvironment = isEnvironment;
@ -86,7 +89,7 @@ public partial class UnitTestHardCoded
[TestMethod]
public void TestMethodGetApproximateYears()
{
string personDisplayDirectory = "D:/1-Images-A/Images-7007a9df-Results/A2)People/7007a9df/{}/^/Sydney Dupray^9";
string personDisplayDirectory = string.Concat($"D:/1-Images-A/Images-{_Git}-Results/A2)People/{_Git}", "/{}/^/Sydney Dupray^9");
if (Directory.Exists(Directory.GetDirectoryRoot(personDisplayDirectory)) && Directory.Exists(personDisplayDirectory))
{
char numberSign = '#';
@ -189,7 +192,7 @@ public partial class UnitTestHardCoded
[TestMethod]
public void TestMethodRenameAbandoned()
{
string directory = "D:/1-Images-A/Images-7007a9df-Results/A2)People/7007a9df/{}/!/Abandoned";
string directory = string.Concat($"D:/1-Images-A/Images-{_Git}-Results/A2)People/{_Git}", "/{}/!/Abandoned");
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{
string checkFile;
@ -209,7 +212,7 @@ public partial class UnitTestHardCoded
[TestMethod]
public void TestMethodRenameDelete()
{
string directory = "D:/1-Images-A/Images-7007a9df-Results/A)Property/7007a9df/{}";
string directory = string.Concat($"D:/1-Images-A/Images-{_Git}-Results/A)Property/{_Git}", "/{}");
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{
string checkFile;
@ -229,7 +232,7 @@ public partial class UnitTestHardCoded
[TestMethod]
public void TestMethodRenameOld()
{
string directory = "D:/1-Images-A/Images-7007a9df-Results/E)Distance/7007a9df/()";
string directory = $"D:/1-Images-A/Images-{_Git}-Results/E)Distance/{_Git}/()";
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{
string checkFile;
@ -250,7 +253,7 @@ public partial class UnitTestHardCoded
public void TestMethodRenameDup()
{
string directory;
directory = "D:/1-Images-A/Images-7007a9df-Results/E)Distance/7007a9df/()";
directory = $"D:/1-Images-A/Images-{_Git}-Results/E)Distance/{_Git}/()";
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{
string checkFile;
@ -264,7 +267,7 @@ public partial class UnitTestHardCoded
}
Assert.IsTrue(true);
}
directory = "D:/1-Images-A/Images-7007a9df-Results/A2)People/7007a9df/{}/!";
directory = string.Concat($"D:/1-Images-A/Images-{_Git}-Results/A2)People/{_Git}", "/{}/!");
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{
string checkFile;
@ -284,9 +287,9 @@ public partial class UnitTestHardCoded
[TestMethod]
public void TestMethodRename()
{
// string directory = "D:/2-Images-B/Not-Copy-Copy-7007a9df";
string directory = "D:/1-Images-A/Images-7007a9df";
// string directory = "D:/2-Images-B/Not-Copy-Copy-7007a9df";
// string $directory = "D:/2-Images-B/Not-Copy-Copy-{_Git}";
string directory = $"D:/1-Images-A/Images-{_Git}";
// string $directory = "D:/2-Images-B/Not-Copy-Copy-{_Git}";
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{
string[] directories = Directory.GetDirectories(directory, "*;*", SearchOption.AllDirectories);
@ -301,9 +304,9 @@ public partial class UnitTestHardCoded
}
[TestMethod]
public void TestMethodRenameForUnkown()
public void TestMethodRenameForUnknown()
{
string directory = "D:/1-Images-A/Images-7007a9df-Results/E)Distance/7007a9df/(RectInt-2023-06-19-less-0.99)";
string directory = $"D:/1-Images-A/Images-{_Git}-Results/E)Distance/{_Git}/(RectInt-2023-06-19-less-0.99)";
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{
string[] files = Directory.GetFiles(directory, "*.unk", SearchOption.AllDirectories);
@ -316,13 +319,13 @@ public partial class UnitTestHardCoded
[TestMethod]
public void TestMethodRenameForTicks()
{
string directory = "D:/1-Images-A/Images-7007a9df-Results/A2)People/7007a9df/([])/ged";
string directory = $"D:/1-Images-A/Images-{_Git}-Results/A2)People/{_Git}/([])/ged";
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{
string checkName;
DateTime dateTime;
string weekOfYear;
string checkDirectoy;
string checkDirectory;
Calendar calendar = new CultureInfo("en-US").Calendar;
string[] files = Directory.GetFiles(directory, "*.ged", SearchOption.TopDirectoryOnly);
foreach (string file in files)
@ -331,10 +334,10 @@ public partial class UnitTestHardCoded
continue;
dateTime = new(ticks);
weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
checkDirectoy = Path.Combine(directory, dateTime.Year.ToString(), $"{dateTime.Year}-Week-{weekOfYear}");
checkName = Path.Combine(checkDirectoy, Path.GetFileName(file));
if (!Directory.Exists(checkDirectoy))
_ = Directory.CreateDirectory(checkDirectoy);
checkDirectory = Path.Combine(directory, dateTime.Year.ToString(), $"{dateTime.Year}-Week-{weekOfYear}");
checkName = Path.Combine(checkDirectory, Path.GetFileName(file));
if (!Directory.Exists(checkDirectory))
_ = Directory.CreateDirectory(checkDirectory);
if (File.Exists(checkName))
continue;
File.Move(file, checkName);
@ -343,4 +346,22 @@ public partial class UnitTestHardCoded
NonThrowTryCatch();
}
[TestMethod]
public void TestMethodImmichAsset()
{
if (!string.IsNullOrEmpty(_Configuration.ImmichAssetsFile) && File.Exists(_Configuration.ImmichAssetsFile))
{
Dictionary<string, ImmichAsset> keyValuePairs = [];
string json = File.ReadAllText(_Configuration.ImmichAssetsFile);
ImmichAsset[]? immichAssets = JsonSerializer.Deserialize(json, ImmichAssetCollectionSourceGenerationContext.Default.ImmichAssetArray);
if (immichAssets is not null)
{
foreach (ImmichAsset immichAsset in immichAssets)
keyValuePairs.Add(immichAsset.OriginalPath, immichAsset);
}
Assert.IsTrue(keyValuePairs.Count > 0);
}
NonThrowTryCatch();
}
}

View File

@ -11,13 +11,13 @@ public static partial class ThumbHash
private const int _MinHash = 5;
[DoesNotReturn]
static void ThrowIfLessThan<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null) => throw new ArgumentOutOfRangeException(paramName, value, $"'{value}' must be greater than or equal to '{other}'.");
private static void ThrowIfLessThan<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null) => throw new ArgumentOutOfRangeException(paramName, value, $"'{value}' must be greater than or equal to '{other}'.");
[DoesNotReturn]
static void ThrowIfGreaterThan<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null) => throw new ArgumentOutOfRangeException(paramName, value, $"'{paramName}' must be less than or equal to '{other}'.");
private static void ThrowIfGreaterThan<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null) => throw new ArgumentOutOfRangeException(paramName, value, $"'{paramName}' must be less than or equal to '{other}'.");
[DoesNotReturn]
static void ThrowNotEqual<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null, [CallerArgumentExpression(nameof(other))] string? otherName = null) => throw new ArgumentOutOfRangeException(paramName, value, $"'{paramName}' must be equal to '{other}' ('{otherName}').");
private static void ThrowNotEqual<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null, [CallerArgumentExpression(nameof(other))] string? otherName = null) => throw new ArgumentOutOfRangeException(paramName, value, $"'{paramName}' must be equal to '{other}' ('{otherName}').");
/// <summary>
/// Encodes an RGBA image to a ThumbHash.