Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Otiel committed Feb 28, 2022
2 parents 4e8e3e1 + 9a007cd commit d3a59b0
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 53 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 1.4.1

## Improvements

* Added / updated translations thanks to contributors. [#203](https://github.com/Otiel/BandcampDownloader/pull/203) [#205](https://github.com/Otiel/BandcampDownloader/pull/205)

## Bug fixes

* Fixed an issue when trying to download tracks containing special characters in their title. [#189](https://github.com/Otiel/BandcampDownloader/issues/189)

# 1.4.0

## New features
Expand Down
35 changes: 16 additions & 19 deletions src/BandcampDownloader/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,14 @@ 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, "_");
fileName = fileName.ReplaceInvalidPathCharacters('_');

// Remove trailing dot(s)
fileName = Regex.Replace(fileName, @"\.+$", "");
Expand All @@ -91,5 +73,20 @@ public static string ToAllowedFileName(this string fileName)

return fileName;
}

private static string ReplaceInvalidPathCharacters(this string path, char replaceBy)
{
foreach (var invalidCharacter in Path.GetInvalidPathChars())
{
path = path.Replace(invalidCharacter, replaceBy);
}

foreach (var invalidCharacter in Path.GetInvalidFileNameChars())
{
path = path.Replace(invalidCharacter, replaceBy);
}

return path;
}
}
}
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.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
[assembly: GuidAttribute("8C171C7F-9BAC-4EC0-A287-59908B48953F")]
Loading

0 comments on commit d3a59b0

Please sign in to comment.