Fixed an issue with automatic destinations (#29)
This commit is contained in:
parent
506892b6e0
commit
9928f7d62f
@ -7,8 +7,13 @@ public static class CompressionModule
|
|||||||
public static void CompressZip(string source, string? destination = null,
|
public static void CompressZip(string source, string? destination = null,
|
||||||
CompressionLevel level = CompressionLevel.Optimal, string comment = "")
|
CompressionLevel level = CompressionLevel.Optimal, string comment = "")
|
||||||
{
|
{
|
||||||
destination ??= Path.Combine(Path.GetDirectoryName(Path.GetFullPath(source))!,
|
if (destination is null)
|
||||||
$"{Path.GetFileNameWithoutExtension(source)}.zip");
|
{
|
||||||
|
string full = Path.GetFullPath(source);
|
||||||
|
string name = Path.GetFileNameWithoutExtension(full);
|
||||||
|
string folder = Program.Shell!.WorkingDirectory;
|
||||||
|
destination ??= $"{folder}\\{name}.zip";
|
||||||
|
}
|
||||||
|
|
||||||
string absSource = Path.GetFullPath(source),
|
string absSource = Path.GetFullPath(source),
|
||||||
localDest = Path.GetRelativePath(Program.Shell!.WorkingDirectory, destination);
|
localDest = Path.GetRelativePath(Program.Shell!.WorkingDirectory, destination);
|
||||||
@ -44,13 +49,34 @@ public static class CompressionModule
|
|||||||
|
|
||||||
List<string> files = new(GetAllFiles(absSource)),
|
List<string> files = new(GetAllFiles(absSource)),
|
||||||
relative = new();
|
relative = new();
|
||||||
foreach (string f in files) relative.Add(Path.GetRelativePath(absSource, f));
|
for (int i = 0; i < files.Count; i++)
|
||||||
|
{
|
||||||
|
string f = files[i];
|
||||||
|
if (f.Trim().ToLower() == destination.Trim().ToLower())
|
||||||
|
{
|
||||||
|
files.RemoveAt(i);
|
||||||
|
i--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
relative.Add(Path.GetRelativePath(absSource, f));
|
||||||
|
}
|
||||||
|
|
||||||
|
int failed = 0;
|
||||||
|
|
||||||
LoadingBarStart();
|
LoadingBarStart();
|
||||||
for (int i = 0; i < files.Count; i++)
|
for (int i = 0; i < files.Count; i++)
|
||||||
{
|
{
|
||||||
archive.CreateEntryFromFile(files[i], relative[i], level);
|
bool failedThisTime = false;
|
||||||
LoadingBarSet((i + 1) / (float)files.Count, ConsoleColor.DarkGreen);
|
try
|
||||||
|
{
|
||||||
|
archive.CreateEntryFromFile(files[i], relative[i], level);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
failedThisTime = true;
|
||||||
|
failed++;
|
||||||
|
}
|
||||||
|
LoadingBarSet((i + 1) / (float)files.Count, failedThisTime ? ConsoleColor.Red : ConsoleColor.DarkGreen); ;
|
||||||
Console.CursorLeft = 0;
|
Console.CursorLeft = 0;
|
||||||
string message = $"{relative[i]}";
|
string message = $"{relative[i]}";
|
||||||
int remainder = Console.BufferWidth - message.Length;
|
int remainder = Console.BufferWidth - message.Length;
|
||||||
@ -69,6 +95,14 @@ public static class CompressionModule
|
|||||||
Write(new string(' ', Console.BufferWidth), newLine: false);
|
Write(new string(' ', Console.BufferWidth), newLine: false);
|
||||||
Console.SetCursorPosition(0, Console.CursorTop - 2);
|
Console.SetCursorPosition(0, Console.CursorTop - 2);
|
||||||
Write(new string(' ', Console.BufferWidth), newLine: false);
|
Write(new string(' ', Console.BufferWidth), newLine: false);
|
||||||
|
|
||||||
|
if (failed > 0)
|
||||||
|
{
|
||||||
|
Console.CursorLeft = 0;
|
||||||
|
Console.CursorTop--;
|
||||||
|
Write($"{failed} file{(failed == 1 ? " has" : "s have")} been ignored due to an error.",
|
||||||
|
ConsoleColor.DarkYellow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else throw new("No file or directory located at \"source\"");
|
else throw new("No file or directory located at \"source\"");
|
||||||
|
|
||||||
|
|||||||
@ -8,8 +8,14 @@ public static class ExtractionModule
|
|||||||
{
|
{
|
||||||
if (!File.Exists(source)) throw new($"No file exists at \"{source}\".");
|
if (!File.Exists(source)) throw new($"No file exists at \"{source}\".");
|
||||||
|
|
||||||
destination ??= Path.GetDirectoryName(Path.GetFullPath(source));
|
if (destination is null)
|
||||||
if (destination is null) throw new("Error detecting destination path.");
|
{
|
||||||
|
string full = Path.GetFullPath(source);
|
||||||
|
string folder = Program.Shell!.WorkingDirectory;
|
||||||
|
string name = Path.GetFileNameWithoutExtension(full);
|
||||||
|
|
||||||
|
destination = $"{folder}\\{name}";
|
||||||
|
}
|
||||||
|
|
||||||
if (!Directory.Exists(destination)) Directory.CreateDirectory(destination);
|
if (!Directory.Exists(destination)) Directory.CreateDirectory(destination);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user