/SparkleShare/Program.cs
C# | 96 lines | 58 code | 20 blank | 18 comment | 6 complexity | 3107ed5617f783db4199a883e9517b13 MD5 | raw file
1// SparkleShare, a collaboration and sharing tool. 2// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com> 3// 4// This program is free software: you can redistribute it and/or modify 5// it under the terms of the GNU General Public License as published by 6// the Free Software Foundation, either version 3 of the License, or 7// (at your option) any later version. 8// 9// This program is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13// 14// You should have received a copy of the GNU General Public License 15// along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 18using System; 19using System.Threading; 20 21using SparkleLib; 22 23namespace SparkleShare { 24 25 // This is SparkleShare! 26 public class Program { 27 28 public static SparkleController Controller; 29 public static SparkleUI UI; 30 public static string [] Arguments; 31 32 private static Mutex program_mutex = new Mutex (false, "SparkleShare"); 33 34 35 #if !__MonoCS__ 36 [STAThread] 37 #endif 38 public static void Main (string [] args) 39 { 40 Arguments = args; 41 42 if (args.Length != 0 && !args [0].Equals ("help") && 43 SparkleBackend.Platform != PlatformID.MacOSX && 44 SparkleBackend.Platform != PlatformID.Win32NT) { 45 46 string n = Environment.NewLine; 47 48 Console.WriteLine (n + 49 "SparkleShare is a collaboration and sharing tool that is" + n + 50 "designed to keep things simple and to stay out of your way." + n + 51 n + 52 "Version: " + SparkleLib.SparkleBackend.Version + n + 53 "Copyright (C) 2010 Hylke Bons and others" + n + 54 "This program comes with ABSOLUTELY NO WARRANTY." + n + 55 n + 56 "This is free software, and you are welcome to redistribute it" + n + 57 "under certain conditions. Please read the GNU GPLv3 for details." + n + 58 n + 59 "Usage: sparkleshare [start|open]"); 60 61 Environment.Exit (-1); 62 } 63 64 // Only allow one instance of SparkleShare (on Windows) 65 if (!program_mutex.WaitOne (0, false)) { 66 Console.WriteLine ("SparkleShare is already running."); 67 Environment.Exit (-1); 68 } 69 70 AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; 71 72 Controller = new SparkleController (); 73 Controller.Initialize (); 74 75 UI = new SparkleUI (); 76 UI.Run (); 77 78 #if !__MonoCS__ 79 // Suppress assertion messages in debug mode 80 GC.Collect (GC.MaxGeneration, GCCollectionMode.Forced); 81 GC.WaitForPendingFinalizers (); 82 #endif 83 } 84 85 private static void OnUnhandledException (object sender, UnhandledExceptionEventArgs exception_args) 86 { 87 try { 88 Exception e = (Exception) exception_args.ExceptionObject; 89 SparkleLogger.WriteCrashReport (e); 90 91 } finally { 92 Environment.Exit (-1); 93 } 94 } 95 } 96}