public void Update() { Logger.Info("Checking for update"); LastUpdateCheck = DateTimeOffset.Now; var hasUpdated = gameRepository.HasUpdated(game) || Filesystem.GetSaveFileLastWrite(game, Settings.Default.HotSeatFolder) < gameRepository.GetSaveGameLastModifiedTime(game); if (hasUpdated) { var remoteSavefileLastModified = gameRepository.GetSaveGameLastModifiedTime(game); var remoteFileIsNewer = SaveGameTime < remoteSavefileLastModified; if (remoteFileIsNewer) { Logger.Info($"Detected newer remote save file for {game}"); saveFileWatcher.EnableRaisingEvents = false; var fullSavefileName = Filesystem.GetHotSeatSaveFileFullName(Settings.Default.HotSeatFolder, Filesystem.GetSaveFileName(game)); game = gameRepository.UpdateGameAndSaveFile(game, fullSavefileName); FirePropertiesChanged(nameof(SaveGameTime), nameof(CurrentPlayer), nameof(Players), nameof(Name), nameof(IsMyTurn), nameof(LastUpdateCheck)); saveFileWatcher.EnableRaisingEvents = true; } } }
private void SaveFileWatcher_Changed(object sender, FileSystemEventArgs e) { var changeType = e.ChangeType; if (changeType != WatcherChangeTypes.Changed) { return; } var saveName = Path.GetFileNameWithoutExtension(e.FullPath); if (saveName != game.SavefileName) { return; } var fileName = e.FullPath; Logger.Debug($"Detected write to {fileName}"); var lastWrite = Filesystem.GetSaveFileLastWrite(game, Settings.Default.HotSeatFolder); game.LastUpdated = lastWrite; FirePropertyChanged(nameof(SaveGameTime)); }