Skip to content

Commit

Permalink
1.6.0: Fixed some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrix25633 committed Nov 26, 2022
1 parent 77df594 commit ef79124
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 105 deletions.
9 changes: 7 additions & 2 deletions Files.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public bool ToCopy(ref Dictionary<string, DirectoryEntry> destinationDictionary,
reason = Reason.CopyNotThere;
return true;
}
// Remove from destination dictionary to speed up the search for files to remove
destinationDictionary.Remove(relativePath);
// Skip if directory
if((e.fileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory) return false;
if((e.fileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
return false;
// Check size
if(fileInfo.Length != e.fileInfo.Length) {
reason = Reason.CopyDifferentSize;
Expand All @@ -47,7 +50,9 @@ public bool ToCopy(ref Dictionary<string, DirectoryEntry> destinationDictionary,
stream1.Close();
stream2.Close();
bool toCopy = (byte1 != byte2);
if(toCopy) reason = Reason.CopyDifferentContent;
if(toCopy) {
reason = Reason.CopyDifferentContent;
}
return toCopy;
}
catch(Exception exc) {
Expand Down
123 changes: 50 additions & 73 deletions Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ public class Logger {
private static string barFull = "█", barEmpty = " ";
private static string? logfilename;
private static StreamWriter? logstream;
private static List<Task> logTasks = new List<Task>();
private static int ticket = 0;
/// <summary>
/// Function to initialize the file logging
/// (<paramref name="log"/>)
Expand All @@ -29,91 +27,73 @@ public static void ReinitializeLogging() {
/// <summary>
/// Function to close the log stream
/// </summary>
public static async void TerminateLogging() {
public static void TerminateLogging() {
if(logstream != null) {
if(logTasks.Count != 0) await logTasks[logTasks.Count - 1];
logstream.Close();
logTasks = new List<Task>();
}
}
/// <summary>
/// Function to output a success message
/// (<paramref name="message"/>)
/// </summary>
/// <param name="message">The message to output</param>
public static async void Success(string message) {
int t = ticket++;
public static void Success(string message) {
string time = TimeString();
await logTasks.ElementAt(t);
logTasks.Append(Task.Run(() => {
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(time);
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("(Success) ");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(message);
Console.ResetColor();
if(logstream != null) logstream.WriteLineAsync(time + "(Success) " + message);
}));
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(time);
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("(Success) ");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(message);
Console.ResetColor();
if(logstream != null) logstream.WriteLineAsync(time + "(Success) " + message);
}
/// <summary>
/// Function to output an info message
/// (<paramref name="message"/>)
/// </summary>
/// <param name="message">The message to output</param>
public static async void Info(string message) {
int t = ticket++;
public static void Info(string message) {
string time = TimeString();
await logTasks.ElementAt(t);
logTasks.Append(Task.Run(() => {
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(time);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("(Info) ");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(message);
Console.ResetColor();
}));
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(time);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("(Info) ");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(message);
Console.ResetColor();
}
/// <summary>
/// Function to output a warning message
/// (<paramref name="message"/>)
/// </summary>
/// <param name="message">The message to output</param>
public static async void Warning(string message) {
int t = ticket++;
public static void Warning(string message) {
string time = TimeString();
await logTasks.ElementAt(t);
logTasks.Append(Task.Run(() => {
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(time);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("(Warning) ");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(message);
Console.ResetColor();
if(logstream != null) logstream.WriteLineAsync(time + "(Warning) " + message);
}));
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(time);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("(Warning) ");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(message);
Console.ResetColor();
if(logstream != null) logstream.WriteLineAsync(time + "(Warning) " + message);
}
/// <summary>
/// Function to output an error message
/// (<paramref name="message"/>)
/// </summary>
/// <param name="message">The message to output</param>
public static async void Error(string message) {
int t = ticket++;
public static void Error(string message) {
string time = TimeString();
await logTasks.ElementAt(t);
logTasks.Append(Task.Run(() => {
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(time);
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("(Error) ");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(message);
Console.ResetColor();
if(logstream != null) logstream.WriteLineAsync(time + "(Error) " + message);
}));
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(time);
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("(Error) ");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(message);
Console.ResetColor();
if(logstream != null) logstream.WriteLineAsync(time + "(Error) " + message);
}
/// <summary>
/// Function to clear the last console line
Expand All @@ -123,17 +103,11 @@ public static async void Error(string message) {
public static void RemoveLine(Int16 line = 1) {
Int32 currentLineCursor = Console.CursorTop;
Console.SetCursorPosition(0, currentLineCursor - line);
for (Int32 i = 0; i < Console.WindowWidth; i++)
for(Int32 i = 0; i < Console.WindowWidth; i++)
Console.Write(" ");
Console.SetCursorPosition(0, currentLineCursor - line);
}
/// <summary>
/// Function to output the hour
/// </summary>
public static void WriteHour() {
Console.Write(TimeString());
}
/// <summary>
/// Function to get the string time
/// </summary>
/// <returns>The string time, hh:mm:ss.msmsms</returns>
Expand All @@ -159,13 +133,15 @@ public static string LongTimeString() {
}
/// <summary>
/// Function to print a progress bar string
/// (<paramref name="current"/>, <paramref name="total"/>)
/// (<paramref name="currentSize"/>, <paramref name="totalSize"/>, <paramref name="currentElements"/>, <paramref name="totalElements"/>)
/// </summary>
/// <param name="current">The current stage</param>
/// <param name="total">The total</param>
public static void ProgressBar(UInt64 current, UInt64 total) {
/// <param name="currentSize">The current size</param>
/// <param name="totalSize">The total size</param>
/// <param name="currentElements">The current number of elements</param>
/// <param name="totalElements">The total number of elements</param>
public static void ProgressBar(UInt64 currentSize, UInt64 totalSize, Int32 currentElements, Int32 totalElements) {
string bar = "[";
Int16 percent = (Int16)((float)current / total * 100);
Int16 percent = (Int16)((float)currentSize / totalSize * 100);
for(Int16 i = 1; i <= percent; i++) {
bar += barFull;
}
Expand All @@ -177,7 +153,8 @@ public static void ProgressBar(UInt64 current, UInt64 total) {
}
Console.BackgroundColor = ConsoleColor.DarkGray;
Console.Write(bar);
bar = "] " + percent.ToString() + "% (" + HumanReadableSize(current) + "/" + HumanReadableSize(total) + ")";
bar = "] " + percent.ToString() + "% (" + HumanReadableSize(currentSize) + "/" + HumanReadableSize(totalSize) + ") (" +
currentElements + "/" + totalElements + ")";
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine(bar);
Expand All @@ -189,7 +166,7 @@ public static void ProgressBar(UInt64 current, UInt64 total) {
/// </summary>
/// <param name="reason">The reason</param>
/// <param name="file">The name of the file</param>
public static void InfoReason(Reason reason, string file) {
public static void InfoReason(Reason reason, string file, UInt64? size = null) {
string line = "";
switch(reason) {
case Reason.CopyNotThere:
Expand All @@ -205,15 +182,15 @@ public static void InfoReason(Reason reason, string file) {
line = "Removing: ";
break;
}
Info(line + file);
Info(line + file + " (" + ((size != null) ? HumanReadableSize((UInt64)size) : "folder") + ")");
}
/// <summary>
/// Function to print a message of the file that has been copied
/// (<paramref name="reason"/>, <paramref name="file"/>)
/// </summary>
/// <param name="reason">The reason</param>
/// <param name="file">The name of the file</param>
public static void SuccessReason(Reason reason, string file) {
public static void SuccessReason(Reason reason, string file, UInt64? size = null) {
string line = "";
switch(reason) {
case Reason.CopyNotThere:
Expand All @@ -229,7 +206,7 @@ public static void SuccessReason(Reason reason, string file) {
line = "Removed: ";
break;
}
Success(line + file);
Success(line + file + " (" + ((size != null) ? HumanReadableSize((UInt64)size) : "folder") + ")");
}
/// <summary>
/// Function to print a progress bar string
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.RECIPEPREFIX=>
VERSION=1.5.6
VERSION=1.6.0

default:
> clear
Expand All @@ -24,5 +24,4 @@ run-dotnet-debug:
> dotnet ./transfer/docker/debug/backup-utility.dll -- -s test/source -d test/destination -r test/removed -t 100 -e extensions.txt -l -b

run-dotnet-release:
> dotnet publish -c debug
> ./transfer/docker/release/linux-x64/backup-utility -s test/source -d test/destination -r test/removed -l
> ./transfer/docker/release/linux-x64/backup-utility -s test/source -d test/destination -r test/removed -l -e extensions.txt
Loading

0 comments on commit ef79124

Please sign in to comment.