deterministicHashCode
This commit is contained in:
23
Shared/Models/DeterministicHashCode.cs
Normal file
23
Shared/Models/DeterministicHashCode.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public record DeterministicHashCode(int? Height,
|
||||
int? Id,
|
||||
int? Width)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, DeterministicHashCodeSourceGenerationContext.Default.DeterministicHashCode);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(DeterministicHashCode))]
|
||||
public partial class DeterministicHashCodeSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
@ -10,6 +10,7 @@ public record ExifDirectory(AviDirectory AviDirectory,
|
||||
GifHeaderDirectory GifHeaderDirectory,
|
||||
GpsDirectory GpsDirectory,
|
||||
int? Height,
|
||||
int? Id,
|
||||
string JsonFile,
|
||||
JpegDirectory JpegDirectory,
|
||||
PhotoshopDirectory PhotoshopDirectory,
|
||||
|
28
Shared/Models/FilePath.cs
Normal file
28
Shared/Models/FilePath.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public record FilePath(string DirectoryName,
|
||||
string ExtensionLowered,
|
||||
string FullName,
|
||||
int? Id,
|
||||
bool IsIdFormat,
|
||||
bool IsPaddedIdFormat,
|
||||
string Name,
|
||||
string NameWithoutExtension)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, FilePathSourceGenerationContext.Default.FilePath);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(FilePath))]
|
||||
public partial class FilePathSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public record NameWithoutExtension(string FileNameWithoutExtension,
|
||||
int? Id,
|
||||
bool IsIdFormat,
|
||||
bool IsPaddedIdFormat)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, NameWithoutExtensionSourceGenerationContext.Default.NameWithoutExtension);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(NameWithoutExtension))]
|
||||
public partial class NameWithoutExtensionSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
@ -20,15 +20,27 @@ internal abstract class Id
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static NameWithoutExtension GetNameWithoutExtension(IMetadataConfiguration configuration, string file)
|
||||
internal static FilePath GetFilePath(FilePath filePath, string file)
|
||||
{
|
||||
NameWithoutExtension result;
|
||||
FilePath result;
|
||||
string fileName = Path.GetFileName(file);
|
||||
string fileExtensionLowered = Path.GetExtension(file).ToLower();
|
||||
result = new(filePath.DirectoryName, fileExtensionLowered, file, filePath.Id, filePath.IsIdFormat, filePath.IsPaddedIdFormat, fileName, filePath.NameWithoutExtension);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static FilePath GetFilePath(IMetadataConfiguration configuration, string file)
|
||||
{
|
||||
FilePath result;
|
||||
int? id;
|
||||
short? multiplier;
|
||||
char negativeMarker;
|
||||
int absoluteValueOfId;
|
||||
string fileName = Path.GetFileName(file);
|
||||
string fileExtensionLowered = Path.GetExtension(file).ToLower();
|
||||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
|
||||
short sortOrderOnlyLengthIndex = IId.GetSortOrderOnlyLengthIndex(configuration.Offset);
|
||||
string fileDirectoryName = Path.GetDirectoryName(file) ?? throw new NullReferenceException();
|
||||
bool nameWithoutExtensionIsIdFormat = IId.NameWithoutExtensionIsIdFormat(fileNameWithoutExtension);
|
||||
bool nameWithoutExtensionIsPaddedIdFormat = IId.NameWithoutExtensionIsPaddedIdFormat(fileNameWithoutExtension, sortOrderOnlyLengthIndex);
|
||||
if (!nameWithoutExtensionIsIdFormat && !nameWithoutExtensionIsPaddedIdFormat)
|
||||
@ -58,7 +70,26 @@ internal abstract class Id
|
||||
id = null;
|
||||
}
|
||||
}
|
||||
result = new(fileNameWithoutExtension, id, nameWithoutExtensionIsIdFormat, nameWithoutExtensionIsPaddedIdFormat);
|
||||
result = new(fileDirectoryName, fileExtensionLowered, file, id, nameWithoutExtensionIsIdFormat, nameWithoutExtensionIsPaddedIdFormat, fileName, fileNameWithoutExtension);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static int GetDeterministicHashCode(byte[] value)
|
||||
{
|
||||
int result;
|
||||
unchecked
|
||||
{
|
||||
int hash1 = (5381 << 16) + 5381;
|
||||
int hash2 = hash1;
|
||||
for (int i = 0; i < value.Length; i += 2)
|
||||
{
|
||||
hash1 = ((hash1 << 5) + hash1) ^ value[i];
|
||||
if (i == value.Length - 1)
|
||||
break;
|
||||
hash2 = ((hash2 << 5) + hash2) ^ value[i + 1];
|
||||
}
|
||||
result = hash1 + (hash2 * 1566083941);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,19 @@ public interface IId
|
||||
static short GetSortOrderOnlyLengthIndex(int offset) =>
|
||||
(short)(offset.ToString().Length + 3);
|
||||
|
||||
NameWithoutExtension TestStatic_GetNameWithoutExtension(IMetadataConfiguration configuration, string file) =>
|
||||
GetNameWithoutExtension(configuration, file);
|
||||
static NameWithoutExtension GetNameWithoutExtension(IMetadataConfiguration configuration, string file) =>
|
||||
Id.GetNameWithoutExtension(configuration, file);
|
||||
FilePath TestStatic_GetFilePath(FilePath filePath, string file) =>
|
||||
GetFilePath(filePath, file);
|
||||
static FilePath GetFilePath(FilePath filePath, string file) =>
|
||||
Id.GetFilePath(filePath, file);
|
||||
|
||||
FilePath TestStatic_GetFilePath(IMetadataConfiguration configuration, string file) =>
|
||||
GetFilePath(configuration, file);
|
||||
static FilePath GetFilePath(IMetadataConfiguration configuration, string file) =>
|
||||
Id.GetFilePath(configuration, file);
|
||||
|
||||
int TestStatic_GetDeterministicHashCode(byte[] value) =>
|
||||
GetDeterministicHashCode(value);
|
||||
static int GetDeterministicHashCode(byte[] value) =>
|
||||
Id.GetDeterministicHashCode(value);
|
||||
|
||||
}
|
9
Shared/Models/Stateless/Methods/IRename.cs
Normal file
9
Shared/Models/Stateless/Methods/IRename.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IRename
|
||||
{
|
||||
|
||||
string[]? ConvertAndGetFfmpegFiles(FilePath filePath);
|
||||
DeterministicHashCode GetDeterministicHashCode(FilePath filePath);
|
||||
|
||||
}
|
Reference in New Issue
Block a user