From a8ccfe2034edc66f284d0f86632cfa76c00d2e28 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 21 Jun 2021 22:45:43 -0700 Subject: [PATCH] Separate loading into a new method --- RedBookPlayer/PlayerView.xaml.cs | 67 ++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/RedBookPlayer/PlayerView.xaml.cs b/RedBookPlayer/PlayerView.xaml.cs index 411b101..f5ac532 100644 --- a/RedBookPlayer/PlayerView.xaml.cs +++ b/RedBookPlayer/PlayerView.xaml.cs @@ -220,6 +220,43 @@ namespace RedBookPlayer }; } + /// + /// Load an image from the path + /// + /// Path to the image to load + private async void LoadImage(string path) + { + bool result = await Task.Run(() => + { + var image = new AaruFormat(); + var filter = new ZZZNoFilter(); + filter.Open(path); + image.Open(filter); + + if(IsPlayableImage(image)) + { + PlayableDisc.Init(image, App.Settings.AutoPlay); + if(PlayableDisc.Initialized) + { + Player.Init(PlayableDisc, App.Settings.AutoPlay); + return true; + } + + return false; + } + else + return false; + }); + + if(result) + { + await Dispatcher.UIThread.InvokeAsync(() => + { + MainWindow.Instance.Title = "RedBookPlayer - " + path.Split('/').Last().Split('\\').Last(); + }); + } + } + /// /// Update the UI with the most recent information from the Player /// @@ -257,35 +294,7 @@ namespace RedBookPlayer if (path == null) return; - bool result = await Task.Run(() => - { - var image = new AaruFormat(); - var filter = new ZZZNoFilter(); - filter.Open(path); - image.Open(filter); - - if (IsPlayableImage(image)) - { - PlayableDisc.Init(image, App.Settings.AutoPlay); - if (PlayableDisc.Initialized) - { - Player.Init(PlayableDisc, App.Settings.AutoPlay); - return true; - } - - return false; - } - else - return false; - }); - - if (result) - { - await Dispatcher.UIThread.InvokeAsync(() => - { - MainWindow.Instance.Title = "RedBookPlayer - " + path.Split('/').Last().Split('\\').Last(); - }); - } + LoadImage(path); } public void PlayButton_Click(object sender, RoutedEventArgs e) => Player.Play();