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/AppOrchestrator.cs

88 lines
3.7 KiB
C#
Raw Normal View History

2024-02-28 02:44:21 +00:00
using AutoUpdaterDotNET;
using MSFSPopoutPanelManager.Shared;
using MSFSPopoutPanelManager.WindowsAgent;
using System;
using System.IO;
using System.Threading.Tasks;
namespace MSFSPopoutPanelManager.Orchestration
{
public class AppOrchestrator : BaseOrchestrator
{
private readonly PanelConfigurationOrchestrator _panelConfigurationOrchestrator;
private readonly FlightSimOrchestrator _flightSimOrchestrator;
private readonly KeyboardOrchestrator _keyboardOrchestrator;
public AppOrchestrator(SharedStorage sharedStorage, PanelConfigurationOrchestrator panelConfigurationOrchestrator, FlightSimOrchestrator flightSimOrchestrator, HelpOrchestrator helpOrchestrator, KeyboardOrchestrator keyboardOrchestrator) : base(sharedStorage)
{
_panelConfigurationOrchestrator = panelConfigurationOrchestrator;
_flightSimOrchestrator = flightSimOrchestrator;
_keyboardOrchestrator = keyboardOrchestrator;
ProfileData.FlightSimDataRef = FlightSimData;
ProfileData.AppSettingDataRef = AppSettingData;
FlightSimData.ProfileDataRef = ProfileData;
_flightSimOrchestrator.OnSimulatorExited += (_, _) => { ApplicationClose(); Environment.Exit(0); };
// Delete all existing cache version of app
helpOrchestrator.DeleteAppCache();
}
public ProfileOrchestrator Profile { get; set; }
public void Initialize()
{
if (AppSettingData.ApplicationSetting.GeneralSetting.CheckForUpdate)
CheckForAutoUpdate();
ProfileData.SetActiveProfile(AppSettingData.ApplicationSetting.SystemSetting.LastUsedProfileId); // Load last used profile
2024-03-01 11:28:09 +00:00
Task.Run(() => _flightSimOrchestrator.StartSimConnectServer()); // Start the SimConnect server
2024-02-28 02:44:21 +00:00
_keyboardOrchestrator.Initialize();
2024-07-28 00:12:07 +00:00
AppSettingData.ApplicationSetting.GeneralSetting.OnApplicationDataPathUpdated += (_, e) =>
{
AppSettingDataManager.MoveAppSettings(AppSettingData.ApplicationSetting);
ProfileDataManager.MoveProfiles(ProfileData.Profiles, e);
FileLogger.UseApplicationDataPath = e;
try
{
FileLogger.CloseFileLogger();
if (Directory.Exists(FileIo.GetUserDataFilePath(!e)))
Directory.Delete(FileIo.GetUserDataFilePath(!e), true);
}
catch
{
FileLogger.WriteLog($"Unable to remove old POPM data folder. {FileIo.GetUserDataFilePath(!e)}", StatusMessageType.Error);
}
};
2024-02-28 02:44:21 +00:00
}
public void ApplicationClose()
{
// Force unhook all win events
_panelConfigurationOrchestrator.EndConfiguration();
_panelConfigurationOrchestrator.EndTouchHook();
2024-03-03 05:02:21 +00:00
InputHookManager.EndKeyboardHook();
_keyboardOrchestrator.EndGlobalKeyboardHookForced();
2024-02-28 02:44:21 +00:00
_flightSimOrchestrator.EndSimConnectServer(true);
}
private void CheckForAutoUpdate()
{
2024-07-28 00:12:07 +00:00
var jsonPath = Path.Combine(Path.Combine(FileIo.GetUserDataFilePath(AppSettingData.ApplicationSetting.GeneralSetting.UseApplicationDataPath), "autoupdate.json"));
2024-02-28 02:44:21 +00:00
AutoUpdater.PersistenceProvider = new JsonFilePersistenceProvider(jsonPath);
AutoUpdater.Synchronous = true;
AutoUpdater.AppTitle = "MSFS Pop Out Panel Manager";
AutoUpdater.RunUpdateAsAdmin = false;
AutoUpdater.UpdateFormSize = new System.Drawing.Size(1024, 660);
AutoUpdater.Start(AppSettingData.ApplicationSetting.SystemSetting.AutoUpdaterUrl);
}
}
}