From 60aa2523520d5751fbe7f1685331afc9f874cecc Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Mon, 1 Oct 2018 10:24:23 -0700 Subject: [PATCH] Improve chances of running under Mono Updated the RuntimeData directory finder to work, and made the stuff that crashed when the directory wasn't found crash in less obvious ways. Under Mono+Linux it still falls over with some complaints about ListViews. This will need some work. --- SourceGen/AppForms/ProjectView.cs | 8 +++++++- SourceGen/RuntimeDataAccess.cs | 5 ++++- SourceGen/Sandbox/PluginDllCache.cs | 6 +++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/SourceGen/AppForms/ProjectView.cs b/SourceGen/AppForms/ProjectView.cs index 89aa253..2b3c8d1 100644 --- a/SourceGen/AppForms/ProjectView.cs +++ b/SourceGen/AppForms/ProjectView.cs @@ -200,15 +200,21 @@ namespace SourceGen.AppForms { Properties.Resources.RUNTIME_DIR_NOT_FOUND_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); + return; } try { PluginDllCache.PreparePluginDir(); } catch (Exception ex) { + string pluginPath = PluginDllCache.GetPluginDirPath(); + if (pluginPath == null) { + pluginPath = ""; + } string msg = string.Format(Properties.Resources.PLUGIN_DIR_FAIL, - PluginDllCache.GetPluginDirPath() + ": " + ex.Message); + pluginPath + ": " + ex.Message); MessageBox.Show(msg, Properties.Resources.PLUGIN_DIR_FAIL_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); + return; } logoPictureBox.ImageLocation = RuntimeDataAccess.GetPathName(LOGO_FILE_NAME); diff --git a/SourceGen/RuntimeDataAccess.cs b/SourceGen/RuntimeDataAccess.cs index 1e60ff2..7c0f43c 100644 --- a/SourceGen/RuntimeDataAccess.cs +++ b/SourceGen/RuntimeDataAccess.cs @@ -38,7 +38,10 @@ namespace SourceGen { return sBasePath; } - string exeName = Process.GetCurrentProcess().MainModule.FileName; + // Process.GetCurrentProcess().MainModule.FileName returns "/usr/bin/mono-sgen" + // under Linux, which is not what we want. Since this class is part of the main + // executable, we can use our own assembly location to get the desired answer. + string exeName = typeof(RuntimeDataAccess).Assembly.Location; string baseDir = Path.GetDirectoryName(exeName); if (string.IsNullOrEmpty(baseDir)) { return null; diff --git a/SourceGen/Sandbox/PluginDllCache.cs b/SourceGen/Sandbox/PluginDllCache.cs index 8396c8c..93a4ff7 100644 --- a/SourceGen/Sandbox/PluginDllCache.cs +++ b/SourceGen/Sandbox/PluginDllCache.cs @@ -63,10 +63,14 @@ namespace SourceGen.Sandbox { /// /// Computes the path to the plugin directory. Does not attempt to verify that it exists. /// - /// Plugin directory path. + /// Plugin directory path, or null if we can't find the application data + /// area. public static string GetPluginDirPath() { if (sPluginDirPath == null) { string runtimeUp = Path.GetDirectoryName(RuntimeDataAccess.GetDirectory()); + if (runtimeUp == null) { + return null; + } sPluginDirPath = Path.Combine(runtimeUp, PLUGIN_DIR_NAME); } return sPluginDirPath;