refactor: reformat source code.

This commit is contained in:
real-zony 2022-02-03 18:10:53 +08:00
parent 089559d058
commit ba3dd5f1bc
16 changed files with 37 additions and 56 deletions

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;

View File

@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;

View File

@ -53,7 +53,7 @@ namespace ZonyLrcTools.Cli.Commands
{
_logger.LogInformation("开始扫描文件夹,请稍等...");
var files = (await _fileScanner.ScanAsync(FilePath, new[] {"*.ncm"}))
var files = (await _fileScanner.ScanAsync(FilePath, new[] { "*.ncm" }))
.SelectMany(f => f.FilePaths)
.ToList();
@ -95,7 +95,7 @@ namespace ZonyLrcTools.Cli.Commands
// TODO: Large Object Issue!!!!!
var result = await _musicDecryptor.ConvertMusic(memoryStream.ToArray());
var newFileName = Path.Combine(Path.GetDirectoryName(filePath),
$"{Path.GetFileNameWithoutExtension(filePath)}.{((JObject) result.ExtensionObjects["JSON"]).SelectToken("$.format").Value<string>()}");
$"{Path.GetFileNameWithoutExtension(filePath)}.{((JObject)result.ExtensionObjects["JSON"]).SelectToken("$.format").Value<string>()}");
await using var musicFileStream = File.Create(newFileName);
await musicFileStream.WriteAsync(result.Data);

View File

@ -44,7 +44,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Album.NetEase
true,
_defaultOption);
if (searchResult is not {StatusCode: 200} || searchResult.Items?.SongCount <= 0)
if (searchResult is not { StatusCode: 200 } || searchResult.Items?.SongCount <= 0)
{
throw new ErrorCodeException(ErrorCodes.NoMatchingSong);
}

View File

@ -39,7 +39,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Album.QQMusic
SearchApi,
requestParameter, _defaultOption);
return new byte[] {0x1, 0x2};
return new byte[] { 0x1, 0x2 };
}
}
}

View File

