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

Revert to .NET Framework #17

Merged
merged 7 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,4 @@ dotnet_diagnostic.CA1036.severity = warning
dotnet_diagnostic.CA1727.severity = warning

# License header
file_header_template = Copyright 2023 CnCNet\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY, without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <http://www.gnu.org/licenses/>.
file_header_template = Copyright 2022-2024 CnCNet\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY, without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <http://www.gnu.org/licenses/>.
131 changes: 98 additions & 33 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,114 @@ on:
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
publish:
runs-on: windows-latest
calculate-version:
name: Calculate Version
runs-on: windows-2022
outputs:
AssemblySemVer: ${{ steps.gitversion.outputs.AssemblySemVer }}
AssemblySemFileVer: ${{ steps.gitversion.outputs.AssemblySemFileVer }}
InformationalVersion: ${{ steps.gitversion.outputs.InformationalVersion }}
NuGetVersionV2: ${{ steps.gitversion.outputs.NuGetVersionV2 }}
SemVer: ${{ steps.gitversion.outputs.SemVer }}
PreReleaseTag: ${{ steps.gitversion.outputs.PreReleaseTag }}
Sha: ${{ steps.gitversion.outputs.Sha }}
steps:
- name: Checkout
uses: actions/checkout@main
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@main
with:
dotnet-version: '7.x.x'

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@main
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: '5.x'

- name: Determine Version
uses: gittools/actions/gitversion/execute@main

id: gitversion
uses: gittools/actions/gitversion/execute@v0
pack-updater:
name: Pack ClientUpdater
runs-on: windows-2022
needs: calculate-version
env:
AssemblySemVer: ${{ needs.calculate-version.outputs.AssemblySemVer }}
AssemblySemFileVer: ${{ needs.calculate-version.outputs.AssemblySemFileVer }}
InformationalVersion: ${{ needs.calculate-version.outputs.InformationalVersion }}
NuGetVersionV2: ${{ needs.calculate-version.outputs.NuGetVersionV2 }}
SemVer: ${{ needs.calculate-version.outputs.SemVer }}
Sha: ${{ needs.calculate-version.outputs.Sha }}
PlatformTarget: ''
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.Sha }}
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x.x'
- name: Pack
run: dotnet pack ClientUpdater\ClientUpdater.csproj -p:AssemblyVersion=${{env.AssemblySemVer}} -p:FileVersion=${{env.AssemblySemFileVer}} -p:InformationalVersion=${{env.InformationalVersion}} -p:PackageVersion=${{env.NuGetVersionV2}}
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ClientUpdater
path: ClientUpdater\bin\*\*.*nupkg
if-no-files-found: error
publish-secondstageupdater:
name: Publish SecondStageUpdater
runs-on: windows-2022
needs: calculate-version
env:
AssemblySemVer: ${{ needs.calculate-version.outputs.AssemblySemVer }}
AssemblySemFileVer: ${{ needs.calculate-version.outputs.AssemblySemFileVer }}
InformationalVersion: ${{ needs.calculate-version.outputs.InformationalVersion }}
NuGetVersionV2: ${{ needs.calculate-version.outputs.NuGetVersionV2 }}
SemVer: ${{ needs.calculate-version.outputs.SemVer }}
Sha: ${{ needs.calculate-version.outputs.Sha }}
PlatformTarget: ''
strategy:
matrix:
framework: [net8.0, net48]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.Sha }}
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x.x'
- name: Publish
run: dotnet publish SecondStageUpdater/SecondStageUpdater.csproj --configuration Release -p:DebugType=embedded -p:AssemblyVersion=$env:GitVersion_AssemblySemVer -p:FileVersion=$env:GitVersion_AssemblySemFileVer -p:InformationalVersion=$env:GitVersion_InformationalVersion

