Ready to test DownloadFile
DirectoryDictionary Add http file .7-Question JustMediaDate CombinedEnumAndIndex
This commit is contained in:
@ -265,40 +265,64 @@ internal abstract class XPath
|
||||
}
|
||||
}
|
||||
|
||||
private static (string, int) GetDirectoryNameAndIndex(int resultAllInOneSubdirectoryLength, string fileNameWithoutExtension)
|
||||
private static byte GetEnum(bool? ik, bool? dto)
|
||||
{
|
||||
byte result;
|
||||
if (ik is not null && ik.Value && dto is not null && dto.Value)
|
||||
result = 11;
|
||||
else if (ik is not null && ik.Value && dto is not null && !dto.Value)
|
||||
result = 15;
|
||||
else if (ik is not null && ik.Value && dto is null)
|
||||
result = 19;
|
||||
else if (ik is not null && !ik.Value && dto is not null && dto.Value)
|
||||
result = 51;
|
||||
else if (ik is not null && !ik.Value && dto is not null && !dto.Value)
|
||||
result = 55;
|
||||
else if (ik is not null && !ik.Value && dto is null)
|
||||
result = 59;
|
||||
else if (ik is null && dto is not null && dto.Value)
|
||||
result = 91;
|
||||
else if (ik is null && dto is not null && !dto.Value)
|
||||
result = 95;
|
||||
else if (ik is null && dto is null)
|
||||
result = 99;
|
||||
else
|
||||
throw new Exception();
|
||||
return result;
|
||||
}
|
||||
|
||||
private static CombinedEnumAndIndex GetCombinedEnumAndIndex(int resultAllInOneSubdirectoryLength, FilePath filePath, string fileNameWithoutExtension)
|
||||
{
|
||||
CombinedEnumAndIndex result;
|
||||
int converted;
|
||||
string result;
|
||||
string combined;
|
||||
string fileNameBeforeFirst = fileNameWithoutExtension.Split('.')[0];
|
||||
string check = fileNameBeforeFirst.Length < resultAllInOneSubdirectoryLength ? new('-', resultAllInOneSubdirectoryLength) : fileNameBeforeFirst[^resultAllInOneSubdirectoryLength..];
|
||||
byte @enum = GetEnum(filePath.HasIgnoreKeyword, filePath.HasDateTimeOriginal);
|
||||
string check = fileNameBeforeFirst.Length < resultAllInOneSubdirectoryLength ?
|
||||
new('-', resultAllInOneSubdirectoryLength) :
|
||||
fileNameBeforeFirst[^resultAllInOneSubdirectoryLength..];
|
||||
if (check.Any(l => !char.IsNumber(l)))
|
||||
{
|
||||
result = new('-', resultAllInOneSubdirectoryLength);
|
||||
combined = $"{@enum}{new('-', resultAllInOneSubdirectoryLength)}";
|
||||
converted = int.Parse($"1{new string('0', resultAllInOneSubdirectoryLength)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
result = check;
|
||||
combined = $"{@enum}{check}";
|
||||
converted = int.Parse(check);
|
||||
}
|
||||
return new(result, converted);
|
||||
result = new(combined, @enum, converted);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static (string, int) GetDirectoryNameAndIndex(ResultSettings resultSettings, int id)
|
||||
internal static CombinedEnumAndIndex GetCombinedEnumAndIndex(ResultSettings resultSettings, FilePath filePath)
|
||||
{
|
||||
(string result, int converted) = GetDirectoryNameAndIndex(resultSettings.ResultAllInOneSubdirectoryLength, id.ToString());
|
||||
return new(result, converted);
|
||||
}
|
||||
|
||||
internal static (string, int) GetDirectoryNameAndIndex(ResultSettings resultSettings, FilePath filePath)
|
||||
{
|
||||
string result;
|
||||
int converted;
|
||||
CombinedEnumAndIndex result;
|
||||
if (filePath.Id is not null)
|
||||
(result, converted) = GetDirectoryNameAndIndex(resultSettings.ResultAllInOneSubdirectoryLength, filePath.Id.Value.ToString());
|
||||
result = GetCombinedEnumAndIndex(resultSettings.ResultAllInOneSubdirectoryLength, filePath, filePath.Id.Value.ToString());
|
||||
else
|
||||
(result, converted) = GetDirectoryNameAndIndex(resultSettings.ResultAllInOneSubdirectoryLength, filePath.NameWithoutExtension);
|
||||
return new(result, converted);
|
||||
result = GetCombinedEnumAndIndex(resultSettings.ResultAllInOneSubdirectoryLength, filePath, filePath.NameWithoutExtension);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<int> GetYears(ResultSettings resultSettings)
|
||||
@ -310,62 +334,121 @@ internal abstract class XPath
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<int, ReadOnlyDictionary<string, string[]>> Convert(Dictionary<int, Dictionary<string, string[]>> collection)
|
||||
private static byte[] GetBytes() =>
|
||||
[
|
||||
11,
|
||||
15,
|
||||
19,
|
||||
51,
|
||||
55,
|
||||
59,
|
||||
91,
|
||||
95,
|
||||
99
|
||||
];
|
||||
|
||||
private static ReadOnlyDictionary<byte, ReadOnlyCollection<string>> Convert(Dictionary<byte, List<string>> keyValuePairs)
|
||||
{
|
||||
Dictionary<int, ReadOnlyDictionary<string, string[]>> results = [];
|
||||
foreach (KeyValuePair<int, Dictionary<string, string[]>> keyValuePair in collection)
|
||||
Dictionary<byte, ReadOnlyCollection<string>> results = [];
|
||||
foreach (KeyValuePair<byte, List<string>> keyValuePair in keyValuePairs)
|
||||
results.Add(keyValuePair.Key, new(keyValuePair.Value));
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
internal static ReadOnlyDictionary<int, ReadOnlyDictionary<string, string[]>> GetKeyValuePairs(ResultSettings resultSettings, string? resultsFullGroupDirectory, string[]? jsonGroups)
|
||||
private static ReadOnlyDictionary<byte, ReadOnlyCollection<string>> Convert(List<CombinedEnumAndIndex> collection)
|
||||
{
|
||||
Dictionary<int, Dictionary<string, string[]>> results = [];
|
||||
Dictionary<byte, List<string>> results = [];
|
||||
List<string>? c;
|
||||
foreach (CombinedEnumAndIndex cei in collection)
|
||||
{
|
||||
if (!results.TryGetValue(cei.Enum, out c))
|
||||
{
|
||||
results.Add(cei.Enum, []);
|
||||
if (!results.TryGetValue(cei.Enum, out c))
|
||||
throw new Exception();
|
||||
}
|
||||
c.Add(cei.Combined);
|
||||
}
|
||||
return Convert(results);
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> GetKeyValuePairs(ResultSettings resultSettings, string? resultsFullGroupDirectory, string[]? jsonGroups, DateTime dateTime)
|
||||
{
|
||||
Dictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> results = [];
|
||||
int plusOne;
|
||||
string directory;
|
||||
string checkDirectory;
|
||||
Dictionary<string, string[]>? keyValuePairs;
|
||||
ReadOnlyCollection<int> years = GetYears(resultSettings);
|
||||
CombinedEnumAndIndex cei;
|
||||
byte[] bytes = GetBytes();
|
||||
List<CombinedEnumAndIndex> collection = [];
|
||||
ReadOnlyDictionary<byte, ReadOnlyCollection<string>> keyValuePairs;
|
||||
int converted = int.Parse($"1{new string('0', resultSettings.ResultAllInOneSubdirectoryLength)}");
|
||||
int plusOne = converted + 1;
|
||||
List<string> collection = [];
|
||||
foreach (int year in years)
|
||||
if (jsonGroups is not null)
|
||||
{
|
||||
results.Add(year, []);
|
||||
if (!results.TryGetValue(year, out keyValuePairs))
|
||||
throw new NullReferenceException(nameof(keyValuePairs));
|
||||
if (jsonGroups is not null)
|
||||
plusOne = converted + 1;
|
||||
foreach (string jsonGroup in jsonGroups)
|
||||
{
|
||||
foreach (string jsonGroup in jsonGroups)
|
||||
if (resultsFullGroupDirectory is null)
|
||||
continue;
|
||||
foreach (byte @enum in bytes)
|
||||
{
|
||||
if (resultsFullGroupDirectory is null)
|
||||
continue;
|
||||
collection.Clear();
|
||||
for (int i = 0; i < plusOne; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonGroup))
|
||||
{
|
||||
if (i == converted)
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(resultsFullGroupDirectory, new('-', resultSettings.ResultAllInOneSubdirectoryLength)));
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(resultsFullGroupDirectory, $"{@enum}{new('-', resultSettings.ResultAllInOneSubdirectoryLength)}"));
|
||||
else
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(resultsFullGroupDirectory, i.ToString().PadLeft(resultSettings.ResultAllInOneSubdirectoryLength, '0')));
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(resultsFullGroupDirectory, $"{@enum}{i.ToString().PadLeft(resultSettings.ResultAllInOneSubdirectoryLength, '0')}"));
|
||||
}
|
||||
else
|
||||
{
|
||||
directory = Path.Combine(resultsFullGroupDirectory, jsonGroup);
|
||||
if (i == converted)
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(directory, new('-', resultSettings.ResultAllInOneSubdirectoryLength)));
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(directory, $"{@enum}{new('-', resultSettings.ResultAllInOneSubdirectoryLength)}"));
|
||||
else
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(directory, i.ToString().PadLeft(resultSettings.ResultAllInOneSubdirectoryLength, '0')));
|
||||
checkDirectory = Path.GetFullPath(Path.Combine(directory, $"{@enum}{i.ToString().PadLeft(resultSettings.ResultAllInOneSubdirectoryLength, '0')}"));
|
||||
}
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
collection.Add(checkDirectory);
|
||||
cei = new(Combined: checkDirectory, Enum: @enum, Index: -1);
|
||||
collection.Add(cei);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(jsonGroup))
|
||||
keyValuePairs.Add(jsonGroup, collection.ToArray());
|
||||
else
|
||||
keyValuePairs.Add(year.ToString(), collection.ToArray());
|
||||
}
|
||||
keyValuePairs = Convert(collection);
|
||||
if (!string.IsNullOrEmpty(jsonGroup))
|
||||
results.Add(jsonGroup, keyValuePairs);
|
||||
else
|
||||
results.Add(dateTime.Ticks.ToString(), keyValuePairs);
|
||||
}
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<int, ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>>> Convert(Dictionary<int, Dictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>>> keyValuePairs)
|
||||
{
|
||||
Dictionary<int, ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>>> results = [];
|
||||
foreach (KeyValuePair<int, Dictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>>> keyValuePair in keyValuePairs)
|
||||
results.Add(keyValuePair.Key, new(keyValuePair.Value));
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
internal static ReadOnlyDictionary<int, ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>>> GetKeyValuePairs(ResultSettings resultSettings, string? resultsFullGroupDirectory, string[]? jsonGroups)
|
||||
{
|
||||
Dictionary<int, Dictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>>> results = [];
|
||||
if (jsonGroups is not null)
|
||||
{
|
||||
DateTime dateTime = DateTime.Now;
|
||||
ReadOnlyCollection<int> years = GetYears(resultSettings);
|
||||
Dictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>>? k;
|
||||
ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePairs = GetKeyValuePairs(resultSettings, resultsFullGroupDirectory, jsonGroups, dateTime);
|
||||
foreach (int year in years)
|
||||
{
|
||||
results.Add(year, []);
|
||||
if (!results.TryGetValue(year, out k))
|
||||
throw new NullReferenceException(nameof(k));
|
||||
foreach (KeyValuePair<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePair in keyValuePairs)
|
||||
k.Add(keyValuePair.Key, keyValuePair.Value);
|
||||
}
|
||||
}
|
||||
return Convert(results);
|
||||
|
Reference in New Issue
Block a user