Marked util classes as static (#460)

* Marked util classes as static

* Used file-scoped namespaces
This commit is contained in:
irodai-majom 2024-11-10 09:15:30 +01:00 committed by GitHub
parent 8a25815c1f
commit 9fc37d5b61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 1560 additions and 1588 deletions

View File

@ -8,9 +8,9 @@ using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Common.Util
{
public class GlobalUtil
namespace N_m3u8DL_RE.Common.Util;
public static class GlobalUtil
{
private static readonly JsonSerializerOptions Options = new JsonSerializerOptions
{
@ -77,4 +77,3 @@ namespace N_m3u8DL_RE.Common.Util
return searchPath.Concat(envPath).Select(p => Path.Combine(p, name + fileExt)).FirstOrDefault(File.Exists);
}
}
}

View File

@ -3,9 +3,9 @@ using System.Net.Http.Headers;
using N_m3u8DL_RE.Common.Log;
using N_m3u8DL_RE.Common.Resource;
namespace N_m3u8DL_RE.Common.Util
{
public class HTTPUtil
namespace N_m3u8DL_RE.Common.Util;
public static class HTTPUtil
{
public static readonly HttpClientHandler HttpClientHandler = new()
{
@ -138,4 +138,3 @@ namespace N_m3u8DL_RE.Common.Util
return htmlCode;
}
}
}

View File

@ -1,12 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Common.Util;
namespace N_m3u8DL_RE.Common.Util
{
public class HexUtil
public static class HexUtil
{
public static string BytesToHex(byte[] data, string split = "")
{
@ -43,4 +37,3 @@ namespace N_m3u8DL_RE.Common.Util
return Convert.FromHexString(hexSpan);
}
}
}

View File

@ -4,7 +4,7 @@ using Spectre.Console;
namespace N_m3u8DL_RE.Common.Util;
public class RetryUtil
public static class RetryUtil
{
public static async Task<T?> WebRequestRetryAsync<T>(Func<Task<T>> funcAsync, int maxRetries = 10, int retryDelayMilliseconds = 1500, int retryDelayIncrementMilliseconds = 0)
{

View File

@ -6,9 +6,9 @@ using System.IO;
using System.Net;
using System.Net.Http.Headers;
namespace N_m3u8DL_RE.Util
{
internal class DownloadUtil
namespace N_m3u8DL_RE.Util;
internal static class DownloadUtil
{
private static readonly HttpClient AppHttpClient = HTTPUtil.AppHttpClient;
@ -143,4 +143,3 @@ namespace N_m3u8DL_RE.Util
}
}
}
}

View File

@ -11,9 +11,9 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Util
{
public class FilterUtil
namespace N_m3u8DL_RE.Util;
public static class FilterUtil
{
public static List<StreamSpec> DoFilterKeep(IEnumerable<StreamSpec> lists, StreamFilter? filter)
{
@ -281,4 +281,3 @@ namespace N_m3u8DL_RE.Util
}
}
}
}

View File

@ -1,13 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Util;
namespace N_m3u8DL_RE.Util
{
internal class ImageHeaderUtil
internal static class ImageHeaderUtil
{
public static bool IsImageHeader(byte[] bArr)
{
@ -86,4 +79,3 @@ namespace N_m3u8DL_RE.Util
await File.WriteAllBytesAsync(sourcePath, sourceData);
}
}
}

View File

@ -6,8 +6,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Util
{
namespace N_m3u8DL_RE.Util;
class Language
{
public string Code;
@ -24,9 +24,8 @@ namespace N_m3u8DL_RE.Util
}
}
internal class LanguageCodeUtil
internal static class LanguageCodeUtil
{
private LanguageCodeUtil() { }
private readonly static List<Language> ALL_LANGS = @"
af;afr;Afrikaans;Afrikaans
@ -544,4 +543,3 @@ sr;srp
if (string.IsNullOrEmpty(outputFile.Description)) outputFile.Description = originalLangCode;
}
}
}

View File

@ -9,9 +9,9 @@ using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Util
{
internal class LargeSingleFileSplitUtil
namespace N_m3u8DL_RE.Util;
internal static class LargeSingleFileSplitUtil
{
class Clip
{
@ -119,4 +119,3 @@ namespace N_m3u8DL_RE.Util
return clips;
}
}
}

View File

@ -5,9 +5,9 @@ using N_m3u8DL_RE.Config;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace N_m3u8DL_RE.Util
{
internal class MP4DecryptUtil
namespace N_m3u8DL_RE.Util;
internal static class MP4DecryptUtil
{
private static string ZeroKid = "00000000000000000000000000000000";
public static async Task<bool> DecryptAsync(bool shakaPackager, string bin, string[]? keys, string source, string dest, string? kid, string init = "", bool isMultiDRM=false)
@ -185,4 +185,3 @@ namespace N_m3u8DL_RE.Util
return ShakaKeyIDRegex.Match(errorOutput).Groups[1].Value;
}
}
}

View File

@ -8,9 +8,9 @@ using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace N_m3u8DL_RE.Util
{
internal partial class MediainfoUtil
namespace N_m3u8DL_RE.Util;
internal static partial class MediainfoUtil
{
[GeneratedRegex(" Stream #.*")]
private static partial Regex TextRegex();
@ -96,4 +96,3 @@ namespace N_m3u8DL_RE.Util
return result;
}
}
}

View File

@ -5,9 +5,9 @@ using System.Diagnostics;
using System.Text;
using N_m3u8DL_RE.Enum;
namespace N_m3u8DL_RE.Util
{
internal class MergeUtil
namespace N_m3u8DL_RE.Util;
internal static class MergeUtil
{
/// <summary>
/// 输入一堆已存在的文件,合并到新文件
@ -291,4 +291,3 @@ namespace N_m3u8DL_RE.Util
return code == 0;
}
}
}

View File

@ -6,8 +6,8 @@ using System.IO.Compression;
using System.Text;
using System.Text.RegularExpressions;
namespace N_m3u8DL_RE.Util
{
namespace N_m3u8DL_RE.Util;
internal class OtherUtil
{
public static Dictionary<string, string> SplitHeaderArrayToDic(string[]? headers)
@ -177,4 +177,3 @@ namespace N_m3u8DL_RE.Util
};
}
}
}

View File

@ -10,9 +10,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Util
{
internal class PipeUtil
namespace N_m3u8DL_RE.Util;
internal static class PipeUtil
{
public static Stream CreatePipe(string pipeName)
{
@ -110,4 +110,3 @@ namespace N_m3u8DL_RE.Util
return p.ExitCode == 0;
}
}
}

View File

@ -7,9 +7,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Util
{
internal class SubtitleUtil
namespace N_m3u8DL_RE.Util;
internal static class SubtitleUtil
{
/// <summary>
/// 写出图形字幕PNG文件
@ -37,4 +37,3 @@ namespace N_m3u8DL_RE.Util
else return false;
}
}
}