Skip to content

Commit

Permalink
Migrate to .NET 4.8 + 8.0
Browse files Browse the repository at this point in the history
Co-Authored-By: Rans4ckeR <[email protected]>
Co-Authored-By: Kerbiter <[email protected]>
  • Loading branch information
3 people committed Feb 25, 2024
1 parent fbf4dec commit 7808d16
Show file tree
Hide file tree
Showing 57 changed files with 486 additions and 203 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.x.x'
dotnet-version: '8.x.x'

- name: Build ${{matrix.Game}}
run: ./BuildScripts/Build-${{matrix.Game}}.ps1
Expand Down
9 changes: 7 additions & 2 deletions BuildScripts/Build-Ares.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ param($Configuration = "Release")

. $PSScriptRoot\Common.ps1

Build-Project $Configuration Ares UniversalGL net7.0
$Game = "Ares"

Build-Project $Configuration $Game UniversalGL net8.0
if ($IsWindows) {
@('WindowsDX', 'WindowsGL', 'WindowsXNA') | ForEach-Object {
Build-Project $Configuration Ares $_ net7.0-windows
$Engine = $_
@('net48', 'net8.0-windows') | ForEach-Object {
Build-Project $Configuration $Game $Engine $_
}
}
}
9 changes: 7 additions & 2 deletions BuildScripts/Build-TS.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ param($Configuration = "Release")

. $PSScriptRoot\Common.ps1

Build-Project $Configuration TS UniversalGL net7.0
$Game = "TS"

Build-Project $Configuration $Game UniversalGL net8.0
if ($IsWindows) {
@('WindowsDX', 'WindowsGL', 'WindowsXNA') | ForEach-Object {
Build-Project $Configuration TS $_ net7.0-windows
$Engine = $_
@('net48', 'net8.0-windows') | ForEach-Object {
Build-Project $Configuration $Game $Engine $_
}
}
}
9 changes: 7 additions & 2 deletions BuildScripts/Build-YR.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ param($Configuration = "Release")

. $PSScriptRoot\Common.ps1

Build-Project $Configuration YR UniversalGL net7.0
$Game = "YR"

