diff --git a/auto-creamapi/Models/CreamConfigModel.cs b/auto-creamapi/Models/CreamConfigModel.cs index 5c771e5..b48634b 100644 --- a/auto-creamapi/Models/CreamConfigModel.cs +++ b/auto-creamapi/Models/CreamConfigModel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; namespace auto_creamapi.Models { @@ -15,6 +16,20 @@ namespace auto_creamapi.Models public bool ExtraProtection { get; set; } public bool ForceOffline { get; set; } public List DlcList { get; set; } + + public override string ToString() + { + var value = $"AppID: {AppId}\n" + + $"Language: {Language}\n" + + $"UnlockAll: {UnlockAll}\n" + + $"ExtraProtection: {ExtraProtection}\n" + + $"ForceOffline: {ForceOffline}\n" + + $"DLC ({DlcList.Count}):\n[\n"; + if (DlcList.Count > 0) + value = DlcList.Aggregate(value, (current, x) => current + $" {x.AppId}={x.Name},\n"); + value += "]"; + return value; + } } public sealed class CreamConfigModel diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs index 3d18e68..2f2544d 100644 --- a/auto-creamapi/Services/CacheService.cs +++ b/auto-creamapi/Services/CacheService.cs @@ -17,8 +17,6 @@ namespace auto_creamapi.Services { public interface ICacheService { - public List Languages { get; } - public Task Initialize(); //public Task UpdateCache(); @@ -48,7 +46,6 @@ namespace auto_creamapi.Services public CacheService() { - Languages = Misc.DefaultLanguages; } /*public async void Initialize() @@ -57,8 +54,6 @@ namespace auto_creamapi.Services await UpdateCache(); }*/ - public List Languages { get; } - public async Task Initialize() { MyLogger.Log.Information("Updating cache..."); diff --git a/auto-creamapi/Services/CreamConfigService.cs b/auto-creamapi/Services/CreamConfigService.cs index 712e193..b331410 100644 --- a/auto-creamapi/Services/CreamConfigService.cs +++ b/auto-creamapi/Services/CreamConfigService.cs @@ -162,7 +162,7 @@ namespace auto_creamapi.Services private void ResetConfigData() { Config.AppId = -1; - Config.Language = ""; + Config.Language = Misc.DefaultLanguageSelection; Config.UnlockAll = false; Config.ExtraProtection = false; Config.ForceOffline = false; @@ -191,21 +191,7 @@ namespace auto_creamapi.Services public override string ToString() { - var str = $"INI file: {_configFilePath}, " + - $"AppID: {Config.AppId}, " + - $"Language: {Config.Language}, " + - $"UnlockAll: {Config.UnlockAll}, " + - $"ExtraProtection: {Config.ExtraProtection}, " + - $"ForceOffline: {Config.ForceOffline}, " + - $"DLC ({Config.DlcList.Count}):\n[\n"; - if (Config.DlcList.Count > 0) - str = Config.DlcList.Aggregate(str, (current, x) => current + $" {x.AppId}={x.Name},\n"); - /*foreach (var (key, value) in Config.DlcList) - { - str += $" {key}={value},\n"; - }*/ - - str += "]"; + var str = $"INI file: {_configFilePath}\n{Config}"; return str; } diff --git a/auto-creamapi/Utils/Misc.cs b/auto-creamapi/Utils/Misc.cs index 6a04bbd..2bd85a2 100644 --- a/auto-creamapi/Utils/Misc.cs +++ b/auto-creamapi/Utils/Misc.cs @@ -1,10 +1,13 @@ using System.Collections.Generic; +using System.Collections.ObjectModel; namespace auto_creamapi.Utils { public class Misc { - public static readonly List DefaultLanguages = new List(new[] + + public const string DefaultLanguageSelection = "english"; + public static readonly ObservableCollection DefaultLanguages = new ObservableCollection(new[] { "arabic", "bulgarian", diff --git a/auto-creamapi/ViewModels/MainViewModel.cs b/auto-creamapi/ViewModels/MainViewModel.cs index 5748753..b4ee4d9 100644 --- a/auto-creamapi/ViewModels/MainViewModel.cs +++ b/auto-creamapi/ViewModels/MainViewModel.cs @@ -16,7 +16,6 @@ namespace auto_creamapi.ViewModels { public class MainViewModel : MvxViewModel { - private const string DefaultLanguageSelection = "english"; private readonly ICacheService _cache; private readonly ICreamConfigService _config; @@ -51,6 +50,21 @@ namespace auto_creamapi.ViewModels //_download = download; } + public override async Task Initialize() + { + _config.Initialize(); + var tasks = new List {base.Initialize(), _cache.Initialize()}; + if (!File.Exists("steam_api.dll") | !File.Exists("steam_api64.dll")) + tasks.Add(_navigationService.Navigate()); + tasks.Add(_dll.Initialize()); + await Task.WhenAll(tasks); + Languages = new ObservableCollection(Misc.DefaultLanguages); + ResetForm(); + UseSteamDb = true; + MainWindowEnabled = true; + Status = "Ready."; + } + // // COMMANDS // // public IMvxCommand OpenFileCommand => new MvxCommand(OpenFile); @@ -105,7 +119,7 @@ namespace auto_creamapi.ViewModels { _appId = value; RaisePropertyChanged(() => AppId); - if (value > 0) SetNameById(); + SetNameById(); } } @@ -210,27 +224,6 @@ namespace auto_creamapi.ViewModels } } - public override async Task Initialize() - { - _config.Initialize(); - /*await base.Initialize(); - await _cache.Initialize(); - if (!File.Exists("steam_api.dll") | !File.Exists("steam_api64.dll")) - await _navigationService.Navigate(); - await _dll.Initialize();*/ - var tasks = new List {base.Initialize(), _cache.Initialize()}; - if (!File.Exists("steam_api.dll") | !File.Exists("steam_api64.dll")) - tasks.Add(_navigationService.Navigate()); - tasks.Add(_dll.Initialize()); - await Task.WhenAll(tasks); - Languages = new ObservableCollection(_cache.Languages); - ResetForm(); - Lang = DefaultLanguageSelection; - UseSteamDb = true; - MainWindowEnabled = true; - Status = "Ready."; - } - private void OpenFile() { Status = "Waiting for file..."; @@ -380,8 +373,12 @@ namespace auto_creamapi.ViewModels private void SetNameById() { - var appById = _cache.GetAppById(_appId); - GameName = appById != null ? appById.Name : ""; + if (_appId > 0) + { + var appById = _cache.GetAppById(_appId); + GameName = appById != null ? appById.Name : ""; + } + else GameName = ""; } } } \ No newline at end of file