public void Restore() { string filePath = GetFilePath(settings, window); RestoreWindowData data = StdUtils.XmlDeserializeFile <RestoreWindowData>(filePath); FitRestoreData(data); WindowState restoreState = settings.OverrideMinimized.HasValue && data.WindowState == WindowState.Minimized ? settings.OverrideMinimized.Value : data.WindowState; if (settings.RestoreWindowState && !window.IsLoaded) { window.WindowState = restoreState == WindowState.Normal ? WindowState.Normal : WindowState.Minimized; } if (settings.RestoreLeft) { window.Left = data.Left; } if (settings.RestoreTop) { window.Top = data.Top; } if (settings.RestoreWidth) { window.Width = data.Width; } if (settings.RestoreHeight) { window.Height = data.Height; } if (settings.RestoreWindowState) { if (!window.IsLoaded) { window.Loaded += Window_Loaded; } else { window.WindowState = restoreState; } } void Window_Loaded(object sender, RoutedEventArgs e) { window.Loaded -= Window_Loaded; window.WindowState = restoreState; } }
private void Load() { AudioServiceData data; if (!File.Exists(path)) { return; } try { data = StdUtils.XmlDeserializeFile <AudioServiceData>(path); } catch { return; } Service.Volume = data.Volume; IDictionary <string, Song> allSongs = new Dictionary <string, Song>(); Service.SourcePlaylists = data.SourcePlaylists.Select(playlistData => { Guid id = Guid.Parse(playlistData.ID); ISourcePlaylistBase playlist = Service.SourcePlaylists .FirstOrDefault(s => s.ID == id) ?? Service.CreateSourcePlaylist(id); MergePlaylist(playlist, playlistData); foreach (Song song in playlist.Songs) { allSongs[song.FullPath] = song; } return(playlist); }).ToArray(); Service.Playlists = data.Playlists.Select(playlistData => { Guid id = Guid.Parse(playlistData.ID); IPlaylistBase playlist = Service.Playlists .FirstOrDefault(s => s.ID == id) ?? Service.CreatePlaylist(id); playlistData.Songs = playlistData.Songs.Where(s => allSongs.ContainsKey(s.FullPath)).ToArray(); MergePlaylist(playlist, playlistData); return(playlist); }).ToArray(); if (string.IsNullOrWhiteSpace(data.CurrentPlaylistID)) { Service.CurrentPlaylist = null; } else { Guid currentPlaylistID = Guid.Parse(data.CurrentPlaylistID); Service.CurrentPlaylist = Service.GetAllPlaylists().FirstOrDefault(p => p.ID == currentPlaylistID); } }