Skip to content

Commit

Permalink
避免后缀输入空字符串时,因为文件被占用无法覆盖原始文件的情况。
Browse files Browse the repository at this point in the history
  • Loading branch information
Mapaler committed Aug 6, 2024
1 parent efde00b commit aed8ea9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Audi MMI MP3 Cover Repair/Audi MMI MP3 Cover Repair.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ApplicationIcon>Properties\aodi.ico</ApplicationIcon>
<VersionPrefix>2.1.0</VersionPrefix>
<VersionPrefix>2.1.1</VersionPrefix>
<Authors>枫谷剑仙</Authors>
<Copyright>Copyright © 2024 Mapaler</Copyright>
<Description>修复奥迪汽车多媒体平台 MP3 歌曲不能显示封面的问题</Description>
Expand Down
25 changes: 21 additions & 4 deletions Audi MMI MP3 Cover Repair/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
qualityOption.AddAlias("-q");
qualityOption.AddValidator(result =>
{
if (result.GetValueForOption(qualityOption) > 100)
byte quality = result.GetValueForOption(qualityOption);
if (quality > 100 || quality < 0)
{
result.ErrorMessage = $"Must be less than 100{Environment.NewLine}必须小于100";
result.ErrorMessage = $"JPEG quality can only be between 1-100.{Environment.NewLine}JPEG 质量只能位于 1-100 之间";
}
});

Expand All @@ -60,6 +61,13 @@
name: "--postfix",
description: $"The postfix of the new filename when same a new file. {Environment.NewLine}储存新文件时的后缀名。",
getDefaultValue: () => "-id3");
debugPostfixOption.AddValidator(result =>
{
if (result.GetValueForOption(saveModifiedAudioOption) && String.IsNullOrWhiteSpace(result.GetValueForOption(debugPostfixOption)))
{
result.ErrorMessage = $"When saving as a new file, you must have a filename postfix that is not empty.{Environment.NewLine}储存为新文件时必须拥有不为空的文件名后缀。";
}
});

var rootCommand = new RootCommand($"Fixed the issue that the cover picture of MP3 songs on Audi car MMI could not be displayed, and all the pictures in MP3 files were reduced to no larger than {defaultLength}×{defaultLength}, and the position was adjusted to Cover-Front." + Environment.NewLine +
$"修复奥迪汽车多媒体平台 MP3 歌曲不能显示封面的问题,将 MP3 文件的图片全部缩小到不大于 {defaultLength}×{defaultLength} ,位置调整到封面(Cover-Front)。");
Expand Down Expand Up @@ -205,13 +213,22 @@ static void ReadFile(FileInfo[] files, HandlerOptions aHandlerOptions)

// 添加封面
theTrack.EmbeddedPictures.Add(newPicture);
if (saveModifiedAudio)
string newFilename;

if (saveModifiedAudio &&
(newFilename = Path.Combine(file.DirectoryName, $"{Path.GetFileNameWithoutExtension(file.Name)}{debugPostfixPicture}{file.Extension}")) != theTrack.Path)
{
#if DEBUG
Console.WriteLine("储存到新文件 {0}", newFilename);
#endif
//储存到新文件
string newFilename = Path.Combine(file.DirectoryName, $"{Path.GetFileNameWithoutExtension(file.Name)}{debugPostfixPicture}{file.Extension}");
//newFilename = Path.Combine(file.DirectoryName, $"{Path.GetFileNameWithoutExtension(file.Name)}{debugPostfixPicture}{file.Extension}");
theTrack.SaveTo(newFilename);
} else
{
#if DEBUG
Console.WriteLine("保存到原始文件");
#endif
//保存到原始文件
theTrack.Save();
}
Expand Down
2 changes: 1 addition & 1 deletion Audi MMI MP3 Cover Repair/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Audi MMI MP3 Cover Repair": {
"commandName": "Project",
"commandLineArgs": "\"C:\\Users\\Mapaler\\Desktop\\あよ - 21世紀少女.mp3\""
"commandLineArgs": "\"C:\\Users\\Mapaler\\Desktop\\あよ - 21世紀少女.mp3\" --postfix \"\""
}
}
}

0 comments on commit aed8ea9

Please sign in to comment.