/SparkleShare/Program.cs

http://github.com/hbons/SparkleShare · 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. using System;
  17. using System.Threading;
  18. using SparkleLib;
  19. namespace SparkleShare {
  20. // This is SparkleShare!
  21. public class Program {
  22. public static SparkleController Controller;
  23. public static SparkleUI UI;
  24. public static string [] Arguments;
  25. private static Mutex program_mutex = new Mutex (false, "SparkleShare");
  26. #if !__MonoCS__
  27. [STAThread]
  28. #endif
  29. public static void Main (string [] args)
  30. {
  31. Arguments = args;
  32. if (args.Length != 0 && !args [0].Equals ("help") &&
  33. SparkleBackend.Platform != PlatformID.MacOSX &&
  34. SparkleBackend.Platform != PlatformID.Win32NT) {
  35. string n = Environment.NewLine;
  36. Console.WriteLine (n +
  37. "SparkleShare is a collaboration and sharing tool that is" + n +
  38. "designed to keep things simple and to stay out of your way." + n +
  39. n +
  40. "Version: " + SparkleLib.SparkleBackend.Version + n +
  41. "Copyright (C) 2010 Hylke Bons and others" + n +
  42. "This program comes with ABSOLUTELY NO WARRANTY." + n +
  43. n +
  44. "This is free software, and you are welcome to redistribute it" + n +
  45. "under certain conditions. Please read the GNU GPLv3 for details." + n +
  46. n +
  47. "Usage: sparkleshare [start|open]");
  48. Environment.Exit (-1);
  49. }
  50. // Only allow one instance of SparkleShare (on Windows)
  51. if (!program_mutex.WaitOne (0, false)) {
  52. Console.WriteLine ("SparkleShare is already running.");
  53. Environment.Exit (-1);
  54. }
  55. AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
  56. Controller = new SparkleController ();
  57. Controller.Initialize ();
  58. UI = new SparkleUI ();
  59. UI.Run ();
  60. #if !__MonoCS__
  61. // Suppress assertion messages in debug mode
  62. GC.Collect (GC.MaxGeneration, GCCollectionMode.Forced);
  63. GC.WaitForPendingFinalizers ();
  64. #endif
  65. }
  66. private static void OnUnhandledException (object sender, UnhandledExceptionEventArgs exception_args)
  67. {
  68. try {
  69. Exception e = (Exception) exception_args.ExceptionObject;
  70. SparkleLogger.WriteCrashReport (e);
  71. } finally {
  72. Environment.Exit (-1);
  73. }
  74. }
  75. }
  76. }