Build-Project $Configuration $Game UniversalGL net8.0
if ($IsWindows) {
@('WindowsDX', 'WindowsGL', 'WindowsXNA') | ForEach-Object {
Build-Project $Configuration YR $_ net7.0-windows
$Engine = $_
@('net48', 'net8.0-windows') | ForEach-Object {
Build-Project $Configuration $Game $Engine $_
}
}
}
16 changes: 8 additions & 8 deletions BuildScripts/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
$RepoRoot = Split-Path $PSScriptRoot -Parent
$ProjectPath = Join-Path $RepoRoot DXMainClient DXMainClient.csproj
$CompiledRoot = Join-Path $RepoRoot Compiled
$EngineMap = @{
$EngineSubFolderMap = @{
'UniversalGL' = 'UniversalGL'
'WindowsDX' = 'Windows'
'WindowsGL' = 'OpenGL'
'WindowsXNA' = 'XNA'
}
$FrameworkBinariesFolderMap = @{
'net48' = 'Binaries'
'net8.0' = 'BinariesNET8'
'net8.0-windows' = 'BinariesNET8'
}

function Build-Project($Configuration, $Game, $Engine, $Framework) {
$Output = Join-Path $CompiledRoot $Game $Output Resources Binaries ($EngineMap[$Engine])
if ($Engine -EQ 'WindowsXNA') {
dotnet publish $ProjectPath --configuration=$Configuration -property:GAME=$Game -property:ENGINE=$Engine --framework=$Framework --output=$Output --arch=x86
}
else {
dotnet publish $ProjectPath --configuration=$Configuration -property:GAME=$Game -property:ENGINE=$Engine --framework=$Framework --output=$Output
}
$Output = Join-Path $CompiledRoot $Game $Output Resources ($FrameworkBinariesFolderMap[$Framework]) ($EngineSubFolderMap[$Engine])
dotnet publish $ProjectPath -c $Configuration -p:GAME=$Game -p:ENGINE=$Engine -f $Framework -o $Output -p:SatelliteResourceLanguages=en -p:AssemblyVersion=$AssemblySemVer -p:FileVersion=$AssemblySemFileVer -p:InformationalVersion=$InformationalVersion $($Engine -EQ 'WindowsXNA' ? '--arch=x86' : '')
if ($LASTEXITCODE) {
throw "Build failed for $Game $Engine $Framework $Configuration"
}
Expand Down
4 changes: 2 additions & 2 deletions BuildScripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ TargetFramework configurations
For each Engine configuration one or more TargetFrameworks will be build:

UniversalGL:
* net7.0
* net8.0

WindowsDX, WindowsGL & WindowsXNA:
* net7.0-windows
* net48

Overview of the Engine configurations differences:

Expand Down
47 changes: 42 additions & 5 deletions ClientCore/ClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using ClientCore.I18N;
using ClientCore.Extensions;

Expand Down Expand Up @@ -283,7 +282,7 @@ private List<TranslationGameFile> ParseTranslationGameFiles()
{
// the syntax is GameFileX=path/to/source.file,path/to/destination.file[,checked]
string value = clientDefinitionsIni.GetStringValue(TRANSLATIONS, $"GameFile{i}", string.Empty);
string[] parts = value.Split(',', StringSplitOptions.TrimEntries);
string[] parts = value.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();

// fail explicitly if the syntax is wrong
if (parts.Length is < 2 or > 3
Expand Down Expand Up @@ -382,15 +381,53 @@ public IEnumerable<string> SupplementalMapFileExtensions

public OSVersion GetOperatingSystemVersion()
{
#if NETFRAMEWORK
// OperatingSystem.IsWindowsVersionAtLeast() is the preferred API but is not supported on earlier .NET versions
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
Version osVersion = Environment.OSVersion.Version;

if (osVersion.Major <= 4)
return OSVersion.UNKNOWN;

if (osVersion.Major == 5)
return OSVersion.WINXP;

if (osVersion.Major == 6 && osVersion.Minor == 0)
return OSVersion.WINVISTA;

if (osVersion.Major == 6 && osVersion.Minor <= 1)
return OSVersion.WIN7;

return OSVersion.WIN810;
}

if (ProgramConstants.ISMONO)
return OSVersion.UNIX;

// http://mono.wikia.com/wiki/Detecting_the_execution_platform
int p = (int)Environment.OSVersion.Platform;
if (p == 4 || p == 6 || p == 128)
return OSVersion.UNIX;

return OSVersion.UNKNOWN;
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
if (OperatingSystem.IsWindowsVersionAtLeast(6, 3))
if (OperatingSystem.IsWindowsVersionAtLeast(6, 2))
return OSVersion.WIN810;

return OSVersion.WIN7;
else if (OperatingSystem.IsWindowsVersionAtLeast(6, 1))
return OSVersion.WIN7;
else if (OperatingSystem.IsWindowsVersionAtLeast(6, 0))
return OSVersion.WINVISTA;
else if (OperatingSystem.IsWindowsVersionAtLeast(5, 0))
return OSVersion.WINXP;
else
return OSVersion.UNKNOWN;
}

return OSVersion.UNIX;
#endif
}
}

Expand Down
10 changes: 6 additions & 4 deletions ClientCore/ClientCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>CnCNet Client Core Library</Description>
<Company>CnCNet</Company>
<Product>CnCNet Client</Product>
<Copyright>Copyright © CnCNet, Rampastring 2011-2022</Copyright>
<Copyright>Copyright © CnCNet, Rampastring 2011-2024</Copyright>
<Trademark>CnCNet</Trademark>
<Version>2.0.0.3</Version>
<FileVersion>2.0.0.3</FileVersion>
Expand Down Expand Up @@ -50,9 +50,11 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Rampastring.Tools" Version="2.0.4" />
<PackageReference Include="Rampastring.XNAUI.$(Engine)" Version="2.3.8" Condition="'!$(Configuration.Contains(Debug))'" />
<PackageReference Include="Rampastring.XNAUI.$(Engine).Debug" Version="2.3.8" Condition="'$(Configuration.Contains(Debug))'" />
<!-- TODO: update version after this package targets .NET 8. -->
<PackageReference Include="Rampastring.Tools" Version="2.0.6-local-397fda5" />
<!-- TODO: update version after this package targets .NET 8. -->
<PackageReference Include="Rampastring.XNAUI.$(Engine)" Version="2.3.20-local-2c977ab" Condition="'!$(Configuration.Contains(Debug))'" />
<PackageReference Include="Rampastring.XNAUI.$(Engine).Debug" Version="2.3.20-local-2c977ab" Condition="'$(Configuration.Contains(Debug))'" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down
14 changes: 7 additions & 7 deletions ClientCore/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public static string ToIniString(this string raw)
throw new ArgumentException($"The string contains an illegal character sequence! ({ESCAPED_SEMICOLON})");

return raw
.Replace(ProgramConstants.INI_NEWLINE_PATTERN, ESCAPED_INI_NEWLINE_PATTERN, StringComparison.InvariantCulture)
.Replace(";", ESCAPED_SEMICOLON, StringComparison.InvariantCulture)
.Replace(Environment.NewLine, "\n", StringComparison.InvariantCulture)
.Replace("\n", ProgramConstants.INI_NEWLINE_PATTERN, StringComparison.InvariantCulture);
.Replace(ProgramConstants.INI_NEWLINE_PATTERN, ESCAPED_INI_NEWLINE_PATTERN)
.Replace(";", ESCAPED_SEMICOLON)
.Replace(Environment.NewLine, "\n")
.Replace("\n", ProgramConstants.INI_NEWLINE_PATTERN);
}

/// <summary>
Expand All @@ -54,9 +54,9 @@ public static string ToIniString(this string raw)
public static string FromIniString(this string iniString)
{
return iniString
.Replace(ESCAPED_INI_NEWLINE_PATTERN, ProgramConstants.INI_NEWLINE_PATTERN, StringComparison.InvariantCulture)
.Replace(ESCAPED_SEMICOLON, ";", StringComparison.InvariantCulture)
.Replace(ProgramConstants.INI_NEWLINE_PATTERN, Environment.NewLine, StringComparison.InvariantCulture);
.Replace(ESCAPED_INI_NEWLINE_PATTERN, ProgramConstants.INI_NEWLINE_PATTERN)
.Replace(ESCAPED_SEMICOLON, ";")
.Replace(ProgramConstants.INI_NEWLINE_PATTERN, Environment.NewLine);
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion ClientCore/I18N/Translation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public Translation(string localeCode)
public Translation(IniFile ini, string localeCode)
: this(localeCode)
{
ArgumentNullException.ThrowIfNull(ini);
if (ini is null)
throw new ArgumentNullException(nameof(ini));

IniSection metadataSection = ini.GetSection(METADATA_SECTION);
Name = metadataSection?.GetStringValue(nameof(Name), string.Empty);
Expand Down
58 changes: 52 additions & 6 deletions ClientCore/ProgramConstants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Reflection;
#if WINFORMS
Expand All @@ -20,11 +21,7 @@ public static class ProgramConstants

public static readonly string StartupPath = SafePath.CombineDirectoryPath(new FileInfo(StartupExecutable).Directory.FullName);

#if DEBUG
public static readonly string GamePath = SafePath.CombineDirectoryPath(SafePath.GetDirectory(StartupPath).Parent.Parent.FullName);
#else
public static readonly string GamePath = SafePath.CombineDirectoryPath(SafePath.GetDirectory(StartupPath).Parent.Parent.Parent.FullName);
#endif
public static readonly string GamePath = SafePath.CombineDirectoryPath(GetGamePath(StartupPath));

public static string ClientUserFilesPath => SafePath.CombineDirectoryPath(GamePath, "Client");

Expand Down Expand Up @@ -62,6 +59,15 @@ public static class ProgramConstants

public static readonly Encoding LAN_ENCODING = Encoding.UTF8;

#if NETFRAMEWORK
private static bool? isMono;

/// <summary>
/// Gets a value whether or not the application is running under Mono. Uses lazy loading and caching.
/// </summary>
public static bool ISMONO => isMono ??= Type.GetType("Mono.Runtime") != null;
#endif

public static string GAME_VERSION = "Undefined";
private static string PlayerName = "No name";

Expand Down Expand Up @@ -115,17 +121,57 @@ public static string GetAILevelName(int aiLevel)
/// <summary>
/// Gets or sets the action to perform to notify the user of an error.
/// </summary>
public static Action<string, string, bool> DisplayErrorAction { get; set; } = (title, error, exit) =>
public static Action<string, string, bool> DisplayErrorAction { get; set; } = DefaultDisplayErrorAction;

public static Action<string, string, bool> DefaultDisplayErrorAction = (title, error, exit) =>
{
Logger.Log(FormattableString.Invariant($"{(title is null ? null : title + Environment.NewLine + Environment.NewLine)}{error}"));
#if WINFORMS
#if NETFRAMEWORK
MessageBox.Show(error, title, MessageBoxButtons.OK);
#else
TaskDialog.ShowDialog(new() { Caption = title, Heading = error });
#endif
#else
ProcessLauncher.StartShellProcess(LogFileName);
#endif

if (exit)
Environment.Exit(1);
};

/// <summary>
/// This method finds the "Resources" directory by traversing the directory tree upwards from the startup path.
/// </summary>
/// <remarks>
/// This method is needed by both ClientCore and DXMainClient. However, since it is usually called at the very beginning,
/// where DXMainClient could not refer to ClientCore, this method is copied to both projects.
/// Remember to keep <see cref="ClientCore.ProgramConstants.SearchResourcesDir"/> and <see cref="DTAClient.Program.SearchResourcesDir"/> consistent if you have modified its source codes.
/// </remarks>
private static string SearchResourcesDir(string startupPath)
{
DirectoryInfo currentDir = new(startupPath);
for (int i = 0; i < 3; i++)
{
// Determine if currentDir is the "Resources" folder
if (currentDir.Name.ToLowerInvariant() == "Resources".ToLowerInvariant())
return currentDir.FullName;

// Additional check. This makes developers to debug the client inside Visual Studio a little bit easier.
DirectoryInfo resourcesDir = currentDir.GetDirectories("Resources", SearchOption.TopDirectoryOnly).FirstOrDefault();
if (resourcesDir is not null)
return resourcesDir.FullName;

currentDir = currentDir.Parent;
}

throw new Exception("Could not find Resources directory.");
}

private static string GetGamePath(string startupPath)
{
string resourceDir = SearchResourcesDir(startupPath);
return new DirectoryInfo(resourceDir).Parent.FullName;
}
}
}
2 changes: 1 addition & 1 deletion ClientGUI/ClientGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>CnCNet Client UI Library</Description>
<Company>CnCNet</Company>
<Product>CnCNet Client</Product>
<Copyright>Copyright © CnCNet, Rampastring 2011-2022</Copyright>
<Copyright>Copyright © CnCNet, Rampastring 2011-2024</Copyright>
<Trademark>CnCNet</Trademark>
<Version>2.1.0.1</Version>
<FileVersion>2.1.0.1</FileVersion>
Expand Down
4 changes: 3 additions & 1 deletion ClientGUI/GameProcessLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static void StartGameProcess(WindowManager windowManager)
Logger.Log("Windowed mode is enabled - using QRes.");
Process QResProcess = new Process();
QResProcess.StartInfo.FileName = ProgramConstants.QRES_EXECUTABLE;
QResProcess.StartInfo.UseShellExecute = false;

