Skip to content

Commit

Permalink
Merge pull request #616 from CnCNet/develop
Browse files Browse the repository at this point in the history
2.11.6.0
  • Loading branch information
SadPencil authored Jan 4, 2025
2 parents f6b6b48 + ff5f14c commit 95d43c2
Show file tree
Hide file tree
Showing 22 changed files with 282 additions and 64 deletions.
21 changes: 21 additions & 0 deletions ClientCore/ClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ private List<TranslationGameFile> ParseTranslationGameFiles()

public string AllowedCustomGameModes => clientDefinitionsIni.GetStringValue(SETTINGS, "AllowedCustomGameModes", "Standard,Custom Map");

public string SkillLevelOptions => clientDefinitionsIni.GetStringValue(SETTINGS, "SkillLevelOptions", "Any,Beginner,Intermediate,Pro");

public string GetGameExecutableName()
{
string[] exeNames = clientDefinitionsIni.GetStringValue(SETTINGS, "GameExecutableNames", "Game.exe").Split(',');
Expand Down Expand Up @@ -422,6 +424,25 @@ public IEnumerable<string> SupplementalMapFileExtensions

#endregion

#region Game networking defaults

/// <summary>
/// Default value for FrameSendRate setting written in spawn.ini.
/// </summary>
public int DefaultFrameSendRate => clientDefinitionsIni.GetIntValue(SETTINGS, nameof(DefaultFrameSendRate), 7);

/// <summary>
/// Default value for Protocol setting written in spawn.ini.
/// </summary>
public int DefaultProtocolVersion => clientDefinitionsIni.GetIntValue(SETTINGS, nameof(DefaultProtocolVersion), 2);

/// <summary>
/// Default value for MaxAhead setting written in spawn.ini.
/// </summary>
public int DefaultMaxAhead => clientDefinitionsIni.GetIntValue(SETTINGS, nameof(DefaultMaxAhead), 0);

#endregion

public List<string> GetIRCServers()
{
List<string> servers = [];
Expand Down
26 changes: 13 additions & 13 deletions ClientCore/CnCNet5/GameCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void Initialize()
GameBroadcastChannel = "#cncnet-dta-games",
InternalName = "dta",
RegistryInstallPath = "HKCU\\Software\\TheDawnOfTheTiberiumAge",
UIName = "Dawn of the Tiberium Age".L10N("Client:Core:DawnoftheTiberiumAge"),
UIName = "Dawn of the Tiberium Age".L10N("Client:ClientCore:DawnoftheTiberiumAge"),
Texture = AssetLoader.TextureFromImage(dtaIcon)
},

Expand All @@ -77,7 +77,7 @@ public void Initialize()
GameBroadcastChannel = "#cncnet-ti-games",
InternalName = "ti",
RegistryInstallPath = "HKCU\\Software\\TwistedInsurrection",
UIName = "Twisted Insurrection".L10N("Client:Core:TwistedInsurrection"),
UIName = "Twisted Insurrection".L10N("Client:ClientCore:TwistedInsurrection"),
Texture = AssetLoader.TextureFromImage(tiIcon)
},

Expand All @@ -88,7 +88,7 @@ public void Initialize()
GameBroadcastChannel = "#cncnet-mo-games",
InternalName = "mo",
RegistryInstallPath = "HKCU\\Software\\MentalOmega",
UIName = "Mental Omega".L10N("Client:Core:MentalOmega"),
UIName = "Mental Omega".L10N("Client:ClientCore:MentalOmega"),
Texture = AssetLoader.TextureFromImage(moIcon)
},

Expand All @@ -99,7 +99,7 @@ public void Initialize()
GameBroadcastChannel = "#redres-games",
InternalName = "rr",
RegistryInstallPath = "HKLM\\Software\\RedResurrection",
UIName = "YR Red-Resurrection".L10N("Client:Core:YRRedResurrection"),
UIName = "YR Red-Resurrection".L10N("Client:ClientCore:YRRedResurrection"),
Texture = AssetLoader.TextureFromImage(rrIcon)
},

Expand All @@ -110,7 +110,7 @@ public void Initialize()
GameBroadcastChannel = "#rote-games",
InternalName = "re",
RegistryInstallPath = "HKLM\\Software\\RiseoftheEast",
UIName = "Rise of the East".L10N("Client:Core:RiseoftheEast"),
UIName = "Rise of the East".L10N("Client:ClientCore:RiseoftheEast"),
Texture = AssetLoader.TextureFromImage(reIcon)
},

