AddUserSecrets, RenameByDateTaken and BlurHash
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user