Skip to content

Commit

Permalink
Merge branch 'release-1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Otiel committed Jun 16, 2019
2 parents 6765570 + 9ec1341 commit 24f5151
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 89 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# 1.2.0

## Improvements

* Minor UI improvements.
* Reduced exe file size by 1 MB.

## Bug fixes

* Fixed a regression that caused a crash when an album ends with a space followed by dot(s). [#111](https://github.com/Otiel/BandcampDownloader/issues/111)
* Fixed a bug (another one) preventing downloads from being cancelled in some conditions.
* Fixed some UI freeze when downloading big artwork files.

# 1.1.0

## Improvements
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<a href="https://github.com/Otiel/BandcampDownloader/releases/latest"><img alt="Download" src="docs/images/DownloadButton.png"></a>
</p>

[![build:master status](https://img.shields.io/appveyor/ci/Otiel/BandcampDownloader/master.svg?label=build:master&logo=appveyor)](https://ci.appveyor.com/project/Otiel/bandcampdownloader/branch/master) [![build:develop status](https://img.shields.io/appveyor/ci/Otiel/BandcampDownloader/develop.svg?label=build:develop&logo=appveyor)](https://ci.appveyor.com/project/Otiel/bandcampdownloader/branch/develop)

## Description

BandcampDownloader is a Windows application that helps downloading albums from [bandcamp.com](https://bandcamp.com) by retrieving the 128 kbps MP3 files streamed on the website. It aims to ease the life of those who prefer to listen to music on their favorite player rather than on their web browser, but offers only what is already freely available on Bandcamp.
Expand Down
8 changes: 4 additions & 4 deletions src/BandcampDownloader/BandcampDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.6.4\lib\net45\NLog.dll</HintPath>
<HintPath>..\packages\NLog.4.6.5\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="PlaylistsNET, Version=1.0.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\PlaylistsNET.1.0.4\lib\net45\PlaylistsNET.dll</HintPath>
Expand Down Expand Up @@ -139,8 +139,8 @@
<Reference Include="WPFLocalizeExtension, Version=3.3.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WPFLocalizeExtension.3.3.1\lib\net452\WPFLocalizeExtension.dll</HintPath>
</Reference>
<Reference Include="WpfMessageBox, Version=1.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WpfMessageBox.1.1.1\lib\net40-client\WpfMessageBox.dll</HintPath>
<Reference Include="WpfMessageBox, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WpfMessageBox.1.2.0\lib\net40-client\WpfMessageBox.dll</HintPath>
</Reference>
<Reference Include="XAMLMarkupExtensions, Version=1.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\XAMLMarkupExtensions.1.5.1\lib\net452\XAMLMarkupExtensions.dll</HintPath>
Expand All @@ -154,6 +154,7 @@
<Compile Include="Core\DownloadManager.cs" />
<Compile Include="Core\LogArgs.cs" />
<Compile Include="Helpers\LanguageHelper.cs" />
<Compile Include="Helpers\RichTextBoxHelper.cs" />
<Compile Include="Helpers\SystemVersionHelper.cs" />
<Compile Include="Helpers\ThemeHelper.cs" />
<Compile Include="Model\FileType.cs" />
Expand Down Expand Up @@ -216,7 +217,6 @@
<Compile Include="Helpers\LogHelper.cs" />
<Compile Include="Core\Constants.cs" />
<Compile Include="Core\LogType.cs" />
<Compile Include="Helpers\Extensions.cs" />
<Compile Include="Helpers\FileHelper.cs" />
<Compile Include="Core\UserSettings.cs" />
<Compile Include="UI\Dialogs\WindowMain.xaml.cs">
Expand Down
16 changes: 13 additions & 3 deletions src/BandcampDownloader/Core/DownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ private async Task<bool> DownloadAndTagTrackAsync(Album album, Track track, TagL
} catch (WebException ex) when (ex.Status == WebExceptionStatus.RequestCanceled) {
// Downloads cancelled by the user
return false;
} catch (TaskCanceledException) {
// Downloads cancelled by the user
return false;
} catch (WebException) {
// Connection closed probably because no response from Bandcamp
if (tries + 1 < App.UserSettings.DownloadMaxTries) {
Expand Down Expand Up @@ -285,6 +288,9 @@ private async Task<bool> DownloadAndTagTrackAsync(Album album, Track track, TagL
} catch (WebException ex) when (ex.Status == WebExceptionStatus.RequestCanceled) {
// Downloads cancelled by the user
return null;
} catch (TaskCanceledException) {
// Downloads cancelled by the user
return null;
} catch (WebException) {
// Connection closed probably because no response from Bandcamp
if (tries < App.UserSettings.DownloadMaxTries) {
Expand All @@ -307,9 +313,11 @@ private async Task<bool> DownloadAndTagTrackAsync(Album album, Track track, TagL
settings.MaxWidth = App.UserSettings.CoverArtInFolderMaxSize;
}

ImageBuilder.Current.Build(album.ArtworkTempPath, album.ArtworkPath, settings); // Save it to the album folder
await Task.Run(() => {
ImageBuilder.Current.Build(album.ArtworkTempPath, album.ArtworkPath, settings); // Save it to the album folder
});
} else if (App.UserSettings.SaveCoverArtInFolder) {
File.Copy(album.ArtworkTempPath, album.ArtworkPath, true);
await FileHelper.CopyFileAsync(album.ArtworkTempPath, album.ArtworkPath);
}

// Convert/resize artwork to be saved in tags
Expand All @@ -324,7 +332,9 @@ private async Task<bool> DownloadAndTagTrackAsync(Album album, Track track, TagL
settings.MaxWidth = App.UserSettings.CoverArtInTagsMaxSize;
}

ImageBuilder.Current.Build(album.ArtworkTempPath, album.ArtworkTempPath, settings); // Save it to %Temp%
await Task.Run(() => {
ImageBuilder.Current.Build(album.ArtworkTempPath, album.ArtworkTempPath, settings); // Save it to %Temp%
});
}
artworkInTags = new TagLib.Picture(album.ArtworkTempPath) {
Description = "Picture"
Expand Down
76 changes: 0 additions & 76 deletions src/BandcampDownloader/Helpers/Extensions.cs

This file was deleted.

59 changes: 57 additions & 2 deletions src/BandcampDownloader/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
using System;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace BandcampDownloader {

internal static class FileHelper {

/// <summary>
/// Asynchronously copies an existing file to a new file.
/// </summary>
/// <param name="sourceFile">The file to copy.</param>
/// <param name="destinationFile">The name of the destination file.</param>
public static async Task CopyFileAsync(string sourceFile, string destinationFile) {
// https://stackoverflow.com/a/35467471/825024
const FileOptions fileOptions = FileOptions.Asynchronous | FileOptions.SequentialScan;
const int bufferSize = 4096;

using (var sourceStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, fileOptions)) {
using (var destinationStream = new FileStream(destinationFile, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize, fileOptions)) {
await sourceStream.CopyToAsync(destinationStream);
}
}
}

/// <summary>
/// Returns the size of the file located at the provided URL.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="protocolMethod">The protocol method to use in order to retrieve the file
/// size.</param>
/// <param name="protocolMethod">The protocol method to use in order to retrieve the file size.</param>
/// <returns>The size of the file located at the provided URL.</returns>
public static async Task<long> GetFileSizeAsync(string url, string protocolMethod) {
WebRequest webRequest = HttpWebRequest.Create(url);
Expand All @@ -26,5 +44,42 @@ public static async Task<long> GetFileSizeAsync(string url, string protocolMetho
}
return fileSize;
}

/// <summary>
/// Replaces the forbidden characters \ / : * ? " &lt; &gt; | from the System.String object by an underscore _ in
/// order to be used for a Windows file or folder.
/// </summary>
public static string ToAllowedFileName(this string fileName) {
if (fileName == null) {
throw new ArgumentNullException(nameof(fileName));
}

// Rules are defined here: https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file

// Replace reserved characters by '_'
fileName = fileName.Replace("\\", "_");
fileName = fileName.Replace("/", "_");
fileName = fileName.Replace(":", "_");
fileName = fileName.Replace("*", "_");
fileName = fileName.Replace("?", "_");
fileName = fileName.Replace("\"", "_");
fileName = fileName.Replace("<", "_");
fileName = fileName.Replace(">", "_");
fileName = fileName.Replace("|", "_");

// Replace newline by '_'
fileName = fileName.Replace(Environment.NewLine, "_");

// Remove trailing dot(s)
fileName = Regex.Replace(fileName, @"\.+$", "");

// Replace whitespace(s) by ' '
fileName = Regex.Replace(fileName, @"\s+", " ");

// Remove trailing whitespace(s) /!\ Must be last
fileName = Regex.Replace(fileName, @"\s+$", "");

return fileName;
}
}
}
22 changes: 22 additions & 0 deletions src/BandcampDownloader/Helpers/LogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,27 @@ public static void LogExceptionToFile(Exception exception) {
logger.Log(LogLevel.Fatal, String.Format("{0} {1}", exception.GetType().ToString(), exception.Message));
logger.Log(LogLevel.Fatal, exception.StackTrace);
}

/// <summary>
/// Returns the NLog.LogLevel associated to the specified LogType.
/// </summary>
public static LogLevel ToNLogLevel(this LogType logType) {
switch (logType) {
case LogType.VerboseInfo:
return LogLevel.Debug;
case LogType.Info:
return LogLevel.Info;
case LogType.IntermediateSuccess:
return LogLevel.Info;
case LogType.Success:
return LogLevel.Info;
case LogType.Warning:
return LogLevel.Warn;
case LogType.Error:
return LogLevel.Error;
default:
throw new NotImplementedException();
}
}
}
}
14 changes: 14 additions & 0 deletions src/BandcampDownloader/Helpers/RichTextBoxHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Windows.Controls;

namespace BandcampDownloader {

internal static class RichTextBoxHelper {

/// <summary>
/// Returns true if scroll position of the current RichTextBox is at the end; false otherwise.
/// </summary>
public static bool IsScrolledToEnd(this RichTextBox richTextBox) {
return richTextBox.VerticalOffset > richTextBox.ExtentHeight - richTextBox.ViewportHeight - 10;
}
}
}
4 changes: 2 additions & 2 deletions src/BandcampDownloader/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyVersion("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: GuidAttribute("8C171C7F-9BAC-4EC0-A287-59908B48953F")]
Binary file modified src/BandcampDownloader/Resources/Cloud.ico
Binary file not shown.
1 change: 1 addition & 0 deletions src/BandcampDownloader/UI/Dialogs/WindowMain.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<Label
x:Name="labelProgress"
Grid.Column="2"
Margin="10,0,0,0"
HorizontalAlignment="Right"
HorizontalContentAlignment="Right"
Content="" />
Expand Down
4 changes: 2 additions & 2 deletions src/BandcampDownloader/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<package id="Markdig" version="0.16.0" targetFramework="net472" />
<package id="Markdig.Wpf" version="0.2.8" targetFramework="net472" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net472" />
<package id="NLog" version="4.6.4" targetFramework="net472" />
<package id="NLog" version="4.6.5" targetFramework="net472" />
<package id="PlaylistsNET" version="1.0.4" targetFramework="net472" />
<package id="Resource.Embedder" version="2.0.1" targetFramework="net472" />
<package id="taglib" version="2.1.0.0" targetFramework="net472" />
<package id="WPFLocalizeExtension" version="3.3.1" targetFramework="net472" />
<package id="WpfMessageBox" version="1.1.1" targetFramework="net472" />
<package id="WpfMessageBox" version="1.2.0" targetFramework="net472" />
<package id="XAMLMarkupExtensions" version="1.5.1" targetFramework="net472" />
</packages>

0 comments on commit 24f5151

Please sign in to comment.