2013-12-01 15:05:43 +01:00
using System ;
2013-12-10 11:49:16 +01:00
using System.Diagnostics ;
2013-12-01 15:05:43 +01:00
using Gtk ;
namespace GridProxyGUI
{
class MainClass
{
public static void Main ( string [ ] args )
{
2013-12-10 11:49:16 +01:00
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 ) ;
2013-12-01 15:05:43 +01:00
}
}
}