Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Add even more madness to already too much madness
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Feb 9, 2023
1 parent 58c3bf3 commit 6dcd0f8
Show file tree
Hide file tree
Showing 12 changed files with 388 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.10.0</Version>
<Version>3.11.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
<PackageVersion Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageVersion Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.2" />
<PackageVersion Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageVersion Include="IndexRange" Version="1.0.2" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.2" />
<PackageVersion Include="System.Memory" Version="4.5.5" />
</ItemGroup>
</Project>
60 changes: 51 additions & 9 deletions JustArchiNET.Madness.sln.DotSettings

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions JustArchiNET.Madness/DirectoryInfoMadness/DirectoryInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// _ __ __
// ___ ___ ___ _ __ __| | __ _ | \/ |
// / __|/ __| / _ \| '_ \ / _` | / _` || |\/| |
// \__ \\__ \| __/| | | || (_| || (_| || | | |
// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_|
// |
// Copyright 2021-2023 Łukasz "JustArchi" Domeradzki
// Contact: [email protected]
// |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/LICENSE-2.0
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.IO;
using System.Security.AccessControl;
using JetBrains.Annotations;
using JustArchiNET.Madness.ArgumentNullExceptionMadness;
using JustArchiNET.Madness.FileMadness;
using JustArchiNET.Madness.Helpers;
using JustArchiNET.Madness.Internal;

namespace JustArchiNET.Madness.DirectoryInfoMadness;

[MadnessType(EMadnessType.Replacement)]
[PublicAPI]
public sealed class DirectoryInfo {
private readonly System.IO.DirectoryInfo UnderlyingDirectoryInfo;

[MadnessType(EMadnessType.Implementation)]
public UnixFileMode UnixFileMode {
get => UnixFileMode.None;
set => NativeMethods.Chmod(UnderlyingDirectoryInfo.FullName, value);
}

[MadnessType(EMadnessType.Proxy)]
public DirectoryInfo(string path) : this(new System.IO.DirectoryInfo(path)) { }

internal DirectoryInfo(System.IO.DirectoryInfo directoryInfo) => UnderlyingDirectoryInfo = directoryInfo ?? throw new ArgumentNullException(nameof(directoryInfo));

[MadnessType(EMadnessType.Proxy)]
public void SetAccessControl(DirectorySecurity directorySecurity) => UnderlyingDirectoryInfo.SetAccessControl(directorySecurity);
}
66 changes: 66 additions & 0 deletions JustArchiNET.Madness/DirectoryMadness/Directory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// _ __ __
// ___ ___ ___ _ __ __| | __ _ | \/ |
// / __|/ __| / _ \| '_ \ / _` | / _` || |\/| |
// \__ \\__ \| __/| | | || (_| || (_| || | | |
// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_|
// |
// Copyright 2021-2023 Łukasz "JustArchi" Domeradzki
// Contact: [email protected]
// |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/LICENSE-2.0
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.Generic;
using System.IO;
using JetBrains.Annotations;
using JustArchiNET.Madness.Helpers;
using DirectoryInfo = JustArchiNET.Madness.DirectoryInfoMadness.DirectoryInfo;

namespace JustArchiNET.Madness.DirectoryMadness;

[MadnessType(EMadnessType.Replacement)]
[PublicAPI]
public static class Directory {
[MadnessType(EMadnessType.Replacement)]
public static DirectoryInfo CreateDirectory(string path) {
System.IO.DirectoryInfo directoryInfo = System.IO.Directory.CreateDirectory(path);

return new DirectoryInfo(directoryInfo);
}

[MadnessType(EMadnessType.Proxy)]
public static void Delete(string path) => System.IO.Directory.Delete(path);

[MadnessType(EMadnessType.Proxy)]
public static void Delete(string path, bool recursive) => System.IO.Directory.Delete(path, recursive);

[MadnessType(EMadnessType.Proxy)]
public static IEnumerable<string> EnumerateDirectories(string path) => System.IO.Directory.EnumerateDirectories(path);

[MadnessType(EMadnessType.Proxy)]
public static IEnumerable<string> EnumerateFiles(string path, string searchPattern) => System.IO.Directory.EnumerateFiles(path, searchPattern);

[MadnessType(EMadnessType.Proxy)]
public static IEnumerable<string> EnumerateFiles(string path, string searchPattern, SearchOption searchOption) => System.IO.Directory.EnumerateFiles(path, searchPattern, searchOption);

[MadnessType(EMadnessType.Proxy)]
public static IEnumerable<string> EnumerateFileSystemEntries(string path) => System.IO.Directory.EnumerateFileSystemEntries(path);

[MadnessType(EMadnessType.Proxy)]
public static bool Exists(string path) => System.IO.Directory.Exists(path);

[MadnessType(EMadnessType.Proxy)]
public static string GetCurrentDirectory() => System.IO.Directory.GetCurrentDirectory();

[MadnessType(EMadnessType.Proxy)]
public static void SetCurrentDirectory(string path) => System.IO.Directory.SetCurrentDirectory(path);
}
50 changes: 50 additions & 0 deletions JustArchiNET.Madness/FileInfoMadness/FileInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// _ __ __
// ___ ___ ___ _ __ __| | __ _ | \/ |
// / __|/ __| / _ \| '_ \ / _` | / _` || |\/| |
// \__ \\__ \| __/| | | || (_| || (_| || | | |
// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_|
// |
// Copyright 2021-2023 Łukasz "JustArchi" Domeradzki
// Contact: [email protected]
// |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/LICENSE-2.0
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.IO;
using System.Security.AccessControl;
using JetBrains.Annotations;
using JustArchiNET.Madness.ArgumentNullExceptionMadness;
using JustArchiNET.Madness.FileMadness;
using JustArchiNET.Madness.Helpers;
using JustArchiNET.Madness.Internal;

