mattercontrol/Program.cs

101 lines
4.4 KiB
C#
Raw Normal View History

/*
Copyright (c) 2018, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Globalization;
using System.IO;
using System.Threading;
2017-09-24 07:49:51 -07:00
using MatterHackers.Agg.Platform;
using MatterHackers.MatterControl.DataStorage;
2018-09-02 13:50:43 -07:00
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.SerialPortCommunication.FrostedSerial;
2018-09-02 13:50:43 -07:00
using Microsoft.Extensions.Configuration;
namespace MatterHackers.MatterControl
{
class Program
{
[STAThread]
static void Main(string[] args)
{
2018-01-03 10:46:39 -08:00
// this sets the global culture for the app and all new threads
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
2018-01-03 10:46:39 -08:00
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
// make sure we can bulid a system relevant serial port
FrostedSerialPortFactory.GetPlatformSerialPort = (serialPortName) =>
{
return new CSharpSerialPortWrapper(serialPortName);
};
2018-01-24 09:04:33 -08:00
// and make sure the app is set correctly
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
2018-01-03 10:46:39 -08:00
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
2018-09-02 13:50:43 -07:00
// Set default Agg providers
AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.Agg.UI.OpenGLWinformsWindowProvider, agg_platform_win32";
2018-10-02 13:57:22 -07:00
//AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.MatterControl.WinformsSingleWindowProvider, MatterControl.Winforms";
2018-09-02 13:50:43 -07:00
2018-09-04 12:18:11 -07:00
string userProfilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
2018-09-02 13:50:43 -07:00
// Load optional user configuration
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true)
2018-09-04 12:18:11 -07:00
.AddJsonFile(Path.Combine(userProfilePath, "MatterControl.json"), optional: true)
2018-09-02 13:50:43 -07:00
.Build();
// Override defaults via configuration
config.Bind("Agg:ProviderTypes", AggContext.Config.ProviderTypes);
config.Bind("Agg:GraphicsMode", AggContext.Config.GraphicsMode);
2018-09-04 12:18:11 -07:00
2018-09-02 13:50:43 -07:00
Slicer.RunInProcess = config.GetValue<bool>("MatterControl:Slicer:Debug");
// 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));
Datastore.Instance.Initialize();
// Init platformFeaturesProvider before ShowAsSystemWindow
string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms";
MatterHackers.MatterControl.AppContext.Platform = AggContext.CreateInstanceFrom<INativePlatformFeatures>(platformFeaturesProvider);
MatterHackers.MatterControl.AppContext.Platform.ProcessCommandline();
config.Bind("MatterControl", MatterHackers.MatterControl.AppContext.Options);
// Get startup bounds from MatterControl and construct system window
//var systemWindow = new DesktopMainWindow(400, 200)
var (width, height) = RootSystemWindow.GetStartupBounds();
var systemWindow = Application.LoadRootWindow(width, height);
systemWindow.ShowAsSystemWindow();
2017-12-17 00:17:21 -08:00
}
}
}