@ -4,17 +4,13 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel
{
public class GetLyricAccessKeyRequest
{
[JsonProperty("ver")]
public int UnknownParameters1 { get; }
[JsonProperty("ver")] public int UnknownParameters1 { get; }
[JsonProperty("man")]
public string UnknownParameters2 { get; }
[JsonProperty("man")] public string UnknownParameters2 { get; }
[JsonProperty("client")]
public string UnknownParameters3 { get; }
[JsonProperty("client")] public string UnknownParameters3 { get; }
[JsonProperty("hash")]
public string FileHash { get; }
[JsonProperty("hash")] public string FileHash { get; }
public GetLyricAccessKeyRequest(string fileHash)
{

View File

@ -5,22 +5,17 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel
{
public class GetLyricAccessKeyResponse
{
[JsonProperty("status")]
public int Status { get; set; }
[JsonProperty("status")] public int Status { get; set; }
[JsonProperty("errcode")]
public int ErrorCode { get; set; }
[JsonProperty("errcode")] public int ErrorCode { get; set; }
[JsonProperty("candidates")]
public List<GetLyricAccessKeyDataObject> AccessKeyDataObjects { get; set; }
[JsonProperty("candidates")] public List<GetLyricAccessKeyDataObject> AccessKeyDataObjects { get; set; }
}
public class GetLyricAccessKeyDataObject
{
[JsonProperty("accesskey")]
public string AccessKey { get; set; }
[JsonProperty("accesskey")] public string AccessKey { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("id")] public string Id { get; set; }
}
}

View File

@ -6,14 +6,11 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel
{
public class SongSearchRequest
{
[JsonProperty("filter")]
public int Filter { get; }
[JsonProperty("filter")] public int Filter { get; }
[JsonProperty("platform")]
public string Platform { get; }
[JsonProperty("platform")] public string Platform { get; }
[JsonProperty("keyword")]
public string Keyword { get; }
[JsonProperty("keyword")] public string Keyword { get; }
public SongSearchRequest(string musicName, string artistName)
{

View File

@ -5,23 +5,18 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel
{
public class SongSearchResponse
{
[JsonProperty("status")]
public int Status { get; set; }
[JsonProperty("status")] public int Status { get; set; }
[JsonProperty("data")]
public SongSearchResponseInnerData Data { get; set; }
[JsonProperty("data")] public SongSearchResponseInnerData Data { get; set; }
[JsonProperty("error_code")]
public int ErrorCode { get; set; }
[JsonProperty("error_code")] public int ErrorCode { get; set; }
[JsonProperty("error_msg")]
public string ErrorMessage { get; set; }
[JsonProperty("error_msg")] public string ErrorMessage { get; set; }
}
public class SongSearchResponseInnerData
{
[JsonProperty("lists")]
public List<SongSearchResponseSongDetail> List { get; set; }
[JsonProperty("lists")] public List<SongSearchResponseSongDetail> List { get; set; }
}
public class SongSearchResponseSongDetail

View File

@ -90,7 +90,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric
public static bool operator ==(LyricItem left, LyricItem right)
{
return (int?) left?.SortScore == (int?) right?.SortScore;
return (int?)left?.SortScore == (int?)right?.SortScore;
}
public static bool operator !=(LyricItem item1, LyricItem item2)
@ -113,7 +113,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((LyricItem) obj);
return Equals((LyricItem)obj);
}
public override int GetHashCode()

View File

@ -97,7 +97,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric
private static Dictionary<int, bool> BuildMarkDictionary(LyricItemCollection items)
{
return items
.Select((item, index) => new {index, item})
.Select((item, index) => new { index, item })
.ToDictionary(item => item.index, item => false);
}

View File

@ -70,7 +70,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic
protected virtual void ValidateSongSearchResponse(SongSearchResponse response, LyricDownloaderArgs args)
{
if (response is not {StatusCode: 0} || response.Data.Song.SongItems == null)
if (response is not { StatusCode: 0 } || response.Data.Song.SongItems == null)
{
throw new ErrorCodeException(ErrorCodes.TheReturnValueIsIllegal, attachObj: args);
}

View File

@ -14,8 +14,8 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption
/// </summary>
public class NcmMusicDecryptor : IMusicDecryptor, ITransientDependency
{
protected readonly byte[] AesCoreKey = {0x68, 0x7A, 0x48, 0x52, 0x41, 0x6D, 0x73, 0x6F, 0x35, 0x6B, 0x49, 0x6E, 0x62, 0x61, 0x78, 0x57};
protected readonly byte[] AesModifyKey = {0x23, 0x31, 0x34, 0x6C, 0x6A, 0x6B, 0x5F, 0x21, 0x5C, 0x5D, 0x26, 0x30, 0x55, 0x3C, 0x27, 0x28};
protected readonly byte[] AesCoreKey = { 0x68, 0x7A, 0x48, 0x52, 0x41, 0x6D, 0x73, 0x6F, 0x35, 0x6B, 0x49, 0x6E, 0x62, 0x61, 0x78, 0x57 };
protected readonly byte[] AesModifyKey = { 0x23, 0x31, 0x34, 0x6C, 0x6A, 0x6B, 0x5F, 0x21, 0x5C, 0x5D, 0x26, 0x30, 0x55, 0x3C, 0x27, 0x28 };
public async Task<DecryptionResult> ConvertMusic(byte[] sourceBytes)
{
@ -72,7 +72,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption
{
ExtensionObjects = new Dictionary<string, object>
{
{"JSON", musicInfoJson}
{ "JSON", musicInfoJson }
}
};
}
@ -105,10 +105,10 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption
byte[] box = new byte[256];
for (int i = 0; i < 256; ++i)
{
box[i] = (byte) i;
box[i] = (byte)i;
}
byte keyLength = (byte) key.Length;
byte keyLength = (byte)key.Length;
byte c;
byte lastByte = 0;
byte keyOffset = 0;
@ -117,7 +117,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption
for (int i = 0; i < 256; ++i)
{
swap = box[i];
c = (byte) ((swap + lastByte + key[keyOffset++]) & 0xff);
c = (byte)((swap + lastByte + key[keyOffset++]) & 0xff);
if (keyOffset >= keyLength)
{
@ -169,7 +169,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption
for (int i = 0; i < n; i++)
{
var j = (byte) ((i + 1) & 0xff);
var j = (byte)((i + 1) & 0xff);
tb[i] ^= sBox[sBox[j] + sBox[(sBox[j] + j) & 0xff] & 0xff];
}

View File

@ -123,7 +123,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Network
{
HttpStatusCode.OK => responseString,
HttpStatusCode.ServiceUnavailable => throw new ErrorCodeException(ErrorCodes.ServiceUnavailable),
_ => throw new ErrorCodeException(ErrorCodes.HttpRequestFailed, attachObj: new {requestParameters, responseString})
_ => throw new ErrorCodeException(ErrorCodes.HttpRequestFailed, attachObj: new { requestParameters, responseString })
};
}
@ -136,7 +136,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Network
/// <exception cref="ErrorCodeException">如果反序列化失败,则可能抛出本异常。</exception>
private TResponse ConvertHttpResponseToObject<TResponse>(object requestParameters, string responseString)
{
var throwException = new ErrorCodeException(ErrorCodes.HttpResponseConvertJsonFailed, attachObj: new {requestParameters, responseString});
var throwException = new ErrorCodeException(ErrorCodes.HttpResponseConvertJsonFailed, attachObj: new { requestParameters, responseString });
try
{