xna-cncnet-client icon indicating copy to clipboard operation
xna-cncnet-client copied to clipboard

.NET 6 Cross platform

Open Rans4ckeR opened this issue 3 years ago • 19 comments

  • Updated frameworks

    • .NET 4.8
      • DirectX targets AnyCPU
      • OpenGL targets AnyCPU
      • XNA targets x86
    • .NET 6.0:
      • net6.0-windows: WinForms, Windows 7 and up
      • net6.0: cross platform
      • DirectX targets AnyCPU
      • OpenGL targets AnyCPU
      • XNA targets x86
  • Updated dependencies

    • New Rampastring.Tools local NuGet package
    • New Rampastring.XNAUI.* local NuGet packages
      • XNA 4.0 Refresh
      • MonoGame DX & GL 3.8.0 (.NET 4.8)
      • MonoGame DX & GL 3.8.1 (.NET 6.0)
    • Replaced Ionic.Zip with System.IO.Compression
    • Use Izo.net NuGet package
    • Use OpenMcdf NuGet package
    • New ClientUpdater local NuGet package
  • Switch to new project file format

  • New solution configurations and platforms

    • Configurations: AresWindowsDXDebug;AresUniversalGLDebug;AresWindowsGLDebug;AresWindowsXNADebug; AresWindowsDXRelease;AresUniversalGLRelease;AresWindowsGLRelease;AresWindowsXNARelease; TSWindowsDXDebug;TSUniversalGLDebug;TSWindowsGLDebug;TSWindowsXNADebug; TSWindowsDXRelease;TSUniversalGLRelease;TSWindowsGLRelease;TSWindowsXNARelease; YRWindowsDXDebug;YRUniversalGLDebug;YRWindowsGLDebug;YRWindowsXNADebug; YRWindowsDXRelease;YRUniversalGLRelease;YRWindowsGLRelease;YRWindowsXNARelease
    • Platforms: AnyCPU, x86, x64, ARM64
  • Includes .editorconfig with my default warning rules. This triggers many new warnings. The rules can be reviewed and updated, or I can fix the current warnings in another PR.

  • Cross platform

    • Adds an additional .NET6.0 'UniversalGL' build without WinForms. Allows client to be run on any device with .NET6.0 installed (new Rampastring.XNAUI package).

    • Improves .NET4.8 compatibility on mono

    • Cross platform building (build on Linux, run on Windows and vice versa)

    • Tested (YR):

      • .NET4.8 WindowsGL on mono (WSL2 Ubuntu 20.04)
      • .NET6.0 UniversalGL on WSL2 Ubuntu 20.04
      • .NET6.0 UniversalGL on Fedora 36.1.5
      • .NET6.0 UniversalGL on Windows 11
      • All other existing builds on Windows 11
    • Changes:

      • Uses the platform safe SafePath methods for handling file system path operations (new Rampastring.Tools package)
      • Replaced WinForms Clipboard with TextCopy
      • Replaced WinForms/System.Drawing with ImageSharp
      • Replaced WinForms Screen with XNA GraphicsAdapter.DefaultAdapter
      • Replaced WindowsIdentity.GetCurrent().Name with Environment.UserName
    • Limitations for UniversalGL build:

      • Can not use WinForms based methods of WindowManager; HasFocus, Minimize, Maximize, Hide, ...
      • Win API is only supported on Windows; FlashWindowEx, LoadCursorFromFile
      • Registry is only supported on Windows
    • TODO:

      • The Windows Registry is used by TS. Currently this code is guarded by RuntimeInformation.IsOSPlatform() checks. This will need a replacement to store information on the file system instead.

Notes:

  • Switching to/from an XNA configuration within Visual Studio may require you to unload and reload the ClientCore project file (or restart VS) regarding MonoGame/XNA dependencies

Prerequisites* for this PR:

  • https://github.com/Rampastring/Rampastring.Tools/pull/4
  • https://github.com/Rampastring/Rampastring.XNAUI/pull/17
  • https://github.com/CnCNet/cncnet-client-updater/pull/1 And just FYI there's also this PR, which is not related to this PR:
  • https://github.com/CnCNet/cncnet-server/pull/1

