2013-12-01 15:05:43 +01:00
using System ;
2013-12-10 13:54:47 +01:00
using System.IO ;
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
{
2013-12-10 13:54:47 +01:00
InitLogging ( ) ;
2013-12-10 11:49:16 +01:00
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 ( ) ;
}
2013-12-10 13:54:47 +01:00
static bool InitLogging ( )
{
try
{
string userDir = Path . Combine ( System . Environment . GetFolderPath ( System . Environment . SpecialFolder . ApplicationData ) , "GridProxyGUI" ) ;
if ( ! Directory . Exists ( userDir ) )
{
Directory . CreateDirectory ( userDir ) ;
}
string settingsFile = Path . Combine ( userDir , "Settings.xml" ) ;
Options . CreateInstance ( settingsFile ) ;
return true ;
}
catch
{
return false ;
}
}
2013-12-10 11:49:16 +01:00
}
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
{
2013-12-10 13:54:47 +01:00
LinuxMessageBox ( title , msg , "error" ) ;
2013-12-10 11:49:16 +01:00
}
Environment . Exit ( exitCode ) ;
2013-12-01 15:05:43 +01:00
}
}
}