Expand All @@ -121,7 +121,7 @@ public void Initialize()
GameBroadcastChannel = "#cncreloaded-games",
InternalName = "cncr",
RegistryInstallPath = "HKCU\\Software\\CnCReloaded",
UIName = "C&C: Reloaded".L10N("Client:Core:CnCReloaded"),
UIName = "C&C: Reloaded".L10N("Client:ClientCore:CnCReloaded"),
Texture = AssetLoader.TextureFromImage(cncrIcon)
},

Expand All @@ -132,7 +132,7 @@ public void Initialize()
GameBroadcastChannel = "#cncnet-td-games",
InternalName = "td",
RegistryInstallPath = "HKLM\\Software\\Westwood\\Tiberian Dawn",
UIName = "Tiberian Dawn".L10N("Client:Core:TiberianDawn"),
UIName = "Tiberian Dawn".L10N("Client:ClientCore:TiberianDawn"),
Texture = AssetLoader.TextureFromImage(tdIcon),
Supported = false
},
Expand All @@ -144,7 +144,7 @@ public void Initialize()
GameBroadcastChannel = "#cncnet-ra-games",
InternalName = "ra",
RegistryInstallPath = "HKLM\\Software\\Westwood\\Red Alert",
UIName = "Red Alert".L10N("Client:Core:RedAlert"),
UIName = "Red Alert".L10N("Client:ClientCore:RedAlert"),
Texture = AssetLoader.TextureFromImage(raIcon),
Supported = false
},
Expand All @@ -156,7 +156,7 @@ public void Initialize()
GameBroadcastChannel = "#cncnet-d2k-games",
InternalName = "d2k",
RegistryInstallPath = "HKLM\\Software\\Westwood\\Dune 2000",
UIName = "Dune 2000".L10N("Client:Core:Dune2000"),
UIName = "Dune 2000".L10N("Client:ClientCore:Dune2000"),
Texture = AssetLoader.TextureFromImage(d2kIcon),
Supported = false
},
Expand All @@ -168,7 +168,7 @@ public void Initialize()
GameBroadcastChannel = "#cncnet-ts-games",
InternalName = "ts",
RegistryInstallPath = "HKLM\\Software\\Westwood\\Tiberian Sun",
UIName = "Tiberian Sun".L10N("Client:Core:TiberianSun"),
UIName = "Tiberian Sun".L10N("Client:ClientCore:TiberianSun"),
Texture = AssetLoader.TextureFromImage(tsIcon)
},

Expand All @@ -179,7 +179,7 @@ public void Initialize()
GameBroadcastChannel = "#cncnet-yr-games",
InternalName = "yr",
RegistryInstallPath = "HKLM\\Software\\Westwood\\Yuri's Revenge",
UIName = "Yuri's Revenge".L10N("Client:Core:YurisRevenge"),
UIName = "Yuri's Revenge".L10N("Client:ClientCore:YurisRevenge"),
Texture = AssetLoader.TextureFromImage(yrIcon)
},

Expand All @@ -190,7 +190,7 @@ public void Initialize()
GameBroadcastChannel = "#cncnet-ss-games",
InternalName = "ss",
RegistryInstallPath = "HKLM\\Software\\Westwood\\Sole Survivor",
UIName = "Sole Survivor".L10N("Client:Core:SoleSurvivor"),
UIName = "Sole Survivor".L10N("Client:ClientCore:SoleSurvivor"),
Texture = AssetLoader.TextureFromImage(ssIcon),
Supported = false
}
Expand All @@ -203,7 +203,7 @@ public void Initialize()
{
ChatChannel = "#cncnet",
InternalName = "cncnet",
UIName = "General CnCNet Chat".L10N("Client:Core:GeneralCnCNetChat"),
UIName = "General CnCNet Chat".L10N("Client:ClientCore:GeneralCnCNetChat"),
AlwaysEnabled = true,
Texture = AssetLoader.TextureFromImage(cncnetIcon)
}
Expand Down
2 changes: 1 addition & 1 deletion ClientCore/ProgramConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class ProgramConstants

public const string QRES_EXECUTABLE = "qres.dat";

