Updated Backup (Day-Helper-2024-12-17)
This commit is contained in:
parent
43527b3356
commit
dd5baba9bc
@ -54,13 +54,20 @@ internal static partial class Helper20241217
|
|||||||
Job jobNew;
|
Job jobNew;
|
||||||
string path;
|
string path;
|
||||||
string? json;
|
string? json;
|
||||||
|
string asidePath;
|
||||||
bool areTheyTheSame;
|
bool areTheyTheSame;
|
||||||
string directoryName;
|
string directoryName;
|
||||||
|
logger.LogInformation(args[0]);
|
||||||
|
logger.LogInformation(args[1]);
|
||||||
|
logger.LogInformation(args[2]);
|
||||||
|
logger.LogInformation(args[3]);
|
||||||
|
logger.LogInformation(args[4]);
|
||||||
ReadOnlyCollection<File> files;
|
ReadOnlyCollection<File> files;
|
||||||
string searchPattern = args[2];
|
string searchPattern = args[2];
|
||||||
string[] ignoreFileNames = args[3].Split('~');
|
string[] ignoreFileNames = args[3].Split('~');
|
||||||
|
string destination = Path.GetFullPath(args[4]);
|
||||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||||
char destinationDriveLetter = args[4].Split(':')[0][0];
|
char destinationDriveLetter = destination.Split(':')[0][0];
|
||||||
logger.LogInformation("Searching <{sourceDirectory}> with search pattern {searchPattern}", args[0], searchPattern);
|
logger.LogInformation("Searching <{sourceDirectory}> with search pattern {searchPattern}", args[0], searchPattern);
|
||||||
if (Debugger.IsAttached)
|
if (Debugger.IsAttached)
|
||||||
Verify(searchPattern, ignoreFileNames);
|
Verify(searchPattern, ignoreFileNames);
|
||||||
@ -80,10 +87,15 @@ internal static partial class Helper20241217
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
directoryName = Path.GetFileName(record.Directory);
|
directoryName = Path.GetFileName(record.Directory);
|
||||||
path = Path.Combine(record.Directory, $"{directoryName}-{DateTime.Now:yyyy-MM-dd-HH-mm-ss-fff}{record.Job.Extension}");
|
asidePath = Path.Combine(record.Directory, $"{directoryName}-{DateTime.Now:yyyy-MM-dd-HH-mm-ss-fff}{record.Job.Extension}");
|
||||||
logger.LogInformation("Writing <{directory}> extension", record.Directory);
|
path = $"{destinationDriveLetter}{asidePath[1..]}";
|
||||||
WritePassedExtension(destinationDriveLetter, record, files, path);
|
logger.LogInformation("Writing <{path}> extension", path);
|
||||||
|
WritePassedExtension(record, files, directoryName, path);
|
||||||
|
logger.LogInformation("Wrote <{path}> extension", path);
|
||||||
|
MovePassedExtension(destination, path);
|
||||||
|
logger.LogInformation("Moved <{path}> extension", path);
|
||||||
WriteAllText(record.Path, json);
|
WriteAllText(record.Path, json);
|
||||||
|
Helpers.HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, $"{destinationDriveLetter}{record.Directory[1..]}");
|
||||||
}
|
}
|
||||||
if (Debugger.IsAttached && records.Count() == 0)
|
if (Debugger.IsAttached && records.Count() == 0)
|
||||||
{
|
{
|
||||||
@ -245,8 +257,11 @@ internal static partial class Helper20241217
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = false;
|
result = false;
|
||||||
|
if (Debugger.IsAttached)
|
||||||
|
{
|
||||||
WriteAllText(Path.Combine(Environment.CurrentDirectory, ".vscode", "helper", "old.json"), jsonOld);
|
WriteAllText(Path.Combine(Environment.CurrentDirectory, ".vscode", "helper", "old.json"), jsonOld);
|
||||||
WriteAllText(Path.Combine(Environment.CurrentDirectory, ".vscode", "helper", "new.json"), jsonNew);
|
WriteAllText(Path.Combine(Environment.CurrentDirectory, ".vscode", "helper", "new.json"), jsonNew);
|
||||||
|
}
|
||||||
logger.LogInformation("<{directory}> file serialized are different {filesTotalLengthNew} != {filesTotalLengthOld}", record.Directory, filesTotalLengthNew, filesTotalLengthOld);
|
logger.LogInformation("<{directory}> file serialized are different {filesTotalLengthNew} != {filesTotalLengthOld}", record.Directory, filesTotalLengthNew, filesTotalLengthOld);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,36 +276,44 @@ internal static partial class Helper20241217
|
|||||||
System.IO.File.WriteAllText(path, text);
|
System.IO.File.WriteAllText(path, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WritePassedExtension(char destinationDriveLetter, Record record, ReadOnlyCollection<File> files, string path)
|
private static void WritePassedExtension(Record record, ReadOnlyCollection<File> files, string directoryName, string path)
|
||||||
{
|
{
|
||||||
string directoryName = Path.GetFileName(record.Directory);
|
|
||||||
if (record.Job.Extension.Equals(".iso", StringComparison.OrdinalIgnoreCase))
|
if (record.Job.Extension.Equals(".iso", StringComparison.OrdinalIgnoreCase))
|
||||||
WriteISO(destinationDriveLetter, record, files, path, directoryName);
|
WriteISO(record, files, path, directoryName);
|
||||||
else if (record.Job.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
|
else if (record.Job.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
|
||||||
WriteZIP(destinationDriveLetter, record, files, path);
|
WriteZIP(record, files, path);
|
||||||
else
|
else
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteISO(char destinationDriveLetter, Record record, ReadOnlyCollection<File> files, string path, string directoryName)
|
private static void MovePassedExtension(string destination, string path)
|
||||||
{
|
{
|
||||||
string checkFile = $"{destinationDriveLetter}{path[1..]}";
|
string checkPath = $"{destination}{path[2..]}";
|
||||||
string checkDirectory = Path.GetDirectoryName(checkFile) ?? throw new Exception();
|
string checkDirectory = Path.GetDirectoryName(checkPath) ?? throw new Exception();
|
||||||
|
if (!Directory.Exists(checkDirectory))
|
||||||
|
_ = Directory.CreateDirectory(checkDirectory);
|
||||||
|
if (System.IO.File.Exists(checkPath))
|
||||||
|
throw new NotImplementedException($"<{checkPath}> already exists!");
|
||||||
|
System.IO.File.Move(path, checkPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteISO(Record record, ReadOnlyCollection<File> files, string path, string directoryName)
|
||||||
|
{
|
||||||
|
string checkDirectory = Path.GetDirectoryName(path) ?? throw new Exception();
|
||||||
if (!Directory.Exists(checkDirectory))
|
if (!Directory.Exists(checkDirectory))
|
||||||
_ = Directory.CreateDirectory(checkDirectory);
|
_ = Directory.CreateDirectory(checkDirectory);
|
||||||
CDBuilder builder = new() { UseJoliet = true, VolumeIdentifier = directoryName.Length < 25 ? directoryName : directoryName[..25] };
|
CDBuilder builder = new() { UseJoliet = true, VolumeIdentifier = directoryName.Length < 25 ? directoryName : directoryName[..25] };
|
||||||
foreach (File file in files)
|
foreach (File file in files)
|
||||||
_ = builder.AddFile(file.RelativePath, Path.Combine(record.Directory, file.RelativePath));
|
_ = builder.AddFile(file.RelativePath, Path.Combine(record.Directory, file.RelativePath));
|
||||||
builder.Build(checkFile);
|
builder.Build(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteZIP(char destinationDriveLetter, Record record, ReadOnlyCollection<File> files, string path)
|
private static void WriteZIP(Record record, ReadOnlyCollection<File> files, string path)
|
||||||
{
|
{
|
||||||
string checkFile = $"{destinationDriveLetter}{path[1..]}";
|
string checkDirectory = Path.GetDirectoryName(path) ?? throw new Exception();
|
||||||
string checkDirectory = Path.GetDirectoryName(checkFile) ?? throw new Exception();
|
|
||||||
if (!Directory.Exists(checkDirectory))
|
if (!Directory.Exists(checkDirectory))
|
||||||
_ = Directory.CreateDirectory(checkDirectory);
|
_ = Directory.CreateDirectory(checkDirectory);
|
||||||
using ZipArchive zip = ZipFile.Open(checkFile, ZipArchiveMode.Create);
|
using ZipArchive zip = ZipFile.Open(path, ZipArchiveMode.Create);
|
||||||
string directoryEntry;
|
string directoryEntry;
|
||||||
List<string> directoryEntries = [];
|
List<string> directoryEntries = [];
|
||||||
foreach (File file in files)
|
foreach (File file in files)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user