run: dotnet publish SecondStageUpdater/SecondStageUpdater.csproj -c Release -p:DebugType=embedded -f ${{ matrix.framework }} -p:AssemblyVersion=${{env.AssemblySemVer}} -p:FileVersion=${{env.AssemblySemFileVer}} -p:InformationalVersion=${{env.InformationalVersion}}
- name: Zip
run: 7z a -r ${{ format('SecondStageUpdater-v{0}.zip', env.GitVersion_SemVer) }} ./SecondStageUpdater/bin/Release/net7.0/publish/*.*

- name: Pack
run: dotnet pack ClientUpdater\ClientUpdater.csproj --configuration Release -p:AssemblyVersion=$env:GitVersion_AssemblySemVer -p:FileVersion=$env:GitVersion_AssemblySemFileVer -p:InformationalVersion=$env:GitVersion_InformationalVersion -p:PackageVersion=$env:GitVersion_NuGetVersionV2

- name: Prerelease
if: ${{ env.GitVersion_PreReleaseTag != '' }}
run: gh release create ${{ format('v{0}', env.GitVersion_SemVer) }} (@(get-item *.zip) + @(get-item ClientUpdater\bin\Release\*.*nupkg)) --generate-notes --target ${{ github.sha }} --prerelease
env:
GH_TOKEN: ${{ github.token }}

run: 7z a -r "${{ format('SecondStageUpdater-v{0}-{1}.zip', env.SemVer, matrix.framework) }}" "./SecondStageUpdater/bin/Release/${{ matrix.framework }}/publish/*.*" "-x!*.xml"
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: SecondStageUpdater-${{ matrix.framework }}
path: ./*.zip
if-no-files-found: error
release:
name: Release
needs: [calculate-version, pack-updater, publish-secondstageupdater]
env:
PreReleaseTag: ${{ needs.calculate-version.outputs.PreReleaseTag }}
SemVer: ${{ needs.calculate-version.outputs.SemVer }}
Sha: ${{ needs.calculate-version.outputs.Sha }}
runs-on: windows-2022
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.Sha }}
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Push
run: dotnet nuget push artifacts\*\*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
- name: Release
if: ${{ env.GitVersion_PreReleaseTag == '' }}
run: gh release create ${{ format('v{0}', env.GitVersion_SemVer) }} (@(get-item *.zip) + @(get-item ClientUpdater\bin\Release\*.*nupkg)) --generate-notes --target ${{ github.sha }}
run: gh release create v${{ env.SemVer }} @((Get-Item artifacts\*.zip) + (Get-Item artifacts\*\*.*nupkg)) --generate-notes --target ${{ env.Sha }} ${{ env.PreReleaseTag != '' && '--prerelease' || '' }}
env:
GH_TOKEN: ${{ github.token }}

- name: Push
run: dotnet nuget push ClientUpdater\bin\Release\*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source ${{ format('https://nuget.pkg.github.com/{0}/index.json', github.repository_owner) }}
GH_TOKEN: ${{ github.token }}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -398,5 +398,4 @@ FodyWeavers.xsd
*.sln.iml

# CnCNet
/Compiled
.idea/.idea.Updater/.idea/
/Compiled
17 changes: 9 additions & 8 deletions ClientUpdater/ClientUpdater.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>net8.0;net48</TargetFrameworks>
<Title>CnCNet.ClientUpdater</Title>
<Description>CnCNet Client Updater Library</Description>
<Company>CnCNet</Company>
<Product></Product>
<Copyright>Copyright © CnCNet 2023</Copyright>
<Product>CnCNet.ClientUpdater</Product>
<Copyright>Copyright © CnCNet 2022-2024</Copyright>
<Trademark></Trademark>
<AssemblyName>ClientUpdater</AssemblyName>
<RootNamespace>ClientUpdater</RootNamespace>
Expand All @@ -26,25 +26,26 @@
<PackageProjectUrl>https://github.com/CnCNet/cncnet-client-updater</PackageProjectUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<PackageLicenseExpression></PackageLicenseExpression>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
<EnablePackageValidation>true</EnablePackageValidation>
<AnalysisMode Condition="'$(Configuration)' == 'Debug'">All</AnalysisMode>
<EnforceCodeStyleInBuild Condition="'$(Configuration)' == 'Debug'">true</EnforceCodeStyleInBuild>
<AnalysisMode Condition="'$(Configuration)' != 'Debug'">Recommended</AnalysisMode>
<AnalysisModeDocumentation Condition="'$(Configuration)' != 'Debug'">None</AnalysisModeDocumentation>
<AnalysisModeNaming Condition="'$(Configuration)' != 'Debug'">None</AnalysisModeNaming>
<AnalysisModeStyle Condition="'$(Configuration)' != 'Debug'">None</AnalysisModeStyle>
<LangVersion>12.0</LangVersion>
<Nullable>disable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<None Include="..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="Rampastring.Tools" Version="2.0.4" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="StyleCop.Analyzers" Version="1.2.0-beta.435">
<PackageReference Include="Polyfill" Version="2.2.0" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
</Project>
43 changes: 10 additions & 33 deletions ClientUpdater/Compression/CompressionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 CnCNet
// Copyright 2022-2024 CnCNet
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -34,25 +34,13 @@ public static class CompressionHelper
public static async ValueTask CompressFileAsync(string inputFilename, string outputFilename, CancellationToken cancellationToken = default)
{
var encoder = new Encoder(cancellationToken);
var inputStream = new FileStream(inputFilename, new FileStreamOptions
{
Access = FileAccess.Read,
Mode = FileMode.Open,
Options = FileOptions.Asynchronous | FileOptions.SequentialScan,
Share = FileShare.None
});
var inputStream = new FileStream(inputFilename, FileMode.Open, FileAccess.Read, FileShare.None, 4096, FileOptions.Asynchronous | FileOptions.SequentialScan);

await using (inputStream.ConfigureAwait(false))
using (inputStream)
{
var outputStream = new FileStream(outputFilename, new FileStreamOptions
{
Access = FileAccess.Write,
Mode = FileMode.Create,
Options = FileOptions.Asynchronous,
Share = FileShare.None
});
var outputStream = new FileStream(outputFilename, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);

await using (outputStream.ConfigureAwait(false))
using (outputStream)
{
encoder.WriteCoderProperties(outputStream);
await outputStream.WriteAsync(BitConverter.GetBytes(inputStream.Length).AsMemory(0, 8), cancellationToken).ConfigureAwait(false);
Expand All @@ -69,25 +57,14 @@ public static async ValueTask CompressFileAsync(string inputFilename, string out
public static async ValueTask DecompressFileAsync(string inputFilename, string outputFilename, CancellationToken cancellationToken = default)
{
var decoder = new Decoder(cancellationToken);
var inputStream = new FileStream(inputFilename, new FileStreamOptions
{
Access = FileAccess.Read,
Mode = FileMode.Open,
Options = FileOptions.Asynchronous | FileOptions.SequentialScan,
Share = FileShare.None
});

await using (inputStream.ConfigureAwait(false))
var inputStream = new FileStream(inputFilename, FileMode.Open, FileAccess.Read, FileShare.None, 4096, FileOptions.Asynchronous | FileOptions.SequentialScan);

using (inputStream)
{
var outputStream = new FileStream(outputFilename, new FileStreamOptions
{
Access = FileAccess.Write,
Mode = FileMode.Create,
Options = FileOptions.Asynchronous,
Share = FileShare.None
});
var outputStream = new FileStream(outputFilename, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);

await using (outputStream.ConfigureAwait(false))
using (outputStream)
{
byte[] properties = new byte[5];
byte[] fileLengthArray = new byte[sizeof(long)];
Expand Down
47 changes: 22 additions & 25 deletions ClientUpdater/CustomComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 CnCNet
// Copyright 2022-2024 CnCNet
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -157,15 +157,25 @@ private async Task DoDownloadComponentAsync(CancellationToken cancellationToken)
{
Logger.Log("CustomComponent: Initializing download of custom component: " + GUIName);

progressMessageHandler = new ProgressMessageHandler(new SocketsHttpHandler
#if NETFRAMEWORK
progressMessageHandler = new(new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
});

using var httpClient = new HttpClient(progressMessageHandler, true);
#else
progressMessageHandler = new(new SocketsHttpHandler
{
PooledConnectionLifetime = TimeSpan.FromMinutes(15),
AutomaticDecompression = DecompressionMethods.All
});

using var httpClient = new HttpClient(progressMessageHandler, true)
{
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher
};
#endif

IsBeingDownloaded = true;
currentDownloadPercentage = -1;
Expand All @@ -181,21 +191,15 @@ private async Task DoDownloadComponentAsync(CancellationToken cancellationToken)

Logger.Log("CustomComponent: Downloading version info.");

var versionFileStream = new FileStream(versionFileName, new FileStreamOptions
{
Access = FileAccess.Write,
Mode = FileMode.Create,
Options = FileOptions.Asynchronous,
Share = FileShare.None
});
var versionFileStream = new FileStream(versionFileName, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);

await using (versionFileStream.ConfigureAwait(false))
using (versionFileStream)
{
Stream stream = await httpClient.GetStreamAsync(new Uri(uriString), cancellationToken).ConfigureAwait(false);
Stream stream = await httpClient.GetStreamAsync(new Uri(uriString)).ConfigureAwait(false);

await using (stream.ConfigureAwait(false))
using (stream)
{
await stream.CopyToAsync(versionFileStream, cancellationToken).ConfigureAwait(false);
await stream.CopyToAsync(versionFileStream, 81920, cancellationToken).ConfigureAwait(false);
}
}

Expand All @@ -218,21 +222,14 @@ private async Task DoDownloadComponentAsync(CancellationToken cancellationToken)

num++;

var downloadFileStream = new FileStream(downloadFileName, new FileStreamOptions
{
Access = FileAccess.Write,
Mode = FileMode.Create,
Options = FileOptions.Asynchronous,
Share = FileShare.None
});

await using (downloadFileStream.ConfigureAwait(false))
var downloadFileStream = new FileStream(versionFileName, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);
using (downloadFileStream)
{
Stream stream = await httpClient.GetStreamAsync(downloadUri, cancellationToken).ConfigureAwait(false);
Stream stream = await httpClient.GetStreamAsync(downloadUri).ConfigureAwait(false);

await using (stream.ConfigureAwait(false))
using (stream)
{
await stream.CopyToAsync(downloadFileStream, cancellationToken).ConfigureAwait(false);
await stream.CopyToAsync(downloadFileStream, 81920, cancellationToken).ConfigureAwait(false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ClientUpdater/UpdateMirror.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 CnCNet
// Copyright 2022-2024 CnCNet
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down
Loading