1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-25 15:20:10 +00:00
msfs-popout-panel-manager/Orchestration/MainOrchestrator.cs

109 lines
4.1 KiB
C#
Raw Normal View History

2022-07-23 19:23:32 +00:00
using AutoUpdaterDotNET;
using MSFSPopoutPanelManager.Shared;
using MSFSPopoutPanelManager.WindowsAgent;
2022-07-23 19:23:32 +00:00
using System;
using System.IO;
using System.Threading.Tasks;
2023-07-12 22:41:31 +00:00
using System.Windows;
2022-07-23 19:23:32 +00:00
namespace MSFSPopoutPanelManager.Orchestration
{
public class MainOrchestrator : ObservableObject
{
public MainOrchestrator()
{
2023-07-12 22:41:31 +00:00
AppSettingData = new AppSettingData();
ProfileData = new ProfileData();
2022-07-23 19:23:32 +00:00
FlightSimData = new FlightSimData();
2023-07-12 22:41:31 +00:00
ProfileData.FlightSimDataRef = FlightSimData;
ProfileData.AppSettingDataRef = AppSettingData;
FlightSimData.ProfileDataRef = ProfileData;
2022-07-23 19:23:32 +00:00
2023-07-12 22:41:31 +00:00
Profile = new ProfileOrchestrator(ProfileData, FlightSimData);
2023-07-30 21:30:47 +00:00
PanelSource = new PanelSourceOrchestrator(ProfileData, AppSettingData, FlightSimData);
2023-07-12 22:41:31 +00:00
PanelPopOut = new PanelPopOutOrchestrator(ProfileData, AppSettingData, FlightSimData);
PanelConfiguration = new PanelConfigurationOrchestrator(ProfileData, AppSettingData, FlightSimData);
FlightSim = new FlightSimOrchestrator(ProfileData, AppSettingData, FlightSimData);
Help = new HelpOrchestrator();
Keyboard = new KeyboardOrchestrator(AppSettingData, FlightSimData);
2022-07-23 19:23:32 +00:00
2023-07-12 22:41:31 +00:00
PanelSource.FlightSimOrchestrator = FlightSim;
PanelPopOut.FlightSimOrchestrator = FlightSim;
PanelPopOut.PanelSourceOrchestrator = PanelSource;
PanelPopOut.PanelConfigurationOrchestrator = PanelConfiguration;
FlightSim.PanelPopOutOrchestrator = PanelPopOut;
FlightSim.PanelConfigurationOrchestrator = PanelConfiguration;
FlightSim.OnSimulatorExited += (sender, e) => { ApplicationClose(); Environment.Exit(0); };
Keyboard.PanelPopOutOrchestrator = PanelPopOut;
2023-09-10 16:19:41 +00:00
// Delete all existing cache version of app
Help.DeleteAppCache();
2022-07-23 19:23:32 +00:00
}
public ProfileOrchestrator Profile { get; set; }
public PanelSourceOrchestrator PanelSource { get; set; }
public PanelPopOutOrchestrator PanelPopOut { get; set; }
public PanelConfigurationOrchestrator PanelConfiguration { get; set; }
public ProfileData ProfileData { get; set; }
public AppSettingData AppSettingData { get; private set; }
public FlightSimData FlightSimData { get; private set; }
public FlightSimOrchestrator FlightSim { get; set; }
2023-07-12 22:41:31 +00:00
public HelpOrchestrator Help { get; set; }
2022-07-23 19:23:32 +00:00
public KeyboardOrchestrator Keyboard { get; set; }
2022-07-23 19:23:32 +00:00
public IntPtr ApplicationHandle { get; set; }
2023-07-12 22:41:31 +00:00
public Window ApplicationWindow { get; set; }
2022-07-23 19:23:32 +00:00
2023-07-12 22:41:31 +00:00
public void Initialize()
{
2022-07-23 19:23:32 +00:00
AppSettingData.ReadSettings();
ProfileData.ReadProfiles();
2023-07-12 22:41:31 +00:00
PanelSource.ApplicationHandle = ApplicationHandle;
2022-07-23 19:23:32 +00:00
2023-07-12 22:41:31 +00:00
if (AppSettingData.ApplicationSetting.GeneralSetting.CheckForUpdate)
CheckForAutoUpdate();
2022-07-23 19:23:32 +00:00
2023-07-12 22:41:31 +00:00
ProfileData.SetActiveProfile(AppSettingData.ApplicationSetting.SystemSetting.LastUsedProfileId); // Load last used profile
2022-07-23 19:23:32 +00:00
2023-07-12 22:41:31 +00:00
Task.Run(() => FlightSim.StartSimConnectServer()); // Start the SimConnect server
Keyboard.Initialize();
2022-07-23 19:23:32 +00:00
}
2023-07-12 22:41:31 +00:00
public void ApplicationClose()
2022-07-23 19:23:32 +00:00
{
// Force unhook all win events
PanelConfiguration.EndConfiguration();
2023-07-12 22:41:31 +00:00
PanelConfiguration.EndTouchHook();
InputHookManager.EndKeyboardHook();
2022-07-23 19:23:32 +00:00
FlightSim.EndSimConnectServer(true);
}
private void CheckForAutoUpdate()
{
string jsonPath = Path.Combine(Path.Combine(FileIo.GetUserDataFilePath(), "autoupdate.json"));
AutoUpdater.PersistenceProvider = new JsonFilePersistenceProvider(jsonPath);
AutoUpdater.Synchronous = true;
AutoUpdater.AppTitle = "MSFS Pop Out Panel Manager";
AutoUpdater.RunUpdateAsAdmin = false;
2023-07-12 22:41:31 +00:00
AutoUpdater.UpdateFormSize = new System.Drawing.Size(1024, 660);
AutoUpdater.Start(AppSettingData.ApplicationSetting.SystemSetting.AutoUpdaterUrl);
2022-10-16 13:11:01 +00:00
}
2022-07-23 19:23:32 +00:00
}
}