Update to MvvmCross 8; Replace SteamfrontendAPI with fork to fix DLC issues; code refactoring
This commit is contained in:
parent
991f52e87e
commit
95361440f6
12 changed files with 89 additions and 35 deletions
|
@ -5,6 +5,7 @@ using System.Windows;
|
|||
using auto_creamapi.Messenger;
|
||||
using auto_creamapi.Services;
|
||||
using auto_creamapi.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MvvmCross.Logging;
|
||||
using MvvmCross.Navigation;
|
||||
using MvvmCross.Plugin.Messenger;
|
||||
|
@ -12,24 +13,26 @@ using MvvmCross.ViewModels;
|
|||
|
||||
namespace auto_creamapi.ViewModels
|
||||
{
|
||||
|
||||
|
||||
public class DownloadViewModel : MvxNavigationViewModel
|
||||
{
|
||||
private readonly IDownloadCreamApiService _download;
|
||||
private readonly IMvxNavigationService _navigationService;
|
||||
private readonly MvxSubscriptionToken _token;
|
||||
private readonly ILogger<DownloadViewModel> _logger;
|
||||
private string _filename;
|
||||
|
||||
private string _info;
|
||||
private double _progress;
|
||||
|
||||
public DownloadViewModel(IMvxLogProvider logProvider, IMvxNavigationService navigationService,
|
||||
IDownloadCreamApiService download, IMvxMessenger messenger) : base(logProvider, navigationService)
|
||||
public DownloadViewModel(ILoggerFactory loggerFactory, IMvxNavigationService navigationService,
|
||||
IDownloadCreamApiService download, IMvxMessenger messenger) : base(loggerFactory, navigationService)
|
||||
{
|
||||
_navigationService = navigationService;
|
||||
_logger = loggerFactory.CreateLogger<DownloadViewModel>();
|
||||
_download = download;
|
||||
_token = messenger.Subscribe<ProgressMessage>(OnProgressMessage);
|
||||
MyLogger.Log.Debug("{Count}", messenger.CountSubscriptionsFor<ProgressMessage>());
|
||||
_logger.LogDebug("{Count}", messenger.CountSubscriptionsFor<ProgressMessage>());
|
||||
}
|
||||
|
||||
public string InfoLabel
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
|||
using auto_creamapi.Models;
|
||||
using auto_creamapi.Services;
|
||||
using auto_creamapi.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Win32;
|
||||
using MvvmCross.Commands;
|
||||
using MvvmCross.Navigation;
|
||||
|
@ -19,6 +20,7 @@ namespace auto_creamapi.ViewModels
|
|||
private readonly ICacheService _cache;
|
||||
private readonly ICreamConfigService _config;
|
||||
|
||||
private readonly ILogger<MainViewModel> _logger;
|
||||
private readonly ICreamDllService _dll;
|
||||
private readonly IMvxNavigationService _navigationService;
|
||||
private int _appId;
|
||||
|
@ -43,9 +45,10 @@ namespace auto_creamapi.ViewModels
|
|||
//private const string DlcRegexPattern = @"(?<id>.*) *= *(?<name>.*)";
|
||||
|
||||
public MainViewModel(ICacheService cache, ICreamConfigService config, ICreamDllService dll,
|
||||
IMvxNavigationService navigationService)
|
||||
IMvxNavigationService navigationService, ILoggerFactory loggerFactory)
|
||||
{
|
||||
_navigationService = navigationService;
|
||||
_logger = loggerFactory.CreateLogger<MainViewModel>();
|
||||
_cache = cache;
|
||||
_config = config;
|
||||
_dll = dll;
|
||||
|
@ -56,7 +59,7 @@ namespace auto_creamapi.ViewModels
|
|||
{
|
||||
base.Prepare();
|
||||
_config.Initialize();
|
||||
var tasks = new List<Task> {_cache.Initialize()};
|
||||
var tasks = new List<Task> { _cache.Initialize() };
|
||||
if (!File.Exists("steam_api.dll") | !File.Exists("steam_api64.dll"))
|
||||
tasks.Add(_navigationService.Navigate<DownloadViewModel>());
|
||||
//tasks.Add(_navigationService.Navigate<DownloadViewModel>());
|
||||
|
@ -310,7 +313,7 @@ namespace auto_creamapi.ViewModels
|
|||
}
|
||||
else
|
||||
{
|
||||
MyLogger.Log.Warning("Empty game name, cannot initiate search!");
|
||||
_logger.LogWarning("Empty game name, cannot initiate search!");
|
||||
}
|
||||
|
||||
MainWindowEnabled = true;
|
||||
|
@ -321,7 +324,7 @@ namespace auto_creamapi.ViewModels
|
|||
Status = "Trying to get DLC...";
|
||||
if (AppId > 0)
|
||||
{
|
||||
var app = new SteamApp {AppId = AppId, Name = GameName};
|
||||
var app = new SteamApp { AppId = AppId, Name = GameName };
|
||||
var task = _cache.GetListOfDlc(app, UseSteamDb, IgnoreUnknown);
|
||||
MainWindowEnabled = false;
|
||||
var listOfDlc = await task.ConfigureAwait(false);
|
||||
|
@ -341,7 +344,7 @@ namespace auto_creamapi.ViewModels
|
|||
else
|
||||
{
|
||||
Status = $"Could not get DLC for AppID {AppId}";
|
||||
MyLogger.Log.Error("GetListOfDlc: Invalid AppID {AppId}", AppId);
|
||||
_logger.LogError("GetListOfDlc: Invalid AppID {AppId}", AppId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -392,7 +395,7 @@ namespace auto_creamapi.ViewModels
|
|||
}
|
||||
else
|
||||
{
|
||||
MyLogger.Log.Error("OpenURL: Invalid AppID {AppId}", AppId);
|
||||
_logger.LogError("OpenURL: Invalid AppID {AppId}", AppId);
|
||||
Status = $"Could not open URL: Invalid AppID {AppId}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||
using System.Threading.Tasks;
|
||||
using auto_creamapi.Models;
|
||||
using auto_creamapi.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MvvmCross.Commands;
|
||||
using MvvmCross.Logging;
|
||||
using MvvmCross.Navigation;
|
||||
|
@ -13,16 +14,18 @@ namespace auto_creamapi.ViewModels
|
|||
IMvxViewModel<IEnumerable<SteamApp>, SteamApp>
|
||||
{
|
||||
private readonly IMvxNavigationService _navigationService;
|
||||
private readonly ILogger<SearchResultViewModel> _logger;
|
||||
private IEnumerable<SteamApp> _steamApps;
|
||||
|
||||
/*public override async Task Initialize()
|
||||
{
|
||||
await base.Initialize();
|
||||
}*/
|
||||
public SearchResultViewModel(IMvxLogProvider logProvider, IMvxNavigationService navigationService) : base(
|
||||
logProvider, navigationService)
|
||||
public SearchResultViewModel(ILoggerFactory loggerFactory, IMvxNavigationService navigationService) : base(
|
||||
loggerFactory, navigationService)
|
||||
{
|
||||
_navigationService = navigationService;
|
||||
_logger = loggerFactory.CreateLogger<SearchResultViewModel>();
|
||||
}
|
||||
|
||||
public IEnumerable<SteamApp> Apps
|
||||
|
@ -55,9 +58,11 @@ namespace auto_creamapi.ViewModels
|
|||
|
||||
public override void ViewDestroy(bool viewFinishing = true)
|
||||
{
|
||||
if (viewFinishing && CloseCompletionSource != null && !CloseCompletionSource.Task.IsCompleted &&
|
||||
if (viewFinishing && CloseCompletionSource?.Task.IsCompleted == false &&
|
||||
!CloseCompletionSource.Task.IsFaulted)
|
||||
{
|
||||
CloseCompletionSource?.TrySetCanceled();
|
||||
}
|
||||
|
||||
base.ViewDestroy(viewFinishing);
|
||||
}
|
||||
|
@ -66,7 +71,7 @@ namespace auto_creamapi.ViewModels
|
|||
{
|
||||
if (Selected != null)
|
||||
{
|
||||
MyLogger.Log.Information("Successfully got app {Selected}", Selected);
|
||||
_logger.LogInformation("Successfully got app {Selected}", Selected);
|
||||
await _navigationService.Close(this, Selected).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue