using System; using System.ComponentModel; using System.Configuration; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Runtime.Serialization; using Newtonsoft.Json; using Plume.Interfaces.Settings; using Plume.WPF.Mvvm; namespace JD.Guinness.WPF.Module.Configuration { public sealed class GuinnessSettings : BindableBase, ISettings { private int _imageMaxHeight; [JsonIgnore] [Browsable(false)] public int Ps4NameLimit { get; set; } [JsonIgnore] [Browsable(false)] public int Ps4ObjectiveLimit { get; set; } [JsonIgnore] [Browsable(false)] public int Ps5NameLimit { get; set; } [JsonIgnore] [Browsable(false)] public int Ps5ObjectiveLimit { get; set; } [JsonIgnore] [Browsable(false)] public int XBoxOneNameLimit { get; set; } [JsonIgnore] [Browsable(false)] public int XBoxOneObjectiveLimit { get; set; } [JsonIgnore] [Browsable(false)] public int XBoxSeriesXNameLimit { get; set; } [JsonIgnore] [Browsable(false)] public int XBoxSeriesXObjectiveLimit { get; set; } [JsonIgnore] [Browsable(false)] public int StadiaNameLimit { get; set; } [JsonIgnore] [Browsable(false)] public int StadiaObjectiveLimit { get; set; } [JsonIgnore] [Browsable(false)] public int[] IgnoredLanguages { get; set; } [JsonProperty] [Browsable(false)] public string WorkspaceName { get; set; } [JsonProperty] [Browsable(false)] public string WorkspacePath { get; set; } [JsonProperty] [Browsable(false)] public string GameSaveFilePath { get; set; } [JsonProperty] [Browsable(false)] public DataGridSettings LanguageDataGridSettings { get; set; } [JsonProperty] [Browsable(false)] public DataGridSettings ChallengeDataGridSettings { get; set; } [JsonProperty] [Browsable(false)] public DataGridSettings Ps4DataGridSettings { get; set; } [JsonProperty] [Browsable(false)] public DataGridSettings Ps5DataGridSettings { get; set; } [JsonProperty] [Browsable(false)] public DataGridSettings XBoxOneDataGridSettings { get; set; } [JsonProperty] [Browsable(false)] public DataGridSettings XBoxSeriesXDataGridSettings { get; set; } [JsonProperty] [Browsable(false)] public DataGridSettings StadiaDataGridSettings { get; set; } [JsonProperty] [Browsable(false)] public DataGridSettings WarningDataGridSettings { get; set; } [JsonProperty] [Browsable(false)] public string PerforceServer { get; set; } [JsonProperty] [Description("Path to the sony sdk tool used to generate trophy pack file")] [Category("Advanced")] public string SonyPublishingToolFilePath { get; set; } [JsonProperty] [Description("Path to the folder relative to the root of the workspace where PS4 trophy images are found")] [Category("Advanced")] public string Ps4ImagesFolderPath { get; set; } [JsonProperty] [Description("Path to the folder relative to the root of the workspace where PS5 trophy images are found")] [Category("Advanced")] public string Ps5ImagesFolderPath { get; set; } [JsonProperty] [Description("Path to the folder relative to the root of the workspace where XBOX ONE achievement images are found")] [Category("Advanced")] public string XBoxOneImagesFolderPath { get; set; } [JsonProperty] [Description("Path to the folder relative to the root of the workspace where XBOX SERIES X achievement images are found")] [Category("Advanced")] public string XBoxSeriesXImagesFolderPath { get; set; } [JsonProperty] [Description("Path to the folder relative to the root of the workspace where Stadia achievement images are found")] [Category("Advanced")] public string StadiaImagesFolderPath { get; set; } [JsonProperty] [Description("Maximal height of image displayed in guinness")] public int ImageMaxHeight { get => _imageMaxHeight; set => SetProperty(ref _imageMaxHeight, value); } [OnDeserialized] public void OnDeserialized(StreamingContext _) { void SetIfDefault(Expression> property, T value) { if (property.Body is MemberExpression member && member.Member is PropertyInfo propertyInfo && Equals(propertyInfo.GetValue(this), default(T))) { propertyInfo.SetValue(this, value); } } SetIfDefault(() => Ps4NameLimit, int.TryParse(ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(Ps4NameLimit)}"], out int ps4NameLimit) ? ps4NameLimit : 126); SetIfDefault(() => Ps4ObjectiveLimit, int.TryParse(ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(Ps4ObjectiveLimit)}"], out int ps4ObjectiveLimit) ? ps4ObjectiveLimit : 1024); SetIfDefault(() => Ps5NameLimit, int.TryParse(ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(Ps5NameLimit)}"], out int ps5NameLimit) ? ps5NameLimit : 126); SetIfDefault(() => Ps5ObjectiveLimit, int.TryParse(ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(Ps5ObjectiveLimit)}"], out int ps5ObjectiveLimit) ? ps5ObjectiveLimit : 1024); SetIfDefault(() => XBoxOneNameLimit, int.TryParse(ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(XBoxOneNameLimit)}"], out int xBoxOneNameLimit) ? xBoxOneNameLimit : 100); SetIfDefault(() => XBoxOneObjectiveLimit, int.TryParse(ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(XBoxOneObjectiveLimit)}"], out int xBoxOneObjectiveLimit) ? xBoxOneObjectiveLimit : 100); SetIfDefault(() => XBoxSeriesXNameLimit, int.TryParse(ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(XBoxSeriesXNameLimit)}"], out int xBoxSeriesXNameLimit) ? xBoxSeriesXNameLimit : 100); SetIfDefault(() => XBoxSeriesXObjectiveLimit, int.TryParse(ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(XBoxSeriesXObjectiveLimit)}"], out int xBoxSeriesXObjectiveLimit) ? xBoxSeriesXObjectiveLimit : 100); SetIfDefault(() => StadiaNameLimit, int.TryParse(ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(StadiaNameLimit)}"], out int stadiaNameLimit) ? stadiaNameLimit : 65); SetIfDefault(() => StadiaObjectiveLimit, int.TryParse(ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(StadiaObjectiveLimit)}"], out int stadiaObjectiveLimit) ? stadiaObjectiveLimit : 100); SetIfDefault(() => GameSaveFilePath, ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(GameSaveFilePath)}"] ?? @"data\World\Features\Achievements\JD2021.gui"); // 1: master language, 20000002: chinese GAV SetIfDefault(() => IgnoredLanguages, (ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(IgnoredLanguages)}"] ?? "1,20000002").Split(',').Select(s => int.TryParse(s, out int i) ? i : -1).Where(i => i > 0).ToArray()); SetIfDefault(() => PerforceServer, ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(PerforceServer)}"] ?? "p4-jd-data-mrc.ubisoft.org:1808"); SetIfDefault(() => SonyPublishingToolFilePath, ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(SonyPublishingToolFilePath)}"] ?? @"C:\Program Files (x86)\SCE\ORBIS\Tools\Publishing Tools\bin\orbis-pub-cmd.exe"); SetIfDefault(() => Ps4ImagesFolderPath, ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(Ps4ImagesFolderPath)}"] ?? @"data\World\Features\Achievements\PS4"); SetIfDefault(() => Ps5ImagesFolderPath, ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(Ps5ImagesFolderPath)}"] ?? @"data\World\Features\Achievements\PS4"); SetIfDefault(() => XBoxOneImagesFolderPath, ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(XBoxOneImagesFolderPath)}"] ?? @"data\World\Features\Achievements\XBOX_ONE"); SetIfDefault(() => XBoxSeriesXImagesFolderPath, ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(XBoxSeriesXImagesFolderPath)}"] ?? @"data\World\Features\Achievements\XBOX_ONE"); SetIfDefault(() => StadiaImagesFolderPath, ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(StadiaImagesFolderPath)}"] ?? @"data\World\Features\Achievements\GGP"); SetIfDefault(() => ImageMaxHeight, int.TryParse(ConfigurationManager.AppSettings[$"{nameof(GuinnessSettings)}.Default.{nameof(ImageMaxHeight)}"], out int imageMaxHeight) ? imageMaxHeight : 50); } } }