* Strictly taken these are not prerequisites because the code in the linked PR's is included in this PR as local NuGet packages.

Rans4ckeR avatar Jun 12 '22 17:06 Rans4ckeR

Nightly build for this pull request:

  • artifacts.zip This comment is automatic and is meant to allow guests to get latest automatic builds without registering. It is updated on every successful build.

github-actions[bot] avatar Jun 12 '22 18:06 github-actions[bot]

I added the recently added new updater temporarily as a project in the solution until it's made officially public. This is needed to make it work on .NET6 as the current updater code throws exceptions.

Rans4ckeR avatar Jun 12 '22 20:06 Rans4ckeR

I added the recently added new updater temporarily as a project in the solution until it's made officially public. This is needed to make it work on .NET6 as the current updater code throws exceptions.

Check CnCNet repos, should be public already.

Metadorius avatar Jun 12 '22 20:06 Metadorius

I added the recently added new updater temporarily as a project in the solution until it's made officially public. This is needed to make it work on .NET6 as the current updater code throws exceptions.

Check CnCNet repos, should be public already.

Thanks for the heads up. I saw that repo a while ago but noticed it was not the currently included updater dll. I didn't realize the newly added dll was coming from this repo. I'll create a PR for that repo and include it as a NuGet package in this PR similar to Rampastring.Tools and Rampastring.XNAUI.

Rans4ckeR avatar Jun 12 '22 20:06 Rans4ckeR

Included the new updater as a NuGet package

Rans4ckeR avatar Jun 13 '22 10:06 Rans4ckeR

.NET 6 abandoned the machine-specific ANSI encoding and writing text files with this encoding is needed for the map editors for TS/RA2. Otherwise, the map editors will not work if the program path contains any non-ASCII characters. I suggest find an alternative way to generate configuration files for map editors before migrating to .NET 6.

SadPencil avatar Jun 22 '22 01:06 SadPencil

See https://github.com/CnCNet/xna-cncnet-client/pull/127 for more details about the text encoding issues that is needed for legacy games

See also https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding.default?view=netframework-4.8

https://stackoverflow.com/a/70258850

SadPencil avatar Jun 22 '22 02:06 SadPencil

image

ref

  • https://docs.microsoft.com/dotnet/api/system.text.codepagesencodingprovider
  • https://github.com/dotnet/standard/issues/260#issuecomment-289534859

frg2089 avatar Jun 22 '22 03:06 frg2089

image

ref

* https://docs.microsoft.com/dotnet/api/system.text.codepagesencodingprovider

