Skip to content

Commit

Permalink
Improve file open dialogs + update installer and zip to 1.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bertyhell committed Dec 26, 2018
1 parent fe91b94 commit b2a8d5c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 84 deletions.
Binary file modified PlaylistDownloader.exe
Binary file not shown.
Binary file modified PlaylistDownloader.zip
Binary file not shown.
4 changes: 0 additions & 4 deletions PlaylistDownloader/PlaylistDownloader/RunSettings.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
160 changes: 81 additions & 79 deletions PlaylistDownloader/PlaylistDownloader/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
using System;
using System.Configuration;
using NLog;
using Microsoft.Win32;

using Ookii.Dialogs.Wpf;
using Microsoft.Win32;

namespace PlaylistDownloader
{
Expand Down Expand Up @@ -84,47 +85,68 @@ 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,
FfmpegPath = Properties.Settings.Default.FfmpegPath,
SongsFolder = Properties.Settings.Default.OutputPath
};

// TODO 005: Get all settings from the configuration file

settings.IsDebug = _isDebugMode;
if (_isDebugMode)
{
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PlaylistDownloader 1.9.1
PlaylistDownloader 1.9.2
========================

Download your whole playlist with one click of a button
Expand Down

0 comments on commit b2a8d5c

Please sign in to comment.