corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 using System;
2 using System.IO;
3 using System.Diagnostics;
4 using Gtk;
5  
6 namespace GridProxyGUI
7 {
8 class MainClass
9 {
10 public static void Main(string[] args)
11 {
12 try
13 {
14 InitLogging();
15 StartGtkApp();
16 }
17 catch (Exception ex)
18 {
19 if (ex is TypeInitializationException || ex is TypeLoadException || ex is System.IO.FileNotFoundException)
20 {
21 NativeApi.ExitWithMessage("Failed to start", ex.Message + "\n\nMake sure tha application install isn't missing accompanied files and that Gtk# is installed.", 1);
22 }
23 throw;
24 }
25 }
26  
27 static void StartGtkApp()
28 {
29 Gtk.Application.Init();
30 MainWindow win = new MainWindow();
31 win.Show();
32 Application.Run();
33 }
34  
35 static bool InitLogging()
36 {
37 try
38 {
39 string userDir = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), "GridProxyGUI");
40  
41 if (!Directory.Exists(userDir))
42 {
43 Directory.CreateDirectory(userDir);
44 }
45  
46 string settingsFile = Path.Combine(userDir, "Settings.xml");
47 Options.CreateInstance(settingsFile);
48  
49 return true;
50 }
51 catch
52 {
53 return false;
54 }
55 }
56 }
57  
58 public static class NativeApi
59 {
60 [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
61 public static extern int MessageBox(IntPtr hWnd, String text, String caption, int options);
62  
63 public static void LinuxMessageBox(string title, string msg, string type)
64 {
65 try
66 {
67 ProcessStartInfo p = new ProcessStartInfo("zenity", string.Format("--{0} --title=\"{1}\" --text=\"{2}\"", type, title.Replace("\"", "\\\""), msg.Replace("\"", "\\\"")));
68 p.CreateNoWindow = true;
69 p.ErrorDialog = false;
70 p.UseShellExecute = true;
71 var process = Process.Start(p);
72 process.WaitForExit();
73 }
74 catch { }
75 }
76  
77 public static void ExitWithMessage(string title, string msg, int exitCode)
78 {
79 Console.Error.WriteLine(title + ": " + msg);
80 if (PlatformDetection.IsWindows)
81 {
82 MessageBox(IntPtr.Zero, msg, title, 0x10);
83 }
84 else if (PlatformDetection.IsMac)
85 {
86 }
87 else
88 {
89 LinuxMessageBox(title, msg, "error");
90 }
91  
92 Environment.Exit(exitCode);
93 }
94 }
95 }