Make GUI work with mkbundle

This commit is contained in:
UnknownShadow200 2022-05-26 22:48:33 +10:00
parent eae64acf20
commit 10a91128d7

View File

@ -27,15 +27,32 @@ namespace MCGalaxy.Gui
{
[STAThread]
public static void Main(string[] args) {
Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
SetCurrentDirectory();
if (!File.Exists("MCGalaxy_.dll")) {
// separate method, in case MCGalaxy_.dll is missing
try {
StartGUI();
} catch (FileNotFoundException) {
// If MCGalaxy_.dll is missing, a FileNotFoundException will get thrown for MCGalaxy dll
Popup.Error("Cannot start server as MCGalaxy_.dll is missing from " + Environment.CurrentDirectory
+ "\r\nDownload it from " + Updater.UploadsURL);
+ "\n\nDownload it from " + Updater.UploadsURL);
return;
}
// separate method, in case MCGalaxy_.dll is missing
StartGUI();
}
static void SetCurrentDirectory() {
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
try {
Environment.CurrentDirectory = path;
} catch (Exception ex) {
// assembly.Location usually gives full path of the .exe, but has issues with mkbundle
// https://mono-devel-list.ximian.narkive.com/KfCAxY1F/mkbundle-assembly-getentryassembly
// https://stackoverflow.com/questions/57648241/reliably-get-location-of-bundled-executable-on-linux
// Rather than trying to guess when this issue happens, just don't bother at all
// (since most users will not be trying to run .exe from a different folder anyways)
string msg = "Failed to set working directory to '{0}', running in current directory..\n\n{1}";
Popup.Warning(string.Format(msg, path, ex));
}
}
static void StartGUI() {