* [What is default encoding in .Net? dotnet/standard#260 (comment)](https://github.com/dotnet/standard/issues/260#issuecomment-289534859)

Good catch. One question remaining: If the option "Beta: Use Unicode UTF-8 for worldwide language support" is enabled, does your code get UTF-8 as the default ANSI encoding?

SadPencil avatar Jun 22 '22 07:06 SadPencil

image ref

* https://docs.microsoft.com/dotnet/api/system.text.codepagesencodingprovider

* [What is default encoding in .Net? dotnet/standard#260 (comment)](https://github.com/dotnet/standard/issues/260#issuecomment-289534859)

Good catch. One question remaining: If the option "Beta: Use Unicode UTF-8 for worldwide language support" is enabled, does your code get UTF-8 as the default ANSI encoding?

yes

image

frg2089 avatar Jun 22 '22 07:06 frg2089

Isn't this handled already with this change in the PR? bc885d6ab8b977176d13ff41510d588f29bfbec9

Rans4ckeR avatar Jun 22 '22 08:06 Rans4ckeR

Isn't this handled already with this change in the PR? bc885d6

No. Your commit completely breaks the functionality. See the original comment in the source code.

ANSI doesn't mean a specific codepage, it means the default non-Unicode codepage which can be changed from Control Panel.

SadPencil avatar Jun 22 '22 08:06 SadPencil

image ref

* https://docs.microsoft.com/dotnet/api/system.text.codepagesencodingprovider

* [What is default encoding in .Net? dotnet/standard#260 (comment)](https://github.com/dotnet/standard/issues/260#issuecomment-289534859)

Good catch. One question remaining: If the option "Beta: Use Unicode UTF-8 for worldwide language support" is enabled, does your code get UTF-8 as the default ANSI encoding?

yes

image

Excellent work

SadPencil avatar Jun 22 '22 08:06 SadPencil

Looks good to me :)

SadPencil avatar Jun 23 '22 13:06 SadPencil

Looks good to my eye. Though I think this now bumps the requirement to having VS2022 if you plan on building for .NET 6 right? Would be good to mention that in the readme.

I made some updates to the readme

Rans4ckeR avatar Jun 23 '22 18:06 Rans4ckeR

Closes #218

Rans4ckeR avatar Jun 24 '22 19:06 Rans4ckeR

Closes #218

We can use asynchronous methods. It waits until there is no data until it is transferred.

The suggestion I wrote in #218 was a busy waiting, which was a mistake.

and add closed CnCNet/xna-cncnet-client#218 in commit can close issue when PR be merge. see github docs https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue

frg2089 avatar Jun 25 '22 00:06 frg2089

Closes #218

We can use asynchronous methods. It waits until there is no data until it is transferred.

I was planning to replace all Threading code with Tasks and async/await at a later stage.

Rans4ckeR avatar Jun 26 '22 20:06 Rans4ckeR

Cross platform changes merged MonoGame updated to 3.8.1

Rans4ckeR avatar Jul 24 '22 22:07 Rans4ckeR

Umm... May you can public the AppHostPatcher source code? I'll try to make it as MSBuild Extension.

frg2089 avatar Aug 24 '22 05:08 frg2089

Umm... May you can public the AppHostPatcher source code? I'll try to make it as MSBuild Extension.

I don't have a proper place to upload it, but it's not that much code, you can maybe use ILSpy or something :)

Rans4ckeR avatar Aug 25 '22 18:08 Rans4ckeR

Umm... May you can public the AppHostPatcher source code? I'll try to make it as MSBuild Extension.

I don't have a proper place to upload it, but it's not that much code, you can maybe use ILSpy or something :)

Well, I find a MSBuild Task in .Net SDK. We can use this target to hack apphost. We just need to change the AppBinaryName property. It should be executed after the task _CreateAppHost and before _ComputeNETCoreBuildOutputFiles.

  • _CreateAppHost will create an apphost.exe in obj folder.
  • _ComputeNETCoreBuildOutputFiles will move apphost.exe to output folder.
  <Target Name="_CreateAppHost_Hack" AfterTargets="_CreateAppHost">
    <CreateAppHost AppHostSourcePath="$(AppHostSourcePath)"
                   AppHostDestinationPath="$(AppHostIntermediatePath)"
                   AppBinaryName="$(AssemblyName)$(TargetExt)"
                   IntermediateAssembly="@(IntermediateAssembly->'%(FullPath)')"
                   WindowsGraphicalUserInterface="$(_UseWindowsGraphicalUserInterface)"
                   Retries="$(CopyRetryCount)"
                   RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
                   EnableMacOSCodeSign="$(_EnableMacOSCodeSign)"
                   />
  </Target>

My brain is churning.

frg2089 avatar Aug 26 '22 05:08 frg2089

I resignoff some commit at https://github.com/frg2089/xna-cncnet-client/commits/develop rebase that to remove Unverified tag. maybe.

use this command to signoff commit history.

git rebase --signoff <HASH>

frg2089 avatar Sep 02 '22 14:09 frg2089

Oh and also, I didn't see a clear way to specify what target runtime, 4.8 or 6.0, to compile for.

Metadorius avatar Sep 09 '22 19:09 Metadorius

LGTM on your front 😄

Metadorius avatar Sep 13 '22 20:09 Metadorius