Skip to content

Commit

Permalink
Add support for multiple game executable names
Browse files Browse the repository at this point in the history
  • Loading branch information
Rampastring committed Dec 18, 2024
1 parent 09673d7 commit e1a2a01
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/TSMapEditor/Config/Constants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ TerrainPaletteBuildingsAffectedByLighting=true
; Should voxel models be affected by map lighting?
VoxelsAffectedByLighting=false

; The file name of the executable that the map editor expects to find from the game directory.
; The file name(s) of the executable file(s) that the map editor tries to find from the game directory.
; Used for the verification that the user has given us the correct game directory.
; You can input multiple executable names by separating them with a comma (,).
ExpectedClientExecutableName=DTA.exe

; Specifies the path(s) that we should check in the Windows registry to determine
Expand Down
9 changes: 7 additions & 2 deletions src/TSMapEditor/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class Constants
public static bool WarnOfTooManyTriggerActions = true;
public static bool DefaultPreview = false;

public static string ExpectedClientExecutableName = "DTA.exe";
public static string[] ExpectedClientExecutableNames = new string[] { "DTA.exe" };
public static string GameRegistryInstallPath = "SOFTWARE\\DawnOfTheTiberiumAge";
public static string OpenFileDialogFilter = "TS maps|*.map|All files|*.*";

Expand Down Expand Up @@ -143,7 +143,12 @@ public static void Init()
WarnOfTooManyTriggerActions = constantsIni.GetBooleanValue(ConstantsSectionName, nameof(WarnOfTooManyTriggerActions), WarnOfTooManyTriggerActions);
DefaultPreview = constantsIni.GetBooleanValue(ConstantsSectionName, nameof(DefaultPreview), DefaultPreview);

ExpectedClientExecutableName = constantsIni.GetStringValue(ConstantsSectionName, nameof(ExpectedClientExecutableName), ExpectedClientExecutableName);
// Check two keys for backwards compatibility
if (constantsIni.KeyExists(ConstantsSectionName, "ExpectedClientExecutableName"))
ExpectedClientExecutableNames = constantsIni.GetSection(ConstantsSectionName).GetListValue("ExpectedClientExecutableName", ',', s => s).ToArray();
else
ExpectedClientExecutableNames = constantsIni.GetSection(ConstantsSectionName).GetListValue(nameof(ExpectedClientExecutableNames), ',', s => s).ToArray();

GameRegistryInstallPath = constantsIni.GetStringValue(ConstantsSectionName, nameof(GameRegistryInstallPath), GameRegistryInstallPath);
OpenFileDialogFilter = constantsIni.GetStringValue(ConstantsSectionName, nameof(OpenFileDialogFilter), OpenFileDialogFilter);

Expand Down
2 changes: 1 addition & 1 deletion src/TSMapEditor/Models/ArtConfig/VehicleArtConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void ReadFromIniSection(IniSection iniSection)

// Hackity hackity hack hack
// In DTA WalkFrames defaults to 1 instead of 15
if (Constants.ExpectedClientExecutableName == "DTA.exe")
if (Constants.ExpectedClientExecutableNames[0] == "DTA.exe")
WalkFrames = 1;

WalkFrames = iniSection.GetIntValue(nameof(WalkFrames), WalkFrames);
Expand Down
34 changes: 27 additions & 7 deletions src/TSMapEditor/UI/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public override void Initialize()

#if DEBUG
// When debugging we might often switch between configs - make it a bit more convenient
string expectedPath = Path.Combine(tbGameDirectory.Text, Constants.ExpectedClientExecutableName);
if (!File.Exists(expectedPath))
if (!VerifyGameDirectory())
{
ReadGameInstallDirectoryFromRegistry();
}
Expand Down Expand Up @@ -304,8 +303,14 @@ private void ReadGameInstallDirectoryFromRegistry()
tbGameDirectory.Text = valueAsString;
}

if (File.Exists(Path.Combine(tbGameDirectory.Text, Constants.ExpectedClientExecutableName)))
isValid = true;
foreach (string expectedExecutableName in Constants.ExpectedClientExecutableNames)
{
if (File.Exists(Path.Combine(tbGameDirectory.Text, expectedExecutableName)))
{
isValid = true;
break;
}
}
}

key.Close();
Expand All @@ -332,13 +337,28 @@ private void LbFileList_FileDoubleLeftClick(object sender, EventArgs e)
BtnLoad_LeftClick(this, EventArgs.Empty);
}

private bool VerifyGameDirectory()
{
bool gameDirectoryVerified = false;
foreach (string expectedExecutableName in Constants.ExpectedClientExecutableNames)
{
if (File.Exists(Path.Combine(tbGameDirectory.Text, expectedExecutableName)))
{
gameDirectoryVerified = true;
break;
}
}

return gameDirectoryVerified;
}

private bool CheckGameDirectory()
{
if (!File.Exists(Path.Combine(tbGameDirectory.Text, Constants.ExpectedClientExecutableName)))
if (!VerifyGameDirectory())
{
EditorMessageBox.Show(WindowManager,
"Invalid game directory",
$"{Constants.ExpectedClientExecutableName} not found, please check that you typed the correct game directory.",
$"{Constants.ExpectedClientExecutableNames[0]} not found, please check that you typed the correct game directory.",
MessageBoxButtons.OK);

return false;
Expand Down Expand Up @@ -376,7 +396,7 @@ private void BtnBrowseGameDirectory_LeftClick(object sender, EventArgs e)
{
openFileDialog.InitialDirectory = tbGameDirectory.Text;
openFileDialog.Filter =
$"Game executable|{Constants.ExpectedClientExecutableName}";
$"Game executable|{string.Join(';', Constants.ExpectedClientExecutableNames)}";
openFileDialog.RestoreDirectory = true;

if (openFileDialog.ShowDialog() == DialogResult.OK)
Expand Down

0 comments on commit e1a2a01

Please sign in to comment.