Skip to content

Commit

Permalink
Downgrade back to net461 :)))
Browse files Browse the repository at this point in the history
  • Loading branch information
UncraftedName committed Feb 25, 2024
1 parent c801c82 commit 84cf25f
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 23 deletions.
18 changes: 17 additions & 1 deletion ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@
<AssemblyName>UntitledParser</AssemblyName>
<Nullable>enable</Nullable>
<WarningLevel>9999</WarningLevel>
<TargetFrameworks>net7.0;net7.0-windows</TargetFrameworks>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<TargetName>UntitledParser.Unmerged</TargetName>
<WarningLevel>9999</WarningLevel>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug_ProcessEnts' ">
<DefineConstants>TRACE;DEBUG</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>full</DebugType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ILRepack.MSBuild.Task" Version="2.0.13" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>embedded</DebugType>
Expand Down Expand Up @@ -72,4 +81,11 @@
<Exec Command="git branch --show-current &gt;&gt; version.txt" />
<Exec Command="git describe --always --dirty --exclude=* &gt;&gt; version.txt" />
</Target>

<Target Condition=" '$(Configuration)' == 'Release' " Name="Merge" AfterTargets="Build">
<PropertyGroup>
<WorkingDirectory>$(MSBuildThisFileDirectory)bin\$(Configuration)\$(TargetFramework)</WorkingDirectory>
</PropertyGroup>
<ILRepack OutputType="$(OutputType)" MainAssembly="$(AssemblyName).Unmerged.exe" OutputAssembly="UntitledParser.exe" InputAssemblies="$(WorkingDirectory)\*.dll" WilcardInputAssemblies="true" WorkingDirectory="$(WorkingDirectory)" />
</Target>
</Project>
18 changes: 0 additions & 18 deletions ConsoleApp/Properties/PublishProfiles/publish-single-file.pubxml

This file was deleted.

2 changes: 1 addition & 1 deletion ConsoleApp/src/DemoArgProcessing/DemoParserSubCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void FlattenDirectories(DemoParsingSetupInfo setupInfo) {
demoPath,
commonParent == ""
? demoPath.FullName
: Path.GetRelativePath(commonParent, demoPath.FullName)
: PathExt.GetRelativePath(commonParent, demoPath.FullName)
));
}

Expand Down
177 changes: 177 additions & 0 deletions ConsoleApp/src/PathExt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* More-or-less ripped straight from .NET Core runtime, with some ws/comments stripped out
*
* Licensed to the .NET Foundation under one or more agreements.
* The .NET Foundation licenses this file to you under the MIT license.
*/

// FIXME: This is very Windows-specific! This will probably be one of the things
// that needs fixed up if/when doing a Linux/Mono port.

using System;
using System.IO;
using System.Text;

