2022-07-23 19:23:32 +00:00
|
|
|
|
using AutoUpdaterDotNET;
|
|
|
|
|
using MSFSPopoutPanelManager.Shared;
|
|
|
|
|
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);
|
|
|
|
|
PanelSource = new PanelSourceOrchestrator(ProfileData, AppSettingData);
|
|
|
|
|
PanelPopOut = new PanelPopOutOrchestrator(ProfileData, AppSettingData, FlightSimData);
|
|
|
|
|
PanelConfiguration = new PanelConfigurationOrchestrator(ProfileData, AppSettingData, FlightSimData);
|
|
|
|
|
FlightSim = new FlightSimOrchestrator(ProfileData, AppSettingData, FlightSimData);
|
|
|
|
|
Help = new HelpOrchestrator();
|
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); };
|
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 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
|
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();
|
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
|
|
|
|
}
|
|
|
|
|
}
|