Improve error message when running on systems with required libraries missing
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Gtk;
|
||||
|
||||
namespace GridProxyGUI
|
||||
@@ -7,10 +8,64 @@ namespace GridProxyGUI
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Application.Init();
|
||||
MainWindow win = new MainWindow();
|
||||
win.Show();
|
||||
Application.Run();
|
||||
try
|
||||
{
|
||||
StartGtkApp();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is TypeInitializationException || ex is TypeLoadException || ex is System.IO.FileNotFoundException)
|
||||
{
|
||||
NativeApi.ExitWithMessage("Failed to start", ex.Message + "\n\nMake sure tha application install isn't missing accompanied files and that Gtk# is installed.", 1);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
static void StartGtkApp()
|
||||
{
|
||||
Gtk.Application.Init();
|
||||
MainWindow win = new MainWindow();
|
||||
win.Show();
|
||||
Application.Run();
|
||||
}
|
||||
}
|
||||
|
||||
public static class NativeApi
|
||||
{
|
||||
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
|
||||
public static extern int MessageBox(IntPtr hWnd, String text, String caption, int options);
|
||||
|
||||
public static void LinuxMessageBox(string title, string msg, string type)
|
||||
{
|
||||
try
|
||||
{
|
||||
ProcessStartInfo p = new ProcessStartInfo("zenity", string.Format("--{0} --title=\"{1}\" --text=\"{2}\"", type, title.Replace("\"", "\\\""), msg.Replace("\"", "\\\"")));
|
||||
p.CreateNoWindow = true;
|
||||
p.ErrorDialog = false;
|
||||
p.UseShellExecute = true;
|
||||
var process = Process.Start(p);
|
||||
process.WaitForExit();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public static void ExitWithMessage(string title, string msg, int exitCode)
|
||||
{
|
||||
Console.Error.WriteLine(title + ": " + msg);
|
||||
if (PlatformDetection.IsWindows)
|
||||
{
|
||||
MessageBox(IntPtr.Zero, msg, title, 0x10);
|
||||
}
|
||||
else if (PlatformDetection.IsMac)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
LinuxMessageBox(title, msg + @" foo ""bar"" baz", "error");
|
||||
}
|
||||
|
||||
Environment.Exit(exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user