2017-08-20 02:34:39 -07:00
|
|
|
|
using System;
|
2017-12-16 19:25:46 -08:00
|
|
|
|
using System.Diagnostics;
|
2017-08-20 02:34:39 -07:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Threading;
|
2017-12-16 19:25:46 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2017-09-24 07:49:51 -07:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2017-12-16 19:25:46 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2017-08-20 02:34:39 -07:00
|
|
|
|
using MatterHackers.MatterControl.DataStorage;
|
2017-09-24 08:07:59 -07:00
|
|
|
|
using MatterHackers.MatterControl.SettingsManagement;
|
2017-08-22 14:58:13 -07:00
|
|
|
|
using Mindscape.Raygun4Net;
|
2017-08-20 02:34:39 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
|
|
|
|
|
static class Program
|
|
|
|
|
|
{
|
2017-12-16 19:25:46 -08:00
|
|
|
|
private const int RaygunMaxNotifications = 15;
|
2017-08-20 02:34:39 -07:00
|
|
|
|
|
2017-12-16 19:25:46 -08:00
|
|
|
|
private static int raygunNotificationCount = 0;
|
2017-08-22 14:58:13 -07:00
|
|
|
|
|
2017-12-16 19:25:46 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[STAThread]
|
2017-08-20 02:34:39 -07:00
|
|
|
|
public static void Main()
|
|
|
|
|
|
{
|
|
|
|
|
|
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
|
2017-12-16 19:25:46 -08:00
|
|
|
|
|
2017-08-20 02:34:39 -07:00
|
|
|
|
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
|
|
|
|
|
|
|
2017-10-12 12:16:09 -07:00
|
|
|
|
AggContext.Init(embeddedResourceName: "config.json");
|
|
|
|
|
|
|
2017-08-20 02:34:39 -07:00
|
|
|
|
// Make sure we have the right working directory as we assume everything relative to the executable.
|
|
|
|
|
|
Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !DEBUG
|
|
|
|
|
|
// Conditionally spin up error reporting if not on the Stable channel
|
|
|
|
|
|
string channel = UserSettings.Instance.get(UserSettingsKey.UpdateFeedType);
|
|
|
|
|
|
if (string.IsNullOrEmpty(channel) || channel != "release" || OemSettings.Instance.WindowTitleExtra == "Experimental")
|
|
|
|
|
|
#endif
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
|
|
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-16 19:25:46 -08:00
|
|
|
|
var timer = Stopwatch.StartNew();
|
|
|
|
|
|
|
|
|
|
|
|
// Get startup bounds from MatterControl and construct system window
|
|
|
|
|
|
//var systemWindow = new DesktopMainWindow(400, 200)
|
|
|
|
|
|
var (width, height) = DesktopRootSystemWindow.GetStartupBounds();
|
|
|
|
|
|
|
|
|
|
|
|
var systemWindow = new DesktopRootSystemWindow(width, height)
|
|
|
|
|
|
{
|
|
|
|
|
|
BackgroundColor = Color.DarkGray
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
AppContext.RootSystemWindow = systemWindow;
|
|
|
|
|
|
|
|
|
|
|
|
// Hook SystemWindow load and spin up MatterControl once we've hit first draw
|
|
|
|
|
|
systemWindow.Load += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
2017-12-16 20:06:03 -08:00
|
|
|
|
Datastore.Instance.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
var mainView = MatterControlApplication.Initialize(systemWindow, ReportStartupProgress);
|
2017-12-16 19:25:46 -08:00
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Time to MatterControlApplication.Instance init: " + timer.Elapsed.TotalSeconds);
|
|
|
|
|
|
|
|
|
|
|
|
systemWindow.RemoveAllChildren();
|
|
|
|
|
|
|
2017-12-16 20:06:03 -08:00
|
|
|
|
systemWindow.AddChild(mainView);
|
2017-12-16 19:25:46 -08:00
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Time to MatterControlApplication Layout: " + timer.Elapsed.TotalSeconds);
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Block indefinitely
|
|
|
|
|
|
systemWindow.ShowAsSystemWindow();
|
2017-08-20 02:34:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-16 20:06:03 -08:00
|
|
|
|
private static void ReportStartupProgress(string status)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(status);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-20 02:34:39 -07:00
|
|
|
|
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
#if !DEBUG
|
|
|
|
|
|
if(raygunNotificationCount++ < RaygunMaxNotifications)
|
|
|
|
|
|
{
|
|
|
|
|
|
_raygunClient.Send(e.Exception);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
#if !DEBUG
|
|
|
|
|
|
if(raygunNotificationCount++ < RaygunMaxNotifications)
|
|
|
|
|
|
{
|
|
|
|
|
|
_raygunClient.Send(e.ExceptionObject as Exception);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
2017-08-22 14:58:13 -07:00
|
|
|
|
|
2017-12-16 19:25:46 -08:00
|
|
|
|
private static RaygunClient _raygunClient = GetCorrectClient();
|
|
|
|
|
|
|
|
|
|
|
|
private static RaygunClient GetCorrectClient()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (AggContext.OperatingSystem == OSType.Mac)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new RaygunClient("qmMBpKy3OSTJj83+tkO7BQ=="); // this is the Mac key
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return new RaygunClient("hQIlyUUZRGPyXVXbI6l1dA=="); // this is the PC key
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ** Standard Winforms Main ** //
|
|
|
|
|
|
//[STAThread]
|
|
|
|
|
|
//static void Main()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Application.EnableVisualStyles();
|
|
|
|
|
|
// Application.SetCompatibleTextRenderingDefault(false);
|
|
|
|
|
|
// Application.Run(new Form1());
|
|
|
|
|
|
//}
|
|
|
|
|
|
}
|
2017-08-20 02:34:39 -07:00
|
|
|
|
}
|