Skip to content

Commit

Permalink
v 2.2.0
Browse files Browse the repository at this point in the history
Code Cleaning
Update NCMDumpCLI.csproj
  • Loading branch information
kingsznhone committed Mar 23, 2024
1 parent a27f693 commit c6fb4fb
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 35 deletions.
14 changes: 14 additions & 0 deletions NCMDump.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,34 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NCMDumpGUI", "NCMDumpGUI\NC
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6D29FF99-9A20-4AC2-8246-746C2AE4FB73}.Debug|Any CPU.ActiveCfg = Debug|x64
{6D29FF99-9A20-4AC2-8246-746C2AE4FB73}.Debug|Any CPU.Build.0 = Debug|x64
{6D29FF99-9A20-4AC2-8246-746C2AE4FB73}.Debug|x64.ActiveCfg = Debug|x64
{6D29FF99-9A20-4AC2-8246-746C2AE4FB73}.Debug|x64.Build.0 = Debug|x64
{6D29FF99-9A20-4AC2-8246-746C2AE4FB73}.Release|Any CPU.ActiveCfg = Release|x64
{6D29FF99-9A20-4AC2-8246-746C2AE4FB73}.Release|Any CPU.Build.0 = Release|x64
{6D29FF99-9A20-4AC2-8246-746C2AE4FB73}.Release|x64.ActiveCfg = Release|x64
{6D29FF99-9A20-4AC2-8246-746C2AE4FB73}.Release|x64.Build.0 = Release|x64
{4CB104C3-FE3A-4CF4-9910-5FB0150B22A6}.Debug|Any CPU.ActiveCfg = Debug|x64
{4CB104C3-FE3A-4CF4-9910-5FB0150B22A6}.Debug|Any CPU.Build.0 = Debug|x64
{4CB104C3-FE3A-4CF4-9910-5FB0150B22A6}.Debug|x64.ActiveCfg = Debug|x64
{4CB104C3-FE3A-4CF4-9910-5FB0150B22A6}.Debug|x64.Build.0 = Debug|x64
{4CB104C3-FE3A-4CF4-9910-5FB0150B22A6}.Release|Any CPU.ActiveCfg = Release|x64
{4CB104C3-FE3A-4CF4-9910-5FB0150B22A6}.Release|Any CPU.Build.0 = Release|x64
{4CB104C3-FE3A-4CF4-9910-5FB0150B22A6}.Release|x64.ActiveCfg = Release|x64
{4CB104C3-FE3A-4CF4-9910-5FB0150B22A6}.Release|x64.Build.0 = Release|x64
{F4B097C1-58BB-4A79-8997-8225639D2A92}.Debug|Any CPU.ActiveCfg = Debug|x64
{F4B097C1-58BB-4A79-8997-8225639D2A92}.Debug|Any CPU.Build.0 = Debug|x64
{F4B097C1-58BB-4A79-8997-8225639D2A92}.Debug|x64.ActiveCfg = Debug|x64
{F4B097C1-58BB-4A79-8997-8225639D2A92}.Debug|x64.Build.0 = Debug|x64
{F4B097C1-58BB-4A79-8997-8225639D2A92}.Release|Any CPU.ActiveCfg = Release|x64
{F4B097C1-58BB-4A79-8997-8225639D2A92}.Release|Any CPU.Build.0 = Release|x64
{F4B097C1-58BB-4A79-8997-8225639D2A92}.Release|x64.ActiveCfg = Release|x64
{F4B097C1-58BB-4A79-8997-8225639D2A92}.Release|x64.Build.0 = Release|x64
EndGlobalSection
Expand Down
4 changes: 2 additions & 2 deletions NCMDumpCLI/NCMDumpCLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks>net8.0-windows;</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartupObject>NCMDumpCLI</StartupObject>
<ApplicationIcon>NCMDump.ico</ApplicationIcon>
<PlatformTarget>x64</PlatformTarget>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>2.0.0</Version>
<Version>2.2.0</Version>
<Platforms>x64</Platforms>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion NCMDumpCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class NCMDumpCLI
{
public static void Main(string[] args)
{
NCMDump Core = new();
NCMDumper Core = new();

if (args.Length == 0)
{
Expand Down
11 changes: 5 additions & 6 deletions NCMDumpCore/MetaInfo.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System.Text.Json;

namespace NCMDumpCore
namespace NCMDumpCore
{
public class MetaInfo
{
public string musicId { get; set; }
public string musicName { get; set; }
public List<List<JsonElement>> artist { get; set; }
public List<List<string>> artist { get; set; }
public string albumId { get; set; }
public string album { get; set; }
public JsonElement albumPicDocId { get; set; }
public string albumPicDocId { get; set; }
public string albumPic { get; set; }
public int bitrate { get; set; }
public string mp3DocId { get; set; }
Expand All @@ -18,7 +16,8 @@ public class MetaInfo
public List<string> alias { get; set; }
public List<string> transNames { get; set; }
public string format { get; set; }
public JsonElement fee { get; set; }
public float fee { get; set; }
public float volumeDelta { get; set; }
public Dictionary<string, int> privilege { get; set; }
}
}
2 changes: 1 addition & 1 deletion NCMDumpCore/NCMDumpCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net8.0;</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.7.0</VersionPrefix>
<VersionPrefix>2.2.0</VersionPrefix>
<AssemblyVersion></AssemblyVersion>
<FileVersion></FileVersion>
<Platforms>x64</Platforms>
Expand Down
25 changes: 12 additions & 13 deletions NCMDumpCore/NCMDump.cs → NCMDumpCore/NCMDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@

namespace NCMDumpCore
{
public class NCMDump
public class NCMDumper
{
private readonly int vectorSize = Vector256<byte>.Count;
private readonly byte[] coreKey = { 0x68, 0x7A, 0x48, 0x52, 0x41, 0x6D, 0x73, 0x6F, 0x35, 0x6B, 0x49, 0x6E, 0x62, 0x61, 0x78, 0x57 };
private readonly byte[] metaKey = { 0x23, 0x31, 0x34, 0x6C, 0x6A, 0x6B, 0x5F, 0x21, 0x5C, 0x5D, 0x26, 0x30, 0x55, 0x3C, 0x27, 0x28 };

private bool ReadHeader(ref MemoryStream ms)
private bool VerifyHeader(ref MemoryStream ms)
{
// Header Should be "CTENFDAM"
Span<byte> header = stackalloc byte[8];
ms.Read(header);
// Header Should be "CTENFDAM"
return Enumerable.SequenceEqual(header.ToArray(), new byte[] { 067, 084, 069, 078, 070, 068, 065, 077 });
long header_num = MemoryMarshal.Read<long>(header);
return header_num == 0x4d4144464e455443;
//return Enumerable.SequenceEqual(header.ToArray(), new byte[] { 0x43, 0x54, 0x45, 0x4E, 0x46, 0x44, 0x41, 0x4D });
}

private byte[] ReadRC4Key(ref MemoryStream ms)
Expand Down Expand Up @@ -47,9 +49,8 @@ private byte[] ReadRC4Key(ref MemoryStream ms)
}

// decrypt keybox data
using (AesCng aes = new AesCng() { Key = coreKey, Mode = CipherMode.ECB })
using (var decrypter = new AesCng() { Key = coreKey, Mode = CipherMode.ECB }.CreateDecryptor())
{
var decrypter = aes.CreateDecryptor();
buffer = decrypter.TransformFinalBlock(buffer.ToArray(), 0, buffer.Length).Skip(17).ToArray(); // 17 = len("neteasecloudmusic")
}
return buffer.ToArray();
Expand Down Expand Up @@ -80,11 +81,9 @@ private MetaInfo ReadMeta(ref MemoryStream ms)
buffer = System.Convert.FromBase64String(Encoding.ASCII.GetString(buffer.ToArray()[22..]));

// decrypt meta data which is a json contains info of the song
using (AesCng aes = new AesCng() { Key = metaKey, Mode = CipherMode.ECB })
using (var cryptor = new AesCng() { Key = metaKey, Mode = CipherMode.ECB }.CreateDecryptor())
{
var cryptor = aes.CreateDecryptor();
buffer = cryptor.TransformFinalBlock(buffer.ToArray(), 0, buffer.Length);

var MetaJsonString = Encoding.UTF8.GetString(buffer).Replace("music:", "");
MetaInfo metainfo = JsonSerializer.Deserialize<MetaInfo>(MetaJsonString);
return metainfo;
Expand Down Expand Up @@ -125,7 +124,7 @@ private void AddTag(string fileName, byte[]? ImgData, MetaInfo metainfo)

//Add more infomation
tagfile.Tag.Title = metainfo.musicName;
tagfile.Tag.Performers = metainfo.artist.Select(x => x[0].GetString()).ToArray();
tagfile.Tag.Performers = metainfo.artist.Select(x => x[0]).ToArray();
tagfile.Tag.Album = metainfo.album;
tagfile.Tag.Subtitle = String.Join(@";", metainfo.alias);
tagfile.Save();
Expand Down Expand Up @@ -181,17 +180,17 @@ public async Task<bool> ConvertAsync(string path)
{
if (!System.IO.File.Exists(path))
{
Console.WriteLine("File Path Not Exist!");
Console.WriteLine($"File {path} Not Exist!");
return false;
}

//Read all bytes to ram.
MemoryStream ms = new MemoryStream(await System.IO.File.ReadAllBytesAsync(path));

//Verify Header
if (!ReadHeader(ref ms))
if (!VerifyHeader(ref ms))
{
Console.WriteLine("Not a NCM File");
Console.WriteLine($"{path} is not a NCM File");
return false;
}

Expand Down
42 changes: 41 additions & 1 deletion NCMDumpGUI/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
using Microsoft.Extensions.DependencyInjection;
using NCMDumpCore;
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows;

namespace NCMDumpGUI
{
public partial class App : Application
{
private IServiceProvider _serviceProvider;
private ObservableCollection<NCMProcessStatus> NCMCollection = new();

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();

OnDrop(e.Args.ToArray());
if (NCMCollection.Count > 0)
{
MainWindowViewModel vm = _serviceProvider.GetRequiredService<MainWindowViewModel>();
vm.NCMCollection = NCMCollection;
}
var mainWindow = _serviceProvider.GetRequiredService<MainWindow>();
mainWindow.Show();
}

private void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<NCMDump>();
services.AddSingleton<NCMDumper>();
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton<MainWindow>();
}
Expand All @@ -35,5 +46,34 @@ protected override void OnExit(ExitEventArgs e)

base.OnExit(e);
}

private void OnDrop(string[] args)
{
foreach (string _path in args)
{
if (new DirectoryInfo(_path).Exists)
{
WalkThrough(new DirectoryInfo(_path));
}
else if (new FileInfo(_path).Exists)
{
if (_path.EndsWith(@".ncm") && !NCMCollection.Any(x => x.FilePath == _path))
NCMCollection.Add(new NCMProcessStatus(_path, "Await"));
}
}
}

private void WalkThrough(DirectoryInfo dir)
{
foreach (DirectoryInfo d in dir.GetDirectories())
{
WalkThrough(d);
}
foreach (FileInfo f in dir.EnumerateFiles())
{
if (f.FullName.EndsWith(@".ncm") && !NCMCollection.Any(x => x.FilePath == f.FullName))
NCMCollection.Add(new NCMProcessStatus(f.FullName, "Await"));
}
}
}
}
3 changes: 2 additions & 1 deletion NCMDumpGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public MainWindow(MainWindowViewModel _vm)
VM = _vm;
this.DataContext = VM;
InitializeComponent();

if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 22000, 0))
{
SystemThemeWatcher.Watch(this);
Expand Down Expand Up @@ -42,6 +42,7 @@ private void DataGrid_SizeChanged(object sender, SizeChangedEventArgs e)
private void WorkingList_Drop(object sender, System.Windows.DragEventArgs e)
{
string[] args = (string[])e.Data.GetData(DataFormats.FileDrop);

if (args is not null && args.Length != 0)
{
VM.OnDrop(args);
Expand Down
19 changes: 10 additions & 9 deletions NCMDumpGUI/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace NCMDumpGUI
[ObservableObject]
public partial class MainWindowViewModel
{
private readonly NCMDump Core;
private readonly NCMDumper Core;

private bool _willDeleteNCM;

Expand All @@ -27,22 +27,22 @@ public bool WillDeleteNCM
set => SetProperty(ref _willDeleteNCM, value);
}

private string _ApplicationTitle;
private string _applicationTitle;

public string ApplicationTitle
{
get => _ApplicationTitle;
set => _ApplicationTitle = value;
get => _applicationTitle;
set => SetProperty(ref _applicationTitle, value);
}

public ObservableCollection<NCMProcessStatus> NCMCollection { get; set; }

public MainWindowViewModel(NCMDump _core)
public MainWindowViewModel(NCMDumper _core)
{
Core = _core;
WillDeleteNCM = true;
ApplicationTitle = "NCMDump.NET";
NCMCollection = new ObservableCollection<NCMProcessStatus>();
NCMCollection = new();
AddFolderCommand = new RelayCommand(FolderDialog);
AddFileCommand = new RelayCommand(FileDialog);
ClearCommand = new RelayCommand(ClearList);
Expand Down Expand Up @@ -148,7 +148,7 @@ private void FolderDialog()

private void FileDialog()
{
Microsoft.Win32.OpenFileDialog ofp = new Microsoft.Win32.OpenFileDialog();
Microsoft.Win32.OpenFileDialog ofp = new();
ofp.Multiselect = true;
ofp.Filter = "NCM File(*.ncm)|*.ncm";
if (ofp.ShowDialog() == true)
Expand All @@ -161,12 +161,13 @@ private void FileDialog()
}
}

private void SwitchTheme() {
private void SwitchTheme()
{
var appTheme = ApplicationThemeManager.GetAppTheme();
ApplicationTheme newTheme = appTheme == ApplicationTheme.Dark ? ApplicationTheme.Light : ApplicationTheme.Dark;

WindowBackdropType backdrop = WindowBackdropType.Acrylic;
if (newTheme ==ApplicationTheme.Dark)
if (newTheme == ApplicationTheme.Dark)
{
if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 22000, 0))
{
Expand Down
2 changes: 1 addition & 1 deletion NCMDumpGUI/NCMDumpGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<UseWPF>True</UseWPF>
<ApplicationIcon>NCMDump.ico</ApplicationIcon>
<Version>2.1.0</Version>
<Version>2.2.0</Version>
<Platforms>x64</Platforms>
</PropertyGroup>

Expand Down
7 changes: 7 additions & 0 deletions NCMDumpGUI/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"profiles": {
"NCMDumpGUI": {
"commandName": "Project"
}
}
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Keep ID3 tags and cover image.

## Changelog

### v2.2.0 2024.03.24

Code Cleaning.

### v2.1.0 2023.11.19

Fix some UI problem on Windows 10.
Expand Down

0 comments on commit c6fb4fb

Please sign in to comment.