namespace ConsoleApp {

internal static class PathExt {

private static bool IsDirectorySeparator(char c) => c == '\\' || c == '/';
private static bool EndsInDirectorySeparator(string path)
=> path.Length > 0 && IsDirectorySeparator(path[^1]);

private static unsafe int EqualStartingCharacterCount(string? first, string? second, bool ignoreCase) {
if (string.IsNullOrEmpty(first) || string.IsNullOrEmpty(second)) return 0;

int commonChars = 0;
fixed (char* f = first)
fixed (char* s = second) {
char* l = f;
char* r = s;
char* leftEnd = l + first!.Length;
char* rightEnd = r + second!.Length;

while (l != leftEnd && r != rightEnd
&& (*l == *r || (ignoreCase && char.ToUpperInvariant(*l) == char.ToUpperInvariant(*r)))) {
commonChars++;
l++;
r++;
}
}

return commonChars;
}

private static int GetCommonPathLength(string first, string second, bool ignoreCase) {
int commonChars = EqualStartingCharacterCount(first, second, ignoreCase);
if (commonChars == 0) return commonChars;
if (commonChars == first.Length && (commonChars == second.Length ||
IsDirectorySeparator(second[commonChars])))
return commonChars;
if (commonChars == second.Length && IsDirectorySeparator(first[commonChars]))
return commonChars;
while (commonChars > 0 && !IsDirectorySeparator(first[commonChars - 1]))
commonChars--;
return commonChars;
}

private static bool AreRootsEqual(string first, string second, StringComparison comparisonType) {
int firstRootLength = GetRootLength(first);
int secondRootLength = GetRootLength(second);

return firstRootLength == secondRootLength
&& string.Compare(
strA: first,
indexA: 0,
strB: second,
indexB: 0,
length: firstRootLength,
comparisonType: comparisonType) == 0;
}

private const int
DevicePrefixLength = 4,
UncPrefixLength = 2,
UncExtendedPrefixLength = 8;

private static bool IsExtended(string path) {
return path.Length >= DevicePrefixLength
&& path[0] == '\\'
&& (path[1] == '\\' || path[1] == '?')
&& path[2] == '?'
&& path[3] == '\\';
}

private static bool IsDevice(string path) {
return IsExtended(path)
||
(
path.Length >= DevicePrefixLength
&& IsDirectorySeparator(path[0])
&& IsDirectorySeparator(path[1])
&& (path[2] == '.' || path[2] == '?')
&& IsDirectorySeparator(path[3])
);
}

private static bool IsDeviceUNC(string path) {
return path.Length >= UncExtendedPrefixLength
&& IsDevice(path)
&& IsDirectorySeparator(path[7])
&& path[4] == 'U'
&& path[5] == 'N'
&& path[6] == 'C';
}

private static bool IsValidDriveChar(char value) {
return (value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z');
}

private static int GetRootLength(string path) {
int pathLength = path.Length;
int i = 0;

bool deviceSyntax = IsDevice(path);
bool deviceUnc = deviceSyntax && IsDeviceUNC(path);
if ((!deviceSyntax || deviceUnc) && pathLength > 0 && IsDirectorySeparator(path[0])) {
if (deviceUnc || (pathLength > 1 && IsDirectorySeparator(path[1]))) {
i = deviceUnc ? UncExtendedPrefixLength : UncPrefixLength;
int n = 2;
while (i < pathLength && (!IsDirectorySeparator(path[i]) || --n > 0)) i++;
} else {
i = 1;
}
} else if (deviceSyntax) {
i = DevicePrefixLength;
while (i < pathLength && !IsDirectorySeparator(path[i])) i++;
if (i < pathLength && i > DevicePrefixLength && IsDirectorySeparator(path[i])) i++;
}
else if (pathLength >= 2
&& path[1] == ':'
&& IsValidDriveChar(path[0])) {
i = 2;
if (pathLength > 2 && IsDirectorySeparator(path[2])) i++;
}
return i;
}

public static string GetRelativePath(string relativeTo, string path, StringComparison comparisonType = StringComparison.OrdinalIgnoreCase) {
if (relativeTo == null) throw new ArgumentNullException(nameof(relativeTo));
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException("Empty path", nameof(relativeTo));
if (path == null) throw new ArgumentNullException(nameof(path));
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException("Empty path", nameof(path));
relativeTo = Path.GetFullPath(relativeTo);
path = Path.GetFullPath(path);
if (!AreRootsEqual(relativeTo, path, comparisonType)) return path;
int commonLength = GetCommonPathLength(relativeTo, path, ignoreCase: comparisonType == StringComparison.OrdinalIgnoreCase);
if (commonLength == 0) return path;
int relativeToLength = relativeTo.Length;
if (EndsInDirectorySeparator(relativeTo)) relativeToLength--;
bool pathEndsInSeparator = EndsInDirectorySeparator(path);
int pathLength = path.Length;
if (pathEndsInSeparator) pathLength--;
if (relativeToLength == pathLength && commonLength >= relativeToLength) return ".";
var sb = new StringBuilder();
sb.EnsureCapacity(Math.Max(relativeTo.Length, path.Length));
if (commonLength < relativeToLength) {
sb.Append("..");
for (int i = commonLength + 1; i < relativeToLength; i++) {
if (IsDirectorySeparator(relativeTo[i])) {
sb.Append("\\..");
}
}
}
else if (IsDirectorySeparator(path[commonLength])) {
commonLength++;
}
int differenceLength = pathLength - commonLength;
if (pathEndsInSeparator) differenceLength++;
if (differenceLength > 0) {
if (sb.Length > 0) sb.Append(Path.DirectorySeparatorChar);
sb.Append(path.AsSpan(commonLength, differenceLength).ToString());
}

return sb.ToString();
}
}
}
2 changes: 1 addition & 1 deletion DemoParser/DemoParser.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net7.0-windows</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Title>UntitledDemoParser</Title>
<Authors>UncraftedName</Authors>
Expand All @@ -13,6 +12,7 @@
<Configurations>Debug;Release;Debug_ProcessEnts</Configurations>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
<TargetFrameworks>net461</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down
20 changes: 20 additions & 0 deletions DemoParser/src/Utils/System/Index.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace System
{
/* Polyfill for System.Index from .NET Core, to allow C# 8.0 [^n] notation */
public readonly struct Index
{
private readonly int _val;
public Index(int val, bool fromend = false)
{
_val = val;
if (fromend) _val = ~_val;
}
public int GetOffset(int len)
{
if (_val < 0) return len + _val;
return _val;
}

public static implicit operator Index(int i) => new Index(i);
}
}
14 changes: 14 additions & 0 deletions DemoParser/src/Utils/System/Range.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace System
{
/* Polyfill for System.Index from .NET Core, to allow C# 8.0 [start..end] notation */
public readonly struct Range
{
public Index Start { get; }
public Index End { get; }
public Range(Index start, Index end) { Start = start; End = end; }

public static Range StartAt(Index start) => new Range(start, new Index(-1));
public static Range EndAt(Index end) => new Range(new Index(0), end);
public static Range All => new Range(new Index(0), new Index(-1));
}
}
2 changes: 1 addition & 1 deletion Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net7.0-windows</TargetFrameworks>
<TargetFrameworks>net461</TargetFrameworks>
<IsPackable>false</IsPackable>
<Platforms>AnyCPU;x64</Platforms>
<Configurations>Debug;Release;Debug_ProcessEnts</Configurations>
Expand Down
2 changes: 1 addition & 1 deletion Tests/src/DemoParseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static string ProjectDir {
* when it doesn't.
*/
string projectName = Assembly.GetCallingAssembly().GetName().Name!;
string dir = Path.GetFullPath(Environment.CurrentDirectory);
string dir = Directory.GetParent(Assembly.GetCallingAssembly().Location).FullName;
for (int i = 0; i < 10; i++) {
if (dir.EndsWith(projectName, StringComparison.OrdinalIgnoreCase)) {
_projectDir = dir;
Expand Down
Binary file added UntitledParser.exe
Binary file not shown.

0 comments on commit 84cf25f

Please sign in to comment.