Skip to content

Commit

Permalink
Merge pull request CmlLib#34 from LiamSho/master
Browse files Browse the repository at this point in the history
Target to netstandard 2.0 and some optimizations
  • Loading branch information
AlphaBs authored Sep 22, 2021
2 parents 36da638 + dc60b05 commit ae7bb90
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 68 deletions.
82 changes: 41 additions & 41 deletions CmlLib/CmlLib.csproj
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<Version>3.3.2</Version>
<Description>Minecraft Launcher Library for .NET
Support all version, forge, optifine
</Description>
<Copyright>Copyright (c) 2021 AlphaBs</Copyright>
<PackageProjectUrl>https://github.com/CmlLib/CmlLib.Core</PackageProjectUrl>
<RepositoryUrl>https://github.com/CmlLib/CmlLib.Core</RepositoryUrl>
<PackageIcon>icon.png</PackageIcon>
<RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>Minecraft Launcher forge optifine mojang Crossplatform C#</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>AlphaBs</Authors>
<PackageReleaseNotes />
<PackageId>CmlLib.Core</PackageId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ConfigureAwait.Fody" Version="3.3.1">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Fody" Version="6.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="LZMA-SDK" Version="19.0.0" />
<PackageReference Include="MethodTimer.Fody" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="SharpZipLib" Version="1.2.0" />
<None Include="../icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<Version>3.3.2</Version>
<Description>Minecraft Launcher Library for .NET
Support all version, forge, optifine
</Description>
<Copyright>Copyright (c) 2021 AlphaBs</Copyright>
<PackageProjectUrl>https://github.com/CmlLib/CmlLib.Core</PackageProjectUrl>
<RepositoryUrl>https://github.com/CmlLib/CmlLib.Core</RepositoryUrl>
<PackageIcon>icon.png</PackageIcon>
<RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>Minecraft Launcher forge optifine mojang Crossplatform C#</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>AlphaBs</Authors>
<PackageReleaseNotes />
<PackageId>CmlLib.Core</PackageId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ConfigureAwait.Fody" Version="3.3.1">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Fody" Version="6.5.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="LZMA-SDK" Version="19.0.0" />
<PackageReference Include="MethodTimer.Fody" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="SharpZipLib" Version="1.3.3" />
<None Include="../icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>

</Project>
12 changes: 0 additions & 12 deletions CmlLib/Core/MRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,12 @@ static MRule()

private static string getOSName()
{
// Environment.OSVersion.Platform does not work in NET Core
#if NETFRAMEWORK
var osType = Environment.OSVersion.Platform;

if (osType == PlatformID.MacOSX)
return OSX;
else if (osType == PlatformID.Unix)
return Linux;
else
return Windows;
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return OSX;
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return Windows;
else
return Linux;
#endif
}

public static bool CheckOSRequire(JArray arr)
Expand Down
8 changes: 4 additions & 4 deletions CmlLib/Utils/IOUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static StreamWriter AsyncStreamWriter(string path, Encoding encoding, boo
return new StreamWriter(stream, encoding);
}

// In .NET Framework 4.6.2, There is no File.ReadFileTextAsync. so I copied it from .NET Core source code
// In .NET Standard 2.0, There is no File.ReadFileTextAsync. so I copied it from .NET Core source code
public static async Task<string> ReadFileAsync(string path)
{
using var reader = AsyncStreamReader(path, Encoding.UTF8);
Expand All @@ -184,8 +184,8 @@ public static async Task<string> ReadFileAsync(string path)
await reader.BaseStream.FlushAsync().ConfigureAwait(false);
return content;
}
// In .NET Framework 4.6.2, There is no File.WriteFileTextAsync. so I copied it from .NET Core source code

// In .NET Standard 2.0, There is no File.WriteFileTextAsync. so I copied it from .NET Core source code
public static async Task WriteFileAsync(string path, string content)
{
// UTF8 with BOM might not be recognized by minecraft. not tested
Expand All @@ -201,7 +201,7 @@ public static async Task CopyFileAsync(string sourceFile, string destinationFile
using var destinationStream = AsyncWriteStream(destinationFile, false);

await sourceStream.CopyToAsync(destinationStream).ConfigureAwait(false);

await destinationStream.FlushAsync().ConfigureAwait(false);
}

Expand Down
2 changes: 1 addition & 1 deletion CmlLibCoreSample/CmlLibCoreSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion CmlLibWinFormSample/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
</configuration>
6 changes: 5 additions & 1 deletion CmlLibWinFormSample/CmlLibWinFormSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
<OutputType>WinExe</OutputType>
<RootNamespace>CmlLibWinFormSample</RootNamespace>
<AssemblyName>CmlLibWinFormSample</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -32,6 +33,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
13 changes: 5 additions & 8 deletions release.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
if ($args.Length -gt 0)
{
$ver=$args[0]
if ($args.Length -gt 0) {
$ver = $args[0]
}
else
{
else {
$ver = Read-Host 'version'
}

Expand All @@ -14,9 +12,8 @@ mkdir .\release\SampleCoreLauncher$ver
mkdir .\release\SampleWinformLauncher$ver

Copy-Item .\CmlLib\bin\Release\* -Destination .\release\CmlLib.Core.$ver -Recurse
Get-ChildItem .\release\CmlLib.Core.$ver -Recurse -File | Where {($_.Extension -ne ".dll")} | Remove-Item
Copy-Item -Path .\CmlLibCoreSample\bin\Release\netcoreapp3.1\* -Destination .\release\SampleCoreLauncher$ver
Copy-Item .\CmlLibWinFormSample\bin\Release\* -Destination .\release\SampleWinformLauncher$ver -Include *.exe,*.dll,*.pdb,*.config
Get-ChildItem .\release\CmlLib.Core.$ver -Recurse -File | Where-Object { ($_.Extension -ne ".dll") } | Remove-Item
Copy-Item .\CmlLibWinFormSample\bin\Release\* -Destination .\release\SampleWinformLauncher$ver -Include *.exe, *.dll, *.pdb, *.config

Compress-Archive -Path .\release\CmlLib.Core.$ver -DestinationPath .\release\CmlLib.Core.$ver.zip
Compress-Archive -Path .\release\SampleCoreLauncher$ver -DestinationPath .\release\SampleCoreLauncher$ver.zip
Expand Down

0 comments on commit ae7bb90

Please sign in to comment.