Skip to content

Commit

Permalink
新增进度条
Browse files Browse the repository at this point in the history
  • Loading branch information
WhatDamon committed Aug 20, 2024
1 parent 9f0bf0c commit 9fcbed1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
17 changes: 16 additions & 1 deletion WndMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions WndMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ namespace NCMDumpGUI
{
public partial class WndMain : Form
{
// 初始化
public WndMain()
{
InitializeComponent();
toolTip.SetToolTip(fixMetaDataCheckBox, "将歌曲的详细信息添加到转换后的文件\n注意:不能保证100%正常工作,部分元数据可能无法修复!");
toolTip.SetToolTip(convertButton, "点击开始转换文件到能被主流播放器识别的格式");
}

// 窗口标题栏右键菜单
#region fields
private const int WM_SYSCOMMAND = 0X112;
private const int MF_STRING = 0X0;
private const int MF_SEPARATOR = 0X800;
private enum SystemMenuItem : int
{
About,
FeedBack,
}
#endregion

Expand Down Expand Up @@ -59,13 +62,14 @@ protected override void WndProc(ref Message m)
switch ((SystemMenuItem)m.WParam)
{
case SystemMenuItem.About:
MessageBox.Show("NCMDumpGUI v1.0.0.2\n基于libncmdump开发", "关于", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("NCMDumpGUI v1.0.0.2\n基于libncmdump开发\n仅供学习使用", "关于", MessageBoxButtons.OK, MessageBoxIcon.Information);
break;
}
}
}
#endregion

// “浏览”按钮被点击
private void browseButton_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
Expand All @@ -77,6 +81,7 @@ private void browseButton_Click(object sender, EventArgs e)
}
}

// 检查ncm二进制文件
private bool CheckNCMBinary(string filePath)
{
string correctHeader = "CTENFDAM";
Expand All @@ -93,6 +98,7 @@ private bool CheckNCMBinary(string filePath)
string header = Encoding.ASCII.GetString(bytes);
if (header == correctHeader)
{
toolStripProgressBar1.Value += 1;
return true;
}
else
Expand All @@ -118,6 +124,7 @@ private bool CheckNCMBinary(string filePath)
}
}

// 检查路径合法性
public static bool IsValidFilePath(string path)
{
if (Path.GetInvalidPathChars().Any(c => path.Contains(c)))
Expand All @@ -135,6 +142,7 @@ public static bool IsValidFilePath(string path)
}
}

// “转换”按钮被点击
private void convertButton_Click(object sender, EventArgs e)
{
if (filepathTextBox.Text == "")
Expand Down Expand Up @@ -163,10 +171,13 @@ private void convertButton_Click(object sender, EventArgs e)
browseButton.Enabled = false;
convertButton.Enabled = false;
NeteaseCrypt neteaseCrypt = new NeteaseCrypt(filepathTextBox.Text);
toolStripProgressBar1.Value += 1;
int result = neteaseCrypt.Dump();
toolStripProgressBar1.Value += 1;
if (fixMetaDataCheckBox.Checked)
{
neteaseCrypt.FixMetadata();
toolStripProgressBar1.Value += 1;
}
neteaseCrypt.Destroy();
if (result != 0)
Expand All @@ -176,13 +187,16 @@ private void convertButton_Click(object sender, EventArgs e)
else
{
toolStripStatusLabel2.Text = "转换完成!文件在ncm歌曲同级目录下";
toolStripProgressBar1.Value += 1;
}
filepathTextBox.Enabled = true;
browseButton.Enabled = true;
convertButton.Enabled = true;
toolStripProgressBar1.Value = 0;
}
}

// 窗口键盘事件
public void WndMain_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
Expand All @@ -191,6 +205,7 @@ public void WndMain_KeyDown(object sender, KeyEventArgs e)
}
}

// 文件拖入
private void WndMain_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
Expand All @@ -207,5 +222,19 @@ private void WndMain_DragDrop(object sender, DragEventArgs e)
{
filepathTextBox.Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
}

// 进度条最大值修改
private void fixMetaDataCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (fixMetaDataCheckBox.Checked)
{
toolStripProgressBar1.Maximum = 5;
}
else
{
toolStripProgressBar1.Maximum = 4;
}

}
}
}
3 changes: 3 additions & 0 deletions WndMain.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,7 @@
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>185, 17</value>
</metadata>
</root>

0 comments on commit 9fcbed1

Please sign in to comment.