Fixed issues with language selection

Fixed game name field not resetting properly
This commit is contained in:
Jeddunk 2020-12-29 12:32:04 +01:00
parent 933e84cdaa
commit a5ca4ceb33
5 changed files with 43 additions and 47 deletions

View File

@ -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<SteamApp> 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

View File

@ -17,8 +17,6 @@ namespace auto_creamapi.Services
{
public interface ICacheService
{
public List<string> 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<string> Languages { get; }
public async Task Initialize()
{
MyLogger.Log.Information("Updating cache...");

View File

@ -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;
}

View File

@ -1,10 +1,13 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace auto_creamapi.Utils
{
public class Misc
{
public static readonly List<string> DefaultLanguages = new List<string>(new[]
public const string DefaultLanguageSelection = "english";
public static readonly ObservableCollection<string> DefaultLanguages = new ObservableCollection<string>(new[]
{
"arabic",
"bulgarian",

View File

@ -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<Task> {base.Initialize(), _cache.Initialize()};
if (!File.Exists("steam_api.dll") | !File.Exists("steam_api64.dll"))
tasks.Add(_navigationService.Navigate<DownloadViewModel>());
tasks.Add(_dll.Initialize());
await Task.WhenAll(tasks);
Languages = new ObservableCollection<string>(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<DownloadViewModel>();
await _dll.Initialize();*/
var tasks = new List<Task> {base.Initialize(), _cache.Initialize()};
if (!File.Exists("steam_api.dll") | !File.Exists("steam_api64.dll"))
tasks.Add(_navigationService.Navigate<DownloadViewModel>());
tasks.Add(_dll.Initialize());
await Task.WhenAll(tasks);
Languages = new ObservableCollection<string>(_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 = "";
}
}
}