if (!string.IsNullOrEmpty(extraCommandLine))
QResProcess.StartInfo.Arguments = "c=16 /R " + "\"" + SafePath.CombineFilePath(ProgramConstants.GamePath, gameExecutableName) + "\" " + additionalExecutableName + "-SPAWN " + extraCommandLine;
Expand Down Expand Up @@ -119,6 +120,7 @@ public static void StartGameProcess(WindowManager windowManager)
var gameProcess = new Process();
gameProcess.StartInfo.FileName = gameFileInfo.FullName;
gameProcess.StartInfo.Arguments = arguments;
gameProcess.StartInfo.UseShellExecute = false;

gameProcess.EnableRaisingEvents = true;
gameProcess.Exited += Process_Exited;
Expand All @@ -144,7 +146,7 @@ public static void StartGameProcess(WindowManager windowManager)
if ((RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
&& Environment.ProcessorCount > 1 && SingleCoreAffinity)
{
gameProcess.ProcessorAffinity = 2;
gameProcess.ProcessorAffinity = (IntPtr)2;
}
}

Expand Down
4 changes: 2 additions & 2 deletions DTAConfig/DTAConfig.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>CnCNet Config Library</Description>
<Company>CnCNet</Company>
<Product>CnCNet Client</Product>
<Copyright>Copyright © CnCNet, Rampastring 2011-2022</Copyright>
<Copyright>Copyright © CnCNet, Rampastring 2011-2024</Copyright>
<Trademark>CnCNet</Trademark>
<Version>2.2.0.0</Version>
<FileVersion>2.2.0.0</FileVersion>
Expand All @@ -14,7 +14,7 @@
</PropertyGroup>
<Import Project="$(MSBuildThisFileDirectory)..\build\WinForms.props" />
<ItemGroup>
<PackageReference Include="CnCNet.ClientUpdater" Version="1.0.15" />
<PackageReference Include="CnCNet.ClientUpdater" Version="1.0.16" />
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 2 additions & 0 deletions DXMainClient/DXGUI/Generic/ExtrasWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ private void BtnExMapEditor_LeftClick(object sender, EventArgs e)
else
mapEditorProcess.StartInfo.FileName = SafePath.CombineFilePath(ProgramConstants.GamePath, ClientConfiguration.Instance.UnixMapEditorExePath);

mapEditorProcess.StartInfo.UseShellExecute = false;

mapEditorProcess.Start();

Enabled = false;
Expand Down
Loading

0 comments on commit 7808d16

Please sign in to comment.