Browse Source

Formatting cleanup

pull/165/head
Ionite 1 year ago
parent
commit
626e3436ef
No known key found for this signature in database
  1. 70
      StabilityMatrix.Core/Helper/FileTransfers.cs
  2. 7
      StabilityMatrix.Core/Helper/SharedFolders.cs

70
StabilityMatrix.Core/Helper/FileTransfers.cs

@ -17,7 +17,8 @@ public static class FileTransfers
/// </summary>
/// <param name="totalBytes"></param>
/// <returns></returns>
public static ulong GetBufferSize(ulong totalBytes) => totalBytes switch
public static ulong GetBufferSize(ulong totalBytes) =>
totalBytes switch
{
< Size.MiB => 8 * Size.KiB,
< 100 * Size.MiB => 16 * Size.KiB,
@ -42,7 +43,11 @@ public static class FileTransfers
/// <param name="totalProgress">
/// Optional (total) progress.
/// </param>
public static async Task CopyFiles(Dictionary<string, string> files, IProgress<ProgressReport>? fileProgress = default, IProgress<ProgressReport>? totalProgress = default)
public static async Task CopyFiles(
Dictionary<string, string> files,
IProgress<ProgressReport>? fileProgress = default,
IProgress<ProgressReport>? totalProgress = default
)
{
var totalFiles = files.Count;
var completedFiles = 0;
@ -53,19 +58,48 @@ public static class FileTransfers
{
var totalReadForFile = 0ul;
await using var outStream = new FileStream(destPath, FileMode.Create, FileAccess.Write, FileShare.Read);
await using var inStream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read, FileShare.Read);
await using var outStream = new FileStream(
destPath,
FileMode.Create,
FileAccess.Write,
FileShare.Read
);
await using var inStream = new FileStream(
sourcePath,
FileMode.Open,
FileAccess.Read,
FileShare.Read
);
var fileSize = (ulong)inStream.Length;
var fileName = Path.GetFileName(sourcePath);
completedFiles++;
await CopyStream(inStream , outStream, fileReadBytes =>
await CopyStream(
inStream,
outStream,
fileReadBytes =>
{
var lastRead = totalReadForFile;
totalReadForFile = Convert.ToUInt64(fileReadBytes);
totalRead += totalReadForFile - lastRead;
fileProgress?.Report(new ProgressReport(totalReadForFile, fileSize, fileName, $"{completedFiles}/{totalFiles}"));
totalProgress?.Report(new ProgressReport(totalRead, totalSize, fileName, $"{completedFiles}/{totalFiles}"));
} );
fileProgress?.Report(
new ProgressReport(
totalReadForFile,
fileSize,
fileName,
$"{completedFiles}/{totalFiles}"
)
);
totalProgress?.Report(
new ProgressReport(
totalRead,
totalSize,
fileName,
$"{completedFiles}/{totalFiles}"
)
);
}
)
.ConfigureAwait(false);
}
}
@ -104,7 +138,8 @@ public static class FileTransfers
DirectoryPath sourceDir,
DirectoryPath destinationDir,
bool overwrite = false,
bool overwriteIfHashMatches = false)
bool overwriteIfHashMatches = false
)
{
// Create the destination directory if it doesn't exist
if (!destinationDir.Exists)
@ -120,8 +155,13 @@ public static class FileTransfers
{
var destinationSubDir = destinationDir.JoinDir(subDir.Name);
// Recursively move sub directories
await MoveAllFilesAndDirectories(subDir, destinationSubDir,
overwrite, overwriteIfHashMatches);
await MoveAllFilesAndDirectories(
subDir,
destinationSubDir,
overwrite,
overwriteIfHashMatches
)
.ConfigureAwait(false);
}
}
@ -137,7 +177,8 @@ public static class FileTransfers
DirectoryPath sourceDir,
DirectoryPath destinationDir,
bool overwrite = false,
bool overwriteIfHashMatches = false)
bool overwriteIfHashMatches = false
)
{
foreach (var file in sourceDir.Info.EnumerateFiles())
{
@ -160,8 +201,9 @@ public static class FileTransfers
if (sourceHash == destinationHash)
{
Logger.Info(
$"Deleted source file {file.Name} as it already exists in {destinationDir}." +
$" Matching Blake3 hash: {sourceHash}");
$"Deleted source file {file.Name} as it already exists in {destinationDir}."
+ $" Matching Blake3 hash: {sourceHash}"
);
sourceFile.Delete();
continue;
}

7
StabilityMatrix.Core/Helper/SharedFolders.cs

@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using NLog;
using NLog;
using StabilityMatrix.Core.Extensions;
using StabilityMatrix.Core.Helper.Factory;
using StabilityMatrix.Core.Models;
@ -54,7 +53,8 @@ public class SharedFolders : ISharedFolders
Logger.Info($"Creating junction source {sourceDir}");
sourceDir.Create();
}
// Delete the destination folder if it exists
// Destination folder exists, move files to source then delete
if (destinationDir.Exists)
{
// Copy all files from destination to source
@ -76,6 +76,7 @@ public class SharedFolders : ISharedFolders
Logger.Info($"Deleting junction target {destinationDir}");
destinationDir.Delete(true);
}
Logger.Info($"Creating junction link from {sourceDir} to {destinationDir}");
CreateLinkOrJunction(destinationDir, sourceDir, true);
}

Loading…
Cancel
Save