Verify that the launched exe belongs to the selected content package, and if not, ask if the player wants to relaunch with the correct exe. Closes #955

This commit is contained in:
Joonas Rikkonen
2018-12-02 17:41:21 +02:00
parent 6695c733a7
commit 1c1fe3a161
5 changed files with 53 additions and 2 deletions
@@ -11,6 +11,7 @@ using System.Diagnostics;
using System.Reflection; using System.Reflection;
using GameAnalyticsSDK.Net; using GameAnalyticsSDK.Net;
using System.Threading; using System.Threading;
using System.IO;
namespace Barotrauma namespace Barotrauma
{ {
@@ -386,6 +387,8 @@ namespace Barotrauma
LocationType.Init(); LocationType.Init();
MainMenuScreen.Select(); MainMenuScreen.Select();
CheckContentPackage();
TitleScreen.LoadState = 100.0f; TitleScreen.LoadState = 100.0f;
hasLoaded = true; hasLoaded = true;
if (GameSettings.VerboseLogging) if (GameSettings.VerboseLogging)
@@ -396,6 +399,27 @@ namespace Barotrauma
} }
private void CheckContentPackage()
{
var exePaths = Config.SelectedContentPackage.GetFilesOfType(ContentType.Executable);
if (exePaths.Count > 0 && AppDomain.CurrentDomain.FriendlyName != exePaths[0])
{
var msgBox = new GUIMessageBox(TextManager.Get("Error"),
TextManager.Get("IncorrectExe")
.Replace("[selectedpackage]", Config.SelectedContentPackage.Name)
.Replace("[exename]", exePaths[0]),
new string[] { TextManager.Get("Yes"), TextManager.Get("No") });
msgBox.Buttons[0].OnClicked += (_, userdata) =>
{
string fullPath = Path.GetFullPath(exePaths[0]);
Process.Start(fullPath);
Exit();
return true;
};
msgBox.Buttons[1].OnClicked = msgBox.Close;
}
}
/// <summary> /// <summary>
/// UnloadContent will be called once per game and is the place to unload /// UnloadContent will be called once per game and is the place to unload
/// all content. /// all content.
@@ -5,6 +5,7 @@ using Microsoft.Xna.Framework;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using System.Xml.Linq; using System.Xml.Linq;
@@ -101,6 +102,29 @@ namespace Barotrauma
Screen.SelectNull(); Screen.SelectNull();
NetLobbyScreen = new NetLobbyScreen(); NetLobbyScreen = new NetLobbyScreen();
CheckContentPackage();
}
private void CheckContentPackage()
{
var exePaths = Config.SelectedContentPackage.GetFilesOfType(ContentType.ServerExecutable);
if (exePaths.Count > 0 && AppDomain.CurrentDomain.FriendlyName != exePaths[0])
{
DebugConsole.ShowQuestionPrompt(TextManager.Get("IncorrectExe")
.Replace("[selectedpackage]", Config.SelectedContentPackage.Name)
.Replace("[exename]", exePaths[0]),
(option) =>
{
if (option.ToLower() == "y" || option.ToLower() == "yes")
{
string fullPath = Path.GetFullPath(exePaths[0]);
Process.Start(fullPath);
ShouldRun = false;
}
});
}
} }
public void StartServer() public void StartServer()
@@ -44,6 +44,7 @@
<ApplySettingsNo>Discard</ApplySettingsNo> <ApplySettingsNo>Discard</ApplySettingsNo>
<RestartRequiredLabel>Restart required</RestartRequiredLabel> <RestartRequiredLabel>Restart required</RestartRequiredLabel>
<RestartRequiredText>You need to restart the game for the resolution changes to take effect.</RestartRequiredText> <RestartRequiredText>You need to restart the game for the resolution changes to take effect.</RestartRequiredText>
<IncorrectExe>The executable you've launched is not present in the content package [selectedpackage]. Do you want to launch [exename]?</IncorrectExe>
<!-- Round summary --> <!-- Round summary -->
<RoundSummaryProgress>[sub] has made its way to [location].</RoundSummaryProgress> <RoundSummaryProgress>[sub] has made its way to [location].</RoundSummaryProgress>
@@ -57,4 +57,5 @@
<Jobs file="Content/Jobs.xml" /> <Jobs file="Content/Jobs.xml" />
<Sounds file="Content/Sounds/sounds.xml" /> <Sounds file="Content/Sounds/sounds.xml" />
<Executable file="Barotrauma.exe" /> <Executable file="Barotrauma.exe" />
<ServerExecutable file="BarotraumaServer.exe" />
</contentpackage> </contentpackage>
@@ -14,6 +14,7 @@ namespace Barotrauma
Character, Character,
Structure, Structure,
Executable, Executable,
ServerExecutable,
LocationTypes, LocationTypes,
LevelGenerationParameters, LevelGenerationParameters,
RandomEvents, RandomEvents,
@@ -144,7 +145,7 @@ namespace Barotrauma
var md5 = MD5.Create(); var md5 = MD5.Create();
foreach (ContentFile file in files) foreach (ContentFile file in files)
{ {
if (file.type == ContentType.Executable) continue; if (file.type == ContentType.Executable || file.type == ContentType.ServerExecutable) continue;
try try
{ {