Skip to content

Commit

Permalink
Downgrade to net4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
UncraftedName committed Sep 20, 2023
1 parent 0de593e commit 96f9b20
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 101 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
fail-fast: false
matrix:
platform:
- {os: windows-latest, framework: net7.0-windows, runtime: win-x64}
- {os: ubuntu-latest, framework: net7.0, runtime: linux-x64}
- {os: windows-latest, framework: net481, runtime: win-x64}
# - {os: ubuntu-latest, framework: net7.0, runtime: linux-x64}
build_type:
- {
name: 'Build',
Expand Down
80 changes: 39 additions & 41 deletions ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,72 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net481</TargetFramework>
<ApplicationIcon>../github-resources/investigation.ico</ApplicationIcon>
<Platforms>AnyCPU;x64</Platforms>
<Platforms>AnyCPU</Platforms>
<Configurations>Debug;Release;Debug_ProcessEnts</Configurations>
<LangVersion>10</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>UntitledParser</AssemblyName>
<Nullable>enable</Nullable>
<WarningLevel>9999</WarningLevel>
<TargetFrameworks>net7.0;net7.0-windows</TargetFrameworks>
</PropertyGroup>

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

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>full</DebugType>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<TargetName>UntitledParser.Unmerged</TargetName>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DebugType>embedded</DebugType>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug_ProcessEnts' ">
<DefineConstants>TRACE;DEBUG</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_ProcessEnts|AnyCPU'">
<DebugType>full</DebugType>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>full</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_ProcessEnts|x64'">
<DebugType>full</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ILRepack.MSBuild.Task" Version="2.0.13" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DemoParser\DemoParser.csproj" />
<ProjectReference Include="..\DemoParser\DemoParser.csproj" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="ConsoleApp.BuildDateAttribute">
<_Parameter1>$([System.DateTime]::UtcNow.ToString("yyyyMMddHHmmss"))</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="ConsoleApp.BuildDateAttribute">
<_Parameter1>$([System.DateTime]::UtcNow.ToString("yyyyMMddHHmmss"))</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Remove="version.txt" />
<EmbeddedResource Include="version.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Remove="version.txt" />
<EmbeddedResource Include="version.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

<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>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<!--Make sure to update Utils.GetVersionString() if you edit this!-->
<Exec Command="git rev-list --count HEAD &gt; version.txt" />
<Exec Command="git branch --show-current &gt;&gt; version.txt" />
<Exec Command="git describe --always --dirty --exclude=* &gt;&gt; version.txt" />
<!--Make sure to update Utils.GetVersionString() if you edit this!-->
<Exec Command="git rev-list --count HEAD > version.txt"/>
<Exec Command="git branch --show-current >> version.txt"/>
<Exec Command="git describe --always --dirty --exclude=* >> version.txt"/>
</Target>
</Project>
18 changes: 0 additions & 18 deletions ConsoleApp/Properties/PublishProfiles/publish-single-file.pubxml

This file was deleted.

4 changes: 4 additions & 0 deletions ConsoleApp/src/DemoArgProcessing/DemoParserSubCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ private void FlattenDirectories(DemoParsingSetupInfo setupInfo) {
demoPath,
commonParent == ""
? demoPath.FullName
#if NET5_0_OR_GREATER
: Path.GetRelativePath(commonParent, demoPath.FullName)
#else
: PathExt.GetRelativePath(commonParent, demoPath.FullName)
#endif
));
}

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();
}
}
}
30 changes: 15 additions & 15 deletions DemoParser/DemoParser.csproj
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net7.0-windows</TargetFrameworks>
<TargetFramework>net481</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Title>UntitledDemoParser</Title>
<Authors>UncraftedName</Authors>
<RepositoryUrl>https://github.com/UncraftedName/UncraftedDemoParser</RepositoryUrl>
<PackageTags>SourceEngine demo Valve Portal</PackageTags>
<Description>A parser for Source Engine demos.</Description>
<PackageIconUrl>https://raw.githubusercontent.com/UncraftedName/UncraftedDemoParser/master/github-resources/investigation.ico</PackageIconUrl>
<Platforms>AnyCPU;x64</Platforms>
<Platforms>AnyCPU</Platforms>
<Configurations>Debug;Release;Debug_ProcessEnts</Configurations>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE</DefineConstants>
<NoWarn>1701;1702;8618;8602</NoWarn>
<DefineConstants>TRACE</DefineConstants>
<NoWarn>1701;1702;8618;8602</NoWarn>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug_ProcessEnts' ">
<DefineConstants>TRACE;FORCE_PROCESS_ENTS;DEBUG</DefineConstants>
<NoWarn>1701;1702;8618;8602</NoWarn>
<DefineConstants>TRACE;FORCE_PROCESS_ENTS;DEBUG</DefineConstants>
<NoWarn>1701;1702;8618;8602</NoWarn>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<NoWarn>1701;1702;8618;8602</NoWarn>
<NoWarn>1701;1702;8618;8602</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_ProcessEnts|AnyCPU'">
<Optimize>false</Optimize>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_ProcessEnts|x64'">
<Optimize>false</Optimize>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_ProcessEnts|x64'">
<Optimize>false</Optimize>
<Optimize>false</Optimize>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="C5" Version="3.0.0-rc" />
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" />
<PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="C5" Version="3.0.0-rc" />
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" />
<PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project>
Loading

0 comments on commit 96f9b20

Please sign in to comment.