diff --git a/PlaylistDownloader.exe b/PlaylistDownloader.exe index 3b170ef..fe34856 100644 Binary files a/PlaylistDownloader.exe and b/PlaylistDownloader.exe differ diff --git a/PlaylistDownloader.zip b/PlaylistDownloader.zip index 23890eb..81aa929 100644 Binary files a/PlaylistDownloader.zip and b/PlaylistDownloader.zip differ diff --git a/PlaylistDownloader/PlaylistDownloader/RunSettings.cs b/PlaylistDownloader/PlaylistDownloader/RunSettings.cs index 38be42b..d5173db 100644 --- a/PlaylistDownloader/PlaylistDownloader/RunSettings.cs +++ b/PlaylistDownloader/PlaylistDownloader/RunSettings.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace PlaylistDownloader { diff --git a/PlaylistDownloader/PlaylistDownloader/SettingsWindow.xaml.cs b/PlaylistDownloader/PlaylistDownloader/SettingsWindow.xaml.cs index ba52a10..0354061 100644 --- a/PlaylistDownloader/PlaylistDownloader/SettingsWindow.xaml.cs +++ b/PlaylistDownloader/PlaylistDownloader/SettingsWindow.xaml.cs @@ -9,8 +9,9 @@ using System; using System.Configuration; using NLog; -using Microsoft.Win32; + using Ookii.Dialogs.Wpf; +using Microsoft.Win32; namespace PlaylistDownloader { @@ -84,38 +85,61 @@ public SettingsWindow() private RunSettings InitializeRunSettings() { - string applicationFolder = Debugger.IsAttached - ? ".\\" - : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "PlaylistDownloader"); - - if (!Directory.Exists(applicationFolder)) - { - applicationFolder = ".\\"; - } - - if (!File.Exists(Properties.Settings.Default.YoutubeDlPath)) { - // set default path - Properties.Settings.Default.YoutubeDlPath = Path.Combine(applicationFolder, "youtube-dl.exe"); - } - ChooseYoutubePath_Click(null, null); + string applicationFolder = + //Debugger.IsAttached + //? ".\\" + //: + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PlaylistDownloader"); - if (!File.Exists(Properties.Settings.Default.FfmpegPath)) + // Find youtube-dl.exe + string[] youtubeDownloadPaths = new string[] { + Path.Combine(applicationFolder, "youtube-dl.exe"), + Path.Combine(".", "youtube-dl.exe") + }; + if (!File.Exists(Properties.Settings.Default.YoutubeDlPath)) { - // set default path - Properties.Settings.Default.FfmpegPath = Path.Combine(applicationFolder, "ffmpeg", "ffmpeg.exe"); + if (File.Exists(youtubeDownloadPaths[0])) + { + Properties.Settings.Default.YoutubeDlPath = youtubeDownloadPaths[0]; + } + else if (File.Exists(youtubeDownloadPaths[1])) + { + Properties.Settings.Default.YoutubeDlPath = youtubeDownloadPaths[1]; + } + else + { + // If it still doesn't find it => should never happen since either + // * the installer should install it in that directory + // * or the zip should contain it in the same folder as the playlist downloader exe + ChooseYoutubePathClick(null, null); + } } - ChooseFfmpegPath_Click(null, null); - - if (!Directory.Exists(Properties.Settings.Default.OutputPath)) + // Find ffmpeg.exe + string[] ffmpegPaths = new string[] { + Path.Combine(applicationFolder, "ffmpeg", "ffmpeg.exe"), + Path.Combine(".", "ffmpeg", "ffmpeg.exe") + }; + if (!File.Exists(Properties.Settings.Default.FfmpegPath)) { - // set default path - Properties.Settings.Default.OutputPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), "PlaylistDownloader"); + if (File.Exists(ffmpegPaths[0])) + { + Properties.Settings.Default.FfmpegPath = ffmpegPaths[0]; + } + else if (File.Exists(ffmpegPaths[1])) + { + Properties.Settings.Default.FfmpegPath = ffmpegPaths[1]; + } + else + { + // If it still doesn't find it => should never happen since either + // * the installer should install it in that directory + // * or the zip should contain it in the same folder as the playlist downloader exe + ChooseFfmpegPathClick(null, null); + } } - - var settings = new RunSettings { YoutubeDlPath = Properties.Settings.Default.YoutubeDlPath, @@ -123,8 +147,6 @@ private RunSettings InitializeRunSettings() SongsFolder = Properties.Settings.Default.OutputPath }; - // TODO 005: Get all settings from the configuration file - settings.IsDebug = _isDebugMode; if (_isDebugMode) { @@ -305,69 +327,49 @@ private void ButtonOpenFolderClick(object sender, RoutedEventArgs e) Process.Start(_runSettings.SongsFolder); } - private void ChooseYoutubePath_Click(object sender, RoutedEventArgs e) + private void ChooseYoutubePathClick(object sender, RoutedEventArgs e) { - var forceChooseDialog = false; - if (sender != null) + OpenFileDialog openFileDialog = new OpenFileDialog { - // user clicked choose button - forceChooseDialog = true; - } - - bool changed = false; - - while (!File.Exists(Properties.Settings.Default.YoutubeDlPath) || forceChooseDialog) + Filter = "Executable|*.exe", + Title = "Select youtube-dl.exe" + }; + bool? userClickedOk = openFileDialog.ShowDialog(); + if (userClickedOk == true) { - forceChooseDialog = false; - var ret = Microsoft.VisualBasic.Interaction.InputBox( - "Please enter full path to youtube-dl.exe", "Cannot find Youtube-dl", Properties.Settings.Default.YoutubeDlPath); - if (string.IsNullOrEmpty(ret)) - { - return; - } - else - { - Properties.Settings.Default.YoutubeDlPath = ret; - changed = true; - } + Properties.Settings.Default.YoutubeDlPath = openFileDialog.FileName; + Properties.Settings.Default.Save(); } - - if (changed) + else { - Properties.Settings.Default.Save(); + MessageBoxResult result = MessageBox.Show("Without youtube-dl.exe this application cannot function", + "Error", + MessageBoxButton.OK, + MessageBoxImage.Error); + Application.Current.Shutdown(); } } - private void ChooseFfmpegPath_Click(object sender, RoutedEventArgs e) + private void ChooseFfmpegPathClick(object sender, RoutedEventArgs e) { - var forceChooseDialog = false; - if (sender != null) + OpenFileDialog openFileDialog = new OpenFileDialog { - // user clicked choose button - forceChooseDialog = true; - } - - bool changed = false; - - while (!File.Exists(Properties.Settings.Default.FfmpegPath) || forceChooseDialog) + Filter = "Executable|*.exe", + Title = "Select ffmpeg.exe" + }; + bool? userClickedOk = openFileDialog.ShowDialog(); + if (userClickedOk == true) { - forceChooseDialog = false; - var ret = Microsoft.VisualBasic.Interaction.InputBox( - "Please enter full path to ffmpeg.exe", "Cannot find ffmpeg", Properties.Settings.Default.FfmpegPath); - if (string.IsNullOrEmpty(ret)) - { - return; - } - else - { - Properties.Settings.Default.FfmpegPath = ret; - changed = true; - } + Properties.Settings.Default.FfmpegPath = openFileDialog.FileName; + Properties.Settings.Default.Save(); } - - if (changed) + else { - Properties.Settings.Default.Save(); + MessageBoxResult result = MessageBox.Show("Without ffmpeg.exe this application cannot function", + "Error", + MessageBoxButton.OK, + MessageBoxImage.Error); + Application.Current.Shutdown(); } } @@ -376,13 +378,13 @@ private void ChooseOutputPathClick(object sender, RoutedEventArgs e) var dialog = new VistaFolderBrowserDialog { Description = "Select output folder", - UseDescriptionForTitle = true + UseDescriptionForTitle = true, + SelectedPath = Properties.Settings.Default.OutputPath }; bool? showDialog = dialog.ShowDialog(this); if (showDialog != null && (bool)showDialog) { Properties.Settings.Default.OutputPath = dialog.SelectedPath; - Directory.CreateDirectory(Properties.Settings.Default.OutputPath); Properties.Settings.Default.Save(); } } diff --git a/README.md b/README.md index c0997bc..4529669 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -PlaylistDownloader 1.9.1 +PlaylistDownloader 1.9.2 ======================== Download your whole playlist with one click of a button