namespace JustArchiNET.Madness.FileInfoMadness;

[MadnessType(EMadnessType.Replacement)]
[PublicAPI]
public sealed class FileInfo {
private readonly System.IO.FileInfo UnderlyingFileInfo;

[MadnessType(EMadnessType.Implementation)]
public UnixFileMode UnixFileMode {
get => UnixFileMode.None;
set => NativeMethods.Chmod(UnderlyingFileInfo.FullName, value);
}

[MadnessType(EMadnessType.Proxy)]
public FileInfo(string path) : this(new System.IO.FileInfo(path)) { }

internal FileInfo(System.IO.FileInfo fileInfo) => UnderlyingFileInfo = fileInfo ?? throw new ArgumentNullException(nameof(fileInfo));

[MadnessType(EMadnessType.Proxy)]
public void SetAccessControl(FileSecurity fileSecurity) => UnderlyingFileInfo.SetAccessControl(fileSecurity);
}
45 changes: 45 additions & 0 deletions JustArchiNET.Madness/FileMadness/UnixFileMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// _ __ __
// ___ ___ ___ _ __ __| | __ _ | \/ |
// / __|/ __| / _ \| '_ \ / _` | / _` || |\/| |
// \__ \\__ \| __/| | | || (_| || (_| || | | |
// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_|
// |
// Copyright 2021-2023 Łukasz "JustArchi" Domeradzki
// Contact: [email protected]
// |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/LICENSE-2.0
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using JustArchiNET.Madness.Helpers;

namespace JustArchiNET.Madness.FileMadness;

[MadnessType(EMadnessType.Implementation)]
[PublicAPI]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public enum UnixFileMode {
None = 0,
OtherExecute = 1,
OtherWrite = 2,
OtherRead = 4,
GroupExecute = 8,
GroupWrite = 16,
GroupRead = 32,
UserExecute = 64,
UserWrite = 128,
UserRead = 256,
StickyBit = 512,
SetGroup = 1024,
SetUser = 2048
}
30 changes: 30 additions & 0 deletions JustArchiNET.Madness/Internal/NativeMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// _ __ __
// ___ ___ ___ _ __ __| | __ _ | \/ |
// / __|/ __| / _ \| '_ \ / _` | / _` || |\/| |
// \__ \\__ \| __/| | | || (_| || (_| || | | |
// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_|
// |
// Copyright 2021-2023 Łukasz "JustArchi" Domeradzki
// Contact: [email protected]
// |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/LICENSE-2.0
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Runtime.InteropServices;
using JustArchiNET.Madness.FileMadness;

namespace JustArchiNET.Madness.Internal;

internal static class NativeMethods {
[DllImport("libc", EntryPoint = "chmod", SetLastError = true)]
internal static extern int Chmod(string path, UnixFileMode mode);
}
3 changes: 2 additions & 1 deletion JustArchiNET.Madness/JustArchiNET.Madness.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
<PackageReference Include="JetBrains.Annotations" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="System.IO.FileSystem.AccessControl" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="IndexRange" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="System.Memory" />
</ItemGroup>

Expand Down
40 changes: 40 additions & 0 deletions JustArchiNET.Madness/NewtonsoftJsonMadness/JsonTextReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// _ __ __
// ___ ___ ___ _ __ __| | __ _ | \/ |
// / __|/ __| / _ \| '_ \ / _` | / _` || |\/| |
// \__ \\__ \| __/| | | || (_| || (_| || | | |
// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_|
// |
// Copyright 2021-2023 Łukasz "JustArchi" Domeradzki
// Contact: [email protected]
// |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/LICENSE-2.0
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.IO;
using System.Threading.Tasks;
using JetBrains.Annotations;
using JustArchiNET.Madness.Helpers;

namespace JustArchiNET.Madness.NewtonsoftJsonMadness;

[MadnessType(EMadnessType.Replacement)]
[PublicAPI]
public class JsonTextReader : Newtonsoft.Json.JsonTextReader, IAsyncDisposable {
public JsonTextReader(TextReader reader) : base(reader) { }

public ValueTask DisposeAsync() {
Dispose(true);

return default(ValueTask);
}
}
40 changes: 40 additions & 0 deletions JustArchiNET.Madness/NewtonsoftJsonMadness/JsonTextWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// _ __ __
// ___ ___ ___ _ __ __| | __ _ | \/ |
// / __|/ __| / _ \| '_ \ / _` | / _` || |\/| |
// \__ \\__ \| __/| | | || (_| || (_| || | | |
// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_|
// |
// Copyright 2021-2023 Łukasz "JustArchi" Domeradzki
// Contact: [email protected]
// |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/LICENSE-2.0
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.IO;
using System.Threading.Tasks;
using JetBrains.Annotations;
using JustArchiNET.Madness.Helpers;

namespace JustArchiNET.Madness.NewtonsoftJsonMadness;

[MadnessType(EMadnessType.Replacement)]
[PublicAPI]
public class JsonTextWriter : Newtonsoft.Json.JsonTextWriter, IAsyncDisposable {
public JsonTextWriter(TextWriter writer) : base(writer) { }

public ValueTask DisposeAsync() {
Dispose(true);

return default(ValueTask);
}
}
Loading

0 comments on commit 6dcd0f8

Please sign in to comment.