From bc1e47c9168098bf48d5c8d1e0442c52e8881c6f Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sun, 6 Jan 2019 22:42:47 +0200 Subject: [PATCH] Disable GameAnalytics if an exception is thrown during initialization. --- .../Source/GameAnalyticsManager.cs | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/GameAnalyticsManager.cs b/Barotrauma/BarotraumaShared/Source/GameAnalyticsManager.cs index 36cc8fbe1..b276e7ed7 100644 --- a/Barotrauma/BarotraumaShared/Source/GameAnalyticsManager.cs +++ b/Barotrauma/BarotraumaShared/Source/GameAnalyticsManager.cs @@ -34,17 +34,25 @@ namespace Barotrauma { DebugConsole.ThrowError("Error while calculating MD5 hash for the executable \"" + exePath + "\"", e); } + try + { + GameAnalytics.ConfigureBuild(GameMain.Version.ToString() + + (string.IsNullOrEmpty(exeName) ? "Unknown" : exeName) + ":" + + ((exeHash?.ShortHash == null) ? "Unknown" : exeHash.ShortHash)); - GameAnalytics.ConfigureBuild(GameMain.Version.ToString() - + (string.IsNullOrEmpty(exeName) ? "Unknown" : exeName) + ":" - + ((exeHash?.ShortHash == null) ? "Unknown" : exeHash.ShortHash)); - - GameAnalytics.AddDesignEvent("Executable:" - + (string.IsNullOrEmpty(exeName) ? "Unknown" : exeName) + ":" - + ((exeHash?.ShortHash == null) ? "Unknown" : exeHash.ShortHash)); + GameAnalytics.AddDesignEvent("Executable:" + + (string.IsNullOrEmpty(exeName) ? "Unknown" : exeName) + ":" + + ((exeHash?.ShortHash == null) ? "Unknown" : exeHash.ShortHash)); - GameAnalytics.ConfigureAvailableCustomDimensions01("singleplayer", "multiplayer", "editor"); - GameAnalytics.Initialize("a3a073c20982de7c15d21e840e149122", "9010ad9a671233b8d9610d76cec8c897d9ff3ba7"); + GameAnalytics.ConfigureAvailableCustomDimensions01("singleplayer", "multiplayer", "editor"); + GameAnalytics.Initialize("a3a073c20982de7c15d21e840e149122", "9010ad9a671233b8d9610d76cec8c897d9ff3ba7"); + } + catch (Exception e) + { + DebugConsole.ThrowError("Initializing GameAnalytics failed. Disabling user statistics...", e); + GameSettings.SendUserStatistics = false; + return; + } string contentPackageName = GameMain.Config?.SelectedContentPackage?.Name; if (!string.IsNullOrEmpty(contentPackageName))