Skip to content

Commit

Permalink
Fix ReplaceInvalidFilenameChars throwing on null input & add some nul…
Browse files Browse the repository at this point in the history
…l annotations
  • Loading branch information
ScrubN committed Jun 15, 2024
1 parent cebee28 commit 38103d3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions TwitchDownloaderCore/Tools/FilenameService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Text;
Expand All @@ -9,7 +10,7 @@ namespace TwitchDownloaderCore.Tools
{
public static class FilenameService
{
public static string GetFilename(string template, string title, string id, DateTime date, string channel, TimeSpan trimStart, TimeSpan trimEnd, long viewCount, string game)
public static string GetFilename(string template, [AllowNull] string title, [AllowNull] string id, DateTime date, [AllowNull] string channel, TimeSpan trimStart, TimeSpan trimEnd, long viewCount, [AllowNull] string game)
{
var videoLength = trimEnd - trimStart;

Expand Down Expand Up @@ -86,8 +87,14 @@ private static string[] GetTemplateSubfolders(ref string fullPath)

private static readonly char[] FilenameInvalidChars = Path.GetInvalidFileNameChars();

public static string ReplaceInvalidFilenameChars(string filename)
[return: NotNullIfNotNull(nameof(filename))]
public static string ReplaceInvalidFilenameChars([AllowNull] string filename)
{
if (string.IsNullOrEmpty(filename))
{
return filename;
}

const string TIMESTAMP_PATTERN = /*lang=regex*/ @"(?<=\d):(?=\d\d)";
var newName = Regex.Replace(filename, TIMESTAMP_PATTERN, "_");

Expand Down

0 comments on commit 38103d3

Please sign in to comment.