Skip to content

Commit 1233abc

Browse files
author
LoneWandererProductions
committed
cleanup more
1 parent 0bdf09b commit 1233abc

3 files changed

Lines changed: 33 additions & 34 deletions

File tree

CommonLibraryTests/IoFileHandler.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ public async Task CutListAsync()
593593
/// Cuts the files valid source and target cuts files.
594594
/// </summary>
595595
[TestMethod]
596-
public void CutFilesValidSourceAndTargetCutsFiles()
596+
public async Task CutFilesValidSourceAndTargetCutsFilesAsync()
597597
{
598598
// Arrange
599599
var sourceFilePath = Path.Combine(TestSourceDir, "test.txt");
@@ -624,7 +624,7 @@ public void CutFilesSourceAndTargetEqualThrowsFileHandlerException()
624624
/// Cuts the files non existent source returns false.
625625
/// </summary>
626626
[TestMethod]
627-
public void CutFilesNonExistentSourceReturnsFalse()
627+
public async Task CutFilesNonExistentSourceReturnsFalseAsync()
628628
{
629629
var result = FileHandleCut.CutFiles("NonExistentSource", TestTargetDir, true);
630630
Assert.IsFalse(result);
@@ -634,7 +634,7 @@ public void CutFilesNonExistentSourceReturnsFalse()
634634
/// Cuts the files with file list cuts files successfully.
635635
/// </summary>
636636
[TestMethod]
637-
public void CutFilesWithFileListCutsFilesSuccessfully()
637+
public async Task CutFilesWithFileListCutsFilesSuccessfullyAsync()
638638
{
639639
// Arrange
640640
var sourceFilePath = Path.Combine(TestSourceDir, "test.txt");
@@ -666,7 +666,7 @@ public void CutFilesFileListNullOrEmptyThrowsFileHandlerException()
666666
/// Cuts the files file list non existent file returns false.
667667
/// </summary>
668668
[TestMethod]
669-
public void CutFilesFileListNonExistentFileReturnsFalse()
669+
public async Task CutFilesFileListNonExistentFileReturnsFalseAsync()
670670
{
671671
var fileList = new List<string> { "NonExistentFile.txt" };
672672
var result = FileHandleCut.CutFiles(fileList, TestTargetDir, true);
@@ -677,7 +677,7 @@ public void CutFilesFileListNonExistentFileReturnsFalse()
677677
/// Cuts the files with overwrite cuts files successfully.
678678
/// </summary>
679679
[TestMethod]
680-
public void CutFilesWithOverwriteCutsFilesSuccessfully()
680+
public async Task CutFilesWithOverwriteCutsFilesSuccessfullyAsync()
681681
{
682682
// Arrange
683683
var sourceFilePath = Path.Combine(TestSourceDir, "test.txt");
@@ -699,7 +699,7 @@ public void CutFilesWithOverwriteCutsFilesSuccessfully()
699699
/// Cuts the files without overwrite existing files not overwritten.
700700
/// </summary>
701701
[TestMethod]
702-
public void CutFilesWithoutOverwriteExistingFilesNotOverwritten()
702+
public async Task CutFilesWithoutOverwriteExistingFilesNotOverwrittenAsync()
703703
{
704704
// Arrange
705705
var sourceFilePath = Path.Combine(TestSourceDir, "test.txt");
@@ -721,7 +721,7 @@ public void CutFilesWithoutOverwriteExistingFilesNotOverwritten()
721721
/// Cuts the files handles subdirectories.
722722
/// </summary>
723723
[TestMethod]
724-
public void CutFilesHandlesSubdirectories()
724+
public async Task CutFilesHandlesSubdirectoriesAsync()
725725
{
726726
// Arrange
727727
var subDir = Path.Combine(TestSourceDir, "SubDir");

FileHandler/FileHandleCreate.cs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,68 @@
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: FileHandler
44
* FILE: FileHandler/FileHandleCreate.cs
5-
* PURPOSE: Does all types of File Operations, Create Files
6-
* PROGRAMER: Peter Geinitz (Wayfarer)
5+
* PURPOSE: Handles all types of file creation operations
6+
* PROGRAMMER: Peter Geinitz (Wayfarer)
77
*/
88

9-
// ReSharper disable UnusedMember.Global
10-
119
using System;
1210
using System.Diagnostics;
1311
using System.IO;
1412

1513
namespace FileHandler;
1614

1715
/// <summary>
18-
/// The file handle create class.
16+
/// Handles file and folder creation.
1917
/// </summary>
2018
public static class FileHandleCreate
2119
{
2220
/// <summary>
23-
/// Create a Folder
21+
/// Creates a folder at the specified path.
2422
/// </summary>
25-
/// <param name="path">path</param>
26-
/// <exception cref="FileHandlerException">No Correct Path was provided</exception>
23+
/// <param name="path">Target folder path.</param>
24+
/// <exception cref="FileHandlerException">Thrown if the path is null or empty.</exception>
2725
public static void CreateFolder(string path)
2826
{
29-
if (string.IsNullOrEmpty(path))
30-
{
27+
if (string.IsNullOrWhiteSpace(path))
3128
throw new FileHandlerException(FileHandlerResources.ErrorEmptyString);
32-
}
3329

3430
_ = CreateDirectory(path);
3531
}
3632

3733
/// <summary>
38-
/// Creates a Folder in a specific path, based on the root folder
34+
/// Creates a folder with a specific name inside a parent path.
3935
/// </summary>
40-
/// <param name="path">Path</param>
41-
/// <param name="name">Folder Name</param>
42-
/// <returns>If path was generated </returns>
43-
/// <exception cref="FileHandlerException">No Correct Path was provided</exception>
36+
/// <param name="path">Parent path.</param>
37+
/// <param name="name">Folder name.</param>
38+
/// <returns>True if the folder was created or already exists; false if creation failed.</returns>
39+
/// <exception cref="FileHandlerException">Thrown if the path or name is null or empty.</exception>
4440
public static bool CreateFolder(string path, string name)
4541
{
46-
if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(name))
47-
{
42+
if (string.IsNullOrWhiteSpace(path) || string.IsNullOrWhiteSpace(name))
4843
throw new FileHandlerException(FileHandlerResources.ErrorEmptyString);
49-
}
5044

51-
var root = Path.Combine(path, name);
45+
var fullPath = Path.Combine(path, name);
5246

53-
return CreateDirectory(root);
47+
return CreateDirectory(fullPath);
5448
}
5549

5650
/// <summary>
57-
/// Creates the directory.
51+
/// Creates the directory safely.
5852
/// </summary>
59-
/// <param name="path">The path.</param>
60-
/// <returns>If path was generated </returns>
53+
/// <param name="path">Full folder path.</param>
54+
/// <returns>True if the folder was created or already exists; false if creation failed.</returns>
6155
private static bool CreateDirectory(string path)
6256
{
6357
try
6458
{
65-
_ = Directory.CreateDirectory(path);
59+
// Directory.CreateDirectory is safe: it does nothing if the directory already exists.
60+
Directory.CreateDirectory(path);
6661
return true;
6762
}
68-
catch (Exception ex) when (ex is UnauthorizedAccessException or IOException or PathTooLongException)
63+
catch (Exception ex) when (ex is UnauthorizedAccessException
64+
or IOException
65+
or PathTooLongException
66+
or NotSupportedException)
6967
{
7068
FileHandlerRegister.AddError(nameof(CreateFolder), path, ex);
7169
Trace.WriteLine(ex);

FileHandler/FileHandlerRegister.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
using System;
1515
using System.Collections.Generic;
16+
using System.Threading;
1617

1718
namespace FileHandler;
1819

@@ -34,7 +35,7 @@ public static class FileHandlerRegister
3435
/// <summary>
3536
/// The error log lock
3637
/// </summary>
37-
private static readonly object _errorLogLock = new();
38+
private static readonly Lock _errorLogLock = new();
3839

3940
/// <summary>
4041
/// Gets the error log.

0 commit comments

Comments
 (0)