From 87767e9358636267fbad2cfb54bc7a4bc4a7233a Mon Sep 17 00:00:00 2001 From: memchr Date: Sat, 21 Jan 2023 01:20:38 +0800 Subject: [PATCH 1/3] Fix mkbundle executable crash In `CKAN.GameInstance.PortableDir (CKAN.Games.IGame game)`: ```cs // Find the directory our executable is stored in. string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); ```` An empty string would be assigned to `exeDir` when ckan is packaged using mkbundle. This caused following method call `game.GameInFolder(new DirectoryInfo(exeDir))` to crash with `System.ArgumentException: The specified path is not of a legal form (empty).` --- Core/GameInstance.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Core/GameInstance.cs b/Core/GameInstance.cs index 98d918c328..1d5467243b 100644 --- a/Core/GameInstance.cs +++ b/Core/GameInstance.cs @@ -241,6 +241,10 @@ public static string PortableDir(IGame game) // Find the directory our executable is stored in. string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + if (exeDir.Length == 0) + { + return null; + } log.DebugFormat("Checking if {0} is in my exe dir: {1}", game.ShortName, exeDir); From 1941c5fe11f63c14729572016d565e09c2df8498 Mon Sep 17 00:00:00 2001 From: memchr <118117622+memchr@users.noreply.github.com> Date: Sun, 19 Feb 2023 04:23:40 +0800 Subject: [PATCH 2/3] Fix indentation Co-authored-by: HebaruSan --- Core/GameInstance.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/GameInstance.cs b/Core/GameInstance.cs index 1d5467243b..08a8e960f9 100644 --- a/Core/GameInstance.cs +++ b/Core/GameInstance.cs @@ -241,10 +241,10 @@ public static string PortableDir(IGame game) // Find the directory our executable is stored in. string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - if (exeDir.Length == 0) - { - return null; - } + if (exeDir.Length == 0) + { + return null; + } log.DebugFormat("Checking if {0} is in my exe dir: {1}", game.ShortName, exeDir); From 9c2b4cee1b3ce062f66cb3d3c1f229f4a81c9bdd Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Sat, 18 Feb 2023 21:34:44 +0000 Subject: [PATCH 3/3] Fallback to main module path, add logging --- Core/GameInstance.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Core/GameInstance.cs b/Core/GameInstance.cs index 08a8e960f9..8cf0ef2e8b 100644 --- a/Core/GameInstance.cs +++ b/Core/GameInstance.cs @@ -5,6 +5,8 @@ using System.Reflection; using System.Text.RegularExpressions; using System.Transactions; +using System.Diagnostics; + using ChinhDo.Transactions.FileManager; using log4net; using Newtonsoft.Json; @@ -241,9 +243,15 @@ public static string PortableDir(IGame game) // Find the directory our executable is stored in. string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - if (exeDir.Length == 0) + if (string.IsNullOrEmpty(exeDir)) { - return null; + exeDir = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); + if (string.IsNullOrEmpty(exeDir)) + { + log.InfoFormat("Executing assembly path and main module path not found"); + return null; + } + log.InfoFormat("Executing assembly path not found, main module path is {0}", exeDir); } log.DebugFormat("Checking if {0} is in my exe dir: {1}",