AddUserSecrets, RenameByDateTaken and BlurHash
This commit is contained in:
9
Rename/.vscode/UserSecrets/secrets.json
vendored
Normal file
9
Rename/.vscode/UserSecrets/secrets.json
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"_Application": "Rename",
|
||||
"ComparePathsFile": "C:/Users/mikep/AppData/Local/PharesApps/Drag-Drop-Explorer/2023_21/638202586000194405.json",
|
||||
"Windows": {
|
||||
"Configuration": {
|
||||
"RootDirectory": "D:/1) Images A/Images-1e85c0ba"
|
||||
}
|
||||
}
|
||||
}
|
85
Rename/.vscode/tasks.json
vendored
85
Rename/.vscode/tasks.json
vendored
@ -1,41 +1,76 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"options": {
|
||||
"env": {
|
||||
"serverUserSecretsId": "6e026d2f-9edf-4c6c-a042-162758114e9a"
|
||||
}
|
||||
},
|
||||
"tasks": [
|
||||
{
|
||||
"label": "userSecretsInit",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"user-secrets",
|
||||
"-p",
|
||||
"${workspaceFolder}/Rename.csproj",
|
||||
"init"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "userSecretsSet",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"user-secrets",
|
||||
"-p",
|
||||
"${workspaceFolder}/Rename.csproj",
|
||||
"set",
|
||||
"SaveDirectory",
|
||||
"D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "userSecretsMkLink",
|
||||
"command": "cmd",
|
||||
"type": "shell",
|
||||
"args": [
|
||||
"/c",
|
||||
"mklink",
|
||||
"/J",
|
||||
".vscode\\UserSecrets",
|
||||
"${userHome}\\AppData\\Roaming\\Microsoft\\UserSecrets\\$env:serverUserSecretsId"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "format",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"format",
|
||||
"--report",
|
||||
".vscode",
|
||||
"--verbosity",
|
||||
"detailed",
|
||||
"--severity",
|
||||
"warn"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/Rename.csproj",
|
||||
"${workspaceFolder}/View-by-Distance-MKLink-Console.sln",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/Rename.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"--project",
|
||||
"${workspaceFolder}/Rename.csproj"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
@ -20,7 +20,8 @@ public class Program
|
||||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true);
|
||||
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true)
|
||||
.AddUserSecrets<Program>();
|
||||
IConfigurationRoot configurationRoot = configurationBuilder.Build();
|
||||
AppSettings appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
||||
if (appSettings.MaxDegreeOfParallelism > Environment.ProcessorCount)
|
||||
|
@ -3,9 +3,11 @@ using Phares.Shared;
|
||||
using Serilog;
|
||||
using ShellProgressBar;
|
||||
using System.Text.Json;
|
||||
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;
|
||||
|
||||
@ -15,7 +17,7 @@ public class Rename
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly string _WorkingDirectory;
|
||||
private readonly IsEnvironment _IsEnvironment;
|
||||
private readonly Configuration _Configuration;
|
||||
private readonly Models.Configuration _Configuration;
|
||||
private readonly IConfigurationRoot _ConfigurationRoot;
|
||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||
|
||||
@ -34,7 +36,7 @@ public class Rename
|
||||
ILogger? log = Log.ForContext<Rename>();
|
||||
Dictionary<long, Dictionary<long, List<string>>> fileSizeToCollection = new();
|
||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||
Models.Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
_Configuration = configuration;
|
||||
propertyConfiguration.Update();
|
||||
@ -63,6 +65,8 @@ public class Rename
|
||||
MoveMatches(matchNginxCollection[0]);
|
||||
else if (matchNginxCollection.All(l => l.Name.StartsWith("#")) || matchNginxCollection.All(l => l.Name.StartsWith(" #")) || matchNginxCollection.All(l => l.Name.StartsWith("=20")) || matchNginxCollection.All(l => l.Name.StartsWith("#20")))
|
||||
Rename2000(log, matchNginxCollection);
|
||||
else if (matchNginxCollection.All(l => l.Name.Length > 4) && matchNginxCollection.All(l => l.Name[0..3] is "198" or "199" or "200" or "201"))
|
||||
RenameByDateTaken(log, matchNginxCollection);
|
||||
else if (matchNginxCollection.Any())
|
||||
{
|
||||
List<string> lines = RenameFilesInDirectories(log, matchNginxCollection);
|
||||
@ -323,6 +327,8 @@ public class Rename
|
||||
continue;
|
||||
if (File.Exists(matchNginx.ConvertedPath))
|
||||
continue;
|
||||
if (!Directory.Exists(matchNginx.ConvertedPath))
|
||||
continue;
|
||||
files = Directory.GetFiles(matchNginx.ConvertedPath, "*", SearchOption.AllDirectories);
|
||||
if (files.All(l => l.EndsWith(".id")))
|
||||
{
|
||||
@ -425,8 +431,8 @@ public class Rename
|
||||
List<string> allFiles;
|
||||
ProgressBar progressBar;
|
||||
List<(FileHolder, string)> toDoCollection;
|
||||
List<(FileHolder, string)> verifiedToDoCollection;
|
||||
allFiles = GetAllFiles(matchNginxCollection);
|
||||
List<(FileHolder, string)> verifiedToDoCollection;
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
for (int i = 1; i < 3; i++)
|
||||
{
|
||||
@ -464,4 +470,88 @@ public class Rename
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
private void RenameByDateTakenB(MatchNginx[] matchNginxCollection, string aPropertySingletonDirectory, string[] jsonFiles)
|
||||
{
|
||||
string json;
|
||||
char directory;
|
||||
string[] files;
|
||||
string fileName;
|
||||
string extension;
|
||||
string[] matches;
|
||||
string checkFile;
|
||||
DateTime dateTime;
|
||||
string[] segments;
|
||||
string? checkFileName;
|
||||
string checkDirectory;
|
||||
string? subdirectory;
|
||||
Shared.Models.Property? property;
|
||||
foreach (MatchNginx matchNginx in matchNginxCollection)
|
||||
{
|
||||
if (File.Exists(matchNginx.ConvertedPath))
|
||||
continue;
|
||||
if (!Directory.Exists(matchNginx.ConvertedPath))
|
||||
continue;
|
||||
subdirectory = Path.GetDirectoryName(matchNginx.ConvertedPath);
|
||||
if (string.IsNullOrEmpty(subdirectory))
|
||||
continue;
|
||||
files = Directory.GetFiles(matchNginx.ConvertedPath, "*", SearchOption.AllDirectories);
|
||||
for (int i = 65; i < 91; i++)
|
||||
{
|
||||
checkDirectory = Path.Combine(subdirectory, nameof(Rename), ((char)i).ToString());
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileName = Path.GetFileName(file);
|
||||
segments = fileName.Split('.');
|
||||
extension = Path.GetExtension(file);
|
||||
directory = IDirectory.GetDirectory(fileName);
|
||||
checkFileName = $"{segments.First()}{Path.GetExtension(Path.GetFileNameWithoutExtension(file))}.json";
|
||||
checkDirectory = Path.Combine(aPropertySingletonDirectory, _PropertyConfiguration.ResultAllInOne, directory.ToString());
|
||||
checkFile = Path.Combine(checkDirectory, checkFileName);
|
||||
matches = jsonFiles.Where(l => l == checkFile).ToArray();
|
||||
if (!matches.Any())
|
||||
{
|
||||
matches = jsonFiles.Where(l => l.EndsWith(checkFileName)).ToArray();
|
||||
if (!matches.Any())
|
||||
continue;
|
||||
}
|
||||
json = File.ReadAllText(matches.First());
|
||||
property = JsonSerializer.Deserialize<Shared.Models.Property>(json);
|
||||
if (property is null)
|
||||
continue;
|
||||
checkFileName = null;
|
||||
dateTime = property.DateTimeOriginal is not null ? property.DateTimeOriginal.Value : Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(property);
|
||||
for (int i = 65; i < 91; i++)
|
||||
{
|
||||
if (checkFileName is not null && !File.Exists(checkFileName))
|
||||
break;
|
||||
checkFileName = Path.Combine(subdirectory, nameof(Rename), ((char)i).ToString(), $"{dateTime.Ticks}{extension}");
|
||||
}
|
||||
if (checkFileName is null || File.Exists(checkFileName))
|
||||
continue;
|
||||
File.Move(file, checkFileName);
|
||||
}
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(subdirectory);
|
||||
}
|
||||
}
|
||||
|
||||
private void RenameByDateTaken(ILogger log, MatchNginx[] matchNginxCollection)
|
||||
{
|
||||
string aResultsFullGroupDirectory = Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(
|
||||
_PropertyConfiguration,
|
||||
nameof(A_Property),
|
||||
string.Empty,
|
||||
includeResizeGroup: false,
|
||||
includeModel: false,
|
||||
includePredictorModel: false);
|
||||
string aPropertySingletonDirectory = Path.GetFullPath(Path.Combine(aResultsFullGroupDirectory, "{}"));
|
||||
string[] jsonFiles = !Directory.Exists(aPropertySingletonDirectory) ? Array.Empty<string>() : Directory.GetFiles(aPropertySingletonDirectory, "*.json", SearchOption.AllDirectories);
|
||||
if (!jsonFiles.Any())
|
||||
log.Information($"No json file(s) found! Check directory <{aPropertySingletonDirectory}>");
|
||||
else
|
||||
RenameByDateTakenB(matchNginxCollection, aPropertySingletonDirectory, jsonFiles);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<UserSecretsId>6e026d2f-9edf-4c6c-a042-162758114e9a</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Rename</PackageId>
|
||||
@ -38,7 +39,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
|
@ -1,14 +1,9 @@
|
||||
{
|
||||
"ComparePathsFile": "C:/Users/mikep/AppData/Local/PharesApps/Drag-Drop-Explorer/2023_13/638158781544395303.json",
|
||||
"CopyTo": "",
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Log4netProvider": "Debug"
|
||||
}
|
||||
},
|
||||
"MaxDegreeOfParallelism": 6,
|
||||
"MaxMinutesDelta": 2,
|
||||
"RenameUndo": false,
|
||||
"Serilog": {
|
||||
"MinimumLevel": "Debug"
|
||||
},
|
||||
|
@ -68,7 +68,7 @@
|
||||
"ResultCollection": "[]",
|
||||
"ResultContent": "()",
|
||||
"ResultSingleton": "{}",
|
||||
"RootDirectory": "C:/Tmp/Phares/Compare/Images-1e85c0ba",
|
||||
"RootDirectory": "D:/Images",
|
||||
"WriteBitmapDataBytes": false,
|
||||
"IgnoreExtensions": [
|
||||
".gif",
|
||||
|
Reference in New Issue
Block a user