public const string CNCNET_PROTOCOL_REVISION = "R11";
public const string CNCNET_PROTOCOL_REVISION = "R12";
public const string LAN_PROTOCOL_REVISION = "RL7";
public const int LAN_PORT = 1234;
public const int LAN_INGAME_PORT = 1234;
Expand Down
5 changes: 5 additions & 0 deletions ClientUpdater/CustomComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ namespace ClientUpdater;
using System.Net.Http.Handlers;
using System.Threading;
using System.Threading.Tasks;

using ClientUpdater.Compression;

using Rampastring.Tools;

/// <summary>
Expand Down Expand Up @@ -377,7 +379,10 @@ private void CleanUpAfterDownload()
foreach (string filename in filesToCleanup)
{
if (File.Exists(filename))
{
new FileInfo(filename).IsReadOnly = false;
File.Delete(filename);
}
}
}
catch (Exception)
Expand Down
83 changes: 67 additions & 16 deletions ClientUpdater/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ namespace ClientUpdater;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using ClientUpdater.Compression;

using Rampastring.Tools;

public static class Updater
Expand Down Expand Up @@ -429,6 +431,8 @@ internal static void DeleteFileAndWait(string filepath, int timeout = 10000)
{
mre.Set();
};
if (fileInfo.Exists)
fileInfo.IsReadOnly = false;
fileInfo.Delete();
mre.Wait(timeout);
}
Expand Down Expand Up @@ -613,15 +617,15 @@ private static async Task DoVersionCheckAsync()

UpdateUserAgent(SharedHttpClient);

FileInfo downloadFile = SafePath.GetFile(GamePath, FormattableString.Invariant($"{VERSION_FILE}_u"));
FileInfo versionFile = SafePath.GetFile(GamePath, FormattableString.Invariant($"{VERSION_FILE}_u"));

