Align with BaGet
This commit is contained in:
parent
7417cc49e1
commit
79b9daedfa
@ -8,8 +8,9 @@ namespace File_Folder_Helper.Helpers;
|
||||
internal static class HelperZipFilesByDate
|
||||
{
|
||||
|
||||
internal static void ZipFilesByDate(ILogger log, string sourceDirectory, SearchOption searchOption = SearchOption.TopDirectoryOnly, string dayFormat = "")
|
||||
internal static bool ZipFilesByDate(ILogger log, string sourceDirectory, SearchOption searchOption = SearchOption.TopDirectoryOnly, string dayFormat = "")
|
||||
{
|
||||
bool result = false;
|
||||
string key;
|
||||
bool addFile;
|
||||
string? zipPath;
|
||||
@ -137,7 +138,11 @@ internal static class HelperZipFilesByDate
|
||||
if (weeks.TryGetValue(fileName, out DateTime value))
|
||||
{
|
||||
try
|
||||
{ File.SetLastWriteTime(subFile, value); }
|
||||
{
|
||||
if (!result)
|
||||
result = true;
|
||||
File.SetLastWriteTime(subFile, value);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
@ -147,33 +152,19 @@ internal static class HelperZipFilesByDate
|
||||
{ _ = HelperDeleteEmptyDirectories.DeleteEmptyDirectories(topDirectory); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
log.LogInformation(topDirectory);
|
||||
log.LogInformation("{topDirectory}", topDirectory);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void SetDateFromZipEntry(ILogger log, string sourceDirectory, SearchOption searchOption = SearchOption.AllDirectories)
|
||||
private static bool SetDateFromZipEntry(ILogger log, string[] zipFiles, string keyFile, string keyFileB, string keyFileC)
|
||||
{
|
||||
bool result = false;
|
||||
string[] files;
|
||||
string keyFile;
|
||||
string keyFileB;
|
||||
string keyFileC;
|
||||
string checkFile;
|
||||
FileInfo fileInfo;
|
||||
string[] zipFiles;
|
||||
string searchPattern;
|
||||
string? zipDirectory;
|
||||
DateTimeOffset? dateTimeOffset;
|
||||
if (!Directory.Exists(sourceDirectory))
|
||||
_ = Directory.CreateDirectory(sourceDirectory);
|
||||
for (int i = 1; i < 3; i++)
|
||||
{
|
||||
(searchPattern, keyFile, keyFileB, keyFileC) = i switch
|
||||
{
|
||||
1 => ("*.nupkg", ".nuspec", "icon", "readme"),
|
||||
2 => ("*.vsix", ".vsixmanifest", string.Empty, string.Empty),
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
zipFiles = Directory.GetFiles(sourceDirectory, searchPattern, searchOption);
|
||||
foreach (string zipFile in zipFiles)
|
||||
{
|
||||
try
|
||||
@ -192,13 +183,21 @@ internal static class HelperZipFilesByDate
|
||||
if (dateTimeOffset is null || zipDirectory is null)
|
||||
continue;
|
||||
if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime);
|
||||
if (!result)
|
||||
result = true;
|
||||
}
|
||||
files = Directory.GetFiles(zipDirectory, $"*{keyFile}", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileInfo = new(file);
|
||||
if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime);
|
||||
if (!result)
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(keyFileB))
|
||||
continue;
|
||||
@ -207,7 +206,11 @@ internal static class HelperZipFilesByDate
|
||||
{
|
||||
fileInfo = new(file);
|
||||
if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime);
|
||||
if (!result)
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(keyFileC))
|
||||
continue;
|
||||
@ -216,12 +219,16 @@ internal static class HelperZipFilesByDate
|
||||
{
|
||||
fileInfo = new(file);
|
||||
if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime);
|
||||
if (!result)
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
log.LogInformation($"<{zipFile}> is invalid!");
|
||||
log.LogInformation("<{zipFile}> is invalid!", zipFile);
|
||||
checkFile = string.Concat(zipFile, ".err");
|
||||
for (int e = 0; e < short.MaxValue; e++)
|
||||
{
|
||||
@ -231,10 +238,40 @@ internal static class HelperZipFilesByDate
|
||||
}
|
||||
try
|
||||
{ File.Move(zipFile, checkFile); }
|
||||
catch (Exception) { log.LogInformation($"<{zipFile}> couldn't be moved!"); }
|
||||
catch (Exception) { log.LogInformation("<{zipFile}> couldn't be moved!", zipFile); }
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static bool SetDateFromZipEntryForNuspec(ILogger log, string[] files) =>
|
||||
SetDateFromZipEntry(log, files, ".nuspec", "icon", "readme");
|
||||
|
||||
internal static bool SetDateFromZipEntry(ILogger log, string sourceDirectory, SearchOption searchOption = SearchOption.AllDirectories)
|
||||
{
|
||||
bool result = false;
|
||||
bool loop;
|
||||
string keyFile;
|
||||
string keyFileB;
|
||||
string keyFileC;
|
||||
string[] zipFiles;
|
||||
string searchPattern;
|
||||
if (!Directory.Exists(sourceDirectory))
|
||||
_ = Directory.CreateDirectory(sourceDirectory);
|
||||
for (int i = 1; i < 3; i++)
|
||||
{
|
||||
(searchPattern, keyFile, keyFileB, keyFileC) = i switch
|
||||
{
|
||||
1 => ("*.nupkg", ".nuspec", "icon", "readme"),
|
||||
2 => ("*.vsix", ".vsixmanifest", string.Empty, string.Empty),
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
zipFiles = Directory.GetFiles(sourceDirectory, searchPattern, searchOption);
|
||||
loop = SetDateFromZipEntry(log, zipFiles, keyFile, keyFileB, keyFileC);
|
||||
if (loop && !result)
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -144,7 +144,7 @@ public class Worker : BackgroundService
|
||||
Helpers.HelperRenameToOldMoveDeleteOldMerge.RenameToOldMoveDeleteOld(_Logger, _Args[0]);
|
||||
break;
|
||||
case ConsoleKey.S:
|
||||
Helpers.HelperZipFilesByDate.SetDateFromZipEntry(_Logger, _Args[0]);
|
||||
_ = Helpers.HelperZipFilesByDate.SetDateFromZipEntry(_Logger, _Args[0]);
|
||||
break;
|
||||
case ConsoleKey.T:
|
||||
Helpers.HelperTooLong.TooLong(_Args[0], delete: false);
|
||||
@ -154,7 +154,7 @@ public class Worker : BackgroundService
|
||||
Helpers.HelperMarkdown.MarkdownConvertLinksForHugo(_AppSettings, _Logger, _Args);
|
||||
break;
|
||||
case ConsoleKey.Z:
|
||||
Helpers.HelperZipFilesByDate.ZipFilesByDate(_Logger, _Args[0]);
|
||||
_ = Helpers.HelperZipFilesByDate.ZipFilesByDate(_Logger, _Args[0]);
|
||||
break;
|
||||
default:
|
||||
switch (consoleKey)
|
||||
|
Loading…
x
Reference in New Issue
Block a user