Skip to content

Commit

Permalink
Updated version and check interval.
Browse files Browse the repository at this point in the history
  • Loading branch information
freezy committed Nov 10, 2015
1 parent 00f1bd7 commit 7e78b27
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
11 changes: 6 additions & 5 deletions Application/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public class GameManager : IGameManager
private readonly Subject<Unit> _initialized = new Subject<Unit>();
private bool _isInitialized;
private readonly List<Tuple<string, string, string>> _gamesToLink = new List<Tuple<string, string, string>>();
private IDisposable _gamesSubscription;

public GameManager(IMenuManager menuManager, IVpdbClient vpdbClient, ISettingsManager
settingsManager, IDownloadManager downloadManager, IDatabaseManager databaseManager,
Expand Down Expand Up @@ -172,9 +173,9 @@ public IGameManager Initialize()
}

// handle api authentication
_settingsManager.ApiAuthenticated.Subscribe(user => {
_logger.Info("Authenticated successfully.");
}, exception => _vpdbClient.HandleApiError(exception, "subscribing to ApiAuthenticated for printing something"));
// _settingsManager.ApiAuthenticated.Subscribe(user => {
// _logger.Info("Authenticated successfully.");
// }, exception => _vpdbClient.HandleApiError(exception, "subscribing to ApiAuthenticated for printing something"));

// initialize managers
_databaseManager.Initialize();
Expand All @@ -183,7 +184,7 @@ public IGameManager Initialize()
_versionManager.Initialize();

// validate settings and retrieve profile
Task.Run(() => _settingsManager.Validate());
Task.Run(async () => await _settingsManager.Validate());

return this;
}
Expand Down Expand Up @@ -236,7 +237,7 @@ private void SetupGameChanges()
.Select(_ => Unit.Default),
Platforms.Changed.Select(_ => Unit.Default)); // one of the platforms changes

whenPlatformsOrGamesInThosePlatformsChange
_gamesSubscription = whenPlatformsOrGamesInThosePlatformsChange
.StartWith(Unit.Default)
.Select(_ => Platforms.SelectMany(x => x.Games).ToList())
.Where(games => games.Count > 0)
Expand Down
2 changes: 1 addition & 1 deletion Application/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void OnValidationResult(Exception e, UserFull user)
{
System.Windows.Application.Current.Dispatcher.Invoke(delegate {
if (user != null) {
_apiAuthenticated.OnNext(user);
//_apiAuthenticated.OnNext(user);
AuthenticatedUser = user;
} else {
_apiAuthenticated.OnNext(null);
Expand Down
19 changes: 12 additions & 7 deletions Models/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Windows;
using Newtonsoft.Json;
using NLog;
using ReactiveUI;
Expand Down Expand Up @@ -157,10 +156,10 @@ private IEnumerable<Game> MergeGames(PinballXSystem system, GlobalDatabase db)
List<Game> mergedGames;
if (_database == null) {
_logger.Warn("No vpdb.json at {0}", DatabaseFile);
mergedGames = MergeGames(xmlGames, null, TablePath, db);
mergedGames = MergeGames(xmlGames, null, db);
} else {
_logger.Info("Found and parsed vpdb.json at {0}", DatabaseFile);
mergedGames = MergeGames(xmlGames, _database.Games, TablePath, db);
mergedGames = MergeGames(xmlGames, _database.Games, db);
}

return mergedGames;
Expand All @@ -172,20 +171,26 @@ private IEnumerable<Game> MergeGames(PinballXSystem system, GlobalDatabase db)
/// </summary>
/// <param name="xmlGames">Games read from an .XML file</param>
/// <param name="jsonGames">Games read from the internal .json database</param>
/// <param name="tablePath">Path to the table folder</param>
/// <param name="db">Reference to global database</param>
/// <returns>List of merged games</returns>
private List<Game> MergeGames(IEnumerable<PinballX.Models.Game> xmlGames, IEnumerable<Game> jsonGames, string tablePath, GlobalDatabase db)
private List<Game> MergeGames(IEnumerable<PinballX.Models.Game> xmlGames, IEnumerable<Game> jsonGames, GlobalDatabase db)
{
_logger.Info("MergeGames() START");

var games = new List<Game>();
var enumerableGames = jsonGames as Game[] ?? jsonGames.ToArray();
var enumerableXmlGames = xmlGames as PinballX.Models.Game[] ?? xmlGames.ToArray();

// ReSharper disable once LoopCanBeConvertedToQuery
foreach (var xmlGame in xmlGames) {
var jsonGame = jsonGames?.FirstOrDefault(g => (g.Id.Equals(xmlGame.Description)));
foreach (var xmlGame in enumerableXmlGames) {
var jsonGame = enumerableGames.FirstOrDefault(g => (g.Id.Equals(xmlGame.Description)));
games.Add(jsonGame == null
? new Game(xmlGame, this, db)
: jsonGame.Merge(xmlGame, this, db)
);
}

_logger.Info("MergeGames() DONE");
return games;
}

Expand Down
12 changes: 9 additions & 3 deletions ViewModels/Settings/SettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using NLog;
Expand Down Expand Up @@ -78,7 +79,12 @@ public SettingsViewModel(IScreen screen, ISettingsManager settingsManager, IVers
CloseSettings.InvokeCommand(HostScreen.Router, r => r.NavigateBack);

_settingsManager.WhenAnyValue(sm => sm.IsFirstRun).ToProperty(this, vm => vm.IsFirstRun, out _isFirstRun);
_settingsManager.WhenAnyValue(sm => sm.CanCancel).ToProperty(this, vm => vm.CanCancel, out _canCancel);
_settingsManager.WhenAnyValue(sm => sm.CanCancel)
.CombineLatest(screen.Router.NavigationStack.Changed, (canCancel, _) => canCancel || screen.Router.NavigationStack.Count > 1)
.DistinctUntilChanged()
.StartWith(true)
.ToProperty(this, vm => vm.CanCancel, out _canCancel);

}

public SettingsViewModel(IScreen screen, ISettingsManager settingsManager, IVersionManager versionManager, Dictionary<string, string> errors) : this(screen, settingsManager, versionManager)
Expand Down Expand Up @@ -116,10 +122,10 @@ private async Task<Dictionary<string, string>> Save()
_settingsManager.Save();
Logger.Info("Settings saved.");

if (firstRun) {
if (HostScreen.Router.NavigationStack.Count == 1) {
HostScreen.Router.NavigateAndReset.Execute(new MainViewModel(HostScreen, _settingsManager, _versionManager));
} else {
HostScreen.Router.Navigate.Execute(new MainViewModel(HostScreen, _settingsManager, _versionManager));
HostScreen.Router.NavigateBack.Execute(null);
}

} else {
Expand Down

0 comments on commit 7e78b27

Please sign in to comment.