while (currentUpdateMirrorIndex < updateMirrors.Count)
{
try
{
Logger.Log("Updater: Trying to connect to update mirror " + updateMirrors[currentUpdateMirrorIndex].URL);

FileStream fileStream = new FileStream(downloadFile.FullName, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);
FileStream fileStream = new FileStream(versionFile.FullName, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);

using (fileStream)
{
Expand Down Expand Up @@ -650,7 +654,7 @@ private static async Task DoVersionCheckAsync()
}

Logger.Log("Updater: Downloaded version information.");
var version = new IniFile(downloadFile.FullName);
var version = new IniFile(versionFile.FullName);
string versionString = version.GetStringValue("DTA", "Version", string.Empty);
string updaterVersionString = version.GetStringValue("DTA", "UpdaterVersion", "N/A");
string manualDownloadURLString = version.GetStringValue("DTA", "ManualDownloadURL", string.Empty);
Expand Down Expand Up @@ -722,7 +726,7 @@ private static async Task DoVersionCheckAsync()
if (versionString == GameVersion)
{
VersionState = VersionState.UPTODATE;
downloadFile.Delete();
versionFile.Delete();
DoFileIdentifiersUpdatedEvent();

if (AreCustomComponentsOutdated())
Expand All @@ -736,7 +740,7 @@ private static async Task DoVersionCheckAsync()
VersionState = VersionState.OUTDATED;
ManualUpdateRequired = true;
ManualDownloadURL = manualDownloadURLString;
downloadFile.Delete();
versionFile.Delete();
DoFileIdentifiersUpdatedEvent();
}
else
Expand Down Expand Up @@ -779,7 +783,7 @@ private static async ValueTask ExecuteAfterUpdateScriptAsync()
try
{
string downloadFile = SafePath.CombineFilePath(GamePath, "updateexec");

FileStream fileStream = new FileStream(downloadFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);

using (fileStream)
Expand Down Expand Up @@ -811,7 +815,7 @@ private static async ValueTask<bool> ExecutePreUpdateScriptAsync()
try
{
string downloadFile = SafePath.CombineFilePath(GamePath, "preupdateexec");

FileStream fileStream = new FileStream(downloadFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);

using (fileStream)
Expand Down Expand Up @@ -851,7 +855,13 @@ private static void ExecuteScript(string fileName)

try
{
SafePath.DeleteFileIfExists(GamePath, key);
FileInfo fileInfo = SafePath.GetFile(GamePath, key);

if (fileInfo.Exists)
{
fileInfo.IsReadOnly = false;
fileInfo.Delete();
}
}
catch (Exception ex)
{
Expand All @@ -869,10 +879,30 @@ private static void ExecuteScript(string fileName)
{
Logger.Log("Updater: " + fileName + ": Renaming file '" + key + "' to '" + newFilename + "'");

FileInfo file = SafePath.GetFile(GamePath, key);
FileInfo srcFile = SafePath.GetFile(GamePath, key);

if (srcFile.Exists)
{
bool isSrcReadOnly = srcFile.IsReadOnly;
srcFile.IsReadOnly = false;

{
FileInfo destFile = SafePath.GetFile(GamePath, newFilename);
if (destFile.Exists)
{
destFile.IsReadOnly = false;
destFile.Delete();
}
}

srcFile.MoveTo(SafePath.CombineFilePath(GamePath, newFilename));

if (file.Exists)
file.MoveTo(SafePath.CombineFilePath(GamePath, newFilename));
if (isSrcReadOnly)
{
FileInfo destFile = SafePath.GetFile(GamePath, newFilename);
destFile.IsReadOnly = true;
}
}
}
catch (Exception ex)
{
Expand All @@ -890,10 +920,10 @@ private static void ExecuteScript(string fileName)
{
Logger.Log("Updater: " + fileName + ": Renaming directory '" + key + "' to '" + newDirectoryName + "'");

DirectoryInfo directory = SafePath.GetDirectory(GamePath, key);
DirectoryInfo srcDirectory = SafePath.GetDirectory(GamePath, key);

if (directory.Exists)
directory.MoveTo(SafePath.CombineDirectoryPath(GamePath, newDirectoryName));
if (srcDirectory.Exists)
srcDirectory.MoveTo(SafePath.CombineDirectoryPath(GamePath, newDirectoryName));
}
catch (Exception ex)
{
Expand Down Expand Up @@ -928,18 +958,29 @@ private static void ExecuteScript(string fileName)
FileInfo[] files = gameDirectory.GetFiles();
foreach (FileInfo file in files)
{
bool isSrcReadOnly = file.IsReadOnly;
file.IsReadOnly = false;

FileInfo fileToMergeInto = SafePath.GetFile(directoryToMergeInto.FullName, file.Name);
if (fileToMergeInto.Exists)
{
Logger.Log("Updater: " + fileName + ": Destination file '" + directoryNameToMergeInto + "/" + file.Name +
"' exists, removing original source file " + directoryName + "/" + file.Name);
fileToMergeInto.Delete();

// Note: Previously, the incorrect file was deleted as of commit fc939a06ff978b51daa6563eaa15a28cf48319ec.

// Remove the original source file
file.Delete();
}
else
{
Logger.Log("Updater: " + fileName + ": Destination file '" + directoryNameToMergeInto + "/" + file.Name +
"' does not exist, moving original source file " + directoryName + "/" + file.Name);
file.MoveTo(fileToMergeInto.FullName);

// Resume the read-only property
fileToMergeInto.Refresh();
fileToMergeInto.IsReadOnly = isSrcReadOnly;
}
}
}
Expand All @@ -959,7 +1000,17 @@ private static void ExecuteScript(string fileName)
{
Logger.Log("Updater: " + fileName + ": Deleting directory '" + key + "'");

SafePath.DeleteDirectoryIfExists(true, GamePath, key);
DirectoryInfo directoryInfo = SafePath.GetDirectory(GamePath, key);
if (directoryInfo.Exists)
{
// Unset read-only attribute from all files in the directory.
foreach (FileInfo file in directoryInfo.GetFiles("*", SearchOption.AllDirectories))
{
file.IsReadOnly = false;
}

directoryInfo.Delete(true);
}
}
catch (Exception ex)
{
Expand Down
1 change: 1 addition & 0 deletions DTAConfig/OptionPanels/ComponentsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private void Btn_LeftClick(object sender, EventArgs e)
{
if (cc.LocalIdentifier == cc.RemoteIdentifier)
{
localFileInfo.IsReadOnly = false;
localFileInfo.Delete();
btn.Text = "Install".L10N("Client:DTAConfig:Install") + $" ({GetSizeString(cc.RemoteSize)})";
return;
Expand Down
Loading

0 comments on commit 95d43c2

Please sign in to comment.