Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v10 #137

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c55a406
Update Build (#87)
AnakinRaW Jan 28, 2023
3d742b7
Versioning (#88)
AnakinRaW Jan 28, 2023
5b29cae
Merge branch 'main' into develop
AnakinRaW Jan 28, 2023
5c61f2e
update projects (#91)
AnakinRaW Jan 29, 2023
f651d1d
merge conflicts
AnakinRaW Jan 29, 2023
c883b74
Merge branch 'develop' of https://github.com/AnakinRaW/CommonUtilitie…
AnakinRaW Jan 29, 2023
a5af695
Download manager update (#93)
AnakinRaW Jan 30, 2023
68027dc
Merge branch 'develop' of https://github.com/AnakinRaW/CommonUtilitie…
AnakinRaW Jan 30, 2023
bf498c8
fix local files get disposed
AnakinRaW Jan 30, 2023
34c2975
disposing
AnakinRaW Jan 30, 2023
4b218b6
make download config immutable
AnakinRaW Jan 31, 2023
449992e
release 4.0
AnakinRaW Jan 31, 2023
a8c5fc7
Merge branch 'main' into develop
AnakinRaW Jan 31, 2023
8f5d5be
fix not using io.abstractions
AnakinRaW Mar 14, 2023
e170cda
add test cases
AnakinRaW Mar 14, 2023
12bb0ee
Bump Microsoft.NET.Test.Sdk from 17.4.1 to 17.5.0 (#100)
dependabot[bot] Mar 14, 2023
f110796
Bump System.IO.Abstractions from 19.1.13 to 19.2.1 (#101)
dependabot[bot] Mar 14, 2023
de7221a
update deps
AnakinRaW Mar 14, 2023
75eb8ec
Merge branch 'main' into develop
AnakinRaW Mar 14, 2023
77fa1f3
New pipeline (#105)
AnakinRaW Apr 5, 2023
328732e
update version
AnakinRaW Apr 5, 2023
dedf306
add process elevation
AnakinRaW Apr 12, 2023
9566268
update
AnakinRaW Apr 12, 2023
b79a3e7
ignore test
AnakinRaW Apr 12, 2023
7e731c5
use config provider
AnakinRaW Apr 22, 2023
c7586dc
merge
AnakinRaW Apr 22, 2023
70d7a2b
fix build from merge
AnakinRaW Apr 22, 2023
bcb6812
update and move verification
AnakinRaW Apr 22, 2023
3b2a95d
update deps
AnakinRaW Apr 22, 2023
b4a84a3
to class
AnakinRaW Apr 22, 2023
5088866
merge
AnakinRaW Apr 22, 2023
ba9d90a
update deps
AnakinRaW May 9, 2023
21fc3be
add CurrentProcessInfo
AnakinRaW May 9, 2023
7bc35ed
increase version
AnakinRaW May 9, 2023
d35d65a
merge cpi and elevation
AnakinRaW May 9, 2023
f5f5aa1
remove test
AnakinRaW May 9, 2023
a2a62f5
merge
AnakinRaW May 10, 2023
04c52fa
move namespace
AnakinRaW May 10, 2023
ea4ec29
don't move ns
AnakinRaW May 10, 2023
11478c8
Merge branch 'main' into develop
AnakinRaW May 10, 2023
e351c82
fix logger
AnakinRaW May 20, 2023
38367f4
added base pipelines implemntations
AnakinRaW May 20, 2023
d842f8c
update deps
AnakinRaW May 20, 2023
4fcdf47
Merge branch 'main' into develop
AnakinRaW May 20, 2023
2cd7acd
Update dependencies (#133)
AnakinRaW Jan 2, 2024
0ed546e
Version 9.0 Impl (#134)
AnakinRaW Mar 11, 2024
e5ef968
Version 10 impl (#136)
AnakinRaW Mar 11, 2024
1dbc5d9
merge
AnakinRaW Mar 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ jobs:
needs: [test]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Checkout source
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
- name: Create packages
run: dotnet pack --configuration Release --output ./packages
- name: Upload a Build Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: NuGet packages
path: packages/*.*
Expand All @@ -38,21 +38,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v3
- uses: actions/download-artifact@v3
uses: actions/setup-dotnet@v4
- uses: actions/download-artifact@v4
with:
name: NuGet packages
path: packages
- name: Push packages
run: dotnet nuget push "packages/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
- uses: dotnet/[email protected].0
- uses: dotnet/[email protected].2
id: nbgv
- name: Create GitHub release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
name: v${{ steps.nbgv.outputs.SemVer2 }}
tag_name: v${{ steps.nbgv.outputs.SemVer2 }}
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v3
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Build & Test in Release Mode
run: dotnet test --configuration Release --logger "GitHubActions"

- name: Build & Test .NET Framework
if: matrix.os == 'windows-latest'
run: dotnet test --configuration Release -f net48 --logger "GitHubActions"
run: dotnet test --configuration Release --logger "GitHubActions"
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.IO;
using System.IO.Abstractions;
using System.Runtime.CompilerServices;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text.RegularExpressions;

namespace AnakinRaW.CommonUtilities.FileSystem.Windows;

Expand All @@ -13,93 +11,6 @@ namespace AnakinRaW.CommonUtilities.FileSystem.Windows;
/// </summary>
public static class WindowsPathExtensions
{
private static readonly Regex RegexInvalidName =
new("^(COM\\d|CLOCK\\$|LPT\\d|AUX|NUL|CON|PRN|(.*[\\ud800-\\udfff]+.*))$", RegexOptions.IgnoreCase);

private static readonly char[] InvalidNameChars = Path.GetInvalidFileNameChars();

/// <summary>
/// Checks whether a file name is valid on Windows.
/// </summary>
/// <param name="_"></param>
/// <param name="fileName">The file name to validate.</param>
/// <returns><see langword="true"/> if the file name is valid; Otherwise, <see langword="false"/>.</returns>
/// <exception cref="PlatformNotSupportedException">If the current system is not Windows.</exception>
public static FileNameValidationResult IsValidFileName(this IPath _, string fileName)
{
ThrowHelper.ThrowIfNotWindows();

if (string.IsNullOrEmpty(fileName))
return FileNameValidationResult.NullOrEmpty;

var fileNameSpan = fileName.AsSpan();

if (!EdgesValid(fileNameSpan, out var whiteSpaceError))
return whiteSpaceError
? FileNameValidationResult.LeadingOrTrailingWhiteSpace
: FileNameValidationResult.TrailingPeriod;

if (ContainsInvalidChars(fileNameSpan))
return FileNameValidationResult.InvalidCharacter;

if (RegexInvalidName.IsMatch(fileName))
return FileNameValidationResult.WindowsReserved;

return FileNameValidationResult.Valid;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool ContainsInvalidChars(ReadOnlySpan<char> value)
{
foreach (var t in value)
if (IsInvalidFileCharacter(t))
return true;

return false;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsInvalidFileCharacter(char c)
{
// Additional check for invalid Windows file name characters
foreach (var charToCheck in InvalidNameChars)
{
if (charToCheck == c)
return true;
}

return false;
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool EdgesValid(ReadOnlySpan<char> value, out bool whiteSpace)
{
whiteSpace = false;

if (value[0] is '\x0020')
{
whiteSpace = true;
return false;
}

#if NET
var lastChar = value[^1];
#else
var lastChar = value[value.Length - 1];
#endif
if (lastChar is '\x0020')
{
whiteSpace = true;
return false;
}

if (lastChar is '.')
return false;

return true;
}

// Based on: https://stackoverflow.com/questions/1410127/c-sharp-test-if-user-has-write-access-to-a-folder
/// <summary>
/// Checks whether the current executing user that the requested rights on a given location.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,90 +1,12 @@
using System.IO;
using System.Security.AccessControl;
using AnakinRaW.CommonUtilities.Testing;
using Testably.Abstractions.Testing;
using Xunit;

namespace AnakinRaW.CommonUtilities.FileSystem.Windows.Test;

public class WindowsPathServiceTest
{
private readonly MockFileSystem _fileSystem = new();

[PlatformSpecificTheory(TestPlatformIdentifier.Windows)]
[InlineData("123")]
[InlineData("123.txt")]
[InlineData("123..txt")]
[InlineData("fileNameWithCase")]
[InlineData("fileNameWith_underscore")]
[InlineData("fileNameWith-hyphen")]
[InlineData(".test")]
[InlineData("LPT12")]
[InlineData("COM12")]
[InlineData("NUL.txt")] // Though it's not recommend by MS, it's actually allowed to use this name in explorer
[InlineData("nameWithNonASCII_ö")]
[InlineData("\u0160")]
public void Test_IsValidFileName_ValidNames(string input)
{
Assert.Equal(FileNameValidationResult.Valid, _fileSystem.Path!.IsValidFileName(input));
}


[PlatformSpecificTheory(TestPlatformIdentifier.Windows)]
[InlineData(null, FileNameValidationResult.NullOrEmpty)]
[InlineData("", FileNameValidationResult.NullOrEmpty)]
[InlineData(" ", FileNameValidationResult.LeadingOrTrailingWhiteSpace)]
[InlineData("\0", FileNameValidationResult.InvalidCharacter)]
[InlineData("123\0", FileNameValidationResult.InvalidCharacter)]
[InlineData("123\t", FileNameValidationResult.InvalidCharacter)]
[InlineData("123\r", FileNameValidationResult.InvalidCharacter)]
[InlineData("123\n", FileNameValidationResult.InvalidCharacter)]
[InlineData("nameWithTrailingSpace ", FileNameValidationResult.LeadingOrTrailingWhiteSpace)]
[InlineData(" nameWithLeadingSpace", FileNameValidationResult.LeadingOrTrailingWhiteSpace)]
[InlineData("my\\path", FileNameValidationResult.InvalidCharacter)]
[InlineData("my/path", FileNameValidationResult.InvalidCharacter)]
[InlineData("illegalChar_<", FileNameValidationResult.InvalidCharacter)]
[InlineData("illegalChar_>", FileNameValidationResult.InvalidCharacter)]
[InlineData("illegalChar_|", FileNameValidationResult.InvalidCharacter)]
[InlineData("illegalChar_:", FileNameValidationResult.InvalidCharacter)]
[InlineData("illegalChar_*", FileNameValidationResult.InvalidCharacter)]
[InlineData("illegalChar_?", FileNameValidationResult.InvalidCharacter)]
[InlineData(".", FileNameValidationResult.TrailingPeriod)]
[InlineData("..", FileNameValidationResult.TrailingPeriod)]
[InlineData("test....", FileNameValidationResult.TrailingPeriod)]
[InlineData("test..", FileNameValidationResult.TrailingPeriod)]
[InlineData("test.", FileNameValidationResult.TrailingPeriod)]
[InlineData("con", FileNameValidationResult.WindowsReserved)]
[InlineData("PRN", FileNameValidationResult.WindowsReserved)]
[InlineData("AUX", FileNameValidationResult.WindowsReserved)]
[InlineData("NUL", FileNameValidationResult.WindowsReserved)]
[InlineData("COM0", FileNameValidationResult.WindowsReserved)]
[InlineData("COM1", FileNameValidationResult.WindowsReserved)]
[InlineData("COM2", FileNameValidationResult.WindowsReserved)]
[InlineData("COM3", FileNameValidationResult.WindowsReserved)]
[InlineData("COM4", FileNameValidationResult.WindowsReserved)]
[InlineData("COM5", FileNameValidationResult.WindowsReserved)]
[InlineData("COM6", FileNameValidationResult.WindowsReserved)]
[InlineData("COM7", FileNameValidationResult.WindowsReserved)]
[InlineData("COM8", FileNameValidationResult.WindowsReserved)]
[InlineData("COM9", FileNameValidationResult.WindowsReserved)]
[InlineData("lpt0", FileNameValidationResult.WindowsReserved)]
[InlineData("lpt1", FileNameValidationResult.WindowsReserved)]
[InlineData("lpt2", FileNameValidationResult.WindowsReserved)]
[InlineData("lpt3", FileNameValidationResult.WindowsReserved)]
[InlineData("lpt4", FileNameValidationResult.WindowsReserved)]
[InlineData("lpt5", FileNameValidationResult.WindowsReserved)]
[InlineData("lpt6", FileNameValidationResult.WindowsReserved)]
[InlineData("lpt7", FileNameValidationResult.WindowsReserved)]
[InlineData("lpt8", FileNameValidationResult.WindowsReserved)]
[InlineData("lpt9", FileNameValidationResult.WindowsReserved)]
[InlineData("\\file", FileNameValidationResult.InvalidCharacter)]
[InlineData("/file", FileNameValidationResult.InvalidCharacter)]
[InlineData("|file", FileNameValidationResult.InvalidCharacter)]
public void Test_IsValidFileName_InvalidNames(string input, FileNameValidationResult expected)
{
Assert.Equal(expected, _fileSystem.Path!.IsValidFileName(input));
}

[PlatformSpecificTheory(TestPlatformIdentifier.Windows)]
[InlineData(null, FileSystemRights.Read, true)]
[InlineData(null, FileSystemRights.Write, true)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AnakinRaW.CommonUtilities.FileSystem;

internal class FileNameValidator
{

}
Loading
Loading