diff --git a/.kanbn/index.md b/.kanbn/index.md index 3297951..b8bf80b 100644 --- a/.kanbn/index.md +++ b/.kanbn/index.md @@ -10,23 +10,27 @@ completedColumns: ## Backlog - [asdf](tasks/asdf.md) +- [merge-scan-photos](tasks/merge-scan-photos.md) ## Todo -- [nef-support](tasks/nef-support.md) -- [determine-if-location-container-collection-is-needed-in-get-faces](tasks/determine-if-location-container-collection-is-needed-in-get-faces.md) -- [use-photo-prism-to-map](tasks/use-photo-prism-to-map.md) - [import-face-region-metadata](tasks/import-face-region-metadata.md) +- [use-photo-prism-to-map](tasks/use-photo-prism-to-map.md) +- [determine-if-location-container-collection-is-needed-in-get-faces](tasks/determine-if-location-container-collection-is-needed-in-get-faces.md) +- [google-timeline-for-geo](tasks/google-timeline-for-geo.md) +- [merge-kristy-files](tasks/merge-kristy-files.md) +- [setup-syncthing-server](tasks/setup-syncthing-server.md) ## In Progress -- [import-know-faces-into-db](tasks/import-know-faces-into-db.md) -- [setup-photo-prism-again-in-wsl-docker](tasks/setup-photo-prism-again-in-wsl-docker.md) -- [run-scan-originals](tasks/run-scan-originals.md) - [find-incorrectly-mapped-faces](tasks/find-incorrectly-mapped-faces.md) -- [shrink-percent](tasks/shrink-percent.md) +- [nef-support](tasks/nef-support.md) - [use-eyes-to-find-orientation](tasks/use-eyes-to-find-orientation.md) +- [import-know-faces-into-db](tasks/import-know-faces-into-db.md) ## Done -- [eof-error](tasks/eof-error.md) \ No newline at end of file +- [eof-error](tasks/eof-error.md) +- [setup-photo-prism-again-in-wsl-docker](tasks/setup-photo-prism-again-in-wsl-docker.md) +- [run-scan-originals](tasks/run-scan-originals.md) +- [shrink-percent](tasks/shrink-percent.md) diff --git a/.kanbn/tasks/asdf.md b/.kanbn/tasks/asdf.md index d21e844..006bf3d 100644 --- a/.kanbn/tasks/asdf.md +++ b/.kanbn/tasks/asdf.md @@ -1,9 +1,10 @@ --- -created: 2023-06-12T15:44:11.932Z -updated: 2023-06-12T15:45:59.891Z +created: 2023-06-12T21:54:44.803Z +updated: 2023-06-12T21:54:44.803Z assigned: "" progress: 0 tags: [] +status: "1-Backlog" --- # asdf diff --git a/.kanbn/tasks/determine-if-location-container-collection-is-needed-in-get-faces.md b/.kanbn/tasks/determine-if-location-container-collection-is-needed-in-get-faces.md index a894a39..912288d 100644 --- a/.kanbn/tasks/determine-if-location-container-collection-is-needed-in-get-faces.md +++ b/.kanbn/tasks/determine-if-location-container-collection-is-needed-in-get-faces.md @@ -1,9 +1,10 @@ --- -created: 2023-06-12T15:44:11.932Z -updated: 2023-06-12T15:45:59.891Z +created: 2023-06-24T02:12:00.629Z +updated: 2023-06-24T02:12:47.758Z assigned: "" progress: 0 tags: [] +status: "2-Todo" --- # determine-if-location-container-collection-is-needed-in-get-faces diff --git a/.kanbn/tasks/eof-error.md b/.kanbn/tasks/eof-error.md index a174dda..5f9c039 100644 --- a/.kanbn/tasks/eof-error.md +++ b/.kanbn/tasks/eof-error.md @@ -1,9 +1,10 @@ --- -created: 2023-06-12T15:44:11.932Z -updated: 2023-06-12T15:45:59.891Z +created: 2023-06-12T21:55:20.591Z +updated: 2023-06-18T15:18:01.941Z assigned: "" progress: 0 tags: [] +status: "4-Done" --- # eof-error diff --git a/.kanbn/tasks/find-incorrectly-mapped-faces.md b/.kanbn/tasks/find-incorrectly-mapped-faces.md index 50e9089..08da9ba 100644 --- a/.kanbn/tasks/find-incorrectly-mapped-faces.md +++ b/.kanbn/tasks/find-incorrectly-mapped-faces.md @@ -1,9 +1,10 @@ --- -created: 2023-06-12T15:44:11.932Z -updated: 2023-06-12T15:45:59.891Z +created: 2023-06-18T20:29:10.288Z +updated: 2023-06-19T01:50:22.660Z assigned: "" progress: 0 tags: [] +status: "3-In Progress" --- # find-incorrectly-mapped-faces diff --git a/.kanbn/tasks/google-timeline-for-geo.md b/.kanbn/tasks/google-timeline-for-geo.md new file mode 100644 index 0000000..c17b12c --- /dev/null +++ b/.kanbn/tasks/google-timeline-for-geo.md @@ -0,0 +1,15 @@ +--- +created: 2023-06-25T15:26:35.170Z +updated: 2023-06-25T15:29:50.594Z +assigned: "" +progress: 0 +tags: [] +status: "2-Todo" +--- + +# google-timeline-for-geo + +## Sub-tasks + +- [ ] Download google-timeline then update images within time frame +- [ ] Determine if NIKON CORPORATION NIKON D3400 changes timezones diff --git a/.kanbn/tasks/import-face-region-metadata.md b/.kanbn/tasks/import-face-region-metadata.md index 5a36f5b..90e5aa9 100644 --- a/.kanbn/tasks/import-face-region-metadata.md +++ b/.kanbn/tasks/import-face-region-metadata.md @@ -1,9 +1,10 @@ --- -created: 2023-06-12T15:44:11.932Z -updated: 2023-06-12T15:45:59.891Z +created: 2023-06-19T21:38:12.818Z +updated: 2023-06-19T21:38:12.818Z assigned: "" progress: 0 tags: [] +status: "2-Todo" --- # import-face-region-metadata diff --git a/.kanbn/tasks/import-know-faces-into-db.md b/.kanbn/tasks/import-know-faces-into-db.md index e2db065..1a3018d 100644 --- a/.kanbn/tasks/import-know-faces-into-db.md +++ b/.kanbn/tasks/import-know-faces-into-db.md @@ -1,9 +1,10 @@ --- -created: 2023-06-12T15:44:11.932Z -updated: 2023-06-12T15:45:59.891Z +created: 2023-06-12T21:54:44.803Z +updated: 2023-06-25T01:24:50.138Z assigned: "" progress: 0 tags: [] +status: "3-In Progress" --- # import-know-faces-into-db diff --git a/.kanbn/tasks/merge-kristy-files.md b/.kanbn/tasks/merge-kristy-files.md new file mode 100644 index 0000000..1199d97 --- /dev/null +++ b/.kanbn/tasks/merge-kristy-files.md @@ -0,0 +1,14 @@ +--- +created: 2023-06-25T16:35:28.627Z +updated: 2023-06-25T16:35:35.404Z +assigned: "" +progress: 0 +tags: [] +status: "2-Todo" +--- + +# merge-kristy-files + +## Sub-tasks + +- [ ] asdf diff --git a/.kanbn/tasks/merge-scan-photos.md b/.kanbn/tasks/merge-scan-photos.md new file mode 100644 index 0000000..269b45e --- /dev/null +++ b/.kanbn/tasks/merge-scan-photos.md @@ -0,0 +1,20 @@ +--- +created: 2023-06-12T21:54:44.803Z +updated: 2023-06-12T21:54:44.803Z +assigned: "" +progress: 0 +tags: [] +status: "1-Backlog" +--- + +# merge-scan-photos + +- Inform about the few file name duplicates + +```bash +cd "D:/7) Question/- Scans 12.22 (2043)" +``` + +## Sub-tasks + +- [ ] asdf diff --git a/.kanbn/tasks/nef-support.md b/.kanbn/tasks/nef-support.md index 5c99289..087dd14 100644 --- a/.kanbn/tasks/nef-support.md +++ b/.kanbn/tasks/nef-support.md @@ -1,9 +1,10 @@ --- -created: 2023-06-12T15:44:11.932Z -updated: 2023-06-12T15:45:59.891Z +created: 2023-06-24T02:13:16.426Z +updated: 2023-06-24T02:13:20.545Z assigned: "" progress: 0 tags: [] +status: "3-In Progress" --- # nef-support diff --git a/.kanbn/tasks/run-scan-originals.md b/.kanbn/tasks/run-scan-originals.md index 6f47897..fbf10de 100644 --- a/.kanbn/tasks/run-scan-originals.md +++ b/.kanbn/tasks/run-scan-originals.md @@ -1,13 +1,14 @@ --- -created: 2023-06-12T15:44:11.932Z -updated: 2023-06-12T15:45:59.891Z +created: 2023-06-12T21:54:44.810Z +updated: 2023-06-25T16:30:22.805Z assigned: "" progress: 0 tags: [] +status: "4-Done" --- # run-scan-originals ## Sub-tasks -- [ ] run-scan-originals +- [x] run-scan-originals diff --git a/.kanbn/tasks/setup-photo-prism-again-in-wsl-docker.md b/.kanbn/tasks/setup-photo-prism-again-in-wsl-docker.md index 34fb00d..38e195e 100644 --- a/.kanbn/tasks/setup-photo-prism-again-in-wsl-docker.md +++ b/.kanbn/tasks/setup-photo-prism-again-in-wsl-docker.md @@ -1,14 +1,15 @@ --- -created: 2023-06-12T15:44:11.932Z -updated: 2023-06-12T15:45:59.891Z +created: 2023-06-12T17:28:20.080Z +updated: 2023-06-25T16:29:52.487Z assigned: "" progress: 0 tags: [] +status: "4-Done" --- # Setup PhotoPrism again in WSL / Docker ## Sub-tasks -- [ ] Install Docker -- [ ] Install WSL +- [x] Install Docker +- [x] Install WSL diff --git a/.kanbn/tasks/setup-syncthing-server.md b/.kanbn/tasks/setup-syncthing-server.md new file mode 100644 index 0000000..e7caeff --- /dev/null +++ b/.kanbn/tasks/setup-syncthing-server.md @@ -0,0 +1,19 @@ +--- +created: 2023-06-12T21:54:44.803Z +updated: 2023-06-12T21:54:44.803Z +assigned: "" +progress: 0 +tags: [] +status: "1-Backlog" +--- + +# setup-syncthing-server + +- Share one folder at a time +- Use push only feature + +## Sub-tasks + +- [ ] Use Windows box to create Syncthing server +- [ ] Find 256 GB SSD to put pictures on +- [ ] asdf diff --git a/.kanbn/tasks/shrink-percent.md b/.kanbn/tasks/shrink-percent.md index 11e0a7f..836f996 100644 --- a/.kanbn/tasks/shrink-percent.md +++ b/.kanbn/tasks/shrink-percent.md @@ -1,9 +1,10 @@ --- -created: 2023-06-12T15:44:11.932Z -updated: 2023-06-12T15:45:59.891Z +created: 2023-06-19T21:39:09.103Z +updated: 2023-06-25T16:24:52.333Z assigned: "" progress: 0 tags: [] +status: "4-Done" --- # shrink-percent diff --git a/.kanbn/tasks/use-eyes-to-find-orientation.md b/.kanbn/tasks/use-eyes-to-find-orientation.md index 2870bf7..9a10f9f 100644 --- a/.kanbn/tasks/use-eyes-to-find-orientation.md +++ b/.kanbn/tasks/use-eyes-to-find-orientation.md @@ -1,9 +1,10 @@ --- -created: 2023-06-12T15:44:11.932Z -updated: 2023-06-12T15:45:59.891Z +created: 2023-06-23T13:56:11.956Z +updated: 2023-06-24T15:11:14.038Z assigned: "" progress: 0 tags: [] +status: "3-In Progress" --- # use-eyes-to-find-orientation diff --git a/.kanbn/tasks/use-photo-prism-to-map.md b/.kanbn/tasks/use-photo-prism-to-map.md index a8b3085..fcf68df 100644 --- a/.kanbn/tasks/use-photo-prism-to-map.md +++ b/.kanbn/tasks/use-photo-prism-to-map.md @@ -1,9 +1,10 @@ --- -created: 2023-06-12T15:44:11.932Z -updated: 2023-06-12T15:45:59.891Z +created: 2023-06-19T21:38:12.818Z +updated: 2023-06-19T21:38:12.818Z assigned: "" progress: 0 tags: [] +status: "2-Todo" --- # use-photo-prism-to-map @@ -11,4 +12,4 @@ tags: [] ## Sub-tasks - [ ] Do I need to join makers with subjects -- [ ] Build logic to use photo prism to suggest missing mapping \ No newline at end of file +- [ ] Build logic to use photo prism to suggest missing mapping diff --git a/.vscode/settings.json b/.vscode/settings.json index e1798cd..17af8af 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -34,6 +34,7 @@ "Serilog", "Subfile", "Subfiles", + "Syncthing", "Unmanaged", "Upsample", "Vericruz" diff --git a/BlurHash/Models/BlurHasher.cs b/BlurHash/Models/BlurHasher.cs index b263302..2b46bd2 100644 --- a/BlurHash/Models/BlurHasher.cs +++ b/BlurHash/Models/BlurHasher.cs @@ -2,16 +2,21 @@ using System.Drawing; using System.Text; using View_by_Distance.Shared.Models; using View_by_Distance.Shared.Models.Methods; +using View_by_Distance.Shared.Models.Properties; namespace View_by_Distance.BlurHash.Models; public class C2_BlurHasher : IBlurHasher { - private readonly IReadOnlyDictionary _JsonGroups; + private readonly IPropertyConfiguration _PropertyConfiguration; + private readonly IReadOnlyDictionary _FileGroups; - public C2_BlurHasher(string resultAllInOne, string? resultsFullGroupDirectory) => - _JsonGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(resultAllInOne, resultsFullGroupDirectory, new string[] { "{}", "()" }, maxValue: 102); + public C2_BlurHasher(IPropertyConfiguration propertyConfiguration, string? resultsFullGroupDirectory) + { + _PropertyConfiguration = propertyConfiguration; + _FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, resultsFullGroupDirectory, new string[] { propertyConfiguration.ResultContent, propertyConfiguration.ResultSingleton }); + } string IBlurHasher.Encode(FileHolder fileHolder) { @@ -26,24 +31,21 @@ public class C2_BlurHasher : IBlurHasher return result; } - string? IBlurHasher.GetFile(FileHolder fileHolder) + string IBlurHasher.GetFile(FileHolder fileHolder) { - string? result; - string directory = Shared.Models.Stateless.Methods.IDirectory.GetDirectory(fileHolder.Name, length: 2); - result = !int.TryParse(directory, out int directoryIndex) ? null : Path.Combine(_JsonGroups["{}"][directoryIndex], $"{fileHolder.Name}.csv"); + string result; + (_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration.ResultAllInOneSubdirectoryLength, fileHolder.Name); + result = Path.Combine(_FileGroups[_PropertyConfiguration.ResultSingleton][directoryIndex], $"{fileHolder.Name}.csv"); return result; } string IBlurHasher.EncodeAndSave(FileHolder fileHolder) { - string? file; string result; int actualByte; string extension = ".png"; IBlurHasher blurHasher = this; - file = blurHasher.GetFile(fileHolder); - if (file is null) - throw new NullReferenceException(nameof(file)); + string file = blurHasher.GetFile(fileHolder); #pragma warning disable CA1416 Image image = Image.FromFile(fileHolder.FullName); int outputWidth = (int)(image.Width * .25); @@ -57,23 +59,20 @@ public class C2_BlurHasher : IBlurHasher string fileNameWithoutExtension = $"{componentsX}x{componentsY}-{outputWidth}x{outputHeight}-{joined}"; 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); - string directory = Shared.Models.Stateless.Methods.IDirectory.GetDirectory(joined, length: 2); - if (int.TryParse(directory, out int directoryIndex)) + (_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration.ResultAllInOneSubdirectoryLength, joined); + file = Path.Combine(_FileGroups[_PropertyConfiguration.ResultContent][directoryIndex], $"{fileNameWithoutExtension}{extension}"); + if (!File.Exists(file)) { - file = Path.Combine(_JsonGroups["()"][directoryIndex], $"{fileNameWithoutExtension}{extension}"); - if (!File.Exists(file)) + try { - try - { - using FileStream fileStream = new(file, FileMode.CreateNew); - actualImage.Save(fileStream, System.Drawing.Imaging.ImageFormat.Png); - _ = fileStream.Seek(0, SeekOrigin.Begin); + using FileStream fileStream = new(file, FileMode.CreateNew); + actualImage.Save(fileStream, System.Drawing.Imaging.ImageFormat.Png); + _ = fileStream.Seek(0, SeekOrigin.Begin); + actualByte = fileStream.ReadByte(); + while (actualByte > -1) actualByte = fileStream.ReadByte(); - while (actualByte > -1) - actualByte = fileStream.ReadByte(); - } - catch (Exception) { } } + catch (Exception) { } } image.Dispose(); #pragma warning restore CA1416 diff --git a/Copy-Distinct/CopyDistinct.cs b/Copy-Distinct/CopyDistinct.cs index de1dd74..73f1484 100644 --- a/Copy-Distinct/CopyDistinct.cs +++ b/Copy-Distinct/CopyDistinct.cs @@ -16,7 +16,7 @@ public class CopyDistinct private readonly Configuration _Configuration; private readonly IsEnvironment _IsEnvironment; private readonly IConfigurationRoot _ConfigurationRoot; - private readonly IReadOnlyDictionary _JsonGroups; + private readonly IReadOnlyDictionary _FileGroups; private readonly Property.Models.Configuration _PropertyConfiguration; public CopyDistinct(List args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console) @@ -29,10 +29,10 @@ public class CopyDistinct _IsEnvironment = isEnvironment; _WorkingDirectory = workingDirectory; _ConfigurationRoot = configurationRoot; - string[] directories = new string[] { "()" }; ILogger? log = Log.ForContext(); Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot); - _JsonGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration.ResultAllInOne, appSettings.CopyTo, directories, appSettings.MaxValue); + string[] directories = new string[] { propertyConfiguration.ResultContent }; + _FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, appSettings.CopyTo, directories); Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration); _PropertyConfiguration = propertyConfiguration; _Configuration = configuration; @@ -41,7 +41,7 @@ public class CopyDistinct Verify(); List lines = CopyDistinctFilesInDirectories(log); File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines); - if (lines.Any()) + if (!lines.Any()) _ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory); } @@ -83,13 +83,10 @@ public class CopyDistinct private List<(FileHolder, string)> GetToDoCollection(ProgressBar progressBar, List files) { List<(FileHolder, string)> results = new(); - string directory; string checkFile; int directoryIndex; FileHolder fileHolder; - bool isIgnoreExtension; List distinct = new(); - bool isValidImageFormatExtension; bool nameWithoutExtensionIsIdFormat; foreach (string file in files) { @@ -99,17 +96,15 @@ public class CopyDistinct continue; if (files.Contains($"{fileHolder.FullName}.id")) continue; - isValidImageFormatExtension = _PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered); - isIgnoreExtension = isValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered); - if (isIgnoreExtension || !isValidImageFormatExtension) - continue; nameWithoutExtensionIsIdFormat = Shared.Models.Stateless.Methods.IProperty.NameWithoutExtensionIsIdFormat(fileHolder); if (!nameWithoutExtensionIsIdFormat) - continue; - directory = Shared.Models.Stateless.Methods.IDirectory.GetDirectory(fileHolder.NameWithoutExtension, 2); - if (!int.TryParse(directory, out directoryIndex)) - continue; - checkFile = Path.Combine(_JsonGroups["()"][directoryIndex], fileHolder.Name); + { + nameWithoutExtensionIsIdFormat = Shared.Models.Stateless.Methods.IProperty.NameWithoutExtensionIsIdFormat(_PropertyConfiguration.ValidImageFormatExtensions, fileHolder); + if (!nameWithoutExtensionIsIdFormat) + continue; + } + (_, directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration.ResultAllInOneSubdirectoryLength, fileHolder.NameWithoutExtension); + checkFile = Path.Combine(_FileGroups[_PropertyConfiguration.ResultContent][directoryIndex], fileHolder.Name); if (distinct.Contains(checkFile)) continue; distinct.Add(checkFile); @@ -160,8 +155,8 @@ public class CopyDistinct ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true }; ProgressBar progressBar = new(allFiles.Count, message, options); List<(FileHolder, string)> toDoCollection = GetToDoCollection(progressBar, allFiles); - results.AddRange(Copy(log, toDoCollection)); progressBar.Dispose(); + results.AddRange(Copy(log, toDoCollection)); return results; } diff --git a/Copy-Distinct/Models/AppSettings.cs b/Copy-Distinct/Models/AppSettings.cs index 47048d0..5f087eb 100644 --- a/Copy-Distinct/Models/AppSettings.cs +++ b/Copy-Distinct/Models/AppSettings.cs @@ -9,20 +9,17 @@ public class AppSettings public string Company { init; get; } public string CopyTo { init; get; } public int MaxDegreeOfParallelism { init; get; } - public int MaxValue { init; get; } public string WorkingDirectoryName { init; get; } [JsonConstructor] public AppSettings(string company, string copyTo, int maxDegreeOfParallelism, - int maxValue, string workingDirectoryName) { Company = company; CopyTo = copyTo; MaxDegreeOfParallelism = maxDegreeOfParallelism; - MaxValue = maxValue; WorkingDirectoryName = workingDirectoryName; } diff --git a/Copy-Distinct/Models/Binder/AppSettings.cs b/Copy-Distinct/Models/Binder/AppSettings.cs index e15404c..440ae9c 100644 --- a/Copy-Distinct/Models/Binder/AppSettings.cs +++ b/Copy-Distinct/Models/Binder/AppSettings.cs @@ -10,7 +10,6 @@ public class AppSettings public string Company { get; set; } public int? MaxDegreeOfParallelism { get; set; } - public int? MaxValue { get; set; } public string CopyTo { get; set; } public string WorkingDirectoryName { get; set; } @@ -27,13 +26,10 @@ public class AppSettings Models.AppSettings result; if (appSettings?.MaxDegreeOfParallelism is null) throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism)); - if (appSettings?.MaxValue is null) - throw new NullReferenceException(nameof(appSettings.MaxValue)); result = new( appSettings.Company, appSettings.CopyTo, appSettings.MaxDegreeOfParallelism.Value, - appSettings.MaxValue.Value, appSettings.WorkingDirectoryName ); return result; diff --git a/Copy-Distinct/appsettings.json b/Copy-Distinct/appsettings.json index f0ec745..cda8ada 100644 --- a/Copy-Distinct/appsettings.json +++ b/Copy-Distinct/appsettings.json @@ -12,7 +12,6 @@ } }, "MaxDegreeOfParallelism": 6, - "MaxValue": 12, "Serilog": { "Using": [ "Serilog.Sinks.Console", @@ -64,6 +63,7 @@ "PopulatePropertyId": true, "PropertiesChangedForProperty": false, "ResultAllInOne": "_ _ _", + "ResultAllInOneSubdirectoryLength": 2, "ResultCollection": "[]", "ResultContent": "()", "ResultSingleton": "{}", diff --git a/Date-Group/appsettings.json b/Date-Group/appsettings.json index e1fc0b4..988a7e2 100644 --- a/Date-Group/appsettings.json +++ b/Date-Group/appsettings.json @@ -64,6 +64,7 @@ "PopulatePropertyId": false, "PropertiesChangedForProperty": false, "ResultAllInOne": "_ _ _", + "ResultAllInOneSubdirectoryLength": 2, "ResultCollection": "[]", "ResultContent": "()", "ResultSingleton": "{}", diff --git a/Delete-By-Distinct/appsettings.json b/Delete-By-Distinct/appsettings.json index 96b08fd..2f52075 100644 --- a/Delete-By-Distinct/appsettings.json +++ b/Delete-By-Distinct/appsettings.json @@ -66,6 +66,7 @@ "PopulatePropertyId": true, "PropertiesChangedForProperty": false, "ResultAllInOne": "_ _ _", + "ResultAllInOneSubdirectoryLength": 2, "ResultCollection": "[]", "ResultContent": "()", "ResultSingleton": "{}", diff --git a/Delete-By-Relative/appsettings.json b/Delete-By-Relative/appsettings.json index 64b4ba3..563c05f 100644 --- a/Delete-By-Relative/appsettings.json +++ b/Delete-By-Relative/appsettings.json @@ -61,6 +61,7 @@ "PopulatePropertyId": true, "PropertiesChangedForProperty": false, "ResultAllInOne": "_ _ _", + "ResultAllInOneSubdirectoryLength": 2, "ResultCollection": "[]", "ResultContent": "()", "ResultSingleton": "{}", diff --git a/Duplicate-Search/appsettings.json b/Duplicate-Search/appsettings.json index f00a5b6..1ce1ea2 100644 --- a/Duplicate-Search/appsettings.json +++ b/Duplicate-Search/appsettings.json @@ -63,6 +63,7 @@ "PopulatePropertyId": true, "PropertiesChangedForProperty": false, "ResultAllInOne": "_ _ _", + "ResultAllInOneSubdirectoryLength": 2, "ResultCollection": "[]", "ResultContent": "()", "ResultSingleton": "{}", diff --git a/Face/Models/_D_Face.cs b/Face/Models/_D_Face.cs index 94f26b2..e8ac915 100644 --- a/Face/Models/_D_Face.cs +++ b/Face/Models/_D_Face.cs @@ -11,6 +11,7 @@ using View_by_Distance.Property.Models; using View_by_Distance.Property.Models.Stateless; using View_by_Distance.Resize.Models; using View_by_Distance.Shared.Models; +using View_by_Distance.Shared.Models.Properties; using View_by_Distance.Shared.Models.Stateless; namespace View_by_Distance.Face.Models; @@ -33,7 +34,6 @@ public class D_Face private readonly string _ArgZero; private readonly Serilog.ILogger? _Log; private readonly bool _OverrideForFaceImages; - private readonly Configuration _Configuration; private readonly bool _LoadPhotoPrismLocations; private readonly ImageCodecInfo _ImageCodecInfo; private readonly ModelParameter _ModelParameter; @@ -45,14 +45,16 @@ public class D_Face private readonly int _FaceDistanceHiddenImageFactor; private readonly EncoderParameters _EncoderParameters; private readonly ImageCodecInfo _HiddenImageCodecInfo; + private readonly Dictionary _FileGroups; private readonly bool _ForceFaceLastWriteTimeToCreationTime; private readonly EncoderParameters _HiddenEncoderParameters; + private readonly IPropertyConfiguration _PropertyConfiguration; private readonly JsonSerializerOptions _WriteIndentedAndWhenWritingNull; public D_Face( string argZero, + IPropertyConfiguration propertyConfiguration, bool checkDFaceAndUpWriteDates, - Configuration configuration, EncoderParameters encoderParameters, int faceDistanceHiddenImageFactor, string filenameExtension, @@ -70,7 +72,7 @@ public class D_Face float[] rectangleIntersectMinimums) { _ArgZero = argZero; - _Configuration = configuration; + _FileGroups = new(); _ImageCodecInfo = imageCodecInfo; _EncoderParameters = encoderParameters; _FileNameExtension = filenameExtension; @@ -78,6 +80,7 @@ public class D_Face AngleBracketCollection = new List(); _HiddenImageCodecInfo = hiddenImageCodecInfo; _OverrideForFaceImages = overrideForFaceImages; + _PropertyConfiguration = propertyConfiguration; _HiddenEncoderParameters = hiddenEncoderParameters; _HiddenFileNameExtension = hiddenFileNameExtension; _LoadPhotoPrismLocations = loadPhotoPrismLocations; @@ -101,6 +104,14 @@ public class D_Face return result; } + public void Update(string dResultsFullGroupDirectory) + { + _FileGroups.Clear(); + Dictionary keyValuePairs = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(_PropertyConfiguration, dResultsFullGroupDirectory, new string[] { _PropertyConfiguration.ResultCollection }); + foreach (KeyValuePair keyValuePair in keyValuePairs) + _FileGroups.Add(keyValuePair.Key, keyValuePair.Value); + } + private static (Model model, PredictorModel predictorModel, ModelParameter modelParameter) GetModel(string modelDirectory, string modelName, string predictorModelName) { (Model, PredictorModel, ModelParameter) result; @@ -179,7 +190,7 @@ public class D_Face continue; if (face.FaceEncoding is null || face?.Location is null || face?.OutputResolution is null) continue; - location = Shared.Models.Stateless.Methods.ILocation.GetLocation(face.Location, ILocation.Digits, ILocation.Factor, source.Height, source.Width, collection.Count); + 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; @@ -202,7 +213,7 @@ public class D_Face } if (File.Exists(fileName)) File.Delete(fileName); - location = Shared.Models.Stateless.Methods.ILocation.GetLocation(_FaceDistanceHiddenImageFactor, face.Location, ILocation.Digits, ILocation.Factor, source.Height, source.Width, collection.Count); + 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; @@ -222,10 +233,10 @@ public class D_Face { if (_Log is null) throw new NullReferenceException(nameof(_Log)); - if (_Configuration.NumberOfJitters is null) - throw new NullReferenceException(nameof(_Configuration.NumberOfJitters)); - if (_Configuration.NumberOfTimesToUpsample is null) - throw new NullReferenceException(nameof(_Configuration.NumberOfTimesToUpsample)); + if (_PropertyConfiguration.NumberOfJitters is null) + throw new NullReferenceException(nameof(_PropertyConfiguration.NumberOfJitters)); + if (_PropertyConfiguration.NumberOfTimesToUpsample is null) + throw new NullReferenceException(nameof(_PropertyConfiguration.NumberOfTimesToUpsample)); List results = new(); FaceRecognitionDotNet.Image? unknownImage; try @@ -239,7 +250,7 @@ public class D_Face { (int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation) = Resize.Models.Stateless.Methods.IResize.Get(outputResolution, outputResolutionToResize); List<(Location Location, FaceRecognitionDotNet.FaceEncoding? FaceEncoding, Dictionary? FaceParts)> collection; - FaceRecognition faceRecognition = new(_Configuration.NumberOfJitters.Value, _Configuration.NumberOfTimesToUpsample.Value, _Model, _ModelParameter, _PredictorModel); + FaceRecognition faceRecognition = new(_PropertyConfiguration.NumberOfJitters.Value, _PropertyConfiguration.NumberOfTimesToUpsample.Value, _Model, _ModelParameter, _PredictorModel); collection = faceRecognition.GetCollection(unknownImage, locations, includeFaceEncoding: true, includeFaceParts: true); if (!collection.Any()) results.Add(new(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, location: null)); @@ -271,7 +282,7 @@ public class D_Face public void SetAngleBracketCollection(string dResultsFullGroupDirectory, string sourceDirectory) { AngleBracketCollection.Clear(); - AngleBracketCollection.AddRange(IResult.GetDirectoryInfoCollection(_Configuration, + AngleBracketCollection.AddRange(IResult.GetDirectoryInfoCollection(_PropertyConfiguration, sourceDirectory, dResultsFullGroupDirectory, contentDescription: "n png file(s) for each face found", @@ -290,7 +301,7 @@ public class D_Face throw new NullReferenceException(nameof(item.ImageFileHolder.DirectoryName)); SetAngleBracketCollection(dResultsFullGroupDirectory, item.ImageFileHolder.DirectoryName); } - result = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), item.ImageFileHolder.NameWithoutExtension); + result = Path.Combine(AngleBracketCollection[0].Replace("<>", _PropertyConfiguration.ResultContent), item.ImageFileHolder.NameWithoutExtension); if (!angleBracketCollectionAny) AngleBracketCollection.Clear(); return result; @@ -311,7 +322,7 @@ public class D_Face { if (face.Location is null || face.OutputResolution is null) continue; - skip.Add(Shared.Models.Stateless.Methods.ILocation.GetWholePercentages(face.Location, ILocation.Digits, face.OutputResolution)); + skip.Add(Shared.Models.Stateless.Methods.ILocation.GetWholePercentages(face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution)); } foreach (LocationContainer locationContainer in locationContainers) { @@ -329,7 +340,7 @@ public class D_Face outputResolutionCheck = JsonSerializer.Deserialize(json); if (outputResolutionCheck is null || outputResolutionCheck.Width != outputResolutionWidth || outputResolutionCheck.Height != outputResolutionHeight) continue; - rectangle = Shared.Models.Stateless.Methods.ILocation.GetRectangle(ILocation.Digits, outputResolutionCheck, locationContainer.WholePercentages); + rectangle = Shared.Models.Stateless.Methods.ILocation.GetRectangle(Shared.Models.Stateless.ILocation.Digits, outputResolutionCheck, locationContainer.WholePercentages); if (rectangle is null) continue; location = Shared.Models.Stateless.Methods.ILocation.GetLocation(outputResolutionHeight, rectangle.Value, outputResolutionWidth); @@ -353,8 +364,8 @@ public class D_Face List? locations; string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize) }; List dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList(); - string dCollectionFile = Path.Combine(dResultsFullGroupDirectory, "[]", _Configuration.ResultAllInOne, $"{mappingFromItem.Id}{mappingFromItem.ImageFileHolder.ExtensionLowered}.json"); - FileInfo fileInfo = new(dCollectionFile); + (_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration.ResultAllInOneSubdirectoryLength, mappingFromItem.ImageFileHolder.Name); + FileInfo fileInfo = new(Path.Combine(_FileGroups[_PropertyConfiguration.ResultCollection][directoryIndex], $"{mappingFromItem.ImageFileHolder.NameWithoutExtension}{mappingFromItem.ImageFileHolder.ExtensionLowered}.json")); if (_ForceFaceLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete"))) { File.Move(Path.ChangeExtension(fileInfo.FullName, ".delete"), fileInfo.FullName); @@ -440,7 +451,7 @@ public class D_Face results.Add(new(face, null, string.Empty, save)); continue; } - deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(mappingFromItem.Id, face.Location, ILocation.Digits, face.OutputResolution); + deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(mappingFromItem.Id, face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution); fileInfo = new FileInfo(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{mappingFromItem.ImageFileHolder.ExtensionLowered}{_FileNameExtension}")); if (_OverrideForFaceImages) save = true; diff --git a/Instance/DlibDotNet.cs b/Instance/DlibDotNet.cs index 49b3069..cd866ef 100644 --- a/Instance/DlibDotNet.cs +++ b/Instance/DlibDotNet.cs @@ -85,8 +85,8 @@ public partial class DlibDotNet (ImageCodecInfo hiddenImageCodecInfo, EncoderParameters hiddenEncoderParameters, string hiddenFileNameExtension) = C_Resize.GetGifLowQuality(); _Faces = new D_Face( argZero, - configuration.CheckDFaceAndUpWriteDates, configuration.PropertyConfiguration, + configuration.CheckDFaceAndUpWriteDates, encoderParameters, configuration.FaceDistanceHiddenImageFactor, filenameExtension, @@ -136,6 +136,7 @@ public partial class DlibDotNet configuration.OutputExtension, configuration.OutputQuality); _Resize = new C_Resize( + configuration.PropertyConfiguration, configuration.ForceResizeLastWriteTimeToCreationTime, configuration.OverrideForResizeImages, configuration.PropertiesChangedForResize, @@ -682,7 +683,9 @@ public partial class DlibDotNet { total = 0; (cResultsFullGroupDirectory, c2ResultsFullGroupDirectory, dResultsFullGroupDirectory, d2ResultsFullGroupDirectory) = GetResultsFullGroupDirectories(outputResolution); - _BlurHasher = new BlurHash.Models.C2_BlurHasher(_Configuration.PropertyConfiguration.ResultAllInOne, c2ResultsFullGroupDirectory); + _Faces.Update(dResultsFullGroupDirectory); + _Resize.Update(cResultsFullGroupDirectory); + _BlurHasher = new BlurHash.Models.C2_BlurHasher(_Configuration.PropertyConfiguration, c2ResultsFullGroupDirectory); for (int i = 0; i < containers.Length; i++) { container = containers[i]; @@ -702,7 +705,7 @@ public partial class DlibDotNet if (_Configuration.SaveFaceLandmarkForOutputResolutions.Contains(outputResolution)) _FaceParts.SetAngleBracketCollection(_Configuration.PropertyConfiguration, d2ResultsFullGroupDirectory, container.SourceDirectory); propertyLogic.SetAngleBracketCollection(aResultsFullGroupDirectory, container.SourceDirectory, anyNullOrNoIsUniqueFileName); - _Resize.SetAngleBracketCollection(_Configuration.PropertyConfiguration, cResultsFullGroupDirectory, container.SourceDirectory); + _Resize.SetAngleBracketCollection(cResultsFullGroupDirectory, container.SourceDirectory); exceptionCount = FullParallelWork(maxDegreeOfParallelism, propertyLogic, metadata, diff --git a/Instance/appsettings.json b/Instance/appsettings.json index 1e6177e..30d16fa 100644 --- a/Instance/appsettings.json +++ b/Instance/appsettings.json @@ -104,6 +104,7 @@ "PropertiesChangedForProperty": false, "PropertiesChangedForResize": false, "ResultAllInOne": "_ _ _", + "ResultAllInOneSubdirectoryLength": 2, "ResultCollection": "[]", "ResultContent": "()", "ResultSingleton": "{}", diff --git a/Metadata/Models/B_Metadata.cs b/Metadata/Models/B_Metadata.cs index e9bd6fc..5e74fed 100644 --- a/Metadata/Models/B_Metadata.cs +++ b/Metadata/Models/B_Metadata.cs @@ -3,6 +3,7 @@ using System.Text.Json; using View_by_Distance.Metadata.Models.Stateless; using View_by_Distance.Property.Models; using View_by_Distance.Property.Models.Stateless; +using View_by_Distance.Shared.Models.Properties; using View_by_Distance.Shared.Models.Stateless; namespace View_by_Distance.Metadata.Models; @@ -15,17 +16,19 @@ public class B_Metadata private readonly Serilog.ILogger? _Log; private readonly bool _PropertiesChangedForMetadata; + private readonly IPropertyConfiguration _PropertyConfiguration; private readonly bool _ForceMetadataLastWriteTimeToCreationTime; - private readonly IReadOnlyDictionary _JsonGroups; + private readonly IReadOnlyDictionary _FileGroups; private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions; - public B_Metadata(Configuration configuration, bool forceMetadataLastWriteTimeToCreationTime, bool propertiesChangedForMetadata, string bResultsFullGroupDirectory) + public B_Metadata(IPropertyConfiguration propertyConfiguration, bool forceMetadataLastWriteTimeToCreationTime, bool propertiesChangedForMetadata, string bResultsFullGroupDirectory) { _Log = Serilog.Log.ForContext(); + _PropertyConfiguration = propertyConfiguration; _PropertiesChangedForMetadata = propertiesChangedForMetadata; _ForceMetadataLastWriteTimeToCreationTime = forceMetadataLastWriteTimeToCreationTime; _WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true }; - _JsonGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(configuration.ResultAllInOne, bResultsFullGroupDirectory, new string[] { "{}" }); + _FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, bResultsFullGroupDirectory, new string[] { propertyConfiguration.ResultSingleton }); } public override string ToString() @@ -83,10 +86,9 @@ public class B_Metadata string json = string.Empty; string[] changesFrom = new string[] { nameof(A_Property) }; Dictionary>>? dictionary; - char directory = Shared.Models.Stateless.Methods.IDirectory.GetDirectory(mappingFromItem.ImageFileHolder.Name); - int directoryIndex = Shared.Models.Stateless.Methods.IDirectory.GetDirectory(directory); List dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList(); - FileInfo fileInfo = new(Path.Combine(_JsonGroups["{}"][directoryIndex], $"{mappingFromItem.ImageFileHolder.NameWithoutExtension}{mappingFromItem.ImageFileHolder.ExtensionLowered}.json")); + (_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration.ResultAllInOneSubdirectoryLength, mappingFromItem.ImageFileHolder.Name); + FileInfo fileInfo = new(Path.Combine(_FileGroups[_PropertyConfiguration.ResultSingleton][directoryIndex], $"{mappingFromItem.ImageFileHolder.NameWithoutExtension}{mappingFromItem.ImageFileHolder.ExtensionLowered}.json")); if (_ForceMetadataLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete"))) { File.Move(Path.ChangeExtension(fileInfo.FullName, ".delete"), fileInfo.FullName); diff --git a/Move-By-Id/MoveById.cs b/Move-By-Id/MoveById.cs index 84c9b60..8ee7fef 100644 --- a/Move-By-Id/MoveById.cs +++ b/Move-By-Id/MoveById.cs @@ -160,6 +160,7 @@ public class MoveById List allFiles = GetAllFiles(matchNginxCollection); ProgressBar progressBar = new(allFiles.Count, message, options); List toDoCollection = GetToDoCollection(progressBar, allFiles); + progressBar.Dispose(); List<(string, string)> moveCollection = new(); foreach (string file in toDoCollection) { @@ -179,7 +180,6 @@ public class MoveById continue; File.Move(from, to); } - progressBar.Dispose(); return results; } diff --git a/Move-By-Id/appsettings.json b/Move-By-Id/appsettings.json index 258e068..b290ae9 100644 --- a/Move-By-Id/appsettings.json +++ b/Move-By-Id/appsettings.json @@ -64,6 +64,7 @@ "PopulatePropertyId": true, "PropertiesChangedForProperty": false, "ResultAllInOne": "_ _ _", + "ResultAllInOneSubdirectoryLength": 2, "ResultCollection": "[]", "ResultContent": "()", "ResultSingleton": "{}", diff --git a/Person/appsettings.json b/Person/appsettings.json index a9bdb08..606eb2e 100644 --- a/Person/appsettings.json +++ b/Person/appsettings.json @@ -13,6 +13,7 @@ "PopulatePropertyId": true, "PropertiesChangedForProperty": false, "ResultAllInOne": "_ _ _", + "ResultAllInOneSubdirectoryLength": 2, "ResultCollection": "[]", "ResultContent": "()", "ResultSingleton": "{}", @@ -134,6 +135,7 @@ "PopulatePropertyId": true, "PropertiesChangedForProperty": false, "ResultAllInOne": "_ _ _", + "ResultAllInOneSubdirectoryLength": 2, "ResultCollection": "[]", "ResultContent": "()", "ResultSingleton": "{}", diff --git a/Property/Models/A_Property.cs b/Property/Models/A_Property.cs index 3c126e5..932a8b4 100644 --- a/Property/Models/A_Property.cs +++ b/Property/Models/A_Property.cs @@ -7,6 +7,7 @@ using System.Text; using System.Text.Json; using View_by_Distance.Property.Models.Stateless; using View_by_Distance.Shared.Models; +using View_by_Distance.Shared.Models.Properties; using View_by_Distance.Shared.Models.Stateless; namespace View_by_Distance.Property.Models; @@ -25,21 +26,23 @@ public class A_Property private readonly ASCIIEncoding _ASCIIEncoding; private readonly Configuration _Configuration; private readonly List _AngleBracketCollection; - private readonly IReadOnlyDictionary _JsonGroups; + private readonly IPropertyConfiguration _PropertyConfiguration; + private readonly IReadOnlyDictionary _FileGroups; private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions; - public A_Property(int maxDegreeOfParallelism, Configuration configuration, string outputExtension, bool reverse, string aResultsFullGroupDirectory) + public A_Property(int maxDegreeOfParallelism, Configuration propertyConfiguration, string outputExtension, bool reverse, string aResultsFullGroupDirectory) { Reverse = reverse; - _Configuration = configuration; _ExceptionsDirectories = new(); _OutputExtension = outputExtension; _ASCIIEncoding = new ASCIIEncoding(); + _Configuration = propertyConfiguration; _Log = Serilog.Log.ForContext(); _AngleBracketCollection = new List(); + _PropertyConfiguration = propertyConfiguration; _MaxDegreeOfParallelism = maxDegreeOfParallelism; _WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true }; - _JsonGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(configuration.ResultAllInOne, aResultsFullGroupDirectory, new string[] { "{}" }); + _FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, aResultsFullGroupDirectory, new string[] { propertyConfiguration.ResultSingleton }); } public override string ToString() @@ -263,12 +266,13 @@ public class A_Property string[] changesFrom = Array.Empty(); string angleBracket = _AngleBracketCollection[0]; bool populateId = _Configuration.PopulatePropertyId; - char directory = Shared.Models.Stateless.Methods.IDirectory.GetDirectory(item.ImageFileHolder.Name); - int directoryIndex = Shared.Models.Stateless.Methods.IDirectory.GetDirectory(directory); if (!item.IsUniqueFileName) - fileInfo = new(Path.Combine(angleBracket.Replace("<>", "{}"), $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}.json")); + fileInfo = new(Path.Combine(angleBracket.Replace("<>", _PropertyConfiguration.ResultSingleton), $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}.json")); else - fileInfo = new(Path.Combine(_JsonGroups["{}"][directoryIndex], $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}.json")); + { + (_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration.ResultAllInOneSubdirectoryLength, item.ImageFileHolder.Name); + fileInfo = new(Path.Combine(_FileGroups[_PropertyConfiguration.ResultSingleton][directoryIndex], $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}.json")); + } List 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"))) { @@ -378,7 +382,7 @@ public class A_Property Shared.Models.Property property; List parseExceptions = new(); bool isValidMetadataExtensions = _Configuration.ValidMetadataExtensions.Contains(item.ImageFileHolder.ExtensionLowered); - bool isIgnoreExtension = item.IsValidImageFormatExtension && _Configuration.IgnoreExtensions.Contains(item.ImageFileHolder.ExtensionLowered); + bool isIgnoreExtension = item.IsValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(item.ImageFileHolder.ExtensionLowered); string filteredSourceDirectoryFileExtensionLowered = Path.Combine(sourceDirectory, $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}"); if (item.IsValidImageFormatExtension && item.ImageFileHolder.FullName.Length == filteredSourceDirectoryFileExtensionLowered.Length && item.ImageFileHolder.FullName != filteredSourceDirectoryFileExtensionLowered) File.Move(item.ImageFileHolder.FullName, filteredSourceDirectoryFileExtensionLowered); @@ -427,7 +431,7 @@ public class A_Property if (!anyNullOrNoIsUniqueFileName) _AngleBracketCollection.AddRange(new[] { Path.Combine(aResultsFullGroupDirectory, "<>") }); else - _AngleBracketCollection.AddRange(IResult.GetDirectoryInfoCollection(_Configuration, + _AngleBracketCollection.AddRange(IResult.GetDirectoryInfoCollection(_PropertyConfiguration, sourceDirectory, aResultsFullGroupDirectory, contentDescription: string.Empty, @@ -439,7 +443,7 @@ public class A_Property private void SetAngleBracketCollection(string sourceDirectory, bool anyNullOrNoIsUniqueFileName) { _AngleBracketCollection.Clear(); - string aResultsFullGroupDirectory = IResult.GetResultsFullGroupDirectory(_Configuration, + string aResultsFullGroupDirectory = IResult.GetResultsFullGroupDirectory(_PropertyConfiguration, nameof(A_Property), string.Empty, includeResizeGroup: false, @@ -461,7 +465,7 @@ public class A_Property int containersLength = containers.Length; const string outputResolution = "Original"; List> sourceDirectoryChanges = new(); - string propertyRoot = IResult.GetResultsGroupDirectory(_Configuration, nameof(A_Property)); + string propertyRoot = IResult.GetResultsGroupDirectory(_PropertyConfiguration, nameof(A_Property)); for (int i = 0; i < containers.Length; i++) { container = containers[i]; @@ -506,7 +510,7 @@ public class A_Property SetAngleBracketCollection(item.ImageFileHolder.DirectoryName, !item.IsUniqueFileName); } bool isValidMetadataExtensions = _Configuration.ValidMetadataExtensions.Contains(item.ImageFileHolder.ExtensionLowered); - bool isIgnoreExtension = item.IsValidImageFormatExtension && _Configuration.IgnoreExtensions.Contains(item.ImageFileHolder.ExtensionLowered); + bool isIgnoreExtension = item.IsValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(item.ImageFileHolder.ExtensionLowered); result = GetPropertyOfPrivate(item, sourceDirectoryFileTuples, parseExceptions, isIgnoreExtension, isValidMetadataExtensions); if (!angleBracketCollectionAny) _AngleBracketCollection.Clear(); diff --git a/Property/Models/Binder/Configuration.cs b/Property/Models/Binder/Configuration.cs index 4d7ff92..3cb74d6 100644 --- a/Property/Models/Binder/Configuration.cs +++ b/Property/Models/Binder/Configuration.cs @@ -21,6 +21,7 @@ public class Configuration [Display(Name = "Properties Changed For Property"), Required] public bool? PropertiesChangedForProperty { get; set; } [Display(Name = "Property Content Collection Files"), Required] public string[] PropertyContentCollectionFiles { get; set; } [Display(Name = "Result All In One"), Required] public string ResultAllInOne { get; set; } + [Display(Name = "Result All In One Max Value"), Required] public int? ResultAllInOneSubdirectoryLength { get; set; } [Display(Name = "Result Collection"), Required] public string ResultCollection { get; set; } [Display(Name = "Result Content"), Required] public string ResultContent { get; set; } [Display(Name = "Result Singleton"), Required] public string ResultSingleton { get; set; } @@ -53,6 +54,8 @@ public class Configuration throw new NullReferenceException(nameof(configuration.PropertiesChangedForProperty)); if (configuration.ResultAllInOne is null) throw new NullReferenceException(nameof(configuration.ResultAllInOne)); + 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) @@ -77,6 +80,7 @@ public class Configuration configuration.PropertiesChangedForProperty.Value, configuration.PropertyContentCollectionFiles, configuration.ResultAllInOne, + configuration.ResultAllInOneSubdirectoryLength.Value, configuration.ResultCollection, configuration.ResultContent, configuration.ResultSingleton, diff --git a/Property/Models/Configuration.cs b/Property/Models/Configuration.cs index 6cf3535..de198b6 100644 --- a/Property/Models/Configuration.cs +++ b/Property/Models/Configuration.cs @@ -29,6 +29,7 @@ public class Configuration : Shared.Models.Properties.IPropertyConfiguration public bool PropertiesChangedForProperty { init; get; } public string[] PropertyContentCollectionFiles { init; get; } public string ResultAllInOne { init; get; } + public int ResultAllInOneSubdirectoryLength { init; get; } public string ResultCollection { init; get; } public string ResultContent { init; get; } public string ResultSingleton { init; get; } @@ -48,6 +49,7 @@ public class Configuration : Shared.Models.Properties.IPropertyConfiguration bool propertiesChangedForProperty, string[] propertyContentCollectionFiles, string resultAllInOne, + int resultAllInOneSubdirectoryLength, string resultCollection, string resultContent, string resultSingleton, @@ -68,6 +70,7 @@ public class Configuration : Shared.Models.Properties.IPropertyConfiguration PropertiesChangedForProperty = propertiesChangedForProperty; PropertyContentCollectionFiles = propertyContentCollectionFiles; ResultAllInOne = resultAllInOne; + ResultAllInOneSubdirectoryLength = resultAllInOneSubdirectoryLength; ResultCollection = resultCollection; ResultContent = resultContent; ResultSingleton = resultSingleton; diff --git a/Rename/Rename.cs b/Rename/Rename.cs index a4db43e..4c1426e 100644 --- a/Rename/Rename.cs +++ b/Rename/Rename.cs @@ -8,7 +8,6 @@ using View_by_Distance.Property.Models; using View_by_Distance.Rename.Models; using View_by_Distance.Shared.Models; using View_by_Distance.Shared.Models.Methods; -using View_by_Distance.Shared.Models.Stateless.Methods; namespace View_by_Distance.Rename; @@ -541,17 +540,17 @@ public class Rename private void RenameByDateTakenB(MatchNginx[] matchNginxCollection, string aPropertySingletonDirectory, string[] jsonFiles) { string json; - char directory; string[] files; string fileName; + string checkFile; string extension; string[] matches; - string checkFile; DateTime dateTime; string[] segments; - string? checkFileName; - string checkDirectory; + string directoryName; string? subdirectory; + string checkDirectory; + string? checkFileName; Shared.Models.Property? property; foreach (MatchNginx matchNginx in matchNginxCollection) { @@ -574,9 +573,9 @@ public class Rename fileName = Path.GetFileName(file); segments = fileName.Split('.'); extension = Path.GetExtension(file); - directory = IDirectory.GetDirectory(fileName); + (directoryName, _) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_Configuration.PropertyConfiguration.ResultAllInOneSubdirectoryLength, fileName); checkFileName = $"{segments.First()}{Path.GetExtension(Path.GetFileNameWithoutExtension(file))}.json"; - checkDirectory = Path.Combine(aPropertySingletonDirectory, _PropertyConfiguration.ResultAllInOne, directory.ToString()); + checkDirectory = Path.Combine(aPropertySingletonDirectory, _PropertyConfiguration.ResultAllInOne, directoryName); checkFile = Path.Combine(checkDirectory, checkFileName); matches = jsonFiles.Where(l => l == checkFile).ToArray(); if (!matches.Any()) @@ -617,7 +616,7 @@ public class Rename string aPropertySingletonDirectory = Path.GetFullPath(Path.Combine(aResultsFullGroupDirectory, "{}")); string[] jsonFiles = !Directory.Exists(aPropertySingletonDirectory) ? Array.Empty() : Directory.GetFiles(aPropertySingletonDirectory, "*.json", SearchOption.AllDirectories); if (!jsonFiles.Any()) - log.Information($"No json file(s) found! Check directory <{aPropertySingletonDirectory}>"); + log.Information($"No json file(s) found! Check directoryName <{aPropertySingletonDirectory}>"); else RenameByDateTakenB(matchNginxCollection, aPropertySingletonDirectory, jsonFiles); } diff --git a/Rename/appsettings.json b/Rename/appsettings.json index 28bca43..5cd6d24 100644 --- a/Rename/appsettings.json +++ b/Rename/appsettings.json @@ -64,6 +64,7 @@ "PopulatePropertyId": true, "PropertiesChangedForProperty": false, "ResultAllInOne": "_ _ _", + "ResultAllInOneSubdirectoryLength": 2, "ResultCollection": "[]", "ResultContent": "()", "ResultSingleton": "{}", diff --git a/Resize/Models/_C_Resize.cs b/Resize/Models/_C_Resize.cs index 3713b13..8c3fbd0 100644 --- a/Resize/Models/_C_Resize.cs +++ b/Resize/Models/_C_Resize.cs @@ -5,8 +5,10 @@ using System.Runtime.InteropServices; using System.Text; using System.Text.Json; using View_by_Distance.Metadata.Models; +using View_by_Distance.Property.Models; using View_by_Distance.Property.Models.Stateless; using View_by_Distance.Shared.Models; +using View_by_Distance.Shared.Models.Properties; using View_by_Distance.Shared.Models.Stateless; namespace View_by_Distance.Resize.Models; @@ -35,11 +37,14 @@ public class C_Resize private readonly int _OutputResolutionHeightIndex; private readonly EncoderParameters _EncoderParameters; private readonly int _OutputResolutionOrientationIndex; + private readonly Dictionary _FileGroups; private readonly bool _ForceResizeLastWriteTimeToCreationTime; + private readonly IPropertyConfiguration _PropertyConfiguration; private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions; - public C_Resize(bool forceResizeLastWriteTimeToCreationTime, bool overrideForResizeImages, bool propertiesChangedForResize, string[] validResolutions, ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) + public C_Resize(IPropertyConfiguration propertyConfiguration, bool forceResizeLastWriteTimeToCreationTime, bool overrideForResizeImages, bool propertiesChangedForResize, string[] validResolutions, ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) { + _FileGroups = new(); _Original = "Original"; _TempResolutionWidth = 3; _TempResolutionHeight = 4; @@ -52,6 +57,7 @@ public class C_Resize _EncoderParameters = encoderParameters; _FileNameExtension = filenameExtension; AngleBracketCollection = new List(); + _PropertyConfiguration = propertyConfiguration; _OverrideForResizeImages = overrideForResizeImages; _PropertiesChangedForResize = propertiesChangedForResize; _ForceResizeLastWriteTimeToCreationTime = forceResizeLastWriteTimeToCreationTime; @@ -66,10 +72,18 @@ public class C_Resize return result; } - public void SetAngleBracketCollection(Property.Models.Configuration configuration, string cResultsFullGroupDirectory, string sourceDirectory) + public void Update(string cResultsFullGroupDirectory) + { + _FileGroups.Clear(); + Dictionary keyValuePairs = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(_PropertyConfiguration, cResultsFullGroupDirectory, new string[] { _PropertyConfiguration.ResultSingleton }); + foreach (KeyValuePair keyValuePair in keyValuePairs) + _FileGroups.Add(keyValuePair.Key, keyValuePair.Value); + } + + public void SetAngleBracketCollection(string cResultsFullGroupDirectory, string sourceDirectory) { AngleBracketCollection.Clear(); - AngleBracketCollection.AddRange(IResult.GetDirectoryInfoCollection(configuration, + AngleBracketCollection.AddRange(IResult.GetDirectoryInfoCollection(_PropertyConfiguration, sourceDirectory, cResultsFullGroupDirectory, contentDescription: "Resized image", @@ -280,7 +294,6 @@ public class C_Resize private void SaveResizedSubfile(Shared.Models.Property property, MappingFromItem mappingFromItem, int[] resize) { - // string subFile, Shared.Models.Property property, Shared.Models.FileHolder? fileHolder string dateTimeFormat = Shared.Models.Stateless.Methods.IProperty.DateTimeFormat(); DateTime dateTime = property.DateTimeOriginal is not null ? property.DateTimeOriginal.Value : Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(property); string dateTimeValue = dateTime.ToString(dateTimeFormat); @@ -295,7 +308,7 @@ public class C_Resize throw new Exception(); } - public void SaveResizedSubfile(Property.Models.Configuration configuration, string outputResolution, string cResultsFullGroupDirectory, List> subFileTuples, Item item, Shared.Models.Property property, MappingFromItem mappingFromItem, Dictionary outputResolutionToResize) + public void SaveResizedSubfile(Configuration configuration, string outputResolution, string cResultsFullGroupDirectory, List> subFileTuples, Item item, Shared.Models.Property property, MappingFromItem mappingFromItem, Dictionary outputResolutionToResize) { if (mappingFromItem.ResizedFileHolder is null) throw new NullReferenceException(nameof(mappingFromItem.ResizedFileHolder)); @@ -310,7 +323,7 @@ public class C_Resize int outputResolutionHeight = resize[_OutputResolutionHeightIndex]; int outputResolutionOrientation = resize[_OutputResolutionOrientationIndex]; int[] originalCollection = outputResolutionToResize[_Original]; - string[] changesFrom = new string[] { nameof(Property.Models.A_Property), nameof(B_Metadata), nameof(C_Resize) }; + string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize) }; List dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList(); if (_OverrideForResizeImages) check = true; @@ -408,18 +421,18 @@ public class C_Resize public FileHolder GetResizedFileHolder(Item item) { - FileHolder result = new(Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), Path.GetFileName(item.ImageFileHolder.FullName))); + FileHolder result = new(Path.Combine(AngleBracketCollection[0].Replace("<>", _PropertyConfiguration.ResultContent), Path.GetFileName(item.ImageFileHolder.FullName))); return result; } - public Dictionary GetResizeKeyValuePairs(Property.Models.Configuration configuration, string cResultsFullGroupDirectory, List> subFileTuples, List parseExceptions, List> metadataCollection, Shared.Models.Property property, MappingFromItem mappingFromItem) + public Dictionary GetResizeKeyValuePairs(Configuration configuration, string cResultsFullGroupDirectory, List> subFileTuples, List parseExceptions, List> metadataCollection, Shared.Models.Property property, MappingFromItem mappingFromItem) { Dictionary? results; string json; - string[] changesFrom = new string[] { nameof(Property.Models.A_Property), nameof(B_Metadata) }; + string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata) }; List dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList(); - string cResizeSingletonFile = Path.Combine(cResultsFullGroupDirectory, "{}", configuration.ResultAllInOne, $"{mappingFromItem.Id}{mappingFromItem.ImageFileHolder.ExtensionLowered}.json"); - FileInfo fileInfo = new(cResizeSingletonFile); + (_, int directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration.ResultAllInOneSubdirectoryLength, mappingFromItem.ImageFileHolder.Name); + FileInfo fileInfo = new(Path.Combine(_FileGroups[_PropertyConfiguration.ResultSingleton][directoryIndex], $"{mappingFromItem.ImageFileHolder.NameWithoutExtension}{mappingFromItem.ImageFileHolder.ExtensionLowered}.json")); if (_ForceResizeLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete"))) { File.Move(Path.ChangeExtension(fileInfo.FullName, ".delete"), fileInfo.FullName); diff --git a/Shared/Models/Methods/IBlurHasher.cs b/Shared/Models/Methods/IBlurHasher.cs index 3be95bb..73242a2 100644 --- a/Shared/Models/Methods/IBlurHasher.cs +++ b/Shared/Models/Methods/IBlurHasher.cs @@ -4,7 +4,7 @@ public interface IBlurHasher { string Encode(FileHolder fileHolder); - string? GetFile(FileHolder fileHolder); + string GetFile(FileHolder fileHolder); string EncodeAndSave(FileHolder fileHolder); } \ No newline at end of file diff --git a/Shared/Models/Properties/IPropertyConfiguration.cs b/Shared/Models/Properties/IPropertyConfiguration.cs index 052487d..7b1f2c1 100644 --- a/Shared/Models/Properties/IPropertyConfiguration.cs +++ b/Shared/Models/Properties/IPropertyConfiguration.cs @@ -9,6 +9,7 @@ public interface IPropertyConfiguration public bool PropertiesChangedForProperty { init; get; } public string[] PropertyContentCollectionFiles { init; get; } public string ResultAllInOne { init; get; } + public int ResultAllInOneSubdirectoryLength { init; get; } public string ResultCollection { init; get; } public string ResultContent { init; get; } public string ResultSingleton { init; get; } diff --git a/Shared/Models/Stateless/Methods/Container.cs b/Shared/Models/Stateless/Methods/Container.cs index 259538a..f588dae 100644 --- a/Shared/Models/Stateless/Methods/Container.cs +++ b/Shared/Models/Stateless/Methods/Container.cs @@ -92,7 +92,7 @@ internal abstract class Container compareFileNamesToFiles = IDirectory.GetFilesKeyValuePairs(jsonFilesCollection); renamed += IDirectory.LookForAbandoned(jsonFilesCollection, fileNamesToFiles, extension); filePairs = IDirectory.GetFiles(filesCollection, fileNamesToFiles, extension, compareFileNamesToFiles); - renamed += IDirectory.MaybeMove(propertyConfiguration.RootDirectory, propertyConfiguration.ResultAllInOne, filePairs, aPropertySingletonDirectory, extension); + renamed += IDirectory.MaybeMove(propertyConfiguration.RootDirectory, propertyConfiguration.ResultAllInOne, propertyConfiguration.ResultAllInOneSubdirectoryLength, filePairs, aPropertySingletonDirectory, extension); if (renamed == 0) break; } @@ -119,7 +119,6 @@ internal abstract class Container private static void ParallelFor(Properties.IPropertyConfiguration propertyConfiguration, string aPropertySingletonDirectory, string extension, int length, Models.FilePair filePair, List results) { - char directory; string fileName; bool abandoned = false; Models.FileHolder sourceDirectoryFileHolder; @@ -136,8 +135,8 @@ internal abstract class Container else { fileName = Path.GetFileName(filePair.Path); - directory = IDirectory.GetDirectory(fileName); - sourceDirectoryFileHolder = new(Path.Combine(aPropertySingletonDirectory, propertyConfiguration.ResultAllInOne, directory.ToString(), $"{fileName}{extension}")); + (string directoryName, _) = IPath.GetDirectoryNameAndIndex(propertyConfiguration.ResultAllInOneSubdirectoryLength, fileName); + sourceDirectoryFileHolder = new(Path.Combine(aPropertySingletonDirectory, propertyConfiguration.ResultAllInOne, directoryName, $"{fileName}{extension}")); } if (imageFileInfo.LastWriteTime is not null && sourceDirectoryFileHolder.CreationTime is not null && sourceDirectoryFileHolder.LastWriteTime is not null && imageFileInfo.LastWriteTime.Value != sourceDirectoryFileHolder.CreationTime.Value) { diff --git a/Shared/Models/Stateless/Methods/IDirectory.cs b/Shared/Models/Stateless/Methods/IDirectory.cs index b7f0d8c..2e03ac1 100644 --- a/Shared/Models/Stateless/Methods/IDirectory.cs +++ b/Shared/Models/Stateless/Methods/IDirectory.cs @@ -8,11 +8,6 @@ public interface IDirectory static char GetDirectory(string fileName) => fileName.Split('-').Length > 2 ? '-' : fileName.Split('.')[0][^1]; - string TestStatic_GetDirectory(string fileName, int length) => - GetDirectory(fileName, length); - static string GetDirectory(string fileName, int length) => - fileName.Length < length ? new('-', length) : fileName.Split('.')[0][^length..]; - int TestStatic_GetDirectory(char directory) => GetDirectory(directory); static int GetDirectory(char directory) => @@ -33,10 +28,10 @@ public interface IDirectory static int LookForAbandoned(List jsonFilesCollection, IReadOnlyDictionary> fileNamesToFiles, string extension) => XDirectory.LookForAbandoned(jsonFilesCollection, fileNamesToFiles, extension); - int TestStatic_MaybeMove(string directory, string resultAllInOne, List filePairs, string jsonGroupDirectory, string extension) => - MaybeMove(directory, resultAllInOne, filePairs, jsonGroupDirectory, extension); - static int MaybeMove(string directory, string resultAllInOne, List filePairs, string jsonGroupDirectory, string extension) => - XDirectory.MaybeMove(directory, resultAllInOne, filePairs, jsonGroupDirectory, extension); + int TestStatic_MaybeMove(string directory, string resultAllInOne, int resultAllInOneSubdirectoryLength, List filePairs, string jsonGroupDirectory, string extension) => + MaybeMove(directory, resultAllInOne, resultAllInOneSubdirectoryLength, filePairs, jsonGroupDirectory, extension); + static int MaybeMove(string directory, string resultAllInOne, int resultAllInOneSubdirectoryLength, List filePairs, string jsonGroupDirectory, string extension) => + XDirectory.MaybeMove(directory, resultAllInOne, resultAllInOneSubdirectoryLength, filePairs, jsonGroupDirectory, extension); List TestStatic_GetFiles(List filesCollection, IReadOnlyDictionary> fileNamesToFiles, string extension, IReadOnlyDictionary> compareFileNamesToFiles) => GetFiles(filesCollection, fileNamesToFiles, extension, compareFileNamesToFiles); diff --git a/Shared/Models/Stateless/Methods/IPath.cs b/Shared/Models/Stateless/Methods/IPath.cs index c634875..bb62bbf 100644 --- a/Shared/Models/Stateless/Methods/IPath.cs +++ b/Shared/Models/Stateless/Methods/IPath.cs @@ -1,3 +1,5 @@ +using View_by_Distance.Shared.Models.Properties; + namespace View_by_Distance.Shared.Models.Stateless.Methods; public interface IPath @@ -59,9 +61,14 @@ public interface IPath static string GetDirectory(string sourceDirectory, int level, string directoryName) => XPath.GetDirectory(sourceDirectory, level, directoryName); - Dictionary TestStatic_GetKeyValuePairs(string resultAllInOne, string? resultsFullGroupDirectory, string[]? directories, int maxValue = 12) => - GetKeyValuePairs(resultAllInOne, resultsFullGroupDirectory, directories, maxValue); - static Dictionary GetKeyValuePairs(string resultAllInOne, string? resultsFullGroupDirectory, string[]? directories, int maxValue = 12) => - XPath.GetKeyValuePairs(resultAllInOne, resultsFullGroupDirectory, directories, maxValue); + (string, int) TestStatic_GetDirectoryNameAndIndex(int resultAllInOneSubdirectoryLength, string fileName) => + GetDirectoryNameAndIndex(resultAllInOneSubdirectoryLength, fileName); + static (string, int) GetDirectoryNameAndIndex(int resultAllInOneSubdirectoryLength, string fileName) => + XPath.GetDirectoryNameAndIndex(resultAllInOneSubdirectoryLength, fileName); + + Dictionary TestStatic_GetKeyValuePairs(IPropertyConfiguration propertyConfiguration, string? resultsFullGroupDirectory, string[]? directories) => + GetKeyValuePairs(propertyConfiguration, resultsFullGroupDirectory, directories); + static Dictionary GetKeyValuePairs(IPropertyConfiguration propertyConfiguration, string? resultsFullGroupDirectory, string[]? directories) => + XPath.GetKeyValuePairs(propertyConfiguration, resultsFullGroupDirectory, directories); } \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/IProperty.cs b/Shared/Models/Stateless/Methods/IProperty.cs index 824315a..f3364ff 100644 --- a/Shared/Models/Stateless/Methods/IProperty.cs +++ b/Shared/Models/Stateless/Methods/IProperty.cs @@ -61,6 +61,11 @@ public interface IProperty static bool NameWithoutExtensionIsIdFormat(string fileNameWithoutExtension) => Property.NameWithoutExtensionIsIdFormat(fileNameWithoutExtension); + bool TestStatic_NameWithoutExtensionIsIdFormat(string[] validImageFormatExtensions, Models.FileHolder fileHolder) => + NameWithoutExtensionIsIdFormat(validImageFormatExtensions, fileHolder); + static bool NameWithoutExtensionIsIdFormat(string[] validImageFormatExtensions, Models.FileHolder fileHolder) => + Property.NameWithoutExtensionIsIdFormat(validImageFormatExtensions, fileHolder); + bool TestStatic_NameWithoutExtensionIsIdFormat(Models.FileHolder fileHolder) => NameWithoutExtensionIsIdFormat(fileHolder); static bool NameWithoutExtensionIsIdFormat(Models.FileHolder fileHolder) => diff --git a/Shared/Models/Stateless/Methods/Property.cs b/Shared/Models/Stateless/Methods/Property.cs index 82d09a9..9dcb7a0 100644 --- a/Shared/Models/Stateless/Methods/Property.cs +++ b/Shared/Models/Stateless/Methods/Property.cs @@ -364,6 +364,30 @@ internal abstract class Property return result; } + internal static bool NameWithoutExtensionIsIdFormat(string[] validImageFormatExtensions, Models.FileHolder fileHolder) + { + bool result; + bool changed; + string? fileNameWithoutExtension = fileHolder.NameWithoutExtension; + for (int i = 0; i < validImageFormatExtensions.Length; i++) + { + changed = false; + foreach (string validImageFormatExtension in validImageFormatExtensions) + { + if (fileNameWithoutExtension.EndsWith(validImageFormatExtension)) + { + changed = true; + fileNameWithoutExtension = fileNameWithoutExtension[..^validImageFormatExtension.Length]; + break; + } + } + if (!changed) + break; + } + result = NameWithoutExtensionIsIdFormat(fileNameWithoutExtension); + return result; + } + #pragma warning disable CA1416 internal static (DateTime?, DateTime?[], int?, string?) Get(Models.FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension) diff --git a/Shared/Models/Stateless/Methods/XDirectory.cs b/Shared/Models/Stateless/Methods/XDirectory.cs index 898f1d3..06497ad 100644 --- a/Shared/Models/Stateless/Methods/XDirectory.cs +++ b/Shared/Models/Stateless/Methods/XDirectory.cs @@ -175,17 +175,17 @@ internal abstract partial class XDirectory return results; } - private static void IsUniqueLoop(string resultAllInOne, string resultAllInOneDirectory, FilePair item, List<(string, string)> rename) + private static void IsUniqueLoop(string resultAllInOne, string resultAllInOneDirectory, int resultAllInOneSubdirectoryLength, FilePair item, List<(string, string)> rename) { - char directory; string fileName; + string directoryName; foreach (string path in item.Collection) { if (path.Contains(resultAllInOne)) continue; fileName = Path.GetFileName(path); - directory = IDirectory.GetDirectory(fileName); - rename.Add(new(path, Path.Combine(resultAllInOneDirectory, directory.ToString(), fileName))); + (directoryName, _) = IPath.GetDirectoryNameAndIndex(resultAllInOneSubdirectoryLength, fileName); + rename.Add(new(path, Path.Combine(resultAllInOneDirectory, directoryName, fileName))); } } @@ -202,7 +202,7 @@ internal abstract partial class XDirectory } } - internal static int MaybeMove(string directory, string resultAllInOne, List filePairs, string jsonGroupDirectory, string extension) + internal static int MaybeMove(string directory, string resultAllInOne, int resultAllInOneSubdirectoryLength, List filePairs, string jsonGroupDirectory, string extension) { FileInfo? toFileInfo; FileInfo fromFileInfo; @@ -212,7 +212,7 @@ internal abstract partial class XDirectory foreach (FilePair item in filePairs) { if (item.IsUnique) - IsUniqueLoop(resultAllInOne, resultAllInOneDirectory, item, rename); + IsUniqueLoop(resultAllInOne, resultAllInOneDirectory, resultAllInOneSubdirectoryLength, item, rename); else IsNotUniqueLoop(directory, resultAllInOne, jsonGroupDirectory, extension, item, rename); } diff --git a/Shared/Models/Stateless/Methods/XPath.cs b/Shared/Models/Stateless/Methods/XPath.cs index 9be137e..e96216f 100644 --- a/Shared/Models/Stateless/Methods/XPath.cs +++ b/Shared/Models/Stateless/Methods/XPath.cs @@ -1,3 +1,5 @@ +using View_by_Distance.Shared.Models.Properties; + namespace View_by_Distance.Shared.Models.Stateless.Methods; internal abstract class XPath @@ -257,15 +259,31 @@ internal abstract class XPath } } - internal static Dictionary GetKeyValuePairs(string resultAllInOne, string? resultsFullGroupDirectory, string[]? directories, int maxValue = 12) + internal static (string, int) GetDirectoryNameAndIndex(int resultAllInOneSubdirectoryLength, string fileName) + { + int converted; + string result; + string check = fileName.Length < resultAllInOneSubdirectoryLength ? new('-', resultAllInOneSubdirectoryLength) : fileName.Split('.')[0][^resultAllInOneSubdirectoryLength..]; + if (check.Any(l => !char.IsNumber(l))) + { + result = new('-', resultAllInOneSubdirectoryLength); + converted = int.Parse($"1{new string('0', resultAllInOneSubdirectoryLength)}"); + } + else + { + result = check; + converted = int.Parse(check); + } + return (result, converted); + } + + internal static Dictionary GetKeyValuePairs(IPropertyConfiguration propertyConfiguration, string? resultsFullGroupDirectory, string[]? directories) { Dictionary results = new(); + int converted = int.Parse($"1{new string('0', propertyConfiguration.ResultAllInOneSubdirectoryLength)}"); string checkDirectory; - int minusOne = maxValue - 1; - int minusTwo = maxValue - 2; - int minusThree = maxValue - 3; + int plusOne = converted + 1; List collection = new(); - int length = minusThree.ToString().Length; if (directories is not null) { foreach (string key in directories) @@ -273,14 +291,12 @@ internal abstract class XPath if (resultsFullGroupDirectory is null) continue; collection.Clear(); - for (int i = 0; i < maxValue; i++) + for (int i = 0; i < plusOne; i++) { - if (i == minusTwo) - checkDirectory = Path.Combine(resultsFullGroupDirectory, key, resultAllInOne, new('-', length)); - else if (i == minusOne) - checkDirectory = Path.Combine(resultsFullGroupDirectory, key, resultAllInOne, new('_', length)); + if (i == converted) + checkDirectory = Path.GetFullPath(Path.Combine(resultsFullGroupDirectory, key, propertyConfiguration.ResultAllInOne, new('-', propertyConfiguration.ResultAllInOneSubdirectoryLength))); else - checkDirectory = Path.Combine(resultsFullGroupDirectory, key, resultAllInOne, i.ToString().PadLeft(length, '0')); + checkDirectory = Path.GetFullPath(Path.Combine(resultsFullGroupDirectory, key, propertyConfiguration.ResultAllInOne, i.ToString().PadLeft(propertyConfiguration.ResultAllInOneSubdirectoryLength, '0'))); if (!Directory.Exists(checkDirectory)) _ = Directory.CreateDirectory(checkDirectory); collection.Add(checkDirectory); diff --git a/Tests/UnitTestCalculations.cs b/Tests/UnitTestCalculations.cs index fefbf7d..0f4a975 100644 --- a/Tests/UnitTestCalculations.cs +++ b/Tests/UnitTestCalculations.cs @@ -255,43 +255,6 @@ public partial class UnitTestCalculations NonThrowTryCatch(); } - [TestMethod] - public void TestMovingFiles() - { - char directory; - string fileName; - string checkFile; - int directoryIndex; - string checkDirectory; - List collection = new(); - string source = "C:/1234567890123456789"; - if (Directory.Exists(source)) - { - for (int i = 0; i < 11; i++) - { - if (i == 10) - checkDirectory = Path.Combine(source, "-"); - else - checkDirectory = Path.Combine(source, i.ToString()); - if (!Directory.Exists(checkDirectory)) - _ = Directory.CreateDirectory(checkDirectory); - collection.Add(checkDirectory); - } - Dictionary jsonGroups = new() { { "{}", collection.ToArray() } }; - foreach (string file in Directory.GetFiles(source)) - { - fileName = Path.GetFileName(file); - directory = IDirectory.GetDirectory(fileName); - directoryIndex = IDirectory.GetDirectory(directory); - checkFile = Path.Combine(jsonGroups["{}"][directoryIndex], fileName); - if (File.Exists(checkFile)) - continue; - File.Move(file, checkFile); - } - } - NonThrowTryCatch(); - } - [TestMethod] public void TestMethodMonth() { diff --git a/Tests/UnitTestResize.cs b/Tests/UnitTestResize.cs index a589e30..161038d 100644 --- a/Tests/UnitTestResize.cs +++ b/Tests/UnitTestResize.cs @@ -154,7 +154,7 @@ public class UnitTestResize (ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) = C_Resize.GetTuple(_Configuration.OutputExtension, _Configuration.OutputQuality); B_Metadata metadata = new(_Configuration.PropertyConfiguration, _Configuration.ForceMetadataLastWriteTimeToCreationTime, _Configuration.PropertiesChangedForMetadata, bResultsFullGroupDirectory); _ = metadata.ToString(); - C_Resize resize = new(_Configuration.ForceResizeLastWriteTimeToCreationTime, _Configuration.OverrideForResizeImages, _Configuration.PropertiesChangedForResize, _Configuration.ValidResolutions, imageCodecInfo, encoderParameters, filenameExtension); + C_Resize resize = new(_Configuration.PropertyConfiguration, _Configuration.ForceResizeLastWriteTimeToCreationTime, _Configuration.OverrideForResizeImages, _Configuration.PropertiesChangedForResize, _Configuration.ValidResolutions, imageCodecInfo, encoderParameters, filenameExtension); _ = resize.ToString(); bool isUniqueFileName = false; bool? isNotUniqueAndNeedsReview = null; @@ -164,7 +164,7 @@ public class UnitTestResize string relativePath = IPath.GetRelativePath(fileHolder.FullName, length); string propertyLogicSourceDirectory = Path.GetFullPath(Path.Combine(aPropertySingletonDirectory, sourceDirectoryName)); propertyLogic.SetAngleBracketCollection(aResultsFullGroupDirectory, propertyLogicSourceDirectory); - resize.SetAngleBracketCollection(_Configuration.PropertyConfiguration, cResultsFullGroupDirectory, sourceDirectory); + resize.SetAngleBracketCollection(cResultsFullGroupDirectory, sourceDirectory); item = new(sourceDirectoryFileHolder, relativePath, fileHolder, isNotUniqueAndNeedsReview, isUniqueFileName, isValidImageFormatExtension, property, false, false, false); Assert.IsNotNull(item.ImageFileHolder); if (item.Property is null) @@ -175,7 +175,7 @@ public class UnitTestResize if (property is null || item.Property is null) throw new NullReferenceException(nameof(property)); resizedFileHolder = resize.GetResizedFileHolder(item); - Shared.Models.Methods.IBlurHasher blurHasher = new BlurHash.Models.C2_BlurHasher(_Configuration.PropertyConfiguration.ResultAllInOne, resultsFullGroupDirectory: null); + Shared.Models.Methods.IBlurHasher blurHasher = new BlurHash.Models.C2_BlurHasher(_Configuration.PropertyConfiguration, resultsFullGroupDirectory: null); _ = blurHasher.Encode(resizedFileHolder); item.SetResizedFileHolder(resize.FileNameExtension, resizedFileHolder); MappingFromItem mappingFromItem = IMappingFromItem.GetMappingFromItem(item); diff --git a/TestsWithFaceRecognitionDotNet/UnitTestFace.cs b/TestsWithFaceRecognitionDotNet/UnitTestFace.cs index b77a28b..014c2b7 100644 --- a/TestsWithFaceRecognitionDotNet/UnitTestFace.cs +++ b/TestsWithFaceRecognitionDotNet/UnitTestFace.cs @@ -228,7 +228,7 @@ public class UnitTestFace (ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) = C_Resize.GetTuple(_Configuration.OutputExtension, _Configuration.OutputQuality); B_Metadata metadata = new(_Configuration.PropertyConfiguration, _Configuration.ForceMetadataLastWriteTimeToCreationTime, _Configuration.PropertiesChangedForMetadata, bResultsFullGroupDirectory); _ = metadata.ToString(); - C_Resize resize = new(_Configuration.ForceResizeLastWriteTimeToCreationTime, _Configuration.OverrideForResizeImages, _Configuration.PropertiesChangedForResize, _Configuration.ValidResolutions, imageCodecInfo, encoderParameters, filenameExtension); + C_Resize resize = new(_Configuration.PropertyConfiguration, _Configuration.ForceResizeLastWriteTimeToCreationTime, _Configuration.OverrideForResizeImages, _Configuration.PropertiesChangedForResize, _Configuration.ValidResolutions, imageCodecInfo, encoderParameters, filenameExtension); _ = resize.ToString(); bool isUniqueFileName = false; bool? isNotUniqueAndNeedsReview = null; @@ -238,7 +238,7 @@ public class UnitTestFace string relativePath = IPath.GetRelativePath(fileHolder.FullName, length); string propertyLogicSourceDirectory = Path.GetFullPath(Path.Combine(aPropertySingletonDirectory, sourceDirectoryName)); propertyLogic.SetAngleBracketCollection(aResultsFullGroupDirectory, propertyLogicSourceDirectory); - resize.SetAngleBracketCollection(_Configuration.PropertyConfiguration, cResultsFullGroupDirectory, sourceDirectory); + resize.SetAngleBracketCollection(cResultsFullGroupDirectory, sourceDirectory); item = new(sourceDirectoryFileHolder, relativePath, fileHolder, isNotUniqueAndNeedsReview, isUniqueFileName, isValidImageFormatExtension, property, false, false, false); Assert.IsNotNull(item.ImageFileHolder); if (item.Property is null)