2022-06-30 23:53:08 +00:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using MSFSPopoutPanelManager.Shared;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace MSFSPopoutPanelManager.Model
|
|
|
|
|
{
|
2022-06-30 23:53:08 +00:00
|
|
|
|
public class AppSetting : ObservableObject
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
|
|
|
|
private const string APP_SETTING_DATA_FILENAME = "appsettingdata.json";
|
|
|
|
|
private bool _saveEnabled;
|
|
|
|
|
|
|
|
|
|
public event EventHandler<EventArgs<bool>> AlwaysOnTopChanged;
|
|
|
|
|
public event EventHandler<EventArgs<bool>> AutoPopOutPanelsChanged;
|
|
|
|
|
|
|
|
|
|
public AppSetting()
|
|
|
|
|
{
|
|
|
|
|
// Set defaults
|
2022-05-04 15:11:04 +00:00
|
|
|
|
AutoUpdaterUrl = "https://raw.githubusercontent.com/hawkeye-stan/msfs-popout-panel-manager/master/autoupdate.xml";
|
|
|
|
|
//AutoUpdaterUrl = "https://raw.githubusercontent.com/hawkeye-stan/AutoUpdateTest/main/autoupdate.xml"; // Test URL against test repo
|
2022-04-18 16:24:00 +00:00
|
|
|
|
LastUsedProfileId = -1;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
MinimizeToTray = false;
|
|
|
|
|
AlwaysOnTop = true;
|
|
|
|
|
UseAutoPanning = true;
|
2022-04-18 03:38:33 +00:00
|
|
|
|
AutoPanningKeyBinding = "0";
|
2022-01-27 13:40:04 +00:00
|
|
|
|
StartMinimized = false;
|
|
|
|
|
IncludeBuiltInPanel = false;
|
2022-05-04 15:11:04 +00:00
|
|
|
|
AutoDisableTrackIR = true;
|
2022-07-06 18:09:10 +00:00
|
|
|
|
AutoPopOutPanels = true;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
AutoPopOutPanelsWaitDelay = new AutoPopOutPanelsWaitDelay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Load()
|
|
|
|
|
{
|
|
|
|
|
var appSetting = ReadAppSetting();
|
2022-05-04 15:11:04 +00:00
|
|
|
|
this.AutoUpdaterUrl = appSetting.AutoUpdaterUrl;
|
2022-04-18 16:24:00 +00:00
|
|
|
|
this.LastUsedProfileId = appSetting.LastUsedProfileId;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
this.MinimizeToTray = appSetting.MinimizeToTray;
|
|
|
|
|
this.AlwaysOnTop = appSetting.AlwaysOnTop;
|
|
|
|
|
this.UseAutoPanning = appSetting.UseAutoPanning;
|
2022-04-18 03:38:33 +00:00
|
|
|
|
this.AutoPanningKeyBinding = appSetting.AutoPanningKeyBinding;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
this.StartMinimized = appSetting.StartMinimized;
|
|
|
|
|
this.IncludeBuiltInPanel = appSetting.IncludeBuiltInPanel;
|
2022-05-04 15:11:04 +00:00
|
|
|
|
this.AutoDisableTrackIR = appSetting.AutoDisableTrackIR;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
this.AutoPopOutPanels = appSetting.AutoPopOutPanels;
|
|
|
|
|
this.AutoPopOutPanelsWaitDelay = appSetting.AutoPopOutPanelsWaitDelay;
|
2022-04-18 03:38:33 +00:00
|
|
|
|
AutoPopOutPanelsWaitDelay.DataChanged += (e, source) => WriteAppSetting(this);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
|
|
|
|
_saveEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnPropertyChanged(string propertyName, object before, object after)
|
|
|
|
|
{
|
|
|
|
|
// Automatic save data
|
|
|
|
|
if (_saveEnabled && propertyName != "AutoStart" && before != after)
|
|
|
|
|
WriteAppSetting(this);
|
|
|
|
|
|
|
|
|
|
switch (propertyName)
|
|
|
|
|
{
|
|
|
|
|
case "AlwaysOnTop":
|
|
|
|
|
AlwaysOnTopChanged?.Invoke(this, new EventArgs<bool>((bool)after));
|
|
|
|
|
break;
|
|
|
|
|
case "AutoPopOutPanels":
|
|
|
|
|
AutoPopOutPanelsChanged?.Invoke(this, new EventArgs<bool>((bool)after));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-04 15:11:04 +00:00
|
|
|
|
public string AutoUpdaterUrl { get; set; }
|
|
|
|
|
|
2022-04-18 16:24:00 +00:00
|
|
|
|
public int LastUsedProfileId { get; set; }
|
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
public bool MinimizeToTray { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool AlwaysOnTop { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool UseAutoPanning { get; set; }
|
|
|
|
|
|
2022-04-18 03:38:33 +00:00
|
|
|
|
public string AutoPanningKeyBinding { get; set; }
|
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
public bool StartMinimized { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IncludeBuiltInPanel { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool AutoPopOutPanels { get; set; }
|
|
|
|
|
|
2022-05-04 15:11:04 +00:00
|
|
|
|
public bool AutoDisableTrackIR { get; set; }
|
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
public AutoPopOutPanelsWaitDelay AutoPopOutPanelsWaitDelay { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public bool AutoStart
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return AppAutoStart.CheckIsAutoStart();
|
|
|
|
|
}
|
2022-06-30 23:53:08 +00:00
|
|
|
|
set
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
|
|
|
|
if (value)
|
|
|
|
|
AppAutoStart.Activate();
|
|
|
|
|
else
|
|
|
|
|
AppAutoStart.Deactivate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AppSetting ReadAppSetting()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (StreamReader reader = new StreamReader(Path.Combine(FileIo.GetUserDataFilePath(), APP_SETTING_DATA_FILENAME)))
|
|
|
|
|
{
|
|
|
|
|
return JsonConvert.DeserializeObject<AppSetting>(reader.ReadToEnd());
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-18 16:24:00 +00:00
|
|
|
|
catch
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
|
|
|
|
// if file does not exist, write default data
|
|
|
|
|
var appSetting = new AppSetting();
|
|
|
|
|
WriteAppSetting(appSetting);
|
|
|
|
|
return appSetting;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void WriteAppSetting(AppSetting appSetting)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var userProfilePath = FileIo.GetUserDataFilePath();
|
|
|
|
|
if (!Directory.Exists(userProfilePath))
|
|
|
|
|
Directory.CreateDirectory(userProfilePath);
|
|
|
|
|
|
|
|
|
|
using (StreamWriter file = File.CreateText(Path.Combine(userProfilePath, APP_SETTING_DATA_FILENAME)))
|
|
|
|
|
{
|
|
|
|
|
JsonSerializer serializer = new JsonSerializer();
|
|
|
|
|
serializer.Serialize(file, appSetting);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-18 16:24:00 +00:00
|
|
|
|
catch
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
|
|
|
|
Logger.LogStatus($"Unable to write app setting data file: {APP_SETTING_DATA_FILENAME}", StatusMessageType.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-30 23:53:08 +00:00
|
|
|
|
public class AutoPopOutPanelsWaitDelay : ObservableObject
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-06-30 23:53:08 +00:00
|
|
|
|
public event EventHandler<EventArgs<string>> DataChanged;
|
2022-04-18 03:38:33 +00:00
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
public AutoPopOutPanelsWaitDelay()
|
|
|
|
|
{
|
2022-07-06 18:09:10 +00:00
|
|
|
|
ReadyToFlyButton = 4;
|
|
|
|
|
InitialCockpitView = 1;
|
|
|
|
|
InstrumentationPowerOn = 1;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int ReadyToFlyButton { get; set; }
|
|
|
|
|
|
|
|
|
|
public int InitialCockpitView { get; set; }
|
|
|
|
|
|
|
|
|
|
public int InstrumentationPowerOn { get; set; }
|
2022-04-18 03:38:33 +00:00
|
|
|
|
|
|
|
|
|
public void OnPropertyChanged(string propertyName, object before, object after)
|
|
|
|
|
{
|
2022-06-30 23:53:08 +00:00
|
|
|
|
DataChanged?.Invoke(this, new EventArgs<string>(propertyName));
|
2022-04-18 03:38:33 +00:00
|
|
|
|
}
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|